fix: mismatch dto marketings

This commit is contained in:
Adnan Zahir
2026-04-22 11:41:09 +07:00
parent 2afcc5d1c9
commit b7f886b51e
2 changed files with 23 additions and 9 deletions
@@ -190,12 +190,19 @@ const DeliveryOrderProductForm = ({
const deliveryOrder = useMemo(() => { const deliveryOrder = useMemo(() => {
if (!hasDeliveryOrder || !deliveryOrders) return null; if (!hasDeliveryOrder || !deliveryOrders) return null;
const marketingProductId =
initialValues?.marketing_product_id ?? initialValues?.id;
for (const doItem of deliveryOrders) { for (const doItem of deliveryOrders) {
const found = doItem.deliveries.find( const found =
(d) => doItem.deliveries.find(
d.product_warehouse.id === (d) => d.marketing_product_id === marketingProductId
initialValues?.marketing_product?.product_warehouse_id ) ??
); doItem.deliveries.find(
(d) =>
d.product_warehouse.id ===
initialValues?.marketing_product?.product_warehouse_id
);
if (found) { if (found) {
return { return {
...found, ...found,
@@ -403,7 +410,10 @@ const DeliveryOrderProductForm = ({
useEffect(() => { useEffect(() => {
if (initialValues) { if (initialValues) {
if (!Boolean(initialValues.qty)) { if (
!Boolean(initialValues.qty) &&
!Boolean(initialValues.marketing_product_id)
) {
handleResetForm(); handleResetForm();
} else { } else {
setFormikValues({ setFormikValues({
@@ -413,7 +423,7 @@ const DeliveryOrderProductForm = ({
}); });
if (initialValues?.marketing_product_id) { if (initialValues?.marketing_product_id) {
setSelectedProduct({ setSelectedProduct({
value: initialValues?.id, value: initialValues?.marketing_product_id,
label: `${initialValues?.marketing_product?.product_warehouse?.label} - ${initialValues?.marketing_product?.warehouse?.label ?? initialValues?.marketing_product?.kandang?.label}`, label: `${initialValues?.marketing_product?.product_warehouse?.label} - ${initialValues?.marketing_product?.warehouse?.label ?? initialValues?.marketing_product?.kandang?.label}`,
} as OptionType); } as OptionType);
} }
@@ -124,7 +124,9 @@ const DeliveryOrderProductTable = ({
<tr> <tr>
<td className='text-sm px-4 py-3'>Qty</td> <td className='text-sm px-4 py-3'>Qty</td>
<td className='text-sm px-4 py-3'> <td className='text-sm px-4 py-3'>
{item.qty {item.qty !== undefined &&
item.qty !== null &&
item.qty !== ''
? `${formatNumber(parseFloat(item.qty as string))} ${item.marketing_product?.uom ?? ''}` ? `${formatNumber(parseFloat(item.qty as string))} ${item.marketing_product?.uom ?? ''}`
: '-'} : '-'}
</td> </td>
@@ -273,7 +275,9 @@ const DeliveryOrderProductTable = ({
<tr> <tr>
<td className='text-sm px-4 py-3'>Qty</td> <td className='text-sm px-4 py-3'>Qty</td>
<td className='text-sm px-4 py-3'> <td className='text-sm px-4 py-3'>
{item.qty {item.qty !== undefined &&
item.qty !== null &&
item.qty !== ''
? `${formatNumber(Number(item.qty))} ${item.marketing_product?.product_warehouse_data?.product.uom.name ?? ''}` ? `${formatNumber(Number(item.qty))} ${item.marketing_product?.product_warehouse_data?.product.uom.name ?? ''}`
: '-'} : '-'}
</td> </td>