🐛 fix: Update quantity handling in Purchase and Renewal components based on showOriginalPrice prop
This commit is contained in:
parent
cc52e3614d
commit
a2746073a6
@ -15,6 +15,7 @@ interface DurationSelectorProps {
|
||||
unitTime?: string;
|
||||
discounts?: Array<{ quantity: number; discount: number }>;
|
||||
onChange: (value: number) => void;
|
||||
showOriginalPrice?: boolean;
|
||||
}
|
||||
|
||||
const DurationSelector: React.FC<DurationSelectorProps> = ({
|
||||
@ -22,6 +23,7 @@ const DurationSelector: React.FC<DurationSelectorProps> = ({
|
||||
unitTime = "Month",
|
||||
discounts = [],
|
||||
onChange,
|
||||
showOriginalPrice = true,
|
||||
}) => {
|
||||
const { t } = useTranslation("subscribe");
|
||||
const handleChange = useCallback(
|
||||
@ -61,7 +63,7 @@ const DurationSelector: React.FC<DurationSelectorProps> = ({
|
||||
onValueChange={handleChange}
|
||||
value={String(quantity)}
|
||||
>
|
||||
{unitTime !== "Minute" && (
|
||||
{showOriginalPrice && unitTime !== "Minute" && (
|
||||
<DurationOption label={`1 / ${t(unitTime)}`} value="1" />
|
||||
)}
|
||||
{discounts?.map((item) => (
|
||||
|
||||
@ -74,9 +74,13 @@ export default function Purchase({
|
||||
|
||||
useEffect(() => {
|
||||
if (subscribe) {
|
||||
const defaultQuantity =
|
||||
subscribe.show_original_price === false && subscribe.discount?.[0]
|
||||
? subscribe.discount[0].quantity
|
||||
: 1;
|
||||
setParams((prev) => ({
|
||||
...prev,
|
||||
quantity: 1,
|
||||
quantity: defaultQuantity,
|
||||
subscribe_id: subscribe?.id,
|
||||
}));
|
||||
}
|
||||
@ -146,6 +150,7 @@ export default function Purchase({
|
||||
handleChange("quantity", value);
|
||||
}}
|
||||
quantity={params.quantity as number}
|
||||
showOriginalPrice={subscribe?.show_original_price}
|
||||
unitTime={subscribe?.unit_time}
|
||||
/>
|
||||
<CouponInput
|
||||
|
||||
@ -72,9 +72,13 @@ export default function Renewal({ id, subscribe }: Readonly<RenewalProps>) {
|
||||
|
||||
useEffect(() => {
|
||||
if (subscribe.id && id) {
|
||||
const defaultQuantity =
|
||||
subscribe.show_original_price === false && subscribe.discount?.[0]
|
||||
? subscribe.discount[0].quantity
|
||||
: 1;
|
||||
setParams((prev) => ({
|
||||
...prev,
|
||||
quantity: 1,
|
||||
quantity: defaultQuantity,
|
||||
subscribe_id: subscribe.id,
|
||||
user_subscribe_id: id,
|
||||
}));
|
||||
@ -145,6 +149,7 @@ export default function Renewal({ id, subscribe }: Readonly<RenewalProps>) {
|
||||
handleChange("quantity", value);
|
||||
}}
|
||||
quantity={params.quantity!}
|
||||
showOriginalPrice={subscribe?.show_original_price}
|
||||
unitTime={subscribe?.unit_time}
|
||||
/>
|
||||
<CouponInput
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user