basicInformation.tsx 7.8 KB

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