+ {csr ? (
+
+ {`${csr.first_name || ""} ${csr.last_name || ""}`}
+ {
- if (!jobRO) {
- setAssignment({ operation: "csr" });
- setVisibility(true);
- }
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ if (!jobRO) handleRemove("csr");
}}
/>
- )}
-
-
-
+
+ ) : (
+ renderAssigner("csr")
+ )}
+
+
);
}
diff --git a/client/src/components/job-employee-assignments/job-employee-assignments.container.jsx b/client/src/components/job-employee-assignments/job-employee-assignments.container.jsx
index f9b1b1fd5..3957e1035 100644
--- a/client/src/components/job-employee-assignments/job-employee-assignments.container.jsx
+++ b/client/src/components/job-employee-assignments/job-employee-assignments.container.jsx
@@ -11,9 +11,7 @@ import { insertAuditTrail } from "../../redux/application/application.actions";
import AuditTrailMapping from "../../utils/AuditTrailMappings";
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
-const mapStateToProps = createStructuredSelector({
- //currentUser: selectCurrentUser
-});
+const mapStateToProps = createStructuredSelector({});
const mapDispatchToProps = (dispatch) => ({
insertAuditTrail: ({ jobid, operation, type }) => dispatch(insertAuditTrail({ jobid, operation, type }))
});
@@ -26,55 +24,69 @@ export function JobEmployeeAssignmentsContainer({ job, refetch, insertAuditTrail
const notification = useNotification();
const handleAdd = async (assignment) => {
- setLoading(true);
const { operation, employeeid, name } = assignment;
- logImEXEvent("job_assign_employee", { operation });
+ const empAssignment = determineFieldName(operation);
- let empAssignment = determineFieldName(operation);
+ if (!job?.id || !empAssignment || !employeeid) return;
- const result = await updateJob({
- variables: { jobId: job.id, job: { [empAssignment]: employeeid } }
- });
- if (refetch) refetch();
-
- if (!result.errors) {
- insertAuditTrail({
- jobid: job.id,
- operation: AuditTrailMapping.jobassignmentchange(operation, name),
- type: "jobassignmentchange"
- });
- } else {
- notification.error({
- title: t("jobs.errors.assigning", {
- message: JSON.stringify(result.errors)
- })
- });
- }
- setLoading(false);
- };
- const handleRemove = async (operation) => {
setLoading(true);
- logImEXEvent("job_unassign_employee", { operation });
+ try {
+ logImEXEvent("job_assign_employee", { operation });
- let empAssignment = determineFieldName(operation);
- const result = await updateJob({
- variables: { jobId: job.id, job: { [empAssignment]: null } }
- });
+ const result = await updateJob({
+ variables: { jobId: job.id, job: { [empAssignment]: employeeid } }
+ });
- if (!result.errors) {
- insertAuditTrail({
- jobid: job.id,
- operation: AuditTrailMapping.jobassignmentremoved(operation),
- type: "jobassignmentremoved"
- });
- } else {
- notification.error({
- title: t("jobs.errors.assigning", {
- message: JSON.stringify(result.errors)
- })
- });
+ if (typeof refetch === "function") await refetch();
+
+ if (!result.errors) {
+ insertAuditTrail({
+ jobid: job.id,
+ operation: AuditTrailMapping.jobassignmentchange(operation, name),
+ type: "jobassignmentchange"
+ });
+ } else {
+ notification.error({
+ title: t("jobs.errors.assigning", {
+ message: JSON.stringify(result.errors)
+ })
+ });
+ }
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ const handleRemove = async (operation) => {
+ const empAssignment = determineFieldName(operation);
+ if (!job?.id || !empAssignment) return;
+
+ setLoading(true);
+ try {
+ logImEXEvent("job_unassign_employee", { operation });
+
+ const result = await updateJob({
+ variables: { jobId: job.id, job: { [empAssignment]: null } }
+ });
+
+ if (typeof refetch === "function") await refetch();
+
+ if (!result.errors) {
+ insertAuditTrail({
+ jobid: job.id,
+ operation: AuditTrailMapping.jobassignmentremoved(operation),
+ type: "jobassignmentremoved"
+ });
+ } else {
+ notification.error({
+ title: t("jobs.errors.assigning", {
+ message: JSON.stringify(result.errors)
+ })
+ });
+ }
+ } finally {
+ setLoading(false);
}
- setLoading(false);
};
return (
@@ -102,7 +114,6 @@ const determineFieldName = (operation) => {
return "employee_csr";
case "refinish":
return "employee_refinish";
-
default:
return null;
}
diff --git a/client/src/components/jobs-detail-labor/jobs-detail-labor.container.jsx b/client/src/components/jobs-detail-labor/jobs-detail-labor.container.jsx
index 95d2ca219..da751c755 100644
--- a/client/src/components/jobs-detail-labor/jobs-detail-labor.container.jsx
+++ b/client/src/components/jobs-detail-labor/jobs-detail-labor.container.jsx
@@ -4,9 +4,11 @@ import AlertComponent from "../alert/alert.component";
import JobsDetailLaborComponent from "./jobs-detail-labor.component";
export default function JobsDetailLaborContainer({ jobId, techConsole, job }) {
+ const id = jobId ?? null;
+
const { loading, error, data, refetch } = useQuery(GET_LINE_TICKET_BY_PK, {
- variables: { id: jobId },
- skip: !jobId,
+ variables: { id },
+ skip: !id,
fetchPolicy: "network-only",
nextFetchPolicy: "network-only"
});
@@ -16,7 +18,7 @@ export default function JobsDetailLaborContainer({ jobId, techConsole, job }) {
return (