continue: create case

This commit is contained in:
smanylov
2026-04-07 19:05:44 +07:00
parent c57685065a
commit 50f45a133b
11 changed files with 519 additions and 28 deletions
@@ -6,6 +6,7 @@ import { useTranslations } from 'next-intl';
import { createComplaint, fetchComplainInfo } from '@/app/actions/violationActions';
import { toast } from 'sonner';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { MatchStatus } from '@/app/actions/violationActions';
interface complaintInfo {
id: number,
@@ -18,7 +19,10 @@ interface complaintInfo {
not_moderated: boolean
}
export default function CaseComplaint({ selectedViolation }: { selectedViolation: ViolationFileDetail }) {
const ENABLED_STATUSES = ['COMPLAINT_IN_WORK', 'COMPLAINT_AND_LEGAL_IN_WORK'];
type UpdateStatusHandler = (id: number, status: MatchStatus) => Promise<boolean>;
export default function CaseComplaint({ selectedViolation, updateStatusHandler }: { selectedViolation: ViolationFileDetail, updateStatusHandler: UpdateStatusHandler }) {
const t = useTranslations('Global');
const queryClient = useQueryClient();
@@ -38,26 +42,26 @@ export default function CaseComplaint({ selectedViolation }: { selectedViolation
return data
}
},
enabled: localViolation.status !== 'NEW' &&
localViolation.status !== 'CREATED' &&
localViolation.status !== 'SHOWED',
enabled: ENABLED_STATUSES.includes(localViolation.status),
});
useEffect(() => {
if (state?.success) {
toast.success(t('the-complaint-has-been-registered'));
const newStatus = selectedViolation.status === 'LEGAL_IN_WORK'
? 'COMPLAINT_AND_LEGAL_IN_WORK'
: 'COMPLAINT_IN_WORK';
setLocalViolation(prev => ({
...prev,
status: 'COMPLAINT_IN_WORK'
status: newStatus
}));
queryClient.invalidateQueries({ queryKey: ['fileViolations'] });
queryClient.invalidateQueries({ queryKey: ['complainInfo', localViolation.id] });
updateStatusHandler(selectedViolation.id, newStatus);
setShowCreateCase(false);
} else if (state && !state.success) {
console.log('state.errorMessage');
console.log(state.errorMessage);
if (state.errorMessage?.server) {
toast.warning(t(state.errorMessage.server));
@@ -65,13 +69,13 @@ export default function CaseComplaint({ selectedViolation }: { selectedViolation
toast.warning(t('the-complaint-has-not-been-registered'));
}
}
}, [state, queryClient, localViolation.id]);
}, [state, updateStatusHandler, selectedViolation.id]);
function toggleForm() {
setShowCreateCase(!showCreateCase);
}
if (localViolation.status === 'NEW' || localViolation.status === 'CREATED' || localViolation.status === 'SHOWED') {
if (!ENABLED_STATUSES.includes(localViolation.status)) {
return (
<div className="violation-info-case">
{!showCreateCase ? (