basicInformation.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { View, Text, StyleSheet } from 'react-native';
  2. import NormalInput from '../../../global/normal_input';
  3. import { useState } from 'react';
  4. import DateModal from '../../../global/date_input';
  5. import NormalButton from '../../../global/normal_button';
  6. import useSignUpStore from '../../../../providers/signup_form_store';
  7. import DropdownSelect from '../../../global/dropdown_select';
  8. type basicInformationProps = {
  9. goToNextPage: () => void;
  10. };
  11. const BasicInformation: React.FC<basicInformationProps> = ({
  12. goToNextPage
  13. }) => {
  14. const { signUpFormData, setSignUpFormData } = useSignUpStore();
  15. const [error, setError] = useState('');
  16. const handleNext = () => {
  17. if (
  18. signUpFormData.name === '' ||
  19. signUpFormData.password === '' ||
  20. signUpFormData.birthDate === ''
  21. ) {
  22. setError('請確保所有資料都已填寫。');
  23. } else {
  24. setError('');
  25. goToNextPage();
  26. }
  27. };
  28. const nameFieldPlaceholder = signUpFormData.name
  29. ? signUpFormData.name
  30. : '姓名';
  31. const genderDropdownOptions = [
  32. { label: '男', value: 'male' },
  33. { label: '女', value: 'female' }
  34. ];
  35. return (
  36. <>
  37. <View style={styles.container}>
  38. <Text style={styles.text}>請填妥以下資料</Text>
  39. <View
  40. style={{
  41. display: 'flex',
  42. flexDirection: 'column',
  43. gap: 10
  44. }}
  45. >
  46. <NormalInput
  47. value={signUpFormData.name}
  48. placeholder={nameFieldPlaceholder}
  49. onChangeText={(text) => {
  50. setSignUpFormData({
  51. ...signUpFormData,
  52. name: text
  53. });
  54. }}
  55. />
  56. <NormalInput
  57. placeholder="帳戶密碼"
  58. onChangeText={(text) => {
  59. setSignUpFormData({
  60. ...signUpFormData,
  61. password: text
  62. });
  63. }}
  64. secureTextEntry={true}
  65. />
  66. <View
  67. style={{
  68. display: 'flex',
  69. flexDirection: 'row',
  70. gap: 10
  71. }}
  72. >
  73. <DropdownSelect
  74. onSelect={(value) => {
  75. setSignUpFormData({
  76. ...signUpFormData,
  77. gender: value
  78. });
  79. }}
  80. dropdownOptions={genderDropdownOptions}
  81. placeholder={'性別'}
  82. />
  83. <DateModal
  84. placeholder={
  85. signUpFormData.birthDate
  86. ? signUpFormData.birthDate
  87. : 'DD/MM/YY'
  88. }
  89. onDateChange={(date) => {
  90. setSignUpFormData({
  91. ...signUpFormData,
  92. birthDate: date
  93. });
  94. }}
  95. />
  96. </View>
  97. <NormalButton
  98. title={<Text style={{ color: '#fff' }}>下一步</Text>}
  99. onPress={handleNext}
  100. extendedStyle={{}}
  101. />
  102. </View>
  103. {error && <Text style={styles.errorMessage}>{error}</Text>}
  104. </View>
  105. </>
  106. );
  107. };
  108. const styles = StyleSheet.create({
  109. container: {
  110. flex: 1,
  111. marginHorizontal: 20
  112. },
  113. text: {
  114. fontSize: 20,
  115. paddingBottom: 10
  116. },
  117. errorMessage: {
  118. fontSize: 14,
  119. color: '#ff0033',
  120. fontWeight: '400',
  121. marginLeft: 10,
  122. marginTop: 10
  123. }
  124. });
  125. export default BasicInformation;