@@ -1,112 +1,113 @@
|
||||
import { useMutation } from "@apollo/client";
|
||||
import { notification } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import { UPDATE_JOB_ASSIGNMENTS } from "../../graphql/jobs.queries";
|
||||
import {useMutation} from "@apollo/client";
|
||||
import {notification} from "antd";
|
||||
import React, {useState} from "react";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {logImEXEvent} from "../../firebase/firebase.utils";
|
||||
import {UPDATE_JOB_ASSIGNMENTS} from "../../graphql/jobs.queries";
|
||||
import JobEmployeeAssignmentsComponent from "./job-employee-assignments.component";
|
||||
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { insertAuditTrail } from "../../redux/application/application.actions";
|
||||
import {connect} from "react-redux";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {insertAuditTrail} from "../../redux/application/application.actions";
|
||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
//currentUser: selectCurrentUser
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
insertAuditTrail: ({ jobid, operation }) =>
|
||||
dispatch(insertAuditTrail({ jobid, operation })),
|
||||
insertAuditTrail: ({jobid, operation}) =>
|
||||
dispatch(insertAuditTrail({jobid, operation})),
|
||||
});
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(JobEmployeeAssignmentsContainer);
|
||||
|
||||
export function JobEmployeeAssignmentsContainer({
|
||||
job,
|
||||
refetch,
|
||||
insertAuditTrail,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [updateJob] = useMutation(UPDATE_JOB_ASSIGNMENTS);
|
||||
const [loading, setLoading] = useState(false);
|
||||
job,
|
||||
refetch,
|
||||
insertAuditTrail,
|
||||
}) {
|
||||
const {t} = useTranslation();
|
||||
const [updateJob] = useMutation(UPDATE_JOB_ASSIGNMENTS);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleAdd = async (assignment) => {
|
||||
setLoading(true);
|
||||
const { operation, employeeid, name } = assignment;
|
||||
logImEXEvent("job_assign_employee", { operation });
|
||||
const handleAdd = async (assignment) => {
|
||||
setLoading(true);
|
||||
const {operation, employeeid, name} = assignment;
|
||||
logImEXEvent("job_assign_employee", {operation});
|
||||
|
||||
let empAssignment = determineFieldName(operation);
|
||||
let empAssignment = determineFieldName(operation);
|
||||
|
||||
const result = await updateJob({
|
||||
variables: { jobId: job.id, job: { [empAssignment]: employeeid } },
|
||||
});
|
||||
if (refetch) refetch();
|
||||
const result = await updateJob({
|
||||
variables: {jobId: job.id, job: {[empAssignment]: employeeid}},
|
||||
});
|
||||
if (refetch) refetch();
|
||||
|
||||
insertAuditTrail({
|
||||
jobid: job.id,
|
||||
operation: AuditTrailMapping.jobassignmentchange(operation, name),
|
||||
});
|
||||
insertAuditTrail({
|
||||
jobid: job.id,
|
||||
operation: AuditTrailMapping.jobassignmentchange(operation, name),
|
||||
});
|
||||
|
||||
if (!!result.errors) {
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.assigning", {
|
||||
message: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
const handleRemove = async (operation) => {
|
||||
setLoading(true);
|
||||
logImEXEvent("job_unassign_employee", { operation });
|
||||
if (!!result.errors) {
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.assigning", {
|
||||
message: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
const handleRemove = async (operation) => {
|
||||
setLoading(true);
|
||||
logImEXEvent("job_unassign_employee", {operation});
|
||||
|
||||
let empAssignment = determineFieldName(operation);
|
||||
const result = await updateJob({
|
||||
variables: { jobId: job.id, job: { [empAssignment]: null } },
|
||||
});
|
||||
let empAssignment = determineFieldName(operation);
|
||||
const result = await updateJob({
|
||||
variables: {jobId: job.id, job: {[empAssignment]: null}},
|
||||
});
|
||||
|
||||
if (!!result.errors) {
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.assigning", {
|
||||
message: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
insertAuditTrail({
|
||||
jobid: job.id,
|
||||
operation: AuditTrailMapping.jobassignmentremoved(operation),
|
||||
});
|
||||
setLoading(false);
|
||||
};
|
||||
if (!!result.errors) {
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.assigning", {
|
||||
message: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
insertAuditTrail({
|
||||
jobid: job.id,
|
||||
operation: AuditTrailMapping.jobassignmentremoved(operation),
|
||||
});
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<JobEmployeeAssignmentsComponent
|
||||
body={job.employee_body_rel}
|
||||
refinish={job.employee_refinish_rel}
|
||||
prep={job.employee_prep_rel}
|
||||
csr={job.employee_csr_rel}
|
||||
handleAdd={handleAdd}
|
||||
handleRemove={handleRemove}
|
||||
loading={loading}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div>
|
||||
<JobEmployeeAssignmentsComponent
|
||||
body={job.employee_body_rel}
|
||||
refinish={job.employee_refinish_rel}
|
||||
prep={job.employee_prep_rel}
|
||||
csr={job.employee_csr_rel}
|
||||
handleAdd={handleAdd}
|
||||
handleRemove={handleRemove}
|
||||
loading={loading}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const determineFieldName = (operation) => {
|
||||
switch (operation) {
|
||||
case "body":
|
||||
return "employee_body";
|
||||
case "prep":
|
||||
return "employee_prep";
|
||||
case "csr":
|
||||
return "employee_csr";
|
||||
case "refinish":
|
||||
return "employee_refinish";
|
||||
switch (operation) {
|
||||
case "body":
|
||||
return "employee_body";
|
||||
case "prep":
|
||||
return "employee_prep";
|
||||
case "csr":
|
||||
return "employee_csr";
|
||||
case "refinish":
|
||||
return "employee_refinish";
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user