mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE): workaround general information closing kandang
This commit is contained in:
@@ -7,18 +7,33 @@ import ClosingDetail from '@/components/pages/closing/ClosingDetail';
|
|||||||
|
|
||||||
import { ClosingApi } from '@/services/api/closing';
|
import { ClosingApi } from '@/services/api/closing';
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
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 ClosingDetailPage = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
const closingId = searchParams.get('closingId');
|
const closingId = searchParams.get('closingId');
|
||||||
|
const kandangId = searchParams.get('kandangId'); // project flock kandang ID
|
||||||
|
|
||||||
const { data: closing, isLoading: isLoadingClosing } = useSWR(
|
const { data: closing, isLoading: isLoadingClosing } = useSWR(
|
||||||
closingId,
|
closingId,
|
||||||
(id: number) => ClosingApi.getGeneralInfo(id)
|
(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(
|
// const { data: salesData, isLoading: isLoadingSales } = useSWR(
|
||||||
// closingId ? `sales-${closingId}` : null,
|
// closingId ? `sales-${closingId}` : null,
|
||||||
// () => ClosingApi.getPenjualan(Number(closingId))
|
// () => ClosingApi.getPenjualan(Number(closingId))
|
||||||
@@ -44,7 +59,11 @@ const ClosingDetailPage = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isLoading = isLoadingClosing || isLoadingHppEkspedisi;
|
const isLoading =
|
||||||
|
isLoadingClosing ||
|
||||||
|
isLoadingHppEkspedisi ||
|
||||||
|
isLoadingProject ||
|
||||||
|
isLoadingKandang;
|
||||||
// const isLoading = isLoadingClosing || isLoadingSales || isLoadingHppEkspedisi;
|
// const isLoading = isLoadingClosing || isLoadingSales || isLoadingHppEkspedisi;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -61,6 +80,12 @@ const ClosingDetailPage = () => {
|
|||||||
? hppEkspedisiData.data
|
? hppEkspedisiData.data
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
projectData={
|
||||||
|
isResponseSuccess(projectData) ? projectData.data : undefined
|
||||||
|
}
|
||||||
|
kandangData={
|
||||||
|
isResponseSuccess(kandangData) ? kandangData.data : undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -19,12 +19,17 @@ import ClosingOverheadTabContent from '@/components/pages/closing/ClosingOverhea
|
|||||||
import ClosingFinanceTabContent from '@/components/pages/closing/ClosingFinanceTabContent';
|
import ClosingFinanceTabContent from '@/components/pages/closing/ClosingFinanceTabContent';
|
||||||
import SalesReportTable from '@/components/pages/closing/sale/SalesReportTable';
|
import SalesReportTable from '@/components/pages/closing/sale/SalesReportTable';
|
||||||
import HppExpeditionReportTable from './hpp-ekspedisi/HppExpeditionReportTable';
|
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 {
|
interface ClosingDetailProps {
|
||||||
id: number;
|
id: number;
|
||||||
initialValue?: ClosingGeneralInformation;
|
initialValue?: ClosingGeneralInformation;
|
||||||
salesData?: BaseClosingSales;
|
salesData?: BaseClosingSales;
|
||||||
hppExpeditionData?: ClosingHppExpedition;
|
hppExpeditionData?: ClosingHppExpedition;
|
||||||
|
projectData?: ProjectFlock;
|
||||||
|
kandangData?: ProjectFlockKandang;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
||||||
@@ -32,6 +37,8 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
|||||||
initialValue,
|
initialValue,
|
||||||
salesData,
|
salesData,
|
||||||
hppExpeditionData,
|
hppExpeditionData,
|
||||||
|
projectData,
|
||||||
|
kandangData,
|
||||||
}) => {
|
}) => {
|
||||||
const [activeTab, setActiveTab] = useState<string>('sapronak');
|
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>
|
<h1 className='text-2xl font-bold text-center'>Detail Closing</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<ClosingGeneralInformationTable initialValue={initialValue} />
|
<ClosingGeneralInformationTable
|
||||||
|
initialValue={initialValue}
|
||||||
|
projectData={projectData}
|
||||||
|
kandangData={kandangData}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!kandangData && (
|
||||||
|
<ClosingKandangList
|
||||||
|
initialValue={initialValue}
|
||||||
|
projectData={projectData}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<Tabs
|
<Tabs
|
||||||
activeTabId={activeTab}
|
activeTabId={activeTab}
|
||||||
|
|||||||
@@ -1,12 +1,29 @@
|
|||||||
import { ClosingGeneralInformation } from '@/types/api/closing';
|
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 {
|
interface ClosingGeneralInformationProps {
|
||||||
initialValue?: ClosingGeneralInformation;
|
initialValue?: ClosingGeneralInformation;
|
||||||
|
projectData?: ProjectFlock;
|
||||||
|
kandangData?: ProjectFlockKandang;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClosingGeneralInformationTable = ({
|
const ClosingGeneralInformationTable = ({
|
||||||
initialValue,
|
initialValue,
|
||||||
|
projectData,
|
||||||
|
kandangData,
|
||||||
}: ClosingGeneralInformationProps) => {
|
}: ClosingGeneralInformationProps) => {
|
||||||
|
const chickinPopulation = useMemo(() => {
|
||||||
|
if (kandangData) {
|
||||||
|
return kandangData?.chickins?.reduce(
|
||||||
|
(acc, chickin) => acc + chickin.usage_qty,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}, [kandangData]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-full my-4 @container'>
|
<div className='w-full my-4 @container'>
|
||||||
<div className='flex flex-col @sm:flex-row gap-4'>
|
<div className='flex flex-col @sm:flex-row gap-4'>
|
||||||
@@ -17,7 +34,9 @@ const ClosingGeneralInformationTable = ({
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Lokasi</td>
|
<td>Lokasi</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>{initialValue?.location_name}</td>
|
<td>
|
||||||
|
{initialValue?.location_name ?? projectData?.location?.name}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Periode</td>
|
<td>Periode</td>
|
||||||
@@ -27,12 +46,20 @@ const ClosingGeneralInformationTable = ({
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Project Flock</td>
|
<td>Project Flock</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>{initialValue?.project_flock?.name}</td>
|
<td>
|
||||||
|
{initialValue?.project_flock?.name ??
|
||||||
|
projectData?.flock_name}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Populasi</td>
|
<td>Populasi</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>{initialValue?.population} Ekor</td>
|
<td>
|
||||||
|
{!kandangData
|
||||||
|
? (initialValue?.population ?? 0)
|
||||||
|
: (chickinPopulation ?? 0)}{' '}
|
||||||
|
Ekor
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Jenis Project</td>
|
<td>Jenis Project</td>
|
||||||
@@ -40,9 +67,13 @@ const ClosingGeneralInformationTable = ({
|
|||||||
<td>{initialValue?.project_type}</td>
|
<td>{initialValue?.project_type}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr className='table-row @sm:hidden'>
|
<tr className='table-row @sm:hidden'>
|
||||||
<td>Kandang Aktif</td>
|
<td>Kandang {!kandangData && 'Aktif'}</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>{initialValue?.active_house_count} Kandang</td>
|
<td>
|
||||||
|
{!kandangData
|
||||||
|
? `${initialValue?.active_house_count} Kandang`
|
||||||
|
: kandangData?.kandang?.name}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr className='table-row @sm:hidden'>
|
<tr className='table-row @sm:hidden'>
|
||||||
<td>Status Pembayaran Penjualan</td>
|
<td>Status Pembayaran Penjualan</td>
|
||||||
@@ -69,9 +100,13 @@ const ClosingGeneralInformationTable = ({
|
|||||||
<table className='table table-zebra table-sm'>
|
<table className='table table-zebra table-sm'>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Kandang Aktif</td>
|
<td>Kandang {!kandangData && 'Aktif'}</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>{initialValue?.active_house_count} Kandang</td>
|
<td>
|
||||||
|
{!kandangData
|
||||||
|
? `${initialValue?.active_house_count} Kandang`
|
||||||
|
: kandangData?.kandang?.name}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Status Pembayaran Penjualan</td>
|
<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;
|
||||||
Reference in New Issue
Block a user