This commit is contained in:
Денис Катаев 2023-12-04 21:08:23 +00:00 committed by Victor Ershov
parent 7d5d53b901
commit 71d1be6416

View File

@ -49,30 +49,28 @@ function SubscriptionPage(): JSX.Element {
const [apiError, setApiError] = useState<ApiError | null>(null);
const [error, setError] = useState<boolean>(false);
const [subPlans, setSubPlans] = useState<ISubscriptionPlan[]>([]);
const activeSubPlanFromStore = useSelector(selectors.selectActiveSubPlan);
const [activeSubPlan, setActiveSubPlan] = useState<ISubscriptionPlan | null>(
activeSubPlanFromStore
);
const { subPlan } = useParams();
const birthday = useSelector(selectors.selectBirthday);
// const queryParameters = new URLSearchParams(window.location.search);
// const sub_plan = queryParameters.get("sub_plan") || "";
const { subPlan } = useParams();
const activeSubPlanFromStore = useSelector(selectors.selectActiveSubPlan);
let activeSubPlan;
if (subPlan) {
const targetSubPlan = subPlans.find(
(sub_plan) =>
String(
sub_plan.trial?.price_cents
? Math.floor(sub_plan.trial?.price_cents / 100)
: sub_plan.id.replace(".", "")
) === subPlan
);
if (targetSubPlan) {
activeSubPlan = targetSubPlan;
useEffect(() => {
if (subPlan) {
const targetSubPlan = subPlans.find(
(sub_plan) =>
String(
sub_plan.trial?.price_cents
? Math.floor(sub_plan.trial?.price_cents / 100)
: sub_plan.id.replace(".", "")
) === subPlan
);
if (targetSubPlan) {
setActiveSubPlan(targetSubPlan);
}
}
} else {
activeSubPlan = activeSubPlanFromStore;
}
}, [subPlan, subPlans]);
const paymentItems = [
{
@ -103,6 +101,11 @@ function SubscriptionPage(): JSX.Element {
dispatch(actions.user.update(updatedUser.user));
}
dispatch(actions.status.update("registred"));
dispatch(
actions.payment.update({
activeSubPlan,
})
);
setIsLoading(false);
setIsAuth(true);
setTimeout(() => {