BOD-14 WIP. CSS issues present with 2 way texting, but working live.
This commit is contained in:
@@ -25,6 +25,11 @@ export const sendMessage = message => ({
|
||||
payload: message
|
||||
});
|
||||
|
||||
export const sendMessageSuccess = message => ({
|
||||
type: MessagingActionTypes.SEND_MESSAGE_SUCCESS,
|
||||
payload: message
|
||||
});
|
||||
|
||||
export const sendMessageFailure = error => ({
|
||||
type: MessagingActionTypes.SEND_MESSAGE_FAILURE,
|
||||
payload: error
|
||||
|
||||
@@ -7,12 +7,16 @@ const INITIAL_STATE = {
|
||||
{
|
||||
phone_num: "6049992002",
|
||||
id: "519ba10d-6467-4fa5-9c22-59ae891edeb6",
|
||||
open: false
|
||||
open: false,
|
||||
isSending: false,
|
||||
sendingError: null
|
||||
},
|
||||
{
|
||||
phone_num: "6049992991",
|
||||
id: "ab57deba-eeb9-40db-b5ae-23f3ce8d7c7b",
|
||||
open: false
|
||||
open: false,
|
||||
isSending: false,
|
||||
sendingError: null
|
||||
}
|
||||
],
|
||||
error: null
|
||||
@@ -30,6 +34,31 @@ const messagingReducer = (state = INITIAL_STATE, action) => {
|
||||
...state,
|
||||
visible: true
|
||||
};
|
||||
case MessagingActionTypes.SEND_MESSAGE:
|
||||
return {
|
||||
...state,
|
||||
conversations: state.conversations.map(c =>
|
||||
c.id === action.payload.conversationid ? { ...c, isSending: true } : c
|
||||
)
|
||||
};
|
||||
case MessagingActionTypes.SEND_MESSAGE_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
conversations: state.conversations.map(c =>
|
||||
c.id === action.payload.conversationid
|
||||
? { ...c, isSending: false }
|
||||
: c
|
||||
)
|
||||
};
|
||||
case MessagingActionTypes.SEND_MESSAGE_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
conversations: state.conversations.map(c =>
|
||||
c.id === action.payload.conversationid
|
||||
? { ...c, isSending: false, sendingError: action.payload.error }
|
||||
: c
|
||||
)
|
||||
};
|
||||
case MessagingActionTypes.OPEN_CONVERSATION:
|
||||
if (
|
||||
state.conversations.find(c => c.phone_num === action.payload.phone_num)
|
||||
@@ -48,7 +77,9 @@ const messagingReducer = (state = INITIAL_STATE, action) => {
|
||||
{
|
||||
phone_num: action.payload.phone_num,
|
||||
id: action.payload.id,
|
||||
open: true
|
||||
open: true,
|
||||
isSending: false,
|
||||
sendingError: null
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -66,8 +97,7 @@ const messagingReducer = (state = INITIAL_STATE, action) => {
|
||||
c.phone_num === action.payload ? { ...c, open: !c.open } : c
|
||||
)
|
||||
};
|
||||
case MessagingActionTypes.SEND_MESSAGE_FAILURE:
|
||||
return { ...state, error: action.payload };
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
import { all, call, put, takeLatest } from "redux-saga/effects";
|
||||
import { sendMessageFailure } from "./messaging.actions";
|
||||
import { sendMessageFailure, sendMessageSuccess } from "./messaging.actions";
|
||||
import MessagingActionTypes from "./messaging.types";
|
||||
import axios from "axios";
|
||||
import { sendEmailFailure } from "../email/email.actions";
|
||||
|
||||
export function* onSendMessage() {
|
||||
yield takeLatest(MessagingActionTypes.SEND_MESSAGE, sendMessage);
|
||||
}
|
||||
export function* sendMessage({ payload }) {
|
||||
console.log("In the saga.");
|
||||
try {
|
||||
console.log("Message Contents", payload);
|
||||
axios.post("/sms/send", payload).then(response => {
|
||||
console.log(JSON.stringify(response));
|
||||
});
|
||||
const response = yield call(axios.post, "/sms/send", payload);
|
||||
if (response.status === 200) {
|
||||
yield put(sendMessageSuccess(payload));
|
||||
} else {
|
||||
yield put(sendEmailFailure(response.data));
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error in sendMessage saga.");
|
||||
console.log("Error in sendMessage saga.", error);
|
||||
yield put(sendMessageFailure(error));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ const MessagingActionTypes = {
|
||||
CLOSE_CONVERSATION: "CLOSE_CONVERSATION",
|
||||
TOGGLE_CONVERSATION_VISIBLE: "TOGGLE_CONVERSATION_VISIBLE",
|
||||
SEND_MESSAGE: "SEND_MESSAGE",
|
||||
SEND_MESSAGE_SUCCESS: "SEND_MESSAGE_SUCCESS",
|
||||
SEND_MESSAGE_FAILURE: "SEND_MESSAGE_FAILURE"
|
||||
};
|
||||
export default MessagingActionTypes;
|
||||
|
||||
@@ -14,21 +14,9 @@ import {
|
||||
} from "./user.actions";
|
||||
import UserActionTypes from "./user.types";
|
||||
|
||||
// export function* getSnapshotFromUserAuth(userAuth) {
|
||||
// try {
|
||||
// const userRef = yield call(createUserProfileDocument, userAuth);
|
||||
// //const userSnapshot = yield userRef.get();
|
||||
// } catch (error) {
|
||||
// yield put(signInFailure(error));
|
||||
// }
|
||||
// }
|
||||
|
||||
export function* signInWithEmail({ payload: { email, password } }) {
|
||||
try {
|
||||
const { user } = yield auth.signInWithEmailAndPassword(email, password);
|
||||
let token = yield user.getIdToken();
|
||||
// localStorage.setItem("token", token);
|
||||
//window.sessionStorage.setItem(`lastTokenRefreshTime`, new Date());
|
||||
yield put(
|
||||
signInSuccess({
|
||||
uid: user.uid,
|
||||
@@ -54,10 +42,6 @@ export function* isUserAuthenticated() {
|
||||
yield put(unauthorizedUser());
|
||||
return;
|
||||
}
|
||||
let token = yield user.getIdToken();
|
||||
//localStorage.setItem("token", token);
|
||||
//window.sessionStorage.setItem(`lastTokenRefreshTime`, new Date());
|
||||
|
||||
yield put(
|
||||
signInSuccess({
|
||||
uid: user.uid,
|
||||
|
||||
Reference in New Issue
Block a user