Skip to content

Commit 9f2d592

Browse files
committed
YKI(Frontend): Refactor, extract common patterns [deploy]
1 parent 0202080 commit 9f2d592

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

frontend/packages/yki/src/components/registration/examSession/PublicExamSessionListingRow.tsx

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { TableCell, TableRow, Typography } from '@mui/material';
22
import dayjs, { Dayjs } from 'dayjs';
3+
import { ReactNode } from 'react';
34
import { CustomButtonLink, Text } from 'shared/components';
45
import { Color, Variant } from 'shared/enums';
56
import { useWindowProperties } from 'shared/hooks';
@@ -108,7 +109,8 @@ const AdmissionPeriodText = ({ examSession }: { examSession: ExamSession }) => {
108109
} else {
109110
return (
110111
<>
111-
{translateCommon('postAdmission')}:<br aria-hidden={true} />
112+
{translateCommon('postAdmission')}:
113+
<br aria-hidden={true} />
112114
{renderAdmissionPeriod(relevantPeriod)}
113115
</>
114116
);
@@ -155,6 +157,22 @@ const PublicExamSessionListingCellsForDesktop = ({
155157
);
156158
};
157159

160+
const TableCellForPhone = ({
161+
columnName,
162+
children,
163+
}: {
164+
columnName: string;
165+
children: ReactNode;
166+
}) => (
167+
<TableCell>
168+
<Text>
169+
<b aria-hidden={true}>{columnName}</b>
170+
<br aria-hidden={true} />
171+
{children}
172+
</Text>
173+
</TableCell>
174+
);
175+
158176
const PublicExamSessionListingCellsForPhone = ({
159177
examSession,
160178
locationInfo,
@@ -175,51 +193,28 @@ const PublicExamSessionListingCellsForPhone = ({
175193
{ExamSessionUtils.languageAndLevelText(examSession)}
176194
</Typography>
177195
</TableCell>
178-
<TableCell>
179-
<Text>
180-
<b aria-hidden={true}>{translateCommon('examDate')}</b>
181-
<br aria-hidden={true} />
182-
{DateUtils.formatOptionalDate(examSession.session_date, 'l')}
183-
</Text>
184-
</TableCell>
185-
<TableCell>
186-
<Text>
187-
<b aria-hidden={true}>{translateCommon('institution')}</b>
188-
<br aria-hidden={true} />
189-
{locationInfo.name}
190-
<br aria-hidden={true} />
191-
{ExamSessionUtils.getMunicipality(locationInfo)}
192-
</Text>
193-
</TableCell>
194-
<TableCell>
195-
<Text>
196-
<b aria-hidden={true}>{translateCommon('registrationPeriod')}</b>
197-
<br aria-hidden={true} />
198-
<AdmissionPeriodText examSession={examSession} />
199-
</Text>
200-
</TableCell>
201-
<TableCell>
202-
<Text>
203-
<b aria-hidden={true}>{translateCommon('price')}</b>
204-
<br aria-hidden={true} />
205-
{examSession.exam_fee}
206-
</Text>
207-
</TableCell>
208-
<TableCell>
209-
<Text>
210-
<b aria-hidden={true}>{translateCommon('placesAvailable')}</b>
211-
<br aria-hidden={true} />
212-
{availablePlacesText}
213-
</Text>
214-
</TableCell>
196+
<TableCellForPhone columnName={translateCommon('examDate')}>
197+
{DateUtils.formatOptionalDate(examSession.session_date, 'l')}
198+
</TableCellForPhone>
199+
<TableCellForPhone columnName={translateCommon('institution')}>
200+
{locationInfo.name}
201+
<br aria-hidden={true} />
202+
{ExamSessionUtils.getMunicipality(locationInfo)}
203+
</TableCellForPhone>
204+
<TableCellForPhone columnName={translateCommon('registrationPeriod')}>
205+
<AdmissionPeriodText examSession={examSession} />
206+
</TableCellForPhone>
207+
<TableCellForPhone columnName={translateCommon('price')}>
208+
{examSession.exam_fee}
209+
</TableCellForPhone>
210+
<TableCellForPhone columnName={translateCommon('placesAvailable')}>
211+
{availablePlacesText}
212+
</TableCellForPhone>
215213
<TableCell>
216214
{registerActionAvailable ? (
217215
<RegisterToExamButton examSession={examSession} />
218216
) : (
219-
<Text
220-
className="centered uppercase"
221-
aria-label={translateCommon('actions')}
222-
>
217+
<Text className="centered uppercase">
223218
<RegistrationUnavailableText examSession={examSession} />
224219
</Text>
225220
)}

0 commit comments

Comments
 (0)