carInformation.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 ? signUpFormData.vehicleType : "車輛品牌";
  25. const vehicleModelFieldPlaceholder = signUpFormData.vehicleModel ? signUpFormData.vehicleModel : "車輛型號";
  26. const licensePlateFieldPlaceholder = signUpFormData.licensePlate ? signUpFormData.licensePlate : "車輛號碼";
  27. return (
  28. <>
  29. <View style={styles.container}>
  30. <Text style={styles.text}>您的車輛</Text>
  31. <View
  32. style={{
  33. display: "flex",
  34. flexDirection: "column",
  35. gap: 10,
  36. }}
  37. >
  38. <NormalInput
  39. value={signUpFormData.vehicleType}
  40. placeholder={vehicleTypeFieldPlaceholder}
  41. onChangeText={(vehicleType) => {
  42. setSignUpFormData({ ...signUpFormData, vehicleType: vehicleType });
  43. }}
  44. />
  45. <NormalInput
  46. value={signUpFormData.vehicleModel}
  47. placeholder={vehicleModelFieldPlaceholder}
  48. onChangeText={(vehicleModel) => {
  49. setSignUpFormData({ ...signUpFormData, vehicleModel: vehicleModel });
  50. }}
  51. />
  52. <NormalInput
  53. value={signUpFormData.licensePlate}
  54. placeholder={licensePlateFieldPlaceholder}
  55. onChangeText={(licensePlate) => {
  56. setSignUpFormData({ ...signUpFormData, licensePlate: licensePlate });
  57. }}
  58. />
  59. <NormalButton
  60. title={<Text style={{ color: "#fff" }}>下一步</Text>}
  61. onPress={handleNext}
  62. extendedStyle={{}}
  63. />
  64. {error && <Text style={styles.errorMessage}>{error}</Text>}
  65. <NormalButton
  66. title={<Text style={{ color: "#888888" }}>略過</Text>}
  67. onPress={goToNextPage}
  68. extendedStyle={{ backgroundColor: "transparent" }}
  69. />
  70. </View>
  71. </View>
  72. </>
  73. );
  74. };
  75. const styles = StyleSheet.create({
  76. container: {
  77. flex: 1,
  78. marginHorizontal: 20,
  79. },
  80. text: {
  81. fontSize: 20,
  82. paddingBottom: 10,
  83. },
  84. errorMessage: {
  85. fontSize: 14,
  86. color: "#ff0033",
  87. fontWeight: "400",
  88. marginLeft: 10,
  89. marginTop: 10,
  90. },
  91. });
  92. export default CarInformation;