From 3bb81315b536404eaeb209a8539a35da297af7b6 Mon Sep 17 00:00:00 2001 From: Andreas Ellewsen <ae@uio.no> Date: Wed, 27 Oct 2021 09:51:07 +0200 Subject: [PATCH] Move ou sorting functions to hook --- frontend/src/hooks/useOus/index.tsx | 20 ++++++++++++++++ .../sponsor/register/stepPersonForm.tsx | 24 ++----------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/frontend/src/hooks/useOus/index.tsx b/frontend/src/hooks/useOus/index.tsx index 64c12dba..01459176 100644 --- a/frontend/src/hooks/useOus/index.tsx +++ b/frontend/src/hooks/useOus/index.tsx @@ -22,5 +22,25 @@ function useOus(): OuData[] { return ous } +export const enSort = (a: OuData, b: OuData) => { + if (a.en > b.en) { + return 1 + } + if (b.en > a.en) { + return -1 + } + return 0 +} + +export const nbSort = (a: OuData, b: OuData) => { + if (a.nb > b.nb) { + return 1 + } + if (b.nb > a.nb) { + return -1 + } + return 0 +} + export type { OuData } export default useOus diff --git a/frontend/src/routes/sponsor/register/stepPersonForm.tsx b/frontend/src/routes/sponsor/register/stepPersonForm.tsx index ca85cbc8..f4bb3a4e 100644 --- a/frontend/src/routes/sponsor/register/stepPersonForm.tsx +++ b/frontend/src/routes/sponsor/register/stepPersonForm.tsx @@ -11,7 +11,7 @@ import { } from '@mui/material' import { Controller, SubmitHandler, useForm } from 'react-hook-form' import { DatePicker } from '@mui/lab' -import React, { +import { forwardRef, Ref, useEffect, @@ -21,7 +21,7 @@ import React, { import { useTranslation } from 'react-i18next' import { RegisterFormData } from './formData' import { PersonFormMethods } from './personFormMethods' -import useOus, { OuData } from '../../../hooks/useOus' +import useOus, { enSort, nbSort } from '../../../hooks/useOus' import useRoleTypes, { RoleTypeData } from '../../../hooks/useRoleTypes' import { isValidEmail } from '../../../utils' @@ -51,26 +51,6 @@ const StepPersonForm = forwardRef( return a.name_en.localeCompare(b.name_en) } - const enSort = (a: OuData, b: OuData) => { - if (a.en > b.en) { - return 1 - } - if (b.en > a.en) { - return -1 - } - return 0 - } - - const nbSort = (a: OuData, b: OuData) => { - if (a.nb > b.nb) { - return 1 - } - if (b.nb > a.nb) { - return -1 - } - return 0 - } - const submit: SubmitHandler<RegisterFormData> = (data) => { nextHandler(data) } -- GitLab