diff --git a/web/src/components/return-page/ErrorReturn.tsx b/web/src/components/return-page/ErrorReturn.tsx new file mode 100644 index 0000000..12a35f7 --- /dev/null +++ b/web/src/components/return-page/ErrorReturn.tsx @@ -0,0 +1,41 @@ +import { useNavigate } from "react-router"; +import { EmailLink } from "../../data/data"; + + +export default function ErrorReturn() { + const navigate = useNavigate(); + return ( + <> +
+
+
+

+ Payment Failed +

+
+
+
+

+ Please try again, or contact{" "} + + {EmailLink} + + . +

+
+ +
+ +
+
+ + ); +} \ No newline at end of file diff --git a/web/src/hooks/api/useUpdateUserTicketInfo.ts b/web/src/hooks/api/useUpdateUserTicketInfo.ts index 5743a27..4d09886 100644 --- a/web/src/hooks/api/useUpdateUserTicketInfo.ts +++ b/web/src/hooks/api/useUpdateUserTicketInfo.ts @@ -2,8 +2,6 @@ import { useMutation } from "@tanstack/react-query"; import { updateUserTicketInfo } from "../../api/apiRequests"; import { AnswerList, - QuestionAnswer, - SubmitUpdateUserInfoOrNewUser, UpdateUserInfoOrNewUser, } from "../../types/types"; diff --git a/web/src/screens/ReturnScreen.tsx b/web/src/screens/ReturnScreen.tsx index 503086c..7bce6b9 100644 --- a/web/src/screens/ReturnScreen.tsx +++ b/web/src/screens/ReturnScreen.tsx @@ -1,83 +1,71 @@ import { useState, useEffect } from "react"; -import { Navigate, useNavigate } from "react-router"; +import { Navigate, useNavigate, useParams } from "react-router"; import { EmailLink } from "../data/data"; -import { getSessionStatus } from "../api/apiRequests"; +// import { getSessionStatus } from "../api/apiRequests"; +import { useSessionStatus } from "../hooks/api/useSessionStatus"; +import LoadingSpinner from "@components/navigation/LoadingSpinner"; +import { useSearchParams } from "react-router-dom"; +import ErrorReturn from "@components/return-page/ErrorReturn"; + +export default function ReturnScreen() { + + + let sessionId: string; + const [searchParams] = useSearchParams(); + const session_id = searchParams.get("session_id"); + if (session_id !== null && session_id.length !== 0) { + sessionId = session_id; + } else { + return ; + } + -export default function ReturnScreen() { const navigate = useNavigate(); - const [status, setStatus] = useState(null); + const [status, setStatus] = useState(""); const [customerEmail, setCustomerEmail] = useState(""); + const { + data: sessionStatus, + status: sessionStatusHookStatus, + } = useSessionStatus(sessionId); + + // update values once data is fetched useEffect(() => { - async function getSessionData() { - const queryString = window.location.search; - const urlParams = new URLSearchParams(queryString); - const sessionId = urlParams.get("session_id"); - const response = await getSessionStatus(sessionId!); - return response; + if (sessionStatusHookStatus === "success") { + setStatus(sessionStatus.status); + setCustomerEmail(sessionStatus.customer_email); } + }, [sessionStatusHookStatus, sessionStatus]); - getSessionData().then((response) => { - setStatus(response.data.status); - setCustomerEmail(response.data.customer_email); - }); - }, []); - - if (status === "open") { - return ; + if (sessionStatusHookStatus === "pending") { + return ; } - if (status === "complete") { - return ( -
-
-
-

- Payment Successful -

-
-
-
-

- Payment successful, a confirmation email will be sent to{" "} - {customerEmail}. -

-

- If you have any questions, please email{" "} - - {EmailLink} - - . -

-
+ if (sessionStatusHookStatus === "error" ){ + return + } -
- -
-
- ); - } else { - return ( - <> + if (sessionStatusHookStatus === "success") { + if (status === "open") { + return ; + } + if (status === "complete") { + return (

- Payment Failed + Payment Successful

-

- Please try again, or contact{" "} +

+ Payment successful, a confirmation email will be sent to{" "} + {customerEmail}. +

+

+ If you have any questions, please email{" "} {EmailLink} @@ -97,7 +85,9 @@ export default function ReturnScreen() {

- - ); + ); + } + } else { + } }