basicInformation.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 { SignUpFormData, HandleSignUpFormDataChange } from "../../../../types/signup";
  7. type basicInformationProps = {
  8. goToNextPage: () => void;
  9. handleFormDataChange: HandleSignUpFormDataChange;
  10. formData: SignUpFormData;
  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 placeholder="姓名" onChangeText={(text) => handleFormDataChange("name", text)} />
  34. <NormalInput
  35. placeholder="帳戶密碼"
  36. onChangeText={(text) => handleFormDataChange("password", text)}
  37. secureTextEntry={true}
  38. />
  39. <View style={{ display: "flex", flexDirection: "row", gap: 10 }}>
  40. {/* await YoYo's code review for gender */}
  41. <NormalInput
  42. placeholder="性別"
  43. onChangeText={(t) => console.log(t)}
  44. extendedStyle={{ width: "50%" }}
  45. />
  46. <DateModal
  47. placeholder={formData.birthDate ? formData.birthDate : "DD/MM/YY"}
  48. onDateChange={(date) => {
  49. handleFormDataChange("birthDate", date);
  50. }}
  51. />
  52. </View>
  53. <NormalButton
  54. title={<Text style={{ color: "#fff" }}>下一步</Text>}
  55. onPress={handleNext}
  56. extendedStyle={{}}
  57. />
  58. </View>
  59. {error && <Text style={styles.errorMessage}>{error}</Text>}
  60. </View>
  61. </>
  62. );
  63. };
  64. const styles = StyleSheet.create({
  65. container: {
  66. flex: 1,
  67. marginHorizontal: 20,
  68. },
  69. text: {
  70. fontSize: 20,
  71. paddingBottom: 10,
  72. },
  73. errorMessage: {
  74. fontSize: 14,
  75. color: "#ff0033",
  76. fontWeight: "400",
  77. marginLeft: 10,
  78. marginTop: 10,
  79. },
  80. });
  81. export default BasicInformation;