CSI updates.
This commit is contained in:
@@ -14,6 +14,11 @@ import { TemplateList } from "../../utils/TemplateConstants";
|
|||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
import { DateTimeFormatter } from "../../utils/DateFormatter";
|
import { DateTimeFormatter } from "../../utils/DateFormatter";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
import parsePhoneNumber from "libphonenumber-js";
|
||||||
|
import {
|
||||||
|
openChatByPhone,
|
||||||
|
setMessage,
|
||||||
|
} from "../../redux/messaging/messaging.actions";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
//currentUser: selectCurrentUser'
|
//currentUser: selectCurrentUser'
|
||||||
@@ -21,12 +26,16 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
});
|
});
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
setEmailOptions: (e) => dispatch(setEmailOptions(e)),
|
setEmailOptions: (e) => dispatch(setEmailOptions(e)),
|
||||||
|
openChatByPhone: (phone) => dispatch(openChatByPhone(phone)),
|
||||||
|
setMessage: (text) => dispatch(setMessage(text)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export function JobsDetailHeaderCsi({
|
export function JobsDetailHeaderCsi({
|
||||||
setEmailOptions,
|
setEmailOptions,
|
||||||
bodyshop,
|
bodyshop,
|
||||||
job,
|
job,
|
||||||
|
openChatByPhone,
|
||||||
|
setMessage,
|
||||||
...props
|
...props
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -36,52 +45,90 @@ export function JobsDetailHeaderCsi({
|
|||||||
const handleCreateCsi = async (e) => {
|
const handleCreateCsi = async (e) => {
|
||||||
logImEXEvent("job_create_csi");
|
logImEXEvent("job_create_csi");
|
||||||
|
|
||||||
const questionSetResult = await client.query({
|
//Is tehre already a CSI?
|
||||||
query: GET_CURRENT_QUESTIONSET_ID,
|
if (job.csi_invites.length === 0) {
|
||||||
});
|
const questionSetResult = await client.query({
|
||||||
|
query: GET_CURRENT_QUESTIONSET_ID,
|
||||||
|
});
|
||||||
|
|
||||||
if (questionSetResult.data.csiquestions.length > 0) {
|
if (questionSetResult.data.csiquestions.length > 0) {
|
||||||
const result = await insertCsi({
|
const result = await insertCsi({
|
||||||
variables: {
|
variables: {
|
||||||
csiInput: {
|
csiInput: {
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
bodyshopid: bodyshop.id,
|
bodyshopid: bodyshop.id,
|
||||||
questionset: questionSetResult.data.csiquestions[0].id,
|
questionset: questionSetResult.data.csiquestions[0].id,
|
||||||
relateddata: {
|
relateddata: {
|
||||||
job: {
|
job: {
|
||||||
id: job.id,
|
id: job.id,
|
||||||
ownr_fn: job.ownr_fn,
|
ownr_fn: job.ownr_fn,
|
||||||
ro_number: job.ro_number,
|
ro_number: job.ro_number,
|
||||||
v_model_yr: job.v_model_yr,
|
v_model_yr: job.v_model_yr,
|
||||||
v_make_desc: job.v_make_desc,
|
v_make_desc: job.v_make_desc,
|
||||||
v_model_desc: job.v_model_desc,
|
v_model_desc: job.v_model_desc,
|
||||||
},
|
},
|
||||||
bodyshop: {
|
bodyshop: {
|
||||||
city: bodyshop.city,
|
city: bodyshop.city,
|
||||||
email: bodyshop.email,
|
email: bodyshop.email,
|
||||||
state: bodyshop.state,
|
state: bodyshop.state,
|
||||||
country: bodyshop.country,
|
country: bodyshop.country,
|
||||||
address1: bodyshop.address1,
|
address1: bodyshop.address1,
|
||||||
address2: bodyshop.address2,
|
address2: bodyshop.address2,
|
||||||
shopname: bodyshop.shopname,
|
shopname: bodyshop.shopname,
|
||||||
zip_post: bodyshop.zip_post,
|
zip_post: bodyshop.zip_post,
|
||||||
logo_img_path: bodyshop.logo_img_path,
|
logo_img_path: bodyshop.logo_img_path,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (!!!result.errors) {
|
if (!!!result.errors) {
|
||||||
notification["success"]({ message: t("csi.successes.created") });
|
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("job").csi_invitation.key,
|
||||||
|
variables: {
|
||||||
|
id: result.data.insert_csi.returning[0].id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (e.key === "text") {
|
||||||
|
const p = parsePhoneNumber(job.ownr_ph1, "CA");
|
||||||
|
if (p && p.isValid()) {
|
||||||
|
// openChatByPhone({
|
||||||
|
// phone_num: p.formatInternational(),
|
||||||
|
// jobid: job.id,
|
||||||
|
// });
|
||||||
|
setMessage(
|
||||||
|
`${window.location.protocol}//${window.location.host}/csi/${result.data.insert_csi.returning[0].id}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
notification["error"]({
|
||||||
|
message: t("messaging.error.invalidphone"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
notification["error"]({
|
notification["error"]({
|
||||||
message: t("csi.errors.creating", {
|
message: t("csi.errors.notconfigured"),
|
||||||
message: JSON.stringify(result.errors),
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (e.key === "email")
|
if (e.key === "email")
|
||||||
setEmailOptions({
|
setEmailOptions({
|
||||||
messageOptions: {
|
messageOptions: {
|
||||||
@@ -91,17 +138,27 @@ export function JobsDetailHeaderCsi({
|
|||||||
template: {
|
template: {
|
||||||
name: TemplateList("job").csi_invitation.key,
|
name: TemplateList("job").csi_invitation.key,
|
||||||
variables: {
|
variables: {
|
||||||
id: result.data.insert_csi.returning[0].id,
|
id: job.csi_invites[0].id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (e.key === "text") {
|
if (e.key === "text") {
|
||||||
|
const p = parsePhoneNumber(job.ownr_ph1, "CA");
|
||||||
|
if (p && p.isValid()) {
|
||||||
|
// openChatByPhone({
|
||||||
|
// phone_num: p.formatInternational(),
|
||||||
|
// jobid: job.id,
|
||||||
|
// });
|
||||||
|
setMessage(
|
||||||
|
`${window.location.protocol}//${window.location.host}/csi/${job.csi_invites[0].id}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
notification["error"]({
|
||||||
|
message: t("messaging.error.invalidphone"),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
notification["error"]({
|
|
||||||
message: t("csi.errors.notconfigured"),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -122,13 +179,26 @@ export function JobsDetailHeaderCsi({
|
|||||||
{t("general.labels.text")}
|
{t("general.labels.text")}
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
<Menu.Divider />
|
<Menu.Divider />
|
||||||
{job.csiinvites.map((item, idx) => (
|
{job.csiinvites.map((item, idx) => {
|
||||||
<Menu.Item key={idx}>
|
return item.completedon ? (
|
||||||
<Link to={`/manage/shop/csi?responseid=${item.id}`}>
|
<Menu.Item key={idx}>
|
||||||
<DateTimeFormatter>{item.completedon}</DateTimeFormatter>
|
<Link to={`/manage/shop/csi?responseid=${item.id}`}>
|
||||||
</Link>
|
<DateTimeFormatter>{item.completedon}</DateTimeFormatter>
|
||||||
</Menu.Item>
|
</Link>
|
||||||
))}
|
</Menu.Item>
|
||||||
|
) : (
|
||||||
|
<Menu.Item
|
||||||
|
key={idx}
|
||||||
|
onClick={() => {
|
||||||
|
navigator.clipboard.writeText(
|
||||||
|
`${window.location.protocol}//${window.location.host}/csi/${item.id}`
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("general.actions.copylink")}
|
||||||
|
</Menu.Item>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</Menu.SubMenu>
|
</Menu.SubMenu>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user