🐛 fix(subscribe): Handle optional values in price and discount calculations
This commit is contained in:
parent
fa56eb8293
commit
5939763b57
@ -564,7 +564,7 @@ export default function SubscribeForm<T extends Record<string, any>>({
|
|||||||
return {
|
return {
|
||||||
...data,
|
...data,
|
||||||
price: evaluateWithPrecision(
|
price: evaluateWithPrecision(
|
||||||
`${unit_price} * ${data.quantity} * ${data.discount} / 100`,
|
`${unit_price || 0} * ${data.quantity || 0} * ${data.discount || 0} / 100`,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -581,7 +581,7 @@ export default function SubscribeForm<T extends Record<string, any>>({
|
|||||||
return {
|
return {
|
||||||
...data,
|
...data,
|
||||||
discount: evaluateWithPrecision(
|
discount: evaluateWithPrecision(
|
||||||
`${data.price} / ${data.quantity} / ${unit_price} * 100`,
|
`${data.price || 0} / ${data.quantity || 0} / ${unit_price || 0} * 100`,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -589,7 +589,6 @@ export default function SubscribeForm<T extends Record<string, any>>({
|
|||||||
]}
|
]}
|
||||||
value={field.value}
|
value={field.value}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
console.log(value);
|
|
||||||
form.setValue(field.name, value);
|
form.setValue(field.name, value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -36,7 +36,7 @@ export function ObjectInput<T extends Record<string, any>>({
|
|||||||
let updatedState = { ...internalState, ...value };
|
let updatedState = { ...internalState, ...value };
|
||||||
|
|
||||||
fields.forEach((field) => {
|
fields.forEach((field) => {
|
||||||
if (field.calculateValue) {
|
if (field?.calculateValue) {
|
||||||
updatedState = field.calculateValue(updatedState);
|
updatedState = field.calculateValue(updatedState);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user