Skip to content

Commit

Permalink
Merge pull request #645 from AkshataKatwal16/reassign-cohorts
Browse files Browse the repository at this point in the history
Issue feat: Add date field validation
  • Loading branch information
itsvick authored Jan 24, 2025
2 parents 62758e5 + eeaad43 commit 9c54d62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/GeneratedSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UiSchema } from '@rjsf/utils';
import { JSONSchema7 } from 'json-schema';
import NumberInputField from './form/NumberInputField';
import { FormData, Field, FieldOption } from '@/utils/Interfaces';
import { getCurrentYearPattern, getEmailPattern } from '@/utils/Helper';
import { getCurrentYearPattern, getEmailPattern, getLastDayDate } from '@/utils/Helper';

export const customFields = {
NumberInputField: NumberInputField,
Expand Down Expand Up @@ -246,6 +246,10 @@ export const GenerateSchemaAndUiSchema = (
if (field?.validation?.includes('currentYear')) {
fieldSchema.pattern = getCurrentYearPattern();
}
if (field?.validation?.includes('dob')) {
fieldSchema.minimum = '1900-01-01';
fieldSchema.maximum = getLastDayDate();
}
fieldSchema.validation = field.validation;
}

Expand Down
10 changes: 10 additions & 0 deletions src/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,3 +918,13 @@ export const getBMG = (cohortData: any) => {
}
return null;
};


export const getLastDayDate= (): string => {
const currentDate = new Date();
currentDate.setDate(currentDate.getDate() - 1); // Subtract 1 day
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, "0"); // Month is zero-indexed
const day = String(currentDate.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
};

0 comments on commit 9c54d62

Please sign in to comment.