carInformation.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { View, Text, StyleSheet } from 'react-native';
  2. import NormalInput from '../../../global/normal_input';
  3. import NormalButton from '../../../global/normal_button';
  4. import { useState } from 'react';
  5. import useSignUpStore from '../../../../providers/signup_form_store';
  6. type CarInformationProps = {
  7. goToNextPage: () => void;
  8. };
  9. const CarInformation: React.FC<CarInformationProps> = ({ goToNextPage }) => {
  10. const { signUpFormData, setSignUpFormData } = useSignUpStore();
  11. const [error, setError] = useState('');
  12. const handleNext = () => {
  13. if (
  14. signUpFormData.vehicleModel === '' ||
  15. signUpFormData.vehicleModel === '' ||
  16. signUpFormData.licensePlate === ''
  17. ) {
  18. setError('請確保所有資料都已填寫。');
  19. } else {
  20. setError('');
  21. goToNextPage();
  22. }
  23. };
  24. const vehicleTypeFieldPlaceholder = signUpFormData.vehicleType
  25. ? signUpFormData.vehicleType
  26. : '車輛品牌';
  27. const vehicleModelFieldPlaceholder = signUpFormData.vehicleModel
  28. ? signUpFormData.vehicleModel
  29. : '車輛型號';
  30. const licensePlateFieldPlaceholder = signUpFormData.licensePlate
  31. ? signUpFormData.licensePlate
  32. : '車輛號碼';
  33. return (
  34. <>
  35. <View style={styles.container}>
  36. <Text style={styles.text}>您的車輛</Text>
  37. <View
  38. style={{
  39. display: 'flex',
  40. flexDirection: 'column',
  41. gap: 10
  42. }}
  43. >
  44. <NormalInput
  45. value={signUpFormData.vehicleType}
  46. placeholder={vehicleTypeFieldPlaceholder}
  47. onChangeText={(vehicleType) => {
  48. setSignUpFormData({
  49. ...signUpFormData,
  50. vehicleType: vehicleType
  51. });
  52. }}
  53. />
  54. <NormalInput
  55. value={signUpFormData.vehicleModel}
  56. placeholder={vehicleModelFieldPlaceholder}
  57. onChangeText={(vehicleModel) => {
  58. setSignUpFormData({
  59. ...signUpFormData,
  60. vehicleModel: vehicleModel
  61. });
  62. }}
  63. />
  64. <NormalInput
  65. value={signUpFormData.licensePlate}
  66. placeholder={licensePlateFieldPlaceholder}
  67. onChangeText={(licensePlate) => {
  68. setSignUpFormData({
  69. ...signUpFormData,
  70. licensePlate: licensePlate
  71. });
  72. }}
  73. />
  74. <NormalButton
  75. title={<Text style={{ color: '#fff' }}>下一步</Text>}
  76. onPress={handleNext}
  77. extendedStyle={{}}
  78. />
  79. {error && <Text style={styles.errorMessage}>{error}</Text>}
  80. <NormalButton
  81. title={<Text style={{ color: '#888888' }}>略過</Text>}
  82. onPress={goToNextPage}
  83. extendedStyle={{ backgroundColor: 'transparent' }}
  84. />
  85. </View>
  86. </View>
  87. </>
  88. );
  89. };
  90. const styles = StyleSheet.create({
  91. container: {
  92. flex: 1,
  93. marginHorizontal: 20
  94. },
  95. text: {
  96. fontSize: 20,
  97. paddingBottom: 10
  98. },
  99. errorMessage: {
  100. fontSize: 14,
  101. color: '#ff0033',
  102. fontWeight: '400',
  103. marginLeft: 10,
  104. marginTop: 10
  105. }
  106. });
  107. export default CarInformation;