mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +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 status = approval.action;
|
||||||
const statusColor = getStatusBadgeColor(status);
|
const statusColor = getStatusBadgeColor(status);
|
||||||
|
|
||||||
const statusText =
|
const statusText = approval.step_name || getStatusText(status);
|
||||||
status === 'REJECTED'
|
|
||||||
? 'Ditolak'
|
|
||||||
: approval.step_name || getStatusText(status);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StatusBadge
|
<StatusBadge
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
|||||||
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||||
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
||||||
import RequirePermission from '@/components/helper/RequirePermission';
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
import Badge from '@/components/Badge';
|
import StatusBadge from '@/components/helper/StatusBadge';
|
||||||
|
|
||||||
import { cn, formatDate } from '@/lib/helper';
|
import { cn, formatDate } from '@/lib/helper';
|
||||||
import { isResponseSuccess } from '@/lib/api-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 { Purchase } from '@/types/api/purchase/purchase';
|
||||||
import { PurchaseApi } from '@/services/api/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 =====
|
// ===== INTERFACES =====
|
||||||
interface RowOptionsMenuProps {
|
interface RowOptionsMenuProps {
|
||||||
type: 'dropdown' | 'collapse';
|
type: 'dropdown' | 'collapse';
|
||||||
@@ -160,16 +202,19 @@ const PurchaseTable = () => {
|
|||||||
const approval = props.row.original.latest_approval;
|
const approval = props.row.original.latest_approval;
|
||||||
if (!approval) return '-';
|
if (!approval) return '-';
|
||||||
|
|
||||||
const isRejected = approval.action === 'REJECTED';
|
const status = approval.action;
|
||||||
|
|
||||||
let statusColor:
|
let statusColor:
|
||||||
| 'warning'
|
| 'warning'
|
||||||
| 'success'
|
| 'success'
|
||||||
| 'neutral'
|
| 'neutral'
|
||||||
| 'error'
|
| 'error'
|
||||||
| 'primary'
|
| 'info'
|
||||||
| 'info' = 'neutral';
|
| 'primary' = 'neutral';
|
||||||
|
|
||||||
|
if (status === 'REJECTED') {
|
||||||
|
statusColor = getStatusBadgeColor(status);
|
||||||
|
} else {
|
||||||
switch (approval.step_number) {
|
switch (approval.step_number) {
|
||||||
case 1:
|
case 1:
|
||||||
statusColor = 'neutral';
|
statusColor = 'neutral';
|
||||||
@@ -187,21 +232,18 @@ const PurchaseTable = () => {
|
|||||||
statusColor = 'success';
|
statusColor = 'success';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRejected) {
|
|
||||||
statusColor = 'error';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const statusText = approval.step_name || getStatusText(status);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Badge
|
<StatusBadge
|
||||||
variant='soft'
|
|
||||||
color={statusColor}
|
color={statusColor}
|
||||||
|
text={statusText}
|
||||||
className={{
|
className={{
|
||||||
badge: 'whitespace-nowrap',
|
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?`}
|
text={`Apakah anda yakin ingin menghapus data permintaan pembelian ini?`}
|
||||||
secondaryButton={{
|
secondaryButton={{
|
||||||
text: 'Tidak',
|
text: 'Tidak',
|
||||||
|
onClick: () => deleteModal.closeModal(),
|
||||||
}}
|
}}
|
||||||
primaryButton={{
|
primaryButton={{
|
||||||
text: 'Ya',
|
text: 'Ya',
|
||||||
|
|||||||
Reference in New Issue
Block a user