change matched table layout
This commit is contained in:
@@ -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>
|
||||
);
|
||||
|
||||
@@ -32,7 +32,6 @@ type UpdateStatusHandler = (id: number, status: MatchStatus) => Promise<boolean>
|
||||
export default function CaseViolation({ selectedViolation, updateStatusHandler }: { selectedViolation: ViolationFileDetail, updateStatusHandler: UpdateStatusHandler }) {
|
||||
const t = useTranslations('Global');
|
||||
const queryClient = useQueryClient();
|
||||
const [showCreateCase, setShowCreateCase] = useState(false);
|
||||
const [localViolation, setLocalViolation] = useState<ViolationFileDetail>(selectedViolation);
|
||||
const [state, formAction, isPending] = useActionState(createCase, undefined);
|
||||
|
||||
@@ -61,8 +60,6 @@ export default function CaseViolation({ selectedViolation, updateStatusHandler }
|
||||
}));
|
||||
|
||||
updateStatusHandler(selectedViolation.id, newStatus);
|
||||
|
||||
setShowCreateCase(false);
|
||||
} else if (state && !state.success) {
|
||||
console.log(state.errorMessage);
|
||||
if (state.errorMessage?.server) {
|
||||
@@ -73,144 +70,121 @@ export default function CaseViolation({ selectedViolation, updateStatusHandler }
|
||||
}
|
||||
}, [state, updateStatusHandler, selectedViolation.id]);
|
||||
|
||||
function toggleForm() {
|
||||
setShowCreateCase(!showCreateCase);
|
||||
}
|
||||
|
||||
if (!ENABLED_STATUSES.includes(localViolation.status)) {
|
||||
return (
|
||||
<div className="violation-info-case">
|
||||
{!showCreateCase ? (
|
||||
<button
|
||||
type="button"
|
||||
className="btn-action btn-case"
|
||||
onClick={toggleForm}
|
||||
>
|
||||
{t('create-case')}
|
||||
</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} />
|
||||
<div
|
||||
className="note-form-flex"
|
||||
>
|
||||
{t('cancel')}
|
||||
</button>
|
||||
|
||||
<div className="note-form">
|
||||
<form action={formAction}>
|
||||
<input type="hidden" name="violationId" value={localViolation.id} />
|
||||
<div
|
||||
className="note-form-flex"
|
||||
<section
|
||||
className="note-form-group"
|
||||
>
|
||||
<label
|
||||
className="note-case-label"
|
||||
htmlFor="caseTitle"
|
||||
>
|
||||
<section
|
||||
className="note-form-group"
|
||||
{/* {t('case-name')} */}
|
||||
Название претензии
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="caseTitle"
|
||||
className="note-case-input"
|
||||
placeholder={t('fill-title-of-the-case') + '...'}
|
||||
/>
|
||||
{state?.errorMessage?.caseTitle && (
|
||||
<p
|
||||
className="text-sm text-red-500"
|
||||
>
|
||||
<label
|
||||
className="note-case-label"
|
||||
htmlFor="caseTitle"
|
||||
>
|
||||
{t('case-name')}
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="caseTitle"
|
||||
className="note-case-input"
|
||||
placeholder={t('fill-title-of-the-case') + '...'}
|
||||
/>
|
||||
{state?.errorMessage?.caseTitle && (
|
||||
<p
|
||||
className="text-sm text-red-500"
|
||||
>
|
||||
{
|
||||
state?.errorMessage?.caseTitle.split('&').map((e, index) => {
|
||||
return (
|
||||
<span key={index}>
|
||||
{t(e)}
|
||||
<br />
|
||||
</span>
|
||||
)
|
||||
})
|
||||
}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
<section
|
||||
className="note-form-group"
|
||||
>
|
||||
<label
|
||||
className="note-case-label"
|
||||
htmlFor="amount"
|
||||
>
|
||||
{t('amount-of-damage')}
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="amount"
|
||||
className="note-case-input"
|
||||
placeholder={t('enter-the-amount-of-damage') + '...'}
|
||||
/>
|
||||
{state?.errorMessage?.amount && (
|
||||
<p
|
||||
className="text-sm text-red-500"
|
||||
>
|
||||
{
|
||||
state?.errorMessage?.amount.split('&').map((e, index) => {
|
||||
return (
|
||||
<span key={index}>
|
||||
{t(e)}
|
||||
<br />
|
||||
</span>
|
||||
)
|
||||
})
|
||||
}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section
|
||||
className="note-textarea-wrapper"
|
||||
{
|
||||
state?.errorMessage?.caseTitle.split('&').map((e, index) => {
|
||||
return (
|
||||
<span key={index}>
|
||||
{t(e)}
|
||||
<br />
|
||||
</span>
|
||||
)
|
||||
})
|
||||
}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
<section
|
||||
className="note-form-group"
|
||||
>
|
||||
<label
|
||||
className="note-case-label"
|
||||
htmlFor="amount"
|
||||
>
|
||||
<textarea
|
||||
name="note"
|
||||
className="note-textarea"
|
||||
placeholder={t('fill-text-of-the-case') + '...'}
|
||||
{t('amount-of-damage')}
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="amount"
|
||||
className="note-case-input"
|
||||
placeholder={t('enter-the-amount-of-damage') + '...'}
|
||||
/>
|
||||
{state?.errorMessage?.amount && (
|
||||
<p
|
||||
className="text-sm text-red-500"
|
||||
>
|
||||
</textarea>
|
||||
{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>
|
||||
)}
|
||||
</section>
|
||||
<div
|
||||
className="flex gap-3"
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
className="btn-small btn-primary-small"
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('submit-violation')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{
|
||||
state?.errorMessage?.amount.split('&').map((e, index) => {
|
||||
return (
|
||||
<span key={index}>
|
||||
{t(e)}
|
||||
<br />
|
||||
</span>
|
||||
)
|
||||
})
|
||||
}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<section
|
||||
className="note-textarea-wrapper"
|
||||
>
|
||||
<textarea
|
||||
name="note"
|
||||
className="note-textarea"
|
||||
placeholder={t('fill-text-of-the-case') + '...'}
|
||||
>
|
||||
</textarea>
|
||||
{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>
|
||||
)}
|
||||
</section>
|
||||
<div
|
||||
className="button-actions"
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
className="btn-small btn-primary-small"
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('submit-violation')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
@@ -237,22 +211,124 @@ export default function CaseViolation({ selectedViolation, updateStatusHandler }
|
||||
{caseInfo.body.content.map((item: CaseInfo) => {
|
||||
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('name')}:</strong> {item.name}</p>
|
||||
<p><strong>{t('description')}:</strong> {item.description}</p>
|
||||
<p><strong>{t('amount')}:</strong> {item.amount}</p>
|
||||
<p><strong>{t('priority')}:</strong> {item.priority}</p>
|
||||
<p><strong>{t('type')}:</strong> {item.type}</p>
|
||||
<p><strong>{t('lawyer')}:</strong> {item.lawyer || t('not-assigned')}</p>
|
||||
<p><strong>{t('violation-id')}:</strong> {item.violationId}</p>
|
||||
<p><strong>{t('date-of-creation')}:</strong> {item.createdAt ? `${formatDate(item.createdAt)}: ${formatDateTime(item.createdAt)}` : '---'}</p>
|
||||
<p><strong>{t('date-of-update')}:</strong> {item.createdAt ? `${formatDate(item.createdAt)}: ${formatDateTime(item.createdAt)}` : '---'}</p>
|
||||
{/* <div className="complaint-details">
|
||||
<div><strong>ID:</strong> {item.id}</div>
|
||||
<div><strong>{t('name')}:</strong>
|
||||
<br />
|
||||
{item.name}
|
||||
</div>
|
||||
<div><strong>{t('description')}:</strong> {item.description}</div>
|
||||
<div><strong>{t('amount')}:</strong> {item.amount}</div>
|
||||
<div><strong>{t('priority')}:</strong> {item.priority}</div>
|
||||
<div><strong>{t('type')}:</strong> {item.type}</div>
|
||||
<div><strong>{t('lawyer')}:</strong> {item.lawyer || t('not-assigned')}</div>
|
||||
<div><strong>{t('violation-id')}:</strong> {item.violationId}</div>
|
||||
<div><strong>{t('date-of-creation')}:</strong> {item.createdAt ? `${formatDate(item.createdAt)}: ${formatDateTime(item.createdAt)}` : '---'}</div>
|
||||
<div><strong>{t('date-of-update')}:</strong> {item.createdAt ? `${formatDate(item.createdAt)}: ${formatDateTime(item.createdAt)}` : '---'}</div>
|
||||
{item.content && <p><strong>{t('content')}:</strong> {item.content}</p>}
|
||||
</div> */}
|
||||
|
||||
|
||||
<div className="complaint-details">
|
||||
<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.type}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className="complaint-details-item"
|
||||
>
|
||||
<span
|
||||
className="complaint-details-title"
|
||||
>
|
||||
{t('date-of-creation')}:
|
||||
</span>
|
||||
<br />
|
||||
<span
|
||||
className="complaint-details-text"
|
||||
>
|
||||
{item.createdAt ? `${formatDate(item.createdAt)}: ${formatDateTime(item.createdAt)}` : '---'}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className="complaint-details-item"
|
||||
>
|
||||
<span
|
||||
className="complaint-details-title"
|
||||
>
|
||||
{t('date-of-update')}:
|
||||
</span>
|
||||
<br />
|
||||
<span
|
||||
className="complaint-details-text"
|
||||
>
|
||||
{item.updatedAt ? `${formatDate(item.updatedAt)}: ${formatDateTime(item.updatedAt)}` : '---'}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className="complaint-details-item"
|
||||
>
|
||||
<span
|
||||
className="complaint-details-title"
|
||||
>
|
||||
{t('description')}:
|
||||
</span>
|
||||
<br />
|
||||
<span
|
||||
className="complaint-details-text"
|
||||
>
|
||||
{item.description}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="complaint-details-item"
|
||||
>
|
||||
<span
|
||||
className="complaint-details-title"
|
||||
>
|
||||
{t('amount-of-damage')}:
|
||||
</span>
|
||||
<br />
|
||||
<span
|
||||
className="complaint-details-text"
|
||||
>
|
||||
{item.amount}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className="complaint-details-item"
|
||||
>
|
||||
<span
|
||||
className="complaint-details-title"
|
||||
>
|
||||
{t('lawyer')}:
|
||||
</span>
|
||||
<br />
|
||||
<span
|
||||
className="complaint-details-text"
|
||||
>
|
||||
{item.lawyer}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -31,7 +31,7 @@ export default function FilePageViolationInfoTabs({ selectedViolation, updateSta
|
||||
<h4>Вы можете</h4>
|
||||
<div className="violation-info-choice-buttons">
|
||||
<button
|
||||
className="violation-info-choice-btn"
|
||||
className="btn btn-primary"
|
||||
onClick={() => {
|
||||
setShowTabs(true);
|
||||
setActiveTab('complaint');
|
||||
@@ -45,7 +45,7 @@ export default function FilePageViolationInfoTabs({ selectedViolation, updateSta
|
||||
</span>
|
||||
|
||||
<button
|
||||
className="violation-info-choice-btn"
|
||||
className="btn btn-primary"
|
||||
onClick={() => {
|
||||
setShowTabs(true);
|
||||
setActiveTab('legal');
|
||||
@@ -62,13 +62,13 @@ export default function FilePageViolationInfoTabs({ selectedViolation, updateSta
|
||||
<div className="violation-info-tabs-wrapper">
|
||||
<div className="violation-info-tabs">
|
||||
<button
|
||||
className={`violation-info-tab ${activeTab === 'complaint' ? 'violation-info-tab--active' : ''}`}
|
||||
className={`btn btn-primary ${activeTab === 'complaint' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('complaint')}
|
||||
>
|
||||
Жалоба
|
||||
</button>
|
||||
<button
|
||||
className={`violation-info-tab ${activeTab === 'legal' ? 'violation-info-tab--active' : ''}`}
|
||||
className={`btn btn-primary ${activeTab === 'legal' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('legal')}
|
||||
>
|
||||
Претензия
|
||||
|
||||
@@ -14,6 +14,7 @@ import { toast } from 'sonner';
|
||||
import FilePageViolationEpmtyScreen from '@/app/ui/file-page/violation-table/file-page-violation-epmty-screen';
|
||||
import Image from 'next/image';
|
||||
import FilePageViolationInfoTabs from '@/app/ui/file-page/violation-table/file-page-violation-info-tabs';
|
||||
import { createPortal } from 'react-dom';
|
||||
|
||||
export default function FilePageViolationInfo({ selectedViolation }: { selectedViolation: ViolationFileDetail | null }) {
|
||||
const t = useTranslations('Global');
|
||||
@@ -21,6 +22,13 @@ export default function FilePageViolationInfo({ selectedViolation }: { selectedV
|
||||
const queryClient = useQueryClient();
|
||||
const [localViolation, setLocalViolation] = useState<ViolationFileDetail | null>(null);
|
||||
const [isUpdating, setIsUpdating] = useState(false);
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
|
||||
const openInNewTab = () => {
|
||||
if (selectedViolation?.url) {
|
||||
window.open(selectedViolation.url, '_blank');
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setLocalViolation(selectedViolation);
|
||||
@@ -55,6 +63,11 @@ export default function FilePageViolationInfo({ selectedViolation }: { selectedV
|
||||
}
|
||||
}, [queryClient, selectedViolation]);
|
||||
|
||||
const cleanUrlForDisplay = (url: string) => {
|
||||
if (!url) return '#';
|
||||
return url.split('?')[0];
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const updateStatus = async () => {
|
||||
if (selectedViolation && (selectedViolation.status === 'CREATED' || selectedViolation.status === 'NEW')) {
|
||||
@@ -71,10 +84,30 @@ export default function FilePageViolationInfo({ selectedViolation }: { selectedV
|
||||
)
|
||||
}
|
||||
|
||||
const ImageModal = ({ src, alt, onClose }: { src: string; alt: string; onClose: () => void }) => {
|
||||
return (
|
||||
<div className="image-modal-overlay" onClick={onClose}>
|
||||
<div className="image-modal-content" onClick={(e) => e.stopPropagation()}>
|
||||
<button className="image-modal-close" onClick={onClose}>×</button>
|
||||
<img src={src} alt={alt} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div
|
||||
className="violation-info"
|
||||
>
|
||||
{isModalOpen && createPortal(
|
||||
<ImageModal
|
||||
src={selectedViolation?.url || '/images/no-image.png'}
|
||||
alt={selectedViolation?.page_title || 'Image'}
|
||||
onClose={() => setIsModalOpen(false)}
|
||||
/>,
|
||||
document.body
|
||||
)}
|
||||
<div
|
||||
className="violation-info-content"
|
||||
>
|
||||
@@ -87,20 +120,47 @@ export default function FilePageViolationInfo({ selectedViolation }: { selectedV
|
||||
<div
|
||||
className="violation-info-header"
|
||||
>
|
||||
<div
|
||||
className="violation-info-image"
|
||||
>
|
||||
<Image
|
||||
src={selectedViolation?.url}
|
||||
alt={selectedViolation?.page_title}
|
||||
unoptimized
|
||||
fill
|
||||
sizes="100px"
|
||||
onError={(e) => {
|
||||
const target = e.target as HTMLImageElement;
|
||||
target.src = '/images/no-image.png';
|
||||
}}
|
||||
/>
|
||||
<div className="violation-info-image-wrapper">
|
||||
<div
|
||||
className="violation-info-image"
|
||||
>
|
||||
<Image
|
||||
src={selectedViolation?.url}
|
||||
alt={selectedViolation?.page_title}
|
||||
unoptimized
|
||||
fill
|
||||
sizes="100px"
|
||||
onError={(e) => {
|
||||
const target = e.target as HTMLImageElement;
|
||||
target.src = '/images/no-image.png';
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="violation-info-image-buttons">
|
||||
<button
|
||||
className="image-btn image-btn-view"
|
||||
onClick={() => setIsModalOpen(true)}
|
||||
title="Увеличить"
|
||||
>
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
||||
<line x1="11" y1="8" x2="11" y2="14" />
|
||||
<line x1="8" y1="11" x2="14" y2="11" />
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
className="image-btn image-btn-open"
|
||||
onClick={openInNewTab}
|
||||
title="Открыть в новой вкладке"
|
||||
>
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
|
||||
<polyline points="15 3 21 3 21 9" />
|
||||
<line x1="10" y1="14" x2="21" y2="3" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
@@ -118,7 +178,7 @@ export default function FilePageViolationInfo({ selectedViolation }: { selectedV
|
||||
target="_blank"
|
||||
scroll={false}
|
||||
>
|
||||
{selectedViolation?.page_url}
|
||||
{selectedViolation?.page_url ? cleanUrlForDisplay(selectedViolation?.page_url) : selectedViolation?.page_url}
|
||||
</Link>
|
||||
</div>
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user