Skip to content

Commit

Permalink
Merge pull request #2141 from City-of-Helsinki/HL-856-deminimis-fix
Browse files Browse the repository at this point in the history
HL-856 | Show deminimis section for company and association
  • Loading branch information
JanneJuhola authored Aug 8, 2023
2 parents d10e377 + 384d195 commit 8b65e8d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,56 +161,56 @@ const ApplicationFormStep1: React.FC<DynamicFormStepComponentProps> = ({
/>
</$GridCell>
</FormSection>
{showDeminimisSection && (
<FormSection
header={t(`${translationsBase}.heading3`)}
tooltip={t(`${translationsBase}.tooltips.heading3`)}
>
<$GridCell $colSpan={8}>
<SelectionGroup
id={fields.deMinimisAid.name}
label={fields.deMinimisAid.label}
direction="vertical"
required
errorText={getErrorMessage(fields.deMinimisAid.name)}
>
<$RadioButton
id={`${fields.deMinimisAid.name}False`}
name={fields.deMinimisAid.name}
value="false"
label={t(
`${translationsBase}.fields.${APPLICATION_FIELDS_STEP1_KEYS.DE_MINIMIS_AID}.no`
)}
onChange={() => {
formik.setFieldValue(fields.deMinimisAid.name, false);
setDeMinimisAids([]);
}}
// 3 states: null (none is selected), true, false
checked={formik.values.deMinimisAid === false}
/>
<$RadioButton
id={`${fields.deMinimisAid.name}True`}
name={fields.deMinimisAid.name}
value="true"
label={t(
`${translationsBase}.fields.${APPLICATION_FIELDS_STEP1_KEYS.DE_MINIMIS_AID}.yes`
)}
onChange={() =>
formik.setFieldValue(fields.deMinimisAid.name, true)
}
checked={formik.values.deMinimisAid === true}
/>
</SelectionGroup>
</$GridCell>
{showDeminimisSection && (
<FormSection
header={t(`${translationsBase}.heading3`)}
tooltip={t(`${translationsBase}.tooltips.heading3`)}
>
<$GridCell $colSpan={8}>
<SelectionGroup
id={fields.deMinimisAid.name}
label={fields.deMinimisAid.label}
direction="vertical"
required
errorText={getErrorMessage(fields.deMinimisAid.name)}
>
<$RadioButton
id={`${fields.deMinimisAid.name}False`}
name={fields.deMinimisAid.name}
value="false"
label={t(
`${translationsBase}.fields.${APPLICATION_FIELDS_STEP1_KEYS.DE_MINIMIS_AID}.no`
)}
onChange={() => {
formik.setFieldValue(fields.deMinimisAid.name, false);
setDeMinimisAids([]);
}}
// 3 states: null (none is selected), true, false
checked={formik.values.deMinimisAid === false}
/>
<$RadioButton
id={`${fields.deMinimisAid.name}True`}
name={fields.deMinimisAid.name}
value="true"
label={t(
`${translationsBase}.fields.${APPLICATION_FIELDS_STEP1_KEYS.DE_MINIMIS_AID}.yes`
)}
onChange={() =>
formik.setFieldValue(fields.deMinimisAid.name, true)
}
checked={formik.values.deMinimisAid === true}
/>
</SelectionGroup>
</$GridCell>

{formik.values.deMinimisAid && (
<>
<DeMinimisAidForm data={deMinimisAidSet} />
<DeMinimisAidsList />
</>
)}
</FormSection>
)}
{formik.values.deMinimisAid && (
<>
<DeMinimisAidForm data={deMinimisAidSet} />
<DeMinimisAidsList />
</>
)}
</FormSection>
)}
<FormSection paddingBottom header={t(`${translationsBase}.heading4`)}>
<$GridCell $colSpan={8}>
<SelectionGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ const useApplicationFormStep1 = (
const applicationId = values?.id;
const handleDelete = applicationId
? () => {
void onDelete(applicationId);
}
void onDelete(applicationId);
}
: undefined;

const clearDeminimisAids = React.useCallback((): void => {
Expand All @@ -125,7 +125,7 @@ const useApplicationFormStep1 = (

const showDeminimisSection =
values.associationHasBusinessActivities === true ||
organizationType !== ORGANIZATION_TYPES.ASSOCIATION;
organizationType === ORGANIZATION_TYPES.COMPANY;

const languageOptions = React.useMemo(
(): OptionType<string>[] => getLanguageOptions(t, 'languages'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,24 @@ export const getValidationSchema = (
.required(t(VALIDATION_MESSAGE_KEYS.REQUIRED)),
[APPLICATION_FIELDS_STEP1_KEYS.DE_MINIMIS_AID]: Yup.boolean()
.nullable()
.required(t(VALIDATION_MESSAGE_KEYS.REQUIRED)),
.when(APPLICATION_FIELDS_STEP1_KEYS.ASSOCIATION_HAS_BUSINESS_ACTIVITIES, {
is: true,
then: Yup.boolean()
.nullable()
.required(t(VALIDATION_MESSAGE_KEYS.REQUIRED)),
})
.test({
message: t(VALIDATION_MESSAGE_KEYS.REQUIRED),
test: (val) => {
if (
organizationType?.toLowerCase() ===
ORGANIZATION_TYPES.COMPANY.toLowerCase()
) {
return typeof val === 'boolean';
}
return true;
},
}),
[APPLICATION_FIELDS_STEP1_KEYS.DE_MINIMIS_AID_SET]: Yup.array().of(
getDeminimisValidationSchema(t).nullable()
),
Expand Down

0 comments on commit 8b65e8d

Please sign in to comment.