From 4f3b19579c3c17a271699ee747d6bb525a5b39ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B5=D0=BD=D0=B8=D1=81=20=D0=9A=D0=B0=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Thu, 6 Jun 2024 22:58:04 +0000 Subject: [PATCH] AW-102-default-product --- .../step-subscription-plan.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/palmistry/step-subscription-plan/step-subscription-plan.tsx b/src/components/palmistry/step-subscription-plan/step-subscription-plan.tsx index e8b0e38..35cd301 100644 --- a/src/components/palmistry/step-subscription-plan/step-subscription-plan.tsx +++ b/src/components/palmistry/step-subscription-plan/step-subscription-plan.tsx @@ -25,7 +25,7 @@ export default function StepSubscriptionPlan() { }); const defaultProduct = properties.find( (property) => property.key === "default.product" - )?._id; + )?.value; const storedEmail = steps.getStoredValue(Step.Email); @@ -34,18 +34,19 @@ export default function StepSubscriptionPlan() { const [email, setEmail] = React.useState(steps.getStoredValue(Step.Email)); React.useEffect(() => { - if (!defaultProduct) return; - const targetDefaultProduct = products.find((p) => p._id === defaultProduct); + if (!defaultProduct || activeProductFromStore) return; + const targetDefaultProduct = products.find((p) => p.key === defaultProduct); if (!targetDefaultProduct) return; - setProduct(defaultProduct); - steps.saveCurrent(defaultProduct); + setProduct(targetDefaultProduct._id); + steps.saveCurrent(targetDefaultProduct._id); dispatch( actions.payment.update({ activeProduct: targetDefaultProduct, }) ); - }, [defaultProduct, dispatch, products, steps]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [defaultProduct]); React.useEffect(() => { if (activeProductFromStore) {