createWallet.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 SingleSelectButtonGroup from "../../../global/select_button";
  7. import useSignUpStore from "../../../../providers/signup_form_store";
  8. type CreateWalletProps = {
  9. goToNextPage: () => void;
  10. handleFormDataChange: HandleSignUpFormDataChange;
  11. formData: SignUpFormData;
  12. };
  13. const creditCard = "信用卡";
  14. const weChatAliPay = "微信支付/支付寶";
  15. const CreateWallet: React.FC<CreateWalletProps> = ({ goToNextPage, handleFormDataChange, formData }) => {
  16. const options = [{ label: creditCard }, { label: weChatAliPay }];
  17. const { signUpFormData, setSignUpFormData } = useSignUpStore();
  18. const handleSelectedChange = (selectedLabel: string) => {
  19. handleFormDataChange("paymentMethod", selectedLabel);
  20. setError("");
  21. };
  22. const handleNext = () => {
  23. if (signUpFormData.paymentMethod === "" || signUpFormData.email === "" || signUpFormData.address === "") {
  24. setError("請確保所有資料都已填寫。");
  25. } else {
  26. setError("");
  27. goToNextPage();
  28. }
  29. };
  30. const selectLabelShown = () => {
  31. if (signUpFormData.paymentMethod == null) {
  32. return null;
  33. } else if (signUpFormData.paymentMethod == creditCard) {
  34. return creditCard;
  35. } else if (signUpFormData.paymentMethod == weChatAliPay) {
  36. return weChatAliPay;
  37. }
  38. };
  39. const [error, setError] = useState("");
  40. return (
  41. <>
  42. <View style={styles.container}>
  43. <Text style={styles.text}>請填妥以下資料</Text>
  44. <View
  45. style={{
  46. display: "flex",
  47. flexDirection: "column",
  48. gap: 10,
  49. }}
  50. >
  51. <NormalInput
  52. placeholder={"電子郵件"}
  53. // onChangeText={(email) => handleFormDataChange("email", email)}
  54. onChangeText={(email) => {
  55. setSignUpFormData( ...signUpFormData, email: email )
  56. }}
  57. />
  58. <NormalInput
  59. placeholder="地址"
  60. onChangeText={(address) => handleFormDataChange("address", address)}
  61. />
  62. <SingleSelectButtonGroup
  63. options={options}
  64. onSelectionChange={handleSelectedChange}
  65. shouldShowRedOutline={error ? true : false}
  66. selectedOption={selectLabelShown()}
  67. />
  68. <NormalButton
  69. title={<Text style={{ color: "#fff" }}>完成</Text>}
  70. onPress={handleNext}
  71. extendedStyle={{}}
  72. />
  73. <NormalButton
  74. title={<Text style={{ color: "#888888" }}>略過</Text>}
  75. onPress={goToNextPage}
  76. extendedStyle={{ backgroundColor: "transparent" }}
  77. />
  78. </View>
  79. {error && <Text style={styles.errorMessage}>{error}</Text>}
  80. </View>
  81. </>
  82. );
  83. };
  84. const styles = StyleSheet.create({
  85. container: {
  86. flex: 1,
  87. marginHorizontal: 20,
  88. },
  89. text: {
  90. fontSize: 20,
  91. paddingBottom: 10,
  92. },
  93. errorMessage: {
  94. fontSize: 14,
  95. color: "#ff0033",
  96. fontWeight: "400",
  97. marginLeft: 10,
  98. marginTop: 10,
  99. },
  100. });
  101. export default CreateWallet;