basicInformation.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 { FormData, HandleFormDataChange } from "../../../type";
  7. type basicInformationProps = {
  8. goToNextPage: () => void;
  9. handleFormDataChange: HandleFormDataChange;
  10. formData: FormData;
  11. };
  12. const BasicInformation: React.FC<basicInformationProps> = ({ handleFormDataChange, goToNextPage, formData }) => {
  13. const [error, setError] = useState("");
  14. const handleNext = () => {
  15. if (formData.name === "" || formData.password === "" || formData.birthDate === "") {
  16. setError("請確保所有資料都已填寫。");
  17. } else {
  18. setError("");
  19. goToNextPage();
  20. }
  21. };
  22. return (
  23. <>
  24. <View style={styles.container}>
  25. <Text style={styles.text}>請填妥以下資料</Text>
  26. <View
  27. style={{
  28. display: "flex",
  29. flexDirection: "column",
  30. gap: 10,
  31. }}
  32. >
  33. <NormalInput
  34. placeholder={formData.name ? formData.name : "姓名"}
  35. onChangeText={(text) => handleFormDataChange("name", text)}
  36. />
  37. <NormalInput
  38. placeholder="帳戶密碼"
  39. onChangeText={(text) => handleFormDataChange("password", text)}
  40. secureTextEntry={true}
  41. />
  42. <View style={{ display: "flex", flexDirection: "row", gap: 10 }}>
  43. {/* await YoYo's code review for gender */}
  44. <NormalInput
  45. placeholder="性別"
  46. onChangeText={(t) => console.log(t)}
  47. extendedStyle={{ width: "50%" }}
  48. />
  49. <DateModal
  50. // placeholder="出生日期"
  51. placeholder={formData.birthDate ? formData.birthDate : "DD/MM/YY"}
  52. onDateChange={(date) => {
  53. handleFormDataChange("birthDate", date);
  54. }}
  55. />
  56. </View>
  57. <NormalButton
  58. title={<Text style={{ color: "#fff" }}>下一步</Text>}
  59. onPress={handleNext}
  60. extendedStyle={{}}
  61. />
  62. </View>
  63. {error && <Text style={styles.errorMessage}>{error}</Text>}
  64. </View>
  65. </>
  66. );
  67. };
  68. const styles = StyleSheet.create({
  69. container: {
  70. flex: 1,
  71. marginHorizontal: 20,
  72. },
  73. text: {
  74. fontSize: 20,
  75. paddingBottom: 10,
  76. },
  77. errorMessage: {
  78. fontSize: 14,
  79. color: "#ff0033",
  80. fontWeight: "400",
  81. marginLeft: 10,
  82. marginTop: 10,
  83. },
  84. });
  85. export default BasicInformation;