feat(FE): workaround general information closing kandang

This commit is contained in:
randy-ar
2026-01-12 12:44:28 +07:00
parent ddd9a3d2da
commit d879acc001
4 changed files with 124 additions and 9 deletions
+26 -1
View File
@@ -7,18 +7,33 @@ import ClosingDetail from '@/components/pages/closing/ClosingDetail';
import { ClosingApi } from '@/services/api/closing';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { FlockApi } from '@/services/api/master-data';
import { ProjectFlockApi } from '@/services/api/production/project-flock';
import { ProjectFlockKandangApi } from '@/services/api/production';
const ClosingDetailPage = () => {
const router = useRouter();
const searchParams = useSearchParams();
const closingId = searchParams.get('closingId');
const kandangId = searchParams.get('kandangId'); // project flock kandang ID
const { data: closing, isLoading: isLoadingClosing } = useSWR(
closingId,
(id: number) => ClosingApi.getGeneralInfo(id)
);
// WORKAROUND - get flock data from closing ID
const { data: projectData, isLoading: isLoadingProject } = useSWR(
`flock-${closingId}`,
() => ProjectFlockApi.getSingle(Number(closingId))
);
// WORKAROUND - get kandang data from closing ID
const { data: kandangData, isLoading: isLoadingKandang } = useSWR(
kandangId ? `kandang-${closingId}-${kandangId}` : null,
() => ProjectFlockKandangApi.getSingle(Number(kandangId))
);
// const { data: salesData, isLoading: isLoadingSales } = useSWR(
// closingId ? `sales-${closingId}` : null,
// () => ClosingApi.getPenjualan(Number(closingId))
@@ -44,7 +59,11 @@ const ClosingDetailPage = () => {
return;
}
const isLoading = isLoadingClosing || isLoadingHppEkspedisi;
const isLoading =
isLoadingClosing ||
isLoadingHppEkspedisi ||
isLoadingProject ||
isLoadingKandang;
// const isLoading = isLoadingClosing || isLoadingSales || isLoadingHppEkspedisi;
return (
@@ -61,6 +80,12 @@ const ClosingDetailPage = () => {
? hppEkspedisiData.data
: undefined
}
projectData={
isResponseSuccess(projectData) ? projectData.data : undefined
}
kandangData={
isResponseSuccess(kandangData) ? kandangData.data : undefined
}
/>
)}
</div>
+19 -1
View File
@@ -19,12 +19,17 @@ import ClosingOverheadTabContent from '@/components/pages/closing/ClosingOverhea
import ClosingFinanceTabContent from '@/components/pages/closing/ClosingFinanceTabContent';
import SalesReportTable from '@/components/pages/closing/sale/SalesReportTable';
import HppExpeditionReportTable from './hpp-ekspedisi/HppExpeditionReportTable';
import ClosingKandangList from '@/components/pages/closing/ClosingKandangList';
import { ProjectFlock } from '@/types/api/production/project-flock';
import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
interface ClosingDetailProps {
id: number;
initialValue?: ClosingGeneralInformation;
salesData?: BaseClosingSales;
hppExpeditionData?: ClosingHppExpedition;
projectData?: ProjectFlock;
kandangData?: ProjectFlockKandang;
}
const ClosingDetail: React.FC<ClosingDetailProps> = ({
@@ -32,6 +37,8 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
initialValue,
salesData,
hppExpeditionData,
projectData,
kandangData,
}) => {
const [activeTab, setActiveTab] = useState<string>('sapronak');
@@ -98,7 +105,18 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
<h1 className='text-2xl font-bold text-center'>Detail Closing</h1>
</header>
<ClosingGeneralInformationTable initialValue={initialValue} />
<ClosingGeneralInformationTable
initialValue={initialValue}
projectData={projectData}
kandangData={kandangData}
/>
{!kandangData && (
<ClosingKandangList
initialValue={initialValue}
projectData={projectData}
/>
)}
<Tabs
activeTabId={activeTab}
@@ -1,12 +1,29 @@
import { ClosingGeneralInformation } from '@/types/api/closing';
import { ProjectFlock } from '@/types/api/production/project-flock';
import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
import { useMemo } from 'react';
interface ClosingGeneralInformationProps {
initialValue?: ClosingGeneralInformation;
projectData?: ProjectFlock;
kandangData?: ProjectFlockKandang;
}
const ClosingGeneralInformationTable = ({
initialValue,
projectData,
kandangData,
}: ClosingGeneralInformationProps) => {
const chickinPopulation = useMemo(() => {
if (kandangData) {
return kandangData?.chickins?.reduce(
(acc, chickin) => acc + chickin.usage_qty,
0
);
}
return 0;
}, [kandangData]);
return (
<div className='w-full my-4 @container'>
<div className='flex flex-col @sm:flex-row gap-4'>
@@ -17,7 +34,9 @@ const ClosingGeneralInformationTable = ({
<tr>
<td>Lokasi</td>
<td>:</td>
<td>{initialValue?.location_name}</td>
<td>
{initialValue?.location_name ?? projectData?.location?.name}
</td>
</tr>
<tr>
<td>Periode</td>
@@ -27,12 +46,20 @@ const ClosingGeneralInformationTable = ({
<tr>
<td>Project Flock</td>
<td>:</td>
<td>{initialValue?.project_flock?.name}</td>
<td>
{initialValue?.project_flock?.name ??
projectData?.flock_name}
</td>
</tr>
<tr>
<td>Populasi</td>
<td>:</td>
<td>{initialValue?.population} Ekor</td>
<td>
{!kandangData
? (initialValue?.population ?? 0)
: (chickinPopulation ?? 0)}{' '}
Ekor
</td>
</tr>
<tr>
<td>Jenis Project</td>
@@ -40,9 +67,13 @@ const ClosingGeneralInformationTable = ({
<td>{initialValue?.project_type}</td>
</tr>
<tr className='table-row @sm:hidden'>
<td>Kandang Aktif</td>
<td>Kandang {!kandangData && 'Aktif'}</td>
<td>:</td>
<td>{initialValue?.active_house_count} Kandang</td>
<td>
{!kandangData
? `${initialValue?.active_house_count} Kandang`
: kandangData?.kandang?.name}
</td>
</tr>
<tr className='table-row @sm:hidden'>
<td>Status Pembayaran Penjualan</td>
@@ -69,9 +100,13 @@ const ClosingGeneralInformationTable = ({
<table className='table table-zebra table-sm'>
<tbody>
<tr>
<td>Kandang Aktif</td>
<td>Kandang {!kandangData && 'Aktif'}</td>
<td>:</td>
<td>{initialValue?.active_house_count} Kandang</td>
<td>
{!kandangData
? `${initialValue?.active_house_count} Kandang`
: kandangData?.kandang?.name}
</td>
</tr>
<tr>
<td>Status Pembayaran Penjualan</td>
@@ -0,0 +1,37 @@
import Button from '@/components/Button';
import { ClosingGeneralInformation } from '@/types/api/closing';
import { ProjectFlock } from '@/types/api/production/project-flock';
const ClosingKandangList = ({
initialValue,
projectData,
}: {
initialValue?: ClosingGeneralInformation;
projectData?: ProjectFlock;
}) => {
return (
<div className='w-full my-4 @container'>
<div className='flex flex-col @sm:flex-row gap-4'>
<div className='w-full'>
<div className='overflow-x-auto'>
<h1 className='font-bold my-4'>Kandang</h1>
<div className='flex flex-wrap gap-2 mb-4'>
{projectData?.kandangs?.map((kandang) => (
<Button
key={kandang.id}
variant='outline'
href={`/closing/detail/?closingId=${initialValue?.flock_id}&kandangId=${kandang.project_flock_kandang_id}`}
className='min-w-32'
>
{kandang.name}
</Button>
))}
</div>
</div>
</div>
</div>
</div>
);
};
export default ClosingKandangList;