Skip to content

Commit

Permalink
use myCohorts on choose program and remove queryData state
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomm19 committed Dec 30, 2024
1 parent 3ef8e6f commit b0a4077
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 110 deletions.
3 changes: 2 additions & 1 deletion src/common/components/LiveEvent/MainEvent.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
/* eslint-disable react/jsx-no-useless-fragment */
import { Box, Divider, Tag, TagLabel } from '@chakra-ui/react';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -26,7 +27,7 @@ function MainEvent({
const liveStartsAtDate = new Date(event?.starting_at);
const liveEndsAtDate = new Date(event?.ended_at || event?.ending_at);

const isTeacher = cohorts.some(({ cohort, role }) => cohort.slug === event.cohort?.slug && ['TEACHER', 'ASSISTANT'].includes(role));
const isTeacher = cohorts.some(({ slug, cohort_user }) => slug === event.cohort?.slug && ['TEACHER', 'ASSISTANT'].includes(cohort_user.role));
const joinMessage = () => (isTeacher ? t('start-class') : event?.cohort?.name);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/common/components/SupportSidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function SupportSidebar({ allCohorts, allSyllabus, services, subscriptions, subs
const filterByFinantialStatus = (list) => list.filter((service) => {
if (allCohorts.length > 0) {
return allCohorts.some((elem) => {
if (elem?.cohort?.academy?.id === service?.academy?.id && (elem?.finantial_status === 'LATE' || elem?.educational_status === 'SUSPENDED')) {
if (elem?.academy?.id === service?.academy?.id && (elem?.cohort_user.finantial_status === 'LATE' || elem?.cohort_user.educational_status === 'SUSPENDED')) {
return false;
}
return true;
Expand Down
18 changes: 9 additions & 9 deletions src/common/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,24 @@ const handlers = {
date: formatedDate,
};
},
getCohortsFinished: (cohorts) => cohorts.filter((program) => {
const educationalStatus = program?.educational_status?.toUpperCase();
const programCohortStage = program?.cohort?.stage?.toUpperCase();
getCohortsFinished: (cohorts) => cohorts.filter((cohort) => {
const educationalStatus = cohort.cohort_user.educational_status.toUpperCase();
const programCohortStage = cohort.stage.toUpperCase();

const hasEnded = ['ENDED'].includes(programCohortStage);
const isGraduated = educationalStatus === 'GRADUATED';

const showStudent = ['GRADUATED', 'POSTPONED', 'ACTIVE'].includes(educationalStatus);
const isNotHiddenOnPrework = programCohortStage === 'PREWORK'
&& program?.cohort?.is_hidden_on_prework === false
&& cohort.is_hidden_on_prework === false
&& hasEnded;

return (isGraduated || hasEnded || isNotHiddenOnPrework) && showStudent;
}),
getActiveCohorts: (cohorts) => cohorts.filter((program) => {
const educationalStatus = program?.educational_status?.toUpperCase();
const programRole = program?.role?.toUpperCase();
const programCohortStage = program?.cohort?.stage?.toUpperCase();
getActiveCohorts: (cohorts) => cohorts.filter((cohort) => {
const educationalStatus = cohort.cohort_user.educational_status?.toUpperCase();
const programRole = cohort.cohort_user.role?.toUpperCase();
const programCohortStage = cohort.stage.toUpperCase();
const isGraduated = educationalStatus === 'GRADUATED';

const visibleForTeacher = programRole !== 'STUDENT';
Expand All @@ -201,7 +201,7 @@ const handlers = {

const cohortIsAvailable = showCohort && !hasEnded;
const isNotHiddenOnPrework = programCohortStage === 'PREWORK'
&& program?.cohort?.is_hidden_on_prework === false
&& cohort.is_hidden_on_prework === false
&& !hasEnded;

const showStudent = ['ACTIVE'].includes(educationalStatus) && programRole === 'STUDENT';
Expand Down
7 changes: 4 additions & 3 deletions src/js_modules/chooseProgram/Programs.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
import PropTypes from 'prop-types';
import { useRouter } from 'next/router';
import { subMinutes } from 'date-fns';
Expand All @@ -11,7 +12,7 @@ function Programs({ item, onOpenModal, setLateModalProps }) {
const { setCohortSession } = useCohortHandler();
const [isLoadingPageContent, setIsLoadingPageContent] = useState(false);
const { programsList } = useProgramList();
const { cohort, ...cohortUser } = item;
const { cohort_user: cohortUser, ...cohort } = item;
const signInDate = item.created_at;
const { version, slug } = cohort.syllabus_version;
const currentCohortProps = programsList[cohort.slug];
Expand Down Expand Up @@ -97,8 +98,8 @@ function Programs({ item, onOpenModal, setLateModalProps }) {
// isBought={!isFreeTrial}
isLoadingPageContent={isLoadingPageContent}
isLoading={currentCohortProps === undefined}
startsIn={item?.cohort?.kickoff_date}
endsAt={item?.cohort?.ending_date}
startsIn={item?.kickoff_date}
endsAt={item?.ending_date}
signInDate={signInDate}
icon="coding"
subscription={subscription || {}}
Expand Down
16 changes: 7 additions & 9 deletions src/js_modules/chooseProgram/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,25 @@ function ChooseProgram({ chooseList, handleChoose, setLateModalProps }) {
const cardColumnSize = 'repeat(auto-fill, minmax(17rem, 1fr))';

const finishedCohorts = handlers.getCohortsFinished(chooseList);
const activeCohorts = handlers.getActiveCohorts(chooseList).map((item) => {
const cohort = item?.cohort;
const activeCohorts = handlers.getActiveCohorts(chooseList).map((cohort) => {
const { cohort_user: cohortUser } = cohort;
const currentCohortProps = programsList[cohort.slug];
return ({
...item,
cohort: {
...cohort,
available_as_saas: item?.role === 'TEACHER' ? false : cohort?.available_as_saas,
},
...cohort,
available_as_saas: cohortUser?.role === 'TEACHER' ? false : cohort.available_as_saas,
cohort_user: { ...cohortUser },
subscription: currentCohortProps?.subscription,
plan_financing: currentCohortProps?.plan_financing,
all_subscriptions: currentCohortProps?.all_subscriptions,
subscription_exists: currentCohortProps?.subscription !== null || currentCohortProps?.plan_financing !== null,
});
});

const hasNonSaasCourse = chooseList.some(({ cohort }) => !cohort.available_as_saas);
const hasNonSaasCourse = chooseList.some((cohort) => !cohort.available_as_saas);

const marketingCourses = marketingCursesList.filter(
(item) => !activeCohorts.some(
({ cohort }) => cohort.slug === item?.cohort?.slug,
(cohort) => cohort.slug === item?.cohort?.slug,
) && item?.course_translation?.title,
);

Expand Down
Loading

0 comments on commit b0a4077

Please sign in to comment.