createWallet.tsx 2.8 KB

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