AW-47-duplicateSubscriptionPlans
This commit is contained in:
parent
04254c4a83
commit
0920d84843
@ -1,21 +1,21 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from "react";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
import { selectors } from "@/store";
|
import { selectors } from "@/store";
|
||||||
import useSteps, { Step } from '@/hooks/palmistry/use-steps';
|
import useSteps, { Step } from "@/hooks/palmistry/use-steps";
|
||||||
import Button from '@/components/palmistry/button/button';
|
import Button from "@/components/palmistry/button/button";
|
||||||
import EmailHeader from '@/components/palmistry/email-header/email-header';
|
import EmailHeader from "@/components/palmistry/email-header/email-header";
|
||||||
import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
|
import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
|
||||||
import { actions } from "@/store";
|
import { actions } from "@/store";
|
||||||
import { useApi } from "@/api";
|
import { useApi } from "@/api";
|
||||||
|
|
||||||
const bestPlanId = 'stripe.15';
|
const bestPlanId = "stripe.15";
|
||||||
|
|
||||||
const getFormattedPrice = (plan: ISubscriptionPlan) => {
|
const getFormattedPrice = (plan: ISubscriptionPlan) => {
|
||||||
return (plan.trial!.price_cents / 100).toFixed(2);
|
return (plan.trial!.price_cents / 100).toFixed(2);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function StepSubscriptionPlan() {
|
export default function StepSubscriptionPlan() {
|
||||||
const steps = useSteps();
|
const steps = useSteps();
|
||||||
@ -23,11 +23,14 @@ export default function StepSubscriptionPlan() {
|
|||||||
const api = useApi();
|
const api = useApi();
|
||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
const activeSubPlanFromStore = useSelector(selectors.selectActiveSubPlan);
|
const activeSubPlanFromStore = useSelector(selectors.selectActiveSubPlan);
|
||||||
|
const allowedPlans = useMemo(() => ["stripe.37"], []);
|
||||||
|
|
||||||
const storedEmail = steps.getStoredValue(Step.Email);
|
const storedEmail = steps.getStoredValue(Step.Email);
|
||||||
|
|
||||||
const [subscriptionPlan, setSubscriptionPlan] = React.useState('');
|
const [subscriptionPlan, setSubscriptionPlan] = React.useState("");
|
||||||
const [subscriptionPlans, setSubscriptionPlans] = React.useState<ISubscriptionPlan[]>([]);
|
const [subscriptionPlans, setSubscriptionPlans] = React.useState<
|
||||||
|
ISubscriptionPlan[]
|
||||||
|
>([]);
|
||||||
const [email, setEmail] = React.useState(steps.getStoredValue(Step.Email));
|
const [email, setEmail] = React.useState(steps.getStoredValue(Step.Email));
|
||||||
|
|
||||||
const locale = i18n.language;
|
const locale = i18n.language;
|
||||||
@ -42,7 +45,10 @@ export default function StepSubscriptionPlan() {
|
|||||||
(async () => {
|
(async () => {
|
||||||
const { sub_plans } = await api.getSubscriptionPlans({ locale });
|
const { sub_plans } = await api.getSubscriptionPlans({ locale });
|
||||||
const plans = sub_plans
|
const plans = sub_plans
|
||||||
.filter((plan: ISubscriptionPlan) => plan.provider === "stripe")
|
.filter(
|
||||||
|
(plan: ISubscriptionPlan) =>
|
||||||
|
plan.provider === "stripe" && !plan.name.includes("(test)")
|
||||||
|
)
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
if (!a.trial || !b.trial) {
|
if (!a.trial || !b.trial) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -55,13 +61,19 @@ export default function StepSubscriptionPlan() {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
setSubscriptionPlans(plans.filter((plan) => plan.trial?.price_cents));
|
setSubscriptionPlans(
|
||||||
|
plans.filter(
|
||||||
|
(plan) => plan.trial?.price_cents || allowedPlans.includes(plan.id)
|
||||||
|
)
|
||||||
|
);
|
||||||
})();
|
})();
|
||||||
}, [api, locale]);
|
}, [allowedPlans, api, locale]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (subscriptionPlan) {
|
if (subscriptionPlan) {
|
||||||
const targetSubPlan = subscriptionPlans.find((sub_plan) => sub_plan.id === subscriptionPlan);
|
const targetSubPlan = subscriptionPlans.find(
|
||||||
|
(sub_plan) => sub_plan.id === subscriptionPlan
|
||||||
|
);
|
||||||
|
|
||||||
if (targetSubPlan) {
|
if (targetSubPlan) {
|
||||||
dispatch(actions.payment.update({ activeSubPlan: targetSubPlan }));
|
dispatch(actions.payment.update({ activeSubPlan: targetSubPlan }));
|
||||||
@ -70,7 +82,7 @@ export default function StepSubscriptionPlan() {
|
|||||||
}, [subscriptionPlan]);
|
}, [subscriptionPlan]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
setEmail(storedEmail || '');
|
setEmail(storedEmail || "");
|
||||||
}, [storedEmail]);
|
}, [storedEmail]);
|
||||||
|
|
||||||
const onNext = () => {
|
const onNext = () => {
|
||||||
@ -80,15 +92,21 @@ export default function StepSubscriptionPlan() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<EmailHeader email={email}/>
|
<EmailHeader email={email} />
|
||||||
|
|
||||||
<div className="palmistry-container__title">
|
<div className="palmistry-container__title">
|
||||||
We've helped millions of people to reveal the destiny of their love life and what the future holds for them and
|
We've helped millions of people to reveal the destiny of their love life
|
||||||
their families.
|
and what the future holds for them and their families.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="palmistry-container__image">
|
<div className="palmistry-container__image">
|
||||||
<svg width="153" height="133" viewBox="0 0 153 133" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg
|
||||||
|
width="153"
|
||||||
|
height="133"
|
||||||
|
viewBox="0 0 153 133"
|
||||||
|
fill="none"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
<g clipPath="url(#clip0_16903_24136)">
|
<g clipPath="url(#clip0_16903_24136)">
|
||||||
<rect width="153" height="133" fill=""></rect>
|
<rect width="153" height="133" fill=""></rect>
|
||||||
<path
|
<path
|
||||||
@ -131,7 +149,11 @@ export default function StepSubscriptionPlan() {
|
|||||||
{subscriptionPlans.map((plan) => (
|
{subscriptionPlans.map((plan) => (
|
||||||
<div
|
<div
|
||||||
key={plan.id}
|
key={plan.id}
|
||||||
className={`palmistry-container__plan ${subscriptionPlan === plan.id ? 'palmistry-container__plan_active' : ''}`}
|
className={`palmistry-container__plan ${
|
||||||
|
subscriptionPlan === plan.id
|
||||||
|
? "palmistry-container__plan_active"
|
||||||
|
: ""
|
||||||
|
}`}
|
||||||
onClick={() => setSubscriptionPlan(plan.id)}
|
onClick={() => setSubscriptionPlan(plan.id)}
|
||||||
>
|
>
|
||||||
<h3>${getFormattedPrice(plan)}</h3>
|
<h3>${getFormattedPrice(plan)}</h3>
|
||||||
@ -139,11 +161,23 @@ export default function StepSubscriptionPlan() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span className={`palmistry-container__subscription-text ${subscriptionPlan === bestPlanId ? 'palmistry-container__subscription-text_active' : ''}`}>
|
<span
|
||||||
It costs us $13.21 to compensate our AURA employees for the trial, but please choose the amount you are comfortable with.
|
className={`palmistry-container__subscription-text ${
|
||||||
|
subscriptionPlan === bestPlanId
|
||||||
|
? "palmistry-container__subscription-text_active"
|
||||||
|
: ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
It costs us $13.21 to compensate our AURA employees for the trial, but
|
||||||
|
please choose the amount you are comfortable with.
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<Button className="palmistry-container__button" type="button" onClick={onNext} active>
|
<Button
|
||||||
|
className="palmistry-container__button"
|
||||||
|
type="button"
|
||||||
|
onClick={onNext}
|
||||||
|
active
|
||||||
|
>
|
||||||
Continue
|
Continue
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user