form.tsx 3.8 KB

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