Skip to content

Commit

Permalink
update snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Sep 1, 2024
1 parent f16afe1 commit c5698e9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
22 changes: 17 additions & 5 deletions src/components/shared/CustomSnackbar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Snackbar, Alert } from '@mui/material';

import { Snackbar, Alert, AlertTitle, Link, Box } from '@mui/material';
import useSnackbarStore from '../../store/useSnackbarStore';

/**
Expand All @@ -16,18 +15,31 @@ export const CustomSnackbar = (): JSX.Element => {
anchorOrigin={
options?.position || { vertical: 'bottom', horizontal: 'right' }
}
autoHideDuration={options?.duration}
autoHideDuration={options?.duration ?? 3000}
open={open}
onClose={closeSnackbar}
>
<Alert
severity={options?.severity || 'info'}
sx={{ width: '100%' }}
sx={{ width: '100%', display: 'flex', alignItems: 'center' }}
variant="filled"
onClose={closeSnackbar}
icon={options?.icon}
aria-live="assertive"
>
{message}
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<Box>
<AlertTitle>{message}</AlertTitle>
{options?.linkText && options?.linkUrl && (
<Link href={options.linkUrl} color="inherit" underline="always">
{options.linkText}
</Link>
)}
</Box>
</Box>
</Alert>
</Snackbar>
);
};

export default CustomSnackbar;
8 changes: 0 additions & 8 deletions src/pages/Dashboard/Dashboard.spec.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/pages/Dashboard/Dashboard.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/pages/Dashboard/index.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/store/useSnackbarStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ interface SnackbarOptions {
severity?: 'success' | 'error' | 'warning' | 'info';
duration?: number;
position?: SnackbarOrigin;
icon?: React.ReactNode;
linkText?: string;
linkUrl?: string;
}

const useSnackbarStore = create<SnackbarState>((set) => ({
Expand Down

0 comments on commit c5698e9

Please sign in to comment.