mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Unify status badge logic and use StatusBadge
This commit is contained in:
@@ -858,10 +858,7 @@ const RecordingTable = () => {
|
||||
const status = approval.action;
|
||||
const statusColor = getStatusBadgeColor(status);
|
||||
|
||||
const statusText =
|
||||
status === 'REJECTED'
|
||||
? 'Ditolak'
|
||||
: approval.step_name || getStatusText(status);
|
||||
const statusText = approval.step_name || getStatusText(status);
|
||||
|
||||
return (
|
||||
<StatusBadge
|
||||
|
||||
@@ -16,7 +16,7 @@ import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
||||
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
||||
import RequirePermission from '@/components/helper/RequirePermission';
|
||||
import Badge from '@/components/Badge';
|
||||
import StatusBadge from '@/components/helper/StatusBadge';
|
||||
|
||||
import { cn, formatDate } from '@/lib/helper';
|
||||
import { isResponseSuccess } from '@/lib/api-helper';
|
||||
@@ -26,6 +26,48 @@ import { ROWS_OPTIONS } from '@/config/constant';
|
||||
import { Purchase } from '@/types/api/purchase/purchase';
|
||||
import { PurchaseApi } from '@/services/api/purchase';
|
||||
|
||||
// ===== STATUS BADGE UTILITIES =====
|
||||
const statusTextMap: Record<string, string> = {
|
||||
APPROVED: 'Disetujui',
|
||||
Disetujui: 'Disetujui',
|
||||
REJECTED: 'Ditolak',
|
||||
Ditolak: 'Ditolak',
|
||||
CREATED: 'Dibuat',
|
||||
UPDATED: 'Diperbarui',
|
||||
};
|
||||
|
||||
const getStatusText = (status: string): string => {
|
||||
return statusTextMap[status] || status;
|
||||
};
|
||||
|
||||
const statusBadgeColorMap: Record<
|
||||
string,
|
||||
'success' | 'error' | 'neutral' | 'info' | 'warning' | 'primary'
|
||||
> = {
|
||||
APPROVED: 'success',
|
||||
Disetujui: 'success',
|
||||
approved: 'success',
|
||||
disetujui: 'success',
|
||||
REJECTED: 'error',
|
||||
Ditolak: 'error',
|
||||
rejected: 'error',
|
||||
ditolak: 'error',
|
||||
CREATED: 'neutral',
|
||||
Dibuat: 'neutral',
|
||||
created: 'neutral',
|
||||
dibuat: 'neutral',
|
||||
UPDATED: 'warning',
|
||||
Diperbarui: 'warning',
|
||||
updated: 'warning',
|
||||
diperbarui: 'warning',
|
||||
};
|
||||
|
||||
const getStatusBadgeColor = (
|
||||
status: string
|
||||
): 'success' | 'error' | 'neutral' | 'info' | 'warning' | 'primary' => {
|
||||
return statusBadgeColorMap[status] || 'neutral';
|
||||
};
|
||||
|
||||
// ===== INTERFACES =====
|
||||
interface RowOptionsMenuProps {
|
||||
type: 'dropdown' | 'collapse';
|
||||
@@ -160,48 +202,48 @@ const PurchaseTable = () => {
|
||||
const approval = props.row.original.latest_approval;
|
||||
if (!approval) return '-';
|
||||
|
||||
const isRejected = approval.action === 'REJECTED';
|
||||
const status = approval.action;
|
||||
|
||||
let statusColor:
|
||||
| 'warning'
|
||||
| 'success'
|
||||
| 'neutral'
|
||||
| 'error'
|
||||
| 'primary'
|
||||
| 'info' = 'neutral';
|
||||
| 'info'
|
||||
| 'primary' = 'neutral';
|
||||
|
||||
switch (approval.step_number) {
|
||||
case 1:
|
||||
statusColor = 'neutral';
|
||||
break;
|
||||
case 2:
|
||||
statusColor = 'primary';
|
||||
break;
|
||||
case 3:
|
||||
statusColor = 'info';
|
||||
break;
|
||||
case 4:
|
||||
statusColor = 'warning';
|
||||
break;
|
||||
case 5:
|
||||
statusColor = 'success';
|
||||
break;
|
||||
if (status === 'REJECTED') {
|
||||
statusColor = getStatusBadgeColor(status);
|
||||
} else {
|
||||
switch (approval.step_number) {
|
||||
case 1:
|
||||
statusColor = 'neutral';
|
||||
break;
|
||||
case 2:
|
||||
statusColor = 'primary';
|
||||
break;
|
||||
case 3:
|
||||
statusColor = 'info';
|
||||
break;
|
||||
case 4:
|
||||
statusColor = 'warning';
|
||||
break;
|
||||
case 5:
|
||||
statusColor = 'success';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isRejected) {
|
||||
statusColor = 'error';
|
||||
}
|
||||
const statusText = approval.step_name || getStatusText(status);
|
||||
|
||||
return (
|
||||
<Badge
|
||||
variant='soft'
|
||||
<StatusBadge
|
||||
color={statusColor}
|
||||
text={statusText}
|
||||
className={{
|
||||
badge: 'whitespace-nowrap',
|
||||
}}
|
||||
>
|
||||
{isRejected ? 'Ditolak' : approval.step_name}
|
||||
</Badge>
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -369,6 +411,7 @@ const PurchaseTable = () => {
|
||||
text={`Apakah anda yakin ingin menghapus data permintaan pembelian ini?`}
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
onClick: () => deleteModal.closeModal(),
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
|
||||
Reference in New Issue
Block a user