From 33a5b5a595154aeb9f8412c4152f4d8025107d3b Mon Sep 17 00:00:00 2001 From: ivic00 <102467664+ivic00@users.noreply.github.com> Date: Sun, 27 Oct 2024 20:51:38 +0100 Subject: [PATCH] sign/login ui tweaks --- components/pages/main/SignInPage.tsx | 356 +++++++++++++++------------ components/pages/main/SignUpPage.tsx | 129 +++++++--- 2 files changed, 290 insertions(+), 195 deletions(-) diff --git a/components/pages/main/SignInPage.tsx b/components/pages/main/SignInPage.tsx index ac2b640..216d420 100644 --- a/components/pages/main/SignInPage.tsx +++ b/components/pages/main/SignInPage.tsx @@ -1,170 +1,218 @@ -import {Button, ButtonSize, Dialog, Text, TextField, View} from "react-native-ui-lib"; -import React, {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'; +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> +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 [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 { 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 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 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(); - } - }; + const getCameraPermissions = async (callback: () => void) => { + const { status } = await Camera.requestCameraPermissionsAsync(); + setHasPermission(status === "granted"); + if (status === "granted") { + callback(); + } + }; - return ( - - - -