diff --git a/src/App.tsx b/src/App.tsx index 2100a0a..40bcfc9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,7 @@ import { useQuery } from '@tanstack/react-query' import 'bulma/css/bulma.min.css' import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom' +import './animation.css' import Home from './components/Home' import LoginPage from './components/LoginPage' import Nav from './components/Nav' @@ -12,7 +13,6 @@ import { fetchFoodRatings, useUserData } from './contexts/UserDataContext' import { images } from './data/images.json' import { tasks } from './data/tasks.json' import './main.css' -import './animation.css' import { TaskInfo } from './types/Task' function PrivateRoute({ children }: { children: JSX.Element }) { diff --git a/src/components/Error.tsx b/src/components/Error.tsx new file mode 100644 index 0000000..1a86836 --- /dev/null +++ b/src/components/Error.tsx @@ -0,0 +1,20 @@ +import { useState } from 'react' + +export default function Error({ message }: { message: string }) { + const [isVisible, setIsVisible] = useState(true) + + const handleClose = () => { + setIsVisible(false) + } + + return ( + <> + {isVisible && ( +
+
+ )} + + ) +} diff --git a/src/components/LoginPage.tsx b/src/components/LoginPage.tsx index 9aa57ac..6fc3c42 100644 --- a/src/components/LoginPage.tsx +++ b/src/components/LoginPage.tsx @@ -1,16 +1,19 @@ import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { supabase } from '../supabaseClient' +import Error from './Error' export default function LoginPage() { const [loading, setLoading] = useState(false) - const [email, setEmail] = useState('test@test') - const [password, setPassword] = useState('test') + const [error, setError] = useState(null) + const [email, setEmail] = useState('') + const [password, setPassword] = useState('') const navigate = useNavigate() const handleLogin = async (event: any) => { event.preventDefault() + setError(null) setLoading(true) const { error } = await supabase.auth.signInWithPassword({ email, @@ -18,7 +21,7 @@ export default function LoginPage() { }) if (error) { - alert(error.message) + setError(`Error logging in: ${error.message}`) } else { navigate('/') } @@ -73,6 +76,7 @@ export default function LoginPage() {

+ {error && }

{ return await supabase.from('food_ratings').insert(foodRating) }, @@ -102,6 +108,10 @@ export default function RateFoodPage() { )} + {isFetchFoodRatingsError && ( + + )} + {isRecordRatingError && } )}