Skip to content

Commit

Permalink
fix: bugs related to step 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mjturt committed Sep 25, 2023
1 parent 3d6850a commit 271c9c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,6 @@ const ApplicationFormStep2: React.FC<DynamicFormStepComponentProps> = ({

useAlertBeforeLeaving(formik.dirty);

const isAbleToSelectEmploymentBenefit =
data?.company?.organizationType !== ORGANIZATION_TYPES.ASSOCIATION ||
(data?.company?.organizationType === ORGANIZATION_TYPES.ASSOCIATION &&
data?.associationHasBusinessActivities);

// TODO: Preselect this from backend
const isAbleToSelectSalaryBenefit =
formik.values.paySubsidyGranted === PAY_SUBSIDY_GRANTED.GRANTED;

const isNoAvailableBenefitTypes =
formik.values.paySubsidyGranted !== null &&
!isAbleToSelectEmploymentBenefit &&
!isAbleToSelectSalaryBenefit;

return (
<form onSubmit={handleSubmit} noValidate>
<FormSection headerLevel="h2" header={t(`${translationsBase}.heading1`)}>
Expand Down Expand Up @@ -558,7 +544,6 @@ const ApplicationFormStep2: React.FC<DynamicFormStepComponentProps> = ({
handleSave={handleSave}
handleBack={handleBack}
handleDelete={handleDelete}
disabledNext={isNoAvailableBenefitTypes}
/>
</form>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ export const getValidationSchema = (
[APPLICATION_FIELDS_STEP2_KEYS.END_DATE]: Yup.string().required(
t(VALIDATION_MESSAGE_KEYS.REQUIRED)
),
[APPLICATION_FIELDS_STEP2_KEYS.ASSOCIATION_IMMEDIATE_MANAGER_CHECK]:
Yup.boolean()
.nullable()
.test({
message: t(VALIDATION_MESSAGE_KEYS.REQUIRED),
test: (val) => {
if (
organizationType?.toLowerCase() ===
ORGANIZATION_TYPES.ASSOCIATION.toLowerCase()
)
return val === true;

return true;
},
}),
[APPLICATION_FIELDS_STEP2_KEYS.EMPLOYEE]: Yup.object().shape({
[EMPLOYEE_KEYS.FIRST_NAME]: Yup.string()
.matches(NAMES_REGEX, t(VALIDATION_MESSAGE_KEYS.INVALID))
Expand All @@ -72,21 +87,6 @@ export const getValidationSchema = (
[true],
t(VALIDATION_MESSAGE_KEYS.REQUIRED_IS_LIVING_IN_HELSINKI)
),
[APPLICATION_FIELDS_STEP2_KEYS.ASSOCIATION_IMMEDIATE_MANAGER_CHECK]:
Yup.boolean()
.nullable()
.test({
message: t(VALIDATION_MESSAGE_KEYS.REQUIRED),
test: (val) => {
if (
organizationType?.toLowerCase() ===
ORGANIZATION_TYPES.ASSOCIATION.toLowerCase()
)
return val === true;

return true;
},
}),
[EMPLOYEE_KEYS.JOB_TITLE]: Yup.string()
.nullable()
.required(t(VALIDATION_MESSAGE_KEYS.REQUIRED)),
Expand Down

0 comments on commit 271c9c5

Please sign in to comment.