form.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { useState } from 'react';
  2. import { View, Text, StyleSheet, TouchableWithoutFeedback, Keyboard, Pressable } from 'react-native';
  3. import ResetSuccessful from './formPages/resetSuccessful';
  4. import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
  5. import ForgetPasswordPage from './formPages/forgetPasswordPage';
  6. import { forgetPasswordFormData } from '../../../types/signup';
  7. import PaginationIndicator from '../../global/PaginationIndicator';
  8. import { router } from 'expo-router';
  9. type ForgetPasswordFormProps = {
  10. forgetPasswordFormData: forgetPasswordFormData;
  11. setForgetPasswordFormData: React.Dispatch<React.SetStateAction<forgetPasswordFormData>>;
  12. };
  13. const ForgetPasswordForm: React.FC<ForgetPasswordFormProps> = ({
  14. forgetPasswordFormData,
  15. setForgetPasswordFormData
  16. }) => {
  17. const [screen, setScreen] = useState<number>(0);
  18. const FormTitle = ['忘記密碼 - 電話驗證'];
  19. // const goToPreviousPage = () => {
  20. // router.back();
  21. // };
  22. const goToPreviousPage = () => {
  23. if (router.canGoBack()) {
  24. router.back();
  25. } else {
  26. router.replace('/(public)/login');
  27. }
  28. };
  29. const ScreenDisplay = () => {
  30. switch (screen) {
  31. case 0:
  32. return (
  33. <ForgetPasswordPage
  34. forgetPasswordFormData={forgetPasswordFormData}
  35. setForgetPasswordFormData={setForgetPasswordFormData}
  36. setScreen={setScreen}
  37. />
  38. );
  39. case 1:
  40. return <ResetSuccessful />;
  41. default:
  42. return <></>;
  43. }
  44. };
  45. return (
  46. <>
  47. <KeyboardAwareScrollView
  48. enableOnAndroid={true}
  49. resetScrollToCoords={{ x: 0, y: 0 }}
  50. style={{
  51. height: '100%'
  52. }}
  53. >
  54. {screen === 0 && (
  55. <View style={styles.topContainer}>
  56. <Text style={styles.text}>{FormTitle[screen]}</Text>
  57. <View style={styles.breakline} />
  58. <View className="w-full flex-row justify-between items-center">
  59. <Pressable onPress={goToPreviousPage} className="flex-1">
  60. <Text
  61. style={{
  62. color: '#888888',
  63. fontSize: 18,
  64. paddingLeft: 25
  65. }}
  66. >{`< 上一步`}</Text>
  67. </Pressable>
  68. <PaginationIndicator totalPages={2} currentPage={0} />
  69. <View className="flex-1" />
  70. </View>
  71. </View>
  72. )}
  73. <View style={styles.bottomContainer}>{ScreenDisplay()}</View>
  74. </KeyboardAwareScrollView>
  75. </>
  76. );
  77. };
  78. const styles = StyleSheet.create({
  79. topContainer: {
  80. flex: 1,
  81. alignItems: 'center',
  82. justifyContent: 'center',
  83. paddingBottom: '25%',
  84. paddingTop: '15%'
  85. },
  86. previouspageAndPaginationWrapper: {
  87. display: 'flex',
  88. width: '100%',
  89. flexDirection: 'row',
  90. justifyContent: 'space-between',
  91. alignItems: 'center',
  92. paddingHorizontal: 25
  93. },
  94. bottomContainer: { flex: 1 },
  95. breakline: {
  96. width: 24,
  97. height: 1,
  98. backgroundColor: '#000000',
  99. marginVertical: 17
  100. },
  101. text: { fontSize: 24, fontWeight: '300' }
  102. });
  103. export default ForgetPasswordForm;