fix tabs switch bag for matches table
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { ViolationFileDetail } from '@/app/hooks/react-query/useFileViolations';
|
import { ViolationFileDetail } from '@/app/hooks/react-query/useFileViolations';
|
||||||
import { useActionState, useEffect, useState } from 'react';
|
import {useActionState, useEffect, useState, SetStateAction} from 'react';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { createComplaint, fetchComplainInfo, MatchStatus } from '@/app/actions/violationActions';
|
import { createComplaint, fetchComplainInfo, MatchStatus } from '@/app/actions/violationActions';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
@@ -23,28 +23,29 @@ interface complaintInfo {
|
|||||||
const ENABLED_STATUSES = ['COMPLAINT_IN_WORK', 'COMPLAINT_AND_LEGAL_IN_WORK'];
|
const ENABLED_STATUSES = ['COMPLAINT_IN_WORK', 'COMPLAINT_AND_LEGAL_IN_WORK'];
|
||||||
type UpdateStatusHandler = (id: number, status: MatchStatus) => Promise<boolean>;
|
type UpdateStatusHandler = (id: number, status: MatchStatus) => Promise<boolean>;
|
||||||
|
|
||||||
export default function CaseComplaint({ selectedViolation, updateStatusHandler }: { selectedViolation: ViolationFileDetail, updateStatusHandler: UpdateStatusHandler }) {
|
export default function CaseComplaint({ selectedViolation, updateStatusHandler, setLocalViolation }:
|
||||||
|
{
|
||||||
|
selectedViolation: ViolationFileDetail,
|
||||||
|
updateStatusHandler: UpdateStatusHandler,
|
||||||
|
setLocalViolation: React.Dispatch<SetStateAction<ViolationFileDetail>>
|
||||||
|
}
|
||||||
|
) {
|
||||||
const t = useTranslations('Global');
|
const t = useTranslations('Global');
|
||||||
|
|
||||||
const [localViolation, setLocalViolation] = useState<ViolationFileDetail>(selectedViolation);
|
|
||||||
const [noteText, setNoteText] = useState('');
|
const [noteText, setNoteText] = useState('');
|
||||||
const [state, formAction, isPending] = useActionState(createComplaint, undefined);
|
const [state, formAction, isPending] = useActionState(createComplaint, undefined);
|
||||||
const [isTemplateModalOpen, setIsTemplateModalOpen] = useState(false);
|
const [isTemplateModalOpen, setIsTemplateModalOpen] = useState(false);
|
||||||
const [templateName, setTemplateName] = useState('');
|
const [templateName, setTemplateName] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setLocalViolation(selectedViolation);
|
|
||||||
}, [selectedViolation]);
|
|
||||||
|
|
||||||
const { data: complainInfo, isLoading: isLoadingComplain } = useQuery({
|
const { data: complainInfo, isLoading: isLoadingComplain } = useQuery({
|
||||||
queryKey: ['complainInfo', localViolation.id],
|
queryKey: ['complainInfo', selectedViolation.id],
|
||||||
queryFn: () => fetchComplainInfo(localViolation.id),
|
queryFn: () => fetchComplainInfo(selectedViolation.id),
|
||||||
select: (data) => {
|
select: (data) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enabled: ENABLED_STATUSES.includes(localViolation.status),
|
enabled: ENABLED_STATUSES.includes(selectedViolation.status),
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -58,7 +59,7 @@ export default function CaseComplaint({ selectedViolation, updateStatusHandler }
|
|||||||
setLocalViolation(prev => ({
|
setLocalViolation(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
status: newStatus
|
status: newStatus
|
||||||
}));
|
}))
|
||||||
|
|
||||||
updateStatusHandler(selectedViolation.id, newStatus);
|
updateStatusHandler(selectedViolation.id, newStatus);
|
||||||
} else if (state && !state.success) {
|
} else if (state && !state.success) {
|
||||||
@@ -106,13 +107,13 @@ export default function CaseComplaint({ selectedViolation, updateStatusHandler }
|
|||||||
setTemplateName('');
|
setTemplateName('');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ENABLED_STATUSES.includes(localViolation.status)) {
|
if (!ENABLED_STATUSES.includes(selectedViolation.status)) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="violation-info-case">
|
<div className="violation-info-case">
|
||||||
<div className="note-form">
|
<div className="note-form">
|
||||||
<form action={formAction}>
|
<form action={formAction}>
|
||||||
<input type="hidden" name="violationId" value={localViolation.id} />
|
<input type="hidden" name="violationId" value={selectedViolation.id} />
|
||||||
<section
|
<section
|
||||||
className="note-form-section"
|
className="note-form-section"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { ViolationFileDetail } from '@/app/hooks/react-query/useFileViolations';
|
import { ViolationFileDetail } from '@/app/hooks/react-query/useFileViolations';
|
||||||
import { useEffect, useState, useActionState } from 'react';
|
import { useEffect, useActionState, SetStateAction } from 'react';
|
||||||
import { fetchCaseInfo, createCase, MatchStatus } from '@/app/actions/violationActions';
|
import { fetchCaseInfo, createCase, MatchStatus } from '@/app/actions/violationActions';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
@@ -29,20 +29,25 @@ interface CaseInfo {
|
|||||||
const ENABLED_STATUSES = ['LEGAL_IN_WORK', 'COMPLAINT_AND_LEGAL_IN_WORK'];
|
const ENABLED_STATUSES = ['LEGAL_IN_WORK', 'COMPLAINT_AND_LEGAL_IN_WORK'];
|
||||||
type UpdateStatusHandler = (id: number, status: MatchStatus) => Promise<boolean>;
|
type UpdateStatusHandler = (id: number, status: MatchStatus) => Promise<boolean>;
|
||||||
|
|
||||||
export default function CaseViolation({ selectedViolation, updateStatusHandler }: { selectedViolation: ViolationFileDetail, updateStatusHandler: UpdateStatusHandler }) {
|
export default function CaseViolation({ selectedViolation, updateStatusHandler, setLocalViolation }:
|
||||||
|
{
|
||||||
|
selectedViolation: ViolationFileDetail,
|
||||||
|
updateStatusHandler: UpdateStatusHandler,
|
||||||
|
setLocalViolation: React.Dispatch<SetStateAction<ViolationFileDetail>>
|
||||||
|
}
|
||||||
|
) {
|
||||||
const t = useTranslations('Global');
|
const t = useTranslations('Global');
|
||||||
const [localViolation, setLocalViolation] = useState<ViolationFileDetail>(selectedViolation);
|
|
||||||
const [state, formAction, isPending] = useActionState(createCase, undefined);
|
const [state, formAction, isPending] = useActionState(createCase, undefined);
|
||||||
|
|
||||||
const { data: caseInfo, isLoading: isLoadingCase } = useQuery({
|
const { data: caseInfo, isLoading: isLoadingCase } = useQuery({
|
||||||
queryKey: ['caseInfo', localViolation.id],
|
queryKey: ['caseInfo', selectedViolation.id],
|
||||||
queryFn: () => fetchCaseInfo(localViolation.id),
|
queryFn: () => fetchCaseInfo(selectedViolation.id),
|
||||||
select: (data) => {
|
select: (data) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enabled: ENABLED_STATUSES.includes(localViolation.status)
|
enabled: ENABLED_STATUSES.includes(selectedViolation.status)
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -56,7 +61,7 @@ export default function CaseViolation({ selectedViolation, updateStatusHandler }
|
|||||||
setLocalViolation(prev => ({
|
setLocalViolation(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
status: newStatus
|
status: newStatus
|
||||||
}));
|
}))
|
||||||
|
|
||||||
updateStatusHandler(selectedViolation.id, newStatus);
|
updateStatusHandler(selectedViolation.id, newStatus);
|
||||||
} else if (state && !state.success) {
|
} else if (state && !state.success) {
|
||||||
@@ -69,12 +74,12 @@ export default function CaseViolation({ selectedViolation, updateStatusHandler }
|
|||||||
}
|
}
|
||||||
}, [state, updateStatusHandler, selectedViolation.id]);
|
}, [state, updateStatusHandler, selectedViolation.id]);
|
||||||
|
|
||||||
if (!ENABLED_STATUSES.includes(localViolation.status)) {
|
if (!ENABLED_STATUSES.includes(selectedViolation.status)) {
|
||||||
return (
|
return (
|
||||||
<div className="violation-info-case">
|
<div className="violation-info-case">
|
||||||
<div className="note-form">
|
<div className="note-form">
|
||||||
<form action={formAction}>
|
<form action={formAction}>
|
||||||
<input type="hidden" name="violationId" value={localViolation.id} />
|
<input type="hidden" name="violationId" value={selectedViolation.id} />
|
||||||
<div
|
<div
|
||||||
className="note-form-flex"
|
className="note-form-flex"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ export default function FilePageViolationInfoTabs({ selectedViolation, updateSta
|
|||||||
key={"complaint_" + localViolation.id}
|
key={"complaint_" + localViolation.id}
|
||||||
selectedViolation={localViolation}
|
selectedViolation={localViolation}
|
||||||
updateStatusHandler={updateStatusHandler}
|
updateStatusHandler={updateStatusHandler}
|
||||||
|
setLocalViolation={setLocalViolation}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{activeTab === 'claim' && (
|
{activeTab === 'claim' && (
|
||||||
@@ -120,6 +121,7 @@ export default function FilePageViolationInfoTabs({ selectedViolation, updateSta
|
|||||||
key={"legal_" + localViolation.id}
|
key={"legal_" + localViolation.id}
|
||||||
selectedViolation={localViolation}
|
selectedViolation={localViolation}
|
||||||
updateStatusHandler={updateStatusHandler}
|
updateStatusHandler={updateStatusHandler}
|
||||||
|
setLocalViolation={setLocalViolation}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user