Added app reducer, fixed package issues, begun camera screen updates
This commit is contained in:
21
redux/app/app.actions.js
Normal file
21
redux/app/app.actions.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import AppActionTypes from "./app.types";
|
||||
|
||||
export const setCameraJobId = (jobId) => ({
|
||||
type: AppActionTypes.SET_CAMERA_JOB_ID,
|
||||
payload: jobId,
|
||||
});
|
||||
|
||||
export const documentUploadStart = (jobId) => ({
|
||||
type: AppActionTypes.DOCUMENT_UPLOAD_START,
|
||||
payload: jobId,
|
||||
});
|
||||
|
||||
export const documentUploadSuccess = (jobId) => ({
|
||||
type: AppActionTypes.DOCUMNET_UPLOAD_SUCCESS,
|
||||
payload: jobId,
|
||||
});
|
||||
|
||||
export const documentUploadFailure = (error) => ({
|
||||
type: AppActionTypes.DOCUMENT_UPLOAD_FAILURE,
|
||||
payload: error,
|
||||
});
|
||||
39
redux/app/app.reducer.js
Normal file
39
redux/app/app.reducer.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import AppActionTypes from "./app.types";
|
||||
|
||||
const INITIAL_STATE = {
|
||||
cameraJobId: null,
|
||||
documentUploadInProgress: null,
|
||||
documentUploadError: null,
|
||||
};
|
||||
|
||||
const appReducer = (state = INITIAL_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case AppActionTypes.SET_CAMERA_JOB_ID:
|
||||
return {
|
||||
...state,
|
||||
cameraJobId: action.payload,
|
||||
};
|
||||
case AppActionTypes.DOCUMENT_UPLOAD_START:
|
||||
return {
|
||||
...state,
|
||||
documentUploadError: null,
|
||||
documentUploadInProgress: action.payload,
|
||||
};
|
||||
case AppActionTypes.DOCUMNET_UPLOAD_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
documentUploadError: null,
|
||||
documentUploadInProgress: null,
|
||||
};
|
||||
case AppActionTypes.DOCUMENT_UPLOAD_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
documentUploadError: action.payload,
|
||||
documentUploadInProgress: null,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default appReducer;
|
||||
158
redux/app/app.sagas.js
Normal file
158
redux/app/app.sagas.js
Normal file
@@ -0,0 +1,158 @@
|
||||
import {
|
||||
all,
|
||||
//call, put, takeLatest
|
||||
} from "redux-saga/effects";
|
||||
// import {
|
||||
// auth,
|
||||
// getCurrentUser,
|
||||
// updateCurrentUser,
|
||||
// } from "../../firebase/firebase.utils";
|
||||
// import {
|
||||
// sendPasswordResetFailure,
|
||||
// sendPasswordResetSuccess,
|
||||
// signInFailure,
|
||||
// signInSuccess,
|
||||
// signOutFailure,
|
||||
// signOutSuccess,
|
||||
// unauthorizedUser,
|
||||
// updateUserDetailsSuccess,
|
||||
// validatePasswordResetFailure,
|
||||
// validatePasswordResetSuccess,
|
||||
// setBodyshop,
|
||||
// } from "./user.actions";
|
||||
// import UserActionTypes from "./user.types";
|
||||
// import { client } from "../../graphql/client";
|
||||
// import { QUERY_BODYSHOP } from "../../graphql/bodyshop.queries";
|
||||
|
||||
// export function* onEmailSignInStart() {
|
||||
// yield takeLatest(UserActionTypes.EMAIL_SIGN_IN_START, signInWithEmail);
|
||||
// }
|
||||
// export function* signInWithEmail({ payload: { email, password } }) {
|
||||
// try {
|
||||
// //logImEXEvent("redux_sign_in_attempt", { user: email });
|
||||
// const { user } = yield auth.signInWithEmailAndPassword(email, password);
|
||||
// yield put(
|
||||
// signInSuccess({
|
||||
// uid: user.uid,
|
||||
// email: user.email,
|
||||
// displayName: user.displayName,
|
||||
// photoURL: user.photoURL,
|
||||
// authorized: true,
|
||||
// })
|
||||
// );
|
||||
// } catch (error) {
|
||||
// yield put(signInFailure(error));
|
||||
// //logImEXEvent("redux_sign_in_failure", { user: email, error });
|
||||
// }
|
||||
// }
|
||||
|
||||
// export function* onCheckUserSession() {
|
||||
// yield takeLatest(UserActionTypes.CHECK_USER_SESSION, isUserAuthenticated);
|
||||
// }
|
||||
// export function* isUserAuthenticated() {
|
||||
// try {
|
||||
// //logImEXEvent("redux_auth_check");
|
||||
|
||||
// const user = yield getCurrentUser();
|
||||
// if (!user) {
|
||||
// yield put(unauthorizedUser());
|
||||
// return;
|
||||
// }
|
||||
|
||||
// yield put(
|
||||
// signInSuccess({
|
||||
// uid: user.uid,
|
||||
// email: user.email,
|
||||
// displayName: user.displayName,
|
||||
// photoURL: user.photoURL,
|
||||
// authorized: true,
|
||||
// })
|
||||
// );
|
||||
// } catch (error) {
|
||||
// yield put(signInFailure(error));
|
||||
// }
|
||||
// }
|
||||
// export function* onSignOutStart() {
|
||||
// yield takeLatest(UserActionTypes.SIGN_OUT_START, signOutStart);
|
||||
// }
|
||||
// export function* signOutStart() {
|
||||
// try {
|
||||
// //logImEXEvent("redux_sign_out");
|
||||
|
||||
// yield auth.signOut();
|
||||
// yield put(signOutSuccess());
|
||||
// } catch (error) {
|
||||
// yield put(signOutFailure(error.message));
|
||||
// }
|
||||
// }
|
||||
|
||||
// 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* onSignInSuccess() {
|
||||
// yield takeLatest(UserActionTypes.SIGN_IN_SUCCESS, signInSuccessSaga);
|
||||
// }
|
||||
|
||||
// export function* signInSuccessSaga({ payload }) {
|
||||
// try {
|
||||
// const shop = yield client.query({ query: QUERY_BODYSHOP });
|
||||
|
||||
// yield put(setBodyshop(shop.data.bodyshops[0]));
|
||||
// } catch (error) {
|
||||
// console.log("UH-OH. Couldn't get shop details.", error);
|
||||
// }
|
||||
// }
|
||||
|
||||
// export function* onSendPasswordResetStart() {
|
||||
// yield takeLatest(
|
||||
// UserActionTypes.SEND_PASSWORD_RESET_EMAIL_START,
|
||||
// sendPasswordResetEmail
|
||||
// );
|
||||
// }
|
||||
// export function* sendPasswordResetEmail({ payload }) {
|
||||
// try {
|
||||
// yield auth.sendPasswordResetEmail(payload, {
|
||||
// url: "https://imex.online/passwordreset",
|
||||
// });
|
||||
// yield put(sendPasswordResetSuccess());
|
||||
// } 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) {
|
||||
// yield put(validatePasswordResetFailure(error.message));
|
||||
// }
|
||||
// }
|
||||
|
||||
export function* appSagas() {
|
||||
yield all([
|
||||
// call(onEmailSignInStart),
|
||||
// call(onCheckUserSession),
|
||||
// call(onSignOutStart),
|
||||
// call(onUpdateUserDetails),
|
||||
// call(onSignInSuccess),
|
||||
// call(onSendPasswordResetStart),
|
||||
// call(onValidatePasswordResetStart),
|
||||
]);
|
||||
}
|
||||
16
redux/app/app.selectors.js
Normal file
16
redux/app/app.selectors.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { createSelector } from "reselect";
|
||||
|
||||
const selectApp = (state) => state.app;
|
||||
|
||||
export const selectCurrentCameraJobId = createSelector(
|
||||
[selectApp],
|
||||
(user) => app.cameraJobId
|
||||
);
|
||||
export const selectDocumentUploadInProgress = createSelector(
|
||||
[selectApp],
|
||||
(user) => app.documentUploadInProgress
|
||||
);
|
||||
export const selectDocumentUploadError = createSelector(
|
||||
[selectApp],
|
||||
(user) => app.documentUploadError
|
||||
);
|
||||
7
redux/app/app.types.js
Normal file
7
redux/app/app.types.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const AppActionTypes = {
|
||||
SET_CAMERA_JOB_ID: "SET_CAMERA_JOB_ID",
|
||||
DOCUMENT_UPLOAD_START: "DOCUMENT_UPLOAD_START",
|
||||
DOCUMNET_UPLOAD_SUCCESS: "DOCUMNET_UPLOAD_SUCCESS",
|
||||
DOCUMENT_UPLOAD_FAILURE: "DOCUMENT_UPLOAD_FAILURE",
|
||||
};
|
||||
export default AppActionTypes;
|
||||
@@ -1,30 +1,21 @@
|
||||
import AsyncStorage from "@react-native-community/async-storage";
|
||||
import { combineReducers } from "redux";
|
||||
import { persistReducer } from "redux-persist";
|
||||
import AsyncStorage from "@react-native-community/async-storage";
|
||||
|
||||
import appReducer from "./app/app.reducer";
|
||||
import userReducer from "./user/user.reducer";
|
||||
// import messagingReducer from "./messaging/messaging.reducer";
|
||||
// import emailReducer from "./email/email.reducer";
|
||||
// import modalsReducer from "./modals/modals.reducer";
|
||||
// import applicationReducer from "./application/application.reducer";
|
||||
// import techReducer from "./tech/tech.reducer";
|
||||
|
||||
const persistConfig = {
|
||||
key: "root",
|
||||
storage: AsyncStorage,
|
||||
whitelist: [],
|
||||
blacklist: ["user"],
|
||||
blacklist: ["user", "app"],
|
||||
// whitelist: ["messaging", "tech", "application"],
|
||||
// blacklist: ["user", "email", "modals"],
|
||||
};
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
user: userReducer,
|
||||
// messaging: messagingReducer,
|
||||
// email: emailReducer,
|
||||
// modals: modalsReducer,
|
||||
// application: applicationReducer,
|
||||
// tech: techReducer,
|
||||
app: appReducer,
|
||||
});
|
||||
|
||||
export default persistReducer(persistConfig, rootReducer);
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
import { all, call } from "redux-saga/effects";
|
||||
|
||||
import { appSagas } from "./app/app.sagas";
|
||||
import { userSagas } from "./user/user.sagas";
|
||||
// import { messagingSagas } from "./messaging/messaging.sagas";
|
||||
// import { emailSagas } from "./email/email.sagas";
|
||||
// import { modalsSagas } from "./modals/modals.sagas";
|
||||
// import { applicationSagas } from "./application/application.sagas";
|
||||
// import { techSagas } from "./tech/tech.sagas";
|
||||
|
||||
export default function* rootSaga() {
|
||||
yield all([
|
||||
call(userSagas),
|
||||
// call(messagingSagas),
|
||||
// call(emailSagas),
|
||||
// call(modalsSagas),
|
||||
// call(applicationSagas),
|
||||
// call(techSagas),
|
||||
]);
|
||||
yield all([call(userSagas), call(appSagas)]);
|
||||
}
|
||||
|
||||
@@ -10,14 +10,23 @@ const sagaMiddleWare = createSagaMiddleware();
|
||||
|
||||
const middlewares = [sagaMiddleWare];
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
middlewares.push(
|
||||
createLogger({
|
||||
collapsed: true,
|
||||
})
|
||||
);
|
||||
middlewares
|
||||
.push
|
||||
// createLogger({
|
||||
// collapsed: true,
|
||||
// })
|
||||
();
|
||||
}
|
||||
|
||||
const enhancer = compose(
|
||||
//Add in for React Native Debugger.
|
||||
const composeEnhancers =
|
||||
typeof window === "object" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
||||
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
|
||||
// Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize...
|
||||
})
|
||||
: compose;
|
||||
|
||||
const enhancer = composeEnhancers(
|
||||
applyMiddleware(...middlewares)
|
||||
// other store enhancers if any
|
||||
);
|
||||
|
||||
@@ -106,7 +106,7 @@ export function* signInSuccessSaga({ payload }) {
|
||||
|
||||
yield put(setBodyshop(shop.data.bodyshops[0]));
|
||||
} catch (error) {
|
||||
console.log("UHOH. Couldn't get shop details.", error);
|
||||
console.log("UH-OH. Couldn't get shop details.", error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user