Skip to content

Commit

Permalink
Refactor the variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
Malith-19 committed Dec 20, 2024
1 parent 95586aa commit 99ed0d0
Showing 1 changed file with 33 additions and 37 deletions.
70 changes: 33 additions & 37 deletions features/admin.validation.v1/pages/validation-config-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
state?.config?.ui?.features?.loginAndRegistration?.disabledFeatures);
const isRuleBasedPasswordExpiryDisabled: boolean = disabledFeatures?.includes("ruleBasedPasswordExpiry");
const featureConfig: FeatureConfigInterface = useSelector((state: AppState) => state?.config?.ui?.features);
const maxPasswordLenghtLimit: number = useSelector((state: AppState) =>
const maxPasswordLengthLimit: number = useSelector((state: AppState) =>
state?.config?.ui?.passwordPolicyConfigs?.maxPasswordAllowedLength);
const maxPasswordLenghtLimitLength: number = maxPasswordLenghtLimit.toString().length;
const maxPasswordLengthLimitLength: number = maxPasswordLengthLimit.toString().length;

const [ isSubmitting, setSubmitting ] = useState<boolean>(false);
const [ initialFormValues, setInitialFormValues ] = useState<
Expand Down Expand Up @@ -512,10 +512,10 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
description = t(
"validation:validationError.minLimitError"
);
} else if (Number(values.maxLength) > maxPasswordLenghtLimit) {
} else if (Number(values.maxLength) > maxPasswordLengthLimit) {
error = true;
description = t(
"validation:validationError.maxLimitError", { maxPasswordValue: maxPasswordLenghtLimit }
"validation:validationError.maxLimitError", { maxPasswordValue: maxPasswordLengthLimit }
);
} else if (Number(values.minLength) > Number(values.maxLength)) {
error = true;
Expand Down Expand Up @@ -743,7 +743,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
}
const max: number = allValues.maxLength
? parseInt(allValues.maxLength as string)
: maxPasswordLenghtLimit;
: maxPasswordLengthLimit;

if (numValue > max) {
return t("common:maxValidation", { max });
Expand All @@ -757,7 +757,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
max={
currentValues.maxLength
? currentValues.maxLength
: maxPasswordLenghtLimit
: maxPasswordLengthLimit
}
listen={ (
value: string
Expand All @@ -774,7 +774,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
required
hidden={ false }
placeholder={ "min" }
maxLength={ maxPasswordLenghtLimitLength }
maxLength={ maxPasswordLengthLimitLength }
minLength={
ValidationConfigConstants
.VALIDATION_CONFIGURATION_FORM_FIELD_CONSTRAINTS
Expand Down Expand Up @@ -806,10 +806,8 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
return t("common:minValidation", { min });
}

const max: number = maxPasswordLenghtLimit;

if (numValue > max) {
return t("common:maxValidation", { max });
if (numValue > maxPasswordLengthLimit) {
return t("common:maxValidation", { maxPasswordLengthLimit });
}
} }
min={
Expand All @@ -819,7 +817,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
.VALIDATION_CONFIGURATION_FORM_FIELD_CONSTRAINTS
.PASSWORD_MIN_VALUE
}
max={ maxPasswordLenghtLimit }
max={ maxPasswordLengthLimit }
width={ 2 }
required
hidden={ false }
Expand All @@ -835,7 +833,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
}
);
} }
maxLength={ maxPasswordLenghtLimitLength }
maxLength={ maxPasswordLengthLimitLength }
labelPosition="top"
minLength={
ValidationConfigConstants
Expand Down Expand Up @@ -1006,7 +1004,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
}
const max: number = allValues.maxLength
? parseInt(allValues.maxLength as string)
: maxPasswordLenghtLimit;
: maxPasswordLengthLimit;

