summaryrefslogtreecommitdiff
path: root/src/components/Rsvp.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/Rsvp.tsx')
-rw-r--r--src/components/Rsvp.tsx41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/components/Rsvp.tsx b/src/components/Rsvp.tsx
index 858ca71..466175e 100644
--- a/src/components/Rsvp.tsx
+++ b/src/components/Rsvp.tsx
@@ -1,29 +1,30 @@
-import { useState } from 'react';
+import { useMemo } from 'react';
+import { useLocation, Navigate, Outlet } from 'react-router-dom';
+import { useSelector } from 'react-redux';
+import CssBaseline from '@mui/material/CssBaseline';
+
+import NavBar from './NavBar';
import RsvpForm from './RsvpForm';
-import GuestLogin from './GuestLogin';
-import { useGetGuestsQuery } from '../apiSlice'
+import { selectCurrentUser } from '../features/auth/authSlice';
-function Rsvp() {
- // Enter your name to RSVP; query the database
- const [loggedIn, setLoggedIn] = useState(false);
+const authenticate = () => {
+ const user = useSelector(selectCurrentUser);
+ return useMemo(() => ({ user }), [user]);
+};
- const {
- data: guests,
- isLoading,
- isSuccess,
- isError,
- error
- } = useGetGuestsQuery()
+function Rsvp() {
+ const auth = authenticate();
+ const location = useLocation();
- return (
+ return auth.user ? (
<>
- {loggedIn ? (
- <RsvpForm />
- ) : (
- <GuestLogin loggedIn={loggedIn} setLoggedIn={setLoggedIn} />
- )}
+ <CssBaseline />
+ <NavBar />
+ <Outlet />
</>
- )
+ ) : (
+ <Navigate to="/guest-login" state={{ from: location }} replace />
+ );
}
export default Rsvp;