|
| 1 | +import { FC } from 'react'; |
| 2 | +import { Box, Typography, useTheme } from '@mui/material'; |
| 3 | +import { useCustomNavigate } from '../../../../../shared/hooks/use-custom-navigate'; |
| 4 | +import A2ZButton from '../../../../../shared/components/atoms/button'; |
| 5 | +import { ROUTES_V1 } from '../../constants/routes'; |
| 6 | + |
| 7 | +interface ProtectedPlaceholderProps { |
| 8 | + onClick?: () => void; |
| 9 | + heading?: string; |
| 10 | + description?: string; |
| 11 | + buttonText?: string; |
| 12 | + showButton?: boolean; |
| 13 | +} |
| 14 | + |
| 15 | +const ProtectedPlaceholder: FC<ProtectedPlaceholderProps> = ({ |
| 16 | + heading = 'Access Denied', |
| 17 | + description = 'You do not have access to this content.', |
| 18 | + onClick, |
| 19 | + buttonText = 'Go to Home', |
| 20 | + showButton = true, |
| 21 | +}) => { |
| 22 | + const theme = useTheme(); |
| 23 | + const navigate = useCustomNavigate(); |
| 24 | + |
| 25 | + return ( |
| 26 | + <Box |
| 27 | + sx={{ |
| 28 | + display: 'flex', |
| 29 | + justifyContent: 'center', |
| 30 | + alignItems: 'center', |
| 31 | + height: '100%', |
| 32 | + width: '100%', |
| 33 | + }} |
| 34 | + > |
| 35 | + <Box |
| 36 | + sx={{ |
| 37 | + display: 'flex', |
| 38 | + justifyContent: 'center', |
| 39 | + alignItems: 'center', |
| 40 | + flexDirection: 'column', |
| 41 | + p: { xs: 3, sm: '36px 72px' }, |
| 42 | + borderRadius: 2, |
| 43 | + bgcolor: |
| 44 | + theme.palette.mode === 'dark' |
| 45 | + ? 'background.paper' |
| 46 | + : theme.palette.grey[50], |
| 47 | + boxShadow: theme.shadows[2], |
| 48 | + maxWidth: { xs: '90%', sm: 'auto' }, |
| 49 | + }} |
| 50 | + > |
| 51 | + <Typography |
| 52 | + variant="h4" |
| 53 | + component="h1" |
| 54 | + sx={{ |
| 55 | + m: 0, |
| 56 | + fontWeight: 600, |
| 57 | + color: 'text.primary', |
| 58 | + textAlign: 'center', |
| 59 | + }} |
| 60 | + > |
| 61 | + {heading} |
| 62 | + </Typography> |
| 63 | + <Typography |
| 64 | + variant="body1" |
| 65 | + component="p" |
| 66 | + sx={{ |
| 67 | + mt: 2, |
| 68 | + color: 'text.secondary', |
| 69 | + textAlign: 'center', |
| 70 | + maxWidth: 400, |
| 71 | + }} |
| 72 | + > |
| 73 | + {description} |
| 74 | + </Typography> |
| 75 | + |
| 76 | + {showButton && ( |
| 77 | + <A2ZButton |
| 78 | + variant="contained" |
| 79 | + sx={{ |
| 80 | + mt: 6, |
| 81 | + px: 3, |
| 82 | + py: 1.5, |
| 83 | + fontSize: 16, |
| 84 | + transition: 'all 0.2s ease-in-out', |
| 85 | + bgcolor: 'primary.main', |
| 86 | + color: 'primary.contrastText', |
| 87 | + '&:hover': { |
| 88 | + transform: 'scale(1.05)', |
| 89 | + bgcolor: 'primary.dark', |
| 90 | + }, |
| 91 | + }} |
| 92 | + onClick={() => { |
| 93 | + if (onClick) { |
| 94 | + onClick(); |
| 95 | + } else { |
| 96 | + navigate({ pathname: ROUTES_V1.HOME.replace('/*', '/') }); |
| 97 | + } |
| 98 | + }} |
| 99 | + > |
| 100 | + {buttonText} |
| 101 | + </A2ZButton> |
| 102 | + )} |
| 103 | + </Box> |
| 104 | + </Box> |
| 105 | + ); |
| 106 | +}; |
| 107 | + |
| 108 | +export default ProtectedPlaceholder; |
0 commit comments