CSI updates.
This commit is contained in:
@@ -14,6 +14,11 @@ import { TemplateList } from "../../utils/TemplateConstants";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import { DateTimeFormatter } from "../../utils/DateFormatter";
|
||||
import { Link } from "react-router-dom";
|
||||
import parsePhoneNumber from "libphonenumber-js";
|
||||
import {
|
||||
openChatByPhone,
|
||||
setMessage,
|
||||
} from "../../redux/messaging/messaging.actions";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser'
|
||||
@@ -21,12 +26,16 @@ const mapStateToProps = createStructuredSelector({
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setEmailOptions: (e) => dispatch(setEmailOptions(e)),
|
||||
openChatByPhone: (phone) => dispatch(openChatByPhone(phone)),
|
||||
setMessage: (text) => dispatch(setMessage(text)),
|
||||
});
|
||||
|
||||
export function JobsDetailHeaderCsi({
|
||||
setEmailOptions,
|
||||
bodyshop,
|
||||
job,
|
||||
openChatByPhone,
|
||||
setMessage,
|
||||
...props
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
@@ -36,6 +45,8 @@ export function JobsDetailHeaderCsi({
|
||||
const handleCreateCsi = async (e) => {
|
||||
logImEXEvent("job_create_csi");
|
||||
|
||||
//Is tehre already a CSI?
|
||||
if (job.csi_invites.length === 0) {
|
||||
const questionSetResult = await client.query({
|
||||
query: GET_CURRENT_QUESTIONSET_ID,
|
||||
});
|
||||
@@ -97,12 +108,58 @@ export function JobsDetailHeaderCsi({
|
||||
});
|
||||
|
||||
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 {
|
||||
notification["error"]({
|
||||
message: t("csi.errors.notconfigured"),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (e.key === "email")
|
||||
setEmailOptions({
|
||||
messageOptions: {
|
||||
to: [job.ownr_ea],
|
||||
replyTo: bodyshop.email,
|
||||
},
|
||||
template: {
|
||||
name: TemplateList("job").csi_invitation.key,
|
||||
variables: {
|
||||
id: job.csi_invites[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/${job.csi_invites[0].id}`
|
||||
);
|
||||
} else {
|
||||
notification["error"]({
|
||||
message: t("messaging.error.invalidphone"),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -122,13 +179,26 @@ export function JobsDetailHeaderCsi({
|
||||
{t("general.labels.text")}
|
||||
</Menu.Item>
|
||||
<Menu.Divider />
|
||||
{job.csiinvites.map((item, idx) => (
|
||||
{job.csiinvites.map((item, idx) => {
|
||||
return item.completedon ? (
|
||||
<Menu.Item key={idx}>
|
||||
<Link to={`/manage/shop/csi?responseid=${item.id}`}>
|
||||
<DateTimeFormatter>{item.completedon}</DateTimeFormatter>
|
||||
</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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user