From 9846a4e1ae8202c17aa739e8fb305c8ae6af8301 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 18 Feb 2021 23:20:24 +0100 Subject: [PATCH 01/15] 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 02/15] 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', From 283832f17e3498dc6881861db41054b8c986cff6 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 18 Feb 2021 23:20:24 +0100 Subject: [PATCH 03/15] 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 5244ff3a57f2192780b1879aa6b0ccd791a126e5 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 19 Feb 2021 16:19:55 +0100 Subject: [PATCH 04/15] 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 0c39a35..0fc351f 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -101,6 +101,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', From e14bb5701ac047304c9bac3cfebe10fad3d00dad Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 19 Feb 2021 21:19:00 +0100 Subject: [PATCH 05/15] feat(Twitter): Remove success on create | useSnackbar --- .../apps/twitter/hooks/useTwitterService.ts | 26 +++++-------------- phone/src/common/typings/alerts.ts | 4 +++ resources/client/cl_twitter.ts | 9 ++++--- resources/server/sv_twitter.ts | 17 ++++++++---- 4 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 phone/src/common/typings/alerts.ts diff --git a/phone/src/apps/twitter/hooks/useTwitterService.ts b/phone/src/apps/twitter/hooks/useTwitterService.ts index d94a7d0..0921f4f 100644 --- a/phone/src/apps/twitter/hooks/useTwitterService.ts +++ b/phone/src/apps/twitter/hooks/useTwitterService.ts @@ -9,6 +9,7 @@ import { useNotifications } from '../../../os/notifications/hooks/useNotificatio import { useApp } from '../../../os/apps/hooks/useApps'; import { useTranslation } from 'react-i18next'; import { useCallback } from 'react'; +import { useSnackbar } from '../../../ui/hooks/useSnackbar'; /** * Perform all necessary processing/transforms from the raw database @@ -34,6 +35,7 @@ function processTweet(tweet) { export const useTwitterService = () => { const { t } = useTranslation(); const { addNotification } = useNotifications(); + const { addAlert } = useSnackbar() const { icon, notificationIcon } = useApp('TWITTER'); const setNotification = useCallback( @@ -53,25 +55,11 @@ export const useTwitterService = () => { const setUpdateProfileLoading = useSetRecoilState( twitterState.updateProfileLoading ); - const setUpdateProfileSuccess = useSetRecoilState( - twitterState.updateProfileSuccess - ); + + const setTweets = useSetRecoilState(twitterState.tweets); const setFilteredTweets = useSetRecoilState(twitterState.filteredTweets); const setCreateLoading = useSetRecoilState(twitterState.createTweetLoading); - const setCreateSuccess = useSetRecoilState( - twitterState.createTweetSuccessful - ); - - const _setUpdateProfileSuccess = (isSuccessful) => { - setUpdateProfileSuccess(isSuccessful); - setUpdateProfileLoading(false); // on any result we should set loading to false - }; - - const _setCreateSuccess = (isSuccessful) => { - setCreateSuccess(isSuccessful); - setCreateLoading(false); - }; const _setTweets = (tweets) => { setTweets(tweets.map(processTweet)); @@ -82,10 +70,10 @@ export const useTwitterService = () => { useNuiEvent(APP_TWITTER, 'getOrCreateTwitterProfile', setProfile); useNuiEvent(APP_TWITTER, 'updateProfileLoading', setUpdateProfileLoading); - useNuiEvent(APP_TWITTER, 'updateProfileResult', _setUpdateProfileSuccess); + useNuiEvent(APP_TWITTER, 'updateProfileResult', addAlert); useNuiEvent(APP_TWITTER, 'fetchTweets', _setTweets); useNuiEvent(APP_TWITTER, 'fetchTweetsFiltered', _setFilteredTweets); useNuiEvent(APP_TWITTER, 'createTweetLoading', setCreateLoading); - useNuiEvent(APP_TWITTER, 'createTweetResult', _setCreateSuccess); + useNuiEvent(APP_TWITTER, 'createTweetResult', addAlert); useNuiEvent(APP_TWITTER, 'createTweetBroadcast', setNotification); -}; +}; \ No newline at end of file diff --git a/phone/src/common/typings/alerts.ts b/phone/src/common/typings/alerts.ts new file mode 100644 index 0000000..067b731 --- /dev/null +++ b/phone/src/common/typings/alerts.ts @@ -0,0 +1,4 @@ +export interface IAlertProps { + message: string; + type: 'success' | 'error'; +} \ No newline at end of file diff --git a/resources/client/cl_twitter.ts b/resources/client/cl_twitter.ts index 4da7527..734969a 100644 --- a/resources/client/cl_twitter.ts +++ b/resources/client/cl_twitter.ts @@ -1,5 +1,6 @@ import events from '../utils/events'; import { sendTwitterMessage } from '../utils/messages'; +import { IAlertProps } from '../../phone/src/common/typings/alerts'; /** * Twitter get or create profile @@ -26,8 +27,8 @@ on(`__cfx_nui:${events.TWITTER_UPDATE_PROFILE}`, (data: string) => { emitNet(events.TWITTER_UPDATE_PROFILE, data); }); -onNet(events.TWITTER_UPDATE_PROFILE_RESULT, (result: boolean) => { - sendTwitterMessage(events.TWITTER_UPDATE_PROFILE_RESULT, result); +onNet(events.TWITTER_UPDATE_PROFILE_RESULT, (alert: IAlertProps) => { + sendTwitterMessage(events.TWITTER_UPDATE_PROFILE_RESULT, alert); emitNet(events.TWITTER_GET_OR_CREATE_PROFILE); }); @@ -75,8 +76,8 @@ on(`__cfx_nui:${events.TWITTER_CREATE_TWEET}`, (data: string) => { emitNet(events.TWITTER_CREATE_TWEET, data); }); -onNet(events.TWITTER_CREATE_TWEET_RESULT, (result: boolean) => { - sendTwitterMessage(events.TWITTER_CREATE_TWEET_RESULT, result); +onNet(events.TWITTER_CREATE_TWEET_RESULT, (alert: IAlertProps) => { + sendTwitterMessage(events.TWITTER_CREATE_TWEET_RESULT, alert); emitNet(events.TWITTER_FETCH_TWEETS); }); diff --git a/resources/server/sv_twitter.ts b/resources/server/sv_twitter.ts index b1462b0..5aa0d9e 100644 --- a/resources/server/sv_twitter.ts +++ b/resources/server/sv_twitter.ts @@ -311,12 +311,18 @@ onNet(events.TWITTER_UPDATE_PROFILE, async (profile: Profile) => { try { const identifier = getIdentifier(_source); await updateProfile(identifier, profile); - emitNet(events.TWITTER_UPDATE_PROFILE_RESULT, _source, true); + emitNet(events.TWITTER_UPDATE_PROFILE_RESULT, _source, { + message: 'TWITTER_EDIT_PROFILE_SUCCESS', + type: 'success' + }); } catch (e) { twitterLogger.error(`Failed to update twitter profile: ${e.message}`, { source: _source, }); - emitNet(events.TWITTER_UPDATE_PROFILE_RESULT, _source, false); + emitNet(events.TWITTER_UPDATE_PROFILE_RESULT, _source, { + message: 'TWITTER_EDIT_PROFILE_FAILURE', + type: 'error' + }); } }); @@ -355,14 +361,15 @@ onNet(events.TWITTER_CREATE_TWEET, async (tweet: Tweet) => { try { const identifier = getIdentifier(_source); const createdTweet = await createTweet(identifier, tweet); - - emitNet(events.TWITTER_CREATE_TWEET_RESULT, _source, true); emitNet(events.TWITTER_CREATE_TWEET_BROADCAST, -1, createdTweet); } catch (e) { twitterLogger.error(`Create tweet failed, ${e.message}`, { source: _source, }); - emitNet(events.TWITTER_CREATE_TWEET_RESULT, _source, false); + emitNet(events.TWITTER_CREATE_TWEET_RESULT, _source, { + message: 'TWITTER_CREATE_FAILED', + type: 'error' + }); } }); From 767402a6b2217dc40edf37e83b6865dff15a40e0 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 21 Feb 2021 17:29:06 +0100 Subject: [PATCH 06/15] feat(alerts): useSnackbar for twitter --- .../apps/twitter/components/TwitterApp.tsx | 2 - .../twitter/components/alerts/AlertBar.tsx | 66 ------------------- 2 files changed, 68 deletions(-) delete mode 100644 phone/src/apps/twitter/components/alerts/AlertBar.tsx diff --git a/phone/src/apps/twitter/components/TwitterApp.tsx b/phone/src/apps/twitter/components/TwitterApp.tsx index 0547669..7b0239b 100644 --- a/phone/src/apps/twitter/components/TwitterApp.tsx +++ b/phone/src/apps/twitter/components/TwitterApp.tsx @@ -12,7 +12,6 @@ import TweetButton from './buttons/TweetButton'; import TwitterTitle from './TwitterTitle'; import BottomNavigation from './BottomNavigation'; import TwitterProfile from './profile/Profile'; -import AlertBar from './alerts/AlertBar'; import TwitterSearch from './TwitterSearch'; import './twitter.css'; @@ -178,7 +177,6 @@ export const TwitterApp = () => { )} {showTweetButton && } - {!promptProfileName && ( ({ - root: { - width: '100%', - bottom: '60px', - }, -})); - -const ALERT_TIMEOUT = 4000; - -export default function AlertBar() { - const classes = useStyles(); - const { t } = useTranslation(); - const { updateProfileSuccessful, setUpdateProfileSuccessful } = useProfile(); - const { createTweetSuccessful, setCreateTweetSuccessful } = useTweetStatus(); - const [severity, setSeverity] = useState(null); - const [open, setOpen] = useState(false); - const [message, setMessage] = useState(null); - - const handleClose = () => { - setOpen(false); - setUpdateProfileSuccessful(null); - setCreateTweetSuccessful(null); - }; - - useEffect(() => { - if (createTweetSuccessful === true) { - setOpen(true); - setSeverity('success'); - setMessage(t('APPS_TWITTER_CREATE_SUCCESS')); - } else if (createTweetSuccessful === false) { - setOpen(true); - setSeverity('error'); - setMessage(t('APPS_TWITTER_CREATE_FAILED')); - } else if (updateProfileSuccessful === true) { - setOpen(true); - setSeverity('success'); - setMessage(t('APPS_TWITTER_EDIT_PROFILE_SUCCESS')); - } else if (updateProfileSuccessful === false) { - setOpen(true); - setSeverity('error'); - setMessage(t('APPS_TWITTER_EDIT_PROFILE_FAILURE')); - } - }, [updateProfileSuccessful, createTweetSuccessful, t]); - - return ( - - - {message} - - - ); -} From a9ba633241c92afa2450bbc2c8a813cc8f8f2b01 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 26 Feb 2021 12:00:46 +0100 Subject: [PATCH 07/15] tweak(phone): remove bank & twitter notification components --- .../notification/BankNotification.tsx | 48 ---------- .../notification/notification.style.ts | 43 --------- .../notification/TwitterNotification.test.tsx | 47 ---------- .../notification/TwitterNotification.tsx | 88 ------------------- phone/src/index.tsx | 2 - 5 files changed, 228 deletions(-) delete mode 100644 phone/src/apps/bank/components/notification/BankNotification.tsx delete mode 100644 phone/src/apps/bank/components/notification/notification.style.ts delete mode 100644 phone/src/apps/twitter/components/notification/TwitterNotification.test.tsx delete mode 100644 phone/src/apps/twitter/components/notification/TwitterNotification.tsx diff --git a/phone/src/apps/bank/components/notification/BankNotification.tsx b/phone/src/apps/bank/components/notification/BankNotification.tsx deleted file mode 100644 index 410f995..0000000 --- a/phone/src/apps/bank/components/notification/BankNotification.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import Notification from '../../../../ui/components/Notification'; -import { usePhone } from '../../../../os/phone/hooks/usePhone'; -import { useTranslation } from 'react-i18next'; -import useStyles from './notification.style'; -import { useBankNotification } from '../../hooks/useBankNotification'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faWonSign } from '@fortawesome/free-solid-svg-icons'; - -export const BankNotification = () => { - const { notification } = useBankNotification(); - const classes = useStyles(); - const { t } = useTranslation(); - const [visible, setVisible] = useState(false); - const { config } = usePhone(); - - useEffect(() => { - if (notification && notification.id) { - setVisible(true); - } - }, [notification]); - - if (!config?.bank.showNotifications || !notification) return null; - - return ( - setVisible(false)} - > -
-
-
-
- -
-
{notification.type}
-
-
{t('APPS_BANK_TIME_JUST_NOW')}
-
-
- {notification.source} sent you ${notification.transferAmount}.{' '} -