if (numValue > max) {
return t("common:maxValidation", { max });
Expand All @@ -1020,13 +1018,13 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
max={
currentValues.maxLength
? currentValues.maxLength
: maxPasswordLenghtLimit
: maxPasswordLengthLimit
}
width={ 2 }
required
hidden={ false }
placeholder={ "min" }
maxLength={ maxPasswordLenghtLimitLength }
maxLength={ maxPasswordLengthLimitLength }
minLength={
ValidationConfigConstants
.VALIDATION_CONFIGURATION_FORM_FIELD_CONSTRAINTS
Expand Down Expand Up @@ -1066,10 +1064,8 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
return t("common:minValidation", { min });
}

const max: number = maxPasswordLenghtLimit;

if (numValue > max) {
return t("common:maxValidation", { max });
if (numValue > maxPasswordLengthLimit) {
return t("common:maxValidation", { maxPasswordLengthLimit });
}
} }
min={
Expand All @@ -1079,7 +1075,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
.VALIDATION_CONFIGURATION_FORM_FIELD_CONSTRAINTS
.PASSWORD_MIN_VALUE
}
max={ maxPasswordLenghtLimit }
max={ maxPasswordLengthLimit }
width={ 2 }
required
hidden={ false }
Expand All @@ -1094,7 +1090,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
}
);
} }
maxLength={ maxPasswordLenghtLimitLength }
maxLength={ maxPasswordLengthLimitLength }
labelPosition="top"
minLength={
ValidationConfigConstants
Expand Down Expand Up @@ -1138,7 +1134,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa

const max: number = allValues.minLength
? parseInt(allValues.minLength as string)
: maxPasswordLenghtLimit;
: maxPasswordLengthLimit;

if (numValue > max) {
return t("common:maxValidation", { max });
Expand All @@ -1152,7 +1148,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
max={
currentValues.minLength
? currentValues.minLength
: maxPasswordLenghtLimit
: maxPasswordLengthLimit
}
width={ 2 }
required
Expand All @@ -1168,7 +1164,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
}
);
} }
maxLength={ maxPasswordLenghtLimitLength }
maxLength={ maxPasswordLengthLimitLength }
minLength={
ValidationConfigConstants
.VALIDATION_CONFIGURATION_FORM_FIELD_CONSTRAINTS
Expand Down Expand Up @@ -1202,7 +1198,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa

const max: number = allValues.minLength
? parseInt(allValues.minLength as string)
: maxPasswordLenghtLimit;
: maxPasswordLengthLimit;

if (numValue > max) {
return t("common:maxValidation", { max });
Expand All @@ -1216,7 +1212,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
max={
currentValues.minLength
? currentValues.minLength
: maxPasswordLenghtLimit
: maxPasswordLengthLimit
}
width={ 2 }
required
Expand All @@ -1232,7 +1228,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
}
);
} }
maxLength={ maxPasswordLenghtLimitLength }
maxLength={ maxPasswordLengthLimitLength }
minLength={
ValidationConfigConstants
.VALIDATION_CONFIGURATION_FORM_FIELD_CONSTRAINTS
Expand Down Expand Up @@ -1267,7 +1263,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa

const max: number = allValues.minLength
? parseInt(allValues.minLength as string)
: maxPasswordLenghtLimit;
: maxPasswordLengthLimit;

if (numValue > max) {
return t("common:maxValidation", { max });
Expand All @@ -1281,7 +1277,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
max={
currentValues.minLength
? currentValues.minLength
: maxPasswordLenghtLimit
: maxPasswordLengthLimit
}
width={ 2 }
required
Expand All @@ -1297,7 +1293,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
}
);
} }
maxLength={ maxPasswordLenghtLimitLength }
maxLength={ maxPasswordLengthLimitLength }
minLength={
ValidationConfigConstants
.VALIDATION_CONFIGURATION_FORM_FIELD_CONSTRAINTS
Expand Down Expand Up @@ -1332,7 +1328,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa

const max: number = allValues.minLength
? parseInt(allValues.minLength as string)
: maxPasswordLenghtLimit;
: maxPasswordLengthLimit;

if (numValue > max) {
return t("common:maxValidation", { max });
Expand All @@ -1346,7 +1342,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
max={
currentValues.minLength
? currentValues.minLength
: maxPasswordLenghtLimit
: maxPasswordLengthLimit
}
width={ 2 }
required
Expand Down Expand Up @@ -1416,7 +1412,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa

const max: number = allValues.minLength
? parseInt(allValues.minLength as string)
: maxPasswordLenghtLimit;
: maxPasswordLengthLimit;

if (numValue > max) {
return t("common:maxValidation", { max });
Expand All @@ -1426,7 +1422,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
max={
currentValues.minLength
? currentValues.minLength
: maxPasswordLenghtLimit
: maxPasswordLengthLimit
}
width={ 2 }
required
Expand Down Expand Up @@ -1505,7 +1501,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa

const max: number = allValues.minLength
? parseInt(allValues.minLength as string)
: maxPasswordLenghtLimit;
: maxPasswordLengthLimit;

if (numValue > max) {
return t("common:maxValidation", { max });
Expand All @@ -1515,7 +1511,7 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
max={
currentValues.minLength
? currentValues.minLength
: maxPasswordLenghtLimit
: maxPasswordLengthLimit
}
width={ 2 }
required
Expand Down

0 comments on commit 99ed0d0

Please sign in to comment.