Merge pull request #110 from project-error/feat/alerts-for-apps

Feat/alerts for apps (in memory of daft punk)
This commit is contained in:
Christopher Gjelten authored and GitHub committed 2021-02-28 17:25:56 +01:00
commit a5a04cdef7
33 files changed
+171 -402

No files matched your search

@@ -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 = () => {
<Route path='/bank/account' exact component={BankAccount} />
<Route path='/bank/transactions' exact component={TransactionList} />
</Switch>
<BankAlert />
</AppContent>
<NavigationBar />
</AppWrapper>
@@ -1,8 +0,0 @@
import React from 'react';
import MuiAlert from '@material-ui/lab/Alert';
export function Alert(props) {
return <MuiAlert elevation={6} variant='filled' {...props} />;
}
export default Alert;
@@ -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 (
<Snackbar
style={{ width: '80%' }}
open={open}
autoHideDuration={6000}
onClose={_handleClose}
>
<Alert onClose={_handleClose} severity={severity}>
{message}
</Alert>
</Snackbar>
);
};
@@ -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 (
<Notification
key={notification.id}
open={visible}
handleClose={() => setVisible(false)}
>
<div className={classes.content}>
<div className={classes.title}>
<div className={classes.titleLeft}>
<div className={classes.icon}>
<FontAwesomeIcon icon={faWonSign} />
</div>
<div className={classes.heading}>{notification.type}</div>
</div>
<div className={classes.justNow}>{t('APPS_BANK_TIME_JUST_NOW')}</div>
</div>
<div className={classes.message}>
{notification.source} sent you ${notification.transferAmount}.{' '}
<br></br> {notification.message}
</div>
</div>
</Notification>
);
};
@@ -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;
-4
View File
@@ -9,10 +9,6 @@ export const bankState = {
key: 'modalVisibility',
default: false,
}),
transferSuccessful: atom({
key: 'bankAlert',
default: null,
}),
bankCredentials: atom({
key: 'bankCredentails',
default: 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 };
};
+4 -6
View File
@@ -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 };
};
+1 -5
View File
@@ -20,9 +20,5 @@ export const contactsState = {
contactDetail: atom({
key: 'contactDetail',
default: null,
}),
contactAlert: atom({
key: 'contactAlert',
default: 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 };
};
@@ -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();
};
@@ -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<string | null>(null);
const [open, setOpen] = useState(false);
const [message, setMessage] = useState<string | null>(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 (
<Snackbar
autoHideDuration={ALERT_TIMEOUT}
className={classes.root}
open={open}
onClose={handleClose}
>
<Alert onClose={handleClose} severity={severity}>
{message}
</Alert>
</Snackbar>
);
}
@@ -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 = () => {
</Switch>
</AppContent>
<NewMessageGroupButton onClick={() => history.push('/messages/new')} />
<AlertBar />
</AppWrapper>
</MessagesThemeProvider>
);
@@ -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<CreateMessageGroupResult | null>(
messageState.createMessageGroupResult
);
return { createMessageGroupResult };
};
@@ -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);
};
-4
View File
@@ -12,9 +12,5 @@ export const noteStates = {
noteDetail: atom({
key: 'noteDetail',
default: null,
}),
alert: atom({
key: 'notesAlert',
default: null
})
};
@@ -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();
};
};
@@ -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 = () => {
)}
</AppContent>
{showTweetButton && <TweetButton openModal={openModal} />}
<AlertBar />
{!promptProfileName && (
<BottomNavigation
activePage={activePage}
@@ -1,66 +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 { useProfile } from '../../hooks/useProfile';
import { useTweetStatus } from '../../hooks/useTweetStatus';
import Alert from '../../../../ui/components/Alert';
const useStyles = makeStyles((theme) => ({
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<string | null>(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 (
<Snackbar
autoHideDuration={ALERT_TIMEOUT}
className={classes.root}
open={open}
onClose={handleClose}
>
<Alert onClose={handleClose} severity={severity}>
{message}
</Alert>
</Snackbar>
);
}
@@ -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);
};
};
+4
View File
@@ -0,0 +1,4 @@
export interface IAlertProps {
message: string;
type: 'success' | 'error';
}
+5 -1
View File
@@ -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",
+3 -2
View File
@@ -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,
})
);
});
+2 -2
View File
@@ -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
})
);
});
+4
View File
@@ -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);
});
+12 -2
View File
@@ -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
})
)
})
+5 -4
View File
@@ -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);
});
+19 -3
View File
@@ -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'
}
);
}
});
+24 -6
View File
@@ -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'
});
}
});
+41 -11
View File
@@ -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,
});
+10
View File
@@ -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'
})
}
});
+12 -5
View File
@@ -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'
});
}
});
+4 -3
View File
@@ -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',
};
};