Draft: Preview stripe payment

This commit is contained in:
Bega Jumayev 2023-11-21 03:13:30 +00:00 committed by Anton Semenov
parent 6234a284e0
commit c6fe5b4ff1

View File

@ -1,5 +1,6 @@
import MainButton from "@/components/MainButton"; import MainButton from "@/components/MainButton";
import Title from "@/components/Title"; import Title from "@/components/Title";
import routes from "@/routes";
import { actions } from "@/store"; import { actions } from "@/store";
import { import {
PaymentElement, PaymentElement,
@ -8,6 +9,7 @@ import {
} from "@stripe/react-stripe-js"; } from "@stripe/react-stripe-js";
import { useState } from "react"; import { useState } from "react";
import { useDispatch } from "react-redux"; import { useDispatch } from "react-redux";
import { useNavigate } from "react-router-dom";
interface ICheckoutFormProps { interface ICheckoutFormProps {
children?: JSX.Element | null; children?: JSX.Element | null;
@ -17,6 +19,7 @@ export default function CheckoutForm({ children }: ICheckoutFormProps) {
const stripe = useStripe(); const stripe = useStripe();
const elements = useElements(); const elements = useElements();
const dispatch = useDispatch(); const dispatch = useDispatch();
const navigate = useNavigate();
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
const [isProcessing, setIsProcessing] = useState(false); const [isProcessing, setIsProcessing] = useState(false);
@ -43,6 +46,7 @@ export default function CheckoutForm({ children }: ICheckoutFormProps) {
setMessage(error?.message || "Oops! Something went wrong."); setMessage(error?.message || "Oops! Something went wrong.");
} else { } else {
dispatch(actions.status.update("subscribed")); dispatch(actions.status.update("subscribed"));
navigate(routes.client.paymentSuccess());
} }
} catch(error) { } catch(error) {
console.log('error -> ', error); console.log('error -> ', error);