Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We are still showing the saas courses to graduated students #1605

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/services/breathecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`),
};
},

Expand Down Expand Up @@ -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}`),
Expand Down
201 changes: 100 additions & 101 deletions src/js_modules/chooseProgram/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ({
Expand All @@ -43,65 +42,67 @@ 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(
tommygonzaleza marked this conversation as resolved.
Show resolved Hide resolved
(item) => !activeCohorts.some(
({ cohort }) => cohort.slug === item?.cohort?.slug,
) && item?.course_translation?.title,
);

useEffect(() => {
axiosInstance.defaults.headers.common['Accept-Language'] = router.locale;
}, [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 && (
<Box display="flex" flexDirection={{ base: 'column', md: 'row' }} margin="5rem 0 3rem 0" alignItems="center" gridGap={{ base: '4px', md: '1rem' }}>
<Heading size="sm" width="fit-content" whiteSpace="nowrap">
{t('your-active-programs')}
</Heading>
<Box as="hr" width="100%" margin="0.5rem 0 0 0" />
</Box>
{activeCohorts.length > 0 && (
<>
<Box display="flex" flexDirection={{ base: 'column', md: 'row' }} margin="5rem 0 3rem 0" alignItems="center" gridGap={{ base: '4px', md: '1rem' }}>
<Heading size="sm" width="fit-content" whiteSpace="nowrap">
{t('your-active-programs')}
</Heading>
<Box as="hr" width="100%" margin="0.5rem 0 0 0" />
</Box>
<Box
display="grid"
gridTemplateColumns={{ base: activeCohorts.length > 1 ? cardColumnSize : '', md: cardColumnSize }}
height="auto"
gridGap="4rem"
>
{activeCohorts.map((item) => (
<Programs
key={item?.cohort?.slug}
item={item}
handleChoose={handleChoose}
onOpenModal={() => setUpgradeModalIsOpen(true)}
setLateModalProps={setLateModalProps}
/>
))}
</Box>
</>
)}
<UpgradeAccessModal
isOpen={upgradeModalIsOpen}
onClose={() => setUpgradeModalIsOpen(false)}
/>
{activeSubscriptionCohorts.length > 0 && (
<Box
display="grid"
gridTemplateColumns={{ base: activeSubscriptionCohorts.length > 1 ? cardColumnSize : '', md: cardColumnSize }}
height="auto"
gridGap="4rem"
>
{activeSubscriptionCohorts.map((item) => (
<Programs
key={item?.cohort?.slug}
item={item}
handleChoose={handleChoose}
onOpenModal={() => setUpgradeModalIsOpen(true)}
setLateModalProps={setLateModalProps}
/>
))}
</Box>
)}

{!isNotAvailableForMktCourses && marketingCourses?.length > 0 && marketingCourses.some((l) => l?.course_translation?.title) && (
{marketingCourses?.length > 0 && (
<>
<Box display="flex" flexDirection={{ base: 'column', md: 'row' }} margin="5rem 0 3rem 0" alignItems="center" gridGap={{ base: '4px', md: '1rem' }}>
<Heading size="sm" width="fit-content" whiteSpace="nowrap">
Expand All @@ -115,7 +116,7 @@ function ChooseProgram({ chooseList, handleChoose, setLateModalProps }) {
height="auto"
gridGap="4rem"
>
{marketingCourses.map((item) => (
{marketingCourses.filter(filterForNonSaasStudents).map((item) => (
<ProgramCard
isMarketingCourse
icon="coding"
Expand All @@ -133,67 +134,65 @@ function ChooseProgram({ chooseList, handleChoose, setLateModalProps }) {
</>
)}

{
finishedCohorts.length > 0 && (
<>
<Box
display="flex"
margin="2rem auto"
flexDirection={{ base: 'column', md: 'row' }}
gridGap={{ base: '0', md: '6px' }}
justifyContent="center"
{finishedCohorts.length > 0 && (
<>
<Box
display="flex"
margin="2rem auto"
flexDirection={{ base: 'column', md: 'row' }}
gridGap={{ base: '0', md: '6px' }}
justifyContent="center"
>
<Text
size="md"
>
<Text
size="md"
>
{isPlural(finishedCohorts)
? t('finished.plural', { finishedCohorts: finishedCohorts.length })
: t('finished.singular', { finishedCohorts: finishedCohorts.length })}
</Text>
<Text
as="button"
alignSelf="center"
size="md"
fontWeight="bold"
textAlign="left"
gridGap="10px"
_focus={{
boxShadow: '0 0 0 3px rgb(66 153 225 / 60%)',
}}
color="blue.default"
display="flex"
alignItems="center"
onClick={() => setShowFinished(!showFinished)}
>
{showFinished ? t('finished.hide') : t('finished.show')}
<Icon
icon="arrowDown"
width="20px"
height="20px"
style={{ transform: showFinished ? 'rotate(180deg)' : 'rotate(0deg)' }}
/>
</Text>
</Box>
<Box
display="grid"
mt="1rem"
gridTemplateColumns={cardColumnSize}
gridColumnGap="5rem"
gridRowGap="3rem"
height="auto"
{isPlural(finishedCohorts)
? t('finished.plural', { finishedCohorts: finishedCohorts.length })
: t('finished.singular', { finishedCohorts: finishedCohorts.length })}
</Text>
<Text
as="button"
alignSelf="center"
size="md"
fontWeight="bold"
textAlign="left"
gridGap="10px"
_focus={{
boxShadow: '0 0 0 3px rgb(66 153 225 / 60%)',
}}
color="blue.default"
display="flex"
alignItems="center"
onClick={() => setShowFinished(!showFinished)}
>
{showFinished && finishedCohorts.map((item) => (
<Programs
key={item?.cohort?.slug}
item={item}
handleChoose={handleChoose}
onOpenModal={() => setUpgradeModalIsOpen(true)}
/>
))}
</Box>
</>
)
}
{showFinished ? t('finished.hide') : t('finished.show')}
<Icon
icon="arrowDown"
width="20px"
height="20px"
style={{ transform: showFinished ? 'rotate(180deg)' : 'rotate(0deg)' }}
/>
</Text>
</Box>
<Box
display="grid"
mt="1rem"
gridTemplateColumns={cardColumnSize}
gridColumnGap="5rem"
gridRowGap="3rem"
height="auto"
>
{showFinished && finishedCohorts.map((item) => (
<Programs
key={item?.cohort?.slug}
item={item}
handleChoose={handleChoose}
onOpenModal={() => setUpgradeModalIsOpen(true)}
/>
))}
</Box>
</>
)}
</>
);
}
Expand Down