basicInformation.tsx 7.1 KB

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