fix alert provider | remove alert from notes and contact

This commit is contained in:
Christopher committed 2021-02-13 13:48:05 +01:00
1 parent 9ba8bd683f
commit b4258718d8
13 files changed
+67 -175

No files matched your search

+5 -3
View File
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { AppWrapper } from '../../ui/components/AppWrapper';
import { AppContent } from '../../ui/components/AppContent';
import { AppTitle } from '../../ui/components/AppTitle';
@@ -15,7 +15,8 @@ import { useNoteDetail } from './hooks/useNoteDetail';
import useStyles from './notes.styles';
import InjectDebugData from '../../os/debug/InjectDebugData';
import { NotesAlert } from './alert/NotesAlert';
import { useSnackbar } from '../../ui/hooks/useSnackbar';
import { useTranslation } from 'react-i18next';
InjectDebugData([
{
@@ -38,9 +39,11 @@ InjectDebugData([
export const NotesApp = () => {
const { setNoteModal } = useNoteModal();
const { t } = useTranslation()
const { detail, setDetail } = useNoteDetail();
const { notes } = useNotes();
const notesApp = useApp('NOTES');
const { addAlert } = useSnackbar()
const classes = useStyles();
@@ -66,7 +69,6 @@ export const NotesApp = () => {
>
<AddIcon />
</Fab>
<NotesAlert />
</AppWrapper>
);
};
-62
View File
@@ -1,62 +0,0 @@
import React, { useState, useEffect, useCallback } from 'react'
import { Snackbar } from '@material-ui/core';
import { Alert } from '../../../ui/components/Alert';
import { AlertCategory } from '../../../common/typings/notes';
import { useTranslation } from 'react-i18next';
import { useNotesAlert } from '../hooks/useNoteAlert';
const LOCALE_PREFIX = 'APPS_';
export const NotesAlert = () => {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const { alert, setAlert } = useNotesAlert();
const [message, setMessage] = useState(null);
const [severity, setSeverity] = useState('');
const _handleClose = () => {
setOpen(false)
setAlert(null)
}
const setMessageAlert = useCallback((type: AlertCategory, severity: 'success' | 'error') => {
setMessage(t(LOCALE_PREFIX + type));
setSeverity(severity)
setOpen(true)
}, [t])
useEffect(() => {
switch (alert) {
case 'NOTES_ADD_SUCCESS':
setMessageAlert(alert, 'success');
break;
case 'NOTES_ADD_FAILED':
setMessageAlert(alert, 'error');
break;
case 'NOTES_UPDATE_SUCCESS':
setMessageAlert(alert, 'success');
break;
case 'NOTES_UPDATE_FAILED':
setMessageAlert(alert, 'error');
break;
case 'NOTES_DELETE_SUCCESS':
setMessageAlert(alert, 'success');
break;
case 'NOTES_DELETE_FAILED':
setMessageAlert(alert, 'error')
}
}, [alert, setMessageAlert])
return (
<Snackbar
style={{ width: '80%', position: 'absolute', bottom: '10%' }}
autoHideDuration={1500}
open={open}
onClose={_handleClose}
>
<Alert severity={severity} variant='filled'>
{message}
</Alert>
</Snackbar>
)
}
@@ -1,8 +0,0 @@
import { useRecoilState } from 'recoil';
import { INotesAlert } from '../../../common/typings/notes';
import { noteStates } from './state';
export const useNotesAlert = (): INotesAlert => {
const [alert, setAlert] = useRecoilState(noteStates.alert)
return { alert, setAlert }
}
@@ -1,13 +1,16 @@
import { createContext, useCallback } from 'react';
import { useSetRecoilState } from 'recoil';
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { useNotes } from './useNotes';
import { noteStates } from './state';
import { useNotesAlert } from './useNoteAlert';
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
export const useNotesService = () => {
const { addAlert } = useSnackbar()
const setNotes = useSetRecoilState(noteStates.noteItems);
const setAlert = useSetRecoilState(noteStates.alert);
useNuiEvent('NOTES', 'setNotes', setNotes);
useNuiEvent('NOTES', 'setAlert', setAlert)
return { useNotes, useNotesAlert };
useNuiEvent('NOTES', 'setAlert', addAlert)
return useNotes();
};