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.

applied date conditiaonal logic

Khuram Niaz4ad967184abc
diff --git a/src/actions/dashboard.actions.ts b/src/actions/dashboard.actions.ts
index f2cc0a4..b009920 100644
--- a/src/actions/dashboard.actions.ts
+++ b/src/actions/dashboard.actions.ts
@@ -37,9 +37,7 @@ export const getJobsAppliedForPeriod = async (
const count = await prisma.job.count({
where: {
userId: user.id,
- Status: {
- value: "applied",
- },
+ applied: true,
appliedDate: {
gte: startDate,
lt: endDate,
@@ -68,9 +66,7 @@ export const getJobsAppliedThisWeek = async (): Promise<any | undefined> => {
const count = await prisma.job.count({
where: {
userId: user.id,
- Status: {
- value: "applied",
- },
+ applied: true,
appliedDate: {
gte: startOfWeek,
lt: new Date(endOfWeek.setDate(endOfWeek.getDate() + 1)), // Add 1 to include the end of the week
@@ -96,9 +92,7 @@ export const getRecentJobs = async (): Promise<any | undefined> => {
const list = await prisma.job.findMany({
where: {
userId: user.id,
- Status: {
- value: "applied",
- },
+ applied: true,
},
include: {
JobSource: true,
@@ -148,9 +142,7 @@ export const getJobsActivityForPeriod = async (): Promise<any | undefined> => {
},
where: {
userId: user.id,
- Status: {
- value: "applied",
- },
+ applied: true,
appliedDate: {
gte: sevenDaysAgo,
lte: today,
diff --git a/src/components/AddJob.tsx b/src/components/AddJob.tsx
index 8c1c6ae..d2fe796 100644
--- a/src/components/AddJob.tsx
+++ b/src/components/AddJob.tsx
@@ -43,6 +43,7 @@ import { SALARY_RANGES } from "@/lib/data/salaryRangeData";
import TiptapEditor from "./TiptapEditor";
import { Input } from "./ui/input";
import { Switch } from "./ui/switch";
+import { redirect } from "next/navigation";
type AddJobProps = {
jobStatuses: JobStatus[];
@@ -73,14 +74,15 @@ export function AddJob({
// mode: "onChange",
defaultValues: {
type: Object.keys(JOB_TYPES)[0],
- dateApplied: new Date(),
dueDate: addDays(new Date(), 3),
status: jobStatuses[0].id,
salaryRange: "1",
},
});
- const { setValue, reset } = form;
+ const { setValue, reset, watch, resetField } = form;
+
+ const appliedValue = watch("applied");
useEffect(() => {
if (editJob) {
@@ -93,13 +95,15 @@ export function AddJob({
setValue("source", editJob.JobSource.id);
setValue("status", editJob.Status.id);
setValue("dueDate", editJob.dueDate);
- setValue("dateApplied", editJob.appliedDate);
setValue("salaryRange", editJob.salaryRange);
setValue("jobDescription", editJob.description);
setValue("applied", editJob.applied);
if (editJob.jobUrl) {
setValue("jobUrl", editJob.jobUrl);
}
+ if (editJob.appliedDate) {
+ setValue("dateApplied", editJob.appliedDate);
+ }
setDialogOpen(true);
}
}, [editJob, setValue]);
@@ -109,7 +113,8 @@ export function AddJob({
const res = editJob ? await updateJob(data) : await addJob(data);
reset();
setDialogOpen(false);
- reloadJobs();
+ // reloadJobs();
+ redirect("/dashboard/myjobs");
});
toast({
variant: "success",
@@ -127,6 +132,18 @@ export function AddJob({
setDialogOpen(true);
};
+ const jobAppliedChange = (applied: boolean) => {
+ if (applied) {
+ form.getValues("status") === jobStatuses[0].id
+ ? setValue("status", jobStatuses[1].id)
+ : null;
+ setValue("dateApplied", new Date());
+ } else {
+ resetField("dateApplied");
+ setValue("status", jobStatuses[0].id);
+ }
+ };
+
return (
<>
<Button size="sm" className="h-8 gap-1" onClick={addJobForm}>
@@ -284,7 +301,10 @@ export function AddJob({
<FormItem className="flex flex-row">
<Switch
checked={field.value}
- onCheckedChange={field.onChange}
+ onCheckedChange={(a) => {
+ field.onChange(a);
+ jobAppliedChange(a);
+ }}
/>
<FormLabel className="flex items-center ml-4 mb-2">
{field.value ? "Applied" : "Not Applied"}
@@ -314,34 +334,45 @@ export function AddJob({
)}
/>
</div>
- {/* Due Date */}
- <div>
+
+ {/* Date Applied */}
+ <div className="flex flex-col">
<FormField
control={form.control}
- name="dueDate"
+ name="dateApplied"
render={({ field }) => (
<FormItem className="flex flex-col">
- <FormLabel>Due Date</FormLabel>
- <DatePicker field={field} presets={true} />
+ <FormLabel>Date Applied</FormLabel>
+ <DatePicker
+ field={field}
+ presets={false}
+ isEnabled={appliedValue}
+ />
<FormMessage />
</FormItem>
)}
/>
</div>
- {/* Date Applied */}
- <div className="flex flex-col">
+
+ {/* Due Date */}
+ <div>
<FormField
control={form.control}
- name="dateApplied"
+ name="dueDate"
render={({ field }) => (
<FormItem className="flex flex-col">
- <FormLabel>Date Applied</FormLabel>
- <DatePicker field={field} presets={false} />
+ <FormLabel>Due Date</FormLabel>
+ <DatePicker
+ field={field}
+ presets={true}
+ isEnabled={true}
+ />
<FormMessage />
</FormItem>
)}
/>
</div>
+
{/* Salary Range */}
<div>
<FormField
diff --git a/src/components/DatePicker.tsx b/src/components/DatePicker.tsx
index 73d17b8..de5a29a 100644
--- a/src/components/DatePicker.tsx
+++ b/src/components/DatePicker.tsx
@@ -26,9 +26,10 @@ import { FormControl } from "./ui/form";
interface DatePickerProps {
field: ControllerRenderProps<JobForm, any>;
presets: boolean;
+ isEnabled: boolean;
}
-export function DatePicker({ field, presets }: DatePickerProps) {
+export function DatePicker({ field, presets, isEnabled }: DatePickerProps) {
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);
return (
@@ -41,6 +42,7 @@ export function DatePicker({ field, presets }: DatePickerProps) {
"md:w-[240px] lg:w-[280px] justify-start text-left font-normal",
!field.value && "text-muted-foreground"
)}
+ disabled={!isEnabled}
>
<CalendarIcon className="mr-2 h-4 w-4" />
{field.value ? format(field.value, "PP") : <span>Pick a date</span>}
diff --git a/src/components/JobsContainer.tsx b/src/components/JobsContainer.tsx
index d3ddb22..8f6be1e 100644
--- a/src/components/JobsContainer.tsx
+++ b/src/components/JobsContainer.tsx
@@ -32,6 +32,7 @@ import {
SelectGroup,
SelectItem,
SelectLabel,
+ SelectSeparator,
SelectTrigger,
SelectValue,
} from "./ui/select";
@@ -113,7 +114,7 @@ function JobsContainer({
<SelectContent>
<SelectGroup>
<SelectLabel>Filter by</SelectLabel>
- <DropdownMenuSeparator />
+ <SelectSeparator />
<SelectItem value="none">None</SelectItem>
<SelectItem value="applied">Applied</SelectItem>
<SelectItem value="interview">Interview</SelectItem>
diff --git a/src/components/MyJobsTable.tsx b/src/components/MyJobsTable.tsx
index 840d606..d21394a 100644
--- a/src/components/MyJobsTable.tsx
+++ b/src/components/MyJobsTable.tsx
@@ -142,7 +142,7 @@ function MyJobsTable({
/>
</TableCell>
<TableCell className="hidden md:table-cell w-[120px]">
- {format(job.appliedDate, "PP")}
+ {job.appliedDate ? format(job.appliedDate, "PP") : "N/A"}
</TableCell>
<TableCell className="font-medium">
{job.JobTitle?.label}
diff --git a/src/components/Select.tsx b/src/components/Select.tsx
index fa9e9d5..c904f8f 100644
--- a/src/components/Select.tsx
+++ b/src/components/Select.tsx
@@ -22,7 +22,7 @@ function SelectFormCtrl({ label, options, field }: SelectProps) {
<>
<Select
onValueChange={field.onChange}
- defaultValue={field.value}
+ value={field.value}
name={field.name}
>
<FormControl>
diff --git a/src/models/addJobForm.schema.ts b/src/models/addJobForm.schema.ts
index fd4b29b..ac6ced5 100644
--- a/src/models/addJobForm.schema.ts
+++ b/src/models/addJobForm.schema.ts
@@ -46,7 +46,7 @@ export const AddJobFormSchema = z.object({
* z.string().datetime({ offset: true });
*/
//
- dateApplied: z.date(),
+ dateApplied: z.date().optional(),
salaryRange: z.string(),
jobDescription: z.string().min(10, {
message: "Job description must be at least 10 characters.",
diff --git a/src/models/job.model.ts b/src/models/job.model.ts
index 63cce05..7cf4932 100644
--- a/src/models/job.model.ts
+++ b/src/models/job.model.ts
@@ -8,7 +8,7 @@ export interface JobForm {
location: string;
status: string;
dueDate: Date;
- dateApplied: Date;
+ dateApplied?: Date;
salaryRange: string;
jobDescription: string;
jobUrl?: string;