Skip to content

Commit

Permalink
FIO-8798: add isDayComponent type guard
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria-Golomb committed Aug 22, 2024
1 parent 07ac994 commit 129711f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/process/validation/rules/validateDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,37 @@ export const validateDay: RuleFn = async (context: ValidationContext) => {

export const validateDaySync: RuleFnSync = (context: ValidationContext) => {
const { component, value } = context;
if (!shouldValidate(context)) {
if (!shouldValidate(context) || !isDayComponent(component)) {
return null;
}
const error = new FieldError('invalidDay', context, 'day');
if (typeof value !== 'string') {
return error;
}
let [DAY, MONTH, YEAR] = (component as DayComponent).dayFirst ? [0, 1, 2] : [1, 0, 2];
let [DAY, MONTH, YEAR] = component.dayFirst ? [0, 1, 2] : [1, 0, 2];

const values = value.split('/').map((x) => parseInt(x, 10));
let day = values[DAY];
let month = values[MONTH];
let year = values[YEAR];

if(values.length !== 3) {
if((component as DayComponent).fields.day.hide) {
if (values.length !== 3) {
if (component.fields.day.hide) {
MONTH = MONTH === 0 ? 0 : MONTH - 1;
YEAR = YEAR - 1;
day = 0;
month = values[MONTH];
year = values[YEAR];

};
if((component as DayComponent).fields.month.hide) {
if (component.fields.month.hide) {
DAY = DAY === 0 ? 0 : DAY - 1;
YEAR = YEAR - 1;
day = values[DAY];
month = 0;
year = values[YEAR];
};
if((component as DayComponent).fields.year.hide) {
if (component.fields.year.hide) {
day = values[DAY];
month = values[MONTH];
year = 0;
Expand Down

0 comments on commit 129711f

Please sign in to comment.