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
delete activity
Khuram Niaz7614822997d9
diff --git a/src/actions/activity.actions.ts b/src/actions/activity.actions.tsindex 25f74ef..acae79b 100644--- a/src/actions/activity.actions.ts+++ b/src/actions/activity.actions.ts@@ -121,3 +121,26 @@ export const createActivity = async (return handleError(error, msg);}};++export const deleteActivityById = async (+ activityId: string+): Promise<any | undefined> => {+ try {+ const user = await getCurrentUser();++ if (!user) {+ throw new Error("Not authenticated");+ }++ const res = await prisma.activity.delete({+ where: {+ id: activityId,+ userId: user.id,+ },+ });+ return { res, success: true };+ } catch (error) {+ const msg = "Failed to delete job.";+ return handleError(error, msg);+ }+};diff --git a/src/components/activities/ActivitiesContainer.tsx b/src/components/activities/ActivitiesContainer.tsxindex 194a2f9..5bd1386 100644--- a/src/components/activities/ActivitiesContainer.tsx+++ b/src/components/activities/ActivitiesContainer.tsx@@ -3,7 +3,7 @@ import ActivitiesTable from "./ActivitiesTable";import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";import { Button } from "../ui/button";import { PlusCircle } from "lucide-react";-import { useEffect, useState } from "react";+import { useCallback, useEffect, useState } from "react";import {Dialog,DialogContent,@@ -12,21 +12,44 @@ import {DialogTrigger,} from "../ui/dialog";import { ActivityForm } from "./ActivityForm";-import { activitiesData } from "@/lib/data/activitiesData";import { getActivitiesList } from "@/actions/activity.actions";import { Activity } from "@/models/activity.model";-import { set } from "date-fns";+import { toast } from "../ui/use-toast";+import Loading from "../Loading";function ActivitiesContainer() {const [activityFormOpen, setActivityFormOpen] = useState<boolean>(false);const [activitiesList, setActivitiesList] = useState<Activity[]>([]);- const loadActivities = async () => {- const response = await getActivitiesList();- setActivitiesList(response.data);- };+ const [loading, setLoading] = useState(false);+ const loadActivities = useCallback(async () => {+ setLoading(true);+ try {+ const { data, success, message } = await getActivitiesList();+ if (success) {+ setActivitiesList(data);+ } else {+ toast({+ variant: "destructive",+ title: "Error!",+ description: message,+ });+ }+ } catch (error) {+ toast({+ variant: "destructive",+ title: "Error!",+ description: "Failed to load activities. Please try again.",+ });+ } finally {+ setLoading(false);+ }+ }, []);+ const reloadActivities = useCallback(async () => {+ await loadActivities();+ }, [loadActivities]);useEffect(() => {loadActivities();- }, []);+ }, [loadActivities]);return (<Card><CardHeader className="flex-row justify-between items-center">@@ -49,12 +72,19 @@ function ActivitiesContainer() {<DialogHeader><DialogTitle>Add New Activity</DialogTitle></DialogHeader>- <ActivityForm onClose={() => setActivityFormOpen(false)} />+ <ActivityForm+ onClose={() => setActivityFormOpen(false)}+ reloadActivities={reloadActivities}+ /></DialogContent></Dialog></CardHeader><CardContent>- <ActivitiesTable activities={activitiesList} />+ {loading && <Loading />}+ <ActivitiesTable+ activities={activitiesList}+ reloadActivities={reloadActivities}+ /></CardContent></Card>);diff --git a/src/components/activities/ActivitiesTable.tsx b/src/components/activities/ActivitiesTable.tsxindex b6ba245..a4a3a59 100644--- a/src/components/activities/ActivitiesTable.tsx+++ b/src/components/activities/ActivitiesTable.tsx@@ -1,4 +1,5 @@-import { MoreHorizontal, Pencil, Trash } from "lucide-react";+"use client";+import { CirclePlay, MoreHorizontal, Trash } from "lucide-react";import {Table,TableBody,@@ -15,89 +16,162 @@ import {DropdownMenuLabel,DropdownMenuTrigger,} from "../ui/dropdown-menu";-import { Button } from "../ui/button";-import { differenceInMinutes, format } from "date-fns";+import { Button, buttonVariants } from "../ui/button";+import { format } from "date-fns";import { Activity, ActivityType } from "@/models/activity.model";+import { deleteActivityById } from "@/actions/activity.actions";+import { toast } from "../ui/use-toast";+import { useMemo, useState } from "react";+import {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+} from "../ui/alert-dialog";interface ActivitiesTableProps {activities: Activity[];+ reloadActivities: () => void;}-function ActivitiesTable({ activities }: ActivitiesTableProps) {- const calculateDuration = (start: Date, end: Date) => {- const totalMinutes = differenceInMinutes(end, start);-+function ActivitiesTable({+ activities,+ reloadActivities,+}: ActivitiesTableProps) {+ const [alertOpen, setAlertOpen] = useState(false);+ const [activityIdToDelete, setActivityIdToDelete] = useState<string>();+ const calculateDuration = (totalMinutes: number) => {const hours = Math.floor(totalMinutes / 60);const minutes = totalMinutes % 60;- return `${hours}h ${minutes}min`;+ return totalMinutes === 0 ? "" : `${hours}h ${minutes}min`;+ };++ const onDeleteActivity = useMemo(+ () => (id: string) => {+ setAlertOpen(true);+ setActivityIdToDelete(id);+ },+ []+ );++ const deleteActivity = async (activityId: string) => {+ const { success, message } = await deleteActivityById(activityId);+ if (success) {+ toast({+ variant: "success",+ description: `Activity has been deleted successfully`,+ });+ reloadActivities();+ } else {+ toast({+ variant: "destructive",+ title: "Error!",+ description: message,+ });+ }};return (- <Table>- <TableHeader>- <TableRow>- <TableHead className="hidden md:table-cell">Date</TableHead>- <TableHead>Activity</TableHead>- <TableHead className="hidden md:table-cell">Activity Type</TableHead>- <TableHead>Start Time</TableHead>- <TableHead>End Time</TableHead>- <TableHead className="hidden md:table-cell">Duration</TableHead>- <TableHead>- <span className="sr-only">Actions</span>- </TableHead>- </TableRow>- </TableHeader>- <TableBody>- {activities.map((activity: Activity) => {- return (- <TableRow key={activity.id} className="cursor-pointer">- <TableCell className="hidden md:table-cell w-[120px]">- {activity.startTime ? format(activity.startTime, "PP") : "N/A"}- </TableCell>- <TableCell className="font-medium">- {activity.activityName}- </TableCell>- <TableCell className="font-medium">- {(activity.activityType as ActivityType)?.label}- </TableCell>- <TableCell className="hidden md:table-cell">- {format(activity.startTime, "p")}- </TableCell>- <TableCell className="hidden md:table-cell">- {format(activity.endTime!, "p")}- </TableCell>- <TableCell className="hidden md:table-cell">- {activity.startTime &&- activity.endTime &&- calculateDuration(activity.startTime, activity.endTime!)}- </TableCell>- <TableCell>- <DropdownMenu>- <DropdownMenuTrigger asChild>- <Button aria-haspopup="true" size="icon" variant="ghost">- <MoreHorizontal className="h-4 w-4" />- <span className="sr-only">Toggle menu</span>- </Button>- </DropdownMenuTrigger>- <DropdownMenuContent align="end" className="w-[200px]">- <DropdownMenuLabel>Actions</DropdownMenuLabel>- <DropdownMenuGroup>- <DropdownMenuItem className="cursor-pointer">- <Pencil className="mr-2 h-4 w-4" />- Edit Activity- </DropdownMenuItem>- <DropdownMenuItem className="text-red-600 cursor-pointer">- <Trash className="mr-2 h-4 w-4" />- Delete- </DropdownMenuItem>- </DropdownMenuGroup>- </DropdownMenuContent>- </DropdownMenu>- </TableCell>- </TableRow>- );- })}- </TableBody>- </Table>+ <>+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead className="hidden md:table-cell">Date</TableHead>+ <TableHead>Activity</TableHead>+ <TableHead className="hidden md:table-cell">+ Activity Type+ </TableHead>+ <TableHead>Start Time</TableHead>+ <TableHead>End Time</TableHead>+ <TableHead className="hidden md:table-cell">Duration</TableHead>+ <TableHead>+ <span className="sr-only">Actions</span>+ </TableHead>+ </TableRow>+ </TableHeader>+ <TableBody>+ {activities?.map((activity: Activity) => {+ return (+ <TableRow key={activity.id} className="cursor-pointer">+ <TableCell className="hidden md:table-cell w-[120px]">+ {activity.startTime+ ? format(activity.startTime, "PP")+ : "N/A"}+ </TableCell>+ <TableCell className="font-medium">+ {activity.activityName}+ </TableCell>+ <TableCell className="font-medium">+ {(activity.activityType as ActivityType)?.label}+ </TableCell>+ <TableCell className="hidden md:table-cell">+ {format(activity.startTime, "p")}+ </TableCell>+ <TableCell className="hidden md:table-cell">+ {format(activity.endTime!, "p")}+ </TableCell>+ <TableCell className="hidden md:table-cell">+ {activity.startTime &&+ activity.endTime &&+ calculateDuration(activity.duration ?? 0)}+ </TableCell>+ <TableCell>+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button aria-haspopup="true" size="icon" variant="ghost">+ <MoreHorizontal className="h-4 w-4" />+ <span className="sr-only">Toggle menu</span>+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" className="w-[200px]">+ <DropdownMenuLabel>Actions</DropdownMenuLabel>+ <DropdownMenuGroup>+ <DropdownMenuItem className="cursor-pointer text-green-400">+ <CirclePlay className="mr-2 h-4 w-4" />+ Start Activity+ </DropdownMenuItem>+ <DropdownMenuItem+ className="text-red-600 cursor-pointer"+ onClick={() => onDeleteActivity(activity.id!)}+ >+ <Trash className="mr-2 h-4 w-4" />+ Delete+ </DropdownMenuItem>+ </DropdownMenuGroup>+ </DropdownMenuContent>+ </DropdownMenu>+ </TableCell>+ </TableRow>+ );+ })}+ </TableBody>+ </Table>+ <AlertDialog open={alertOpen} onOpenChange={setAlertOpen}>+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>+ Are you sure you want to delete this activity?+ </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={() => deleteActivity(activityIdToDelete!)}+ >+ Delete+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ </>);}diff --git a/src/components/activities/ActivityForm.tsx b/src/components/activities/ActivityForm.tsxindex aa60562..db0f1f1 100644--- a/src/components/activities/ActivityForm.tsx+++ b/src/components/activities/ActivityForm.tsx@@ -34,6 +34,7 @@ import { combineDateAndTime } from "@/lib/utils";interface ActivityFormProps {onClose: () => void;+ reloadActivities: () => void;}type Duration = {@@ -41,7 +42,7 @@ type Duration = {minutes: number;};-export function ActivityForm({ onClose }: ActivityFormProps) {+export function ActivityForm({ onClose, reloadActivities }: ActivityFormProps) {const [activityTypes, setActivityTypes] = useState<ActivityType[]>([]);const [duration, setDuration] = useState<Duration | null>(null);const defaultValues = useMemo(() => {@@ -131,6 +132,7 @@ export function ActivityForm({ onClose }: ActivityFormProps) {};const response = await createActivity(payload);onClose();+ reloadActivities();} catch (error) {console.error("Error parsing date and time:", error);}diff --git a/src/components/dashboard/JobsAppliedCard.tsx b/src/components/dashboard/JobsAppliedCard.tsxindex fd4d8dd..2a39d74 100644--- a/src/components/dashboard/JobsAppliedCard.tsx+++ b/src/components/dashboard/JobsAppliedCard.tsx@@ -7,6 +7,7 @@ import {CardHeader,CardTitle,} from "@/components/ui/card";+import { PlusCircle } from "lucide-react";import { useRouter } from "next/navigation";export default function JobsAppliedCard() {@@ -24,7 +25,10 @@ export default function JobsAppliedCard() {variant="outline"onClick={() => router.push("/dashboard/myjobs")}>- Add New Job+ <PlusCircle className="h-3.5 w-3.5 mr-1" />+ <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">+ Add New Job+ </span></Button></CardFooter></Card>diff --git a/src/components/myjobs/JobsContainer.tsx b/src/components/myjobs/JobsContainer.tsxindex 11179e9..9030ed5 100644--- a/src/components/myjobs/JobsContainer.tsx+++ b/src/components/myjobs/JobsContainer.tsx@@ -218,22 +218,19 @@ function JobsContainer({</div></CardHeader><CardContent>- {!loading ? (- <MyJobsTable- jobs={jobs}- jobStatuses={statuses}- currentPage={currentPage}- totalPages={totalPages}- jobsPerPage={jobsPerPage}- totalJobs={totalJobs}- onPageChange={onPageChange}- deleteJob={onDeleteJob}- editJob={onEditJob}- onChangeJobStatus={onChangeJobStatus}- />- ) : (- <Loading />- )}+ {loading && <Loading />}+ <MyJobsTable+ jobs={jobs}+ jobStatuses={statuses}+ currentPage={currentPage}+ totalPages={totalPages}+ jobsPerPage={jobsPerPage}+ totalJobs={totalJobs}+ onPageChange={onPageChange}+ deleteJob={onDeleteJob}+ editJob={onEditJob}+ onChangeJobStatus={onChangeJobStatus}+ /></CardContent><CardFooter></CardFooter></Card>diff --git a/src/components/profile/ProfileContainer.tsx b/src/components/profile/ProfileContainer.tsxindex be21d22..3b20c42 100644--- a/src/components/profile/ProfileContainer.tsx+++ b/src/components/profile/ProfileContainer.tsx@@ -102,20 +102,17 @@ function ActivitiesContainer() {</div></CardHeader><CardContent>- {!loading ? (- <ResumeTable- resumes={resumes}- currentPage={currentPage}- totalPages={totalPages}- recordsPerPage={recordsPerPage}- totalResumes={totalResumes}- // onPageChange={onPageChange}- editResume={onEditResume}- reloadResumes={reloadResumes}- />- ) : (- <Loading />- )}+ {loading && <Loading />}+ <ResumeTable+ resumes={resumes}+ currentPage={currentPage}+ totalPages={totalPages}+ recordsPerPage={recordsPerPage}+ totalResumes={totalResumes}+ // onPageChange={onPageChange}+ editResume={onEditResume}+ reloadResumes={reloadResumes}+ /></CardContent></Card>);