Skip to content

Commit

Permalink
resume-form
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutoshpadhi629 committed Oct 11, 2024
1 parent f500dfd commit 34ee6a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
20 changes: 20 additions & 0 deletions src/actions/user.profile.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,23 @@ export const validateUserBoarding = async () => {
return new ErrorHandler('Internal server error', 'DATABASE_ERROR');
}
};
export const addUserResume = async (resume: string) => {
const auth = await getServerSession(authOptions);

if (!auth || !auth?.user?.id)
throw new ErrorHandler('Not Authorized', 'UNAUTHORIZED');

try {
await prisma.user.update({
where: {
id: auth.user.id,
},
data: {
resume: resume,
},
});
return new SuccessResponse('Resume SuccessFully Uploaded', 200).serialize();
} catch (_error) {
return new ErrorHandler('Internal server error', 'DATABASE_ERROR');
}
};
24 changes: 16 additions & 8 deletions src/components/user-multistep-form/add-resume-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { X } from 'lucide-react';
import { Button } from '../ui/button';
import { useToast } from '../ui/use-toast';
import { uploadFileAction } from '@/actions/upload-to-cdn';
import { addUserResume } from '@/actions/user.profile.actions';

export const AddResume = () => {
const resumeFileRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -65,19 +66,26 @@ export const AddResume = () => {
variant: 'destructive',
});
}

if (res.message) {
toast({
title: res.message,
variant: 'success',
});
} else if (res.error) {
toast({
if (res.error) {
return toast({
title: 'Upload Failed',
description: `Error: ${res.error}`,
variant: 'destructive',
});
}
if (res.message) {
const response = await addUserResume(res.url);
if (!response.status) {
return toast({
title: response.message || 'Error',
variant: 'destructive',
});
}
return toast({
title: response.message,
variant: 'success',
});
}
} catch (error) {
console.error('Image upload failed:', error);
toast({
Expand Down

0 comments on commit 34ee6a7

Please sign in to comment.