added notification
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { getApp } from '@react-native-firebase/app';
|
||||
import { getMessaging, getToken } from '@react-native-firebase/messaging';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
@@ -6,7 +8,13 @@ import { authApi } from 'api/auth';
|
||||
import { loginPayload } from 'api/auth/type';
|
||||
import { Branch, branchApi } from 'api/branch';
|
||||
import formatPhone from 'helpers/formatPhone';
|
||||
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { Controller, useForm } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
@@ -20,6 +28,7 @@ import {
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} from 'react-native';
|
||||
import DeviceInfo from 'react-native-device-info';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
import Logo from 'screens/../../assets/bootsplash/logo_512.png';
|
||||
import { LoginFormType, loginSchema } from 'screens/auth/login/lib/form';
|
||||
@@ -50,6 +59,36 @@ const Login = () => {
|
||||
queryKey: ['branchList'],
|
||||
queryFn: branchApi.branchList,
|
||||
});
|
||||
const [firebaseToken, setFirebseToken] = useState<{
|
||||
fcmToken: string;
|
||||
deviceId: string;
|
||||
deviceName: string;
|
||||
deviceType: string;
|
||||
} | null>();
|
||||
|
||||
const app = getApp();
|
||||
const messaging = getMessaging(app);
|
||||
|
||||
const getDeviceData = async () => {
|
||||
try {
|
||||
const fcmToken = await getToken(messaging);
|
||||
return {
|
||||
fcmToken,
|
||||
deviceId: await DeviceInfo.getUniqueId(),
|
||||
deviceName: await DeviceInfo.getDeviceName(),
|
||||
deviceType: await DeviceInfo.getDeviceType(),
|
||||
};
|
||||
} catch (e) {
|
||||
console.log('Xato:', e);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getDeviceData().then(data => {
|
||||
setFirebseToken(data);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const { mutate, isPending } = useMutation({
|
||||
mutationFn: (payload: loginPayload) => authApi.login(payload),
|
||||
@@ -84,6 +123,10 @@ const Login = () => {
|
||||
passportSerial: `${data.passportSeriya.toUpperCase()}${
|
||||
data.passportNumber
|
||||
}`,
|
||||
fcmToken: firebaseToken?.fcmToken || '',
|
||||
deviceId: firebaseToken?.deviceId || '',
|
||||
deviceType: firebaseToken?.deviceType || '',
|
||||
deviceName: firebaseToken?.deviceName || '',
|
||||
});
|
||||
// navigation.navigate('Login-Confirm');
|
||||
setUser({
|
||||
|
||||
Reference in New Issue
Block a user