- Merge client update into test-beta
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -1,115 +1,116 @@
|
||||
import { notification, Select } from "antd";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useMutation } from "@apollo/client";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { UPDATE_JOB_LINE } from "../../graphql/jobs-lines.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import {notification, Select} from "antd";
|
||||
import React, {useEffect, useState} from "react";
|
||||
import {useMutation} from "@apollo/client";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {connect} from "react-redux";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {UPDATE_JOB_LINE} from "../../graphql/jobs-lines.queries";
|
||||
import {selectBodyshop} from "../../redux/user/user.selectors";
|
||||
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
|
||||
import { insertAuditTrail } from "../../redux/application/application.actions";
|
||||
import {insertAuditTrail} from "../../redux/application/application.actions";
|
||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
bodyshop: selectBodyshop,
|
||||
//currentUser: selectCurrentUser
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
insertAuditTrail: ({ jobid, operation }) =>
|
||||
dispatch(insertAuditTrail({ jobid, operation })),
|
||||
insertAuditTrail: ({jobid, operation}) =>
|
||||
dispatch(insertAuditTrail({jobid, operation})),
|
||||
});
|
||||
|
||||
export function JoblineTeamAssignment({
|
||||
bodyshop,
|
||||
jobline,
|
||||
disabled,
|
||||
jobId,
|
||||
insertAuditTrail,
|
||||
}) {
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [assignedTeam, setAssignedTeam] = useState(jobline.assigned_team);
|
||||
const [updateJob] = useMutation(UPDATE_JOB_LINE);
|
||||
const { t } = useTranslation();
|
||||
bodyshop,
|
||||
jobline,
|
||||
disabled,
|
||||
jobId,
|
||||
insertAuditTrail,
|
||||
}) {
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [assignedTeam, setAssignedTeam] = useState(jobline.assigned_team);
|
||||
const [updateJob] = useMutation(UPDATE_JOB_LINE);
|
||||
const {t} = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
if (editing) setAssignedTeam(jobline.assigned_team);
|
||||
}, [editing, jobline.assigned_team]);
|
||||
useEffect(() => {
|
||||
if (editing) setAssignedTeam(jobline.assigned_team);
|
||||
}, [editing, jobline.assigned_team]);
|
||||
|
||||
const handleChange = (e) => {
|
||||
setAssignedTeam(e);
|
||||
};
|
||||
const handleChange = (e) => {
|
||||
setAssignedTeam(e);
|
||||
};
|
||||
|
||||
const handleSave = async (e) => {
|
||||
setLoading(true);
|
||||
const result = await updateJob({
|
||||
variables: {
|
||||
lineId: jobline.id,
|
||||
line: { assigned_team: assignedTeam },
|
||||
},
|
||||
});
|
||||
const handleSave = async (e) => {
|
||||
setLoading(true);
|
||||
const result = await updateJob({
|
||||
variables: {
|
||||
lineId: jobline.id,
|
||||
line: {assigned_team: assignedTeam},
|
||||
},
|
||||
});
|
||||
|
||||
if (!!!result.errors) {
|
||||
notification["success"]({ message: t("joblines.successes.saved") });
|
||||
//insert the audit trail here.
|
||||
const teamName = bodyshop.employee_teams.find(
|
||||
(et) => et.id === assignedTeam
|
||||
)?.name;
|
||||
insertAuditTrail({
|
||||
jobid: jobId,
|
||||
operation: AuditTrailMapping.assignedlinehours(
|
||||
teamName,
|
||||
jobline.mod_lb_hrs
|
||||
),
|
||||
});
|
||||
} else {
|
||||
notification["error"]({
|
||||
message: t("joblines.errors.saving", {
|
||||
error: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
setEditing(false);
|
||||
};
|
||||
if (!!!result.errors) {
|
||||
notification["success"]({message: t("joblines.successes.saved")});
|
||||
//insert the audit trail here.
|
||||
const teamName = bodyshop.employee_teams.find(
|
||||
(et) => et.id === assignedTeam
|
||||
)?.name;
|
||||
insertAuditTrail({
|
||||
jobid: jobId,
|
||||
operation: AuditTrailMapping.assignedlinehours(
|
||||
teamName,
|
||||
jobline.mod_lb_hrs
|
||||
),
|
||||
});
|
||||
} else {
|
||||
notification["error"]({
|
||||
message: t("joblines.errors.saving", {
|
||||
error: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
setEditing(false);
|
||||
};
|
||||
|
||||
if (editing)
|
||||
return (
|
||||
<div>
|
||||
<LoadingSpinner loading={loading}>
|
||||
<Select
|
||||
autoFocus
|
||||
allowClear
|
||||
dropdownMatchSelectWidth={100}
|
||||
value={assignedTeam}
|
||||
onSelect={handleChange}
|
||||
onBlur={handleSave}
|
||||
onClear={() => handleChange(null)}
|
||||
>
|
||||
{Object.values(bodyshop.employee_teams).map((s, idx) => (
|
||||
<Select.Option key={idx} value={s.id}>
|
||||
{s.name}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</LoadingSpinner>
|
||||
</div>
|
||||
if (editing)
|
||||
return (
|
||||
<div>
|
||||
<LoadingSpinner loading={loading}>
|
||||
<Select
|
||||
autoFocus
|
||||
allowClear
|
||||
dropdownMatchSelectWidth={100}
|
||||
value={assignedTeam}
|
||||
onSelect={handleChange}
|
||||
onBlur={handleSave}
|
||||
onClear={() => handleChange(null)}
|
||||
>
|
||||
{Object.values(bodyshop.employee_teams).map((s, idx) => (
|
||||
<Select.Option key={idx} value={s.id}>
|
||||
{s.name}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</LoadingSpinner>
|
||||
</div>
|
||||
);
|
||||
|
||||
const team = bodyshop.employee_teams.find(
|
||||
(tm) => tm.id === jobline.assigned_team
|
||||
);
|
||||
|
||||
const team = bodyshop.employee_teams.find(
|
||||
(tm) => tm.id === jobline.assigned_team
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{ width: "100%", minHeight: "1rem", cursor: "pointer" }}
|
||||
onClick={() => !disabled && setEditing(true)}
|
||||
>
|
||||
{team?.name}
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div
|
||||
style={{width: "100%", minHeight: "1rem", cursor: "pointer"}}
|
||||
onClick={() => !disabled && setEditing(true)}
|
||||
>
|
||||
{team?.name}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(JoblineTeamAssignment);
|
||||
|
||||
Reference in New Issue
Block a user