mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 14:38:45 +00:00
feat(Alerts): alerts for contacts
This commit is contained in:
1 parent
11af8bfb5a
commit
9846a4e1ae
4 files changed
+31
-21
No files matched your search
@@ -1,8 +0,0 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { IContactAlert } from '../../../common/typings/contact';
|
||||
import { contactsState } from './state';
|
||||
|
||||
export const useContactAlert = (): IContactAlert => {
|
||||
const [alert, setAlert] = useRecoilState(contactsState.contactAlert);
|
||||
return { alert, setAlert };
|
||||
};
|
||||
@@ -2,12 +2,12 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { contactsState } from './state';
|
||||
import { useContacts } from './useContacts';
|
||||
import { useContactAlert } from './useAlert';
|
||||
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
|
||||
export const useContactsService = () => {
|
||||
const setContacts = useSetRecoilState(contactsState.contacts);
|
||||
const setAlert = useSetRecoilState(contactsState.contactAlert);
|
||||
const { addAlert } = useSnackbar()
|
||||
useNuiEvent('CONTACTS', 'setContacts', setContacts);
|
||||
useNuiEvent('CONTACTS', 'setAlert', setAlert);
|
||||
return { useContacts, useContactAlert };
|
||||
};
|
||||
useNuiEvent('CONTACTS', 'setAlert', addAlert);
|
||||
return useContacts();
|
||||
};
|
||||
@@ -40,12 +40,12 @@ onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => {
|
||||
emitNet(events.CONTACTS_GET_CONTACTS);
|
||||
});
|
||||
|
||||
onNet(events.CONTACTS_ACTION_RESULT, (result: string) => {
|
||||
onNet(events.CONTACTS_ACTION_RESULT, (alert: any) => {
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: 'CONTACTS',
|
||||
method: 'setAlert',
|
||||
data: result,
|
||||
data: alert
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -85,9 +85,15 @@ onNet(
|
||||
const _identifier = getIdentifier(_source);
|
||||
await addContact(_identifier, number, display, avatar);
|
||||
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source);
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, 'CONTACT_ADD_SUCCESS');
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
|
||||
message: 'CONTACT_ADD_SUCCESS',
|
||||
type: 'success'
|
||||
});
|
||||
} catch (e) {
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, 'CONTACT_ADD_FAILED');
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
|
||||
message: 'CONTACT_ADD_FAILED',
|
||||
type: 'error'
|
||||
});
|
||||
contactsLogger.error(`Failed to add contact, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
@@ -106,11 +112,17 @@ onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
|
||||
emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source);
|
||||
// console.log('ffs, didd it return successful');
|
||||
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, 'CONTACT_UPDATE_SUCCESS');
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
|
||||
message: 'CONTACT_UPDATE_SUCCESS',
|
||||
type: 'success'
|
||||
});
|
||||
// console.log('UPDATED CONTACT: ', contact);
|
||||
} catch (e) {
|
||||
const _source = (global as any).source;
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, 'CONTACT_UPDATE_FAILED');
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
|
||||
message: 'CONTACT_UPDATE_FAILED',
|
||||
type: 'error'
|
||||
});
|
||||
contactsLogger.error(`Failed to update contact, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
@@ -123,11 +135,17 @@ onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
|
||||
const _identifier = await getIdentifier(_source);
|
||||
await deleteContact(contact, _identifier);
|
||||
emitNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, _source);
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, 'CONTACT_DELETE_SUCCESS');
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
|
||||
message: 'CONTACT_DELETE_SUCCESS',
|
||||
type: 'success'
|
||||
});
|
||||
} catch (e) {
|
||||
contactsLogger.error(`Failed to delete contact, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, 'CONTACT_DELETE_FAILED');
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
|
||||
message: 'CONTACT_DELETE_FAILED',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user