createWallet.tsx 2.7 KB

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