From f1ce6bd65ef7fd57faa914f09360c6db5982e79a Mon Sep 17 00:00:00 2001 From: cqb13 Date: Mon, 11 Sep 2023 22:22:47 -0400 Subject: [PATCH] Account validation before score save --- app/page.tsx | 24 +++++++++++++++++++++++- components/misc/signUpPopup.tsx | 27 +++++++++++++++++++++++++++ components/scoring/saveScorePopup.tsx | 2 +- tsconfig.json | 1 + 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 265c197..c34068a 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -2,16 +2,22 @@ import NotificationPopup from "@/components/general/notificationPopup"; import ScoringChart from "@/components/scoring/scoringChart"; -import { useState } from "react"; +import { useState, useEffect} from "react"; import SessionOptions from "@/components/scoring/sessionOptions"; import ScoreSetupMenu from "@/components/scoring/scoreSetupMenu"; import FinalScoringStats from "@/components/scoring/finalScoringStats"; import SaveScorePopup from "@/components/scoring/saveScorePopup"; +import { useAuthContext } from "@context/authContext"; +import SignUpPopup from "@/components/misc/signUpPopup"; export default function Home() { const [setup, setSetup] = useState(true); const [finished, setFinished] = useState(false); const [savingPopup, setSavingPopup] = useState(false); + const [signedIn, setSignedIn] = useState(false); + const [signUpPopup, setSignUpPopup] = useState(false); + + const { user } = useAuthContext() as { user: any }; const [location, setLocation] = useState(""); const [distanceUnit, setDistanceUnit] = useState(""); @@ -31,6 +37,7 @@ export default function Home() { const updateSetup = (value: boolean) => setSetup(value); const updateFinished = (value: boolean) => setFinished(value); const updateSavingPopup = (value: boolean) => setSavingPopup(value); + const updateSignUpPopup = (value: boolean) => setSignUpPopup(value); const updateLocation = (value: string) => setLocation(value); const updateDistanceUnit = (value: string) => setDistanceUnit(value); @@ -52,6 +59,11 @@ export default function Home() { setBow(""); }; + useEffect(() => { + if (user) setSignedIn(true); + else setSignedIn(false); + }, [user]); + const startScoring = () => { if (!checkIfReady()) return; @@ -84,6 +96,11 @@ export default function Home() { }; const beginSaving = () => { + if (!signedIn) { + setSignUpPopup(true); + return; + } + updateSavingPopup(true); }; @@ -144,6 +161,11 @@ export default function Home() { )} + {signUpPopup ? ( + + ) : null} {savingPopup ? ( void; +}) { + const signUpProcess = () => { + updateSignUpPopup(false); + googleSignIn(); + }; + + return ( +
+
+

Sign In

+
+

You must have an account for this action

+
+
+
+
+ ); +} diff --git a/components/scoring/saveScorePopup.tsx b/components/scoring/saveScorePopup.tsx index f752896..68a3d1c 100644 --- a/components/scoring/saveScorePopup.tsx +++ b/components/scoring/saveScorePopup.tsx @@ -17,7 +17,7 @@ type SaveScorePopupProps = { note: string; }) => void; updateNotification: (value: boolean) => void; - updateNotificationType: (value: string) => void; + updateNotificationType: (value: "error" | "success") => void; updateNotificationTitle: (value: string) => void; updateNotificationMessage: (value: string) => void; }; diff --git a/tsconfig.json b/tsconfig.json index 448b6ab..efbfd88 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,6 +23,7 @@ "@components/*": ["./components/*"], "@utils/*": ["./utils/*"], "@lib/*": ["./lib/*"], + "@context/*": ["./lib/context/*"], "@hooks/*": ["./lib/hooks/*"], "@types/*": ["./types/*"], }