Prevent previously claimed tasks.
This commit is contained in:
@@ -235,7 +235,7 @@ export function PayrollLaborAllocationsTable({
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
rowKey={(record) => `${record.cost_center} ${record.mod_lbr_ty}`}
|
||||
rowKey={(record) => `${record.employeeid} ${record.mod_lbr_ty}`}
|
||||
pagination={false}
|
||||
onChange={handleTableChange}
|
||||
dataSource={totals}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import {
|
||||
Alert,
|
||||
Checkbox,
|
||||
Col,
|
||||
Form,
|
||||
Radio,
|
||||
Row,
|
||||
Select,
|
||||
Skeleton,
|
||||
Space,
|
||||
Table,
|
||||
Spin,
|
||||
Typography,
|
||||
} from "antd";
|
||||
import React from "react";
|
||||
@@ -16,10 +14,8 @@ import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
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 LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||
import JobSearchSelectComponent from "../job-search-select/job-search-select.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
@@ -33,7 +29,12 @@ export default connect(
|
||||
mapDispatchToProps
|
||||
)(TimeTicketTaskModalComponent);
|
||||
|
||||
export function TimeTicketTaskModalComponent({ bodyshop, form, loading }) {
|
||||
export function TimeTicketTaskModalComponent({
|
||||
bodyshop,
|
||||
form,
|
||||
loading,
|
||||
completedTasks,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
@@ -57,13 +58,18 @@ export function TimeTicketTaskModalComponent({ bodyshop, form, loading }) {
|
||||
</Form.Item>
|
||||
<Space wrap>
|
||||
<Form.Item name="task" label={t("timetickets.labels.task")}>
|
||||
<Radio.Group
|
||||
optionType="button"
|
||||
options={bodyshop.md_tasks_presets.presets.map((preset) => ({
|
||||
value: preset.name,
|
||||
label: preset.name,
|
||||
}))}
|
||||
/>
|
||||
{loading ? (
|
||||
<Spin />
|
||||
) : (
|
||||
<Radio.Group
|
||||
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 dependencies={["task"]}>
|
||||
{() => {
|
||||
@@ -75,20 +81,24 @@ export function TimeTicketTaskModalComponent({ bodyshop, form, loading }) {
|
||||
if (!task) return null;
|
||||
return (
|
||||
<table className="bill-inventory-table">
|
||||
<tr>
|
||||
<td>{t("bodyshop.fields.md_tasks_presets.percent")}</td>
|
||||
<td>{`${theTaskPreset.percent || 0}%`}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{t("bodyshop.fields.md_tasks_presets.hourstype")}</td>
|
||||
<td>{theTaskPreset.hourstype.join(", ")}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{t("bodyshop.fields.md_tasks_presets.nextstatus")}
|
||||
</td>
|
||||
<td>{theTaskPreset.nextstatus}</td>
|
||||
</tr>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{t("bodyshop.fields.md_tasks_presets.percent")}</td>
|
||||
<td>{`${theTaskPreset.percent || 0}%`}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{t("bodyshop.fields.md_tasks_presets.hourstype")}
|
||||
</td>
|
||||
<td>{theTaskPreset.hourstype.join(", ")}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{t("bodyshop.fields.md_tasks_presets.nextstatus")}
|
||||
</td>
|
||||
<td>{theTaskPreset.nextstatus}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from "react";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import { Form, Modal, notification } from "antd";
|
||||
import axios from "axios";
|
||||
@@ -9,6 +9,8 @@ import { toggleModalVisible } from "../../redux/modals/modals.actions";
|
||||
import { selectTimeTicketTasks } from "../../redux/modals/modals.selectors";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import TimeTicketTaskModalComponent from "./time-ticket-task-modal.component";
|
||||
import { useApolloClient } from "@apollo/client";
|
||||
import { QUERY_COMPLETED_TASKS } from "../../graphql/jobs.queries";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
timeTicketTasksModal: selectTimeTicketTasks,
|
||||
@@ -29,15 +31,41 @@ export function TimeTickeTaskModalContainer({
|
||||
}) {
|
||||
const [form] = Form.useForm();
|
||||
const { context, visible } = timeTicketTasksModal;
|
||||
|
||||
const [completedTasks, setCompletedTasks] = useState([]);
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const client = useApolloClient();
|
||||
|
||||
async function handleFinish(values) {
|
||||
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) {
|
||||
if (changedValues.jobid) {
|
||||
getCompletedTasks(changedValues.jobid);
|
||||
}
|
||||
if (allValues.jobid && allValues.task) {
|
||||
calculateTickets({ values: allValues, handleFinish: false });
|
||||
}
|
||||
@@ -93,7 +121,11 @@ export function TimeTickeTaskModalContainer({
|
||||
initialValues={context}
|
||||
onValuesChange={handleValueChange}
|
||||
>
|
||||
<TimeTicketTaskModalComponent form={form} loading={loading} />
|
||||
<TimeTicketTaskModalComponent
|
||||
form={form}
|
||||
loading={loading}
|
||||
completedTasks={completedTasks}
|
||||
/>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1881,6 +1881,7 @@ exports.QUERY_JOB_PAYROLL_DATA = `query QUERY_JOB_PAYROLL_DATA($id: uuid!) {
|
||||
rate_matd
|
||||
status
|
||||
materials
|
||||
completed_tasks
|
||||
joblines(where: { removed: { _eq: false } }){
|
||||
id
|
||||
line_no
|
||||
|
||||
@@ -76,6 +76,13 @@ exports.claimtask = async function (req, res) {
|
||||
(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);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user