basicInformation.tsx 6.7 KB

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