added refresh Manage Job form whenever closing after editing and creating job
This commit is contained in:
parent
c311324bad
commit
d342550b0f
@ -34,6 +34,7 @@ const Jobs = () => {
|
|||||||
setSelectedJob,
|
setSelectedJob,
|
||||||
setSelectedProject,
|
setSelectedProject,
|
||||||
setManageJob,
|
setManageJob,
|
||||||
|
manageJob,
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@ -20,8 +20,10 @@ import {
|
|||||||
AppFormProvider,
|
AppFormProvider,
|
||||||
useAppForm,
|
useAppForm,
|
||||||
} from "../../hooks/appHooks/useAppForm";
|
} from "../../hooks/appHooks/useAppForm";
|
||||||
|
import { useServiceProjectJobContext } from "./Jobs";
|
||||||
|
|
||||||
const ManageJob = ({ Job }) => {
|
const ManageJob = ({ Job }) => {
|
||||||
|
const { manageJob, setManageJob } = useServiceProjectJobContext();
|
||||||
const methods = useAppForm({
|
const methods = useAppForm({
|
||||||
resolver: zodResolver(jobSchema),
|
resolver: zodResolver(jobSchema),
|
||||||
defaultValues: defaultJobValue,
|
defaultValues: defaultJobValue,
|
||||||
@ -53,8 +55,7 @@ const ManageJob = ({ Job }) => {
|
|||||||
isLoading: isJobLoading,
|
isLoading: isJobLoading,
|
||||||
isError: isJobError,
|
isError: isJobError,
|
||||||
error: jobError,
|
error: jobError,
|
||||||
} = useServiceProjectJobDetails(Job);
|
} = useServiceProjectJobDetails(manageJob.jobId);
|
||||||
// const {} = useSer
|
|
||||||
|
|
||||||
const { mutate: CreateJob, isPending } = useCreateServiceProjectJob(() => {
|
const { mutate: CreateJob, isPending } = useCreateServiceProjectJob(() => {
|
||||||
reset();
|
reset();
|
||||||
@ -72,18 +73,23 @@ const ManageJob = ({ Job }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!JobData || !Job) return;
|
if (manageJob.jobId && JobData) {
|
||||||
const assignedEmployees = (JobData.assignees || []).map((e) => e.id);
|
console.log("freshed data");
|
||||||
reset({
|
const assignedEmployees = (JobData.assignees || []).map((e) => e.id);
|
||||||
title: JobData.title ?? "",
|
reset({
|
||||||
description: JobData.description ?? "",
|
title: JobData.title ?? "",
|
||||||
projectId: JobData.project.id ?? "",
|
description: JobData.description ?? "",
|
||||||
assignees: assignedEmployees,
|
projectId: JobData.project.id ?? "",
|
||||||
startDate: JobData.startDate ?? null,
|
assignees: assignedEmployees,
|
||||||
dueDate: JobData.dueDate ?? null,
|
startDate: JobData.startDate ?? null,
|
||||||
tags: JobData.tags ?? [],
|
dueDate: JobData.dueDate ?? null,
|
||||||
});
|
tags: JobData.tags ?? [],
|
||||||
}, [JobData]);
|
});
|
||||||
|
}
|
||||||
|
if (!manageJob.jobId) {
|
||||||
|
reset(defaultJobValue);
|
||||||
|
}
|
||||||
|
}, [JobData, manageJob]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container">
|
<div className="container">
|
||||||
@ -133,7 +139,7 @@ const ManageJob = ({ Job }) => {
|
|||||||
minDate={watch("startDate")}
|
minDate={watch("startDate")}
|
||||||
name="dueDate"
|
name="dueDate"
|
||||||
className="w-full"
|
className="w-full"
|
||||||
size="md"
|
size="md"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12 col-md-6 mb-2 mb-md-4">
|
<div className="col-12 col-md-6 mb-2 mb-md-4">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user