diff --git a/client/src/redux/messaging/messaging.sagas.js b/client/src/redux/messaging/messaging.sagas.js index fb1c7d4db..f2684a171 100644 --- a/client/src/redux/messaging/messaging.sagas.js +++ b/client/src/redux/messaging/messaging.sagas.js @@ -1,10 +1,10 @@ import axios from "axios"; -import phone from "phone"; +import parsePhoneNumber from "libphonenumber-js"; 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"; @@ -33,13 +33,14 @@ export function* openChatByPhone({ payload }) { logImEXEvent("messaging_open_by_phone"); const { phone_num, jobid } = payload; + const p = parsePhoneNumber(phone_num, "CA"); const bodyshop = yield select(selectBodyshop); try { const { data: { conversations }, } = yield client.query({ query: CONVERSATION_ID_BY_PHONE, - variables: { phone: phone(phone_num).phoneNumber }, + variables: { phone: p.number }, }); if (conversations.length === 0) { @@ -52,7 +53,7 @@ export function* openChatByPhone({ payload }) { variables: { conversation: [ { - phone_num: phone(phone_num).phoneNumber, + phone_num: p.number, bodyshopid: bodyshop.id, job_conversations: jobid ? { data: { jobid: jobid } } : null, },