carInformation.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { View, Text, StyleSheet } from "react-native";
  2. import { SignUpFormData, HandleSignUpFormDataChange } from "../../../../types/signup";
  3. import NormalInput from "../../../global/normal_input";
  4. import NormalButton from "../../../global/normal_button";
  5. import { useState } from "react";
  6. import useSignUpStore from "../../../../providers/signup_form_store";
  7. type CarInformationProps = {
  8. goToNextPage: () => void;
  9. handleFormDataChange: HandleSignUpFormDataChange;
  10. formData: SignUpFormData;
  11. };
  12. const CarInformation: React.FC<CarInformationProps> = ({ goToNextPage, handleFormDataChange, formData }) => {
  13. const { signUpFormData, setSignUpFormData } = useSignUpStore();
  14. const [error, setError] = useState("");
  15. const handleNext = () => {
  16. if (
  17. signUpFormData.vehicleModel === "" ||
  18. signUpFormData.vehicleModel === "" ||
  19. signUpFormData.licensePlate === ""
  20. ) {
  21. setError("請確保所有資料都已填寫。");
  22. } else {
  23. setError("");
  24. goToNextPage();
  25. }
  26. };
  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. placeholder={"車輛品牌"}
  40. onChangeText={(vehicleType) => {
  41. setSignUpFormData({ ...signUpFormData, vehicleType: vehicleType });
  42. }}
  43. />
  44. <NormalInput
  45. placeholder={"車輛型號"}
  46. onChangeText={(vehicleModel) => {
  47. setSignUpFormData({ ...signUpFormData, vehicleModel: vehicleModel });
  48. }}
  49. />
  50. <NormalInput
  51. placeholder="車輛號碼"
  52. onChangeText={(licensePlate) => {
  53. setSignUpFormData({ ...signUpFormData, licensePlate: licensePlate });
  54. }}
  55. />
  56. <NormalButton
  57. title={<Text style={{ color: "#fff" }}>下一步</Text>}
  58. onPress={handleNext}
  59. extendedStyle={{}}
  60. />
  61. {error && <Text style={styles.errorMessage}>{error}</Text>}
  62. <NormalButton
  63. title={<Text style={{ color: "#888888" }}>略過</Text>}
  64. onPress={goToNextPage}
  65. extendedStyle={{ backgroundColor: "transparent" }}
  66. />
  67. </View>
  68. </View>
  69. </>
  70. );
  71. };
  72. const styles = StyleSheet.create({
  73. container: {
  74. flex: 1,
  75. marginHorizontal: 20,
  76. },
  77. text: {
  78. fontSize: 20,
  79. paddingBottom: 10,
  80. },
  81. errorMessage: {
  82. fontSize: 14,
  83. color: "#ff0033",
  84. fontWeight: "400",
  85. marginLeft: 10,
  86. marginTop: 10,
  87. },
  88. });
  89. export default CarInformation;