Skip to content

Commit

Permalink
fix: add max length validation for description field with user feedba…
Browse files Browse the repository at this point in the history
…ck in NewLesson form
  • Loading branch information
typeWolffo committed Mar 7, 2025
1 parent 985f216 commit cb170a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/web/app/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@
"atLeastOneOptionRequired": "At least one option is required",
"imageRequired": "Image is required",
"descriptionLength": "Description must have at least 10 characters.",
"descritpionMaxLength": "Content can have a maximum of 3000 characters.",
"atLeastOneOptionCorrect": "At least one option must be marked as correct for question.",
"allOptionsCorrect": "All options must be correct",
"titleRequired": "Title is required",
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/locales/pl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@
"atLeastOneOptionRequired": "Wymagana jest przynajmniej jedna opcja",
"imageRequired": "Obrazek jest wymagany",
"descriptionLength": "Opis musi mieć co najmniej 10 znaków.",
"descritpionMaxLength": "Treść może mieć maksymalnie 3000 znaków.",
"atLeastOneOptionCorrect": "Przynajmniej jedna opcja musi być oznaczona jako poprawna.",
"allOptionsCorrect": "Wszystkie opcje muszą być poprawne",
"titleRequired": "Tytuł jest wymagany",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ const TextLessonForm = ({
setIsModalOpen(true);
};

const maxDescriptionFieldLength = 3000;

const watchedContentLength = form.watch("description").length;
const descriptionFieldCharactersLeft = Math.max(
0,
maxDescriptionFieldLength - watchedContentLength,
);

return (
<div className="flex flex-col gap-y-6 rounded-lg bg-white p-8">
<div className="flex flex-col gap-y-1">
Expand Down Expand Up @@ -102,6 +110,11 @@ const TextLessonForm = ({
</FormItem>
)}
/>

<p className="mt-1 text-neutral-800">
{descriptionFieldCharactersLeft} {t("adminCourseView.settings.other.charactersLeft")}
</p>

{form.formState.errors.description && (
<p className="details-md flex items-center gap-x-1.5 text-error-600">
<Icon name="Warning" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export const textLessonFormSchema = (t: typeof i18next.t) =>
description: z
.string()
.min(1, { message: t("adminCourseView.curriculum.lesson.validation.descriptionRequired") })
.max(3000, {
message: t("adminCourseView.curriculum.lesson.validation.descritpionMaxLength"),
})
.trim()
.refine((val) => val !== "<p></p>" && val.trim() !== "", {
message: t("adminCourseView.curriculum.lesson.validation.descriptionRequired"),
Expand Down

0 comments on commit cb170a3

Please sign in to comment.