diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aa909a358ffdbc169ed0ad6fd441e2b7eeb90731..82aafbbadf56100f150616af6fada287791752f8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,7 +38,9 @@ backend test: - make test artifacts: reports: - cobertura: coverage.xml + coverage_report: + coverage_format: cobertura + path: coverage.xml backend build: before_script: diff --git a/frontend/src/routes/guest/register/steps/consent.tsx b/frontend/src/routes/guest/register/steps/consent.tsx index e6761163ff6b431cc0fca9063c596d2bbf283135..483ffc9c671b917c34e56c46a4c6b73e11703ee4 100644 --- a/frontend/src/routes/guest/register/steps/consent.tsx +++ b/frontend/src/routes/guest/register/steps/consent.tsx @@ -34,7 +34,7 @@ const GuestConsentStep = forwardRef( control, handleSubmit, formState: { errors }, - } = useForm<GuestConsentData>() + } = useForm<GuestConsentData>({ mode: 'onTouched' }) useFieldArray({ control, name: 'consents' }) const submit: SubmitHandler<GuestConsentData> = (data) => { diff --git a/frontend/src/routes/guest/register/steps/register.tsx b/frontend/src/routes/guest/register/steps/register.tsx index 00c6a596d9a914802e1b0889572f72696415dadc..d9db88a4668b273caed13e6c2122424975dfd782 100644 --- a/frontend/src/routes/guest/register/steps/register.tsx +++ b/frontend/src/routes/guest/register/steps/register.tsx @@ -62,10 +62,11 @@ const GuestRegisterStep = forwardRef( // For select-components it seems to be easier to tie them to a state // and then handle the updating of the form using this, than to tie the // components directly to the form-field using useForm - const [countryCode, setCountryCode] = useState<CountryCallingCode>(defaultCountryCode) + const [countryCode, setCountryCode] = + useState<CountryCallingCode>(defaultCountryCode) const [passportNationality, setPassportNationality] = useState< string | undefined - >(undefined) + >(undefined) // Set suggestion for the gender field if gender is not already given in the input const [gender, setGender] = useState<string>( @@ -91,6 +92,7 @@ const GuestRegisterStep = forwardRef( trigger, formState: { errors }, } = useForm<GuestRegisterData>({ + mode: 'onTouched', defaultValues: registerData ?? {}, }) @@ -207,7 +209,10 @@ const GuestRegisterStep = forwardRef( // for country code const countryCodeType = event.target.value as CountryCode setCountryCode(countryCodeType) - setValue('mobilePhoneCountry', countryCodeType, { shouldDirty: true, shouldTouch: true }) + setValue('mobilePhoneCountry', countryCodeType, { + shouldDirty: true, + shouldTouch: true, + }) } const handleMobilePhoneChange = (value: any) => { @@ -259,8 +264,7 @@ const GuestRegisterStep = forwardRef( if (registerData?.mobilePhoneCountry) { setCountryCode(registerData.mobilePhoneCountry) setValue('mobilePhoneCountry', registerData.mobilePhoneCountry) - } - else { + } else { setCountryCode(defaultCountryCode) setValue('mobilePhoneCountry', defaultCountryCode) } @@ -517,7 +521,9 @@ const GuestRegisterStep = forwardRef( displayEmpty onChange={handleCountryCodeChange} label={t('input.countryCallingCode')} - value={countryCode ? countryCode.toString() : defaultCountryCode} + value={ + countryCode ? countryCode.toString() : defaultCountryCode + } renderValue={(selected: any) => { if (!selected || selected.length === 0) { return t('input.countryCallingCode') diff --git a/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx b/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx index 9bcba27e01543216a6bcc8e29a5264ae5bf68f85..0c1d632e151ecff3bd6f4bbaba6f2d6003ae1d2c 100644 --- a/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx +++ b/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx @@ -142,7 +142,7 @@ export default function GuestRoleInfo({ setValue, reset, formState: { isDirty, isValid }, - } = useForm<RoleFormData>({ mode: 'onChange' }) + } = useForm<RoleFormData>({ mode: 'onTouched' }) // A sponsor can only edit roles belonging to departments where he is a sponsor. // Look at the unit where the role is registered and see if that unit is present diff --git a/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx b/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx index 5a45c1052c0017f28a334e7318ff406692117d02..97e35b086876b26ef4626bc6072867f6b0c7f8f9 100644 --- a/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx +++ b/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx @@ -106,13 +106,13 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) { formState: { errors }, setValue, getValues, - } = useForm<AddRoleFormData>() + } = useForm<AddRoleFormData>({ mode: 'onTouched' }) const { displayContactAtUnit, displayComment } = useFeatureContext() const { pid } = useParams<GuestInfoParams>() // Hack to make typecheck happy. The only way for pid to be undefined // is if the Route is set up wrong, which should brake everything any way - if(typeof(pid) === "undefined"){ + if (typeof pid === 'undefined') { return <></> } const navigate = useNavigate() diff --git a/frontend/src/routes/sponsor/register/stepPersonForm.tsx b/frontend/src/routes/sponsor/register/stepPersonForm.tsx index e93c5e26488503b8caba7f5127f4b832b0ef42da..3002319e6e7aa8e2240ada9a3aaabd5399b75b94 100644 --- a/frontend/src/routes/sponsor/register/stepPersonForm.tsx +++ b/frontend/src/routes/sponsor/register/stepPersonForm.tsx @@ -70,7 +70,10 @@ const StepPersonForm = forwardRef( setValue, getValues, trigger, - } = useForm<RegisterFormData>({ defaultValues: formData }) + } = useForm<RegisterFormData>({ + mode: 'onTouched', + defaultValues: formData, + }) const onSubmit = handleSubmit(submit) const handleOuChange = (event: any, value: any) => { diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 262f09f9244ee6a1bb4a739fd4717bbe8f8dacda..3a4f840984e9b725bfee305cd777e12bfc1ef98b 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -83,8 +83,7 @@ export function isValidFnr( } return i18n.t<string>('common:validation.invalidIdNumber').toString() } - const valid = validator.idnr(data as string).status === 'valid' - if (valid) { + if (validator.idnr(data as string).status === 'valid') { return true } // TypeScript complains if toString is not used on the function result @@ -93,12 +92,11 @@ export function isValidFnr( export function isValidMobilePhoneNumber( data: string | undefined -): boolean | string { +): true | string { if (!data) { return i18n.t<string>('common:validation.invalidMobilePhoneNumber') } - const valid = isValidPhoneNumber(data) - if (valid) { + if (isValidPhoneNumber(data)) { return true } return i18n.t<string>('common:validation.invalidMobilePhoneNumber')