Implemented jobline upsert modal. Updated allocations display on jobline edit to include removal.

This commit is contained in:
Patrick Fic
2020-02-24 13:49:39 -08:00
parent c21f3c0098
commit 13faf47044
16 changed files with 495 additions and 49 deletions

View File

@@ -47,6 +47,53 @@
</concept_node>
</children>
</folder_node>
<folder_node>
<name>errors</name>
<children>
<concept_node>
<name>deleting</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>saving</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
</children>
</folder_node>
<folder_node>
<name>fields</name>
<children>
@@ -73,6 +120,53 @@
</concept_node>
</children>
</folder_node>
<folder_node>
<name>successes</name>
<children>
<concept_node>
<name>deleted</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>save</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
</children>
</folder_node>
</children>
</folder_node>
<folder_node>
@@ -1635,6 +1729,79 @@
<folder_node>
<name>joblines</name>
<children>
<folder_node>
<name>actions</name>
<children>
<concept_node>
<name>new</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
</children>
</folder_node>
<folder_node>
<name>errors</name>
<children>
<concept_node>
<name>creating</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>updating</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
</children>
</folder_node>
<folder_node>
<name>fields</name>
<children>
@@ -1743,6 +1910,27 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>mod_lbr_ty</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>oem_partno</name>
<definition_loaded>false</definition_loaded>
@@ -1764,6 +1952,27 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>op_code_desc</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>part_type</name>
<definition_loaded>false</definition_loaded>
@@ -1876,6 +2085,53 @@
</concept_node>
</children>
</folder_node>
<folder_node>
<name>successes</name>
<children>
<concept_node>
<name>created</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>updated</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
</children>
</folder_node>
</children>
</folder_node>
<folder_node>

View File

