-
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.
SHARED:VKT(Frontend): Properly translated municipality selection comp…
…onent
- Loading branch information
Showing
6 changed files
with
73 additions
and
12 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
39 changes: 39 additions & 0 deletions
39
frontend/packages/vkt/src/hooks/useKoodistoMunicipalities.ts
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,39 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { useKoodistoMunicipalitiesTranslation } from 'configs/i18n'; | ||
import koodistoMunicipalitiesFI from 'public/i18n/fi-FI/koodisto_municipalities.json'; | ||
|
||
interface KoodistoMunicipalities { | ||
vkt: { | ||
koodisto: { | ||
municipalities: Map<string, string>; | ||
}; | ||
}; | ||
} | ||
|
||
const getCodes: () => Array<string> = () => { | ||
return Object.keys( | ||
(koodistoMunicipalitiesFI as KoodistoMunicipalities).vkt.koodisto | ||
.municipalities, | ||
); | ||
}; | ||
|
||
export const useKoodistoMunicipalities = () => { | ||
return getCodes(); | ||
}; | ||
|
||
export const useMunicipalityOptions = () => { | ||
const translate = useKoodistoMunicipalitiesTranslation(); | ||
|
||
const sortedOptions = useMemo(() => { | ||
const options = getCodes().map((value) => ({ | ||
value, | ||
label: translate(value), | ||
})); | ||
const locale = new Intl.Locale('fi-FI'); | ||
|
||
return options.sort((a, b) => a.label.localeCompare(b.label, locale)); | ||
}, [translate]); | ||
|
||
return sortedOptions; | ||
}; |
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