From a54a93b724a6104213b17271fc298e37adedc1c5 Mon Sep 17 00:00:00 2001 From: Michael Hunteman Date: Fri, 20 Sep 2024 11:19:34 -0700 Subject: Use redux for updating snackbar --- client/src/components/Status.tsx | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'client/src/components/Status.tsx') diff --git a/client/src/components/Status.tsx b/client/src/components/Status.tsx index 4bb60ff..bdd7fb2 100644 --- a/client/src/components/Status.tsx +++ b/client/src/components/Status.tsx @@ -1,18 +1,28 @@ import React from 'react'; -import { Alert } from '@mui/material'; -import { isFetchBaseQueryError } from '../error'; -import type { StatusProps } from '../models'; -import type { Data } from '../error'; +import { useDispatch, useSelector } from 'react-redux'; +import { Alert, Snackbar } from '@mui/material'; +import { close, selectSnackbarState } from '../slices/snackbarSlice'; -const Status = ({ error, setOpen, type }: StatusProps) => { - return isFetchBaseQueryError(error) ? ( - setOpen(false)}> - {(error.data as Data).message} - - ) : ( - setOpen(false)}> - {`${type} login failed`} - +const Status = () => { + const dispatch = useDispatch(); + const snackbarState = useSelector(selectSnackbarState); + + const closeSnackbar = () => { + dispatch(close()); + }; + + return ( + +
+ + {snackbarState.message} + +
+
); }; -- cgit v1.2.3