Files
new-phone-who-dis/phone/src/apps/contacts/hooks/useContactsService.ts
T
2021-04-07 19:07:10 -03:00

25 lines
844 B
TypeScript

import { useNuiEvent } from 'fivem-nui-react-lib';
import { useSetRecoilState } from 'recoil';
import { contactsState } from './state';
import { useContacts } from './useContacts';
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
import { useTranslation } from 'react-i18next';
import { ContactEvents } from '../../../../../typings/contact';
export const useContactsService = () => {
const setContacts = useSetRecoilState(contactsState.contacts);
const { addAlert } = useSnackbar();
const { t } = useTranslation();
const handleAddAlert = ({ message, type }: IAlert) => {
addAlert({
message: t(`APPS_${message}`),
type,
});
};
useNuiEvent('CONTACTS', ContactEvents.SEND_CONTACTS, setContacts);
useNuiEvent('CONTACTS', ContactEvents.SEND_ALERT, handleAddAlert);
return useContacts();
};