Merged in feature/IO-2401-duplicate-chat-creation (pull request #1013)
IO-2401 Add prevention of duplicate chat creation by adding loading tracking.
This commit is contained in:
@@ -8,15 +8,23 @@ import PhoneNumberFormatter from "../../utils/PhoneFormatter";
|
|||||||
|
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
|
import { searchingForConversation } from "../../redux/messaging/messaging.selectors";
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
|
searchingForConversation: searchingForConversation,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
openChatByPhone: (phone) => dispatch(openChatByPhone(phone)),
|
openChatByPhone: (phone) => dispatch(openChatByPhone(phone)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export function ChatOpenButton({ bodyshop, phone, jobid, openChatByPhone }) {
|
export function ChatOpenButton({
|
||||||
|
bodyshop,
|
||||||
|
searchingForConversation,
|
||||||
|
phone,
|
||||||
|
jobid,
|
||||||
|
openChatByPhone,
|
||||||
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
if (!phone) return <></>;
|
if (!phone) return <></>;
|
||||||
|
|
||||||
@@ -29,7 +37,7 @@ export function ChatOpenButton({ bodyshop, phone, jobid, openChatByPhone }) {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const p = parsePhoneNumber(phone, "CA");
|
const p = parsePhoneNumber(phone, "CA");
|
||||||
|
if (searchingForConversation) return; //This is to prevent finding the same thing twice.
|
||||||
if (p && p.isValid()) {
|
if (p && p.isValid()) {
|
||||||
openChatByPhone({ phone_num: p.formatInternational(), jobid: jobid });
|
openChatByPhone({ phone_num: p.formatInternational(), jobid: jobid });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const INITIAL_STATE = {
|
|||||||
isSending: false,
|
isSending: false,
|
||||||
error: null,
|
error: null,
|
||||||
message: null,
|
message: null,
|
||||||
|
searchingForConversation: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const messagingReducer = (state = INITIAL_STATE, action) => {
|
const messagingReducer = (state = INITIAL_STATE, action) => {
|
||||||
@@ -17,10 +18,16 @@ const messagingReducer = (state = INITIAL_STATE, action) => {
|
|||||||
...state,
|
...state,
|
||||||
visible: !state.visible,
|
visible: !state.visible,
|
||||||
};
|
};
|
||||||
|
case MessagingActionTypes.OPEN_CHAT_BY_PHONE:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
searchingForConversation: true,
|
||||||
|
};
|
||||||
case MessagingActionTypes.SET_SELECTED_CONVERSATION:
|
case MessagingActionTypes.SET_SELECTED_CONVERSATION:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
visible: true,
|
visible: true,
|
||||||
|
searchingForConversation: false,
|
||||||
selectedConversationId: action.payload,
|
selectedConversationId: action.payload,
|
||||||
};
|
};
|
||||||
case MessagingActionTypes.SEND_MESSAGE:
|
case MessagingActionTypes.SEND_MESSAGE:
|
||||||
|
|||||||
@@ -26,3 +26,8 @@ export const selectMessage = createSelector(
|
|||||||
[selectMessaging],
|
[selectMessaging],
|
||||||
(messaging) => messaging.message
|
(messaging) => messaging.message
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const searchingForConversation = createSelector(
|
||||||
|
[selectMessaging],
|
||||||
|
(messaging) => messaging.searchingForConversation
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user