Commit a4348b96 authored by Bilal's avatar Bilal

Updated snackbar handling

parent 0e44734a
...@@ -21,7 +21,7 @@ const TelepayForm = () => { ...@@ -21,7 +21,7 @@ const TelepayForm = () => {
{ description: '', amount: '' }, { description: '', amount: '' },
], ],
}); });
const [snackbarOpen, setSnackbarOpen] = React.useState(false); const [errorSnackbarOpen, setErrorSnackbarOpen] = React.useState(false);
const [submitted, setSubmitted] = React.useState(false); const [submitted, setSubmitted] = React.useState(false);
const handleChange = (field, value) => { const handleChange = (field, value) => {
...@@ -69,11 +69,11 @@ const TelepayForm = () => { ...@@ -69,11 +69,11 @@ const TelepayForm = () => {
} else { } else {
const errorData = await response.json(); const errorData = await response.json();
setError(errorData.error || 'An error occurred'); setError(errorData.error || 'An error occurred');
setSnackbarOpen(true); setErrorSnackbarOpen(true);
} }
} catch (error) { } catch (error) {
setError('An error occurred while making the API request'); setError('An error occurred while making the API request');
setSnackbarOpen(true); setErrorSnackbarOpen(true);
} finally { } finally {
setSubmitted(false); setSubmitted(false);
} }
...@@ -88,37 +88,31 @@ const TelepayForm = () => { ...@@ -88,37 +88,31 @@ const TelepayForm = () => {
}); });
}; };
const handleClose = (event, reason) => {
if (reason === 'clickaway') {
return;
}
setSnackbarOpen(false);
};
const action = (
<React.Fragment>
<IconButton
size='small'
aria-label='close'
color='inherit'
onClick={handleClose}
>
<CloseOutlined fontSize='small' />
</IconButton>
</React.Fragment>
);
return ( return (
<div> <div>
<Snackbar <Snackbar
open={snackbarOpen} open={errorSnackbarOpen}
autoHideDuration={3000} autoHideDuration={3000}
onClose={handleClose} onClose={(event, reason) => {
if (reason !== 'clickaway') {
setErrorSnackbarOpen(false);
}
}}
message={error} message={error}
action={action} action={
<React.Fragment>
<IconButton
size='small'
aria-label='close'
color='inherit'
onClick={() => setErrorSnackbarOpen(false)}
>
<CloseOutlined fontSize='small' />
</IconButton>
</React.Fragment>
}
> >
<Alert onClose={handleClose} severity='error' sx={{ width: '100%' }}> <Alert onClose={() => setErrorSnackbarOpen(false)} severity='error' sx={{ width: '100%' }}>
{error} {error}
</Alert> </Alert>
</Snackbar> </Snackbar>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment