summaryrefslogtreecommitdiff
path: root/client/src/components/Admin.tsx
blob: ab75976d4c5d3f0a0485e1e8f856899b63529ecf (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 { useSelector } from 'react-redux';
import { selectGuests } from '../slices/auth/adminSlice';

const authenticate = () => {
  const guests = useSelector(selectGuests);
  return useMemo(() => ({ guests }), [guests]);
};

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

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

export default Rsvp;