diff --git a/src/common/services/breathecode.js b/src/common/services/breathecode.js index 5b7c812bd..761f04fdc 100644 --- a/src/common/services/breathecode.js +++ b/src/common/services/breathecode.js @@ -287,6 +287,7 @@ const breathecode = { const qs = parseQuerys(query); return { lead: (data) => axios.post(`${url}/lead${qs}`, data), + courses: () => axios.get(`${url}/course${qs}`), }; }, @@ -325,7 +326,6 @@ const breathecode = { return { checking: (data) => axios.put(`${url}/checking${qs}`, data), subscriptions: () => axios.get(`${url}/me/subscription${qs}`), - courses: () => axios.get(`${host}/marketing/course${qs}`), pay: (data) => breathecode.post(`${url}/pay${qs}`, data), addCard: (data) => breathecode.post(`${url}/card${qs}`, data), cancelSubscription: (id) => axios.put(`${url}/subscription/${id}/cancel${qs}`), diff --git a/src/js_modules/chooseProgram/index.jsx b/src/js_modules/chooseProgram/index.jsx index 0b04be4e0..4eba9cac1 100644 --- a/src/js_modules/chooseProgram/index.jsx +++ b/src/js_modules/chooseProgram/index.jsx @@ -23,13 +23,12 @@ function ChooseProgram({ chooseList, handleChoose, setLateModalProps }) { const [marketingCursesList, setMarketingCursesList] = useState([]); const [showFinished, setShowFinished] = useState(false); const [upgradeModalIsOpen, setUpgradeModalIsOpen] = useState(false); - const activeCohorts = handlers.getActiveCohorts(chooseList); - const finishedCohorts = handlers.getCohortsFinished(chooseList); const { featuredColor } = useStyle(); const router = useRouter(); - const cardColumnSize = 'repeat(auto-fill, minmax(17rem, 1fr))'; - const activeSubscriptionCohorts = activeCohorts?.length > 0 ? activeCohorts.map((item) => { + + const finishedCohorts = handlers.getCohortsFinished(chooseList); + const activeCohorts = handlers.getActiveCohorts(chooseList).map((item) => { const cohort = item?.cohort; const currentCohortProps = programsList[cohort.slug]; return ({ @@ -43,18 +42,14 @@ function ChooseProgram({ chooseList, handleChoose, setLateModalProps }) { all_subscriptions: currentCohortProps?.all_subscriptions, subscription_exists: currentCohortProps?.subscription !== null || currentCohortProps?.plan_financing !== null, }); - }) : []; + }); - const marketingCourses = marketingCursesList?.length > 0 ? marketingCursesList.filter( - (item) => !activeSubscriptionCohorts.some( - (activeCohort) => activeCohort?.all_subscriptions?.some( - (sb) => sb?.selected_cohort_set?.slug === item?.slug, - ), - ) && item?.course_translation?.title, - ) : []; + const hasNonSaasCourse = chooseList.some(({ cohort }) => !cohort.available_as_saas); - const isNotAvailableForMktCourses = activeSubscriptionCohorts.length > 0 && activeSubscriptionCohorts.some( - (item) => item?.cohort?.available_as_saas === false, + const marketingCourses = marketingCursesList.filter( + (item) => !activeCohorts.some( + ({ cohort }) => cohort.slug === item?.cohort?.slug, + ) && item?.course_translation?.title, ); useEffect(() => { @@ -62,46 +57,52 @@ function ChooseProgram({ chooseList, handleChoose, setLateModalProps }) { }, [router.locale]); useEffect(() => { - bc.payment({ academy: WHITE_LABEL_ACADEMY }).courses() + bc.marketing({ academy: WHITE_LABEL_ACADEMY }).courses() .then(({ data }) => { setMarketingCursesList(data); }); }, [router?.locale]); + const filterForNonSaasStudents = (course) => { + if (!hasNonSaasCourse) return true; + + return course.plan_slug === process.env.BASE_PLAN; + }; + return ( <> - {activeSubscriptionCohorts.length > 0 && ( - - - {t('your-active-programs')} - - - + {activeCohorts.length > 0 && ( + <> + + + {t('your-active-programs')} + + + + 1 ? cardColumnSize : '', md: cardColumnSize }} + height="auto" + gridGap="4rem" + > + {activeCohorts.map((item) => ( + setUpgradeModalIsOpen(true)} + setLateModalProps={setLateModalProps} + /> + ))} + + )} setUpgradeModalIsOpen(false)} /> - {activeSubscriptionCohorts.length > 0 && ( - 1 ? cardColumnSize : '', md: cardColumnSize }} - height="auto" - gridGap="4rem" - > - {activeSubscriptionCohorts.map((item) => ( - setUpgradeModalIsOpen(true)} - setLateModalProps={setLateModalProps} - /> - ))} - - )} - {!isNotAvailableForMktCourses && marketingCourses?.length > 0 && marketingCourses.some((l) => l?.course_translation?.title) && ( + {marketingCourses?.length > 0 && ( <> @@ -115,7 +116,7 @@ function ChooseProgram({ chooseList, handleChoose, setLateModalProps }) { height="auto" gridGap="4rem" > - {marketingCourses.map((item) => ( + {marketingCourses.filter(filterForNonSaasStudents).map((item) => ( )} - { - finishedCohorts.length > 0 && ( - <> - 0 && ( + <> + + - - {isPlural(finishedCohorts) - ? t('finished.plural', { finishedCohorts: finishedCohorts.length }) - : t('finished.singular', { finishedCohorts: finishedCohorts.length })} - - setShowFinished(!showFinished)} - > - {showFinished ? t('finished.hide') : t('finished.show')} - - - - + setShowFinished(!showFinished)} > - {showFinished && finishedCohorts.map((item) => ( - setUpgradeModalIsOpen(true)} - /> - ))} - - - ) - } + {showFinished ? t('finished.hide') : t('finished.show')} + + + + + {showFinished && finishedCohorts.map((item) => ( + setUpgradeModalIsOpen(true)} + /> + ))} + + + )} ); }