-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VKT(Frontend): Clerk examiner listing
- Loading branch information
Showing
8 changed files
with
217 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
frontend/packages/vkt/src/components/clerkExaminer/ClerkExaminerListing.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { | ||
Divider, | ||
SelectChangeEvent, | ||
TableCell, | ||
TableHead, | ||
TableRow, | ||
} from '@mui/material'; | ||
import { Link } from 'react-router-dom'; | ||
import { CustomButtonLink, CustomTable, H2, Text } from 'shared/components'; | ||
import { Color, Variant } from 'shared/enums'; | ||
|
||
import { LanguageFilter } from 'components/common/LanguageFilter'; | ||
import { | ||
useClerkTranslation, | ||
useCommonTranslation, | ||
useKoodistoMunicipalitiesTranslation, | ||
} from 'configs/i18n'; | ||
import { useAppDispatch, useAppSelector } from 'configs/redux'; | ||
import { AppRoutes, ExamLanguage } from 'enums/app'; | ||
import { ExaminerDetails } from 'interfaces/examinerDetails'; | ||
import { setExamEventLanguageFilter } from 'redux/reducers/clerkListExamEvent'; | ||
import { clerkListExamEventsSelector } from 'redux/selectors/clerkListExamEvent'; | ||
import { clerkListExaminerSelector } from 'redux/selectors/clerkListExaminer'; | ||
import { ExaminerUtils } from 'utils/examiner'; | ||
|
||
export const ClerkExaminerListingHeader = () => { | ||
const { t } = useClerkTranslation({ | ||
keyPrefix: 'vkt.component.clerkExaminerListing.header', | ||
}); | ||
|
||
return ( | ||
<TableHead className="heading-text"> | ||
<TableRow> | ||
<TableCell>{t('examiner')}</TableCell> | ||
<TableCell>{t('language')}</TableCell> | ||
<TableCell>{t('examLocation')}</TableCell> | ||
<TableCell>{t('examDates')}</TableCell> | ||
<TableCell>{t('actions')}</TableCell> | ||
<TableCell /> | ||
</TableRow> | ||
</TableHead> | ||
); | ||
}; | ||
|
||
const ExaminerListingRow = ({ examiner }: { examiner: ExaminerDetails }) => { | ||
const { t } = useClerkTranslation({ | ||
keyPrefix: 'vkt.component.clerkExaminerListing', | ||
}); | ||
const translateCommon = useCommonTranslation(); | ||
const translateMunicipality = useKoodistoMunicipalitiesTranslation(); | ||
|
||
const examinerUrl = AppRoutes.ExaminerDetailsPage.replace( | ||
/:oid/, | ||
`${examiner.oid}`, | ||
); | ||
|
||
return ( | ||
<> | ||
<TableRow | ||
className="clerk-exam-event-listing__row" | ||
data-testid={`clerk-examiners__id-${examiner.id}-row`} | ||
> | ||
<TableCell> | ||
<Link | ||
className="clerk-exam-event-listing__row__link" | ||
to={examinerUrl} | ||
> | ||
<Text>{`${examiner.firstName} ${examiner.lastName}`}</Text> | ||
</Link> | ||
</TableCell> | ||
<TableCell> | ||
<Text> | ||
{ExaminerUtils.renderExamLanguages(examiner, translateCommon)} | ||
</Text> | ||
</TableCell> | ||
<TableCell> | ||
<Text> | ||
{ExaminerUtils.renderExamLocations(examiner, translateMunicipality)} | ||
</Text> | ||
</TableCell> | ||
<TableCell> | ||
<Text>TODO Ei määritelty?</Text> | ||
</TableCell> | ||
<TableCell> | ||
<CustomButtonLink | ||
variant={Variant.Outlined} | ||
color={Color.Secondary} | ||
to={examinerUrl} | ||
> | ||
{t('buttons.viewDetails')} | ||
</CustomButtonLink> | ||
</TableCell> | ||
</TableRow> | ||
</> | ||
); | ||
}; | ||
|
||
const getRowDetails = (examiner: ExaminerDetails) => { | ||
return <ExaminerListingRow examiner={examiner} />; | ||
}; | ||
|
||
export const ClerkExaminerListing = () => { | ||
const { t } = useClerkTranslation({ | ||
keyPrefix: 'vkt.component.clerkExaminerListing', | ||
}); | ||
const dispatch = useAppDispatch(); | ||
|
||
const { languageFilter } = useAppSelector(clerkListExamEventsSelector); | ||
|
||
const handleLanguageFilterChange = (event: SelectChangeEvent) => { | ||
dispatch(setExamEventLanguageFilter(event.target.value as ExamLanguage)); | ||
}; | ||
|
||
const { examiners } = useAppSelector(clerkListExaminerSelector); | ||
|
||
return ( | ||
<> | ||
<div className="clerk-homepage__grid-container__heading columns grow"> | ||
<H2>{t('title')}</H2> | ||
</div> | ||
<Divider /> | ||
<LanguageFilter | ||
value={languageFilter} | ||
onChange={handleLanguageFilterChange} | ||
/> | ||
<CustomTable | ||
className="table-layout-auto" | ||
data={examiners} | ||
header={<ClerkExaminerListingHeader />} | ||
getRowDetails={getRowDetails} | ||
stickyHeader | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ExamLanguage } from 'enums/app'; | ||
import { ExaminerDetails } from 'interfaces/examinerDetails'; | ||
|
||
export class ExaminerUtils { | ||
static renderExamLanguages( | ||
examiner: ExaminerDetails, | ||
translateCommon: (k: string) => string, | ||
) { | ||
const examLanguages: Array<ExamLanguage> = examiner.examLanguageFinnish | ||
? examiner.examLanguageSwedish | ||
? [ExamLanguage.FI, ExamLanguage.SV] | ||
: [ExamLanguage.FI] | ||
: examiner.examLanguageSwedish | ||
? [ExamLanguage.SV] | ||
: []; | ||
|
||
return examLanguages | ||
.map((v) => translateCommon(`examLanguage.${v}`)) | ||
.join(' & '); | ||
} | ||
|
||
static renderExamLocations( | ||
examiner: ExaminerDetails, | ||
translateMunicipality: (m: string) => string, | ||
) { | ||
return examiner.municipalities | ||
.map(({ code }) => translateMunicipality(code)) | ||
.sort((a, b) => a.localeCompare(b, 'fi-FI')) | ||
.join(', '); | ||
} | ||
} |