Compare commits
No commits in common. "8de1230f791b2842eedbc98a7dd4ab7837873b75" and "70ed617b9b5b8a3f10d373288b96e8f57cac6736" have entirely different histories.
8de1230f79
...
70ed617b9b
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect } from "react";
|
||||||
import Breadcrumb from "../common/Breadcrumb";
|
import Breadcrumb from "../common/Breadcrumb";
|
||||||
import Label from "../common/Label";
|
import Label from "../common/Label";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
@ -8,7 +8,6 @@ import {
|
|||||||
useJobTags,
|
useJobTags,
|
||||||
useServiceProjectJobDetails,
|
useServiceProjectJobDetails,
|
||||||
useServiceProjects,
|
useServiceProjects,
|
||||||
useUpdateServiceProjectJob,
|
|
||||||
} from "../../hooks/useServiceProject";
|
} from "../../hooks/useServiceProject";
|
||||||
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
||||||
import DatePicker from "../common/DatePicker";
|
import DatePicker from "../common/DatePicker";
|
||||||
@ -22,11 +21,9 @@ import {
|
|||||||
useAppForm,
|
useAppForm,
|
||||||
} from "../../hooks/appHooks/useAppForm";
|
} from "../../hooks/appHooks/useAppForm";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
|
|
||||||
const ManageJob = ({ Job }) => {
|
const ManageJob = ({ Job }) => {
|
||||||
const { projectId } = useParams();
|
const { projectId } = useParams();
|
||||||
const dispatch = useDispatch()
|
|
||||||
const methods = useAppForm({
|
const methods = useAppForm({
|
||||||
resolver: zodResolver(jobSchema),
|
resolver: zodResolver(jobSchema),
|
||||||
defaultValues: defaultJobValue,
|
defaultValues: defaultJobValue,
|
||||||
@ -55,62 +52,8 @@ const ManageJob = ({ Job }) => {
|
|||||||
const { mutate: CreateJob, isPending } = useCreateServiceProjectJob(() => {
|
const { mutate: CreateJob, isPending } = useCreateServiceProjectJob(() => {
|
||||||
reset();
|
reset();
|
||||||
});
|
});
|
||||||
const { mutate: UpdateJob, isPending: Updating } = useUpdateServiceProjectJob(
|
|
||||||
() => { dispatch()}
|
|
||||||
);
|
|
||||||
const onSubmit = (formData) => {
|
const onSubmit = (formData) => {
|
||||||
if (Job) {
|
|
||||||
const existingEmployeeIds = JobData?.assignees?.map((e) => e.id) || [];
|
|
||||||
|
|
||||||
const oldEmployees = JobData.assignees.map((e) => ({
|
|
||||||
employeeId: e.id,
|
|
||||||
isActive: formData.assignees.includes(e.id),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const newEmployees = formData.assignees
|
|
||||||
.filter((id) => !existingEmployeeIds.includes(id))
|
|
||||||
.map((id) => ({
|
|
||||||
employeeId: id,
|
|
||||||
isActive: true,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const updatedEmployees = [...oldEmployees, ...newEmployees];
|
|
||||||
|
|
||||||
const payload = [
|
|
||||||
{
|
|
||||||
op: "replace",
|
|
||||||
path: "/title",
|
|
||||||
value: formData.title,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
op: "replace",
|
|
||||||
path: "/description",
|
|
||||||
value: formData.description,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
op: "replace",
|
|
||||||
path: "/startDate",
|
|
||||||
value: localToUtc(formData.startDate) ?? JobData.startDate,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
op: "replace",
|
|
||||||
path: "/dueDate",
|
|
||||||
value: localToUtc(formData.dueDate) ?? JobData.dueDate,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
op: "replace",
|
|
||||||
path: "/tags",
|
|
||||||
value: formData.tags,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
op: "replace",
|
|
||||||
path: "/assignees",
|
|
||||||
value: updatedEmployees,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
UpdateJob({ id: Job, payload });
|
|
||||||
} else {
|
|
||||||
formData.assignees = formData.assignees.map((emp) => ({
|
formData.assignees = formData.assignees.map((emp) => ({
|
||||||
employeeId: emp,
|
employeeId: emp,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
@ -119,9 +62,7 @@ const ManageJob = ({ Job }) => {
|
|||||||
formData.startDate = localToUtc(formData.startDate);
|
formData.startDate = localToUtc(formData.startDate);
|
||||||
formData.dueDate = localToUtc(formData.dueDate);
|
formData.dueDate = localToUtc(formData.dueDate);
|
||||||
formData.projectId = projectId;
|
formData.projectId = projectId;
|
||||||
|
CreateJob(formData);
|
||||||
// CreateJob(formData);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -211,13 +152,9 @@ const ManageJob = ({ Job }) => {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="btn btn-sm btn-primary"
|
className="btn btn-sm btn-primary"
|
||||||
disabled={isPending || Updating}
|
disabled={isPending}
|
||||||
>
|
>
|
||||||
{isPending || Updating
|
{isPending ? "Please wait..." : "Submit"}
|
||||||
? "Please wait..."
|
|
||||||
: Job
|
|
||||||
? "Update"
|
|
||||||
: "Submit"}
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user