basicInformation.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. import TestingDropDownSelect from '../../../global/testingDropDownSelect';
  9. type basicInformationProps = {
  10. goToNextPage: () => void;
  11. };
  12. const BasicInformation: React.FC<basicInformationProps> = ({ goToNextPage }) => {
  13. const { signUpFormData, setSignUpFormData } = useSignUpStore();
  14. const [selectedYear, setSelectedYear] = useState('');
  15. const [selectedMonth, setSelectedMonth] = useState('');
  16. const [selectedDay, setSelectedDay] = useState('');
  17. const [birthDate, setBirthDate] = useState('');
  18. const [error, setError] = useState('');
  19. const handleNext = () => {
  20. setSignUpFormData({
  21. ...signUpFormData,
  22. birthDate: birthDate
  23. });
  24. if (
  25. signUpFormData.nickName === '' ||
  26. signUpFormData.password === '' ||
  27. signUpFormData.gender === '' ||
  28. signUpFormData.birthDateMonth === '' ||
  29. signUpFormData.birthDateDay === ''
  30. ) {
  31. setError('請確保所有資料都已填寫。');
  32. } else {
  33. setError('');
  34. goToNextPage();
  35. }
  36. };
  37. const nameFieldPlaceholder = signUpFormData.nickName ? signUpFormData.nickName : '暱稱';
  38. const birthMonthOptions = Array.from({ length: 12 }, (_, i) => {
  39. const month = i + 1;
  40. return { label: month.toString(), value: month.toString() };
  41. });
  42. const birthDayOptions = Array.from({ length: 31 }, (_, i) => {
  43. const day = i + 1;
  44. return { label: day.toString(), value: day.toString() };
  45. });
  46. const genderDropdownOptions = [
  47. { label: '男', value: 'man' },
  48. { label: '女', value: 'woman' }
  49. ];
  50. const handleSelect = (type: string, value: string) => {
  51. if (type === 'year') {
  52. setSelectedYear(value);
  53. } else if (type === 'month') {
  54. setSelectedMonth(value);
  55. } else if (type === 'day') {
  56. setSelectedDay(value);
  57. }
  58. if (selectedMonth && selectedDay) {
  59. const day = selectedDay.padStart(2, '0');
  60. const month = selectedMonth.padStart(2, '0');
  61. const date = `${day}/${month}/11`;
  62. setBirthDate(date);
  63. }
  64. };
  65. return (
  66. <>
  67. <View style={styles.container}>
  68. <Text style={styles.text}>請填妥以下資料</Text>
  69. <View
  70. className=""
  71. style={{
  72. display: 'flex',
  73. flexDirection: 'column',
  74. gap: 10
  75. }}
  76. >
  77. <NormalInput
  78. value={signUpFormData.nickName}
  79. placeholder={nameFieldPlaceholder}
  80. onChangeText={(text) => {
  81. setSignUpFormData({
  82. ...signUpFormData,
  83. nickName: text
  84. });
  85. }}
  86. />
  87. <NormalInput
  88. placeholder="帳戶密碼"
  89. onChangeText={(text) => {
  90. setSignUpFormData({
  91. ...signUpFormData,
  92. password: text
  93. });
  94. }}
  95. secureTextEntry={true}
  96. />
  97. <View className="">
  98. {/* <TestingDropDownSelect
  99. dropdownOptions={genderDropdownOptions}
  100. onSelect={(value) => {
  101. setSignUpFormData({
  102. ...signUpFormData,
  103. gender: value
  104. });
  105. }}
  106. placeholder={'性別'}
  107. extendedStyle={{ paddingLeft: 10, paddingVertical: 13 }}
  108. /> */}
  109. <DropdownSelect
  110. onSelect={(value) => {
  111. setSignUpFormData({
  112. ...signUpFormData,
  113. gender: value
  114. });
  115. }}
  116. dropdownOptions={genderDropdownOptions}
  117. placeholder={'性別'}
  118. extendedStyle={{ paddingLeft: 10, paddingVertical: 18 }}
  119. />
  120. </View>
  121. <View className="flex flex-row">
  122. <DropdownSelect
  123. onSelect={(value) => {
  124. setSignUpFormData({
  125. ...signUpFormData,
  126. birthDateMonth: value.padStart(2, '0')
  127. });
  128. }}
  129. dropdownOptions={birthMonthOptions}
  130. placeholder={'生日月份'}
  131. extendedStyle={{ paddingLeft: 10, paddingVertical: 18, marginRight: 6 }}
  132. />
  133. <DropdownSelect
  134. onSelect={(value) => {
  135. setSignUpFormData({
  136. ...signUpFormData,
  137. birthDateDay: value.padStart(2, '0')
  138. });
  139. }}
  140. dropdownOptions={birthDayOptions}
  141. placeholder={'日期'}
  142. extendedStyle={{ paddingLeft: 10, paddingVertical: 18, marginLeft: 6 }}
  143. />
  144. </View>
  145. <NormalButton
  146. title={<Text style={{ color: '#fff' }}>下一步</Text>}
  147. onPress={handleNext}
  148. extendedStyle={{}}
  149. />
  150. </View>
  151. {error && <Text style={styles.errorMessage}>{error}</Text>}
  152. </View>
  153. </>
  154. );
  155. };
  156. const styles = StyleSheet.create({
  157. container: {
  158. flex: 1,
  159. marginHorizontal: 20
  160. },
  161. text: {
  162. fontSize: 20,
  163. paddingBottom: 10
  164. },
  165. errorMessage: {
  166. fontSize: 14,
  167. color: '#ff0033',
  168. fontWeight: '400',
  169. marginLeft: 10,
  170. marginTop: 10
  171. }
  172. });
  173. export default BasicInformation;