feat(phone|resources/bank): useSnackbar for alert

This commit is contained in:
Christopher committed 2021-02-26 12:48:27 +01:00
1 parent 1afca13862
commit 47218e63f5
3 files changed
+25 -9

No files matched your search

+3 -4
View File
@@ -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 };
};
+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,
})
);
});
+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'
}
);
}
});