Skip to content

Commit

Permalink
fixed no user signed in error
Browse files Browse the repository at this point in the history
  • Loading branch information
ggsawatyanon committed May 23, 2024
1 parent 3247eb6 commit 0399557
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const App = (): ReactElement => {

return (
<ThemeProvider theme={theme}>
<ModalProvider>
<ModalProvider user={user} setUser={setUser}>
<NavBar headersData={headersData} user={user} setUser={setUser} />
<div className="root">
<Switch>
Expand Down
23 changes: 21 additions & 2 deletions frontend/src/components/utils/Footer/ContactModalContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { createContext, useContext, useState, ReactNode } from 'react';
import { getUser } from '../../../utils/firebase';
import Toast from '../Toast';

interface ModalContextType {
modalOpen: boolean;
Expand Down Expand Up @@ -26,6 +28,8 @@ const useModal = (): ModalContextType => {

interface Props {
children: ReactNode;
user: firebase.User | null;
setUser: React.Dispatch<React.SetStateAction<firebase.User | null>>;
}

/**
Expand All @@ -38,10 +42,25 @@ interface Props {
* @param children – Child components that will receive access to the modal state
* @returns
*/
const ModalProvider = ({ children }: Props) => {
const ModalProvider = ({ children, user, setUser }: Props) => {
const [modalOpen, setModalOpen] = useState(false);
const toastTime = 3500;

const openModal = async () => {
let user = await getUser(true);
setUser(user);
if (!user) {
<Toast
isOpen={true}
severity="error"
message="Error: Please sign in with a Cornell email."
time={toastTime}
/>;
return;
}
setModalOpen(true);
};

const openModal = () => setModalOpen(true);
const closeModal = () => setModalOpen(false);

return (
Expand Down

0 comments on commit 0399557

Please sign in to comment.