Added creation of email based CSI BOD-108
This commit is contained in:
@@ -10,9 +10,12 @@ import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import AddToProduction from "./jobs-detail-header-actions.addtoproduction.util";
|
||||
import DuplicateJob from "./jobs-detail-header-actions.duplicate.util";
|
||||
import { setModalContext } from "../../redux/modals/modals.actions";
|
||||
import JobsDetaiLheaderCsi from "./jobs-detail-header-actions.csi.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
setInvoiceEnterContext: (context) =>
|
||||
@@ -29,29 +32,27 @@ export function JobsDetailHeaderActions({
|
||||
const client = useApolloClient();
|
||||
const history = useHistory();
|
||||
const statusmenu = (
|
||||
<Menu key="popovermenu">
|
||||
<Menu.Item key="cccontract">
|
||||
<Menu key='popovermenu'>
|
||||
<Menu.Item key='cccontract'>
|
||||
<Link
|
||||
to={{
|
||||
pathname: "/manage/courtesycars/contracts/new",
|
||||
state: { jobId: job.id },
|
||||
}}
|
||||
>
|
||||
}}>
|
||||
{t("menus.jobsactions.newcccontract")}
|
||||
</Link>
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
key="addtoproduction"
|
||||
key='addtoproduction'
|
||||
disabled={!!!job.converted || !!job.inproduction}
|
||||
onClick={() => AddToProduction(client, job.id, refetch)}
|
||||
>
|
||||
onClick={() => AddToProduction(client, job.id, refetch)}>
|
||||
{t("jobs.actions.addtoproduction")}
|
||||
</Menu.Item>
|
||||
<Menu.Item key="duplicatejob">
|
||||
<Menu.Item key='duplicatejob'>
|
||||
<Popconfirm
|
||||
title={t("jobs.labels.duplicateconfirm")}
|
||||
okText="Yes"
|
||||
cancelText="No"
|
||||
okText='Yes'
|
||||
cancelText='No'
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onConfirm={() =>
|
||||
DuplicateJob(
|
||||
@@ -63,13 +64,12 @@ export function JobsDetailHeaderActions({
|
||||
}
|
||||
)
|
||||
}
|
||||
getPopupContainer={(trigger) => trigger.parentNode}
|
||||
>
|
||||
getPopupContainer={(trigger) => trigger.parentNode}>
|
||||
{t("menus.jobsactions.duplicate")}
|
||||
</Popconfirm>
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
key="postinvoices"
|
||||
key='postinvoices'
|
||||
onClick={() => {
|
||||
setInvoiceEnterContext({
|
||||
actions: { refetch: refetch },
|
||||
@@ -77,23 +77,22 @@ export function JobsDetailHeaderActions({
|
||||
job: job,
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
}}>
|
||||
{t("jobs.actions.postInvoices")}
|
||||
</Menu.Item>
|
||||
<Menu.Item key="closejob">
|
||||
<Menu.Item key='closejob'>
|
||||
<Link
|
||||
to={{
|
||||
pathname: `/manage/jobs/${job.id}/close`,
|
||||
}}
|
||||
>
|
||||
}}>
|
||||
{t("menus.jobsactions.closejob")}
|
||||
</Link>
|
||||
</Menu.Item>
|
||||
<JobsDetaiLheaderCsi job={job} />
|
||||
</Menu>
|
||||
);
|
||||
return (
|
||||
<Dropdown overlay={statusmenu} key="changestatus">
|
||||
<Dropdown overlay={statusmenu} key='changestatus'>
|
||||
<Button>
|
||||
{t("general.labels.actions")} <DownCircleFilled />
|
||||
</Button>
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import { useMutation, useApolloClient } from "@apollo/react-hooks";
|
||||
import { Menu, notification } from "antd";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import {
|
||||
INSERT_CSI,
|
||||
GET_CURRENT_QUESTIONSET_ID,
|
||||
} from "../../graphql/csi.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { setEmailOptions } from "../../redux/email/email.actions";
|
||||
import { TemplateList } from "../../utils/TemplateConstants";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser'
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setEmailOptions: (e) => dispatch(setEmailOptions(e)),
|
||||
});
|
||||
|
||||
export function JobsDetailHeaderCsi({
|
||||
setEmailOptions,
|
||||
bodyshop,
|
||||
job,
|
||||
...props
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [insertCsi] = useMutation(INSERT_CSI);
|
||||
const client = useApolloClient();
|
||||
|
||||
const handleCreateCsi = async (e) => {
|
||||
console.log("e.target.key", e.key);
|
||||
|
||||
const questionSetResult = await client.query({
|
||||
query: GET_CURRENT_QUESTIONSET_ID,
|
||||
});
|
||||
|
||||
if (questionSetResult.data.csiquestions.length > 0) {
|
||||
const result = await insertCsi({
|
||||
variables: {
|
||||
csiInput: {
|
||||
jobid: job.id,
|
||||
bodyshopid: bodyshop.id,
|
||||
questionset: questionSetResult.data.csiquestions[0].id,
|
||||
relateddata: {
|
||||
job: {
|
||||
id: job.id,
|
||||
ownr_fn: job.ownr_fn,
|
||||
ro_number: job.ro_number,
|
||||
v_model_yr: job.v_model_yr,
|
||||
v_make_desc: job.v_make_desc,
|
||||
v_model_desc: job.v_model_desc,
|
||||
},
|
||||
bodyshop: {
|
||||
city: bodyshop.city,
|
||||
email: bodyshop.email,
|
||||
state: bodyshop.state,
|
||||
country: bodyshop.country,
|
||||
address1: bodyshop.address1,
|
||||
address2: bodyshop.address2,
|
||||
shopname: bodyshop.shopname,
|
||||
zip_post: bodyshop.zip_post,
|
||||
logo_img_path: bodyshop.logo_img_path,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!!!result.errors) {
|
||||
notification["success"]({ message: t("csi.successes.created") });
|
||||
} else {
|
||||
notification["error"]({
|
||||
message: t("csi.errors.creating", {
|
||||
message: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (e.key === "email")
|
||||
setEmailOptions({
|
||||
messageOptions: {
|
||||
to: job.ownr_ea,
|
||||
replyTo: bodyshop.email,
|
||||
},
|
||||
template: {
|
||||
name: TemplateList.csi_invitation.key,
|
||||
variables: {
|
||||
id: result.data.insert_csi.returning[0].id,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (e.key === "text") console.log("TODO Handling texting"); //TODO Implement texting.
|
||||
} else {
|
||||
notification["error"]({
|
||||
message: t("csi.errors.notconfigured"),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Menu.SubMenu title={t("jobs.actions.sendcsi")} {...props}>
|
||||
<Menu.Item
|
||||
onClick={handleCreateCsi}
|
||||
key='email'
|
||||
disabled={!!!job.ownr_ea}>
|
||||
{t("general.labels.email")}
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
onClick={handleCreateCsi}
|
||||
key='text'
|
||||
disabled={!!!job.ownr_ph1}>
|
||||
{t("general.labels.text")}
|
||||
</Menu.Item>
|
||||
</Menu.SubMenu>
|
||||
);
|
||||
}
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(JobsDetailHeaderCsi);
|
||||
Reference in New Issue
Block a user