Skip to content

Commit 909e2c1

Browse files
Merge pull request #2040 from lumi-tip/development-lumi-9048-v2
🐛 fix redirecting the user after clicking Join Cohort
2 parents 0499deb + bc6d2cb commit 909e2c1

File tree

2 files changed

+77
-60
lines changed

2 files changed

+77
-60
lines changed

src/pages/bootcamp/useBootcamp.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const useBootcamp = () => {
3030
const showBottomCTA = useRef(null);
3131
const [isCtaVisible, setIsCtaVisible] = useState(false);
3232
const [allDiscounts, setAllDiscounts] = useState([]);
33-
const { isAuthenticated, user, logout, cohorts, reSetUserAndCohorts } = useAuth();
33+
const { isAuthenticated, user, logout, reSetUserAndCohorts } = useAuth();
3434
const { hexColor, backgroundColor, fontColor, borderColor, complementaryBlue, featuredColor, backgroundColor7, backgroundColor8 } = useStyle();
3535
const { isRigoInitialized, rigo } = useRigo();
3636
const { setCohortSession } = useCohortHandler();
@@ -105,20 +105,20 @@ export const useBootcamp = () => {
105105
return 0;
106106
};
107107

108-
const redirectTocohort = () => {
108+
const redirectTocohort = (userCohorts) => {
109109
const cohort = cohortData?.cohortSyllabus?.cohort;
110110
axiosInstance.defaults.headers.common.Academy = cohort.academy.id;
111111

112-
const joinedCohort = cohorts.find(({ slug }) => slug === cohort?.slug);
112+
const joinedCohort = userCohorts.find(({ slug }) => slug === cohort?.slug);
113113
setCohortSession({
114114
...joinedCohort,
115115
});
116116
router.push(joinedCohort.selectedProgramSlug);
117117
};
118118

119119
const redirectToCohortIfItsReady = async ({ withAlert = true, callback = () => {} } = {}) => {
120-
await reSetUserAndCohorts();
121-
const alreadyHaveThisCohort = cohorts?.some((cohort) => cohort?.id === cohortId);
120+
const { cohorts: userCohorts } = await reSetUserAndCohorts();
121+
const alreadyHaveThisCohort = userCohorts?.some((cohort) => cohort?.id === cohortId);
122122

123123
if (alreadyHaveThisCohort) {
124124
callback();
@@ -131,7 +131,7 @@ export const useBootcamp = () => {
131131
duration: 5000,
132132
});
133133
}
134-
redirectTocohort();
134+
redirectTocohort(userCohorts);
135135
}
136136
};
137137

src/pages/how-to/technology/[technology].jsx

Lines changed: 71 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,64 +37,81 @@ export const getStaticProps = async ({ params, locale, locales }) => {
3737
const { technology } = params;
3838
const currentLang = locale === 'en' ? 'us' : 'es';
3939

40-
const responseTechs = await fetch(`${process.env.BREATHECODE_HOST}/v1/registry/academy/technology?slug=${technology}&limit=1000&academy=${WHITE_LABEL_ACADEMY}`, {
41-
method: 'GET',
42-
headers: {
43-
Authorization: `Token ${process.env.BC_ACADEMY_TOKEN}`,
44-
Academy: 4,
45-
},
46-
});
47-
const techs = await responseTechs.json(); // array of objects
48-
const technologyData = techs.results.find((tech) => tech.slug === technology);
49-
50-
const qs = parseQuerys({
51-
asset_type: 'ARTICLE',
52-
visibility: 'PUBLIC',
53-
status: 'PUBLISHED',
54-
academy: WHITE_LABEL_ACADEMY,
55-
limit: 1000,
56-
technologies: technology,
57-
});
58-
59-
const response = await fetch(`${process.env.BREATHECODE_HOST}/v1/registry/asset${qs}`);
60-
const exercises = await response.json();
61-
62-
const dataFiltered = exercises?.results?.filter(
63-
(l) => l?.category?.slug === 'how-to' || l?.category?.slug === 'como',
64-
);
40+
try {
41+
const responseTechs = await fetch(`${process.env.BREATHECODE_HOST}/v1/registry/academy/technology?slug=${technology}&limit=1000&academy=${WHITE_LABEL_ACADEMY}`, {
42+
method: 'GET',
43+
headers: {
44+
Authorization: `Token ${process.env.BC_ACADEMY_TOKEN}`,
45+
Academy: 4,
46+
},
47+
});
48+
49+
if (!responseTechs.ok) {
50+
console.error(`Error fetching technology data: ${responseTechs.status}`);
51+
return { notFound: true };
52+
}
53+
54+
const techs = await responseTechs.json();
55+
const technologyData = techs.results?.find((tech) => tech.slug === technology);
56+
57+
if (!technologyData) {
58+
return { notFound: true };
59+
}
60+
61+
const qs = parseQuerys({
62+
asset_type: 'ARTICLE',
63+
visibility: 'PUBLIC',
64+
status: 'PUBLISHED',
65+
academy: WHITE_LABEL_ACADEMY,
66+
limit: 1000,
67+
technologies: technology,
68+
});
69+
70+
const response = await fetch(`${process.env.BREATHECODE_HOST}/v1/registry/asset${qs}`);
71+
72+
if (!response.ok) {
73+
console.error(`Error fetching articles: ${response.status}`);
74+
return { notFound: true };
75+
}
76+
77+
const exercises = await response.json();
78+
const dataFiltered = exercises?.results?.filter(
79+
(l) => l?.category?.slug === 'how-to' || l?.category?.slug === 'como',
80+
) || [];
81+
82+
if (dataFiltered.length === 0) {
83+
return { notFound: true };
84+
}
85+
86+
const ogUrl = {
87+
en: `/how-to/technology/${technology}`,
88+
us: `/how-to/technology/${technology}`,
89+
};
6590

66-
if (response.status >= 400 || response.status_code >= 400
67-
|| !technologyData || dataFiltered?.length === 0) {
6891
return {
69-
notFound: true,
92+
props: {
93+
seo: {
94+
title: technologyData?.title,
95+
description: '',
96+
image: technologyData?.icon_url || '',
97+
pathConnector: `/how-to/technology/${technology}`,
98+
url: ogUrl.en,
99+
type: 'website',
100+
card: 'default',
101+
locales,
102+
locale,
103+
},
104+
fallback: false,
105+
technologyData,
106+
articles: dataFiltered.filter((project) => project.lang === currentLang).map(
107+
(l) => ({ ...l, difficulty: l.difficulty?.toLowerCase() || null }),
108+
),
109+
},
70110
};
111+
} catch (error) {
112+
console.error('Error in getStaticProps:', error);
113+
return { notFound: true };
71114
}
72-
73-
const ogUrl = {
74-
en: `/how-to/technology/${technology}`,
75-
us: `/how-to/technology/${technology}`,
76-
};
77-
78-
return {
79-
props: {
80-
seo: {
81-
title: technologyData?.title,
82-
description: '',
83-
image: technologyData?.icon_url || '',
84-
pathConnector: `/how-to/technology/${technology}`,
85-
url: ogUrl.en,
86-
type: 'website',
87-
card: 'default',
88-
locales,
89-
locale,
90-
},
91-
fallback: false,
92-
technologyData,
93-
articles: dataFiltered.filter((project) => project.lang === currentLang).map(
94-
(l) => ({ ...l, difficulty: l.difficulty?.toLowerCase() || null }),
95-
),
96-
},
97-
};
98115
};
99116

100117
function ExercisesByTechnology({ articles, technologyData }) {

0 commit comments

Comments
 (0)