Skip to content

Commit

Permalink
Add max body validator
Browse files Browse the repository at this point in the history
  • Loading branch information
osamasayed committed Nov 27, 2023
1 parent 8f12576 commit 0711dce
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/Notes/NoteModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type NoteFormData = {

const TITLE_MAXIMUM_LENGTH = 150;
const BODY_MIN_LENGTH = 6;
const BODY_MAX_LENGTH = 10000;

const TITLE_VALIDATION_PARAMS = {
value: TITLE_MAXIMUM_LENGTH,
Expand All @@ -57,6 +58,9 @@ const TITLE_VALIDATION_PARAMS = {
const BODY_MIN_VALIDATION_PARAMS = {
value: BODY_MIN_LENGTH,
};
const BODY_MAX_VALIDATION_PARAMS = {
value: BODY_MAX_LENGTH,
};

const NoteModal: React.FC<NoteModalProps> = ({
onClose,
Expand Down Expand Up @@ -272,6 +276,22 @@ const NoteModal: React.FC<NoteModalProps> = ({
},
),
},
{
...BODY_MAX_VALIDATION_PARAMS,
type: RuleType.MaximumLength,
errorId: ErrorMessageId.MaximumLength,
errorExtraParams: {
...BODY_MAX_VALIDATION_PARAMS,
},
errorMessage: buildTranslatedErrorMessageByErrorId(
ErrorMessageId.MaximumLength,
'body',
t,
{
...BODY_MAX_VALIDATION_PARAMS,
},
),
},
],
type: FormFieldType.TextArea,
containerClassName: styles.bodyInput,
Expand Down

0 comments on commit 0711dce

Please sign in to comment.