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