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.

Refactor jobDetails to a page

Khuram Niazdcbd39237461
diff --git a/src/app/dashboard/myjobs/[id]/page.tsx b/src/app/dashboard/myjobs/[id]/page.tsx
new file mode 100644
index 0000000..03b4588
--- /dev/null
+++ b/src/app/dashboard/myjobs/[id]/page.tsx
@@ -0,0 +1,16 @@
+import { getJobDetails } from "@/actions/job.actions";
+import JobDetails from "@/components/myjobs/JobDetails";
+import { toast } from "@/components/ui/use-toast";
+
+async function JobDetailsPage({ params }: any) {
+ const { id } = params;
+ const { job } = await getJobDetails(id);
+
+ return (
+ <div className="col-span-3">
+ <JobDetails job={job} />
+ </div>
+ );
+}
+
+export default JobDetailsPage;
diff --git a/src/components/myjobs/JobDetails.tsx b/src/components/myjobs/JobDetails.tsx
index 83bc0c2..8b55fdd 100644
--- a/src/components/myjobs/JobDetails.tsx
+++ b/src/components/myjobs/JobDetails.tsx
@@ -1,50 +1,39 @@
"use client";
-import { useEffect, useState } from "react";
-import { Button } from "../ui/button";
-import {
- DialogClose,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
-} from "../ui/dialog";
-import { getJobDetails } from "@/actions/job.actions";
import { format } from "date-fns";
import { Badge } from "../ui/badge";
import { cn, formatUrl } from "@/lib/utils";
import { JobResponse } from "@/models/job.model";
-import { toast } from "../ui/use-toast";
import { TipTapContentViewer } from "../TipTapContentViewer";
+import {
+ Card,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+} from "../ui/card";
+import { Button } from "../ui/button";
+import { ChevronLeft } from "lucide-react";
+import { useRouter } from "next/navigation";
-function JobDetails({ jobId }: { jobId: string }) {
- const [job, setJob] = useState<JobResponse>();
- useEffect(() => {
- const getJob = async (id: string) => {
- const { job, success, message } = await getJobDetails(id);
- if (!success) {
- return toast({
- variant: "destructive",
- title: "Error!",
- description: message,
- });
- }
- setJob(job);
- };
- getJob(jobId);
- }, [jobId]);
-
+function JobDetails({ job }: { job: JobResponse }) {
+ const router = useRouter();
+ const goBack = () => router.back();
return (
<>
+ <Button variant="outline" onClick={goBack}>
+ <ChevronLeft />
+ Back
+ </Button>
{job?.id && (
- <div className="col-span-3">
- <DialogHeader className="mb-4">
- <DialogDescription>{job?.Company?.label}</DialogDescription>
- <DialogTitle>{job?.JobTitle?.label}</DialogTitle>
- <DialogDescription>
+ <Card className="col-span-3">
+ <CardHeader className="mb-4">
+ {job?.Company?.label}
+ <CardTitle>{job?.JobTitle?.label}</CardTitle>
+ <CardDescription>
{job?.Location?.label} - {job?.jobType}
- </DialogDescription>
- </DialogHeader>
- <h3>
+ </CardDescription>
+ </CardHeader>
+ <h3 className="ml-4">
{new Date() > job.dueDate && job.Status?.value === "draft" ? (
<Badge className="bg-red-500">Expired</Badge>
) : (
@@ -63,7 +52,7 @@ function JobDetails({ jobId }: { jobId: string }) {
</span>
</h3>
{job.jobUrl && (
- <div className="my-3">
+ <div className="my-3 ml-4">
<span className="font-semibold mr-2">Job URL:</span>
<a
href={formatUrl(job.jobUrl)}
@@ -74,17 +63,11 @@ function JobDetails({ jobId }: { jobId: string }) {
</a>
</div>
)}
- <div className="my-4">
+ <div className="my-4 ml-4">
<TipTapContentViewer content={job?.description} />
</div>
- <DialogFooter>
- <DialogClose>
- <Button variant="outline" className="mt-2 md:mt-0 w-full">
- Cancel
- </Button>
- </DialogClose>
- </DialogFooter>
- </div>
+ <CardFooter></CardFooter>
+ </Card>
)}
</>
);
diff --git a/src/components/myjobs/MyJobsTable.tsx b/src/components/myjobs/MyJobsTable.tsx
index f4f05ba..b3047c1 100644
--- a/src/components/myjobs/MyJobsTable.tsx
+++ b/src/components/myjobs/MyJobsTable.tsx
@@ -34,8 +34,6 @@ import {
import { Button, buttonVariants } from "../ui/button";
import { useState } from "react";
import { TablePagination } from "../TablePagination";
-import { Dialog, DialogContent, DialogTrigger } from "../ui/dialog";
-import JobDetails from "./JobDetails";
import {
AlertDialog,
AlertDialogAction,
@@ -47,6 +45,8 @@ import {
AlertDialogTitle,
} from "../ui/alert-dialog";
import { JobResponse, JobStatus } from "@/models/job.model";
+import Link from "next/link";
+import { useRouter } from "next/navigation";
type MyJobsTableProps = {
jobs: JobResponse[];
@@ -73,17 +73,14 @@ function MyJobsTable({
editJob,
onChangeJobStatus,
}: MyJobsTableProps) {
- 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);
-
+ const router = useRouter();
const viewJobDetails = (jobId: string) => {
- setCurJobId(jobId);
- setDialogOpen(true);
+ router.push(`/dashboard/myjobs/${jobId}`);
};
const onDeleteJob = (jobId: string) => {
@@ -128,9 +125,11 @@ function MyJobsTable({
</TableCell>
<TableCell
className="font-medium cursor-pointer"
- onClick={() => viewJobDetails(job?.id)}
+ // onClick={() => viewJobDetails(job?.id)}
>
- {job.JobTitle?.label}
+ <Link href={`/dashboard/myjobs/${job?.id}`}>
+ {job.JobTitle?.label}
+ </Link>
</TableCell>
<TableCell className="font-medium">
{job.Company?.label}
@@ -244,12 +243,6 @@ function MyJobsTable({
})}
</TableBody>
</Table>
- <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
- <DialogTrigger asChild></DialogTrigger>
- <DialogContent className="lg:max-w-screen-lg lg:max-h-screen overflow-y-scroll">
- <JobDetails jobId={curJobId} />
- </DialogContent>
- </Dialog>
<div className="text-xs text-muted-foreground">
Showing{" "}
<strong>