feat(FE-137): add product flag badges to RecordingForm for enhanced visibility

This commit is contained in:
rstubryan
2025-10-27 13:03:37 +07:00
parent 6dd3593f70
commit 15e6372c30
@@ -148,14 +148,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
if (hasPakanFlag) {
options.push({
value: product.id,
label: `[PAKAN] ${product.product.name} - ${warehouse?.name || ''}`
label: `${product.product.name} - ${warehouse?.name || ''}`
});
}
if (hasOvkFlag) {
options.push({
value: product.id,
label: `[OVK] ${product.product.name} - ${warehouse?.name || ''}`
label: `${product.product.name} - ${warehouse?.name || ''}`
});
}
});
@@ -354,6 +354,47 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
[projectFlocks, recordedProjectFlockIds]
);
const getProductFlagBadgeAdornment = useCallback(
(productWarehouseId: number) => {
if (!isResponseSuccess(stockProducts)) return null;
const productWarehouse = stockProducts.data.find(pw => pw.id === productWarehouseId);
if (!productWarehouse) return null;
const hasPakanFlag = productWarehouse.product.flags?.includes('PAKAN');
const hasOvkFlag = productWarehouse.product.flags?.includes('OVK');
if (hasPakanFlag) {
return (
<Badge
variant="soft"
color="info"
size="sm"
className={{ badge: 'whitespace-nowrap font-semibold text-xs px-2 py-0.5' }}
>
PAKAN
</Badge>
);
}
if (hasOvkFlag) {
return (
<Badge
variant="soft"
color="secondary"
size="sm"
className={{ badge: 'whitespace-nowrap font-semibold text-xs px-2 py-0.5' }}
>
OVK
</Badge>
);
}
return null;
},
[stockProducts]
);
const hasExceededStock = useMemo(() => {
if (type === 'detail') return false;
return (
@@ -1105,6 +1146,11 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
}}
isSearchable
isDisabled={type === 'detail'}
startAdornment={
stock.product_warehouse_id
? getProductFlagBadgeAdornment(stock.product_warehouse_id)
: undefined
}
/>
</td>
<td>