fix(FE): adding skeleton state data on null or unfiltered

This commit is contained in:
randy-ar
2026-01-30 11:02:18 +07:00
parent e980320d00
commit ba1d462a0a
10 changed files with 222 additions and 74 deletions
+12 -2
View File
@@ -42,6 +42,7 @@ interface TableClassNames {
footerRowClassName?: string; footerRowClassName?: string;
footerColumnClassName?: string; footerColumnClassName?: string;
paginationClassName?: string; paginationClassName?: string;
skeletonCellClassName?: string;
} }
export interface TableProps<TData extends object> { export interface TableProps<TData extends object> {
@@ -79,7 +80,9 @@ export interface TableProps<TData extends object> {
getSubRows?: (originalRow: TData, index: number) => TData[] | undefined; getSubRows?: (originalRow: TData, index: number) => TData[] | undefined;
} }
const DUMMY_SKELETON_DATA = [{}, {}, {}, {}, {}]; const DUMMY_SKELETON_DATA = Array.from({ length: 10 }, (_, index) => ({
id: index,
}));
const emptyContentDefaultValue = ( const emptyContentDefaultValue = (
<div className='w-full p-5 text-center'> <div className='w-full p-5 text-center'>
@@ -414,7 +417,14 @@ const Table = <TData extends object>({
cell.getContext() cell.getContext()
)} )}
{isLoading && <div className='skeleton w-full h-4' />} {isLoading && (
<div
className={cn(
'skeleton w-full h-4',
tableClassNames.skeletonCellClassName
)}
/>
)}
</td> </td>
))} ))}
</tr> </tr>
@@ -0,0 +1,26 @@
import IconSkeleton from '@/components/helper/skeleton/IconSkeleton';
import { Icon } from '@iconify/react';
const DataStateSkeleton = ({
icon,
title,
description,
}: {
icon: React.ReactNode;
title: string;
description: string;
}) => {
return (
<div className='flex flex-col items-center justify-center'>
<IconSkeleton>{icon}</IconSkeleton>
<h3 className='text-base-content/50 font-semibold text-sm mb-1'>
{title}
</h3>
<p className='text-base-content/50 text-xs text-center max-w-xs'>
{description}
</p>
</div>
);
};
export default DataStateSkeleton;
@@ -0,0 +1,13 @@
import { ReactNode } from 'react';
const IconSkeleton = ({ children }: { children: ReactNode }) => {
return (
<div className='w-12.5 h-12.5 bg-[var(--main-color-base-100,#FFFFFF)] border border-base-content/10 rounded-[0.875rem] border border-base-content shadow-[0px_25px_50px_-12px_#00000040] flex items-center justify-center'>
<div className='w-9.5 h-9.5 bg-primary rounded-lg border border-primary flex items-center justify-center shadow-[inset_0px_4px_4px_0px_#FFFFFF80,inset_0px_2px_0px_0px_#FFFFFF80]'>
{children}
</div>
</div>
);
};
export default IconSkeleton;
@@ -463,7 +463,6 @@ const DashboardProduction = () => {
Boolean(formik.errors.endDate) && Boolean(formik.errors.endDate) &&
Boolean(formik.touched.endDate) Boolean(formik.touched.endDate)
} }
isRange
/> />
</div> </div>
</div> </div>
@@ -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 Dropdown from '@/components/Dropdown'; import Dropdown from '@/components/Dropdown';
import DataStateSkeleton from '@/components/helper/skeleton/DataStateSkeleton';
import { OptionType } from '@/components/input/SelectInput'; import { OptionType } from '@/components/input/SelectInput';
import Menu from '@/components/menu/Menu'; import Menu from '@/components/menu/Menu';
import MenuItem from '@/components/menu/MenuItem'; import MenuItem from '@/components/menu/MenuItem';
@@ -721,24 +722,18 @@ const DashboardLineChart = ({
return ( return (
<div className='absolute inset-x-0 inset-y-15 z-10 flex flex-col items-center justify-center rounded-lg'> <div className='absolute inset-x-0 inset-y-15 z-10 flex flex-col items-center justify-center rounded-lg'>
{/* Chart icon */} {/* Chart icon */}
<div className='w-12.5 h-12.5 bg-[var(--main-color-base-100,#FFFFFF)] border border-base-content/10 rounded-[0.875rem] border border-base-content shadow-[0px_25px_50px_-12px_#00000040] flex items-center justify-center mb-2'> <DataStateSkeleton
<div className='w-9.5 h-9.5 bg-primary rounded-lg border border-primary flex items-center justify-center shadow-[inset_0px_4px_4px_0px_#FFFFFF80,inset_0px_2px_0px_0px_#FFFFFF80]'> icon={
<Icon <Icon
icon='heroicons:chart-bar' icon='heroicons:chart-bar'
className='text-white' className='text-white'
width={20} width={20}
height={20} height={20}
/> />
</div> }
</div> title='Data Not Yet Available'
description='Please change your filters to get the data.'
{/* Empty state text */} />
<h3 className='text-base-content/50 font-semibold text-sm mb-1'>
Data Not Yet Available
</h3>
<p className='text-base-content/50 text-xs text-center max-w-xs'>
Please change your filters to get the data.
</p>
</div> </div>
); );
} }
@@ -1,5 +1,6 @@
import { Icon } from '@iconify/react'; import { Icon } from '@iconify/react';
import { DashboardMeta } from '@/types/api/dashboard/dashboard'; import { DashboardMeta } from '@/types/api/dashboard/dashboard';
import DataStateSkeleton from '@/components/helper/skeleton/DataStateSkeleton';
const DashboardLineChartSkeleton = ({ meta }: { meta?: DashboardMeta }) => { const DashboardLineChartSkeleton = ({ meta }: { meta?: DashboardMeta }) => {
return ( return (
@@ -24,50 +25,35 @@ const DashboardLineChartSkeleton = ({ meta }: { meta?: DashboardMeta }) => {
{!meta?.filters && ( {!meta?.filters && (
<> <>
{/* Filter icon */} {/* Filter icon */}
<div className='mb-2'> <DataStateSkeleton
<div className='w-12.5 h-12.5 bg-[var(--main-color-base-100,#FFFFFF)] border border-base-content/10 rounded-[0.875rem] border border-base-content shadow-[0px_25px_50px_-12px_#00000040] flex items-center justify-center'> icon={
<div className='w-9.5 h-9.5 bg-primary rounded-lg border border-primary flex items-center justify-center shadow-[inset_0px_4px_4px_0px_#FFFFFF80,inset_0px_2px_0px_0px_#FFFFFF80]'>
<Icon <Icon
icon='heroicons:funnel' icon='heroicons:funnel'
className='text-white' className='text-white'
width={20} width={20}
height={20} height={20}
/> />
</div> }
</div> title='No Filters Selected'
</div> description='Please choose filters to narrow down your results and make your search easier.'
/>
{/* Empty state text */}
<h3 className='text-base-content/50 font-semibold text-sm mb-1'>
No Filters Selected
</h3>
<p className='text-base-content/50 text-xs text-center max-w-xs'>
Please choose filters to narrow down your results and make
your search easier.
</p>
</> </>
)} )}
{meta?.filters && ( {meta?.filters && (
<> <>
{/* Filter icon */} {/* Filter icon */}
<div className='w-12.5 h-12.5 bg-[var(--main-color-base-100,#FFFFFF)] border border-base-content/10 rounded-[0.875rem] border border-base-content shadow-[0px_25px_50px_-12px_#00000040] flex items-center justify-center mb-2'> <DataStateSkeleton
<div className='w-9.5 h-9.5 bg-primary rounded-lg border border-primary flex items-center justify-center shadow-[inset_0px_4px_4px_0px_#FFFFFF80,inset_0px_2px_0px_0px_#FFFFFF80]'> icon={
<Icon <Icon
icon='heroicons:chart-bar' icon='heroicons:chart-bar'
className='text-white' className='text-white'
width={20} width={20}
height={20} height={20}
/> />
</div> }
</div> title='Data Not Yet Available'
description='Please change your filters to get the data.'
{/* Empty state text */} />
<h3 className='text-base-content/50 font-semibold text-sm mb-1'>
Data Not Yet Available
</h3>
<p className='text-base-content/50 text-xs text-center max-w-xs'>
Please change your filters to get the data.
</p>
</> </>
)} )}
</div> </div>
@@ -0,0 +1,37 @@
import DataStateSkeleton from '@/components/helper/skeleton/DataStateSkeleton';
import Table from '@/components/Table';
import { CustomerPaymentRow } from '@/types/api/report/customer-payment';
import { ColumnDef } from '@tanstack/react-table';
const CustomerSupplierSkeleton = ({
columns,
icon,
title,
subtitle,
}: {
columns: ColumnDef<CustomerPaymentRow>[];
icon: React.ReactNode;
title: string;
subtitle: string;
}) => {
return (
<div className='relative size-full'>
<Table
data={[]}
columns={columns}
isLoading={true}
className={{
skeletonCellClassName: 'animate-none w-full h-5 bg-base-content/4',
headerColumnClassName: 'whitespace-nowrap',
containerClassName: 'mb-0 overflow-hidden',
tableWrapperClassName: 'overflow-hidden',
}}
/>
<div className='absolute inset-0 flex items-center justify-center'>
<DataStateSkeleton icon={icon} title={title} description={subtitle} />
</div>
</div>
);
};
export default CustomerSupplierSkeleton;
@@ -0,0 +1,38 @@
import DataStateSkeleton from '@/components/helper/skeleton/DataStateSkeleton';
import Table from '@/components/Table';
import { DebtRow } from '@/types/api/report/debt-supplier';
import { Icon } from '@iconify/react';
import { ColumnDef } from '@tanstack/react-table';
const DebtSupplierSkeleton = ({
columns,
icon,
title,
subtitle,
}: {
columns: ColumnDef<DebtRow>[];
icon: React.ReactNode;
title: string;
subtitle: string;
}) => {
return (
<div className='relative size-full'>
<Table
data={[]}
columns={columns}
isLoading={true}
className={{
skeletonCellClassName: 'animate-none w-full h-5 bg-base-content/4',
headerColumnClassName: 'whitespace-nowrap',
containerClassName: 'mb-0 overflow-hidden',
tableWrapperClassName: 'overflow-hidden',
}}
/>
<div className='absolute inset-0 flex items-center justify-center'>
<DataStateSkeleton icon={icon} title={title} description={subtitle} />
</div>
</div>
);
};
export default DebtSupplierSkeleton;
@@ -14,6 +14,7 @@ import { ColumnDef } from '@tanstack/react-table';
import { formatCurrency, formatDate, formatNumber, cn } from '@/lib/helper'; import { formatCurrency, formatDate, formatNumber, cn } from '@/lib/helper';
import { import {
CustomerPaymentReport, CustomerPaymentReport,
CustomerPaymentRow,
CustomerPaymentSummary, CustomerPaymentSummary,
} from '@/types/api/report/customer-payment'; } from '@/types/api/report/customer-payment';
import { isResponseSuccess } from '@/lib/api-helper'; import { isResponseSuccess } from '@/lib/api-helper';
@@ -27,6 +28,7 @@ import toast from 'react-hot-toast';
import { generateCustomerPaymentExcel } from '@/components/pages/report/finance/export/CustomerPaymentExportXLSX'; import { generateCustomerPaymentExcel } from '@/components/pages/report/finance/export/CustomerPaymentExportXLSX';
import { generateCustomerPaymentPDF } from '@/components/pages/report/finance/export/CustomerPaymentExportPDF'; import { generateCustomerPaymentPDF } from '@/components/pages/report/finance/export/CustomerPaymentExportPDF';
import { useFinanceTabStore } from '@/stores/finance-tab/finance-tab.store'; import { useFinanceTabStore } from '@/stores/finance-tab/finance-tab.store';
import CustomerSupplierSkeleton from '@/components/pages/report/finance/skeleton/CustomerSupplierSkeleton';
interface CustomerPaymentTabProps { interface CustomerPaymentTabProps {
tabId: string; tabId: string;
@@ -650,18 +652,37 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
<> <>
<div className='w-full p-0 sm:p-3 flex flex-col gap-3'> <div className='w-full p-0 sm:p-3 flex flex-col gap-3'>
{!isSubmitted ? ( {!isSubmitted ? (
<div className='mt-6 text-center text-base-content/50'> <CustomerSupplierSkeleton
Silakan klik tombol Filter untuk mengatur filter dan menampilkan columns={getTableColumns({} as CustomerPaymentSummary)}
data. icon={
</div> <Icon
icon='heroicons:funnel'
className='text-white'
width={20}
height={20}
/>
}
title='No Filters Selected'
subtitle='Please choose filters to narrow down your results and make your search easier.'
/>
) : isLoading ? ( ) : isLoading ? (
<div className='w-full flex flex-row justify-center items-center p-4'> <div className='w-full flex flex-row justify-center items-center p-4'>
<span className='loading loading-spinner loading-xl' /> <span className='loading loading-spinner loading-xl' />
</div> </div>
) : data.length === 0 ? ( ) : data.length === 0 ? (
<div className='mt-6 text-center text-base-content/50'> <CustomerSupplierSkeleton
Tidak ada data yang dapat ditampilkan... columns={getTableColumns({} as CustomerPaymentSummary)}
</div> icon={
<Icon
icon='heroicons:chart-bar'
className='text-white'
width={20}
height={20}
/>
}
title='Data Not Yet Available'
subtitle='Please change your filters to get the data.'
/>
) : ( ) : (
data.map((customerReport) => { data.map((customerReport) => {
const summary = customerReport.summary || { const summary = customerReport.summary || {
@@ -35,6 +35,8 @@ import SelectInputCheckbox from '@/components/input/SelectInputCheckbox';
import SelectInputRadio from '@/components/input/SelectInputRadio'; import SelectInputRadio from '@/components/input/SelectInputRadio';
import { useFinanceTabStore } from '@/stores/finance-tab/finance-tab.store'; import { useFinanceTabStore } from '@/stores/finance-tab/finance-tab.store';
import StatusBadge from '@/components/helper/StatusBadge'; import StatusBadge from '@/components/helper/StatusBadge';
import DebtSupplierSkeleton from '@/components/pages/report/finance/skeleton/DebtSupplierSkeleton';
import DataStateSkeleton from '@/components/helper/skeleton/DataStateSkeleton';
const dueStatus: Record<string, Color> = { const dueStatus: Record<string, Color> = {
'Sudah Jatuh Tempo': 'error', 'Sudah Jatuh Tempo': 'error',
@@ -332,7 +334,7 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => {
}; };
}, [tabId, clearTabActions]); }, [tabId, clearTabActions]);
const getTableColumns = (supplier: DebtSupplier): ColumnDef<DebtRow>[] => [ const getTableColumns = (supplier?: DebtSupplier): ColumnDef<DebtRow>[] => [
{ {
id: 'no', id: 'no',
header: 'No', header: 'No',
@@ -398,8 +400,10 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => {
return <div className='text-center'>{formatNumber(value)} Hari</div>; return <div className='text-center'>{formatNumber(value)} Hari</div>;
}, },
footer: () => { footer: () => {
const value = supplier.total.aging; const value = supplier?.total.aging;
return <div className='text-center'>{formatNumber(value)} Hari</div>; return (
<div className='text-center'>{formatNumber(value || 0)} Hari</div>
);
}, },
}, },
{ {
@@ -460,10 +464,10 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => {
); );
}, },
footer: () => { footer: () => {
const value = supplier.total.total_price; const value = supplier?.total.total_price;
return ( return (
<div className={`text-right ${value < 0 ? 'text-red-500' : ''}`}> <div className={`text-right ${value || 0 < 0 ? 'text-red-500' : ''}`}>
{formatCurrency(value)} {formatCurrency(value || 0)}
</div> </div>
); );
}, },
@@ -482,10 +486,10 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => {
); );
}, },
footer: () => { footer: () => {
const value = supplier.total.payment_price; const value = supplier?.total.payment_price;
return ( return (
<div className={`text-right ${value < 0 ? 'text-red-500' : ''}`}> <div className={`text-right ${value || 0 < 0 ? 'text-red-500' : ''}`}>
{formatCurrency(value)} {formatCurrency(value || 0)}
</div> </div>
); );
}, },
@@ -504,10 +508,10 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => {
); );
}, },
footer: () => { footer: () => {
const value = supplier.total.debt_price; const value = supplier?.total.debt_price;
return ( return (
<div className={`text-right ${value < 0 ? 'text-red-500' : ''}`}> <div className={`text-right ${value || 0 < 0 ? 'text-red-500' : ''}`}>
{formatCurrency(value)} {formatCurrency(value || 0)}
</div> </div>
); );
}, },
@@ -541,18 +545,37 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => {
<> <>
<div className='w-full p-0 sm:p-3 flex flex-col gap-3'> <div className='w-full p-0 sm:p-3 flex flex-col gap-3'>
{!isSubmitted ? ( {!isSubmitted ? (
<div className='mt-6 text-center text-base-content/50'> <DebtSupplierSkeleton
Silakan klik tombol Filter untuk mengatur filter dan menampilkan columns={getTableColumns()}
data. icon={
</div> <Icon
icon='heroicons:funnel'
className='text-white'
width={20}
height={20}
/>
}
title='No Filters Selected'
subtitle='Please choose filters to narrow down your results and make your search easier.'
/>
) : isLoading ? ( ) : isLoading ? (
<div className='w-full flex flex-row justify-center items-center p-4'> <div className='w-full flex flex-row justify-center items-center p-4'>
<span className='loading loading-spinner loading-xl' /> <span className='loading loading-spinner loading-xl' />
</div> </div>
) : data.length === 0 ? ( ) : data.length === 0 ? (
<div className='mt-6 text-center text-base-content/50'> <DebtSupplierSkeleton
Tidak ada data yang dapat ditampilkan... columns={getTableColumns()}
</div> icon={
<Icon
icon='heroicons:chart-bar'
className='text-white'
width={20}
height={20}
/>
}
title='Data Not Yet Available'
subtitle='Please change your filters to get the data.'
/>
) : ( ) : (
data.map((supplierReport) => { data.map((supplierReport) => {
return ( return (