Skip to content

Commit

Permalink
remove location from signup hook
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomm19 committed Oct 29, 2024
1 parent 43d13c5 commit b6ce61c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 51 deletions.
8 changes: 1 addition & 7 deletions src/common/store/actions/signupAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useToast } from '@chakra-ui/react';
import useTranslation from 'next-translate/useTranslation';
import { useRouter } from 'next/router';
import {
NEXT_STEP, PREV_STEP, HANDLE_STEP, SET_DATE_PROPS, SET_CHECKOUT_DATA, SET_LOCATION, SET_PAYMENT_INFO,
NEXT_STEP, PREV_STEP, HANDLE_STEP, SET_DATE_PROPS, SET_CHECKOUT_DATA, SET_PAYMENT_INFO,
SET_PLAN_DATA, SET_LOADER, SET_PLAN_CHECKOUT_DATA, SET_PLAN_PROPS, SET_COHORT_PLANS, TOGGLE_IF_ENROLLED,
PREPARING_FOR_COHORT, SET_SERVICE_PROPS, SET_SELECTED_SERVICE, SET_PAYMENT_METHODS, SET_PAYMENT_STATUS,
SET_SUBMITTING_CARD, SET_SUBMITTING_PAYMENT, SET_SELF_APPLIED_COUPON,
Expand Down Expand Up @@ -72,11 +72,6 @@ const useSignup = () => {
payload,
});

const setLocation = (payload) => dispatch({
type: SET_LOCATION,
payload,
});

const setPaymentInfo = (payload, value) => dispatch({
type: SET_PAYMENT_INFO,
payload,
Expand Down Expand Up @@ -482,7 +477,6 @@ const useSignup = () => {
handleStep,
setDateProps,
setCheckoutData,
setLocation,
setPaymentMethods,
setPaymentStatus,
setIsSubmittingCard,
Expand Down
11 changes: 1 addition & 10 deletions src/common/store/reducers/signupReducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
NEXT_STEP, PREV_STEP, HANDLE_STEP, SET_DATE_PROPS, SET_CHECKOUT_DATA, SET_LOCATION,
NEXT_STEP, PREV_STEP, HANDLE_STEP, SET_DATE_PROPS, SET_CHECKOUT_DATA,
SET_PAYMENT_INFO, SET_PLAN_DATA, SET_LOADER, SET_PLAN_CHECKOUT_DATA, SET_PLAN_PROPS, SET_COHORT_PLANS,
TOGGLE_IF_ENROLLED, SET_SERVICE_PROPS, SET_SELECTED_SERVICE, SET_PAYMENT_METHODS, SET_PAYMENT_STATUS,
SET_SUBMITTING_CARD, SET_SUBMITTING_PAYMENT, SET_SELF_APPLIED_COUPON,
Expand All @@ -9,7 +9,6 @@ const initialState = {
stepIndex: 0,
dateProps: null,
checkoutData: null,
location: null,
paymentInfo: {
card_number: '',
exp: '',
Expand Down Expand Up @@ -83,14 +82,6 @@ const signupReducer = (state = initialState, action) => {
};
}

// location
case SET_LOCATION: {
return {
...state,
location: action.payload,
};
}

// planData
case SET_COHORT_PLANS: {
return {
Expand Down
2 changes: 0 additions & 2 deletions src/common/store/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const PREV_STEP = 'PREV_STEP';
const HANDLE_STEP = 'HANDLE_STEP';
const SET_DATE_PROPS = 'SET_DATE_PROPS';
const SET_CHECKOUT_DATA = 'SET_CHECKOUT_DATA';
const SET_LOCATION = 'SET_LOCATION';
const SET_PAYMENT_INFO = 'SET_PAYMENT_INFO';
const HANDLE_PAYMENT = 'HANDLE_PAYMENT';
const SET_PLAN_DATA = 'SET_PLAN_DATA';
Expand Down Expand Up @@ -37,7 +36,6 @@ export {
HANDLE_STEP,
SET_DATE_PROPS,
SET_CHECKOUT_DATA,
SET_LOCATION,
SET_PAYMENT_INFO,
SET_PAYMENT_STATUS,
SET_SUBMITTING_CARD,
Expand Down
34 changes: 2 additions & 32 deletions src/js_modules/checkout/ChooseYourClass.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ function ChooseYourClass({
const inputRef = useRef();
const buttonRef = useRef();
const GOOGLE_KEY = process.env.GOOGLE_GEO_KEY;
const { isSecondStep, setLocation } = useSignup();
const { isSecondStep } = useSignup();
const { backgroundColor, backgroundColor3 } = useStyle();

const plan = getQueryString('plan');
const planFormated = plan ? encodeURIComponent(plan) : undefined;

const { gmapStatus, geocode, geolocate } = useGoogleMaps(
const { gmapStatus, geocode } = useGoogleMaps(
GOOGLE_KEY,
'places',
);
Expand Down Expand Up @@ -147,36 +147,6 @@ function ChooseYourClass({
}
}, [isSecondStep, gmapStatus]);

useEffect(() => {
const userLocation = localStorage.getItem('user-location');
if (gmapStatus.loaded && GOOGLE_KEY && !userLocation) {
geolocate(GOOGLE_KEY).then(({ data }) => {
if (data) {
setCoords({
latitude: data.location.lat,
longitude: data.location.lng,
});
}

geocode({ location: data.location }).then((results) => {
const loc = {};

results[0].address_components.forEach((comp) => {
if (comp.types.includes('locality')) loc.city = comp.long_name;
if (comp.types.includes('country')) {
loc.country = comp.long_name;
loc.countryShort = comp.short_name;
}
});
localStorage.setItem('user-location', JSON.stringify(loc));
setLocation(loc);
});
});
} else if (userLocation) {
setLocation(JSON.parse(userLocation));
}
}, [gmapStatus]);

return isSecondStep && (
<Box
display="flex"
Expand Down

0 comments on commit b6ce61c

Please sign in to comment.