From 34f8a6650c58330f7620989cc6c6d52ac7366397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Sun, 6 Mar 2022 10:11:02 +0400 Subject: [PATCH] Change PaymentMethod component --- components/soutyen/payment-method.js | 225 +++++++++++++++------------ 1 file changed, 127 insertions(+), 98 deletions(-) diff --git a/components/soutyen/payment-method.js b/components/soutyen/payment-method.js index 0a844ec..78c315a 100644 --- a/components/soutyen/payment-method.js +++ b/components/soutyen/payment-method.js @@ -1,117 +1,146 @@ -import {useEffect, useMemo} from 'react' import PropTypes from 'prop-types' -import clsx from 'clsx' -import {styled} from '@mui/system' -import {useSwitch} from '@mui/base/SwitchUnstyled' +import Tabs from '@mui/material/Tabs' +import Tab from '@mui/material/Tab' +import Box from '@mui/material/Box' +import Button from '@mui/material/Button' -const green = { - 700: '#4CAF50', -} +import {Paypal} from '@icons-pack/react-simple-icons' +import {Elements} from '@stripe/react-stripe-js' +import {loadStripe} from '@stripe/stripe-js' -const grey = { - 400: '#BFC7CF', - 800: '#2F3A45', -} +import {appearance} from '../../lib/utils/stripe-style' -const SwitchRoot = styled('span')` - display: inline-block; - position: relative; - width: 84px; - height: 36px; - padding: 8px; -` +import CheckoutForm from './checkout-form' +import StripePayment from './stripe-payment' -const SwitchInput = styled('input')` - position: absolute; - width: 100%; - height: 100%; - top: 0; - left: 0; - opacity: 0; - z-index: 1; - margin: 0; - cursor: pointer; -` - -const SwitchThumb = styled('span')` - position: absolute; - display: block; - background-color: ${green[700]}; - width: 40px; - height: 40px; - border-radius: 8px; - top: -1px; - left: 4px; - transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1); - - &::before { - display: block; - content: ''; - width: 100%; - height: 100%; - background: url('data:image/svg+xml;utf8,') - center center no-repeat; - } - - &.focusVisible { - background-color: #79b; - } - - &.checked { - transform: translateX(44px); - - &::before { - background-image: url('data:image/svg+xml;utf8,'); - } - } -` - -const SwitchTrack = styled('span')( - ({theme}) => ` - background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[400]}; - border-radius: 4px; - width: 100%; - height: 100%; - display: block; -`, +const stripePromise = loadStripe( + process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY ) -function MUISwitch(props) { - const {setIsPaypal} = props - const {getInputProps, checked, disabled, focusVisible} = useSwitch(props) +const PAYPAL_ID = process.env.NEXT_PUBLIC_PAYPAL_DONATE_ID - const stateClasses = useMemo(() => ({ - checked, - disabled, - focusVisible, - }), [checked, disabled, focusVisible]) - - useEffect(() => { - setIsPaypal(stateClasses.checked) - }, [setIsPaypal, stateClasses]) +function TabPanel(props) { + const {children, value, index, ...other} = props return ( - - - - - - + ) } -MUISwitch.propTypes = { - setIsPaypal: PropTypes.func.isRequired +TabPanel.propTypes = { + children: PropTypes.node, + index: PropTypes.number.isRequired, + value: PropTypes.number.isRequired, } -export default function PaymentMethod({setIsPaypal}) { - return +function a11yProps(index) { + return { + id: `simple-tab-${index}`, + 'aria-controls': `simple-tabpanel-${index}`, + } +} + +export default function PaymentMethod({isLoading, paymentMethod, setPaymentMethod, selectedMontant, setSelectedMontant, validMontant, setValidMontant, prices, paymentIntent, setClientSecret, setPaymentIntent, setIsLoading, setPaymentIsReady, setClientEmail, clientEmail, error, setError, clientSecret}) { + const options = { + clientSecret, + appearance, + } + + const handleChange = (event, newValue) => { + setPaymentMethod(newValue) + } + + return ( + + + + + + + + + + + + + + + + + + {clientSecret && validMontant && paymentMethod === 2 && ( + + + + )} + + + ) +} + +PaymentMethod.defaultProps = { + selectedMontant: null, + validMontant: null, + paymentIntent: null, + clientEmail: null, + error: null, + clientSecret: null } PaymentMethod.propTypes = { - setIsPaypal: PropTypes.func.isRequired + isLoading: PropTypes.bool.isRequired, + paymentMethod: PropTypes.number.isRequired, + setPaymentMethod: PropTypes.func.isRequired, + selectedMontant: PropTypes.string, + setSelectedMontant: PropTypes.func.isRequired, + validMontant: PropTypes.string, + setValidMontant: PropTypes.func.isRequired, + prices: PropTypes.array.isRequired, + paymentIntent: PropTypes.string, + setClientSecret: PropTypes.func.isRequired, + setPaymentIntent: PropTypes.func.isRequired, + setIsLoading: PropTypes.func.isRequired, + setPaymentIsReady: PropTypes.func.isRequired, + setClientEmail: PropTypes.func.isRequired, + clientEmail: PropTypes.string, + error: PropTypes.string, + setError: PropTypes.func.isRequired, + clientSecret: PropTypes.string }