basicInformation.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 useSignUpStore from "../../../../providers/signup_form_store";
  7. type basicInformationProps = {
  8. goToNextPage: () => void;
  9. };
  10. const BasicInformation: React.FC<basicInformationProps> = ({ goToNextPage }) => {
  11. const { signUpFormData, setSignUpFormData } = useSignUpStore();
  12. const [error, setError] = useState("");
  13. const handleNext = () => {
  14. if (signUpFormData.name === "" || signUpFormData.password === "" || signUpFormData.birthDate === "") {
  15. setError("請確保所有資料都已填寫。");
  16. } else {
  17. setError("");
  18. goToNextPage();
  19. }
  20. };
  21. const nameFieldPlaceholder = signUpFormData.name ? signUpFormData.name : "姓名";
  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. value={signUpFormData.name}
  35. placeholder={nameFieldPlaceholder}
  36. onChangeText={(text) => {
  37. setSignUpFormData({ ...signUpFormData, name: text });
  38. }}
  39. />
  40. <NormalInput
  41. placeholder="帳戶密碼"
  42. onChangeText={(text) => {
  43. setSignUpFormData({ ...signUpFormData, password: text });
  44. }}
  45. secureTextEntry={true}
  46. />
  47. <View style={{ display: "flex", flexDirection: "row", gap: 10 }}>
  48. {/* await YoYo's code review for gender */}
  49. <NormalInput
  50. placeholder="性別"
  51. onChangeText={(t) => console.log(t)}
  52. extendedStyle={{ width: "50%" }}
  53. />
  54. <DateModal
  55. placeholder={signUpFormData.birthDate ? signUpFormData.birthDate : "DD/MM/YY"}
  56. onDateChange={(date) => {
  57. setSignUpFormData({ ...signUpFormData, birthDate: date });
  58. }}
  59. />
  60. </View>
  61. <NormalButton
  62. title={<Text style={{ color: "#fff" }}>下一步</Text>}
  63. onPress={handleNext}
  64. extendedStyle={{}}
  65. />
  66. </View>
  67. {error && <Text style={styles.errorMessage}>{error}</Text>}
  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 BasicInformation;