carInformation.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. type CarInformationProps = {
  7. goToNextPage: () => void;
  8. handleFormDataChange: HandleSignUpFormDataChange;
  9. formData: SignUpFormData;
  10. };
  11. const CarInformation: React.FC<CarInformationProps> = ({ goToNextPage, handleFormDataChange, formData }) => {
  12. const [error, setError] = useState("");
  13. const handleNext = () => {
  14. if (formData.vehicleModel === "" || formData.vehicleModel === "" || formData.licensePlate === "") {
  15. setError("請確保所有資料都已填寫。");
  16. } else {
  17. setError("");
  18. goToNextPage();
  19. }
  20. };
  21. return (
  22. <>
  23. <View style={styles.container}>
  24. <Text style={styles.text}>您的車輛</Text>
  25. <View
  26. style={{
  27. display: "flex",
  28. flexDirection: "column",
  29. gap: 10,
  30. }}
  31. >
  32. <NormalInput
  33. placeholder={"車輛品牌"}
  34. onChangeText={(vehicleType) => handleFormDataChange("vehicleType", vehicleType)}
  35. />
  36. <NormalInput
  37. placeholder={"車輛型號"}
  38. onChangeText={(vehicleModel) => handleFormDataChange("vehicleModel", vehicleModel)}
  39. />
  40. <NormalInput
  41. placeholder="車輛號碼"
  42. onChangeText={(licensePlate) => handleFormDataChange("licensePlate", licensePlate)}
  43. />
  44. <NormalButton
  45. title={<Text style={{ color: "#fff" }}>下一步</Text>}
  46. onPress={handleNext}
  47. extendedStyle={{}}
  48. />
  49. {error && <Text style={styles.errorMessage}>{error}</Text>}
  50. <NormalButton
  51. title={<Text style={{ color: "#888888" }}>略過</Text>}
  52. onPress={goToNextPage}
  53. extendedStyle={{ backgroundColor: "transparent" }}
  54. />
  55. </View>
  56. </View>
  57. </>
  58. );
  59. };
  60. const styles = StyleSheet.create({
  61. container: {
  62. flex: 1,
  63. marginHorizontal: 20,
  64. },
  65. text: {
  66. fontSize: 20,
  67. paddingBottom: 10,
  68. },
  69. errorMessage: {
  70. fontSize: 14,
  71. color: "#ff0033",
  72. fontWeight: "400",
  73. marginLeft: 10,
  74. marginTop: 10,
  75. },
  76. });
  77. export default CarInformation;