feat(bank/nui): state and hooks for alert and notificatioln

This commit is contained in:
chip committed 2020-11-04 16:11:12 +01:00
1 parent 3d865dd887
commit e6cee7b414
4 files changed
+30 -7

No files matched your search

+5 -1
View File
@@ -9,7 +9,7 @@ export const bankState = {
key: 'modalVisibility',
default: false,
}),
bankAlert: atom({
transferSuccessful: atom({
key: 'bankAlert',
default: null
}),
@@ -17,4 +17,8 @@ export const bankState = {
key: 'bankCredentails',
default: null
}),
notification: atom({
key: 'bankNotification',
default: null
})
}
+2 -2
View File
@@ -1,7 +1,7 @@
import { useRecoilState } from 'recoil';
import { bankState } from './state';
export const useBankAlert = () => {
const [ bankAlert, setBankAlert ] = useRecoilState(bankState.bankAlert);
export const useBankAlert = (): any => {
const [ bankAlert, setBankAlert ] = useRecoilState(bankState.transferSuccessful);
return { bankAlert, setBankAlert };
}
@@ -0,0 +1,13 @@
import { useRecoilValue } from 'recoil';
import { Transfer } from '../../../common/interfaces/bank';
import { bankState } from './state';
interface IBankNotification {
notification: Transfer | null;
}
export const useBankNotification = (): IBankNotification => {
const notification = useRecoilValue<Transfer | null>(bankState.notification);
return { notification }
}
+10 -4
View File
@@ -4,13 +4,19 @@ import { useTransactions } from './useTransactions'
import { useCredentials } from './useCredentials';
import { useBankAlert } from './useBankAlert';
import { useSetRecoilState } from 'recoil'
import { useBankNotification } from './useBankNotification';
export const useBankService = () => {
const setTransaction = useSetRecoilState(bankState.transactions)
const setCredentials = useSetRecoilState(bankState.bankCredentials)
const setAlertMessage = useSetRecoilState(bankState.bankAlert)
const setAlertMessage = useSetRecoilState(bankState.transferSuccessful)
const setNotification = useSetRecoilState(bankState.notification);
///
useNuiEvent('BANK', 'setTransaction', setTransaction);
useNuiEvent('BANK', 'setCredentials', setCredentials)
useNuiEvent('BANK', 'setAlert', setAlertMessage)
return {useTransactions, useCredentials, useBankAlert};
useNuiEvent('BANK', 'setCredentials', setCredentials);
useNuiEvent('BANK', 'setAlert', setAlertMessage);
useNuiEvent('BANK', 'setNotification', setNotification);
return { useTransactions, useCredentials, useBankAlert, useBankNotification };
}