Added updating of display name to profile. Added employees table.

This commit is contained in:
Patrick Fic
2020-02-04 12:42:20 -08:00
parent 55cec20914
commit de6ca52fb8
33 changed files with 514 additions and 39 deletions

View File

@@ -0,0 +1,7 @@
import MessagingActionTypes from './messaging.types'
export const toggleChatVisible = () => ({
type: MessagingActionTypes.TOGGLE_CHAT_VISIBLE,
//payload: user
});

View File

@@ -0,0 +1,24 @@
import MessagingActionTypes from "./messaging.types";
const INITIAL_STATE = {
visible: false
};
const messagingReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case MessagingActionTypes.TOGGLE_CHAT_VISIBLE:
return {
...state,
visible: !state.visible
};
case MessagingActionTypes.SET_CHAT_VISIBLE:
return {
...state,
visible: true
};
default:
return state;
}
};
export default messagingReducer;

View File

@@ -0,0 +1,90 @@
import {
all
// call, put, takeLatest
} from "redux-saga/effects";
//import { auth, getCurrentUser } from "../../firebase/firebase.utils";
// import { toggleChatVisible } from "./messaging.actions";
// import MessagingActionTypes from "./messaging.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);
// yield put(
// signInSuccess({
// uid: user.uid,
// email: user.email,
// displayName: user.displayName,
// authorized: true
// })
// );
// } catch (error) {
// yield put(signInFailure(error));
// }
// }
// //This is the listener fo rthe call, and when it finds it, it triggers somethign else.
// export function* onEmailSignInStart() {
// yield takeLatest(UserActionTypes.EMAIL_SIGN_IN_START, signInWithEmail);
// }
// export function* isUserAuthenticated() {
// try {
// const user = yield getCurrentUser();
// if (!user) {
// 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,
// email: user.email,
// displayName: user.displayName,
// authorized: true
// })
// );
// } catch (error) {
// yield put(signInFailure(error));
// }
// }
// export function* onCheckUserSession() {
// yield takeLatest(UserActionTypes.CHECK_USER_SESSION, isUserAuthenticated);
// }
// export function* signOutStart() {
// try {
// yield auth.signOut();
// yield put(signOutSuccess());
// localStorage.removeItem("token");
// } catch (error) {
// yield put(signOutFailure(error.message));
// }
// }
// export function* onSignOutStart() {
// yield takeLatest(UserActionTypes.SIGN_OUT_START, signOutStart);
// }
export function* messagingSagas() {
yield all([
// call(onGoogleSignInStart),
// call(onEmailSignInStart),
// call(onCheckUserSession),
// call(onSignOutStart)
// call(onEmailSignUpStart),
// call(onEmailSignUpSuccess)
]);
}

View File

@@ -0,0 +1,8 @@
import { createSelector } from "reselect";
const selectMessaging = state => state.messaging;
export const selectChatVisible = createSelector(
[selectMessaging],
messaging => messaging.visible
);

View File

@@ -0,0 +1,5 @@
const MessagingActionTypes = {
TOGGLE_CHAT_VISIBLE: "TOGGLE_CHAT_VISIBLE",
SET_CHAT_VISIBLE: "SET_CHAT_VISIBLE"
};
export default MessagingActionTypes;

View File

@@ -3,6 +3,7 @@ import { persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";
import userReducer from "./user/user.reducer";
import messagingReducer from "./messaging/messaging.reducer";
// import cartReducer from './cart/cart.reducer';
// import directoryReducer from './directory/directory.reducer';
// import shopReducer from './shop/shop.reducer';
@@ -15,7 +16,8 @@ const persistConfig = {
};
const rootReducer = combineReducers({
user: userReducer
user: userReducer,
messaging: messagingReducer
// cart: cartReducer,
// directory: directoryReducer,
// shop: shopReducer

View File

@@ -3,9 +3,10 @@ import { all, call } from "redux-saga/effects";
//List of all Sagas
// import { shopSagas } from "./shop/shop.sagas";
import { userSagas } from "./user/user.sagas";
import { messagingSagas } from "./messaging/messaging.sagas";
//import { cartSagas } from "./cart/cart.sagas";
export default function* rootSaga() {
//All starts all the Sagas concurrently.
yield all([call(userSagas)]);
yield all([call(userSagas), call(messagingSagas)]);
}

View File

@@ -38,3 +38,13 @@ export const setUserLanguage = language => ({
type: UserActionTypes.SET_USER_LANGUAGE,
payload: language
});
export const updateUserDetails = userDetails => ({
type: UserActionTypes.UPDATE_USER_DETAILS,
payload: userDetails
});
export const updateUserDetailsSuccess = userDetails => ({
type: UserActionTypes.UPDATE_USER_DETAILS_SUCCESS,
payload: userDetails
});

View File

@@ -33,10 +33,17 @@ const userReducer = (state = INITIAL_STATE, action) => {
...state,
language: action.payload
};
case UserActionTypes.UPDATE_USER_DETAILS_SUCCESS:
return {
...state,
currentUser: {
...state.currentUser,
...action.payload //Spread current user details in.
}
};
case UserActionTypes.SIGN_IN_FAILURE:
case UserActionTypes.SIGN_OUT_FAILURE:
case UserActionTypes.EMAIL_SIGN_UP_FAILURE:
console.log("Reduced getting called.");
return {
...state,
error: action.payload

View File

@@ -1,6 +1,17 @@
import { all, call, put, takeLatest } from "redux-saga/effects";
import { auth, getCurrentUser } from "../../firebase/firebase.utils";
import { signInFailure, signInSuccess, signOutFailure, signOutSuccess, unauthorizedUser } from "./user.actions";
import {
auth,
getCurrentUser,
updateCurrentUser
} from "../../firebase/firebase.utils";
import {
signInFailure,
signInSuccess,
signOutFailure,
signOutSuccess,
unauthorizedUser,
updateUserDetailsSuccess
} from "./user.actions";
import UserActionTypes from "./user.types";
// export function* getSnapshotFromUserAuth(userAuth) {
@@ -74,6 +85,18 @@ export function* onSignOutStart() {
yield takeLatest(UserActionTypes.SIGN_OUT_START, signOutStart);
}
export function* onUpdateUserDetails() {
yield takeLatest(UserActionTypes.UPDATE_USER_DETAILS, updateUserDetails);
}
export function* updateUserDetails(userDetails) {
try {
yield updateCurrentUser(userDetails.payload);
yield put(updateUserDetailsSuccess(userDetails.payload));
} catch (error) {
//yield put(signOutFailure(error.message));
//TODO: error handling
}
}
export function* userSagas() {
yield all([
@@ -81,6 +104,7 @@ export function* userSagas() {
call(onEmailSignInStart),
call(onCheckUserSession),
call(onSignOutStart),
call(onUpdateUserDetails)
// call(onEmailSignUpStart),
// call(onEmailSignUpSuccess)
]);

View File

@@ -12,6 +12,8 @@ const UserActionTypes = {
EMAIL_SIGN_UP_SUCCESS: "EMAIL_SIGN_UP_SUCCESS",
EMAIL_SIGN_UP_FAILURE: "EMAIL_SIGN_UP_FAILURE",
UNAUTHORIZED_USER: "UNAUTHORIZED_USER",
SET_USER_LANGUAGE: "SET_USER_LANGUAGE"
SET_USER_LANGUAGE: "SET_USER_LANGUAGE",
UPDATE_USER_DETAILS: "UPDATE_USER_DETAILS",
UPDATE_USER_DETAILS_SUCCESS: "UPDATE_USER_DETAILS_SUCCESS"
};
export default UserActionTypes;