From 255f327c72dd980f3be94c70849ab9d3793a013e Mon Sep 17 00:00:00 2001 From: lumi-tip Date: Sun, 22 Sep 2024 22:16:58 -0400 Subject: [PATCH 1/8] small changes --- src/common/components/PricingCard.jsx | 1 + src/pages/checkout/index.jsx | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/components/PricingCard.jsx b/src/common/components/PricingCard.jsx index d95a09bb2..543e3da0b 100644 --- a/src/common/components/PricingCard.jsx +++ b/src/common/components/PricingCard.jsx @@ -105,6 +105,7 @@ export default function PricingCard({ item, courseData, isFetching, relatedSubsc const alreadyHaveIt = relatedSubscription?.plans?.[0]?.slug === item?.plan_slug; const handlePlan = () => { + console.log('EJECUTE'); const langPath = lang === 'en' ? '' : `/${lang}`; const qs = parseQuerys({ plan: selectedFinancing?.plan_slug || item?.plan_slug, diff --git a/src/pages/checkout/index.jsx b/src/pages/checkout/index.jsx index 3eaf48843..daa47465c 100644 --- a/src/pages/checkout/index.jsx +++ b/src/pages/checkout/index.jsx @@ -113,6 +113,8 @@ function Checkout() { const accessToken = getStorageItem('accessToken'); const tokenExists = accessToken !== null && accessToken !== undefined && accessToken.length > 5; const { coupon: couponQuery } = query; + const { course } = router.query; + const [coupon] = usePersistentBySession('coupon', ''); const couponValue = useMemo(() => { @@ -121,7 +123,6 @@ function Checkout() { return couponString || formatedCouponQuery; }, [coupon, couponQuery]); - const { course } = router.query; const courseChoosed = course; const queryPlanExists = planFormated !== undefined && planFormated?.length > 0; From 5d833d8efa3783bdec31f358d2ed55f25becf10f Mon Sep 17 00:00:00 2001 From: lumi-tip Date: Tue, 24 Sep 2024 15:57:34 -0400 Subject: [PATCH 2/8] small chagnes --- src/common/components/MktShowPrices.jsx | 5 ----- src/common/components/PricingCard.jsx | 2 -- src/js_modules/checkout/ChooseYourClass.jsx | 1 + src/pages/bootcamp/[course_slug].jsx | 5 +---- src/pages/checkout/index.jsx | 19 +++++++++++++++++++ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/common/components/MktShowPrices.jsx b/src/common/components/MktShowPrices.jsx index a880f3b49..c32270ef3 100644 --- a/src/common/components/MktShowPrices.jsx +++ b/src/common/components/MktShowPrices.jsx @@ -161,14 +161,9 @@ function MktShowPrices({ id, externalPlanProps, cohortId, title, gridColumn1, gr firstSectionTitle={t('subscription.upgrade-modal.subscription')} secondSectionTitle={t('subscription.upgrade-modal.finance')} handleUpgrade={(item) => { - const period = item?.period; - const querys = parseQuerys({ plan: item?.plan_slug, plan_id: item?.plan_id, - price: item?.price, - period, - cohort: cohortId, coupon: queryCoupon || coupon, }); router.push(`/checkout${querys}`); diff --git a/src/common/components/PricingCard.jsx b/src/common/components/PricingCard.jsx index 543e3da0b..2be53c333 100644 --- a/src/common/components/PricingCard.jsx +++ b/src/common/components/PricingCard.jsx @@ -110,8 +110,6 @@ export default function PricingCard({ item, courseData, isFetching, relatedSubsc const qs = parseQuerys({ plan: selectedFinancing?.plan_slug || item?.plan_slug, plan_id: selectedFinancing?.plan_id || item?.plan_id, - price: selectedFinancing?.price || item?.price, - period: selectedFinancing?.period || item?.period, coupon: coupon || queryCoupon, cohort: courseData?.cohort?.id, }); diff --git a/src/js_modules/checkout/ChooseYourClass.jsx b/src/js_modules/checkout/ChooseYourClass.jsx index 6e9028903..5fe8fbaa9 100644 --- a/src/js_modules/checkout/ChooseYourClass.jsx +++ b/src/js_modules/checkout/ChooseYourClass.jsx @@ -87,6 +87,7 @@ function ChooseYourClass({ }; }); + //SI NO AÑADO COHORTS ENTONCES TENGO QUE SABER LA IMPORTANCIA const filteredCohorts = Array.isArray(formatedData) ? formatedData.filter((item) => item?.never_ends === false) : null; setCohorts({ cohorts: filteredCohorts, diff --git a/src/pages/bootcamp/[course_slug].jsx b/src/pages/bootcamp/[course_slug].jsx index 19ed60506..cf7befc04 100644 --- a/src/pages/bootcamp/[course_slug].jsx +++ b/src/pages/bootcamp/[course_slug].jsx @@ -207,10 +207,7 @@ function Page({ data }) { plan: featuredPlanToEnroll?.plan_slug, plan_id: featuredPlanToEnroll?.plan_id, has_available_cohorts: planData?.has_available_cohorts, - price: featuredPlanToEnroll?.price, - period: featuredPlanToEnroll?.period, - cohort: cohortId, - }) : `?plan=${data?.plan_slug}&cohort=${cohortId}`; + }) : `?plan=${data?.plan_slug}`; const getPlanPrice = () => { if (featuredPlanToEnroll?.plan_slug) { diff --git a/src/pages/checkout/index.jsx b/src/pages/checkout/index.jsx index daa47465c..c586bf1a4 100644 --- a/src/pages/checkout/index.jsx +++ b/src/pages/checkout/index.jsx @@ -100,6 +100,8 @@ function Checkout() { const cohorts = cohortsData?.cohorts; + console.log(checkoutData); + axiosInstance.defaults.headers.common['Accept-Language'] = router.locale; const { user, isAuthenticated, isLoading } = useAuth(); const { userSession } = useSession(); @@ -162,6 +164,23 @@ function Checkout() { }; const handleCoupon = (coupons, actions) => { + // Verificar si el cupón ingresado ya está aplicado + const alreadyAppliedCoupon = selfAppliedCoupon?.slug === discountCode || selfAppliedCoupon?.slug === couponValue; + + if (alreadyAppliedCoupon) { + toast({ + position: 'top', + title: t('alert-message:coupon-already-applied'), + status: 'info', + duration: 4000, + isClosable: true, + }); + if (actions) { + actions.setSubmitting(false); + } + return; + } + bc.payment({ coupons: [coupons || discountCode], plan: planFormated, From e9c1d094680038dfc6314c6e7360c23cf4ace2cc Mon Sep 17 00:00:00 2001 From: lumi-tip Date: Tue, 24 Sep 2024 16:42:40 -0400 Subject: [PATCH 3/8] small change --- src/common/components/MktShowPrices.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/components/MktShowPrices.jsx b/src/common/components/MktShowPrices.jsx index c32270ef3..400b6e044 100644 --- a/src/common/components/MktShowPrices.jsx +++ b/src/common/components/MktShowPrices.jsx @@ -164,6 +164,7 @@ function MktShowPrices({ id, externalPlanProps, cohortId, title, gridColumn1, gr const querys = parseQuerys({ plan: item?.plan_slug, plan_id: item?.plan_id, + cohort: cohortId, coupon: queryCoupon || coupon, }); router.push(`/checkout${querys}`); From e8e647651c259fb0acc5cae6350679a6f5d905fa Mon Sep 17 00:00:00 2001 From: lumi-tip Date: Wed, 25 Sep 2024 15:09:25 -0400 Subject: [PATCH 4/8] :recycle: small refactor of router.querys and :bug: bug solving realted to usePersistent and coupons --- public/locales/en/signup.json | 3 ++- public/locales/es/signup.json | 3 ++- src/common/hooks/usePersistent.js | 13 +++++++++---- src/js_modules/checkout/ChooseYourClass.jsx | 1 - src/js_modules/checkout/Summary.jsx | 2 -- src/pages/bootcamp/[course_slug].jsx | 3 ++- src/pages/checkout/index.jsx | 8 ++------ 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/public/locales/en/signup.json b/public/locales/en/signup.json index 0bcbaeecd..60f77b131 100644 --- a/public/locales/en/signup.json +++ b/public/locales/en/signup.json @@ -158,7 +158,8 @@ "validate-email-title": "Verify your email", "validate-email-description": "We sent a confirmation email to: {{email}}, please check your email and click on the confirmation link.", "email-sent-to": "We sent you a confirmation email to {{email}}!", - "email-already-sent": "You have a pending invitation sent less than 1 day ago, check your email" + "email-already-sent": "You have a pending invitation sent less than 1 day ago, check your email", + "coupon-already-applied": "Coupon already applied" }, "alert-message-validate-email": { "title": "Verify email", diff --git a/public/locales/es/signup.json b/public/locales/es/signup.json index 7732374cb..408f651b9 100644 --- a/public/locales/es/signup.json +++ b/public/locales/es/signup.json @@ -158,7 +158,8 @@ "validate-email-title": "Verifique su correo electrónico", "validate-email-description": "Enviamos un correo electrónico de confirmación a: {{email}}, verifica tu correo electrónico y haz clic en el enlace de confirmación.", "email-sent-to": "Enviamos un correo electrónico de confirmación a {{email}}!", - "email-already-sent": "Tienes una invitación pendiente enviada hace menos de 1 día, revisa tu correo" + "email-already-sent": "Tienes una invitación pendiente enviada hace menos de 1 día, revisa tu correo", + "coupon-already-applied": "El cupón ya esta siendo aplicado" }, "alert-message-validate-email": { "title": "Verificar correo electrónico", diff --git a/src/common/hooks/usePersistent.js b/src/common/hooks/usePersistent.js index 43950060c..bb590925e 100644 --- a/src/common/hooks/usePersistent.js +++ b/src/common/hooks/usePersistent.js @@ -23,9 +23,13 @@ const usePersistent = (key, initialValue) => { const usePersistentBySession = (key, initialValue) => { const getStoredValues = useMemo(() => { const item = isWindow ? window.sessionStorage.getItem(key) : null; - const isObject = typeof item === 'object'; - const objectValue = JSON.parse(item) || initialValue; - return isObject ? objectValue : item || initialValue; + if (item === null) return initialValue; + + if (item.startsWith('{') || item.startsWith('[')) { + return JSON.parse(item); + } + + return item; }, [key, initialValue]); const [storedValue, setStoredValue] = useState(getStoredValues); @@ -33,7 +37,8 @@ const usePersistentBySession = (key, initialValue) => { const setValue = (value) => { try { setStoredValue(value); - window.sessionStorage.setItem(key, JSON.stringify(value)); + const valueToStore = typeof value === 'object' ? JSON.stringify(value) : value; + window.sessionStorage.setItem(key, valueToStore); } catch (error) { console.error('usePersistent_error:', error); } diff --git a/src/js_modules/checkout/ChooseYourClass.jsx b/src/js_modules/checkout/ChooseYourClass.jsx index 5fe8fbaa9..6e9028903 100644 --- a/src/js_modules/checkout/ChooseYourClass.jsx +++ b/src/js_modules/checkout/ChooseYourClass.jsx @@ -87,7 +87,6 @@ function ChooseYourClass({ }; }); - //SI NO AÑADO COHORTS ENTONCES TENGO QUE SABER LA IMPORTANCIA const filteredCohorts = Array.isArray(formatedData) ? formatedData.filter((item) => item?.never_ends === false) : null; setCohorts({ cohorts: filteredCohorts, diff --git a/src/js_modules/checkout/Summary.jsx b/src/js_modules/checkout/Summary.jsx index bb99c5fde..4e1a0283a 100644 --- a/src/js_modules/checkout/Summary.jsx +++ b/src/js_modules/checkout/Summary.jsx @@ -194,8 +194,6 @@ function Summary() { query: { ...router.query, plan_id: selectedPlanCheckoutData?.plan_id, - price: selectedPlanCheckoutData?.price, - period: selectedPlanCheckoutData?.period, }, }); } else { diff --git a/src/pages/bootcamp/[course_slug].jsx b/src/pages/bootcamp/[course_slug].jsx index cf7befc04..e0aa35849 100644 --- a/src/pages/bootcamp/[course_slug].jsx +++ b/src/pages/bootcamp/[course_slug].jsx @@ -207,7 +207,8 @@ function Page({ data }) { plan: featuredPlanToEnroll?.plan_slug, plan_id: featuredPlanToEnroll?.plan_id, has_available_cohorts: planData?.has_available_cohorts, - }) : `?plan=${data?.plan_slug}`; + cohort: cohortId, + }) : `?plan=${data?.plan_slug}&cohort=${cohortId}`; const getPlanPrice = () => { if (featuredPlanToEnroll?.plan_slug) { diff --git a/src/pages/checkout/index.jsx b/src/pages/checkout/index.jsx index c586bf1a4..96d36e9c6 100644 --- a/src/pages/checkout/index.jsx +++ b/src/pages/checkout/index.jsx @@ -100,8 +100,6 @@ function Checkout() { const cohorts = cohortsData?.cohorts; - console.log(checkoutData); - axiosInstance.defaults.headers.common['Accept-Language'] = router.locale; const { user, isAuthenticated, isLoading } = useAuth(); const { userSession } = useSession(); @@ -116,6 +114,7 @@ function Checkout() { const tokenExists = accessToken !== null && accessToken !== undefined && accessToken.length > 5; const { coupon: couponQuery } = query; const { course } = router.query; + const courseChoosed = course; const [coupon] = usePersistentBySession('coupon', ''); @@ -125,8 +124,6 @@ function Checkout() { return couponString || formatedCouponQuery; }, [coupon, couponQuery]); - const courseChoosed = course; - const queryPlanExists = planFormated !== undefined && planFormated?.length > 0; const queryMentorshipServiceSlugExists = mentorshipServiceSetSlug && mentorshipServiceSetSlug?.length > 0; const queryEventTypeSetSlugExists = eventTypeSetSlug && eventTypeSetSlug?.length > 0; @@ -164,13 +161,12 @@ function Checkout() { }; const handleCoupon = (coupons, actions) => { - // Verificar si el cupón ingresado ya está aplicado const alreadyAppliedCoupon = selfAppliedCoupon?.slug === discountCode || selfAppliedCoupon?.slug === couponValue; if (alreadyAppliedCoupon) { toast({ position: 'top', - title: t('alert-message:coupon-already-applied'), + title: t('signup:alert-message.coupon-already-applied'), status: 'info', duration: 4000, isClosable: true, From 0dabc1917b401ef4454b0d6409892814fe9c6ec8 Mon Sep 17 00:00:00 2001 From: lumi-tip Date: Wed, 25 Sep 2024 16:59:26 -0400 Subject: [PATCH 5/8] Small change --- src/common/hooks/usePersistent.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/common/hooks/usePersistent.js b/src/common/hooks/usePersistent.js index bb590925e..1c8298385 100644 --- a/src/common/hooks/usePersistent.js +++ b/src/common/hooks/usePersistent.js @@ -22,6 +22,8 @@ const usePersistent = (key, initialValue) => { const usePersistentBySession = (key, initialValue) => { const getStoredValues = useMemo(() => { + if (typeof window === 'undefined') return initialValue; + const item = isWindow ? window.sessionStorage.getItem(key) : null; if (item === null) return initialValue; @@ -34,14 +36,12 @@ const usePersistentBySession = (key, initialValue) => { const [storedValue, setStoredValue] = useState(getStoredValues); + console.log(storedValue); + const setValue = (value) => { - try { - setStoredValue(value); - const valueToStore = typeof value === 'object' ? JSON.stringify(value) : value; - window.sessionStorage.setItem(key, valueToStore); - } catch (error) { - console.error('usePersistent_error:', error); - } + setStoredValue(value); + const valueToStore = typeof value === 'object' ? JSON.stringify(value) : value; + window.sessionStorage.setItem(key, valueToStore); }; return [storedValue, setValue]; }; From 3893d7bac66431efab9a7846b0ea4f6fce3289a3 Mon Sep 17 00:00:00 2001 From: lumi-tip Date: Wed, 25 Sep 2024 16:59:52 -0400 Subject: [PATCH 6/8] Small change --- src/common/hooks/usePersistent.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/common/hooks/usePersistent.js b/src/common/hooks/usePersistent.js index 1c8298385..2a8964b8b 100644 --- a/src/common/hooks/usePersistent.js +++ b/src/common/hooks/usePersistent.js @@ -36,8 +36,6 @@ const usePersistentBySession = (key, initialValue) => { const [storedValue, setStoredValue] = useState(getStoredValues); - console.log(storedValue); - const setValue = (value) => { setStoredValue(value); const valueToStore = typeof value === 'object' ? JSON.stringify(value) : value; From d553ad632406dd1557a4fa08b6c972f8de82c783 Mon Sep 17 00:00:00 2001 From: lumi-tip Date: Wed, 25 Sep 2024 18:56:36 -0400 Subject: [PATCH 7/8] small change to usePersistent --- src/common/hooks/usePersistent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/hooks/usePersistent.js b/src/common/hooks/usePersistent.js index 2a8964b8b..efdfa07b9 100644 --- a/src/common/hooks/usePersistent.js +++ b/src/common/hooks/usePersistent.js @@ -41,7 +41,7 @@ const usePersistentBySession = (key, initialValue) => { const valueToStore = typeof value === 'object' ? JSON.stringify(value) : value; window.sessionStorage.setItem(key, valueToStore); }; - return [storedValue, setValue]; + return [storedValue !== undefined ? storedValue : initialValue, setValue]; }; export { From c28d4ab964c734c705ddbf7779ca9569732b3771 Mon Sep 17 00:00:00 2001 From: Tomas Gonzalez <56565994+tommygonzaleza@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:30:48 -0400 Subject: [PATCH 8/8] Update PricingCard.jsx --- src/common/components/PricingCard.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/components/PricingCard.jsx b/src/common/components/PricingCard.jsx index 2be53c333..437f06df1 100644 --- a/src/common/components/PricingCard.jsx +++ b/src/common/components/PricingCard.jsx @@ -105,7 +105,6 @@ export default function PricingCard({ item, courseData, isFetching, relatedSubsc const alreadyHaveIt = relatedSubscription?.plans?.[0]?.slug === item?.plan_slug; const handlePlan = () => { - console.log('EJECUTE'); const langPath = lang === 'en' ? '' : `/${lang}`; const qs = parseQuerys({ plan: selectedFinancing?.plan_slug || item?.plan_slug,