- Merge client update into test-beta
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -1,124 +1,114 @@
|
||||
import {
|
||||
Checkbox,
|
||||
Col,
|
||||
Form,
|
||||
Input,
|
||||
Row,
|
||||
Select,
|
||||
Space,
|
||||
Switch,
|
||||
Tag,
|
||||
} from "antd";
|
||||
import {Checkbox, Col, Form, Input, Row, Select, Space, Switch, Tag,} from "antd";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectNoteUpsert } from "../../redux/modals/modals.selectors";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {connect} from "react-redux";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {selectNoteUpsert} from "../../redux/modals/modals.selectors";
|
||||
import NotesPresetButton from "../notes-preset-button/notes-preset-button.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
noteUpsertModal: selectNoteUpsert,
|
||||
noteUpsertModal: selectNoteUpsert,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(NoteUpsertModalComponent);
|
||||
|
||||
export function NoteUpsertModalComponent({ form, noteUpsertModal }) {
|
||||
const { t } = useTranslation();
|
||||
const { jobId, existingNote, relatedRos } = noteUpsertModal.context;
|
||||
export function NoteUpsertModalComponent({form, noteUpsertModal}) {
|
||||
const {t} = useTranslation();
|
||||
const {jobId, existingNote, relatedRos} = noteUpsertModal.context;
|
||||
|
||||
const filteredRelatedRos = relatedRos
|
||||
? relatedRos.filter((j) => j.id !== jobId)
|
||||
: [];
|
||||
const filteredRelatedRos = relatedRos
|
||||
? relatedRos.filter((j) => j.id !== jobId)
|
||||
: [];
|
||||
|
||||
return (
|
||||
<>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={8}>
|
||||
<Form.Item
|
||||
label={t("notes.fields.critical")}
|
||||
name="critical"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Form.Item
|
||||
label={t("notes.fields.private")}
|
||||
name="private"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Form.Item
|
||||
label={t("notes.fields.type")}
|
||||
name="type"
|
||||
initialValue="general"
|
||||
>
|
||||
<Select
|
||||
options={[
|
||||
{ value: "general", label: t("notes.fields.types.general") },
|
||||
{ value: "customer", label: t("notes.fields.types.customer") },
|
||||
{ value: "shop", label: t("notes.fields.types.shop") },
|
||||
{ value: "office", label: t("notes.fields.types.office") },
|
||||
{ value: "parts", label: t("notes.fields.types.parts") },
|
||||
{ value: "paint", label: t("notes.fields.types.paint") },
|
||||
{
|
||||
value: "supplement",
|
||||
label: t("notes.fields.types.supplement"),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<NotesPresetButton form={form} />
|
||||
</Col>
|
||||
<Col span={24}>
|
||||
<Form.Item
|
||||
label={t("notes.fields.text")}
|
||||
name="text"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={8}
|
||||
placeholder={t("notes.labels.newnoteplaceholder")}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<div>
|
||||
<div>{!existingNote && t("notes.labels.addtorelatedro")}</div>
|
||||
{!existingNote &&
|
||||
filteredRelatedRos.map((j, idx) => (
|
||||
<Space key={j.id} align="center">
|
||||
<Form.Item
|
||||
noStyle
|
||||
name={["relatedros", j.id]}
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Checkbox />
|
||||
</Form.Item>
|
||||
<Tag>
|
||||
{`${j.ro_number || "N/A"}${j.clm_no ? ` | ${j.clm_no}` : ""}${
|
||||
j.status ? ` | ${j.status}` : ""
|
||||
}`}
|
||||
</Tag>
|
||||
</Space>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={8}>
|
||||
<Form.Item
|
||||
label={t("notes.fields.critical")}
|
||||
name="critical"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Switch/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Form.Item
|
||||
label={t("notes.fields.private")}
|
||||
name="private"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Switch/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Form.Item
|
||||
label={t("notes.fields.type")}
|
||||
name="type"
|
||||
initialValue="general"
|
||||
>
|
||||
<Select
|
||||
options={[
|
||||
{value: "general", label: t("notes.fields.types.general")},
|
||||
{value: "customer", label: t("notes.fields.types.customer")},
|
||||
{value: "shop", label: t("notes.fields.types.shop")},
|
||||
{value: "office", label: t("notes.fields.types.office")},
|
||||
{value: "parts", label: t("notes.fields.types.parts")},
|
||||
{value: "paint", label: t("notes.fields.types.paint")},
|
||||
{
|
||||
value: "supplement",
|
||||
label: t("notes.fields.types.supplement"),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<NotesPresetButton form={form}/>
|
||||
</Col>
|
||||
<Col span={24}>
|
||||
<Form.Item
|
||||
label={t("notes.fields.text")}
|
||||
name="text"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={8}
|
||||
placeholder={t("notes.labels.newnoteplaceholder")}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<div>
|
||||
<div>{!existingNote && t("notes.labels.addtorelatedro")}</div>
|
||||
{!existingNote &&
|
||||
filteredRelatedRos.map((j, idx) => (
|
||||
<Space key={j.id} align="center">
|
||||
<Form.Item
|
||||
noStyle
|
||||
name={["relatedros", j.id]}
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Checkbox/>
|
||||
</Form.Item>
|
||||
<Tag>
|
||||
{`${j.ro_number || "N/A"}${j.clm_no ? ` | ${j.clm_no}` : ""}${
|
||||
j.status ? ` | ${j.status}` : ""
|
||||
}`}
|
||||
</Tag>
|
||||
</Space>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,145 +1,145 @@
|
||||
import { useMutation } from "@apollo/client";
|
||||
import { Form, Modal, notification } from "antd";
|
||||
import React, { useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import { INSERT_NEW_NOTE, UPDATE_NOTE } from "../../graphql/notes.queries";
|
||||
import { insertAuditTrail } from "../../redux/application/application.actions";
|
||||
import { toggleModalVisible } from "../../redux/modals/modals.actions";
|
||||
import { selectNoteUpsert } from "../../redux/modals/modals.selectors";
|
||||
import { selectCurrentUser } from "../../redux/user/user.selectors";
|
||||
import {useMutation} from "@apollo/client";
|
||||
import {Form, Modal, notification} from "antd";
|
||||
import React, {useEffect} from "react";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {connect} from "react-redux";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {logImEXEvent} from "../../firebase/firebase.utils";
|
||||
import {INSERT_NEW_NOTE, UPDATE_NOTE} from "../../graphql/notes.queries";
|
||||
import {insertAuditTrail} from "../../redux/application/application.actions";
|
||||
import {toggleModalVisible} from "../../redux/modals/modals.actions";
|
||||
import {selectNoteUpsert} from "../../redux/modals/modals.selectors";
|
||||
import {selectCurrentUser} from "../../redux/user/user.selectors";
|
||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||
import NoteUpsertModalComponent from "./note-upsert-modal.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
currentUser: selectCurrentUser,
|
||||
noteUpsertModal: selectNoteUpsert,
|
||||
currentUser: selectCurrentUser,
|
||||
noteUpsertModal: selectNoteUpsert,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
toggleModalVisible: () => dispatch(toggleModalVisible("noteUpsert")),
|
||||
insertAuditTrail: ({ jobid, operation }) =>
|
||||
dispatch(insertAuditTrail({ jobid, operation })),
|
||||
toggleModalVisible: () => dispatch(toggleModalVisible("noteUpsert")),
|
||||
insertAuditTrail: ({jobid, operation}) =>
|
||||
dispatch(insertAuditTrail({jobid, operation})),
|
||||
});
|
||||
|
||||
export function NoteUpsertModalContainer({
|
||||
currentUser,
|
||||
noteUpsertModal,
|
||||
toggleModalVisible,
|
||||
insertAuditTrail,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [insertNote] = useMutation(INSERT_NEW_NOTE);
|
||||
const [updateNote] = useMutation(UPDATE_NOTE);
|
||||
currentUser,
|
||||
noteUpsertModal,
|
||||
toggleModalVisible,
|
||||
insertAuditTrail,
|
||||
}) {
|
||||
const {t} = useTranslation();
|
||||
const [insertNote] = useMutation(INSERT_NEW_NOTE);
|
||||
const [updateNote] = useMutation(UPDATE_NOTE);
|
||||
|
||||
const { visible, context, actions } = noteUpsertModal;
|
||||
const { jobId, existingNote, text } = context;
|
||||
const { refetch } = actions;
|
||||
const {open, context, actions} = noteUpsertModal;
|
||||
const {jobId, existingNote, text} = context;
|
||||
const {refetch} = actions;
|
||||
|
||||
const [form] = Form.useForm();
|
||||
const [form] = Form.useForm();
|
||||
|
||||
useEffect(() => {
|
||||
//Required to prevent infinite looping.
|
||||
if (existingNote && visible) {
|
||||
form.setFieldsValue(existingNote);
|
||||
} else if (!existingNote && visible) {
|
||||
form.resetFields();
|
||||
useEffect(() => {
|
||||
//Required to prevent infinite looping.
|
||||
if (existingNote && open) {
|
||||
form.setFieldsValue(existingNote);
|
||||
} else if (!existingNote && open) {
|
||||
form.resetFields();
|
||||
|
||||
if (text) {
|
||||
form.setFieldValue("text", text);
|
||||
}
|
||||
}
|
||||
}, [existingNote, form, visible, text]);
|
||||
if (text) {
|
||||
form.setFieldValue("text", text);
|
||||
}
|
||||
}
|
||||
}, [existingNote, form, open, text]);
|
||||
|
||||
const handleFinish = async (formValues) => {
|
||||
const { relatedros, ...values } = formValues;
|
||||
const handleFinish = async (formValues) => {
|
||||
const {relatedros, ...values} = formValues;
|
||||
|
||||
if (existingNote) {
|
||||
logImEXEvent("job_note_update");
|
||||
if (existingNote) {
|
||||
logImEXEvent("job_note_update");
|
||||
|
||||
updateNote({
|
||||
variables: {
|
||||
noteId: existingNote.id,
|
||||
note: values,
|
||||
},
|
||||
}).then((r) => {
|
||||
notification["success"]({
|
||||
message: t("notes.successes.updated"),
|
||||
});
|
||||
insertAuditTrail({
|
||||
jobid: context.jobId,
|
||||
operation: AuditTrailMapping.jobnoteupdated(),
|
||||
});
|
||||
});
|
||||
if (refetch) refetch();
|
||||
toggleModalVisible();
|
||||
} else {
|
||||
logImEXEvent("job_note_insert");
|
||||
const AdditionalNoteInserts = relatedros
|
||||
? Object.keys(relatedros).filter((key) => relatedros[key])
|
||||
: [];
|
||||
updateNote({
|
||||
variables: {
|
||||
noteId: existingNote.id,
|
||||
note: values,
|
||||
},
|
||||
}).then((r) => {
|
||||
notification["success"]({
|
||||
message: t("notes.successes.updated"),
|
||||
});
|
||||
insertAuditTrail({
|
||||
jobid: context.jobId,
|
||||
operation: AuditTrailMapping.jobnoteupdated(),
|
||||
});
|
||||
});
|
||||
if (refetch) refetch();
|
||||
toggleModalVisible();
|
||||
} else {
|
||||
logImEXEvent("job_note_insert");
|
||||
const AdditionalNoteInserts = relatedros
|
||||
? Object.keys(relatedros).filter((key) => relatedros[key])
|
||||
: [];
|
||||
|
||||
await insertNote({
|
||||
variables: {
|
||||
noteInput: [
|
||||
{ ...values, jobid: jobId, created_by: currentUser.email },
|
||||
],
|
||||
},
|
||||
refetchQueries: ["QUERY_NOTES_BY_JOB_PK"],
|
||||
});
|
||||
await insertNote({
|
||||
variables: {
|
||||
noteInput: [
|
||||
{...values, jobid: jobId, created_by: currentUser.email},
|
||||
],
|
||||
},
|
||||
refetchQueries: ["QUERY_NOTES_BY_JOB_PK"],
|
||||
});
|
||||
|
||||
if (AdditionalNoteInserts.length > 0) {
|
||||
//Insert the others.
|
||||
AdditionalNoteInserts.forEach(async (newJobId) => {
|
||||
await insertNote({
|
||||
variables: {
|
||||
noteInput: [
|
||||
{ ...values, jobid: newJobId, created_by: currentUser.email },
|
||||
],
|
||||
},
|
||||
});
|
||||
insertAuditTrail({
|
||||
jobid: newJobId,
|
||||
operation: AuditTrailMapping.jobnoteadded(),
|
||||
});
|
||||
});
|
||||
}
|
||||
if (AdditionalNoteInserts.length > 0) {
|
||||
//Insert the others.
|
||||
AdditionalNoteInserts.forEach(async (newJobId) => {
|
||||
await insertNote({
|
||||
variables: {
|
||||
noteInput: [
|
||||
{...values, jobid: newJobId, created_by: currentUser.email},
|
||||
],
|
||||
},
|
||||
});
|
||||
insertAuditTrail({
|
||||
jobid: newJobId,
|
||||
operation: AuditTrailMapping.jobnoteadded(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (refetch) refetch();
|
||||
form.resetFields();
|
||||
toggleModalVisible();
|
||||
notification["success"]({
|
||||
message: t("notes.successes.create"),
|
||||
});
|
||||
insertAuditTrail({
|
||||
jobid: context.jobId,
|
||||
operation: AuditTrailMapping.jobnoteadded(),
|
||||
});
|
||||
}
|
||||
};
|
||||
if (refetch) refetch();
|
||||
form.resetFields();
|
||||
toggleModalVisible();
|
||||
notification["success"]({
|
||||
message: t("notes.successes.create"),
|
||||
});
|
||||
insertAuditTrail({
|
||||
jobid: context.jobId,
|
||||
operation: AuditTrailMapping.jobnoteadded(),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={existingNote ? t("notes.actions.edit") : t("notes.actions.new")}
|
||||
visible={visible}
|
||||
okText={t("general.actions.save")}
|
||||
onOk={() => {
|
||||
form.submit();
|
||||
}}
|
||||
onCancel={() => {
|
||||
toggleModalVisible();
|
||||
}}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form form={form} onFinish={handleFinish} layout="vertical">
|
||||
<NoteUpsertModalComponent form={form} />
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
return (
|
||||
<Modal
|
||||
title={existingNote ? t("notes.actions.edit") : t("notes.actions.new")}
|
||||
open={open}
|
||||
okText={t("general.actions.save")}
|
||||
onOk={() => {
|
||||
form.submit();
|
||||
}}
|
||||
onCancel={() => {
|
||||
toggleModalVisible();
|
||||
}}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form form={form} onFinish={handleFinish} layout="vertical">
|
||||
<NoteUpsertModalComponent form={form}/>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(NoteUpsertModalContainer);
|
||||
|
||||
Reference in New Issue
Block a user