change matched table layout

This commit is contained in:
smanylov
2026-04-14 16:01:49 +07:00
parent 35b7f82ad9
commit c4aefdb8b9
9 changed files with 1335 additions and 853 deletions
@@ -7,6 +7,7 @@ import { createComplaint, fetchComplainInfo } from '@/app/actions/violationActio
import { toast } from 'sonner';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { MatchStatus } from '@/app/actions/violationActions';
import {formatDate, formatDateTime} from '@/app/lib/formatDate';
interface complaintInfo {
id: number,
@@ -26,8 +27,8 @@ export default function CaseComplaint({ selectedViolation, updateStatusHandler }
const t = useTranslations('Global');
const queryClient = useQueryClient();
const [showCreateCase, setShowCreateCase] = useState(false);
const [localViolation, setLocalViolation] = useState<ViolationFileDetail>(selectedViolation);
const [noteText, setNoteText] = useState('');
const [state, formAction, isPending] = useActionState(createComplaint, undefined);
useEffect(() => {
@@ -59,8 +60,6 @@ export default function CaseComplaint({ selectedViolation, updateStatusHandler }
}));
updateStatusHandler(selectedViolation.id, newStatus);
setShowCreateCase(false);
} else if (state && !state.success) {
console.log(state.errorMessage);
if (state.errorMessage?.server) {
@@ -71,72 +70,170 @@ export default function CaseComplaint({ selectedViolation, updateStatusHandler }
}
}, [state, updateStatusHandler, selectedViolation.id]);
function toggleForm() {
setShowCreateCase(!showCreateCase);
function templateHandler(e: React.MouseEvent<HTMLLIElement>) {
const sampleItemText = e.currentTarget.querySelector('.sample-item-text');
if (sampleItemText) {
const text = sampleItemText.textContent || '';
setNoteText(text);
}
}
if (!ENABLED_STATUSES.includes(localViolation.status)) {
return (
<div className="violation-info-case">
{!showCreateCase ? (
<button
type="button"
className="btn-action btn-case"
onClick={toggleForm}
>
{t('filing-complaint')}
</button>
) : (
<div>
<button
type="button"
className="btn-action btn-case"
onClick={toggleForm}
<div className="note-form">
<form action={formAction}>
<input type="hidden" name="violationId" value={localViolation.id} />
<textarea
name="note"
className="note-textarea"
placeholder={`${t('text-of-the-complaint')}...`}
value={noteText}
onChange={(e) => setNoteText(e.target.value)}
>
{t('cancel')}
</button>
</textarea>
<div
className="button-actions"
>
<button
type="submit"
className="btn-small btn-primary-small"
disabled={isPending}
onClick={(e) => {
e.preventDefault();
}}
>
Сохранить шаблон
</button>
<div className="note-form">
<form action={formAction}>
<input type="hidden" name="violationId" value={localViolation.id} />
<textarea
name="note"
className="note-textarea"
placeholder={`${t('text-of-the-complaint')}...`}>
</textarea>
<div
className="flex gap-3"
<button
type="submit"
className="btn-small btn-primary-small"
disabled={isPending}
>
{t('submit-violation')}
</button>
{state?.errorMessage?.textArea && (
<p
className="text-sm text-red-500"
>
<button
type="submit"
className="btn-small btn-primary-small"
disabled={isPending}
>
{t('submit-violation')}
</button>
{state?.errorMessage?.textArea && (
<p
className="text-sm text-red-500"
>
{
state?.errorMessage?.textArea.split('&').map((e, index) => {
return (
<span key={index}>
{t(e)}
<br />
</span>
)
})
}
</p>
)}
</div>
</form>
{
state?.errorMessage?.textArea.split('&').map((e, index) => {
return (
<span key={index}>
{t(e)}
<br />
</span>
)
})
}
</p>
)}
</div>
</div>
)}
</form>
</div>
<div
className="samples-wrapper"
>
<h5>Шаблоны</h5>
<ul
className="samples-list"
>
<li
className="sample-item"
onClick={(e) => {
templateHandler(e)
}}
>
<div
className="sample-item-title"
>
title 1
</div>
<div
className="sample-item-text"
>
1text text text text text text text text text text text text
</div>
</li>
<li
className="sample-item"
onClick={(e) => {
templateHandler(e)
}}
>
<div
className="sample-item-title"
>
title 2
</div>
<div
className="sample-item-text"
>
2text text text text text text text text text text text text
</div>
</li>
<li
className="sample-item"
onClick={(e) => {
templateHandler(e)
}}
>
<div
className="sample-item-title"
>
title 3
</div>
<div
className="sample-item-text"
>
3text text text text text text text text text text text text
</div>
</li>
<li
className="sample-item"
onClick={(e) => {
templateHandler(e)
}}
>
<div
className="sample-item-title"
>
title 3
</div>
<div
className="sample-item-text"
>
3text text text text text text text text text text text text
</div>
</li>
<li
className="sample-item"
onClick={(e) => {
templateHandler(e)
}}
>
<div
className="sample-item-title"
>
title 3
</div>
<div
className="sample-item-text"
>
3text text text text text text text text text text text text
</div>
</li>
</ul>
</div>
</div>
);
} else {
@@ -162,17 +259,72 @@ export default function CaseComplaint({ selectedViolation, updateStatusHandler }
{complainInfo.body.content.map((item: complaintInfo) => {
return (
<div key={item.id}>
<h3 className="mb-3">
{t('complaint-Information')}
</h3>
<div className="complaint-details">
<p><strong>ID:</strong> {item.id}</p>
<p><strong>{t('status')}:</strong> {item.status}</p>
<p><strong>{t('text-of-the-complaint')}:</strong> {item.complaint_text}</p>
<p><strong>{t('violation-id')}:</strong> {item.violation_id}</p>
<p><strong>{t('email')}:</strong> {item.email}</p>
<p><strong>{t('date-of-creation')}:</strong> {item.created_at}</p>
<p><strong>{t('date-of-update')}:</strong> {item.updated_at}</p>
<div
className="complaint-details-item"
>
<strong>ID:</strong> {item.id}
</div>
<div
className="complaint-details-item"
>
<span
className="complaint-details-title"
>
{t('status')}:
</span>
<br />
<span
className="complaint-details-text"
>
{item.status}
</span>
</div>
<div
className="complaint-details-item"
>
<span
className="complaint-details-title"
>
{t('date-of-creation')}:
</span>
<br />
<span
className="complaint-details-text"
>
{item.created_at ? `${formatDate(item.created_at)}: ${formatDateTime(item.created_at)}` : '---'}
</span>
</div>
<div
className="complaint-details-item"
>
<span
className="complaint-details-title"
>
{t('date-of-update')}:
</span>
<br />
<span
className="complaint-details-text"
>
{item.updated_at ? `${formatDate(item.updated_at)}: ${formatDateTime(item.updated_at)}` : '---'}
</span>
</div>
<div
className="complaint-details-item"
>
<span
className="complaint-details-title"
>
{t('text-of-the-complaint')}:
</span>
<br />
<span
className="complaint-details-text"
>
{item.complaint_text}
</span>
</div>
</div>
</div>
);