Skip to content

Commit

Permalink
VKT(Frontend): Exam event participants calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoivisto committed Nov 8, 2024
1 parent 27d0185 commit 7722142
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
3 changes: 3 additions & 0 deletions frontend/packages/vkt/public/i18n/fi-FI/examiner.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
}
},
"examinerExamEventListing": {
"actions": {
"createExamEvent": "Lisää tutkintotilaisuus"
},
"heading": "Tutkintotilaisuudet",
"labels": {
"noExamEvents": "Ei tutkintotilaisuuksia"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChevronRight } from '@mui/icons-material';
import AddIcon from '@mui/icons-material/Add';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import {
Divider,
SelectChangeEvent,
Expand All @@ -18,7 +19,7 @@ import {
useKoodistoMunicipalitiesTranslation,
} from 'configs/i18n';
import { useAppDispatch, useAppSelector } from 'configs/redux';
import { AppRoutes, ExamLanguage } from 'enums/app';
import { AppRoutes, EnrollmentStatus, ExamLanguage } from 'enums/app';
import { ExaminerExamEvent } from 'interfaces/examinerExamEvent';
import { setExaminerExamEventLanguageFilter } from 'redux/reducers/examinerDetails';
import { examinerDetailsSelector } from 'redux/selectors/examinerDetails';
Expand Down Expand Up @@ -55,9 +56,22 @@ const ExaminerExamEventListingRow = ({
});
const translateCommon = useCommonTranslation();
const translateMunicipality = useKoodistoMunicipalitiesTranslation();
const { language, date, municipality, isHidden, id } = examEvent;
const {
language,
date,
municipality,
maxParticipants,
enrollments,
isHidden,
id,
} = examEvent;
const { examiner } = useAppSelector(examinerDetailsSelector);

// TODO Clarify which enrollments should be counted here
const participantsCount = enrollments.filter(
(e) => e.status === EnrollmentStatus.COMPLETED,
).length;

return (
<TableRow>
<TableCell>
Expand All @@ -70,7 +84,11 @@ const ExaminerExamEventListingRow = ({
<Text>{translateMunicipality(municipality.code)}</Text>
</TableCell>
<TableCell>
<Text className="bold">TODO</Text>
<Text>
{maxParticipants
? `${participantsCount}/${maxParticipants}`
: `${participantsCount}`}
</Text>
</TableCell>
<TableCell>
<Text>{translateCommon(isHidden ? 'no' : 'yes')}</Text>
Expand All @@ -80,7 +98,7 @@ const ExaminerExamEventListingRow = ({
sx={{ padding: 0 }}
variant={Variant.Text}
color={Color.Secondary}
endIcon={<ChevronRight />}
endIcon={<ChevronRightIcon />}
to={AppRoutes.ExaminerExamEventPage.replace(
/:oid/,
examiner?.oid || '',
Expand Down Expand Up @@ -116,7 +134,9 @@ export const ExaminerExamEventListing = () => {
});

const filteredExamEvents = useAppSelector(selectFilteredExaminerExamEvents);
const { examEventFilters } = useAppSelector(examinerDetailsSelector);
const { examiner, examEventFilters } = useAppSelector(
examinerDetailsSelector,
);
const dispatch = useAppDispatch();

const handleLanguageFilterChange = (event: SelectChangeEvent) => {
Expand All @@ -127,7 +147,23 @@ export const ExaminerExamEventListing = () => {

return (
<div className="examiner-homepage__exam-events rows gapped-xl">
<H2>{t('heading')}</H2>
<div className="columns">
<H2 className="grow">{t('heading')}</H2>
<div className="flex-end">
<CustomButtonLink
data-testid="clerk-exam-events__create-exam-event-btn"
startIcon={<AddIcon />}
color={Color.Secondary}
variant={Variant.Contained}
to={AppRoutes.ExaminerExamEventCreatePage.replace(
/:oid/,
examiner?.oid || '',
)}
>
{t('actions.createExamEvent')}
</CustomButtonLink>{' '}
</div>
</div>
<Divider />
<ExaminerExamEventToggleFilters />
<LanguageFilter
Expand Down
3 changes: 2 additions & 1 deletion frontend/packages/vkt/src/enums/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export enum AppRoutes {
ExaminerRoot = '/vkt/tv',
ExaminerHomePage = '/vkt/tv/:oid',
ExaminerDetailsPage = '/vkt/tv/:oid/omat-tiedot',
ExaminerExamEventPage = '/vkt/tv/:oid/tutkinto/:examEventId',
ExaminerExamEventCreatePage = '/vkt/tv/:oid/tutkintotilaisuus/luo',
ExaminerExamEventPage = '/vkt/tv/:oid/tutkintotilaisuus/:examEventId',

// Miscellaneous
AccessibilityStatementPage = '/vkt/saavutettavuusseloste',
Expand Down
5 changes: 4 additions & 1 deletion frontend/packages/vkt/src/interfaces/examinerExamEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { Dayjs } from "dayjs";
import { ExamLanguage } from "enums/app";
import { WithId, WithVersion } from "shared/interfaces";
import { MunicipalityCode } from "./municipality";

Check failure on line 4 in frontend/packages/vkt/src/interfaces/examinerExamEvent.ts

View workflow job for this annotation

GitHub Actions / frontend / common-frontend (20.9.0)

'./clerkEnrollment' import is restricted from being used by a pattern
import { ClerkEnrollmentAppointment, ClerkEnrollmentAppointmentResponse } from "./clerkEnrollment";

export interface ExaminerExamEventResponse
extends Omit<

Check failure on line 8 in frontend/packages/vkt/src/interfaces/examinerExamEvent.ts

View workflow job for this annotation

GitHub Actions / frontend / common-frontend (20.9.0)

'./municipality' import is restricted from being used by a pattern
ExaminerExamEvent,
'date' | 'registrationCloses'
'date' | 'registrationCloses' | 'enrollments'
> {
date: string;
registrationCloses: string;
enrollments: Array<ClerkEnrollmentAppointmentResponse>;
}

export interface ExaminerExamEvent
Expand All @@ -22,4 +24,5 @@ export interface ExaminerExamEvent
isHidden: boolean;
maxParticipants?: number;
registrationCloses?: Dayjs;
enrollments: Array<ClerkEnrollmentAppointment>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ export const selectFilteredClerkExamEvents = createSelector(
}

if (toggleFilter === ExamEventToggleFilter.Upcoming) {
return ExamEventUtils.getUpcomingExamEvents(filteredExamEvents) as Array<ClerkListExamEvent>;
return ExamEventUtils.getUpcomingExamEvents(
filteredExamEvents,
) as Array<ClerkListExamEvent>;
} else {
return ExamEventUtils.getPassedExamEvents(filteredExamEvents) as Array<ClerkListExamEvent>;
return ExamEventUtils.getPassedExamEvents(
filteredExamEvents,
) as Array<ClerkListExamEvent>;
}
},
);
5 changes: 4 additions & 1 deletion frontend/packages/vkt/src/utils/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,11 @@ export class SerializationUtils {
const registrationCloses = !!examinerExamEvent.registrationCloses
? dayjs(examinerExamEvent.registrationCloses)
: undefined;
const enrollments = examinerExamEvent.enrollments.map(
SerializationUtils.deserializeClerkEnrollmentAppointment,
);

return { ...examinerExamEvent, date, registrationCloses };
return { ...examinerExamEvent, date, registrationCloses, enrollments };
}

static deserializeExaminerDetails(
Expand Down

0 comments on commit 7722142

Please sign in to comment.