added refresh Manage Job form whenever closing after editing and creating job

This commit is contained in:
pramod.mahajan 2025-11-17 13:34:04 +05:30
parent c311324bad
commit d342550b0f
2 changed files with 22 additions and 15 deletions

View File

@ -34,6 +34,7 @@ const Jobs = () => {
setSelectedJob,
setSelectedProject,
setManageJob,
manageJob,
};
return (
<>

View File

@ -20,8 +20,10 @@ import {
AppFormProvider,
useAppForm,
} from "../../hooks/appHooks/useAppForm";
import { useServiceProjectJobContext } from "./Jobs";
const ManageJob = ({ Job }) => {
const { manageJob, setManageJob } = useServiceProjectJobContext();
const methods = useAppForm({
resolver: zodResolver(jobSchema),
defaultValues: defaultJobValue,
@ -53,8 +55,7 @@ const ManageJob = ({ Job }) => {
isLoading: isJobLoading,
isError: isJobError,
error: jobError,
} = useServiceProjectJobDetails(Job);
// const {} = useSer
} = useServiceProjectJobDetails(manageJob.jobId);
const { mutate: CreateJob, isPending } = useCreateServiceProjectJob(() => {
reset();
@ -72,18 +73,23 @@ const ManageJob = ({ Job }) => {
};
useEffect(() => {
if (!JobData || !Job) return;
const assignedEmployees = (JobData.assignees || []).map((e) => e.id);
reset({
title: JobData.title ?? "",
description: JobData.description ?? "",
projectId: JobData.project.id ?? "",
assignees: assignedEmployees,
startDate: JobData.startDate ?? null,
dueDate: JobData.dueDate ?? null,
tags: JobData.tags ?? [],
});
}, [JobData]);
if (manageJob.jobId && JobData) {
console.log("freshed data");
const assignedEmployees = (JobData.assignees || []).map((e) => e.id);
reset({
title: JobData.title ?? "",
description: JobData.description ?? "",
projectId: JobData.project.id ?? "",
assignees: assignedEmployees,
startDate: JobData.startDate ?? null,
dueDate: JobData.dueDate ?? null,
tags: JobData.tags ?? [],
});
}
if (!manageJob.jobId) {
reset(defaultJobValue);
}
}, [JobData, manageJob]);
return (
<div className="container">
@ -133,7 +139,7 @@ const ManageJob = ({ Job }) => {
minDate={watch("startDate")}
name="dueDate"
className="w-full"
size="md"
size="md"
/>
</div>
<div className="col-12 col-md-6 mb-2 mb-md-4">