From dc6251d8597b33c2c34ac40d68c1f3d2c5cc5d19 Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Tue, 25 Jun 2024 10:14:35 -0700 Subject: [PATCH] added loading, success, and pro state --- src/editor/components/Main.js | 1 + .../PaymentModal/PaymentModal.component.jsx | 89 +++++++++++-------- .../PaymentModal/PaymentModal.module.scss | 19 ++++ .../ProfileModal/ProfileModal.component.jsx | 8 +- 4 files changed, 75 insertions(+), 42 deletions(-) diff --git a/src/editor/components/Main.js b/src/editor/components/Main.js index 8e8a589cd..fff48302e 100644 --- a/src/editor/components/Main.js +++ b/src/editor/components/Main.js @@ -162,6 +162,7 @@ export default class Main extends Component { }; onClosePaymentModal = () => { + window.location.hash = '#'; this.setState({ isPaymentModalOpened: false }); }; diff --git a/src/editor/components/modals/PaymentModal/PaymentModal.component.jsx b/src/editor/components/modals/PaymentModal/PaymentModal.component.jsx index 8a4e0c7bd..7a38f05d8 100644 --- a/src/editor/components/modals/PaymentModal/PaymentModal.component.jsx +++ b/src/editor/components/modals/PaymentModal/PaymentModal.component.jsx @@ -1,10 +1,11 @@ import { httpsCallable } from 'firebase/functions'; import styles from './PaymentModal.module.scss'; +import { useState } from 'react'; import { loadStripe } from '@stripe/stripe-js'; import PaymentPlaceholderImg from '../../../../../ui_assets/payment-placeholder.png'; import { useAuthContext } from '../../../contexts/index.js'; -import { CheckMark32Icon } from '../../../icons/icons.jsx'; +import { CheckMark32Icon, Loader } from '../../../icons'; import { Button } from '../../components/index.js'; import Modal from '../Modal.jsx'; import { functions } from '../../../services/firebase.js'; @@ -20,6 +21,41 @@ const getStripe = () => { const PaymentModal = ({ isOpen, onClose }) => { const { currentUser } = useAuthContext(); + const [isLoading, setIsLoading] = useState(false); + + const isSucess = window.location.hash.includes('/success'); + if (isSucess) { + STREET.notify.successMessage('Thank you for subscribing!'); + } + + const startCheckout = async () => { + setIsLoading(true); + try { + const { + data: { id } + } = await httpsCallable( + functions, + 'createStripeSession' + )({ + line_items: [{ price: 'price_1PVKKsA638v2qJqBw2E7cY3S', quantity: 1 }], + mode: 'subscription', + success_url: `${location.origin}/#/modal/payment/success`, + cancel_url: `${location.origin}/#/modal/payment`, + metadata: { userId: currentUser.uid }, + subscription_data: { + metadata: { + userId: currentUser.uid + } + } + }); + + const stripe = await getStripe(); + await stripe.redirectToCheckout({ sessionId: id }); + } catch (error) { + console.log(error); + } + setIsLoading(false); + }; return ( { className={styles.paymentPlaceholder} src={PaymentPlaceholderImg} /> - {currentUser.isPremium ? ( + {currentUser.isPro ? ( ) : ( - + <> + {isLoading ? ( +
+ +
+ ) : ( + + )} + )} ) : ( diff --git a/src/editor/components/modals/PaymentModal/PaymentModal.module.scss b/src/editor/components/modals/PaymentModal/PaymentModal.module.scss index 0938e5962..68c20d91d 100644 --- a/src/editor/components/modals/PaymentModal/PaymentModal.module.scss +++ b/src/editor/components/modals/PaymentModal/PaymentModal.module.scss @@ -80,5 +80,24 @@ font-weight: 500; } } + + .loadingSpinner { + display: flex; + justify-content: center; + align-items: center; + margin: auto; + .spinner { + animation: spin 2s linear infinite; + } + + @keyframes spin { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } + } + } } } diff --git a/src/editor/components/modals/ProfileModal/ProfileModal.component.jsx b/src/editor/components/modals/ProfileModal/ProfileModal.component.jsx index 668089820..8ba411a22 100644 --- a/src/editor/components/modals/ProfileModal/ProfileModal.component.jsx +++ b/src/editor/components/modals/ProfileModal/ProfileModal.component.jsx @@ -55,10 +55,10 @@ const ProfileModal = ({ isOpen, onClose }) => {
- {currentUser?.isPremium ? ( + {currentUser?.isPro ? (

- SubscriptionPlan: Geospatial Pro + Plan: Geospatial Pro

- -
)}