mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
refactor(FE): Refactor HPP Expedition handling in ClosingDetailPage
This commit is contained in:
@@ -5,27 +5,49 @@ import { ColumnDef } from '@tanstack/react-table';
|
||||
import Table from '@/components/Table';
|
||||
import Card from '@/components/Card';
|
||||
import { formatCurrency } from '@/lib/helper';
|
||||
import { BaseHppExpedition, BaseExpeditionCost } from '@/types/api/closing';
|
||||
import { isResponseSuccess } from '@/lib/api-helper';
|
||||
import { BaseExpeditionCost } from '@/types/api/closing';
|
||||
import { ClosingApi } from '@/services/api/closing';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import useSWR from 'swr';
|
||||
|
||||
interface HppExpeditionClosingTableProps {
|
||||
type?: 'detail';
|
||||
initialValues?: BaseHppExpedition;
|
||||
projectFlockId: number;
|
||||
}
|
||||
|
||||
const HppExpeditionClosingTable = ({
|
||||
initialValues,
|
||||
projectFlockId,
|
||||
}: HppExpeditionClosingTableProps) => {
|
||||
const searchParams = useSearchParams();
|
||||
const kandangId = searchParams.get('kandangId');
|
||||
|
||||
const { data: hppExpedition, isLoading } = useSWR(
|
||||
kandangId
|
||||
? `/closing/hpp-expedition/${projectFlockId}/${kandangId}`
|
||||
: `/closing/hpp-expedition/${projectFlockId}`,
|
||||
() =>
|
||||
kandangId
|
||||
? ClosingApi.getHppEkspedisiByKandang(projectFlockId, Number(kandangId))
|
||||
: ClosingApi.getHppEkspedisi(projectFlockId)
|
||||
);
|
||||
|
||||
const costOfRevenueExpeditionData: BaseExpeditionCost[] = useMemo(() => {
|
||||
return initialValues?.expedition_costs || [];
|
||||
}, [initialValues]);
|
||||
if (isResponseSuccess(hppExpedition)) {
|
||||
return hppExpedition.data.expedition_costs || [];
|
||||
}
|
||||
return [];
|
||||
}, [hppExpedition]);
|
||||
|
||||
const totals = useMemo(() => {
|
||||
const totalHpp = initialValues?.total_hpp_amount || 0;
|
||||
|
||||
if (isResponseSuccess(hppExpedition)) {
|
||||
return {
|
||||
totalHpp: hppExpedition.data.total_hpp_amount || 0,
|
||||
};
|
||||
}
|
||||
return {
|
||||
totalHpp,
|
||||
totalHpp: 0,
|
||||
};
|
||||
}, [initialValues]);
|
||||
}, [hppExpedition]);
|
||||
|
||||
const costOfRevenueExpeditionColumns: ColumnDef<BaseExpeditionCost>[] =
|
||||
useMemo(
|
||||
@@ -81,6 +103,7 @@ const HppExpeditionClosingTable = ({
|
||||
<Table
|
||||
data={costOfRevenueExpeditionData}
|
||||
columns={costOfRevenueExpeditionColumns}
|
||||
isLoading={isLoading}
|
||||
renderFooter={costOfRevenueExpeditionData.length > 0}
|
||||
className={{
|
||||
tableWrapperClassName: 'overflow-x-auto',
|
||||
|
||||
Reference in New Issue
Block a user