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(() => {
if (!hasDeliveryOrder || !deliveryOrders) return null;
const marketingProductId =
initialValues?.marketing_product_id ?? initialValues?.id;
for (const doItem of deliveryOrders) {
const found = doItem.deliveries.find(
(d) =>
d.product_warehouse.id ===
initialValues?.marketing_product?.product_warehouse_id
);
const found =
doItem.deliveries.find(
(d) => d.marketing_product_id === marketingProductId
) ??
doItem.deliveries.find(
(d) =>
d.product_warehouse.id ===
initialValues?.marketing_product?.product_warehouse_id
);
if (found) {
return {
...found,
@@ -403,7 +410,10 @@ const DeliveryOrderProductForm = ({
useEffect(() => {
if (initialValues) {
if (!Boolean(initialValues.qty)) {
if (
!Boolean(initialValues.qty) &&
!Boolean(initialValues.marketing_product_id)
) {
handleResetForm();
} else {
setFormikValues({
@@ -413,7 +423,7 @@ const DeliveryOrderProductForm = ({
});
if (initialValues?.marketing_product_id) {
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}`,
} as OptionType);
}
@@ -124,7 +124,9 @@ const DeliveryOrderProductTable = ({
<tr>
<td className='text-sm px-4 py-3'>Qty</td>
<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 ?? ''}`
: '-'}
</td>
@@ -273,7 +275,9 @@ const DeliveryOrderProductTable = ({
<tr>
<td className='text-sm px-4 py-3'>Qty</td>
<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 ?? ''}`
: '-'}
</td>