BRAccountEdit.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import styles from "./styles.module.scss";
  2. import Spring from "@components/Spring";
  3. import React, {useEffect} from "react";
  4. import {ReactComponent as PixLogo} from "@assets/singlesvg/pix.svg";
  5. import {useDispatch, useSelector} from "react-redux";
  6. import {
  7. getWDBaseInfoStatus,
  8. getWDInfoStatus,
  9. getWDSetInfoStatus,
  10. getWithdrawBaseInfo,
  11. getWithdrawInfo
  12. } from "@features/paySlice";
  13. import SmallLoading from "@components/SmallLoading";
  14. import {reqWithdrawBaseInfo, reqWithdrawInfo, reqWithdrawSetInfo} from "@features/api";
  15. import {Controller, useForm} from "react-hook-form";
  16. import PasswordInput from "@components/UInput/PasswordInput";
  17. import classNames from "classnames";
  18. import {APP_GENDER} from "@constants/app";
  19. import {getUserInfo} from "@features/mainSlice";
  20. import {REQ_STATUS} from "@api/config";
  21. const i18n=global.i18n;
  22. const BRAccountEdit=({close})=>{
  23. const user=useSelector(getUserInfo);
  24. const baseStatus=useSelector(getWDBaseInfoStatus);
  25. const setStatus=useSelector(getWDSetInfoStatus);
  26. const infoStatus=useSelector(getWDInfoStatus);
  27. let info=useSelector(getWithdrawInfo);
  28. // if (info==null)info={};
  29. let dinfo=info==null?{}:info;
  30. const dispatch=useDispatch();
  31. const {register, handleSubmit, formState: {errors}, control} = useForm({
  32. values: {
  33. account: dinfo.AccountsBank||"",
  34. userName: dinfo.BankUserName||"",
  35. bank: dinfo.BankNO||"",
  36. branceBank: dinfo.BranchBank||"",
  37. phone: dinfo.PhoneNumber||"",
  38. PAN: dinfo.PANNumber||"",
  39. IFSC:dinfo.IFSCNumber||"",
  40. email: dinfo.EmailAddress||"",
  41. PixNum: dinfo.PixNum||"",
  42. adhaar: dinfo.AdhaarNumber||"",
  43. PixType: dinfo.PixType||"",
  44. }
  45. });
  46. useEffect(()=>{
  47. dispatch(reqWithdrawInfo({UserID:user.UserID}));
  48. },[])
  49. const checkLockStatus=()=>{
  50. if (baseStatus===REQ_STATUS.LOADING)return true;
  51. if (setStatus===REQ_STATUS.LOADING)return true;
  52. return false;
  53. }
  54. // const callbackBase=(data)=>{
  55. // if (close)close();
  56. // }
  57. const callback=(data)=>{
  58. if (data&&data.code===200){
  59. // dispatch(reqWithdrawBaseInfo(callbackBase));
  60. close();
  61. }
  62. }
  63. const handleChange=(data)=>{
  64. if (checkLockStatus())return;
  65. data.callback=callback;
  66. dispatch(reqWithdrawSetInfo(data));
  67. }
  68. const renderPixLogo=()=>{
  69. return (
  70. <div className={styles.pix_title}>
  71. <PixLogo className={styles.logo}/>
  72. {i18n.t("deposit.order_info.pay_type_pix")}
  73. </div>
  74. )
  75. }
  76. const renderAccoutForm=()=>{
  77. return (
  78. <form autoComplete="off" className={styles.accout_form} onSubmit={handleSubmit((data) => {
  79. handleChange(data);
  80. })}>
  81. <Controller control={control}
  82. name="userName"
  83. rules={{required: true}}
  84. render={({field: {ref, onChange, value}, fieldState: {error}}) => (
  85. <div className={styles.form_item}>
  86. <div className={styles.title}>{i18n.t("withdraw.account.userName")}</div>
  87. <div className={`input-control ${error?'input-control--error':''}`}>
  88. <input
  89. value={value}
  90. onChange={e => onChange(e.target.value)}
  91. placeholder={i18n.t('withdraw.account.name_holder')}
  92. ref={ref}
  93. />
  94. </div>
  95. </div>
  96. )}
  97. />
  98. <Controller control={control}
  99. name="phone"
  100. rules={{required: true}}
  101. render={({field: {ref, onChange, value}, fieldState: {error}}) => (
  102. <div className={styles.form_item}>
  103. <div className={styles.title}>{i18n.t("withdraw.account.phone")}</div>
  104. <div className={`input-control ${error?'input-control--error':''}`}>
  105. <input
  106. value={value}
  107. onChange={e => onChange(e.target.value)}
  108. placeholder={i18n.t('withdraw.account.phone_holder')}
  109. ref={ref}
  110. />
  111. </div>
  112. </div>
  113. )}
  114. />
  115. <Controller control={control}
  116. name="email"
  117. rules={{required: true}}
  118. render={({field: {ref, onChange, value}, fieldState: {error}}) => (
  119. <div className={styles.form_item}>
  120. <div className={styles.title}>{i18n.t("withdraw.account.email")}</div>
  121. <div className={`input-control ${error?'input-control--error':''}`}>
  122. <input
  123. value={value}
  124. onChange={e => onChange(e.target.value)}
  125. placeholder={i18n.t('withdraw.account.email_holder')}
  126. ref={ref}
  127. />
  128. </div>
  129. </div>
  130. )}
  131. />
  132. <Controller control={control}
  133. name="PixNum"
  134. rules={{required: true}}
  135. render={({field: {ref, onChange, value}, fieldState: {error}}) => (
  136. <div className={styles.form_item}>
  137. <div className={styles.title}>{i18n.t("withdraw.account.cpf")}</div>
  138. <div className={`input-control ${error?'input-control--error':''}`}>
  139. <input
  140. value={value}
  141. onChange={e => onChange(e.target.value)}
  142. placeholder={i18n.t('withdraw.account.cpf_holder')}
  143. ref={ref}
  144. />
  145. </div>
  146. </div>
  147. )}
  148. />
  149. <Controller control={control}
  150. name="PixType"
  151. rules={{required: true}}
  152. render={({field: {ref, onChange, value}, fieldState: {error}}) => (
  153. <div className={styles.form_item}>
  154. <div className={styles.title}>{i18n.t("withdraw.account.cpf_dict")}</div>
  155. <div className={styles.pix_con}>
  156. <button type={"button"} className={`${styles.radio_btn} ${value==="1"?styles.active:''}`} onClick={()=>{
  157. onChange("1");
  158. }}>
  159. <div className={styles.circle}>
  160. <div className={styles.dot}/>
  161. </div>
  162. <div>{i18n.t("withdraw.account.cpf")}</div>
  163. </button>
  164. <button type={"button"} className={`${styles.radio_btn} ${value==="2"?styles.active:''}`} onClick={()=>{
  165. onChange("2");
  166. }}>
  167. <div className={styles.circle}>
  168. <div className={styles.dot}/>
  169. </div>
  170. <div>{i18n.t("withdraw.account.e_mail")}</div>
  171. </button>
  172. <button type={"button"} className={`${styles.radio_btn} ${value==="3"?styles.active:''}`} onClick={()=>{
  173. onChange("3");
  174. }}>
  175. <div className={styles.circle}>
  176. <div className={styles.dot}/>
  177. </div>
  178. <div>{i18n.t("withdraw.account.phone_type")}</div>
  179. </button>
  180. </div>
  181. </div>
  182. )}
  183. />
  184. <button className={"button-green"}>
  185. {checkLockStatus()?(<SmallLoading fill={"#FFF"}></SmallLoading>):i18n.t("withdraw.account.btn_save")}
  186. {/*{i18n.t("withdraw.account.btn_save")}*/}
  187. </button>
  188. <div className={styles.tips}>{i18n.t("withdraw.account.help")}</div>
  189. </form>
  190. )
  191. }
  192. return (
  193. <>
  194. {
  195. infoStatus===REQ_STATUS.LOADING?(
  196. <div className={styles.loading}>
  197. <SmallLoading/>
  198. </div>
  199. ):(
  200. <Spring type="slideUp" className={styles.container}>
  201. {renderPixLogo()}
  202. {renderAccoutForm()}
  203. </Spring>
  204. )
  205. }
  206. </>
  207. )
  208. }
  209. export default BRAccountEdit;