From 41c56e026ff4faa4921b362dbd18dc66233101c6 Mon Sep 17 00:00:00 2001 From: smanylov Date: Wed, 29 Apr 2026 15:40:34 +0700 Subject: [PATCH] add max lenght validation for create complaint/claim --- src/app/actions/definitions.ts | 3 +++ src/app/ui/file-page/violation-table/case-complaint.tsx | 6 ++---- src/app/ui/file-page/violation-table/case-legal.tsx | 5 ++--- src/i18n/messages/en.json | 3 +++ src/i18n/messages/ru.json | 3 +++ 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/app/actions/definitions.ts b/src/app/actions/definitions.ts index 972eaf3..9f15afd 100644 --- a/src/app/actions/definitions.ts +++ b/src/app/actions/definitions.ts @@ -89,6 +89,7 @@ export const createComplaintSchema = z textArea: z .string() .min(6, { error: 'text-area-error-fill-complaint-text' }) + .max(2000, {error: 'text-area-error-complaint-text-too-long'}) .trim(), }) @@ -97,10 +98,12 @@ export const createCaseSchema = z textArea: z .string() .min(6, { error: 'fill-text-of-the-case' }) + .max(2000, {error: 'claim-text-must-not-exceed-2000-characters'}) .trim(), caseTitle: z .string() .min(6, { error: 'fill-title-of-the-case' }) + .max(300, {error: 'claim-title-must-not-exceed-300-characters'}) .trim(), }) diff --git a/src/app/ui/file-page/violation-table/case-complaint.tsx b/src/app/ui/file-page/violation-table/case-complaint.tsx index b74b07c..9325420 100644 --- a/src/app/ui/file-page/violation-table/case-complaint.tsx +++ b/src/app/ui/file-page/violation-table/case-complaint.tsx @@ -3,10 +3,9 @@ import { ViolationFileDetail } from '@/app/hooks/react-query/useFileViolations'; import { useActionState, useEffect, useState } from 'react'; import { useTranslations } from 'next-intl'; -import { createComplaint, fetchComplainInfo } from '@/app/actions/violationActions'; +import { createComplaint, fetchComplainInfo, MatchStatus } from '@/app/actions/violationActions'; import { toast } from 'sonner'; -import { useQuery, useQueryClient } from '@tanstack/react-query'; -import { MatchStatus } from '@/app/actions/violationActions'; +import { useQuery } from '@tanstack/react-query'; import { formatDate, formatDateTime } from '@/app/lib/formatDate'; interface complaintInfo { @@ -25,7 +24,6 @@ type UpdateStatusHandler = (id: number, status: MatchStatus) => Promise export default function CaseComplaint({ selectedViolation, updateStatusHandler }: { selectedViolation: ViolationFileDetail, updateStatusHandler: UpdateStatusHandler }) { const t = useTranslations('Global'); - const queryClient = useQueryClient(); const [localViolation, setLocalViolation] = useState(selectedViolation); const [noteText, setNoteText] = useState(''); diff --git a/src/app/ui/file-page/violation-table/case-legal.tsx b/src/app/ui/file-page/violation-table/case-legal.tsx index 1a08df8..2f60cc6 100644 --- a/src/app/ui/file-page/violation-table/case-legal.tsx +++ b/src/app/ui/file-page/violation-table/case-legal.tsx @@ -2,8 +2,8 @@ import { ViolationFileDetail } from '@/app/hooks/react-query/useFileViolations'; import { useEffect, useState, useActionState } from 'react'; -import { fetchCaseInfo, MatchStatus, createCase } from '@/app/actions/violationActions'; -import { useQuery, useQueryClient } from '@tanstack/react-query'; +import { fetchCaseInfo, createCase, MatchStatus } from '@/app/actions/violationActions'; +import { useQuery } from '@tanstack/react-query'; import { useTranslations } from 'next-intl'; import { toast } from 'sonner'; import { formatDate, formatDateTime } from '@/app/lib/formatDate'; @@ -31,7 +31,6 @@ type UpdateStatusHandler = (id: number, status: MatchStatus) => Promise export default function CaseViolation({ selectedViolation, updateStatusHandler }: { selectedViolation: ViolationFileDetail, updateStatusHandler: UpdateStatusHandler }) { const t = useTranslations('Global'); - const queryClient = useQueryClient(); const [localViolation, setLocalViolation] = useState(selectedViolation); const [state, formAction, isPending] = useActionState(createCase, undefined); diff --git a/src/i18n/messages/en.json b/src/i18n/messages/en.json index 0d29832..77be32b 100644 --- a/src/i18n/messages/en.json +++ b/src/i18n/messages/en.json @@ -394,6 +394,7 @@ "deselect": "Deselect", "select-all": "Select all", "text-area-error-fill-complaint-text": "Fill out the complaint text", + "text-area-error-complaint-text-too-long": "The complaint text must not exceed 2000 characters", "to-view-a-file-match-click-on-the-card-from-the-list": "To view a file match, click on the card from the list", "insufficient-funds-to-receive-payment": "Insufficient funds to receive payment", "not-found-payout-method": "Not found payout method", @@ -420,6 +421,8 @@ "text-of-the-case": "Text of the case", "fill-text-of-the-case": "Fill the case text", "fill-title-of-the-case": "Fill the case title", + "claim-title-must-not-exceed-300-characters": "The claim title must not exceed 300 characters", + "claim-text-must-not-exceed-2000-characters": "The text of the claim must not exceed 2000 characters", "enter-the-amount-of-damage": "Enter the amount of damage", "download-all": "Download all", "selected-files": "Selected files", diff --git a/src/i18n/messages/ru.json b/src/i18n/messages/ru.json index dc3965e..fcbf3ef 100644 --- a/src/i18n/messages/ru.json +++ b/src/i18n/messages/ru.json @@ -394,6 +394,7 @@ "deselect": "Снять выделение", "select-all": "Выбрать все", "text-area-error-fill-complaint-text": "Заполните текст жалобы", + "text-area-error-complaint-text-too-long": "Текст жалобы не должен превышать 2000 символов", "to-view-a-file-match-click-on-the-card-from-the-list": "Для просмотра совпадения по файлу нажмите на карточку из списка", "insufficient-funds-to-receive-payment": "Недостаточно средств для получения выплаты", "not-found-payout-method": "Метод выплаты не найден", @@ -420,6 +421,8 @@ "text-of-the-case": "Текст претензии", "fill-text-of-the-case": "Заполните текст претензии", "fill-title-of-the-case": "Заполните название претензии", + "claim-title-must-not-exceed-300-characters": "Название претензии не должно превышать 300 символов", + "claim-text-must-not-exceed-2000-characters": "Текст претензии не должен превышать 2000 символов", "enter-the-amount-of-damage": "Введите сумму ущерба", "download-all": "Скачать все", "selected-files": "Выбрано файлов",