import { useMutation } from "@apollo/client/react"; import { Button, Card, Form, InputNumber, Popover, Select } from "antd"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { UPDATE_JOB } from "../../graphql/jobs.queries"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; 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 mapDispatchToProps = (dispatch) => ({ insertAuditTrail: ({ jobid, operation, type }) => dispatch(insertAuditTrail({ jobid, operation, type })) }); export default connect(mapStateToProps, mapDispatchToProps)(LaborAllocationsAdjustmentEdit); export function LaborAllocationsAdjustmentEdit({ insertAuditTrail, jobId, mod_lbr_ty, adjustments, children, refetchQueryNames }) { const [loading, setLoading] = useState(false); const [open, setOpen] = useState(false); const [updateAdjustments] = useMutation(UPDATE_JOB); const [form] = Form.useForm(); const notification = useNotification(); const { t } = useTranslation(); const handleFinish = async (values) => { setLoading(true); const result = await updateAdjustments({ variables: { jobId: jobId, job: { lbr_adjustments: { ...adjustments, [values.mod_lbr_ty]: values.hours } } }, ...(refetchQueryNames ? { refetchQueries: refetchQueryNames } : {}) }); if (result.errors) { notification.error({ title: t("jobs.errors.saving", { message: JSON.stringify(result.errors) }) }); } else { notification.success({ title: t("jobs.successes.save") }); insertAuditTrail({ jobid: jobId, operation: AuditTrailMapping.jobmodifylbradj({ mod_lbr_ty: values.mod_lbr_ty, hours: values.hours - ((adjustments && adjustments[mod_lbr_ty]) || 0).toFixed(1) }), type: "jobmodifylbradj" }); } setLoading(false); setOpen(false); }; const overlay = ( {t("joblines.fields.lbr_types.LAA")} {t("joblines.fields.lbr_types.LAB")} {t("joblines.fields.lbr_types.LAD")} {t("joblines.fields.lbr_types.LAE")} {t("joblines.fields.lbr_types.LAF")} {t("joblines.fields.lbr_types.LAG")} {t("joblines.fields.lbr_types.LAM")} {t("joblines.fields.lbr_types.LAR")} {t("joblines.fields.lbr_types.LAS")} {t("joblines.fields.lbr_types.LAU")} {t("joblines.fields.lbr_types.LA1")} {t("joblines.fields.lbr_types.LA2")} {t("joblines.fields.lbr_types.LA3")} {t("joblines.fields.lbr_types.LA4")} {t("general.actions.save")} ); return ( trigger?.parentElement || document.body} open={open} onOpenChange={(vis) => setOpen(vis)} content={overlay} trigger="click" > {children} ); }