basicInformation.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 { useTranslation } from '../../../../util/hooks/useTranslation';
  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 { t, ready, currentLanguage } = useTranslation();
  20. const handleNext = () => {
  21. setSignUpFormData({
  22. ...signUpFormData,
  23. birthDate: birthDate
  24. });
  25. if (
  26. signUpFormData.nickName === '' ||
  27. signUpFormData.gender === '' ||
  28. signUpFormData.birthDateMonth === '' ||
  29. signUpFormData.birthDateDay === ''
  30. ) {
  31. setError(t("register.three.error1"));
  32. } else {
  33. setError('');
  34. goToNextPage();
  35. }
  36. };
  37. const nameFieldPlaceholder = signUpFormData.nickName ? signUpFormData.nickName : t("register.three.name");
  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}>{t("register.three.label")}</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. <View className="">
  88. <DropdownSelect
  89. onSelect={(value) => {
  90. setSignUpFormData({
  91. ...signUpFormData,
  92. gender: value
  93. });
  94. }}
  95. dropdownOptions={genderDropdownOptions}
  96. placeholder={
  97. signUpFormData.gender
  98. ? genderDropdownOptions.find((option) => option.value === signUpFormData.gender)
  99. ?.label || t("register.three.sex")
  100. : t("register.three.sex")
  101. }
  102. extendedStyle={{ paddingLeft: 10, paddingVertical: 18 }}
  103. />
  104. </View>
  105. <View className="flex flex-row">
  106. <DropdownSelect
  107. onSelect={(value) => {
  108. setSignUpFormData({
  109. ...signUpFormData,
  110. birthDateMonth: value.padStart(2, '0')
  111. });
  112. }}
  113. dropdownOptions={birthMonthOptions}
  114. placeholder={`${
  115. signUpFormData.birthDateMonth
  116. ? parseInt(signUpFormData.birthDateMonth).toString()
  117. : t("register.three.mm")
  118. }`}
  119. extendedStyle={{ paddingLeft: 10, paddingVertical: 18, marginRight: 6 }}
  120. />
  121. <DropdownSelect
  122. onSelect={(value) => {
  123. setSignUpFormData({
  124. ...signUpFormData,
  125. birthDateDay: value.padStart(2, '0')
  126. });
  127. }}
  128. dropdownOptions={birthDayOptions}
  129. // placeholder={'日期'}
  130. placeholder={`${
  131. signUpFormData.birthDateDay
  132. ? parseInt(signUpFormData.birthDateDay).toString()
  133. : t("register.three.dd")
  134. }`}
  135. extendedStyle={{ paddingLeft: 10, paddingVertical: 18, marginLeft: 6 }}
  136. />
  137. </View>
  138. <NormalButton
  139. title={<Text style={{ color: '#fff' }}>{t("register.three.next")}</Text>}
  140. onPress={handleNext}
  141. extendedStyle={{}}
  142. />
  143. <View className="mb-4" />
  144. </View>
  145. {error && <Text style={styles.errorMessage}>{error}</Text>}
  146. </View>
  147. </>
  148. );
  149. };
  150. const styles = StyleSheet.create({
  151. container: {
  152. flex: 1,
  153. marginHorizontal: 20
  154. },
  155. text: {
  156. fontSize: 20,
  157. paddingBottom: 10
  158. },
  159. errorMessage: {
  160. fontSize: 14,
  161. color: '#ff0033',
  162. fontWeight: '400',
  163. marginLeft: 10,
  164. marginTop: 10
  165. }
  166. });
  167. export default BasicInformation;