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} - - - ); -}; 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/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 }; -}; diff --git a/phone/src/apps/bank/hooks/useBankService.ts b/phone/src/apps/bank/hooks/useBankService.ts index 710ef91..19841ae 100644 --- a/phone/src/apps/bank/hooks/useBankService.ts +++ b/phone/src/apps/bank/hooks/useBankService.ts @@ -2,21 +2,19 @@ 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'; 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 }; + 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/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 3c89e7c..fbdc96a 100644 --- a/phone/src/apps/contacts/hooks/useContactsService.ts +++ b/phone/src/apps/contacts/hooks/useContactsService.ts @@ -1,10 +1,14 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { useSetRecoilState } from 'recoil'; import { contactsState } from './state'; +import { useContacts } from './useContacts'; +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); + useNuiEvent('CONTACTS', 'setAlert', addAlert); + return useContacts(); }; 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/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/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/phone/src/apps/messages/hooks/useMessageService.ts b/phone/src/apps/messages/hooks/useMessageService.ts index 37ac1a3..59aaac0 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', 'phone:setMessagesAlert', 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 }) }; 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/apps/twitter/components/TwitterApp.tsx b/phone/src/apps/twitter/components/TwitterApp.tsx index 3498d98..d86a8cd 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'; @@ -84,7 +83,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} - - - ); -} diff --git a/phone/src/apps/twitter/hooks/useTwitterService.ts b/phone/src/apps/twitter/hooks/useTwitterService.ts index 3cf31b7..410e4d1 100644 --- a/phone/src/apps/twitter/hooks/useTwitterService.ts +++ b/phone/src/apps/twitter/hooks/useTwitterService.ts @@ -5,6 +5,7 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { IMAGE_DELIMITER } from '../utils/images'; import { APP_TWITTER } from '../utils/constants'; import { twitterState } from './state'; +import { useSnackbar } from '../../../ui/hooks/useSnackbar'; import { useTwitterNotifications } from './useTwitterNotifications'; /** @@ -29,31 +30,18 @@ function processTweet(tweet) { * there and have moved that logic here instead. */ export const useTwitterService = () => { + const { addAlert } = useSnackbar() const { setNotification } = useTwitterNotifications(); const setProfile = useSetRecoilState(twitterState.profile); 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)); @@ -64,10 +52,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/phone/src/locale/en.json b/phone/src/locale/en.json index 3ac402d..21b1735 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -74,10 +74,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!", @@ -112,6 +113,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_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/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/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/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/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_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' + } + ); } }); diff --git a/resources/server/sv_contacts.ts b/resources/server/sv_contacts.ts index 56994c8..e6ce278 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' + }); } }); diff --git a/resources/server/sv_messages.ts b/resources/server/sv_messages.ts index 496939f..ae72b65 100644 --- a/resources/server/sv_messages.ts +++ b/resources/server/sv_messages.ts @@ -412,21 +412,42 @@ onNet( label ); - if (result.error) { - emitNet( - events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, - _source, - result - ); + 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', + type: 'error', + }); + + // if you are try to add yourself + } else if (result.error && result.mine) { + 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 - ); + 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 +478,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, }); 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/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' + }); } }); diff --git a/resources/utils/events.ts b/resources/utils/events.ts index 3a8e52f..fadb583 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:setMessagesAlert', // Notes NOTE_ADD_NOTE: 'phone:addNote', @@ -78,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', @@ -95,7 +97,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', @@ -111,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 +};