loginPage.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. import {
  2. View,
  3. Text,
  4. Image,
  5. StyleSheet,
  6. Pressable,
  7. Alert,
  8. Dimensions,
  9. ActivityIndicator
  10. } from 'react-native';
  11. import Logo from '../../../global/logo';
  12. import NormalButton from '../../../global/normal_button';
  13. import NormalInput from '../../../global/normal_input';
  14. import { useState } from 'react';
  15. import { useAuth } from '../../../../context/AuthProvider';
  16. import { useSafeAreaInsets } from 'react-native-safe-area-context';
  17. type LoginPageProps = {
  18. goToNextPage: () => void;
  19. goToForgetPassWordPage: () => void;
  20. };
  21. const screenHeight = Dimensions.get('window').height;
  22. console.log(screenHeight);
  23. const LoginPage: React.FC<LoginPageProps> = ({
  24. goToNextPage,
  25. goToForgetPassWordPage
  26. }) => {
  27. const [loginEmail, setLoginEmail] = useState('');
  28. const [loginPassword, setLoginPassword] = useState('');
  29. const [isLoading, setIsLoading] = useState(false);
  30. const { login } = useAuth();
  31. const _login = async (username: string, password: string) => {
  32. setIsLoading(true);
  33. if (username === '' || password === '') {
  34. Alert.alert('Error', 'Please enter a username and password');
  35. } else {
  36. const lowerCaseUsername = username.toLowerCase();
  37. const success = await login(lowerCaseUsername, password);
  38. if (!success) {
  39. Alert.alert('Error', 'Invalid username or password');
  40. }
  41. }
  42. setIsLoading(false);
  43. };
  44. const insets = useSafeAreaInsets();
  45. return (
  46. // <View style={styles.container} className="">
  47. // <View style={styles.topContainerForLogo}>
  48. // <Logo />
  49. // </View>
  50. // <View style={styles.bottomContainer} className="">
  51. // <NormalInput
  52. // placeholder="電子郵件"
  53. // onChangeText={(email) => setLoginEmail(email)}
  54. // extendedStyle={{ borderRadius: 12, padding: 20 }}
  55. // textContentType="username"
  56. // autoComplete="username"
  57. // />
  58. // <NormalInput
  59. // placeholder="密碼"
  60. // onChangeText={(password) => setLoginPassword(password)}
  61. // secureTextEntry={true}
  62. // extendedStyle={{ borderRadius: 12, padding: 20 }}
  63. // textContentType="password"
  64. // autoComplete="password"
  65. // />
  66. // <Pressable onPress={() => goToForgetPassWordPage()}>
  67. // <Text style={styles.text}>忘記密碼</Text>
  68. // </Pressable>
  69. // <NormalButton
  70. // extendedStyle={{ padding: 20 }}
  71. // onPress={() => _login(loginEmail, loginPassword)}
  72. // title={
  73. // isLoading ? (
  74. // <Text
  75. // style={{
  76. // fontWeight: '700',
  77. // fontSize: 20,
  78. // color: '#fff'
  79. // }}
  80. // >
  81. // <ActivityIndicator />
  82. // </Text>
  83. // ) : (
  84. // <Text
  85. // style={{
  86. // fontWeight: '700',
  87. // fontSize: 20,
  88. // color: '#fff'
  89. // }}
  90. // >
  91. // 登入
  92. // </Text>
  93. // )
  94. // }
  95. // />
  96. // <Pressable onPress={goToNextPage}>
  97. // <Text style={styles.text}>註冊會員</Text>
  98. // </Pressable>
  99. // </View>
  100. // </View>
  101. // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  102. // <View className="flex-1 h-screen">
  103. // <View
  104. // className="items-center"
  105. // style={{
  106. // paddingTop: Math.max(insets.top + 20, 20)
  107. // }}
  108. // >
  109. // <Image
  110. // source={require('../../../../assets/ccLogo.png')}
  111. // resizeMode="contain"
  112. // style={{ width: 200, height: 200 }}
  113. // />
  114. // </View>
  115. // <View
  116. // style={{
  117. // gap: 10,
  118. // paddingBottom: Math.max(insets.bottom, 20)
  119. // }}
  120. // className="mx-[5%] flex-1 justify-end mb-10"
  121. // >
  122. // <NormalInput
  123. // placeholder="電子郵件"
  124. // onChangeText={(email) => setLoginEmail(email)}
  125. // extendedStyle={{ borderRadius: 12, padding: 20 }}
  126. // textContentType="username"
  127. // autoComplete="username"
  128. // />
  129. // <NormalInput
  130. // placeholder="密碼"
  131. // onChangeText={(password) => setLoginPassword(password)}
  132. // secureTextEntry={true}
  133. // extendedStyle={{ borderRadius: 12, padding: 20 }}
  134. // textContentType="password"
  135. // autoComplete="password"
  136. // />
  137. // <Pressable onPress={() => goToForgetPassWordPage()}>
  138. // <Text style={styles.text}>忘記密碼</Text>
  139. // </Pressable>
  140. // <NormalButton
  141. // extendedStyle={{ padding: 20 }}
  142. // onPress={() => _login(loginEmail, loginPassword)}
  143. // title={
  144. // isLoading ? (
  145. // <Text
  146. // style={{
  147. // fontWeight: '700',
  148. // fontSize: 20,
  149. // color: '#fff'
  150. // }}
  151. // >
  152. // <ActivityIndicator />
  153. // </Text>
  154. // ) : (
  155. // <Text
  156. // style={{
  157. // fontWeight: '700',
  158. // fontSize: 20,
  159. // color: '#fff'
  160. // }}
  161. // >
  162. // 登入
  163. // </Text>
  164. // )
  165. // }
  166. // />
  167. // <Pressable onPress={goToNextPage}>
  168. // <Text style={styles.text}>註冊會員</Text>
  169. // </Pressable>
  170. // </View>
  171. // </View>
  172. // );
  173. // };
  174. // const styles = StyleSheet.create({
  175. // container: {
  176. // flex: 1,
  177. // height: Dimensions.get('window').height,
  178. // justifyContent: 'center',
  179. // marginHorizontal: 20
  180. // },
  181. // topContainerForLogo: {},
  182. // text: {
  183. // color: '#02677D',
  184. // fontSize: 16,
  185. // paddingVertical: 5
  186. // }
  187. // });
  188. // export default LoginPage;
  189. // <View className="flex-1 h-screen justify-center">
  190. <View
  191. className={`flex-1 justify-center ${
  192. screenHeight < 750 ? 'h-screen' : 'h-[80vh] space-y-8'
  193. }`}
  194. >
  195. <View className="flex-3 items-center justify-end" style={{}}>
  196. <Image
  197. source={require('../../../../assets/ccLogo.png')}
  198. resizeMode="contain"
  199. style={{
  200. width: screenHeight > 750 ? 250 : 200,
  201. height: screenHeight > 750 ? 250 : 200
  202. }}
  203. />
  204. </View>
  205. <View
  206. style={{
  207. gap: 10
  208. // paddingBottom: Math.max(insets.bottom, 20)
  209. // marginTop: screenHeight > 750 ? 40 : 0
  210. }}
  211. className="mx-[5%] flex-2 "
  212. >
  213. <NormalInput
  214. placeholder="電子郵件"
  215. onChangeText={(email) => setLoginEmail(email)}
  216. extendedStyle={{ borderRadius: 12, padding: 20 }}
  217. textContentType="username"
  218. autoComplete="username"
  219. />
  220. <NormalInput
  221. placeholder="密碼"
  222. onChangeText={(password) => setLoginPassword(password)}
  223. secureTextEntry={true}
  224. extendedStyle={{ borderRadius: 12, padding: 20 }}
  225. textContentType="password"
  226. autoComplete="password"
  227. />
  228. <Pressable onPress={() => goToForgetPassWordPage()}>
  229. <Text style={styles.text}>忘記密碼</Text>
  230. </Pressable>
  231. <NormalButton
  232. extendedStyle={{ padding: 20 }}
  233. onPress={() => _login(loginEmail, loginPassword)}
  234. title={
  235. isLoading ? (
  236. <Text
  237. style={{
  238. fontWeight: '700',
  239. fontSize: 20,
  240. color: '#fff'
  241. }}
  242. >
  243. <ActivityIndicator />
  244. </Text>
  245. ) : (
  246. <Text
  247. style={{
  248. fontWeight: '700',
  249. fontSize: 20,
  250. color: '#fff'
  251. }}
  252. >
  253. 登入
  254. </Text>
  255. )
  256. }
  257. />
  258. <Pressable onPress={goToNextPage}>
  259. <Text style={styles.text}>註冊會員</Text>
  260. </Pressable>
  261. </View>
  262. </View>
  263. );
  264. };
  265. const styles = StyleSheet.create({
  266. container: {
  267. flex: 1,
  268. height: Dimensions.get('window').height,
  269. justifyContent: 'center',
  270. marginHorizontal: 20
  271. },
  272. topContainerForLogo: {},
  273. text: {
  274. color: '#02677D',
  275. fontSize: 16,
  276. paddingVertical: 5
  277. }
  278. });
  279. export default LoginPage;