tweak(phone/snackbar-provider): Altered API to expect a string for message, not a key (#135)

Change SnackbarProviderAlert message property to allow for any string rather than a explicit translation key
This commit is contained in:
Taso authored and GitHub committed 2021-03-04 22:40:17 -05:00
1 parent 9abac70427
commit 5c9c75c36c
10 files changed
+87 -19

No files matched your search

@@ -1,8 +1,10 @@
import { useSetRecoilState } from 'recoil';
import { messageState } from './state';
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
import { useTranslation } from 'react-i18next';
import { useMessageNotifications } from './useMessageNotifications';
import { useCallback } from 'react';
export const useMessagesService = () => {
const setMessageGroups = useSetRecoilState(messageState.messageGroups);
@@ -10,11 +12,22 @@ export const useMessagesService = () => {
const setCreateMessageGroupResult = useSetRecoilState(messageState.createMessageGroupResult);
const { addAlert } = useSnackbar();
const { setNotification } = useMessageNotifications();
const { t } = useTranslation();
const handleAddAlert = useCallback(
({ message, type }: IAlert) => {
addAlert({
message: t(`APPS_${message}`),
type,
});
},
[addAlert, t],
);
useNuiEvent('MESSAGES', 'phone:fetchMessageGroupsSuccess', setMessageGroups);
useNuiEvent('MESSAGES', 'phone:fetchMessagesSuccess', setMessages);
useNuiEvent('MESSAGES', 'phone:createMessageGroupSuccess', setCreateMessageGroupResult);
useNuiEvent('MESSAGES', 'phone:createMessageGroupFailed', setCreateMessageGroupResult);
useNuiEvent('MESSAGES', 'phone:setMessagesAlert', addAlert);
useNuiEvent('MESSAGES', 'createMessagesBroadcast', setNotification);
useNuiEvent('MESSAGES', 'phone:setMessagesAlert', handleAddAlert);
};