-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transcript): add provisional grades to transcript
Refs #415
- Loading branch information
Showing
14 changed files
with
614 additions
and
130 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
83 changes: 83 additions & 0 deletions
83
src/features/transcript/components/ProvisionalGradeListItem.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,83 @@ | ||
import { useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { DisclosureIndicator } from '@lib/ui/components/DisclosureIndicator'; | ||
import { ListItem } from '@lib/ui/components/ListItem'; | ||
import { Row } from '@lib/ui/components/Row'; | ||
import { useStylesheet } from '@lib/ui/hooks/useStylesheet'; | ||
import { Theme } from '@lib/ui/types/Theme'; | ||
import { | ||
ProvisionalGrade, | ||
ProvisionalGradeStateEnum, | ||
} from '@polito/api-client/models/ProvisionalGrade'; | ||
|
||
import { IS_IOS } from '../../../core/constants'; | ||
import { formatDate, formatTime } from '../../../utils/dates'; | ||
import { useGetRejectionTime } from '../hooks/useGetRejectionTime'; | ||
import { ProvisionalGradeStatusBadge } from './ProvisionalGradeStatusBadge'; | ||
|
||
type Props = { | ||
grade: ProvisionalGrade; | ||
}; | ||
|
||
export const ProvisionalGradeListItem = ({ grade }: Props) => { | ||
const { t } = useTranslation(); | ||
|
||
const styles = useStylesheet(createStyles); | ||
const isRejected = grade.state === ProvisionalGradeStateEnum.Rejected; | ||
|
||
const rejectionTime = useGetRejectionTime({ | ||
rejectingExpiresAt: grade.rejectingExpiresAt, | ||
isCompact: true, | ||
}); | ||
|
||
const subtitle = useMemo(() => { | ||
switch (grade.state) { | ||
case ProvisionalGradeStateEnum.Confirmed: | ||
return rejectionTime; | ||
case ProvisionalGradeStateEnum.Rejected: | ||
return t('transcriptGradesScreen.rejectedSubtitle', { | ||
date: formatDate(grade.rejectedAt!), | ||
time: formatTime(grade.rejectedAt!), | ||
}); | ||
default: | ||
return undefined; | ||
} | ||
}, [grade.rejectedAt, grade.state, rejectionTime, t]); | ||
|
||
return ( | ||
<ListItem | ||
title={grade.courseName} | ||
subtitle={subtitle} | ||
subtitleStyle={ | ||
grade.state === ProvisionalGradeStateEnum.Confirmed | ||
? styles.rejectableSubtitle | ||
: styles.subtitle | ||
} | ||
disabled={isRejected} | ||
linkTo={ | ||
isRejected | ||
? undefined | ||
: { | ||
screen: 'ProvisionalGrade', | ||
params: { id: grade.id }, | ||
} | ||
} | ||
trailingItem={ | ||
<Row align="center" pl={2}> | ||
<ProvisionalGradeStatusBadge grade={grade} /> | ||
{IS_IOS && !isRejected ? <DisclosureIndicator /> : undefined} | ||
</Row> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
const createStyles = ({ colors, dark, palettes }: Theme) => ({ | ||
subtitle: { | ||
color: colors.title, | ||
}, | ||
rejectableSubtitle: { | ||
color: dark ? palettes.danger[300] : palettes.danger[700], | ||
}, | ||
}); |
Oops, something went wrong.