basicInformation.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 {
  7. SignUpFormData,
  8. HandleSignUpFormDataChange
  9. } from '../../../../types/signup';
  10. import DropdownSelect from '../../../global/dropdown_select';
  11. type basicInformationProps = {
  12. goToNextPage: () => void;
  13. handleFormDataChange: HandleSignUpFormDataChange;
  14. formData: SignUpFormData;
  15. };
  16. const BasicInformation: React.FC<basicInformationProps> = ({
  17. handleFormDataChange,
  18. goToNextPage,
  19. formData
  20. }) => {
  21. const [error, setError] = useState('');
  22. const handleNext = () => {
  23. if (
  24. formData.name === '' ||
  25. formData.password === '' ||
  26. formData.birthDate === ''
  27. ) {
  28. setError('請確保所有資料都已填寫。');
  29. } else {
  30. setError('');
  31. goToNextPage();
  32. }
  33. };
  34. const dropdownOptions = [
  35. { label: '男', value: 'male' },
  36. { label: '女', value: 'female' },
  37. { label: 'Test Item 3', value: '3' },
  38. { label: 'Test Item 4', value: '4' },
  39. { label: 'Test Item 5', value: '5' },
  40. { label: 'Test Item 6', value: '6' },
  41. { label: 'Test Item 7', value: '7' },
  42. { label: 'Test Item 8', value: '8' }
  43. ];
  44. return (
  45. <>
  46. <View style={styles.container}>
  47. <Text style={styles.text}>請填妥以下資料</Text>
  48. <View
  49. style={{
  50. display: 'flex',
  51. flexDirection: 'column',
  52. gap: 10
  53. }}
  54. >
  55. <NormalInput
  56. placeholder="姓名"
  57. onChangeText={(text) =>
  58. handleFormDataChange('name', text)
  59. }
  60. />
  61. <NormalInput
  62. placeholder="帳戶密碼"
  63. onChangeText={(text) =>
  64. handleFormDataChange('password', text)
  65. }
  66. secureTextEntry={true}
  67. />
  68. <View
  69. style={{
  70. display: 'flex',
  71. flexDirection: 'row',
  72. gap: 10
  73. }}
  74. >
  75. <DropdownSelect
  76. onSelect={(value) =>
  77. handleFormDataChange('gender', value)
  78. }
  79. dropdownOptions={dropdownOptions}
  80. placeholder={'性別'}
  81. />
  82. <DateModal
  83. placeholder={
  84. formData.birthDate
  85. ? formData.birthDate
  86. : 'DD/MM/YY'
  87. }
  88. onDateChange={(date) => {
  89. handleFormDataChange('birthDate', date);
  90. }}
  91. />
  92. </View>
  93. <NormalButton
  94. title={<Text style={{ color: '#fff' }}>下一步</Text>}
  95. onPress={handleNext}
  96. extendedStyle={{}}
  97. />
  98. </View>
  99. {error && <Text style={styles.errorMessage}>{error}</Text>}
  100. </View>
  101. </>
  102. );
  103. };
  104. const styles = StyleSheet.create({
  105. container: {
  106. flex: 1,
  107. marginHorizontal: 20
  108. },
  109. text: {
  110. fontSize: 20,
  111. paddingBottom: 10
  112. },
  113. errorMessage: {
  114. fontSize: 14,
  115. color: '#ff0033',
  116. fontWeight: '400',
  117. marginLeft: 10,
  118. marginTop: 10
  119. }
  120. });
  121. export default BasicInformation;