-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Opintopiste/kurssi-homma käliin;
Saattaa ehkä jo toimia, mutta ei ole testattu
- Loading branch information
1 parent
27c8405
commit f25db2e
Showing
11 changed files
with
181 additions
and
38 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
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,74 @@ | ||
import React, { useCallback, useMemo } from 'react' | ||
import { | ||
LaajuusEdit, | ||
LaajuusEditProps | ||
} from '../../components-v2/opiskeluoikeus/LaajuusField' | ||
import { parseISODateNullable, today } from '../../date/date' | ||
import { Koodistokoodiviite } from '../../types/fi/oph/koski/schema/Koodistokoodiviite' | ||
import { LaajuusKursseissa } from '../../types/fi/oph/koski/schema/LaajuusKursseissa' | ||
import { LaajuusOpintopisteissä } from '../../types/fi/oph/koski/schema/LaajuusOpintopisteissa' | ||
import { LaajuusOpintopisteissäTaiKursseissa } from '../../types/fi/oph/koski/schema/LaajuusOpintopisteissaTaiKursseissa' | ||
|
||
const laajuusyksikönVaihtumispäivä = new Date(2025, 8 - 1, 1) | ||
|
||
export type IBLaajuusEditProps = Omit< | ||
LaajuusEditProps<LaajuusOpintopisteissäTaiKursseissa> & { | ||
alkamispäivä?: string | ||
}, | ||
'createLaajuus' | ||
> | ||
|
||
export const IBLaajuusEdit: React.FC<IBLaajuusEditProps> = (props) => { | ||
const yksikkö = useIBLaajuusyksikkö(props.value, props.alkamispäivä) | ||
const createLaajuus = useCallback( | ||
(arvo: number) => { | ||
return createIBLaajuus(arvo, yksikkö!) | ||
}, | ||
[yksikkö] | ||
) | ||
|
||
return yksikkö ? ( | ||
<> | ||
<LaajuusEdit | ||
{...props} | ||
createLaajuus={createLaajuus} | ||
testId={props.testId || 'laajuus'} | ||
/> | ||
</> | ||
) : null | ||
} | ||
|
||
export const createIBLaajuus = ( | ||
arvo: number, | ||
yksikkö: Koodistokoodiviite | ||
): LaajuusOpintopisteissäTaiKursseissa => | ||
yksikkö.koodiarvo === Kursseja | ||
? LaajuusKursseissa({ arvo }) | ||
: LaajuusOpintopisteissä({ arvo }) | ||
|
||
export const Kursseja = '4' | ||
export const Opintopisteitä = '2' | ||
type IBLaajuusYksikkö = Koodistokoodiviite< | ||
'opintojenlaajuusyksikko', | ||
typeof Kursseja | typeof Opintopisteitä | ||
> | ||
|
||
export const useIBLaajuusyksikkö = ( | ||
value?: LaajuusOpintopisteissäTaiKursseissa, | ||
alkamispäivä?: string | ||
): IBLaajuusYksikkö => | ||
useMemo( | ||
() => | ||
value | ||
? value.yksikkö | ||
: laajuusyksikköPäivänPerusteella( | ||
(alkamispäivä && parseISODateNullable(alkamispäivä)) || today() | ||
), | ||
[value, alkamispäivä] | ||
) | ||
|
||
const laajuusyksikköPäivänPerusteella = (pvm: Date): IBLaajuusYksikkö => | ||
Koodistokoodiviite({ | ||
koodiarvo: pvm < laajuusyksikönVaihtumispäivä ? Kursseja : Opintopisteitä, | ||
koodistoUri: 'opintojenlaajuusyksikko' | ||
}) |
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
Oops, something went wrong.