{notification.message} -
-
-
- ); -}; diff --git a/phone/src/apps/bank/components/notification/notification.style.ts b/phone/src/apps/bank/components/notification/notification.style.ts deleted file mode 100644 index b1c0254..0000000 --- a/phone/src/apps/bank/components/notification/notification.style.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { makeStyles, createStyles, Theme } from '@material-ui/core/styles'; - -const useStyles = makeStyles((theme: Theme) => - createStyles({ - content: { - padding: theme.spacing(2), - overflowY: 'hidden', - }, - title: { - display: 'flex', - flexFlow: 'row nowrap', - justifyContent: 'space-between', - alignItems: 'center', - }, - titleLeft: { - display: 'flex', - flexFlow: 'row nowrap', - justifyContent: 'flex-start', - alignItems: 'center', - }, - icon: { - marginTop: '3px', - marginRight: '5px', - }, - heading: { - marginBottom: '3px', - }, - justNow: { - fontSize: '18px', - fontStyle: 'italic', - paddingRight: '3px', - }, - message: { - fontSize: '16px', - overflow: 'hidden', - display: '-webkit-box', - WebkitLineClamp: 2, - WebkitBoxOrient: 'vertical', - }, - }) -); - -export default useStyles; diff --git a/phone/src/apps/twitter/components/notification/TwitterNotification.test.tsx b/phone/src/apps/twitter/components/notification/TwitterNotification.test.tsx deleted file mode 100644 index 958af69..0000000 --- a/phone/src/apps/twitter/components/notification/TwitterNotification.test.tsx +++ /dev/null @@ -1,47 +0,0 @@ -import React from 'react'; -import { shallow } from 'enzyme'; -import TwitterNotification from './TwitterNotification'; - -jest.mock('react-i18next', () => ({ - useTranslation: () => ({ t: (key) => key }), -})); - -jest.mock('../../../../os/phone/hooks/usePhone', () => ({ - usePhone: jest.fn().mockReturnValue({ - config: { - twitter: { - showNotifications: true, - }, - }, - }), -})); - -jest.mock('../../hooks/useTwitterNotification', () => ({ - useTwitterNotification: jest.fn().mockReturnValue({ - notification: { - profile_name: 'test', - message: 'test message', - }, - }), -})); - -describe('TwitterNotification', () => { - let wrapper; - - beforeEach(() => { - wrapper = shallow(); - }); - it('renders', () => { - expect(wrapper).toBeDefined(); - }); - - it('renders profile name', () => { - expect(wrapper.find('.makeStyles-profileName-5').text()).toEqual('@test'); - }); - - it('renders message', () => { - expect(wrapper.find('.makeStyles-message-7').text()).toEqual( - 'test message' - ); - }); -}); diff --git a/phone/src/apps/twitter/components/notification/TwitterNotification.tsx b/phone/src/apps/twitter/components/notification/TwitterNotification.tsx deleted file mode 100644 index 14d7e31..0000000 --- a/phone/src/apps/twitter/components/notification/TwitterNotification.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { makeStyles, createStyles, Theme } from '@material-ui/core/styles'; -import TwitterIcon from '@material-ui/icons/Twitter'; -import { useTwitterNotification } from '../../hooks/useTwitterNotification'; -import Notification from '../../../../ui/components/Notification'; -import { usePhone } from '../../../../os/phone/hooks/usePhone'; - -const useStyles = makeStyles((theme: Theme) => - createStyles({ - content: { - padding: theme.spacing(2), - overflowY: 'hidden', - }, - title: { - display: 'flex', - flexFlow: 'row nowrap', - justifyContent: 'space-between', - alignItems: 'center', - }, - titleLeft: { - display: 'flex', - flexFlow: 'row nowrap', - justifyContent: 'flex-start', - alignItems: 'center', - }, - icon: { - marginTop: '3px', - marginRight: '5px', - }, - profileName: { - marginBottom: '3px', - }, - justNow: { - fontSize: '18px', - fontStyle: 'italic', - paddingRight: '3px', - }, - message: { - fontSize: '16px', - overflow: 'hidden', - display: '-webkit-box', - WebkitLineClamp: 2, - WebkitBoxOrient: 'vertical', - }, - }) -); - -function TwitterNotification() { - const classes = useStyles(); - const { t } = useTranslation(); - const [visible, setVisible] = useState(false); - const { notification } = useTwitterNotification(); - const { config } = usePhone(); - - useEffect(() => { - if (notification && notification.id) { - setVisible(true); - } - }, [notification]); - - if (!config?.twitter.showNotifications || !notification) return null; - - const profileName = `@${notification.profile_name?.trim()}`; - - return ( - setVisible(false)} - > -
-
-
-
- -
-
{profileName}
-
-
{t('APPS_TWITTER_JUST_NOW')}
-
-
{notification.message}
-
-
- ); -} - -export default TwitterNotification; diff --git a/phone/src/index.tsx b/phone/src/index.tsx index 1834931..101048a 100644 --- a/phone/src/index.tsx +++ b/phone/src/index.tsx @@ -29,8 +29,6 @@ if (PhoneConfig.SentryErrorMetrics) { ReactDOM.render( - - From cea0bd653b7e777e2a665d31398369e82c1f6ce3 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 26 Feb 2021 12:08:04 +0100 Subject: [PATCH 08/15] fix(phone): remove unused variables --- phone/src/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/phone/src/index.tsx b/phone/src/index.tsx index 101048a..b771a77 100644 --- a/phone/src/index.tsx +++ b/phone/src/index.tsx @@ -7,8 +7,6 @@ import * as Sentry from '@sentry/react'; import { Integrations } from '@sentry/tracing'; import './main.css'; import Phone from './Phone'; -import TwitterNotification from './apps/twitter/components/notification/TwitterNotification'; -import { BankNotification } from './apps/bank/components/notification/BankNotification'; import PhoneConfig from './config/default.json'; import SnackbarProvider from './ui/providers/SnackbarProvider'; import { NotificationsProvider } from './os/notifications/providers/NotificationsProvider'; From 1afca13862752c188bd5b549631def60e07a40a2 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 26 Feb 2021 12:10:47 +0100 Subject: [PATCH 09/15] feat(phone/bank): remove alert component --- phone/src/apps/bank/components/BankApp.tsx | 2 - .../src/apps/bank/components/alert/Alert.tsx | 8 ---- .../apps/bank/components/alert/BankAlert.tsx | 43 ------------------- 3 files changed, 53 deletions(-) delete mode 100644 phone/src/apps/bank/components/alert/Alert.tsx delete mode 100644 phone/src/apps/bank/components/alert/BankAlert.tsx diff --git a/phone/src/apps/bank/components/BankApp.tsx b/phone/src/apps/bank/components/BankApp.tsx index 01fa233..626fb19 100644 --- a/phone/src/apps/bank/components/BankApp.tsx +++ b/phone/src/apps/bank/components/BankApp.tsx @@ -14,7 +14,6 @@ import { NavigationBar } from './navigation/NavigationBar'; import { BankHome } from './home/BankHome'; import { BankAccount } from './account/BankAccount'; import { TransactionList } from './transactions/TransactionList'; -import { BankAlert } from './alert/BankAlert'; import InjectDebugData from '../../../os/debug/InjectDebugData'; InjectDebugData([ @@ -110,7 +109,6 @@ export const BankApp = () => { - diff --git a/phone/src/apps/bank/components/alert/Alert.tsx b/phone/src/apps/bank/components/alert/Alert.tsx deleted file mode 100644 index 103e28b..0000000 --- a/phone/src/apps/bank/components/alert/Alert.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import React from 'react'; -import MuiAlert from '@material-ui/lab/Alert'; - -export function Alert(props) { - return ; -} - -export default Alert; diff --git a/phone/src/apps/bank/components/alert/BankAlert.tsx b/phone/src/apps/bank/components/alert/BankAlert.tsx deleted file mode 100644 index eb535c4..0000000 --- a/phone/src/apps/bank/components/alert/BankAlert.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import { useBankAlert } from '../../hooks/useBankAlert'; -import Snackbar from '@material-ui/core/Snackbar'; -import Alert from './Alert'; -import { useTranslation } from 'react-i18next'; - -export const BankAlert = () => { - const { t } = useTranslation(); - const [open, setOpen] = useState(false); - const { bankAlert, setBankAlert } = useBankAlert(); - const [message, setMessage] = useState(null); - const [severity, setSeverity] = useState(''); - - const _handleClose = () => { - setOpen(false); - setBankAlert(null); - }; - - useEffect(() => { - if (bankAlert === true) { - setOpen(true); - setMessage(t('APPS_BANK_ALERT_TRANSFER_SUCCESS')); - setSeverity('success'); - } else if (bankAlert === false) { - setOpen(true); - setMessage(t('APPS_BANK_ALERT_TRANSFER_FAILURE')); - setSeverity('error'); - } - }, [bankAlert, t]); - - return ( - - - {message} - - - ); -}; From 47218e63f5a803be09e70b193816ea27d9c20b23 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 26 Feb 2021 12:48:27 +0100 Subject: [PATCH 10/15] feat(phone|resources/bank): useSnackbar for alert --- phone/src/apps/bank/hooks/useBankService.ts | 7 +++---- resources/client/cl_bank.ts | 5 +++-- resources/server/sv_bank.ts | 22 ++++++++++++++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/phone/src/apps/bank/hooks/useBankService.ts b/phone/src/apps/bank/hooks/useBankService.ts index 710ef91..742a556 100644 --- a/phone/src/apps/bank/hooks/useBankService.ts +++ b/phone/src/apps/bank/hooks/useBankService.ts @@ -5,18 +5,17 @@ import { useCredentials } from './useCredentials'; import { useBankAlert } from './useBankAlert'; import { useSetRecoilState } from 'recoil'; import { useBankNotification } from './useBankNotification'; +import { useSnackbar } from '../../../ui/hooks/useSnackbar'; export const useBankService = () => { const setTransaction = useSetRecoilState(bankState.transactions); const setCredentials = useSetRecoilState(bankState.bankCredentials); - const setAlertMessage = useSetRecoilState(bankState.transferSuccessful); const setNotification = useSetRecoilState(bankState.notification); - - /// + const { addAlert } = useSnackbar() useNuiEvent('BANK', 'setTransaction', setTransaction); useNuiEvent('BANK', 'setCredentials', setCredentials); - useNuiEvent('BANK', 'setAlert', setAlertMessage); + useNuiEvent('BANK', 'setAlert', addAlert); useNuiEvent('BANK', 'setNotification', setNotification); return { useTransactions, useCredentials, useBankAlert, useBankNotification }; }; diff --git a/resources/client/cl_bank.ts b/resources/client/cl_bank.ts index 3bf7d6f..07e4592 100644 --- a/resources/client/cl_bank.ts +++ b/resources/client/cl_bank.ts @@ -1,3 +1,4 @@ +import { IAlertProps } from '../../phone/src/common/typings/alerts'; import events from '../utils/events'; onNet(events.BANK_SEND_TRANSFERS, (transfer: any) => { @@ -30,12 +31,12 @@ onNet(events.BANK_ADD_TRANSFER_SUCCESS, () => { emitNet(events.BANK_FETCH_TRANSACTIONS); }); -onNet(events.BANK_TRANSACTION_ALERT, (bool: boolean) => { +onNet(events.BANK_TRANSACTION_ALERT, (result: IAlertProps) => { SendNuiMessage( JSON.stringify({ app: 'BANK', method: 'setAlert', - data: bool, + data: result, }) ); }); diff --git a/resources/server/sv_bank.ts b/resources/server/sv_bank.ts index 972b46d..480e427 100644 --- a/resources/server/sv_bank.ts +++ b/resources/server/sv_bank.ts @@ -103,14 +103,30 @@ onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => { const xTarget = ESX.GetPlayerFromId(transfer.targetID); try { const _identifier = getIdentifier(_source); - const transferNotify = await addTransfer(_identifier, transfer); - emitNet(events.BANK_TRANSACTION_NOTIFICATION, xTarget, transferNotify); + await addTransfer(_identifier, transfer); + + // we need to create a notification for bank. that's why i have commented out. + // as well as creating a check if the player has enough money etc.... + + //emitNet(events.BANK_TRANSACTION_NOTIFICATION, xTarget, transferNotify); + emitNet(events.BANK_ADD_TRANSFER_SUCCESS, _source); + emitNet(events.BANK_TRANSACTION_ALERT, _source, + { + message: 'BANK_ALERT_TRANSFER_SUCCESS', + type: 'success' + } + ); } catch (e) { bankLogger.error(`Failed to add transaction, ${e.message}`, { source: _source, }); - emitNet(events.BANK_TRANSACTION_ALERT, _source, false); + emitNet(events.BANK_TRANSACTION_ALERT, _source, + { + message: 'APPS_BANK_ALERT_TRANSFER_FAILURE', + type: 'error' + } + ); } }); From f0305e3bb2ef12e3ead593bb48be9a9354d102a1 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 26 Feb 2021 14:07:23 +0100 Subject: [PATCH 11/15] remove(phone/bank): remove unused hooks --- phone/src/apps/bank/hooks/state.ts | 4 ---- phone/src/apps/bank/hooks/useBankAlert.ts | 9 --------- 2 files changed, 13 deletions(-) delete mode 100644 phone/src/apps/bank/hooks/useBankAlert.ts diff --git a/phone/src/apps/bank/hooks/state.ts b/phone/src/apps/bank/hooks/state.ts index b89443c..0715f52 100644 --- a/phone/src/apps/bank/hooks/state.ts +++ b/phone/src/apps/bank/hooks/state.ts @@ -9,10 +9,6 @@ export const bankState = { key: 'modalVisibility', default: false, }), - transferSuccessful: atom({ - key: 'bankAlert', - default: null, - }), bankCredentials: atom({ key: 'bankCredentails', default: null, diff --git a/phone/src/apps/bank/hooks/useBankAlert.ts b/phone/src/apps/bank/hooks/useBankAlert.ts deleted file mode 100644 index f25d33b..0000000 --- a/phone/src/apps/bank/hooks/useBankAlert.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { useRecoilState } from 'recoil'; -import { bankState } from './state'; - -export const useBankAlert = (): any => { - const [bankAlert, setBankAlert] = useRecoilState( - bankState.transferSuccessful - ); - return { bankAlert, setBankAlert }; -}; From 796548d9d55600ec216ed23d90509d382d750d29 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 26 Feb 2021 19:52:36 +0100 Subject: [PATCH 12/15] remove more unused variables :( --- phone/src/apps/bank/hooks/useBankService.ts | 3 +-- phone/src/apps/contacts/hooks/state.ts | 6 +----- phone/src/apps/messages/hooks/useMessageService.ts | 3 +++ phone/src/apps/notes/hooks/state.ts | 4 ---- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/phone/src/apps/bank/hooks/useBankService.ts b/phone/src/apps/bank/hooks/useBankService.ts index 742a556..19841ae 100644 --- a/phone/src/apps/bank/hooks/useBankService.ts +++ b/phone/src/apps/bank/hooks/useBankService.ts @@ -2,7 +2,6 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { bankState } from './state'; import { useTransactions } from './useTransactions'; import { useCredentials } from './useCredentials'; -import { useBankAlert } from './useBankAlert'; import { useSetRecoilState } from 'recoil'; import { useBankNotification } from './useBankNotification'; import { useSnackbar } from '../../../ui/hooks/useSnackbar'; @@ -17,5 +16,5 @@ export const useBankService = () => { useNuiEvent('BANK', 'setCredentials', setCredentials); useNuiEvent('BANK', 'setAlert', addAlert); useNuiEvent('BANK', 'setNotification', setNotification); - return { useTransactions, useCredentials, useBankAlert, useBankNotification }; + return { useTransactions, useCredentials, useBankNotification }; }; diff --git a/phone/src/apps/contacts/hooks/state.ts b/phone/src/apps/contacts/hooks/state.ts index e8ed8f8..9d16e4e 100644 --- a/phone/src/apps/contacts/hooks/state.ts +++ b/phone/src/apps/contacts/hooks/state.ts @@ -20,9 +20,5 @@ export const contactsState = { contactDetail: atom({ key: 'contactDetail', default: null, - }), - contactAlert: atom({ - key: 'contactAlert', - default: null, - }), + }) }; diff --git a/phone/src/apps/messages/hooks/useMessageService.ts b/phone/src/apps/messages/hooks/useMessageService.ts index 37ac1a3..5532a3f 100644 --- a/phone/src/apps/messages/hooks/useMessageService.ts +++ b/phone/src/apps/messages/hooks/useMessageService.ts @@ -1,6 +1,7 @@ import { useSetRecoilState } from 'recoil'; import { messageState } from './state'; import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; +import { useSnackbar } from '../../../ui/hooks/useSnackbar'; export const useMessagesService = () => { const setMessageGroups = useSetRecoilState(messageState.messageGroups); @@ -8,6 +9,7 @@ export const useMessagesService = () => { const setCreateMessageGroupResult = useSetRecoilState( messageState.createMessageGroupResult ); + const { addAlert } = useSnackbar() useNuiEvent('MESSAGES', 'phone:fetchMessageGroupsSuccess', setMessageGroups); useNuiEvent('MESSAGES', 'phone:fetchMessagesSuccess', setMessages); @@ -21,4 +23,5 @@ export const useMessagesService = () => { 'phone:createMessageGroupFailed', setCreateMessageGroupResult ); + useNuiEvent('MESSAGES', 'setAlert', addAlert); }; diff --git a/phone/src/apps/notes/hooks/state.ts b/phone/src/apps/notes/hooks/state.ts index b5c0ea7..b01b7ba 100644 --- a/phone/src/apps/notes/hooks/state.ts +++ b/phone/src/apps/notes/hooks/state.ts @@ -12,9 +12,5 @@ export const noteStates = { noteDetail: atom({ key: 'noteDetail', default: null, - }), - alert: atom({ - key: 'notesAlert', - default: null }) }; From ec913fbef439fa0f9ce3fc9d5389475ebebe792d Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 28 Feb 2021 01:35:02 +0100 Subject: [PATCH 13/15] remove(phone/messages): remove alerts components --- .../src/apps/messages/components/AlertBar.tsx | 75 ------------------- phone/src/apps/messages/hooks/useAlerts.ts | 16 ---- resources/server/sv_messages.ts | 55 +++++++++++--- 3 files changed, 45 insertions(+), 101 deletions(-) delete mode 100644 phone/src/apps/messages/components/AlertBar.tsx delete mode 100644 phone/src/apps/messages/hooks/useAlerts.ts diff --git a/phone/src/apps/messages/components/AlertBar.tsx b/phone/src/apps/messages/components/AlertBar.tsx deleted file mode 100644 index 415cb78..0000000 --- a/phone/src/apps/messages/components/AlertBar.tsx +++ /dev/null @@ -1,75 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { Snackbar } from '@material-ui/core'; -import { makeStyles } from '@material-ui/core/styles'; - -import useAlerts from '../hooks/useAlerts'; -import Alert from '../../../ui/components/Alert'; - -const useStyles = makeStyles(() => ({ - root: { - width: '100%', - bottom: '60px', - position: 'absolute', - }, -})); - -const ALERT_TIMEOUT = 6000; - -export default function AlertBar() { - const classes = useStyles(); - const { t } = useTranslation(); - const { createMessageGroupResult } = useAlerts(); - const [severity, setSeverity] = useState(null); - const [open, setOpen] = useState(false); - const [message, setMessage] = useState(null); - const [alert, setAlert] = useState(null); - - const handleClose = () => { - setOpen(false); - setAlert(null); - }; - - useEffect(() => { - if (createMessageGroupResult) { - setAlert(createMessageGroupResult); - } - }, [createMessageGroupResult]); - - useEffect(() => { - if (!alert) return; - - const { error, phoneNumber, duplicate, mine } = alert; - if (error && phoneNumber) { - const error = `${t('APPS_MESSAGES_INVALID_PHONE_NUMBER')}${phoneNumber}`; - setOpen(true); - setSeverity('error'); - setMessage(error); - } else if (error && duplicate) { - setOpen(true); - setSeverity('error'); - setMessage(t('APPS_MESSAGES_MESSAGE_GROUP_DUPLICATE')); - } else if (error && mine) { - setOpen(true); - setSeverity('error'); - setMessage(t('APPS_MESSAGES_MESSAGE_GROUP_CREATE_MINE')); - } else if (error) { - setOpen(true); - setSeverity('error'); - setMessage(t('APPS_MESSAGES_MESSAGE_GROUP_CREATE_FAILED')); - } - }, [alert, t]); - - return ( - - - {message} - - - ); -} diff --git a/phone/src/apps/messages/hooks/useAlerts.ts b/phone/src/apps/messages/hooks/useAlerts.ts deleted file mode 100644 index 9e802f0..0000000 --- a/phone/src/apps/messages/hooks/useAlerts.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { useRecoilValue } from 'recoil'; -import { CreateMessageGroupResult } from '../../../common/typings/messages'; - -import { messageState } from './state'; - -interface IUseAlerts { - createMessageGroupResult: CreateMessageGroupResult | null; -} - -export default (): IUseAlerts => { - const createMessageGroupResult = useRecoilValue( - messageState.createMessageGroupResult - ); - - return { createMessageGroupResult }; -}; diff --git a/resources/server/sv_messages.ts b/resources/server/sv_messages.ts index 496939f..e22026c 100644 --- a/resources/server/sv_messages.ts +++ b/resources/server/sv_messages.ts @@ -413,20 +413,46 @@ onNet( ); if (result.error) { - emitNet( - events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, - _source, - result - ); + // if it just fails, welp + emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source, result); + /*emitNet(events.MESSAGES_ACTION_RESULT, _source, { + message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`, + type: 'error', + });*/ + + console.log(result); + + // if you try to create a existing group + } else if (result.error && result.duplicate) { + emitNet(events.MESSAGES_ACTION_RESULT, _source, { + message: 'MESSAGES_MESSAGE_GROUP_DUPLICATE', + type: 'error', + }); + + // if the phoneNumber is invalid + } else if (result.error && result.phoneNumber) { + emitNet(events.MESSAGES_ACTION_RESULT, _source, { + message: 'MESSAGES_INVALID_PHONE_NUMBER' + result.phoneNumber, + type: 'error', + }); + + // if you are try to add yourself + } else if (result.error && result.mine) { + console.log('yes'); + emitNet(events.MESSAGES_ACTION_RESULT, _source, { + message: 'MESSAGES_MESSAGE_GROUP_CREATE_MINE', + type: 'error', + }); } else { - emitNet( - events.MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS, - _source, - result - ); + emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS, _source, result); } } catch (e) { emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source); + + emitNet(events.MESSAGES_ACTION_RESULT, _source, { + message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`, + type: 'error', + }); messageLogger.error(`Failed to create message group, ${e.message}`, { source: _source, }); @@ -457,7 +483,16 @@ onNet( await createMessage(_identifier, groupId, message); emitNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, _source, groupId); } catch (e) { + // Not really sure what this does? As I cant find any reference + // of this in the ui part. emitNet(events.MESSAGES_SEND_MESSAGE_FAILED, _source); + // sending a new alert + // The message property is always using the locale strings without + // the APPS_ prefix. + emitNet(events.MESSAGES_ACTION_RESULT, _source, { + message: 'MESSAGES_NEW_MESSAGE_FAILED', + type: 'error', + }); messageLogger.error(`Failed to send message, ${e.message}`, { source: _source, }); From 09d397b6cf18b954f33e9939faf83a3e90eb819c Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 28 Feb 2021 01:37:22 +0100 Subject: [PATCH 14/15] feat(resources/messages): server and client functionality for alerts --- resources/client/cl_messages.ts | 4 ++++ resources/server/sv_messages.ts | 23 +++++++++-------------- resources/utils/events.ts | 5 ++--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/resources/client/cl_messages.ts b/resources/client/cl_messages.ts index 68b9cd2..ad4eb85 100644 --- a/resources/client/cl_messages.ts +++ b/resources/client/cl_messages.ts @@ -86,3 +86,7 @@ onNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, (groupId: string) => { onNet(events.MESSAGES_SEND_MESSAGE_FAILED, () => { sendMessageEvent(events.MESSAGES_SEND_MESSAGE_FAILED); }); + +onNet(events.MESSAGES_ACTION_RESULT, (result: any) => { + sendMessageEvent(events.MESSAGES_ACTION_RESULT, result); +}); diff --git a/resources/server/sv_messages.ts b/resources/server/sv_messages.ts index e22026c..ae72b65 100644 --- a/resources/server/sv_messages.ts +++ b/resources/server/sv_messages.ts @@ -412,18 +412,7 @@ onNet( label ); - if (result.error) { - // if it just fails, welp - emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source, result); - /*emitNet(events.MESSAGES_ACTION_RESULT, _source, { - message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`, - type: 'error', - });*/ - - console.log(result); - - // if you try to create a existing group - } else if (result.error && result.duplicate) { + if (result.error && result.duplicate) { emitNet(events.MESSAGES_ACTION_RESULT, _source, { message: 'MESSAGES_MESSAGE_GROUP_DUPLICATE', type: 'error', @@ -432,17 +421,23 @@ onNet( // if the phoneNumber is invalid } else if (result.error && result.phoneNumber) { emitNet(events.MESSAGES_ACTION_RESULT, _source, { - message: 'MESSAGES_INVALID_PHONE_NUMBER' + result.phoneNumber, + message: 'MESSAGES_INVALID_PHONE_NUMBER', type: 'error', }); // if you are try to add yourself } else if (result.error && result.mine) { - console.log('yes'); emitNet(events.MESSAGES_ACTION_RESULT, _source, { message: 'MESSAGES_MESSAGE_GROUP_CREATE_MINE', type: 'error', }); + } else if (result.error) { + // if it just fails, welp + emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source, result); + emitNet(events.MESSAGES_ACTION_RESULT, _source, { + message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`, + type: 'error', + }); } else { emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS, _source, result); } diff --git a/resources/utils/events.ts b/resources/utils/events.ts index 2cef8db..fadb583 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -68,7 +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', + MESSAGES_ACTION_RESULT: 'phone:setMessagesAlert', // Notes NOTE_ADD_NOTE: 'phone:addNote', @@ -81,7 +81,6 @@ export default { NOTE_UPDATE_NOTE_FAILURE: 'phone:updateNoteFailure', NOTE_ACTION_RESULT: 'phone:notesActionResult', - // DO NOT CHANGE WHATS BELOW, PLEASE - CHIP OPEN_APP_CONTACTS: 'phone:app:CONTACTS', OPEN_APP_BANK: 'phone:app:BANK', @@ -113,4 +112,4 @@ export default { PHONE_CALL_FETCH_CALLS: 'phone:fetchCalls', PHONE_CALL_SEND_HISTORY: 'phone:sendCallHistory', PHONE_CALL_SEND_HANGUP_ANIM: 'phone:sendHangupAnim', -}; \ No newline at end of file +}; From 4d82c8e69ae1a5b6478271ecc88664e5213327e3 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 28 Feb 2021 01:39:26 +0100 Subject: [PATCH 15/15] feat(phone/messages): minor changes for nui --- phone/src/apps/messages/components/MessagesApp.tsx | 2 -- phone/src/apps/messages/hooks/useMessageService.ts | 4 ++-- phone/src/locale/en.json | 3 ++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/phone/src/apps/messages/components/MessagesApp.tsx b/phone/src/apps/messages/components/MessagesApp.tsx index fe59786..4d0b1f1 100644 --- a/phone/src/apps/messages/components/MessagesApp.tsx +++ b/phone/src/apps/messages/components/MessagesApp.tsx @@ -3,7 +3,6 @@ import { AppWrapper } from '../../../ui/components'; import { AppTitle } from '../../../ui/components/AppTitle'; import { AppContent } from '../../../ui/components/AppContent'; import { useApp } from '../../../os/apps/hooks/useApps'; -import AlertBar from './AlertBar'; import MessageGroupModal from './modal/MessageGroupModal'; import MessagesList from './list/MessagesList'; import { Route, Switch, useHistory } from 'react-router-dom'; @@ -50,7 +49,6 @@ export const MessagesApp = () => { history.push('/messages/new')} /> - ); diff --git a/phone/src/apps/messages/hooks/useMessageService.ts b/phone/src/apps/messages/hooks/useMessageService.ts index 5532a3f..59aaac0 100644 --- a/phone/src/apps/messages/hooks/useMessageService.ts +++ b/phone/src/apps/messages/hooks/useMessageService.ts @@ -9,7 +9,7 @@ export const useMessagesService = () => { const setCreateMessageGroupResult = useSetRecoilState( messageState.createMessageGroupResult ); - const { addAlert } = useSnackbar() + const { addAlert } = useSnackbar(); useNuiEvent('MESSAGES', 'phone:fetchMessageGroupsSuccess', setMessageGroups); useNuiEvent('MESSAGES', 'phone:fetchMessagesSuccess', setMessages); @@ -23,5 +23,5 @@ export const useMessagesService = () => { 'phone:createMessageGroupFailed', setCreateMessageGroupResult ); - useNuiEvent('MESSAGES', 'setAlert', addAlert); + useNuiEvent('MESSAGES', 'phone:setMessagesAlert', addAlert); }; diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 5dd24e3..c7f0966 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -65,10 +65,11 @@ "APPS_MESSAGES_SEARCH_PLACEHOLDER": "Search messages...", "APPS_MESSAGES_NEW_MESSAGE": "Message...", + "APPS_MESSAGES_NEW_MESSAGE_FAILED:": "Failed to send message", "APPS_MESSAGES_NEW_MESSAGE_GROUP": "Phone numbers...", "APPS_MESSAGES_GROUP_CHAT_LABEL": "Group chat label...", "APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT": "Send", - "APPS_MESSAGES_INVALID_PHONE_NUMBER": "Invalid phone number: ", + "APPS_MESSAGES_INVALID_PHONE_NUMBER": "Invalid phone number", "APPS_MESSAGES_MESSAGE_GROUP_DUPLICATE": "This message group already exists", "APPS_MESSAGES_MESSAGE_GROUP_CREATE_FAILED": "Failed to create message group", "APPS_MESSAGES_MESSAGE_GROUP_CREATE_MINE": "You cannot add yourself!",