@@ -18,14 +18,24 @@ import {
1818import { CurriculumPicker } from '@/components/common/CurriculumPicker'
1919import { StyledAccordion } from '@/components/common/StyledAccordion'
2020import { StyledTable } from '@/components/common/StyledTable'
21- import { useLanguage } from '@/components/LanguagePicker/useLanguage'
21+ import { GetTextIn , useLanguage } from '@/components/LanguagePicker/useLanguage'
2222import { Section } from '@/components/Section'
2323import { DateFormat } from '@/constants/date'
2424import { ArrowDropDownIcon , CloseIcon , DoneIcon } from '@/theme'
25+ import { Absence } from '@/types/students'
2526import { reformatDate } from '@/util/timeAndDate'
27+ import { StudentPageStudent } from '@oodikone/shared/types/studentData'
2628import { useCurriculumState } from '../../../hooks/useCurriculums'
2729
28- const ModuleTable = ( { data, cypress, getTextIn } ) => (
30+ const ModuleTable = ( {
31+ data,
32+ cypress,
33+ getTextIn,
34+ } : {
35+ data : StudentPageStudent [ 'courses' ]
36+ cypress : string
37+ getTextIn : GetTextIn
38+ } ) => (
2939 < StyledTable data-cy = { cypress } >
3040 < TableHead >
3141 < TableRow >
@@ -48,7 +58,15 @@ const ModuleTable = ({ data, cypress, getTextIn }) => (
4858 </ StyledTable >
4959)
5060
51- export const BachelorHonours = ( { absentYears, programmeCode, student } ) => {
61+ export const BachelorHonours = ( {
62+ absentYears,
63+ programmeCode,
64+ student,
65+ } : {
66+ absentYears : Absence [ ]
67+ programmeCode : string
68+ student : StudentPageStudent
69+ } ) => {
5270 const [ curriculum , curriculumList , setCurriculum ] = useCurriculumState (
5371 programmeCode ,
5472 new Date ( ) . getFullYear ( ) . toString ( )
@@ -60,8 +78,8 @@ export const BachelorHonours = ({ absentYears, programmeCode, student }) => {
6078
6179 if ( ! student ?. courses || ! student ?. studyRights ) return null
6280
63- let studyStartDate
64- let reason
81+ let studyStartDate : dayjs . Dayjs
82+ let reason = ''
6583 let graduated = false
6684 let inspection = false
6785 let inTime = false
@@ -72,8 +90,9 @@ export const BachelorHonours = ({ absentYears, programmeCode, student }) => {
7290
7391 if ( studyRightWithCorrectProgramme ) {
7492 studyStartDate = dayjs ( studyRightWithCorrectProgramme . startDate )
75- graduated = ! ! studyRightWithCorrectProgramme . studyRightElements . find ( element => element . code === programmeCode )
76- . graduated
93+ graduated =
94+ studyRightWithCorrectProgramme . studyRightElements . find ( element => element . code === programmeCode ) ?. graduated ??
95+ false
7796 }
7897
7998 const mandatoryModuleCodes = mandatoryModules ? mandatoryModules . map ( mod => mod . code ) . filter ( Boolean ) : [ ]
@@ -84,7 +103,7 @@ export const BachelorHonours = ({ absentYears, programmeCode, student }) => {
84103 intermediateHonoursModules [ programmeCode ] . includes ( mod . course . code )
85104 )
86105
87- const mainModules = [ ]
106+ const mainModules : StudentPageStudent [ 'courses' ] = [ ]
88107 if ( degreeModule ) mainModules . push ( degreeModule )
89108 if ( basicModules . length ) mainModules . push ( ...basicModules )
90109 if ( intermediateModules . length ) mainModules . push ( ...intermediateModules )
@@ -96,7 +115,8 @@ export const BachelorHonours = ({ absentYears, programmeCode, student }) => {
96115
97116 if ( degreeModule ) {
98117 const graduationDate = dayjs ( degreeModule . date )
99- const yearsForGraduation = graduationDate . diff ( studyStartDate , 'years' , true )
118+ // HACK: StudyStartDate should never be null even though db allows it
119+ const yearsForGraduation = graduationDate . diff ( studyStartDate ! , 'years' , true )
100120
101121 // calculate time student has been absent during bachelors degree
102122 const timeAbsent = absentYears . reduce ( ( acc , curr ) => {
0 commit comments