-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/add alert page #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/add alert page #191
Changes from all commits
3c4b179
5076784
26b1886
912e343
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,8 @@ | |
| "buttonInvestigate": "Activer la levée de doute", | ||
| "buttonTreatAlert": "Acquitter l'alerte", | ||
| "buttonModifyAlert": "Modifier l'alerte", | ||
| "buttonShare": "Partager", | ||
| "shareLinkCopied": "Lien de l'alerte copié dans le presse-papier", | ||
| "copyText": "Copié", | ||
| "blinkingMode": { | ||
| "buttonBlinkingView": "Passer en vue clignotante", | ||
|
|
@@ -115,6 +117,12 @@ | |
| "adding": "Ajout..." | ||
| } | ||
| }, | ||
| "alertPage": { | ||
| "forbiddenTitle": "Accès refusé", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those labels aren't used. Maybe we can redirect to dedicated pages. We already have an ErrorPage |
||
| "forbiddenMessage": "Vous n'êtes pas connecté ou vous n'êtes pas autorisé à consulter cette alerte.", | ||
| "errorMessage": "Une erreur inattendue est survenue. Veuillez réessayer plus tard.", | ||
| "buttonGoHome": "Revenir à la page principale" | ||
| }, | ||
| "history": { | ||
| "title": "Historique", | ||
| "noFilterMessage": "Sélectionnez la date souhaitée", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import Box from '@mui/material/Box'; | ||
| import Grid from '@mui/material/Grid'; | ||
| import Typography from '@mui/material/Typography'; | ||
| import { useQuery, useQueryClient } from '@tanstack/react-query'; | ||
| import { useCallback, useMemo } from 'react'; | ||
| import { useNavigate, useParams } from 'react-router-dom'; | ||
|
|
||
| import { DEFAULT_ROUTE } from '@/App'; | ||
| import { AlertContainer } from '@/components/Alerts/AlertDetails/AlertContainer'; | ||
| import { Loader } from '@/components/Common/Loader'; | ||
| import { getAlertById } from '@/services/alerts'; | ||
| import { STATUS_ERROR, STATUS_LOADING, STATUS_SUCCESS } from '@/services/axios'; | ||
| import { getCameraList } from '@/services/camera'; | ||
| import { type AlertType, mapAlertTypeApiToAlertType } from '@/utils/alerts'; | ||
| import { useIsMobile } from '@/utils/useIsMobile'; | ||
| import { useTranslationPrefix } from '@/utils/useTranslationPrefix'; | ||
|
|
||
| export const AlertPage = () => { | ||
| const { alertId } = useParams<{ alertId: string }>(); | ||
| const navigate = useNavigate(); | ||
| const queryClient = useQueryClient(); | ||
| const { t } = useTranslationPrefix('alerts'); | ||
| const isMobile = useIsMobile(); | ||
|
|
||
| const alertIdNumber = Number(alertId); | ||
|
|
||
| const { status: statusAlert, data: alertData } = useQuery({ | ||
| queryKey: ['alert', alertIdNumber], | ||
| queryFn: () => getAlertById(alertIdNumber), | ||
| enabled: !isNaN(alertIdNumber), | ||
| }); | ||
|
|
||
| const { status: statusCameras, data: cameraList } = useQuery({ | ||
| queryKey: ['cameras'], | ||
| queryFn: getCameraList, | ||
| }); | ||
|
|
||
| const alertsList: AlertType[] = useMemo( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's weird to have an alerts list in a signel alert page mapListAlertApiToAlertType(alertList: AlertApi[], cameras: Camera[]) { |
||
| () => | ||
| mapAlertTypeApiToAlertType( | ||
| alertData ? [alertData] : [], | ||
| cameraList ?? [] | ||
| ), | ||
| [alertData, cameraList] | ||
| ); | ||
| const alert = alertsList[0]; | ||
|
|
||
| const invalidateAndRefreshData = useCallback(() => { | ||
| void queryClient.invalidateQueries({ queryKey: ['alert', alertIdNumber] }); | ||
| }, [queryClient, alertIdNumber]); | ||
|
|
||
| const status = useMemo(() => { | ||
| if (statusAlert === STATUS_SUCCESS && statusCameras === STATUS_SUCCESS) { | ||
| return STATUS_SUCCESS; | ||
| } | ||
| if (statusAlert === STATUS_LOADING || statusCameras === STATUS_LOADING) { | ||
| return STATUS_LOADING; | ||
| } | ||
| return STATUS_ERROR; | ||
| }, [statusAlert, statusCameras]); | ||
|
|
||
| return ( | ||
| <> | ||
| {status === STATUS_LOADING && <Loader />} | ||
| {status === STATUS_ERROR && ( | ||
| <Typography variant="body2"> | ||
| {t('errorFetchSequencesMessage')} | ||
| </Typography> | ||
| )} | ||
| {status === STATUS_SUCCESS && alertsList.length > 0 && ( | ||
| <> | ||
| {isMobile ? ( | ||
| <Box height={'100%'} overflow={'auto'}> | ||
| <AlertContainer | ||
| isLiveMode={false} | ||
| alert={alert} | ||
| resetAlert={() => void navigate(DEFAULT_ROUTE)} | ||
| invalidateAndRefreshData={invalidateAndRefreshData} | ||
| /> | ||
| </Box> | ||
| ) : ( | ||
| <Grid container height="100%"> | ||
| <Grid size={12} height={'100%'} overflow={'auto'}> | ||
| <AlertContainer | ||
| isLiveMode={false} | ||
| alert={alert} | ||
| resetAlert={() => void navigate(DEFAULT_ROUTE)} | ||
| invalidateAndRefreshData={invalidateAndRefreshData} | ||
| /> | ||
| </Grid> | ||
| </Grid> | ||
| )} | ||
| </> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snackbar is not visible (too far from the button). Maybe we ca reuse the tooltip from the button "CopyToClipboard" ?