import { Button, ButtonSize, Dialog, Text, TextField, TextFieldRef, View, } from "react-native-ui-lib"; import React, { useRef, useState } from "react"; import { useSignIn } from "@/hooks/firebase/useSignIn"; import { StyleSheet } from "react-native"; import Toast from "react-native-toast-message"; import { useLoginWithQrCode } from "@/hooks/firebase/useLoginWithQrCode"; import { Camera, CameraView } from "expo-camera"; const SignInPage = ({ setTab, }: { setTab: React.Dispatch< React.SetStateAction<"register" | "login" | "reset-password"> >; }) => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [hasPermission, setHasPermission] = useState(null); const [showCameraDialog, setShowCameraDialog] = useState(false); const passwordRef = useRef(null); const { mutateAsync: signIn, error, isError } = useSignIn(); const { mutateAsync: signInWithQrCode } = useLoginWithQrCode(); const handleSignIn = async () => { await signIn({ email, password }); if (!isError) { Toast.show({ type: "success", text1: "Login successful!", }); } else { Toast.show({ type: "error", text1: "Error logging in", text2: `${error}`, }); } }; const handleQrCodeScanned = async ({ data }: { data: string }) => { setShowCameraDialog(false); try { await signInWithQrCode({ userId: data }); Toast.show({ type: "success", text1: "Login successful with QR code!", }); } catch (err) { Toast.show({ type: "error", text1: "Error logging in with QR code", text2: `${err}`, }); } }; const getCameraPermissions = async (callback: () => void) => { const { status } = await Camera.requestCameraPermissionsAsync(); setHasPermission(status === "granted"); if (status === "granted") { callback(); } }; return ( { // Move focus to the description field passwordRef.current?.focus(); }} />