| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- import {
- View,
- Text,
- Image,
- StyleSheet,
- Pressable,
- Alert,
- Dimensions,
- ActivityIndicator
- } from 'react-native';
- import Logo from '../../../global/logo';
- import NormalButton from '../../../global/normal_button';
- import NormalInput from '../../../global/normal_input';
- import { useState } from 'react';
- import { useAuth } from '../../../../context/AuthProvider';
- import { useSafeAreaInsets } from 'react-native-safe-area-context';
- type LoginPageProps = {
- goToNextPage: () => void;
- goToForgetPassWordPage: () => void;
- };
- const screenHeight = Dimensions.get('window').height;
- console.log(screenHeight);
- const LoginPage: React.FC<LoginPageProps> = ({
- goToNextPage,
- goToForgetPassWordPage
- }) => {
- const [loginEmail, setLoginEmail] = useState('');
- const [loginPassword, setLoginPassword] = useState('');
- const [isLoading, setIsLoading] = useState(false);
- const { login } = useAuth();
- const _login = async (username: string, password: string) => {
- setIsLoading(true);
- if (username === '' || password === '') {
- Alert.alert('Error', 'Please enter a username and password');
- } else {
- const lowerCaseUsername = username.toLowerCase();
- const success = await login(lowerCaseUsername, password);
- if (!success) {
- Alert.alert('Error', 'Invalid username or password');
- }
- }
- setIsLoading(false);
- };
- const insets = useSafeAreaInsets();
- return (
- // <View style={styles.container} className="">
- // <View style={styles.topContainerForLogo}>
- // <Logo />
- // </View>
- // <View style={styles.bottomContainer} className="">
- // <NormalInput
- // placeholder="電子郵件"
- // onChangeText={(email) => setLoginEmail(email)}
- // extendedStyle={{ borderRadius: 12, padding: 20 }}
- // textContentType="username"
- // autoComplete="username"
- // />
- // <NormalInput
- // placeholder="密碼"
- // onChangeText={(password) => setLoginPassword(password)}
- // secureTextEntry={true}
- // extendedStyle={{ borderRadius: 12, padding: 20 }}
- // textContentType="password"
- // autoComplete="password"
- // />
- // <Pressable onPress={() => goToForgetPassWordPage()}>
- // <Text style={styles.text}>忘記密碼</Text>
- // </Pressable>
- // <NormalButton
- // extendedStyle={{ padding: 20 }}
- // onPress={() => _login(loginEmail, loginPassword)}
- // title={
- // isLoading ? (
- // <Text
- // style={{
- // fontWeight: '700',
- // fontSize: 20,
- // color: '#fff'
- // }}
- // >
- // <ActivityIndicator />
- // </Text>
- // ) : (
- // <Text
- // style={{
- // fontWeight: '700',
- // fontSize: 20,
- // color: '#fff'
- // }}
- // >
- // 登入
- // </Text>
- // )
- // }
- // />
- // <Pressable onPress={goToNextPage}>
- // <Text style={styles.text}>註冊會員</Text>
- // </Pressable>
- // </View>
- // </View>
- // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
- // <View className="flex-1 h-screen">
- // <View
- // className="items-center"
- // style={{
- // paddingTop: Math.max(insets.top + 20, 20)
- // }}
- // >
- // <Image
- // source={require('../../../../assets/ccLogo.png')}
- // resizeMode="contain"
- // style={{ width: 200, height: 200 }}
- // />
- // </View>
- // <View
- // style={{
- // gap: 10,
- // paddingBottom: Math.max(insets.bottom, 20)
- // }}
- // className="mx-[5%] flex-1 justify-end mb-10"
- // >
- // <NormalInput
- // placeholder="電子郵件"
- // onChangeText={(email) => setLoginEmail(email)}
- // extendedStyle={{ borderRadius: 12, padding: 20 }}
- // textContentType="username"
- // autoComplete="username"
- // />
- // <NormalInput
- // placeholder="密碼"
- // onChangeText={(password) => setLoginPassword(password)}
- // secureTextEntry={true}
- // extendedStyle={{ borderRadius: 12, padding: 20 }}
- // textContentType="password"
- // autoComplete="password"
- // />
- // <Pressable onPress={() => goToForgetPassWordPage()}>
- // <Text style={styles.text}>忘記密碼</Text>
- // </Pressable>
- // <NormalButton
- // extendedStyle={{ padding: 20 }}
- // onPress={() => _login(loginEmail, loginPassword)}
- // title={
- // isLoading ? (
- // <Text
- // style={{
- // fontWeight: '700',
- // fontSize: 20,
- // color: '#fff'
- // }}
- // >
- // <ActivityIndicator />
- // </Text>
- // ) : (
- // <Text
- // style={{
- // fontWeight: '700',
- // fontSize: 20,
- // color: '#fff'
- // }}
- // >
- // 登入
- // </Text>
- // )
- // }
- // />
- // <Pressable onPress={goToNextPage}>
- // <Text style={styles.text}>註冊會員</Text>
- // </Pressable>
- // </View>
- // </View>
- // );
- // };
- // const styles = StyleSheet.create({
- // container: {
- // flex: 1,
- // height: Dimensions.get('window').height,
- // justifyContent: 'center',
- // marginHorizontal: 20
- // },
- // topContainerForLogo: {},
- // text: {
- // color: '#02677D',
- // fontSize: 16,
- // paddingVertical: 5
- // }
- // });
- // export default LoginPage;
- // <View className="flex-1 h-screen justify-center">
- <View
- className={`flex-1 justify-center ${
- screenHeight < 750 ? 'h-screen' : 'h-[80vh] space-y-8'
-
- }`}
- >
- <View className="flex-3 items-center justify-end" style={{}}>
- <Image
- source={require('../../../../assets/ccLogo.png')}
- resizeMode="contain"
- style={{
- width: screenHeight > 750 ? 250 : 200,
- height: screenHeight > 750 ? 250 : 200
- }}
- />
- </View>
- <View
- style={{
- gap: 10
- // paddingBottom: Math.max(insets.bottom, 20)
- // marginTop: screenHeight > 750 ? 40 : 0
- }}
- className="mx-[5%] flex-2 "
- >
- <NormalInput
- placeholder="電子郵件"
- onChangeText={(email) => setLoginEmail(email)}
- extendedStyle={{ borderRadius: 12, padding: 20 }}
- textContentType="username"
- autoComplete="username"
- />
- <NormalInput
- placeholder="密碼"
- onChangeText={(password) => setLoginPassword(password)}
- secureTextEntry={true}
- extendedStyle={{ borderRadius: 12, padding: 20 }}
- textContentType="password"
- autoComplete="password"
- />
- <Pressable onPress={() => goToForgetPassWordPage()}>
- <Text style={styles.text}>忘記密碼</Text>
- </Pressable>
- <NormalButton
- extendedStyle={{ padding: 20 }}
- onPress={() => _login(loginEmail, loginPassword)}
- title={
- isLoading ? (
- <Text
- style={{
- fontWeight: '700',
- fontSize: 20,
- color: '#fff'
- }}
- >
- <ActivityIndicator />
- </Text>
- ) : (
- <Text
- style={{
- fontWeight: '700',
- fontSize: 20,
- color: '#fff'
- }}
- >
- 登入
- </Text>
- )
- }
- />
- <Pressable onPress={goToNextPage}>
- <Text style={styles.text}>註冊會員</Text>
- </Pressable>
- </View>
- </View>
- );
- };
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- height: Dimensions.get('window').height,
- justifyContent: 'center',
- marginHorizontal: 20
- },
- topContainerForLogo: {},
- text: {
- color: '#02677D',
- fontSize: 16,
- paddingVertical: 5
- }
- });
- export default LoginPage;
|