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.

Add alert dialog before delete

Khuram Niaz812f6574c8ce
diff --git a/package-lock.json b/package-lock.json
index 2e9417d..508c314 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,6 +13,7 @@
"@nivo/calendar": "^0.87.0",
"@nivo/core": "^0.87.0",
"@prisma/client": "^5.14.0",
+ "@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
@@ -782,6 +783,34 @@
"@babel/runtime": "^7.13.10"
}
},
+ "node_modules/@radix-ui/react-alert-dialog": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-alert-dialog/-/react-alert-dialog-1.0.5.tgz",
+ "integrity": "sha512-OrVIOcZL0tl6xibeuGt5/+UxoT2N27KCFOPjFyfXMnchxSHZ/OW7cCX2nGlIYJrbHK/fczPcFzAwvNBB6XBNMA==",
+ "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-dialog": "1.0.5",
+ "@radix-ui/react-primitive": "1.0.3",
+ "@radix-ui/react-slot": "1.0.2"
+ },
+ "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-arrow": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-arrow/-/react-arrow-1.0.3.tgz",
diff --git a/package.json b/package.json
index 9e46b51..f911907 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,7 @@
"@nivo/calendar": "^0.87.0",
"@nivo/core": "^0.87.0",
"@prisma/client": "^5.14.0",
+ "@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
diff --git a/src/components/ComboBox.tsx b/src/components/ComboBox.tsx
index 1967e80..35208da 100644
--- a/src/components/ComboBox.tsx
+++ b/src/components/ComboBox.tsx
@@ -19,7 +19,6 @@ import {
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
-import { Job } from "@/models/job.model";
import { ScrollArea } from "./ui/scroll-area";
import { useState, useTransition } from "react";
import { delay } from "@/utils/delay";
@@ -28,10 +27,11 @@ import {
createJobTitle,
createLocation,
} from "@/actions/job.actions";
+import { JobForm } from "@/models/job.model";
interface ComboboxProps {
options: any[];
- field: ControllerRenderProps<Job, any>;
+ field: ControllerRenderProps<JobForm, any>;
creatable?: boolean;
}
diff --git a/src/components/DatePicker.tsx b/src/components/DatePicker.tsx
index 2d1c5ee..73d17b8 100644
--- a/src/components/DatePicker.tsx
+++ b/src/components/DatePicker.tsx
@@ -19,12 +19,12 @@ import {
SelectValue,
} from "@/components/ui/select";
import { ControllerRenderProps } from "react-hook-form";
-import { Job } from "@/models/job.model";
+import { JobForm } from "@/models/job.model";
import { useState } from "react";
import { FormControl } from "./ui/form";
interface DatePickerProps {
- field: ControllerRenderProps<Job, any>;
+ field: ControllerRenderProps<JobForm, any>;
presets: boolean;
}
diff --git a/src/components/JobsContainer.tsx b/src/components/JobsContainer.tsx
index 1b3e7cb..601f08e 100644
--- a/src/components/JobsContainer.tsx
+++ b/src/components/JobsContainer.tsx
@@ -24,6 +24,7 @@ import {
getJobDetails,
getJobsList,
} from "@/actions/job.actions";
+import { toast } from "./ui/use-toast";
type MyJobsProps = {
statuses: { id: string; label: string; value: string }[];
@@ -61,7 +62,12 @@ function JobsContainer({
};
const onDeleteJob = async (jobId: string) => {
- await deleteJobById(jobId);
+ const res = await deleteJobById(jobId);
+ if (res) {
+ toast({
+ description: `Job has been deleted successfully`,
+ });
+ }
reloadJobs();
};
diff --git a/src/components/MyJobsTable.tsx b/src/components/MyJobsTable.tsx
index 94ec884..2fbc654 100644
--- a/src/components/MyJobsTable.tsx
+++ b/src/components/MyJobsTable.tsx
@@ -30,7 +30,7 @@ import {
DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from "./ui/dropdown-menu";
-import { Button } from "./ui/button";
+import { Button, buttonVariants } from "./ui/button";
import {
Command,
CommandEmpty,
@@ -43,6 +43,16 @@ import { useState } from "react";
import { TablePagination } from "./TablePagination";
import { Dialog, DialogContent, DialogTrigger } from "./ui/dialog";
import JobDetails from "./JobDetails";
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from "./ui/alert-dialog";
type MyJobsTableProps = {
jobs: any[];
@@ -77,7 +87,9 @@ function MyJobsTable({
const [label, setLabel] = useState("feature");
const [open, setOpen] = useState(false);
const [dialogOpen, setDialogOpen] = useState(false);
+ const [alertOpen, setAlertOpen] = useState(false);
const [curJobId, setCurJobId] = useState("");
+ const [jobIdToDelete, setJobIdToDelete] = useState("");
const startPostIndex = (currentPage - 1) * jobsPerPage + 1;
const endPostIndex = Math.min(currentPage * jobsPerPage, totalJobs);
@@ -87,6 +99,11 @@ function MyJobsTable({
setDialogOpen(true);
};
+ const onDeleteJob = (jobId: string) => {
+ setAlertOpen(true);
+ setJobIdToDelete(jobId);
+ };
+
return (
<>
<Table>
@@ -210,7 +227,7 @@ function MyJobsTable({
<DropdownMenuSeparator />
<DropdownMenuItem
className="text-red-600 cursor-pointer"
- onClick={() => deleteJob(job.id)}
+ onClick={() => onDeleteJob(job.id)}
>
<Trash className="mr-2 h-4 w-4" />
Delete
@@ -243,6 +260,28 @@ function MyJobsTable({
totalPages={totalPages}
onPageChange={onPageChange}
/>
+ <AlertDialog open={alertOpen} onOpenChange={setAlertOpen}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>
+ Are you sure you want to delete this job?
+ </AlertDialogTitle>
+ <AlertDialogDescription>
+ This action cannot be undone. This will permanently delete and
+ remove data from server.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ className={buttonVariants({ variant: "destructive" })}
+ onClick={() => deleteJob(jobIdToDelete)}
+ >
+ Delete
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
</>
);
}
diff --git a/src/components/Select.tsx b/src/components/Select.tsx
index a145bd2..fa9e9d5 100644
--- a/src/components/Select.tsx
+++ b/src/components/Select.tsx
@@ -9,12 +9,12 @@ import {
} from "./ui/select";
import { FormControl } from "./ui/form";
import { ControllerRenderProps } from "react-hook-form";
-import { Job } from "@/models/job.model";
+import { JobForm } from "@/models/job.model";
interface SelectProps {
label: string;
options: any[];
- field: ControllerRenderProps<Job, any>;
+ field: ControllerRenderProps<JobForm, any>;
}
function SelectFormCtrl({ label, options, field }: SelectProps) {
diff --git a/src/components/TiptapEditor.tsx b/src/components/TiptapEditor.tsx
index 5e4e70c..34aaeee 100644
--- a/src/components/TiptapEditor.tsx
+++ b/src/components/TiptapEditor.tsx
@@ -1,6 +1,6 @@
"use client";
-import { Job } from "@/models/job.model";
+import { JobForm } from "@/models/job.model";
import { useEditor, EditorContent } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
@@ -8,7 +8,7 @@ import { ControllerRenderProps } from "react-hook-form";
import { Toggle } from "./ui/toggle";
import { Bold, Heading2, Italic, List, ListOrdered } from "lucide-react";
-const Tiptap = ({ field }: { field: ControllerRenderProps<Job, any> }) => {
+const Tiptap = ({ field }: { field: ControllerRenderProps<JobForm, any> }) => {
const editor = useEditor({
extensions: [
StarterKit.configure({
diff --git a/src/components/ui/alert-dialog.tsx b/src/components/ui/alert-dialog.tsx
new file mode 100644
index 0000000..25e7b47
--- /dev/null
+++ b/src/components/ui/alert-dialog.tsx
@@ -0,0 +1,141 @@
+"use client"
+
+import * as React from "react"
+import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
+
+import { cn } from "@/lib/utils"
+import { buttonVariants } from "@/components/ui/button"
+
+const AlertDialog = AlertDialogPrimitive.Root
+
+const AlertDialogTrigger = AlertDialogPrimitive.Trigger
+
+const AlertDialogPortal = AlertDialogPrimitive.Portal
+
+const AlertDialogOverlay = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Overlay
+ className={cn(
+ "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
+ className
+ )}
+ {...props}
+ ref={ref}
+ />
+))
+AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName
+
+const AlertDialogContent = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPortal>
+ <AlertDialogOverlay />
+ <AlertDialogPrimitive.Content
+ ref={ref}
+ className={cn(
+ "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
+ className
+ )}
+ {...props}
+ />
+ </AlertDialogPortal>
+))
+AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName
+
+const AlertDialogHeader = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn(
+ "flex flex-col space-y-2 text-center sm:text-left",
+ className
+ )}
+ {...props}
+ />
+)
+AlertDialogHeader.displayName = "AlertDialogHeader"
+
+const AlertDialogFooter = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn(
+ "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
+ className
+ )}
+ {...props}
+ />
+)
+AlertDialogFooter.displayName = "AlertDialogFooter"
+
+const AlertDialogTitle = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Title>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Title
+ ref={ref}
+ className={cn("text-lg font-semibold", className)}
+ {...props}
+ />
+))
+AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName
+
+const AlertDialogDescription = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Description>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Description
+ ref={ref}
+ className={cn("text-sm text-muted-foreground", className)}
+ {...props}
+ />
+))
+AlertDialogDescription.displayName =
+ AlertDialogPrimitive.Description.displayName
+
+const AlertDialogAction = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Action>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Action
+ ref={ref}
+ className={cn(buttonVariants(), className)}
+ {...props}
+ />
+))
+AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName
+
+const AlertDialogCancel = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Cancel
+ ref={ref}
+ className={cn(
+ buttonVariants({ variant: "outline" }),
+ "mt-2 sm:mt-0",
+ className
+ )}
+ {...props}
+ />
+))
+AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName
+
+export {
+ AlertDialog,
+ AlertDialogPortal,
+ AlertDialogOverlay,
+ AlertDialogTrigger,
+ AlertDialogContent,
+ AlertDialogHeader,
+ AlertDialogFooter,
+ AlertDialogTitle,
+ AlertDialogDescription,
+ AlertDialogAction,
+ AlertDialogCancel,
+}
diff --git a/src/models/job.model.ts b/src/models/job.model.ts
index cbd6303..37ae37d 100644
--- a/src/models/job.model.ts
+++ b/src/models/job.model.ts
@@ -1,4 +1,6 @@
-export interface Job {
+export interface JobForm {
+ id?: string;
+ userId?: string;
source: string;
title: string;
type: string;
@@ -11,6 +13,11 @@ export interface Job {
jobDescription: string;
}
+export interface JobResponse {
+ id: string;
+ userId: string;
+}
+
export enum JOB_TYPES {
FT = "Full-time",
PT = "Part-time",