diff --git a/next/components/organisms/PaymentSystem.js b/next/components/organisms/PaymentSystem.js index 4b36a9f3..b3867504 100644 --- a/next/components/organisms/PaymentSystem.js +++ b/next/components/organisms/PaymentSystem.js @@ -14,6 +14,7 @@ import { } from "@stripe/react-stripe-js"; import cookies from "js-cookie"; import Button from "../atoms/RoundedButton"; +import styles from "../../styles/paymentSystem.module.css"; import { getUser @@ -41,7 +42,7 @@ const PaymentForm = ({ userData }) => { const user = await getUser(userData?.email) cookies.set('userBD', JSON.stringify(user)) - window.open(`/user/${user?.username}?plans_and_payment`, "_self") + window.location.reload() } return ( @@ -49,10 +50,15 @@ const PaymentForm = ({ userData }) => { spacing={0} alignItems="start" > -
- + + - + + + ) @@ -93,10 +99,10 @@ export default function PaymentSystem({ userData, plan }) { fonts: [{ cssSrc: 'https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;700&display=swap' }], } - const customerCreatPost = async () => { + const customerCreatPost = async (id) => { let secret = "" - const subscriptionCreate = await createSubscription("19") + const subscriptionCreate = await createSubscription(id) if(subscriptionCreate?.clientSecret) { secret = subscriptionCreate?.clientSecret } @@ -104,15 +110,31 @@ export default function PaymentSystem({ userData, plan }) { const result = await createCustomer() if(result?.id) { - const subscriptionCreate = await createSubscription("19") + const subscriptionCreate = await createSubscription(id) secret = subscriptionCreate?.clientSecret } return setClientSecret(secret) } + async function customerCreat(plan) { + const prices = await getPrices() + + const findPlan = (slug, slots) => { + const foundPlan = prices.find(p => { + return p.node.productSlug === slug && p.node.productSlots === slots + }) + + return foundPlan ? foundPlan.node : null + } + + const idPlan = findPlan(plan.slug, plan.slots)?._id + + customerCreatPost(idPlan) + } + useEffect(() => { - customerCreatPost() + customerCreat(plan) }, []) const SkeletonBox = ({ type, ...props }) => { @@ -133,11 +155,6 @@ export default function PaymentSystem({ userData, plan }) { - - - - - @@ -158,7 +175,6 @@ export default function PaymentSystem({ userData, plan }) { return ( - ) diff --git a/next/pages/api/stripe/getPrices.js b/next/pages/api/stripe/getPrices.js index 62bc71d5..7122265c 100644 --- a/next/pages/api/stripe/getPrices.js +++ b/next/pages/api/stripe/getPrices.js @@ -16,6 +16,8 @@ export default async function getPrices() { _id amount productName + productSlug + productSlots } } } diff --git a/next/pages/precos.js b/next/pages/precos.js index b9d8690e..169053a1 100644 --- a/next/pages/precos.js +++ b/next/pages/precos.js @@ -309,21 +309,34 @@ export const CardPrice = ({ flexDirection="column" gap="16px" > - { - if(button.onClick) return button.onClick() - if(button?.noHasModal) return window.open(button.href, "_self") - onOpen() - setLinkStripe(button.href) - }} - border={button.color && `1px solid ${button.colorText}`} - {...button.styles} - > - {button.text} - + {button.isCurrentPlan ? + + {button.text} + + : + { + if(button.onClick) return button.onClick() + if(button?.noHasModal) return window.open(button.href, "_self") + onOpen() + setLinkStripe(button.href) + }} + border={button.color && `1px solid ${button.colorText}`} + {...button.styles} + > + {button.text} + + } @@ -453,8 +469,10 @@ export default function Price() { {name: "Dezenas de bases de alta frequência atualizadas"}, ]} button={{ - text: `Iniciar teste grátis`, - href: "https://buy.stripe.com/8wM01TeVQ3kg0mIeV4?locale=pt" + text: ifBDPro ? "Plano atual" : `Iniciar teste grátis`, + href: userData === null ? "/user/login" :`/user/${userData.username}?plans_and_payment`, + isCurrentPlan: ifBDPro ? true : false, + noHasModal: true }} hasServiceTerms /> @@ -472,8 +490,10 @@ export default function Price() { {name: "Acesso para 10 contas"},{name: "Suporte prioritário via email e Discord"} ]} button={{ - text: "Iniciar teste grátis", - href: "https://buy.stripe.com/00g4i93d8f2Y5H24gr?locale=pt" + text: ifBDProEmp ? "Plano atual" : "Iniciar teste grátis", + href: userData === null ? "/user/login" :`/user/${userData.username}?plans_and_payment`, + isCurrentPlan: ifBDProEmp ? true : false, + noHasModal: true }} hasServiceTerms /> diff --git a/next/pages/user/[username].js b/next/pages/user/[username].js index c306e110..8e632c7c 100644 --- a/next/pages/user/[username].js +++ b/next/pages/user/[username].js @@ -1377,7 +1377,7 @@ const NewPassword = ({ userInfo }) => { } const PlansAndPayment = ({ userData }) => { - const [plan, setPlan] = useState("") + const [plan, setPlan] = useState({}) const PaymentModal = useDisclosure() const PlansModal = useDisclosure() const CancelModalPlan = useDisclosure() @@ -1483,7 +1483,9 @@ const PlansAndPayment = ({ userData }) => { const cancelSubscripetion = async () => { const subs = await getSubscriptionActive(userData.email) const result = await removeSubscription(subs[0]?.node._id) - window.location.reload() + setTimeout(() => { + window.location.reload() + }, 2000) } return ( @@ -1494,7 +1496,9 @@ const PlansAndPayment = ({ userData }) => { isCentered={isMobileMod() ? false : true} propsModalContent={{ minWidth: "fit-content", - maxWidth: "fit-content" + maxWidth: "fit-content", + maxHeight: isMobileMod() ? "100%" : "700px", + overflowY: "auto" }} > @@ -1592,19 +1596,11 @@ const PlansAndPayment = ({ userData }) => { button={{ text: `${userData?.proSubscription === "bd_pro" ? "Plano atual" : "Iniciar teste grátis"}`, onClick: userData?.proSubscription === "bd_pro" ? () => {} : () => { - setPlan("bd_pro") + setPlan({slug:"bd_pro", slots: "0"}) PlansModal.onClose() PaymentModal.onOpen() }, - styles: - userData?.proSubscription === "bd_pro" && { - color: "#252A32", - backgroundColor: "#FFF", - boxShadow: "none", - cursor: "default", - _hover: {transform: "none"}, - fontWeight: "400" - } + isCurrentPlan: userData?.proSubscription === "bd_pro" ? true : false, }} hasServiceTerms /> @@ -1624,19 +1620,11 @@ const PlansAndPayment = ({ userData }) => { button={{ text: `${userData?.proSubscription === "bd_pro_empresas" ? "Plano atual" : "Iniciar teste grátis"}`, onClick: userData?.proSubscription === "bd_pro_empresas" ? () => {} : () => { - setPlan("bd_pro_empresas") + setPlan({slug:"bd_pro_empresas", slots: "10"}) PlansModal.onClose() PaymentModal.onOpen() }, - styles: - userData?.proSubscription === "bd_pro_empresas" && { - color: "#252A32", - backgroundColor: "#FFF", - boxShadow: "none", - cursor: "default", - _hover: {transform: "none"}, - fontWeight: "400" - } + isCurrentPlan: userData?.proSubscription === "bd_pro_empresas" ? true : false, }} hasServiceTerms /> diff --git a/next/styles/paymentSystem.module.css b/next/styles/paymentSystem.module.css new file mode 100644 index 00000000..61c491d1 --- /dev/null +++ b/next/styles/paymentSystem.module.css @@ -0,0 +1,5 @@ +.content { + display: flex; + flex-direction: column; + gap: 14px; +}