summaryrefslogtreecommitdiff
path: root/client/src/components/Rsvp.tsx
blob: 5b0ba023b8533bbe70727527951da224f28c7cb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import React from 'react';
import { useMemo } from 'react';
import { useLocation, Navigate, Outlet } from 'react-router-dom';
import { useAppSelector } from '../hooks';
import { selectGuest } from '../slices/auth/guestSlice';

const authenticate = () => {
  const guest = useAppSelector(selectGuest);
  return useMemo(() => ({ guest }), [guest]);
};

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

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

export default Rsvp;