diff --git a/client/src/components/chat-media-selector/chat-media-selector.component.jsx b/client/src/components/chat-media-selector/chat-media-selector.component.jsx index f873dfe96..0538adba6 100644 --- a/client/src/components/chat-media-selector/chat-media-selector.component.jsx +++ b/client/src/components/chat-media-selector/chat-media-selector.component.jsx @@ -24,6 +24,7 @@ export function ChatMediaSelector({ conversation, }) { const { t } = useTranslation(); + const [visible, setVisible] = useState(false); const { loading, error, data } = useQuery(GET_DOCUMENTS_BY_JOB, { variables: { @@ -33,12 +34,11 @@ export function ChatMediaSelector({ }, fetchPolicy: "network-only", skip: + !visible || !conversation.job_conversations || conversation.job_conversations.length === 0, }); - const [visible, setVisible] = useState(false); - const handleVisibleChange = (visible) => { setVisible(visible); }; diff --git a/client/src/components/chat-open-button/chat-open-button.component.jsx b/client/src/components/chat-open-button/chat-open-button.component.jsx index 31929af57..ce357a962 100644 --- a/client/src/components/chat-open-button/chat-open-button.component.jsx +++ b/client/src/components/chat-open-button/chat-open-button.component.jsx @@ -6,13 +6,23 @@ import { connect } from "react-redux"; import { openChatByPhone } from "../../redux/messaging/messaging.actions"; import PhoneNumberFormatter from "../../utils/PhoneFormatter"; +import { createStructuredSelector } from "reselect"; +import { selectBodyshop } from "../../redux/user/user.selectors"; +const mapStateToProps = createStructuredSelector({ + bodyshop: selectBodyshop, +}); + const mapDispatchToProps = (dispatch) => ({ openChatByPhone: (phone) => dispatch(openChatByPhone(phone)), }); -export function ChatOpenButton({ phone, jobid, openChatByPhone }) { +export function ChatOpenButton({ bodyshop, phone, jobid, openChatByPhone }) { const { t } = useTranslation(); if (!phone) return <>; + + if (!bodyshop.messagingservicesid) + return {phone}; + return ( ); } -export default connect(null, mapDispatchToProps)(ChatOpenButton); +export default connect(mapStateToProps, mapDispatchToProps)(ChatOpenButton); diff --git a/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx b/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx index 03d2689fa..e47695139 100644 --- a/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx +++ b/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx @@ -84,55 +84,59 @@ export function JobsDetailHeader({ job, bodyshop, disabled }) { - - -
- - {job.ownr_ph1 || ""} - - - {`${job.ownr_addr1 || ""} ${job.ownr_addr2 || ""} ${ - job.ownr_city || "" - } ${job.ownr_st || ""} ${job.ownr_zip || ""}`} - - - {job.ownr_ea || ""} - -
-
- - - - + {`${job.ownr_fn || ""} ${job.ownr_ln || ""} ${ + job.ownr_co_nm || "" + }`} + } > - + + + + + {`${job.ownr_addr1 || ""} ${job.ownr_addr2 || ""} ${ + job.ownr_city || "" + } ${job.ownr_st || ""} ${job.ownr_zip || ""}`} + + + {job.ownr_ea || ""} + + + + + + + {`${job.v_model_yr || ""} ${job.v_color || ""} ${job.v_make_desc || ""} ${job.v_model_desc || ""}`} - > -
- - {`${job.plate_no || t("general.labels.na")} (${`${ - job.plate_st || t("general.labels.na") - }`})`} - - - {`${job.v_vin || t("general.labels.na")}`} - -
-
- + + } + > +
+ + {`${job.plate_no || t("general.labels.na")} (${`${ + job.plate_st || t("general.labels.na") + }`})`} + + + {`${job.v_vin || t("general.labels.na")}`} + +
+ ( - + ), }, diff --git a/client/src/graphql/conversations.queries.js b/client/src/graphql/conversations.queries.js index 8f294f811..f18b43eca 100644 --- a/client/src/graphql/conversations.queries.js +++ b/client/src/graphql/conversations.queries.js @@ -70,6 +70,10 @@ export const CONVERSATION_ID_BY_PHONE = gql` query CONVERSATION_ID_BY_PHONE($phone: String!) { conversations(where: { phone_num: { _eq: $phone } }) { id + job_conversations { + jobid + id + } } } `; diff --git a/client/src/redux/messaging/messaging.sagas.js b/client/src/redux/messaging/messaging.sagas.js index c96a30942..296dca198 100644 --- a/client/src/redux/messaging/messaging.sagas.js +++ b/client/src/redux/messaging/messaging.sagas.js @@ -4,7 +4,7 @@ import { all, call, put, select, takeLatest } from "redux-saga/effects"; import { logImEXEvent } from "../../firebase/firebase.utils"; import { CONVERSATION_ID_BY_PHONE, - CREATE_CONVERSATION + CREATE_CONVERSATION, } from "../../graphql/conversations.queries"; import { INSERT_CONVERSATION_TAG } from "../../graphql/job-conversations.queries"; import client from "../../utils/GraphQLClient"; @@ -12,7 +12,7 @@ import { selectBodyshop } from "../user/user.selectors"; import { sendMessageFailure, sendMessageSuccess, - setSelectedConversation + setSelectedConversation, } from "./messaging.actions"; import MessagingActionTypes from "./messaging.types"; @@ -64,7 +64,9 @@ export function* openChatByPhone({ payload }) { } else if (conversations.length === 1) { //got the ID. Open it. yield put(setSelectedConversation(conversations[0].id)); - if (jobid) + + //Check to see if this job ID is already a child of it. If not add the tag. + if (!conversations[0].job_conversations.find((jc) => jc.jobid === jobid)) yield client.mutate({ mutation: INSERT_CONVERSATION_TAG, variables: {