refactor(FE): Render payment notes as Badge and highlight balance

This commit is contained in:
rstubryan
2026-01-13 15:20:27 +07:00
parent 92bfef850a
commit 60eaec261d
@@ -2,6 +2,7 @@ import { useState, useMemo, useCallback } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import { Icon } from '@iconify/react'; import { Icon } from '@iconify/react';
import Card from '@/components/Card'; import Card from '@/components/Card';
import Badge from '@/components/Badge';
import SelectInput, { import SelectInput, {
useSelect, useSelect,
OptionType, OptionType,
@@ -67,6 +68,38 @@ const CustomerPaymentTab = () => {
[] []
); );
const getPaymentStatusColor = (notes: string) => {
const normalizedValue = notes.toLowerCase();
if (normalizedValue === 'lunas') {
return 'bg-info/10 text-info border-info';
}
if (normalizedValue.includes('belum')) {
return 'bg-warning/10 text-warning border-warning';
}
return 'bg-gray-100 text-gray-600 border-gray-300';
};
const getPaymentStatusIndicatorColor = (notes: string) => {
const normalizedValue = notes.toLowerCase();
if (normalizedValue === 'lunas') {
return 'bg-info';
}
if (normalizedValue.includes('belum')) {
return 'bg-warning';
}
return 'bg-gray-400';
};
const getPaymentStatusText = (notes: string) => {
return notes;
};
// ===== FILTER HANDLERS ===== // ===== FILTER HANDLERS =====
const handleResetFilters = useCallback(() => { const handleResetFilters = useCallback(() => {
setIsSubmitted(false); setIsSubmitted(false);
@@ -435,7 +468,9 @@ const CustomerPaymentTab = () => {
accessorKey: 'accounts_receivable', accessorKey: 'accounts_receivable',
cell: (props) => { cell: (props) => {
const value = props.row.original.accounts_receivable; const value = props.row.original.accounts_receivable;
return <div className='text-right'>{formatCurrency(value)}</div>; return (
<div className='text-right text-error'>{formatCurrency(value)}</div>
);
}, },
footer: () => ( footer: () => (
<div className='text-right font-semibold text-gray-900'> <div className='text-right font-semibold text-gray-900'>
@@ -449,7 +484,23 @@ const CustomerPaymentTab = () => {
accessorKey: 'notes', accessorKey: 'notes',
cell: (props) => { cell: (props) => {
const value = props.row.original.notes; const value = props.row.original.notes;
return value || '-';
if (!value) {
return '-';
}
return (
<Badge
statusIndicator={true}
variant='soft'
className={{
badge: `rounded-xl justify-start border border-gray-200 ${getPaymentStatusColor(value)}`,
status: getPaymentStatusIndicatorColor(value),
}}
>
{getPaymentStatusText(value)}
</Badge>
);
}, },
}, },
{ {
@@ -647,14 +698,13 @@ const CustomerPaymentTab = () => {
total_accounts_receivable: 0, total_accounts_receivable: 0,
}; };
const totalAccountsReceivable = summary.total_accounts_receivable;
const tableColumns = getTableColumns(summary); const tableColumns = getTableColumns(summary);
return ( return (
<Card <Card
key={customerReport.customer.id} key={customerReport.customer.id}
title={customerReport.customer.name} title={customerReport.customer.name}
subtitle={`${customerReport.customer.address || ''}\nSaldo Piutang: ${formatCurrency(totalAccountsReceivable)}`} subtitle={`${customerReport.customer.address || ''}`}
className={{ wrapper: 'w-full' }} className={{ wrapper: 'w-full' }}
variant='bordered' variant='bordered'
collapsible={true} collapsible={true}