mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 05:22:02 +00:00
feat(FE): Add validation for disabling close button in
ProjectFlockDetail
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Button from '@/components/Button';
|
||||
import Card from '@/components/Card';
|
||||
import { RadioGroup, RadioGroupItem } from '@/components/input/RadioInput';
|
||||
import { useSelect } from '@/components/input/SelectInput';
|
||||
import Tooltip from '@/components/Tooltip';
|
||||
import DrawerHeader from '@/components/helper/drawer/DrawerHeader';
|
||||
import { cn, formatCurrency, formatDate, formatNumber } from '@/lib/helper';
|
||||
@@ -37,10 +38,36 @@ const ProjectFlockDetail = ({
|
||||
null
|
||||
);
|
||||
|
||||
const { rawData: projectFlockRawData } = useSelect<ProjectFlock>(
|
||||
ProjectFlockApi.basePath,
|
||||
'id',
|
||||
'flock_name',
|
||||
'search',
|
||||
selectedKandangId ? { kandang_id: `[${selectedKandangId}]` } : undefined
|
||||
);
|
||||
|
||||
const selectedKandang = projectFlock.kandangs?.find(
|
||||
(kandang) => kandang.id === Number(selectedKandangId)
|
||||
);
|
||||
|
||||
const hasActiveProjectWithSameKandang = isResponseSuccess(projectFlockRawData)
|
||||
? projectFlockRawData.data.some((pf) =>
|
||||
pf.kandangs?.some(
|
||||
(k) =>
|
||||
k.id === Number(selectedKandangId) &&
|
||||
k.closed_at &&
|
||||
k.status !== 'NON_ACTIVE'
|
||||
)
|
||||
)
|
||||
: false;
|
||||
|
||||
const isCloseButtonDisabled =
|
||||
!selectedKandangId ||
|
||||
projectFlock?.approval?.step_number == 1 ||
|
||||
(projectFlock?.category === 'GROWING' &&
|
||||
selectedKandang?.status === 'NON_ACTIVE' &&
|
||||
hasActiveProjectWithSameKandang);
|
||||
|
||||
const { data: projectFlockApprovalResponse } = useSWR(
|
||||
projectFlock.id ? ['approval-project-flock', projectFlock.id] : undefined,
|
||||
([, id]) => ProjectFlockApi.getApprovalLineHistory(Number(id))
|
||||
@@ -419,10 +446,7 @@ const ProjectFlockDetail = ({
|
||||
className='w-full px-2 py-1 text-sm'
|
||||
variant='outline'
|
||||
color='error'
|
||||
disabled={
|
||||
!selectedKandangId ||
|
||||
projectFlock?.approval?.step_number == 1
|
||||
}
|
||||
disabled={isCloseButtonDisabled}
|
||||
>
|
||||
{selectedKandang?.status === 'NON_ACTIVE' ? (
|
||||
<>
|
||||
|
||||
+1
@@ -23,6 +23,7 @@ export type BaseProjectFlock = {
|
||||
kandang_ids: number[];
|
||||
kandangs: (Kandang & {
|
||||
project_flock_kandang_id: number;
|
||||
closed_at?: string;
|
||||
})[];
|
||||
project_budgets?: ProjectFlockBudget[];
|
||||
approval: BaseApproval;
|
||||
|
||||
Reference in New Issue
Block a user