@@ -20,13 +20,19 @@ export default function AllocationsAssignmentContainer({
const [insertAllocation] = useMutation(INSERT_ALLOCATION);
const handleAssignment = () => {
insertAllocation({ variables: { alloc: { ...assignment } } }).then(r => {
notification["success"]({
message: t("employees.successes.save")
insertAllocation({ variables: { alloc: { ...assignment } } })
.then(r => {
notification["success"]({
message: t("allocations.successes.save")
});
visibilityState[1](false);
if (refetch) refetch();
})
.catch(error => {
notification["error"]({
message: t("employees.errors.saving", { message: error.message })
});
});
visibilityState[1](false);
if (refetch) refetch();
});
};
return (

View File

@@ -0,0 +1,19 @@
import { Icon } from "antd";
import React from "react";
import { MdRemoveCircleOutline } from "react-icons/md";
export default function AllocationsLabelComponent({ allocation, handleClick }) {
return (
<div style={{ display: "flex" }}>
<span>
{`${allocation.employee.first_name || ""} ${allocation.employee
.last_name || ""} (${allocation.hours || ""})`}
</span>
<Icon
style={{ color: "red", padding: "0px 4px" }}
component={MdRemoveCircleOutline}
onClick={handleClick}
/>
</div>
);
}

View File

@@ -0,0 +1,29 @@
import React from "react";
import { useMutation } from "react-apollo";
import { DELETE_ALLOCATION } from "../../graphql/allocations.queries";
import AllocationsLabelComponent from "./allocations-employee-label.component";
import { notification } from "antd";
import { useTranslation } from "react-i18next";
export default function AllocationsLabelContainer({ allocation, refetch }) {
const [deleteAllocation] = useMutation(DELETE_ALLOCATION);
const { t } = useTranslation();
const handleClick = e => {
e.preventDefault();
deleteAllocation({ variables: { id: allocation.id } })
.then(r => {
notification["success"]({
message: t("allocations.successes.deleted")
});
if (refetch) refetch();
})
.catch(error => {
notification["error"]({ message: t("allocations.errors.deleting") });
});
};
return (
<AllocationsLabelComponent
allocation={allocation}
handleClick={handleClick}
/>
);
}

View File

@@ -10,7 +10,7 @@ export default function ResetForm({ resetFields }) {
message={
<div>
{t("general.messages.unsavedchanges")}
<Button onClick={() => resetFields()}>
<Button style={{ marginLeft: "20px" }} onClick={() => resetFields()}>
{t("general.actions.reset")}
</Button>
</div>

View File

@@ -6,6 +6,7 @@ import CurrencyFormatter from "../../utils/CurrencyFormatter";
import { alphaSort } from "../../utils/sorters";
import AllocationsAssignmentContainer from "../allocations-assignment/allocations-assignment.container";
import AllocationsBulkAssignmentContainer from "../allocations-bulk-assignment/allocations-bulk-assignment.container";
import AllocationsEmployeeLabelContainer from "../allocations-employee-label/allocations-employee-label.container";
import PartsOrderModalContainer from "../parts-order-modal/parts-order-modal.container";
export default function JobLinesComponent({
@@ -135,16 +136,26 @@ export default function JobLinesComponent({
dataIndex: "employee",
key: "employee",
width: "10%",
sorter: (a, b) => a.act_price - b.act_price, //TODO Fix employee sorting.
sorter: (a, b) =>
alphaSort(
a.allocations[0] &&
a.allocations[0].employee.first_name +
a.allocations[0].employee.last_name,
b.allocations[0] &&
b.allocations[0].employee.first_name +
b.allocations[0].employee.last_name
),
sortOrder:
state.sortedInfo.columnKey === "employee" && state.sortedInfo.order,
render: (text, record) => (
<span>
{record.allocations && record.allocations.length > 0
? record.allocations.map(item => (
<div
<AllocationsEmployeeLabelContainer
key={item.id}
>{`${item.employee.first_name} ${item.employee.last_name} (${item.hours})`}</div>
refetch={refetch}
allocation={item}
/>
))
: null}
<AllocationsAssignmentContainer
@@ -168,8 +179,6 @@ export default function JobLinesComponent({
actions: { refetch: refetch },
context: record
});
//lineToEdit[1](record);
//editLineModalVisible[1](true);
}}
>
{t("general.actions.edit")}
@@ -224,6 +233,16 @@ export default function JobLinesComponent({
jobLines={selectedLines}
refetch={refetch}
/>
<Button
onClick={() => {
setJobLineEditContext({
actions: { refetch: refetch },
context: { jobid: jobId }
});
}}
>
{t("joblines.actions.new")}
</Button>
</div>
);
}}

View File

@@ -1,6 +1,7 @@
import { Modal, Form } from "antd";
import { Modal, Form, Input, InputNumber } from "antd";
import React from "react";
import { useTranslation } from "react-i18next";
import ResetForm from "../form-items-formatted/reset-form-item.component";
export default function JobLinesUpsertModalComponent({
visible,
@@ -11,8 +12,8 @@ export default function JobLinesUpsertModalComponent({
form
}) {
const { t } = useTranslation();
//const { getFieldDecorator, isFieldsTouched, resetFields } = form;
console.log("jobLine", jobLine);
const { getFieldDecorator, isFieldsTouched, resetFields } = form;
return (
<Modal
title={
@@ -22,11 +23,46 @@ export default function JobLinesUpsertModalComponent({
}
visible={visible}
okText={t("general.labels.save")}
onOk={handleOk}
onOk={handleSubmit}
onCancel={handleCancel}
>
{isFieldsTouched() ? <ResetForm resetFields={resetFields} /> : null}
<Form onSubmit={handleSubmit} autoComplete={"off"}>
{JSON.stringify(jobLine)}
<Form.Item label={t("joblines.fields.line_desc")}>
{getFieldDecorator("line_desc", {
initialValue: jobLine.line_desc
})(<Input name="line_desc" />)}
</Form.Item>
<Form.Item label={t("joblines.fields.oem_partno")}>
{getFieldDecorator("oem_partno", {
initialValue: jobLine.oem_partno
})(<Input name="oem_partno" />)}
</Form.Item>
<Form.Item label={t("joblines.fields.part_type")}>
{getFieldDecorator("part_type", {
initialValue: jobLine.part_type
})(<Input name="part_type" />)}
</Form.Item>
<Form.Item label={t("joblines.fields.mod_lbr_ty")}>
{getFieldDecorator("mod_lbr_ty", {
initialValue: jobLine.mod_lbr_ty
})(<Input name="mod_lbr_ty" />)}
</Form.Item>
<Form.Item label={t("joblines.fields.op_code_desc")}>
{getFieldDecorator("op_code_desc", {
initialValue: jobLine.op_code_desc
})(<Input name="op_code_desc" />)}
</Form.Item>
<Form.Item label={t("joblines.fields.mod_lb_hrs")}>
{getFieldDecorator("mod_lb_hrs", {
initialValue: jobLine.mod_lb_hrs
})(<InputNumber name="mod_lb_hrs" />)}
</Form.Item>
<Form.Item label={t("joblines.fields.act_price")}>
{getFieldDecorator("act_price", {
initialValue: jobLine.act_price
})(<InputNumber name="act_price" />)}
</Form.Item>
</Form>
</Modal>
);

View File

@@ -39,34 +39,46 @@ function JobLinesUpsertModalContainer({
});
}
if (!err) {
if (true) {
if (!jobLineEditModal.context.id) {
insertJobLine({
variables: {
//lineInput: [{ ...lineState, jobid: jobId }]
lineInput: [{ jobid: jobLineEditModal.context.jobid, ...values }]
}
}).then(r => {
if (jobLineEditModal.actions.refetch)
jobLineEditModal.actions.refetch();
toggleModalVisible();
notification["success"]({
message: t("joblines.successes.create")
})
.then(r => {
if (jobLineEditModal.actions.refetch)
jobLineEditModal.actions.refetch();
toggleModalVisible();
notification["success"]({
message: t("joblines.successes.created")
});
})
.catch(error => {
notification["error"]({
message: t("joblines.errors.creating", {
message: error.message
})
});
});
});
}
if (false) {
//Required, otherwise unable to spread in new note prop.
//delete lineState.__typename;
} else {
updateJobLine({
variables: {
//lineId: lineState.id,
//line: lineState
lineId: jobLineEditModal.context.id,
line: values
}
}).then(r => {
notification["success"]({
message: t("joblines.successes.updated")
})
.then(r => {
notification["success"]({
message: t("joblines.successes.updated")
});
})
.catch(error => {
notification["success"]({
message: t("joblines.errors.updating", {
message: error.message
})
});
});
});
if (jobLineEditModal.actions.refetch)
jobLineEditModal.actions.refetch();
toggleModalVisible();
@@ -75,9 +87,6 @@ function JobLinesUpsertModalContainer({
});
};
const handleOk = () => {
//lineState.id ? updateExistingLine() : insertNewLine();
};
const handleCancel = () => {
toggleModalVisible();
};
@@ -87,7 +96,6 @@ function JobLinesUpsertModalContainer({
visible={jobLineEditModal.visible}
jobLine={jobLineEditModal.context}
handleSubmit={handleSubmit}
handleOk={handleOk}
handleCancel={handleCancel}
form={form}
/>

View File

@@ -9,3 +9,13 @@ export const INSERT_ALLOCATION = gql`
}
}
`;
export const DELETE_ALLOCATION = gql`
mutation DELETE_ALLOCATION($id: uuid!) {
delete_allocations(where: { id: { _eq: $id } }) {
returning {
id
}
}
}
`;

View File

@@ -3,7 +3,7 @@ import ModalsActionTypes from "./modals.types";
const INITIAL_STATE = {
jobLineEdit: {
visible: false,
context: null,
context: {},
actions: {
refetch: null
}

View File

@@ -1,6 +1,6 @@
import { createStore, applyMiddleware } from "redux";
import { persistStore } from "redux-persist";
import logger from "redux-logger";
import { createLogger } from "redux-logger";
import createSagaMiddleware from "redux-saga";
import rootReducer from "./root.reducer";
import rootSaga from "./root.saga";
@@ -8,7 +8,7 @@ import rootSaga from "./root.saga";
const sagaMiddleWare = createSagaMiddleware();
const middlewares = [sagaMiddleWare];
if (process.env.NODE_ENV === "development") {
middlewares.push(logger);
middlewares.push(createLogger({ collapsed: true, diff: true }));
}
export const store = createStore(rootReducer, applyMiddleware(...middlewares));

View File

@@ -4,8 +4,16 @@
"actions": {
"assign": "Assign"
},
"errors": {
"deleting": "Error encountered while deleting allocation. {{message}}",
"saving": "Error while allocating. {{message}}"
},
"fields": {
"employee": "Allocated To"
},
"successes": {
"deleted": "Allocation deleted successfully.",
"save": "Allocated successfully. "
}
},
"appointments": {
@@ -136,13 +144,22 @@
}
},
"joblines": {
"actions": {
"new": "New Line"
},
"errors": {
"creating": "Error encountered while creating job line. {{message}}",
"updating": "Error encountered updating job line. {{message}}"
},
"fields": {
"act_price": "Actual Price",
"db_price": "Database Price",
"line_desc": "Line Description",
"line_ind": "S#",
"mod_lb_hrs": "Labor Hours",
"mod_lbr_ty": "Labor Type",
"oem_partno": "OEM Part #",
"op_code_desc": "Operation Code Description",
"part_type": "Part Type",
"status": "Status",
"unq_seq": "Seq #"
@@ -150,6 +167,10 @@
"labels": {
"edit": "Edit Line",
"new": "New Line"
},
"successes": {
"created": "Job line created successfully.",
"updated": "Job line updated successfully."
}
},
"jobs": {

View File

@@ -4,8 +4,16 @@
"actions": {
"assign": "Asignar"
},
"errors": {
"deleting": "",
"saving": ""
},
"fields": {
"employee": "Asignado a"
},
"successes": {
"deleted": "",
"save": ""
}
},
"appointments": {
@@ -136,13 +144,22 @@
}
},
"joblines": {
"actions": {
"new": ""
},
"errors": {
"creating": "",
"updating": ""
},
"fields": {
"act_price": "Precio actual",
"db_price": "Precio de base de datos",
"line_desc": "Descripción de línea",
"line_ind": "S#",
"mod_lb_hrs": "Horas laborales",
"mod_lbr_ty": "Tipo de trabajo",
"oem_partno": "OEM parte #",
"op_code_desc": "",
"part_type": "Tipo de parte",
"status": "Estado",
"unq_seq": "Seq #"
@@ -150,6 +167,10 @@
"labels": {
"edit": "Línea de edición",
"new": "Nueva línea"
},
"successes": {
"created": "",
"updated": ""
}
},
"jobs": {

View File

@@ -4,8 +4,16 @@
"actions": {
"assign": "Attribuer"
},
"errors": {
"deleting": "",
"saving": ""
},
"fields": {
"employee": "Alloué à"
},
"successes": {
"deleted": "",
"save": ""
}
},
"appointments": {
@@ -136,13 +144,22 @@
}
},
"joblines": {
"actions": {
"new": ""
},
"errors": {
"creating": "",
"updating": ""
},
"fields": {
"act_price": "Prix actuel",
"db_price": "Prix de la base de données",
"line_desc": "Description de la ligne",
"line_ind": "S#",
"mod_lb_hrs": "Heures de travail",
"mod_lbr_ty": "Type de travail",
"oem_partno": "Pièce OEM #",
"op_code_desc": "",
"part_type": "Type de pièce",
"status": "Statut",
"unq_seq": "Seq #"
@@ -150,6 +167,10 @@
"labels": {
"edit": "Ligne d'édition",
"new": "Nouvelle ligne"
},
"successes": {
"created": "",
"updated": ""
}
},
"jobs": {

View File

@@ -31,6 +31,6 @@
"concurrently": "^4.0.1",
"eslint": "^6.7.2",
"eslint-plugin-promise": "^4.2.1",
"hasura-cli": "^1.0.0-beta.10"
"hasura-cli": "^1.1.0"
}
}

View File

@@ -1950,10 +1950,10 @@ has-flag@^3.0.0:
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=
hasura-cli@^1.0.0-beta.10:
version "1.0.0-rc.1"
resolved "https://registry.yarnpkg.com/hasura-cli/-/hasura-cli-1.0.0-rc.1.tgz#481453f88e7624f468f329c75a88fbbde3407f00"
integrity sha512-w6DGAhJZ6l7U89SD6QIxYetP3/dDxJc4jEVzjMAYsueeYWQKDeGgtZBFBW1sdgAlUtRmtIa5wbiFLXuagB6JqA==
hasura-cli@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/hasura-cli/-/hasura-cli-1.1.0.tgz#a095e94c654d30354d8979602b8c0047c7b8a9e1"
integrity sha512-D1qXoYydx9Mgq7VQdCmOOvTlYhd1RcjQtn4s7pN1wb5w1ORIcDFLm1rS3w97bsx7wPRotIl0reyhc3+FDq+FFg==
dependencies:
axios "^0.19.0"
chalk "^2.4.2"