Direct Messages can use redux for creating new DM channels

This commit is contained in:
2019-11-19 19:04:25 -05:00
parent 297619cacb
commit 3d9266778d
6 changed files with 314 additions and 144 deletions

View File

@@ -0,0 +1,57 @@
import {
SET_DIRECT_MESSAGES,
LOADING_UI,
SET_ERRORS,
CLEAR_ERRORS,
SET_LOADING_UI_2,
SET_LOADING_UI_3,
SET_LOADING_UI_4,
SET_NOT_LOADING_UI_2,
SET_NOT_LOADING_UI_3,
SET_NOT_LOADING_UI_4
} from '../types';
import axios from "axios";
export const getDirectMessages = () => (dispatch) => {
dispatch({type: LOADING_UI});
axios.get('/dms')
.then((res) => {
dispatch({
type: SET_DIRECT_MESSAGES,
payload: res.data.data
});
dispatch({type: CLEAR_ERRORS});
})
}
export const createNewDirectMessage = (username) => (dispatch) => {
dispatch({type: SET_LOADING_UI_3});
const data = {
user: username
}
// console.log(username);
axios.post('/dms/new', data)
.then((res) => {
console.log(res.data);
if (res.data.err) {
dispatch({
type: SET_ERRORS,
payload: {
createDirectMessage: res.data.err
}
});
}
dispatch({type: SET_NOT_LOADING_UI_3});
})
.catch((err) => {
dispatch({
type: SET_ERRORS,
payload: {
createDirectMessage: err.response.data.err
}
});
dispatch({type: SET_NOT_LOADING_UI_3});
console.log(err.response.data);
})
}