summaryrefslogtreecommitdiff
path: root/src/components/Rsvp.tsx
blob: 104196fd7499e1976ec0cded39fcc9bf264ee0e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 { selectCurrentGuest } from '../features/auth/authSlice';

const authenticate = () => {
  const guest = useSelector(selectCurrentGuest);
  return useMemo(() => ({ guest }), [guest]);
};

function Rsvp() {
  const auth = authenticate();
  const location = useLocation();

  return auth?.guest ? (
    <>
      <CssBaseline />
      <NavBar />
      <Outlet context={auth?.guest} />
    </>
  ) : (
    <Navigate to="/guest-login" state={{ from: location }} replace />
  );
}

export default Rsvp;