From 9846a4e1ae8202c17aa739e8fb305c8ae6af8301 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 18 Feb 2021 23:20:24 +0100 Subject: [PATCH 1/2] feat(Alerts): alerts for contacts --- phone/src/apps/contacts/hooks/useAlert.ts | 8 ----- .../apps/contacts/hooks/useContactsService.ts | 10 +++---- resources/client/cl_contacts.ts | 4 +-- resources/server/sv_contacts.ts | 30 +++++++++++++++---- 4 files changed, 31 insertions(+), 21 deletions(-) delete mode 100644 phone/src/apps/contacts/hooks/useAlert.ts diff --git a/phone/src/apps/contacts/hooks/useAlert.ts b/phone/src/apps/contacts/hooks/useAlert.ts deleted file mode 100644 index b7d7ee8..0000000 --- a/phone/src/apps/contacts/hooks/useAlert.ts +++ /dev/null @@ -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 }; -}; diff --git a/phone/src/apps/contacts/hooks/useContactsService.ts b/phone/src/apps/contacts/hooks/useContactsService.ts index 82a985d..c8a3a04 100644 --- a/phone/src/apps/contacts/hooks/useContactsService.ts +++ b/phone/src/apps/contacts/hooks/useContactsService.ts @@ -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(); +}; \ No newline at end of file diff --git a/resources/client/cl_contacts.ts b/resources/client/cl_contacts.ts index 0fc8c42..c3cadc9 100644 --- a/resources/client/cl_contacts.ts +++ b/resources/client/cl_contacts.ts @@ -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 }) ); }); diff --git a/resources/server/sv_contacts.ts b/resources/server/sv_contacts.ts index df03f81..4b26060 100644 --- a/resources/server/sv_contacts.ts +++ b/resources/server/sv_contacts.ts @@ -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' + }); } }); From 6d2961ac719ec5891857365d618f6175b6fb3cff Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 19 Feb 2021 16:19:55 +0100 Subject: [PATCH 2/2] feat(Marketplace): minor alerts --- phone/src/apps/sellout/hooks/useSelloutService.ts | 6 +++++- phone/src/locale/en.json | 3 +++ resources/client/cl_sellout.ts | 14 ++++++++++++-- resources/server/sv_sellout.ts | 10 ++++++++++ resources/utils/events.ts | 4 +++- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/phone/src/apps/sellout/hooks/useSelloutService.ts b/phone/src/apps/sellout/hooks/useSelloutService.ts index cac461d..98b9094 100644 --- a/phone/src/apps/sellout/hooks/useSelloutService.ts +++ b/phone/src/apps/sellout/hooks/useSelloutService.ts @@ -2,9 +2,13 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { selloutState } from './state'; import { useListing } from './useListing'; import { useSetRecoilState } from 'recoil'; +import { useSnackbar } from '../../../ui/hooks/useSnackbar'; export const useSelloutService = () => { const setSellout = useSetRecoilState(selloutState.listing); + const { addAlert } = useSnackbar(); + + useNuiEvent('SELLOUT', 'setAlert', addAlert); useNuiEvent('SELLOUT', 'setListings', setSellout); return useListing(); -}; +}; \ No newline at end of file diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 9e8e908..c5e21aa 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -100,6 +100,9 @@ "APPS_SETTINGS_OPTION_RINGTONE": "Ringtone", "APPS_SETTINGS_OPTION_RINGTONEVOL": "Ringtone Volume", + "APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing", + "APPS_MARKETPALCE_CREATE_LISTING_FAILED": "Failed to create a new listing", + "GENERIC_SAVE": "Save", "GENERIC_UPDATE": "Update", "GENERIC_DELETE": "Delete" diff --git a/resources/client/cl_sellout.ts b/resources/client/cl_sellout.ts index 32f6609..584b7dd 100644 --- a/resources/client/cl_sellout.ts +++ b/resources/client/cl_sellout.ts @@ -12,11 +12,21 @@ onNet(events.SELLOUT_SEND_LISTING, (listing: any) => { RegisterNuiCallbackType(events.SELLOUT_ADD_LISTING); on(`__cfx_nui:${events.SELLOUT_ADD_LISTING}`, (data: any) => { - const listing = data; - emitNet(events.SELLOUT_ADD_LISTING, listing); + emitNet(events.SELLOUT_ADD_LISTING, data); setTimeout(() => { emitNet(events.SELLOUT_FETCH_LISTING); console.log('Fetched'); }, 500); }); + + +onNet(events.SELLOUT_ACTION_RESULT, (alert: { message: string, type: string }) => { + SendNuiMessage( + JSON.stringify({ + app: "SELLOUT", + method: "setAlert", + data: alert + }) + ) +}) \ No newline at end of file diff --git a/resources/server/sv_sellout.ts b/resources/server/sv_sellout.ts index c3bda7e..767ae9d 100644 --- a/resources/server/sv_sellout.ts +++ b/resources/server/sv_sellout.ts @@ -62,9 +62,19 @@ onNet(events.SELLOUT_ADD_LISTING, async (listing: Listing) => { const phoneNumber = await usePhoneNumber(_identifier); await addListing(_identifier, name, phoneNumber, listing); + + emitNet(events.SELLOUT_ACTION_RESULT, _source, { + message: 'MARKETPLACE_CREATE_LISTING_SUCCESS', + type: 'success' + }) } catch (e) { selloutLogger.error(`Failed to add listing ${e.message}`, { source: _source, }); + + emitNet(events.SELLOUT_ACTION_RESULT, _source, { + message: 'MARKETPALCE_CREATE_LISTING_FAILED', + type: 'error' + }) } }); diff --git a/resources/utils/events.ts b/resources/utils/events.ts index 3a8e52f..2cef8db 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -37,11 +37,13 @@ export default { CONTACTS_DELETE_CONTACT: 'phone:deleteContact', CONTACTS_DELETE_CONTACT_SUCCESS: 'contacts:deleteSuccess', CONTACTS_UPDATE_CONTACT_SUCCESS: 'phone:updateContactSuccess', + CONTACTS_ACTION_RESULT: 'phone:contactActionResult', // Sellout SELLOUT_ADD_LISTING: 'phone:addListing', SELLOUT_FETCH_LISTING: 'phone:fetchAllListings', SELLOUT_SEND_LISTING: 'phone:sendAllListings', + SELLOUT_ACTION_RESULT: 'phone:selloutActionResult', // BANK_ADD_TRANSFER: 'phone:addTransfer', @@ -66,6 +68,7 @@ export default { MESSAGES_FETCH_MESSAGES: 'phone:fetchMessages', MESSAGES_FETCH_MESSAGES_SUCCESS: 'phone:fetchMessagesSuccess', MESSAGES_FETCH_MESSAGES_FAILED: 'phone:fetchMessagesFailed', + MESSAGES_ACTION_RESULT: 'phone:messagesActionResult', // Notes NOTE_ADD_NOTE: 'phone:addNote', @@ -95,7 +98,6 @@ export default { CAMERA_SEND_PHOTOS: 'phone:SendPhotos', CAMERA_DELETE_PHOTO: 'photo:deletePhoto', CAMERA_DELETE_PHOTO_SUCCESS: 'phone:deletePhotoSuccess', - CONTACTS_ACTION_RESULT: 'phone:contactActionResult', // copy PHONE_USE_CLIPBOARD: 'phone:useClipboard',