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: AddExperience component

Khuram Niazfe53df34f562
diff --git a/src/components/profile/AddEducation.tsx b/src/components/profile/AddEducation.tsx
index e3b1d1b..98cac7e 100644
--- a/src/components/profile/AddEducation.tsx
+++ b/src/components/profile/AddEducation.tsx
@@ -38,7 +38,6 @@ type AddEducationProps = {
dialogOpen: boolean;
setDialogOpen: (e: boolean) => void;
educationToEdit?: ResumeSection;
- resetEducationToEdit: () => void;
};
function AddEducation({
@@ -47,7 +46,6 @@ function AddEducation({
dialogOpen,
setDialogOpen,
educationToEdit,
- resetEducationToEdit,
}: AddEducationProps) {
const pageTitle = educationToEdit ? "Edit Education" : "Add Education";
const [isPending, startTransition] = useTransition();
@@ -92,19 +90,13 @@ function AddEducation({
} else {
reset(
{
+ resumeId,
sectionId,
},
{ keepDefaultValues: true }
);
- resetEducationToEdit();
}
- }, [
- getLocationData,
- educationToEdit,
- sectionId,
- reset,
- resetEducationToEdit,
- ]);
+ }, [getLocationData, educationToEdit, resumeId, sectionId, reset]);
const onDegreeCompleted = (completed: boolean) => {
if (completed) {
diff --git a/src/components/profile/AddExperience.tsx b/src/components/profile/AddExperience.tsx
index 6660e84..2565621 100644
--- a/src/components/profile/AddExperience.tsx
+++ b/src/components/profile/AddExperience.tsx
@@ -40,7 +40,6 @@ type AddExperienceProps = {
dialogOpen: boolean;
setDialogOpen: (e: boolean) => void;
experienceToEdit?: ResumeSection;
- resetExperienceToEdit: () => void;
};
function AddExperience({
@@ -49,7 +48,6 @@ function AddExperience({
dialogOpen,
setDialogOpen,
experienceToEdit,
- resetExperienceToEdit,
}: AddExperienceProps) {
const [companies, setCompanies] = useState<Company[]>([]);
const [locations, setLocations] = useState<JobLocation[]>([]);
@@ -75,41 +73,45 @@ function AddExperience({
},
});
- const { setValue, watch, reset, formState, resetField, clearErrors } = form;
+ const { watch, reset, formState, resetField } = form;
const currentJobValue = watch("currentJob");
- const resetForm = useCallback(() => {
- reset();
- resetExperienceToEdit();
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
-
useEffect(() => {
getTitleCompanyAndLocationData();
if (experienceToEdit) {
- clearErrors();
const experience: WorkExperience =
experienceToEdit.workExperiences?.at(0)!;
- setValue("id", experience?.id);
- setValue("title", experience?.jobTitle.id);
- setValue("company", experience?.Company.id);
- setValue("location", experience?.location.id);
- setValue("startDate", experience?.startDate);
- setValue("endDate", experience?.endDate);
- setValue("jobDescription", experience?.description);
- setValue("currentJob", !!!experience?.endDate);
+ reset(
+ {
+ id: experience?.id,
+ title: experience?.jobTitle.id,
+ company: experience?.Company.id,
+ location: experience?.location.id,
+ startDate: experience?.startDate,
+ endDate: experience?.endDate,
+ jobDescription: experience?.description,
+ currentJob: !!!experience?.endDate,
+ },
+ {
+ keepDefaultValues: true,
+ }
+ );
} else {
- resetForm();
+ reset(
+ {
+ resumeId,
+ sectionId,
+ },
+ { keepDefaultValues: true }
+ );
}
- setValue("sectionId", sectionId);
}, [
getTitleCompanyAndLocationData,
experienceToEdit,
- clearErrors,
- setValue,
+ reset,
+ resumeId,
sectionId,
- resetForm,
]);
const onSubmit = (data: z.infer<typeof AddExperienceFormSchema>) => {
diff --git a/src/components/profile/AddResumeSection.tsx b/src/components/profile/AddResumeSection.tsx
index ab41947..ee09d89 100644
--- a/src/components/profile/AddResumeSection.tsx
+++ b/src/components/profile/AddResumeSection.tsx
@@ -157,7 +157,6 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
dialogOpen={experienceDialogOpen}
setDialogOpen={setExperienceDialogOpen}
experienceToEdit={experienceToEdit!}
- resetExperienceToEdit={resetExperienceToEdit}
/>
<AddEducation
resumeId={resume?.id}
@@ -165,7 +164,6 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
dialogOpen={educationDialogOpen}
setDialogOpen={setEducationDialogOpen}
educationToEdit={educationToEdit!}
- resetEducationToEdit={resetEducationToEdit}
/>
</>
);