BOD-14 Functional 2 way messaging from app.

This commit is contained in:
Patrick Fic
2020-03-25 18:45:48 -07:00
parent 546d2d82b7
commit 4c35337d36
26 changed files with 591 additions and 64 deletions

View File

@@ -2,18 +2,20 @@ import MessagingActionTypes from "./messaging.types";
const INITIAL_STATE = {
visible: false,
unread: 0,
conversations: [
{
phone: "6049992002",
phone_num: "6049992002",
id: "519ba10d-6467-4fa5-9c22-59ae891edeb6",
open: false
},
{
phone: "6049992991",
phone_num: "6049992991",
id: "ab57deba-eeb9-40db-b5ae-23f3ce8d7c7b",
open: false
}
]
],
error: null
};
const messagingReducer = (state = INITIAL_STATE, action) => {
@@ -29,11 +31,13 @@ const messagingReducer = (state = INITIAL_STATE, action) => {
visible: true
};
case MessagingActionTypes.OPEN_CONVERSATION:
if (state.conversations.find(c => c.phone === action.payload))
if (
state.conversations.find(c => c.phone_num === action.payload.phone_num)
)
return {
...state,
conversations: state.conversations.map(c =>
c.phone === action.payload ? { ...c, open: true } : c
c.phone_num === action.payload.phone_num ? { ...c, open: true } : c
)
};
else
@@ -41,23 +45,29 @@ const messagingReducer = (state = INITIAL_STATE, action) => {
...state,
conversations: [
...state.conversations,
{ phone: action.payload, open: true }
{
phone_num: action.payload.phone_num,
id: action.payload.id,
open: true
}
]
};
case MessagingActionTypes.CLOSE_CONVERSATION:
return {
...state,
conversations: state.conversations.filter(
c => c.phone !== action.payload
c => c.phone_num !== action.payload
)
};
case MessagingActionTypes.TOGGLE_CONVERSATION_VISIBLE:
return {
...state,
conversations: state.conversations.map(c =>
c.phone === action.payload ? { ...c, open: !c.open } : c
c.phone_num === action.payload ? { ...c, open: !c.open } : c
)
};
case MessagingActionTypes.SEND_MESSAGE_FAILURE:
return { ...state, error: action.payload };
default:
return state;
}