Skip to content

Commit

Permalink
Merge pull request leandrowd#101 from the-container-store/feature/180…
Browse files Browse the repository at this point in the history
…438268-pop-login

180438268 - When only POP is Available then redirect to Checkout Page
  • Loading branch information
PradeepChada authored Dec 6, 2021
2 parents f02fcb7 + 85567c7 commit ea8416f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/pages/pop-signin/PopSignin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ const PopSignin = ({ history }) => {
const nextButtonHandler = () => {
if (email.trim() !== '') {
if (validateEmail(email.trim())) {
dispatch(fetchPOPAccountDetailsByEmail(email.trim()));
setShowForm((prevState) => !prevState);
dispatch(fetchPOPAccountDetailsByEmail(email.trim(), history));
} else {
dispatch(actions.failure(popAccountNotFound.email));
}
}
if (phone.trim() !== '') {
dispatch(fetchPOPAccountDetailsByPhone(getDigitOnly(phone.trim())));
dispatch(
fetchPOPAccountDetailsByPhone(getDigitOnly(phone.trim()), history)
);
setShowForm((prevState) => !prevState);
}
};
Expand All @@ -68,6 +70,7 @@ const PopSignin = ({ history }) => {
setPOPAccount(getFirstPOPMemeber(accountDetails).emailAddress);
}
}, [accountDetails]);

useEffect(() => {
if (error != null) {
setShowForm(true);
Expand Down
22 changes: 19 additions & 3 deletions src/slices/pop.slice.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as popService from '../services/popAccount.service';
import { createSlice } from '@reduxjs/toolkit';
import { popAccountNotFound } from '../constants/errorMessages';
import { getFirstPOPMemeber } from '../utils/skuHelpers';
const INITIAL_STATE = {
loading: false,
accountDetails: [],
Expand Down Expand Up @@ -34,7 +35,7 @@ const popAccountSlice = createSlice({

export const actions = popAccountSlice.actions;

export const fetchPOPAccountDetailsByPhone = (phone) => (dispatch) => {
export const fetchPOPAccountDetailsByPhone = (phone, history) => (dispatch) => {
dispatch(actions.loading());
popService
.getAccountByPhone(phone)
Expand All @@ -43,14 +44,22 @@ export const fetchPOPAccountDetailsByPhone = (phone) => (dispatch) => {
dispatch(actions.failure(popAccountNotFound.phone));
} else {
dispatch(actions.success(res?.data?._embedded.customers));
if (res?.data?._embedded.customers.length === 1) {
dispatch(
setMainPOPAccount(
getFirstPOPMemeber(res?.data?._embedded.customers).emailAddress
)
);
history.push('/sku-checkout');
}
}
})
.catch((err) => {
dispatch(actions.failure(popAccountNotFound.unknown));
});
};

export const fetchPOPAccountDetailsByEmail = (email) => (dispatch) => {
export const fetchPOPAccountDetailsByEmail = (email, history) => (dispatch) => {
dispatch(actions.loading());
popService
.getAccountByEmail(email)
Expand All @@ -59,6 +68,14 @@ export const fetchPOPAccountDetailsByEmail = (email) => (dispatch) => {
dispatch(actions.failure(popAccountNotFound.email));
} else {
dispatch(actions.success(res?.data?._embedded.customers));
if (res?.data?._embedded.customers.length === 1) {
dispatch(
setMainPOPAccount(
getFirstPOPMemeber(res?.data?._embedded.customers).emailAddress
)
);
history.push('/sku-checkout');
}
}
})
.catch((err) => {
Expand All @@ -71,4 +88,3 @@ export const setMainPOPAccount = (account) => (dispatch) => {
};

export default popAccountSlice;

0 comments on commit ea8416f

Please sign in to comment.