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

View File

@ -49,15 +49,14 @@ function SubscriptionPage(): JSX.Element {
const [apiError, setApiError] = useState<ApiError | null>(null); const [apiError, setApiError] = useState<ApiError | null>(null);
const [error, setError] = useState<boolean>(false); const [error, setError] = useState<boolean>(false);
const [subPlans, setSubPlans] = useState<ISubscriptionPlan[]>([]); 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 birthday = useSelector(selectors.selectBirthday);
// const queryParameters = new URLSearchParams(window.location.search); useEffect(() => {
// const sub_plan = queryParameters.get("sub_plan") || "";
const { subPlan } = useParams();
const activeSubPlanFromStore = useSelector(selectors.selectActiveSubPlan);
let activeSubPlan;
if (subPlan) { if (subPlan) {
const targetSubPlan = subPlans.find( const targetSubPlan = subPlans.find(
(sub_plan) => (sub_plan) =>
@ -68,11 +67,10 @@ function SubscriptionPage(): JSX.Element {
) === subPlan ) === subPlan
); );
if (targetSubPlan) { if (targetSubPlan) {
activeSubPlan = targetSubPlan; setActiveSubPlan(targetSubPlan);
} }
} else {
activeSubPlan = activeSubPlanFromStore;
} }
}, [subPlan, subPlans]);
const paymentItems = [ const paymentItems = [
{ {
@ -103,6 +101,11 @@ function SubscriptionPage(): JSX.Element {
dispatch(actions.user.update(updatedUser.user)); dispatch(actions.user.update(updatedUser.user));
} }
dispatch(actions.status.update("registred")); dispatch(actions.status.update("registred"));
dispatch(
actions.payment.update({
activeSubPlan,
})
);
setIsLoading(false); setIsLoading(false);
setIsAuth(true); setIsAuth(true);
setTimeout(() => { setTimeout(() => {