Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Create resume profile

Khuram Niaz97464302e485
diff --git a/src/actions/profile.actions.ts b/src/actions/profile.actions.ts
new file mode 100644
index 0000000..a097477
--- /dev/null
+++ b/src/actions/profile.actions.ts
@@ -0,0 +1,102 @@
+"use server";
+import prisma from "@/lib/db";
+import { CreateResumeFormSchema } from "@/models/createResumeForm.schema";
+import { getCurrentUser } from "@/utils/user.utils";
+import { z } from "zod";
+
+export const createResumeProfile = async (
+ data: z.infer<typeof CreateResumeFormSchema>
+): Promise<any | undefined> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
+ const { title } = data;
+
+ const profile = await prisma.profile.findFirst({
+ where: {
+ userId: user.id,
+ },
+ });
+
+ const res =
+ profile && profile.id
+ ? await prisma.resume.create({
+ data: {
+ profileId: profile!.id,
+ title,
+ },
+ })
+ : await prisma.profile.create({
+ data: {
+ userId: user.id,
+ resumes: {
+ create: [
+ {
+ title,
+ },
+ ],
+ },
+ },
+ });
+ return { success: true, data: res };
+ } catch (error) {
+ const msg = "Failed to create resume.";
+ console.error(msg, error);
+ if (error instanceof Error) {
+ return { success: false, message: error.message };
+ }
+ }
+};
+
+// export const editResumeTitle = async (
+// data: z.infer<typeof CreateResumeFormSchema>
+// ): Promise<any | undefined> => {
+// try {
+// const user = await getCurrentUser();
+
+// if (!user) {
+// throw new Error("Not authenticated");
+// }
+
+// const { id, company, logoUrl, createdBy } = data;
+
+// if (!id || user.id != createdBy) {
+// throw new Error("Id is not provided or no user privilages");
+// }
+
+// const value = company.trim().toLowerCase();
+
+// const companyExists = await prisma.company.findUnique({
+// where: {
+// value,
+// },
+// });
+
+// if (companyExists) {
+// throw new Error("Company already exists!");
+// }
+
+// const res = await prisma.company.update({
+// where: {
+// id,
+// },
+// data: {
+// value,
+// label: company,
+// logoUrl,
+// },
+// });
+
+// return { success: true, data: res };
+// } catch (error) {
+// const msg = "Failed to update company.";
+// console.error(msg, error);
+// if (error instanceof Error) {
+// return { success: false, message: error.message };
+// }
+// }
+// };
diff --git a/src/components/CreateResume.tsx b/src/components/CreateResume.tsx
new file mode 100644
index 0000000..f2fe7d0
--- /dev/null
+++ b/src/components/CreateResume.tsx
@@ -0,0 +1,142 @@
+"use client";
+import { Loader, PlusCircle } from "lucide-react";
+import { Button } from "./ui/button";
+import { useForm } from "react-hook-form";
+import { CreateResumeFormSchema } from "@/models/createResumeForm.schema";
+import { z } from "zod";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useState, useTransition } from "react";
+import {
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "./ui/dialog";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "./ui/form";
+import { Input } from "./ui/input";
+import { Resume } from "@/models/profile.model";
+import { toast } from "./ui/use-toast";
+import { createResumeProfile } from "@/actions/profile.actions";
+
+type CreateResumeProps = {
+ editResume?: Resume | null;
+};
+
+function CreateResume({ editResume }: CreateResumeProps) {
+ const [dialogOpen, setDialogOpen] = useState(false);
+ const [isPending, startTransition] = useTransition();
+
+ const pageTitle = editResume ? "Edit Resume Title" : "Create Resume";
+
+ const form = useForm<z.infer<typeof CreateResumeFormSchema>>({
+ resolver: zodResolver(CreateResumeFormSchema),
+ });
+
+ const { setValue, reset, formState } = form;
+
+ const createResume = () => {
+ // reset();
+ // resetEditJob();
+ setDialogOpen(true);
+ };
+
+ const onSubmit = (data: z.infer<typeof CreateResumeFormSchema>) => {
+ startTransition(async () => {
+ const res = await createResumeProfile(data);
+ // const res = editCompany
+ // ? await updateCompany(data)
+ // : await addCompany(data);
+ if (!res.success) {
+ toast({
+ variant: "destructive",
+ title: "Error!",
+ description: res.message,
+ });
+ } else {
+ reset();
+ setDialogOpen(false);
+ // reloadCompanies();
+ toast({
+ variant: "success",
+ description: `Resume title has been ${
+ editResume ? "updated" : "created"
+ } successfully`,
+ });
+ }
+ });
+ };
+
+ return (
+ <>
+ <Button size="sm" className="h-8 gap-1" onClick={createResume}>
+ <PlusCircle className="h-3.5 w-3.5" />
+ <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">
+ Create Resume
+ </span>
+ </Button>
+ <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
+ <DialogContent className="lg:max-h-screen overflow-y-scroll">
+ <DialogHeader>
+ <DialogTitle>{pageTitle}</DialogTitle>
+ </DialogHeader>
+ <Form {...form}>
+ <form
+ onSubmit={form.handleSubmit(onSubmit)}
+ className="grid grid-cols-1 md:grid-cols-2 gap-4 p-2"
+ >
+ {/* RESUME TITLE */}
+ <div className="md:col-span-2">
+ <FormField
+ control={form.control}
+ name="title"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Resume Title</FormLabel>
+ <FormControl>
+ <Input
+ {...field}
+ placeholder="Ex: Full Stack Developer Angular, Java"
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <div className="md:col-span-2 mt-4">
+ <DialogFooter>
+ <DialogClose>
+ <Button
+ type="reset"
+ variant="outline"
+ className="mt-2 md:mt-0 w-full"
+ >
+ Cancel
+ </Button>
+ </DialogClose>
+ <Button type="submit" disabled={!formState.isDirty}>
+ Save
+ {isPending ? (
+ <Loader className="h-4 w-4 shrink-0 spinner" />
+ ) : null}
+ </Button>
+ </DialogFooter>
+ </div>
+ </form>
+ </Form>
+ </DialogContent>
+ </Dialog>
+ </>
+ );
+}
+
+export default CreateResume;
diff --git a/src/components/ProfileContainer.tsx b/src/components/ProfileContainer.tsx
index 908d96a..bc8499f 100644
--- a/src/components/ProfileContainer.tsx
+++ b/src/components/ProfileContainer.tsx
@@ -1,11 +1,15 @@
import ActivitiesTable from "./ActivitiesTable";
+import CreateResume from "./CreateResume";
import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";
function ActivitiesContainer() {
return (
<Card>
- <CardHeader>
+ <CardHeader className="flex-row justify-between items-center">
<CardTitle>Profile</CardTitle>
+ <div className="flex items-center">
+ <CreateResume />
+ </div>
</CardHeader>
<CardContent></CardContent>
</Card>
diff --git a/src/models/addCompanyForm.schema.ts b/src/models/addCompanyForm.schema.ts
index 5d2ca6a..60bdbfc 100644
--- a/src/models/addCompanyForm.schema.ts
+++ b/src/models/addCompanyForm.schema.ts
@@ -1,4 +1,4 @@
-import { nullable, z } from "zod";
+import { z } from "zod";
export const AddCompanyFormSchema = z.object({
id: z.string().optional(),
diff --git a/src/models/createResumeForm.schema.ts b/src/models/createResumeForm.schema.ts
new file mode 100644
index 0000000..6cc9dcf
--- /dev/null
+++ b/src/models/createResumeForm.schema.ts
@@ -0,0 +1,12 @@
+import { z } from "zod";
+
+export const CreateResumeFormSchema = z.object({
+ id: z.string().optional(),
+ createdBy: z.string().optional(),
+ title: z
+ .string({
+ required_error: "Resume title is required.",
+ })
+ .min(1),
+ profileId: z.string().optional(),
+});
diff --git a/src/models/profile.model.ts b/src/models/profile.model.ts
new file mode 100644
index 0000000..6854433
--- /dev/null
+++ b/src/models/profile.model.ts
@@ -0,0 +1,7 @@
+export interface Resume {
+ id?: string;
+ profileId?: string;
+ title: string;
+ createdAt?: Date;
+ updatedAt?: Date;
+}