Added log rocket + analytics to ensure functionality
This commit is contained in:
@@ -47,7 +47,7 @@ const userReducer = (state = INITIAL_STATE, action) => {
|
||||
return {
|
||||
...state,
|
||||
currentUser: action.payload,
|
||||
loingLoading: false,
|
||||
loginLoading: false,
|
||||
error: null,
|
||||
};
|
||||
case UserActionTypes.SIGN_OUT_SUCCESS:
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { message } from "antd";
|
||||
import LogRocket from "logrocket";
|
||||
import { all, call, put, takeLatest } from "redux-saga/effects";
|
||||
import {
|
||||
auth,
|
||||
@@ -18,8 +20,6 @@ import {
|
||||
signOutSuccess,
|
||||
unauthorizedUser,
|
||||
updateUserDetailsSuccess,
|
||||
validatePasswordResetFailure,
|
||||
validatePasswordResetSuccess,
|
||||
} from "./user.actions";
|
||||
import UserActionTypes from "./user.types";
|
||||
|
||||
@@ -30,6 +30,10 @@ export function* onEmailSignInStart() {
|
||||
}
|
||||
export function* signInWithEmail({ payload: { email, password } }) {
|
||||
try {
|
||||
ipcRenderer.send(ipcTypes.default.app.toMain.track, {
|
||||
event: "SIGN_IN_ATTEMPT",
|
||||
email: email,
|
||||
});
|
||||
const { user } = yield auth.signInWithEmailAndPassword(email, password);
|
||||
|
||||
const result = yield client.mutate({
|
||||
@@ -50,13 +54,16 @@ export function* signInWithEmail({ payload: { email, password } }) {
|
||||
yield put(signInFailure(JSON.stringify(result.errors)));
|
||||
}
|
||||
} catch (error) {
|
||||
yield put(signInFailure(error));
|
||||
yield put(
|
||||
signInFailure({ ...error, messagePretty: ErrorFormatter(error.code) })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function* onCheckUserSession() {
|
||||
yield takeLatest(UserActionTypes.CHECK_USER_SESSION, isUserAuthenticated);
|
||||
}
|
||||
|
||||
export function* isUserAuthenticated() {
|
||||
try {
|
||||
const user = yield getCurrentUser();
|
||||
@@ -78,9 +85,11 @@ export function* isUserAuthenticated() {
|
||||
yield put(signInFailure(error));
|
||||
}
|
||||
}
|
||||
|
||||
export function* onSignOutStart() {
|
||||
yield takeLatest(UserActionTypes.SIGN_OUT_START, signOutStart);
|
||||
}
|
||||
|
||||
export function* signOutStart() {
|
||||
try {
|
||||
ipcRenderer.send(ipcTypes.default.fileWatcher.toMain.stop);
|
||||
@@ -112,7 +121,15 @@ export function* onSignInSuccess() {
|
||||
|
||||
export function* signInSuccessSaga({ payload }) {
|
||||
//Query for the Correct Bodyshop
|
||||
ipcRenderer.send(ipcTypes.default.app.toMain.setUserName, payload.email);
|
||||
LogRocket.identify(payload.email, {
|
||||
email: payload.email,
|
||||
});
|
||||
|
||||
ipcRenderer.send(ipcTypes.default.app.toMain.track, {
|
||||
event: "SIGN_IN_SUCCESS",
|
||||
email: payload.email,
|
||||
});
|
||||
const shop = yield client.query({ query: QUERY_BODYSHOP });
|
||||
if (shop.data.bodyshops.length > 0) {
|
||||
yield put(setBodyshop(shop.data.bodyshops[0]));
|
||||
@@ -138,32 +155,14 @@ export function* onSendPasswordResetStart() {
|
||||
}
|
||||
export function* sendPasswordResetEmail({ payload }) {
|
||||
try {
|
||||
yield auth.sendPasswordResetEmail(payload, {
|
||||
url: "https://imex.online/passwordreset",
|
||||
});
|
||||
yield auth.sendPasswordResetEmail(payload);
|
||||
|
||||
yield put(sendPasswordResetSuccess());
|
||||
message.success("Password reset sent succesfully.");
|
||||
} catch (error) {
|
||||
yield put(sendPasswordResetFailure(error.message));
|
||||
}
|
||||
}
|
||||
|
||||
export function* onValidatePasswordResetStart() {
|
||||
yield takeLatest(
|
||||
UserActionTypes.VALIDATE_PASSWORD_RESET_START,
|
||||
validatePasswordResetStart
|
||||
);
|
||||
}
|
||||
export function* validatePasswordResetStart({ payload: { password, code } }) {
|
||||
try {
|
||||
yield auth.confirmPasswordReset(code, password);
|
||||
yield put(validatePasswordResetSuccess());
|
||||
} catch (error) {
|
||||
console.log("function*validatePasswordResetStart -> error", error);
|
||||
yield put(validatePasswordResetFailure(error.message));
|
||||
}
|
||||
}
|
||||
|
||||
export function* userSagas() {
|
||||
yield all([
|
||||
call(onEmailSignInStart),
|
||||
@@ -172,6 +171,18 @@ export function* userSagas() {
|
||||
call(onUpdateUserDetails),
|
||||
call(onSignInSuccess),
|
||||
call(onSendPasswordResetStart),
|
||||
call(onValidatePasswordResetStart),
|
||||
]);
|
||||
}
|
||||
|
||||
const ErrorFormatter = (code) => {
|
||||
switch (code) {
|
||||
case "auth/invalid-email":
|
||||
return "Please enter a valid email.";
|
||||
case "auth/user-not-found":
|
||||
return "A user does not exist with that email.";
|
||||
case "auth/wrong-password":
|
||||
return "The email or password is incorrect.";
|
||||
default:
|
||||
return code;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user