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.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
Fix: Edit company
Khuram Niazd7a15e293345
diff --git a/package-lock.json b/package-lock.jsonindex 508c314..2a37713 100644--- a/package-lock.json+++ b/package-lock.json@@ -24,6 +24,7 @@"@radix-ui/react-scroll-area": "^1.0.5","@radix-ui/react-select": "^2.0.0","@radix-ui/react-slot": "^1.0.2",+ "@radix-ui/react-switch": "^1.0.3","@radix-ui/react-tabs": "^1.0.4","@radix-ui/react-toast": "^1.1.5","@radix-ui/react-toggle": "^1.0.3",@@ -1470,6 +1471,35 @@}}},+ "node_modules/@radix-ui/react-switch": {+ "version": "1.0.3",+ "resolved": "https://registry.npmjs.org/@radix-ui/react-switch/-/react-switch-1.0.3.tgz",+ "integrity": "sha512-mxm87F88HyHztsI7N+ZUmEoARGkC22YVW5CaC+Byc+HRpuvCrOBPTAnXgf+tZ/7i0Sg/eOePGdMhUKhPaQEqow==",+ "dependencies": {+ "@babel/runtime": "^7.13.10",+ "@radix-ui/primitive": "1.0.1",+ "@radix-ui/react-compose-refs": "1.0.1",+ "@radix-ui/react-context": "1.0.1",+ "@radix-ui/react-primitive": "1.0.3",+ "@radix-ui/react-use-controllable-state": "1.0.1",+ "@radix-ui/react-use-previous": "1.0.1",+ "@radix-ui/react-use-size": "1.0.1"+ },+ "peerDependencies": {+ "@types/react": "*",+ "@types/react-dom": "*",+ "react": "^16.8 || ^17.0 || ^18.0",+ "react-dom": "^16.8 || ^17.0 || ^18.0"+ },+ "peerDependenciesMeta": {+ "@types/react": {+ "optional": true+ },+ "@types/react-dom": {+ "optional": true+ }+ }+ },"node_modules/@radix-ui/react-tabs": {"version": "1.0.4","resolved": "https://registry.npmjs.org/@radix-ui/react-tabs/-/react-tabs-1.0.4.tgz",diff --git a/package.json b/package.jsonindex 3613505..0572ab8 100644--- a/package.json+++ b/package.json@@ -26,6 +26,7 @@"@radix-ui/react-scroll-area": "^1.0.5","@radix-ui/react-select": "^2.0.0","@radix-ui/react-slot": "^1.0.2",+ "@radix-ui/react-switch": "^1.0.3","@radix-ui/react-tabs": "^1.0.4","@radix-ui/react-toast": "^1.1.5","@radix-ui/react-toggle": "^1.0.3",diff --git a/prisma/migrations/20240612084946_add_joburl_and_applied_fields/migration.sql b/prisma/migrations/20240612084946_add_joburl_and_applied_fields/migration.sqlnew file mode 100644index 0000000..ec83829--- /dev/null+++ b/prisma/migrations/20240612084946_add_joburl_and_applied_fields/migration.sql@@ -0,0 +1,30 @@+-- RedefineTables+PRAGMA foreign_keys=OFF;+CREATE TABLE "new_Job" (+ "id" TEXT NOT NULL PRIMARY KEY,+ "userId" TEXT NOT NULL,+ "jobUrl" TEXT,+ "description" TEXT NOT NULL,+ "jobType" TEXT NOT NULL,+ "createdAt" DATETIME NOT NULL,+ "applied" BOOLEAN NOT NULL DEFAULT false,+ "appliedDate" DATETIME,+ "dueDate" DATETIME,+ "statusId" TEXT NOT NULL,+ "jobTitleId" TEXT NOT NULL,+ "companyId" TEXT NOT NULL,+ "jobSourceId" TEXT,+ "salaryRange" TEXT,+ "locationId" TEXT,+ CONSTRAINT "Job_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "Job_statusId_fkey" FOREIGN KEY ("statusId") REFERENCES "JobStatus" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "Job_jobTitleId_fkey" FOREIGN KEY ("jobTitleId") REFERENCES "JobTitle" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "Job_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "Job_jobSourceId_fkey" FOREIGN KEY ("jobSourceId") REFERENCES "JobSource" ("id") ON DELETE SET NULL ON UPDATE CASCADE,+ CONSTRAINT "Job_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "Location" ("id") ON DELETE SET NULL ON UPDATE CASCADE+);+INSERT INTO "new_Job" ("appliedDate", "companyId", "createdAt", "description", "dueDate", "id", "jobSourceId", "jobTitleId", "jobType", "locationId", "salaryRange", "statusId", "userId") SELECT "appliedDate", "companyId", "createdAt", "description", "dueDate", "id", "jobSourceId", "jobTitleId", "jobType", "locationId", "salaryRange", "statusId", "userId" FROM "Job";+DROP TABLE "Job";+ALTER TABLE "new_Job" RENAME TO "Job";+PRAGMA foreign_key_check("Job");+PRAGMA foreign_keys=ON;diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 319641a..411db76 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -92,9 +92,11 @@ model Job {id String @id @default(uuid())userId StringUser User @relation(fields: [userId], references: [id])+ jobUrl String?description StringjobType StringcreatedAt DateTime+ applied Boolean @default(false)appliedDate DateTime?dueDate DateTime?statusId Stringdiff --git a/src/actions/company.actions.ts b/src/actions/company.actions.tsindex 919cb9c..f7d44d4 100644--- a/src/actions/company.actions.ts+++ b/src/actions/company.actions.ts@@ -1,6 +1,8 @@"use server";import prisma from "@/lib/db";+import { AddCompanyFormSchema } from "@/models/addCompanyForm.schema";import { getCurrentUser } from "@/utils/user.utils";+import { z } from "zod";export const getCompanyList = async (page = 1,@@ -84,9 +86,8 @@ export const getAllCompanies = async (): Promise<any | undefined> => {}};-export const createCompany = async (- label: string,- logoUrl?: string+export const addCompany = async (+ data: z.infer<typeof AddCompanyFormSchema>): Promise<any | undefined> => {try {const user = await getCurrentUser();@@ -95,20 +96,85 @@ export const createCompany = async (throw new Error("Not authenticated");}- const value = label.trim().toLowerCase();+ const { company, logoUrl } = data;- // Upsert the name (create if it does not exist, update if it exists)- const upsertedName = await prisma.company.upsert({- where: { value },- update: { label, value, logoUrl },- create: { label, value, logoUrl, createdBy: user.id },+ 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.create({+ data: {+ createdBy: user.id,+ value,+ label: company,+ logoUrl,+ },});- return upsertedName;+ return { success: true, data: res };} catch (error) {- const msg = "Failed to create company. ";+ const msg = "Failed to create company.";console.error(msg, error);- throw new Error(msg);+ if (error instanceof Error) {+ return { success: false, message: error.message };+ }+ }+};++export const updateCompany = async (+ data: z.infer<typeof AddCompanyFormSchema>+): 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/actions/job.actions.ts b/src/actions/job.actions.tsindex 5d088f7..74e913d 100644--- a/src/actions/job.actions.ts+++ b/src/actions/job.actions.ts@@ -247,7 +247,6 @@ export const updateJob = async (throw new Error("Not authenticated");}if (!data.id || user.id != data.userId) {- console.log({ data, user });throw new Error("Id is not provide or no user privilages");}diff --git a/src/app/dashboard/myjobs/page.tsx b/src/app/dashboard/myjobs/page.tsxindex a0d3436..6ac6953 100644--- a/src/app/dashboard/myjobs/page.tsx+++ b/src/app/dashboard/myjobs/page.tsx@@ -7,7 +7,7 @@ import {getStatusList,} from "@/actions/job.actions";import JobsContainer from "@/components/JobsContainer";-import { getAllCompanies, getCompanyList } from "@/actions/company.actions";+import { getAllCompanies } from "@/actions/company.actions";export const metadata: Metadata = {title: "My Jobs | JobSync",diff --git a/src/components/AddCompany.tsx b/src/components/AddCompany.tsxindex e339d86..0d5649d 100644--- a/src/components/AddCompany.tsx+++ b/src/components/AddCompany.tsx@@ -5,6 +5,7 @@ import {Dialog,DialogClose,DialogContent,+ DialogDescription,DialogFooter,DialogHeader,DialogTitle,@@ -25,7 +26,7 @@ import {} from "./ui/form";import { Input } from "./ui/input";import { toast } from "./ui/use-toast";-import { createCompany } from "@/actions/company.actions";+import { addCompany, updateCompany } from "@/actions/company.actions";import { Company } from "@/models/job.model";type AddCompanyProps = {@@ -48,13 +49,16 @@ function AddCompany({resolver: zodResolver(AddCompanyFormSchema),});- const { setValue, reset } = form;+ const { setValue, reset, formState } = form;useEffect(() => {if (editCompany) {setValue("id", editCompany.id);setValue("company", editCompany.label);- setValue("logoUrl", editCompany.logoUrl);+ setValue("createdBy", editCompany.createdBy);+ if (editCompany.logoUrl) {+ setValue("logoUrl", editCompany?.logoUrl);+ }setDialogOpen(true);}@@ -67,17 +71,27 @@ function AddCompany({};const onSubmit = (data: z.infer<typeof AddCompanyFormSchema>) => {- console.log("form data: ", data);startTransition(async () => {- const res = await createCompany(data.company, data.logoUrl);- reset();- setDialogOpen(false);- reloadCompanies();- });- toast({- description: `Company has been ${- editCompany ? "updated" : "created"- } successfully`,+ 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: `Company has been ${+ editCompany ? "updated" : "created"+ } successfully`,+ });+ }});};@@ -93,11 +107,15 @@ function AddCompany({<DialogContent className="lg:max-h-screen overflow-y-scroll"><DialogHeader><DialogTitle>{pageTitle}</DialogTitle>+ <DialogDescription className="text-primary">+ Caution: Editing name of the company with affect all the related+ job records.+ </DialogDescription></DialogHeader><Form {...form}><formonSubmit={form.handleSubmit(onSubmit)}- className="grid grid-cols-1 md:grid-cols-2 gap-4 p-4"+ className="grid grid-cols-1 md:grid-cols-2 gap-4 p-2">{/* COMPANY NAME */}<div className="md:col-span-2">@@ -145,7 +163,7 @@ function AddCompany({Cancel</Button></DialogClose>- <Button type="submit">+ <Button type="submit" disabled={!formState.isDirty}>Save{isPending ? (<Loader className="h-4 w-4 shrink-0 spinner" />diff --git a/src/components/CompaniesTable.tsx b/src/components/CompaniesTable.tsxindex e8289a9..2853e76 100644--- a/src/components/CompaniesTable.tsx+++ b/src/components/CompaniesTable.tsx@@ -18,7 +18,7 @@ import {TableRow,} from "./ui/table";import { Company } from "@/models/job.model";-import { MoreHorizontal } from "lucide-react";+import { MoreHorizontal, Pencil } from "lucide-react";import { TablePagination } from "./TablePagination";type CompaniesTableProps = {@@ -92,7 +92,8 @@ function CompaniesTable({className="cursor-pointer"onClick={() => editCompany(company.id)}>- Edit+ <Pencil className="mr-2 h-4 w-4" />+ Edit Company</DropdownMenuItem><DropdownMenuItem>Delete</DropdownMenuItem></DropdownMenuContent>diff --git a/src/components/ui/switch.tsx b/src/components/ui/switch.tsxnew file mode 100644index 0000000..bc69cf2--- /dev/null+++ b/src/components/ui/switch.tsx@@ -0,0 +1,29 @@+"use client"++import * as React from "react"+import * as SwitchPrimitives from "@radix-ui/react-switch"++import { cn } from "@/lib/utils"++const Switch = React.forwardRef<+ React.ElementRef<typeof SwitchPrimitives.Root>,+ React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>+>(({ className, ...props }, ref) => (+ <SwitchPrimitives.Root+ className={cn(+ "peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",+ className+ )}+ {...props}+ ref={ref}+ >+ <SwitchPrimitives.Thumb+ className={cn(+ "pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"+ )}+ />+ </SwitchPrimitives.Root>+))+Switch.displayName = SwitchPrimitives.Root.displayName++export { Switch }diff --git a/src/components/ui/toast.tsx b/src/components/ui/toast.tsxindex 521b94b..4237f20 100644--- a/src/components/ui/toast.tsx+++ b/src/components/ui/toast.tsx@@ -1,13 +1,13 @@-"use client"+"use client";-import * as React from "react"-import * as ToastPrimitives from "@radix-ui/react-toast"-import { cva, type VariantProps } from "class-variance-authority"-import { X } from "lucide-react"+import * as React from "react";+import * as ToastPrimitives from "@radix-ui/react-toast";+import { cva, type VariantProps } from "class-variance-authority";+import { X } from "lucide-react";-import { cn } from "@/lib/utils"+import { cn } from "@/lib/utils";-const ToastProvider = ToastPrimitives.Provider+const ToastProvider = ToastPrimitives.Provider;const ToastViewport = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Viewport>,@@ -21,8 +21,8 @@ const ToastViewport = React.forwardRef<)}{...props}/>-))-ToastViewport.displayName = ToastPrimitives.Viewport.displayName+));+ToastViewport.displayName = ToastPrimitives.Viewport.displayName;const toastVariants = cva("group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",@@ -32,13 +32,14 @@ const toastVariants = cva(default: "border bg-background text-foreground",destructive:"destructive group border-destructive bg-destructive text-destructive-foreground",+ success: "success group border-green-500 bg-green-500 text-foreground",},},defaultVariants: {variant: "default",},}-)+);const Toast = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Root>,@@ -51,9 +52,9 @@ const Toast = React.forwardRef<className={cn(toastVariants({ variant }), className)}{...props}/>- )-})-Toast.displayName = ToastPrimitives.Root.displayName+ );+});+Toast.displayName = ToastPrimitives.Root.displayName;const ToastAction = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Action>,@@ -67,8 +68,8 @@ const ToastAction = React.forwardRef<)}{...props}/>-))-ToastAction.displayName = ToastPrimitives.Action.displayName+));+ToastAction.displayName = ToastPrimitives.Action.displayName;const ToastClose = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Close>,@@ -85,8 +86,8 @@ const ToastClose = React.forwardRef<><X className="h-4 w-4" /></ToastPrimitives.Close>-))-ToastClose.displayName = ToastPrimitives.Close.displayName+));+ToastClose.displayName = ToastPrimitives.Close.displayName;const ToastTitle = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Title>,@@ -97,8 +98,8 @@ const ToastTitle = React.forwardRef<className={cn("text-sm font-semibold", className)}{...props}/>-))-ToastTitle.displayName = ToastPrimitives.Title.displayName+));+ToastTitle.displayName = ToastPrimitives.Title.displayName;const ToastDescription = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Description>,@@ -109,12 +110,12 @@ const ToastDescription = React.forwardRef<className={cn("text-sm opacity-90", className)}{...props}/>-))-ToastDescription.displayName = ToastPrimitives.Description.displayName+));+ToastDescription.displayName = ToastPrimitives.Description.displayName;-type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>+type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;-type ToastActionElement = React.ReactElement<typeof ToastAction>+type ToastActionElement = React.ReactElement<typeof ToastAction>;export {type ToastProps,@@ -126,4 +127,4 @@ export {ToastDescription,ToastClose,ToastAction,-}+};diff --git a/src/models/addCompanyForm.schema.ts b/src/models/addCompanyForm.schema.tsindex 8f29e3b..4305aec 100644--- a/src/models/addCompanyForm.schema.ts+++ b/src/models/addCompanyForm.schema.ts@@ -1,10 +1,12 @@-import { z } from "zod";+import { nullable, z } from "zod";export const AddCompanyFormSchema = z.object({id: z.string().optional(),createdBy: z.string().optional(),- company: z.string({- required_error: "Company name is required.",- }),- logoUrl: z.string().optional(),+ company: z+ .string({+ required_error: "Company name is required.",+ })+ .min(1),+ logoUrl: z.string().optional().default(""),});