Prevent previously claimed tasks.

This commit is contained in:
Patrick Fic
2023-07-19 16:42:11 -07:00
parent d7a1d5bbd2
commit 756d97a9cb
6 changed files with 91 additions and 32 deletions

View File

@@ -235,7 +235,7 @@ export function PayrollLaborAllocationsTable({
> >
<Table <Table
columns={columns} columns={columns}
rowKey={(record) => `${record.cost_center} ${record.mod_lbr_ty}`} rowKey={(record) => `${record.employeeid} ${record.mod_lbr_ty}`}
pagination={false} pagination={false}
onChange={handleTableChange} onChange={handleTableChange}
dataSource={totals} dataSource={totals}

View File

@@ -1,14 +1,12 @@
import { import {
Alert, Alert,
Checkbox,
Col, Col,
Form, Form,
Radio, Radio,
Row, Row,
Select,
Skeleton, Skeleton,
Space, Space,
Table, Spin,
Typography, Typography,
} from "antd"; } from "antd";
import React from "react"; import React from "react";
@@ -16,10 +14,8 @@ import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors"; import { selectBodyshop } from "../../redux/user/user.selectors";
import EmployeeTeamSearchSelectComponent from "../employee-team-search-select/employee-team-search-select.component";
import JobSearchSelectComponent from "../job-search-select/job-search-select.component";
import ReadOnlyFormItemComponent from "../form-items-formatted/read-only-form-item.component"; import ReadOnlyFormItemComponent from "../form-items-formatted/read-only-form-item.component";
import LayoutFormRow from "../layout-form-row/layout-form-row.component"; import JobSearchSelectComponent from "../job-search-select/job-search-select.component";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser //currentUser: selectCurrentUser
@@ -33,7 +29,12 @@ export default connect(
mapDispatchToProps mapDispatchToProps
)(TimeTicketTaskModalComponent); )(TimeTicketTaskModalComponent);
export function TimeTicketTaskModalComponent({ bodyshop, form, loading }) { export function TimeTicketTaskModalComponent({
bodyshop,
form,
loading,
completedTasks,
}) {
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
@@ -57,13 +58,18 @@ export function TimeTicketTaskModalComponent({ bodyshop, form, loading }) {
</Form.Item> </Form.Item>
<Space wrap> <Space wrap>
<Form.Item name="task" label={t("timetickets.labels.task")}> <Form.Item name="task" label={t("timetickets.labels.task")}>
<Radio.Group {loading ? (
optionType="button" <Spin />
options={bodyshop.md_tasks_presets.presets.map((preset) => ({ ) : (
value: preset.name, <Radio.Group
label: preset.name, optionType="button"
}))} options={bodyshop.md_tasks_presets.presets.map((preset) => ({
/> value: preset.name,
label: preset.name,
disabled: completedTasks.includes(preset.name),
}))}
/>
)}
</Form.Item> </Form.Item>
<Form.Item dependencies={["task"]}> <Form.Item dependencies={["task"]}>
{() => { {() => {
@@ -75,20 +81,24 @@ export function TimeTicketTaskModalComponent({ bodyshop, form, loading }) {
if (!task) return null; if (!task) return null;
return ( return (
<table className="bill-inventory-table"> <table className="bill-inventory-table">
<tr> <tbody>
<td>{t("bodyshop.fields.md_tasks_presets.percent")}</td> <tr>
<td>{`${theTaskPreset.percent || 0}%`}</td> <td>{t("bodyshop.fields.md_tasks_presets.percent")}</td>
</tr> <td>{`${theTaskPreset.percent || 0}%`}</td>
<tr> </tr>
<td>{t("bodyshop.fields.md_tasks_presets.hourstype")}</td> <tr>
<td>{theTaskPreset.hourstype.join(", ")}</td> <td>
</tr> {t("bodyshop.fields.md_tasks_presets.hourstype")}
<tr> </td>
<td> <td>{theTaskPreset.hourstype.join(", ")}</td>
{t("bodyshop.fields.md_tasks_presets.nextstatus")} </tr>
</td> <tr>
<td>{theTaskPreset.nextstatus}</td> <td>
</tr> {t("bodyshop.fields.md_tasks_presets.nextstatus")}
</td>
<td>{theTaskPreset.nextstatus}</td>
</tr>
</tbody>
</table> </table>
); );
}} }}

View File

@@ -1,4 +1,4 @@
import React, { useState } from "react"; import React, { useCallback, useEffect, useState } from "react";
import { Form, Modal, notification } from "antd"; import { Form, Modal, notification } from "antd";
import axios from "axios"; import axios from "axios";
@@ -9,6 +9,8 @@ import { toggleModalVisible } from "../../redux/modals/modals.actions";
import { selectTimeTicketTasks } from "../../redux/modals/modals.selectors"; import { selectTimeTicketTasks } from "../../redux/modals/modals.selectors";
import { selectBodyshop } from "../../redux/user/user.selectors"; import { selectBodyshop } from "../../redux/user/user.selectors";
import TimeTicketTaskModalComponent from "./time-ticket-task-modal.component"; import TimeTicketTaskModalComponent from "./time-ticket-task-modal.component";
import { useApolloClient } from "@apollo/client";
import { QUERY_COMPLETED_TASKS } from "../../graphql/jobs.queries";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
timeTicketTasksModal: selectTimeTicketTasks, timeTicketTasksModal: selectTimeTicketTasks,
@@ -29,15 +31,41 @@ export function TimeTickeTaskModalContainer({
}) { }) {
const [form] = Form.useForm(); const [form] = Form.useForm();
const { context, visible } = timeTicketTasksModal; const { context, visible } = timeTicketTasksModal;
const [completedTasks, setCompletedTasks] = useState([]);
const { t } = useTranslation(); const { t } = useTranslation();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const client = useApolloClient();
async function handleFinish(values) { async function handleFinish(values) {
calculateTickets({ values, handleFinish: true }); calculateTickets({ values, handleFinish: true });
} }
const getCompletedTasks = useCallback(
async (jobid) => {
setLoading(true);
const { data } = await client.query({
query: QUERY_COMPLETED_TASKS,
variables: { jobid },
});
setCompletedTasks(data.jobs_by_pk.completed_tasks || []);
setLoading(false);
},
[client]
);
useEffect(() => {
if (visible) {
form.setFieldsValue({ ...context, task: null, timetickets: null });
if (context.jobid) {
getCompletedTasks(context.jobid);
}
}
}, [context.jobid, visible, getCompletedTasks, form, context]);
async function handleValueChange(changedValues, allValues) { async function handleValueChange(changedValues, allValues) {
if (changedValues.jobid) {
getCompletedTasks(changedValues.jobid);
}
if (allValues.jobid && allValues.task) { if (allValues.jobid && allValues.task) {
calculateTickets({ values: allValues, handleFinish: false }); calculateTickets({ values: allValues, handleFinish: false });
} }
@@ -93,7 +121,11 @@ export function TimeTickeTaskModalContainer({
initialValues={context} initialValues={context}
onValuesChange={handleValueChange} onValuesChange={handleValueChange}
> >
<TimeTicketTaskModalComponent form={form} loading={loading} /> <TimeTicketTaskModalComponent
form={form}
loading={loading}
completedTasks={completedTasks}
/>
</Form> </Form>
</Modal> </Modal>
); );

View File

@@ -2196,3 +2196,12 @@ export const GET_JOB_LINE_ORDERS = gql`
} }
} }
`; `;
export const QUERY_COMPLETED_TASKS = gql`
query QUERY_COMPLETED_TASKS($jobid: uuid!) {
jobs_by_pk(id: $jobid) {
id
completed_tasks
}
}
`;

View File

@@ -1881,6 +1881,7 @@ exports.QUERY_JOB_PAYROLL_DATA = `query QUERY_JOB_PAYROLL_DATA($id: uuid!) {
rate_matd rate_matd
status status
materials materials
completed_tasks
joblines(where: { removed: { _eq: false } }){ joblines(where: { removed: { _eq: false } }){
id id
line_no line_no

View File

@@ -76,6 +76,13 @@ exports.claimtask = async function (req, res) {
(ticket) => ticket.productivehrs !== 0 (ticket) => ticket.productivehrs !== 0
), ),
}); });
const updateResult = await client.request(queries.UPDATE_JOB, {
jobId: job.id,
job: {
completed_tasks: [...job.completed_tasks, task],
},
});
console.log("🚀 ~ file: claim-task.js:85 ~ updateResult:", updateResult)
} }
res.json(ticketsToInsert); res.json(ticketsToInsert);
} catch (error) { } catch (error) {