mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
feat(Alerts): alerts for contacts
This commit is contained in:
1 parent
11af8bfb5a
commit
9846a4e1ae
4 files changed
+30
-20
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 { useSetRecoilState } from 'recoil';
|
||||||
import { contactsState } from './state';
|
import { contactsState } from './state';
|
||||||
import { useContacts } from './useContacts';
|
import { useContacts } from './useContacts';
|
||||||
import { useContactAlert } from './useAlert';
|
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||||
|
|
||||||
export const useContactsService = () => {
|
export const useContactsService = () => {
|
||||||
const setContacts = useSetRecoilState(contactsState.contacts);
|
const setContacts = useSetRecoilState(contactsState.contacts);
|
||||||
const setAlert = useSetRecoilState(contactsState.contactAlert);
|
const { addAlert } = useSnackbar()
|
||||||
useNuiEvent('CONTACTS', 'setContacts', setContacts);
|
useNuiEvent('CONTACTS', 'setContacts', setContacts);
|
||||||
useNuiEvent('CONTACTS', 'setAlert', setAlert);
|
useNuiEvent('CONTACTS', 'setAlert', addAlert);
|
||||||
return { useContacts, useContactAlert };
|
return useContacts();
|
||||||
};
|
};
|
||||||
@@ -40,12 +40,12 @@ onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => {
|
|||||||
emitNet(events.CONTACTS_GET_CONTACTS);
|
emitNet(events.CONTACTS_GET_CONTACTS);
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(events.CONTACTS_ACTION_RESULT, (result: string) => {
|
onNet(events.CONTACTS_ACTION_RESULT, (alert: any) => {
|
||||||
SendNuiMessage(
|
SendNuiMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
app: 'CONTACTS',
|
app: 'CONTACTS',
|
||||||
method: 'setAlert',
|
method: 'setAlert',
|
||||||
data: result,
|
data: alert
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -85,9 +85,15 @@ onNet(
|
|||||||
const _identifier = getIdentifier(_source);
|
const _identifier = getIdentifier(_source);
|
||||||
await addContact(_identifier, number, display, avatar);
|
await addContact(_identifier, number, display, avatar);
|
||||||
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source);
|
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) {
|
} 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}`, {
|
contactsLogger.error(`Failed to add contact, ${e.message}`, {
|
||||||
source: _source,
|
source: _source,
|
||||||
});
|
});
|
||||||
@@ -106,11 +112,17 @@ onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
|
|||||||
emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source);
|
emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source);
|
||||||
// console.log('ffs, didd it return successful');
|
// 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);
|
// console.log('UPDATED CONTACT: ', contact);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const _source = (global as any).source;
|
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}`, {
|
contactsLogger.error(`Failed to update contact, ${e.message}`, {
|
||||||
source: _source,
|
source: _source,
|
||||||
});
|
});
|
||||||
@@ -123,11 +135,17 @@ onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
|
|||||||
const _identifier = await getIdentifier(_source);
|
const _identifier = await getIdentifier(_source);
|
||||||
await deleteContact(contact, _identifier);
|
await deleteContact(contact, _identifier);
|
||||||
emitNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, _source);
|
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) {
|
} catch (e) {
|
||||||
contactsLogger.error(`Failed to delete contact, ${e.message}`, {
|
contactsLogger.error(`Failed to delete contact, ${e.message}`, {
|
||||||
source: _source,
|
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