index.jsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import React, {useEffect, useState} from "react";
  2. import Popup from "@components/Popup";
  3. import styles from "./styles.module.scss";
  4. import usdimg from "@assets/lvicon/USD.black.png";
  5. import {Controller, useForm} from "react-hook-form";
  6. import PhoneInput from "@components/UInput/PhoneInput";
  7. import classNames from "classnames";
  8. import PasswordInput from "@components/UInput/PasswordInput";
  9. import {validateCountryPhone} from "@utils/helpers";
  10. import {REQ_STATUS} from "@api/config";
  11. const i18n=global.i18n;
  12. const WBindPhone=({})=>{
  13. const [isShow, setIsShow] = useState(false);
  14. const regCoins=5;
  15. const [country, setCountry] = useState("55");
  16. const {register, handleSubmit, formState: {errors}, control} = useForm({
  17. defaultValues: {
  18. phone: '',
  19. password: '',
  20. repassword:'',
  21. code:''
  22. }
  23. });
  24. // /bindsms {phone,code,password,repassword}
  25. const show=()=>{
  26. setIsShow(true);
  27. }
  28. const hide=()=>{
  29. setIsShow(false);
  30. }
  31. const validatePhone=(value)=>{
  32. return validateCountryPhone(country,value);
  33. }
  34. const onSubmitBind=(data)=>{
  35. }
  36. useEffect(()=>{
  37. const bindPhone={
  38. show,
  39. hide
  40. };
  41. global.bindPhone=bindPhone;
  42. },[])
  43. return (
  44. <Popup onClose={hide} open={isShow}>
  45. <div className={styles.container}>
  46. <span className={styles.title}>
  47. {i18n.t("bindPhone.title_link_phone")}
  48. </span>
  49. <div className={styles.award_con}>
  50. {i18n.t("bindPhone.phone_award")}
  51. <img src={usdimg}/>
  52. {regCoins}
  53. </div>
  54. <form autoComplete="off" className={styles.l_form} onSubmit={handleSubmit((data) => {
  55. onSubmitBind(data);
  56. })}>
  57. <Controller control={control}
  58. name="phone"
  59. rules={{required: true, validate: validatePhone}}
  60. render={({field: {ref, onChange, value}, fieldState: {error}}) => {
  61. let message = error ? i18n.t("form_errors.phone_" + country) : "";
  62. return (<PhoneInput
  63. className={classNames({'input-control--error': error})}
  64. value={value}
  65. message={message}
  66. onChange={e => onChange(e.target.value)}
  67. onChangeCountry={(country) => {
  68. setCountry(country);
  69. }}
  70. placeholder={i18n.t('login.phone_ph')}
  71. innerRef={ref}/>)
  72. }}
  73. />
  74. <Controller control={control}
  75. name="password"
  76. rules={{required: true, minLength: 6}}
  77. render={({field: {ref, onChange, value}, fieldState: {error}}) => (
  78. <PasswordInput
  79. className={classNames({'input-control--error': error})}
  80. value={value}
  81. message={error ? i18n.t("form_errors.pass") : ''}
  82. onChange={e => onChange(e.target.value)}
  83. placeholder={i18n.t('login.login_pwd')}
  84. innerRef={ref}/>
  85. )}
  86. />
  87. <Controller control={control}
  88. name="repassword"
  89. rules={{required: true, minLength: 6}}
  90. render={({field: {ref, onChange, value}, fieldState: {error}}) => (
  91. <PasswordInput
  92. className={classNames({'input-control--error': error})}
  93. value={value}
  94. message={error ? i18n.t("form_errors.pass") : ''}
  95. onChange={e => onChange(e.target.value)}
  96. placeholder={i18n.t('login.re_pwd')}
  97. innerRef={ref}/>
  98. )}
  99. />
  100. <Controller control={control}
  101. name="code"
  102. rules={{required: true}}
  103. render={({field: {ref, onChange, value}, fieldState: {error}}) => {
  104. return (
  105. <div className={`d-flex flex-column g-6`}>
  106. <div
  107. className={`input-control ${classNames({'input-control--error': error})}`}>
  108. <input
  109. type={'text'}
  110. autoComplete="off"
  111. ref={ref}
  112. onChange={e => onChange(e.target.value)}
  113. placeholder={i18n.t('login.otp_ph')}
  114. />
  115. <button type={"button"} className={styles.otp_btn}>OTP</button>
  116. </div>
  117. </div>
  118. )
  119. }}
  120. />
  121. <button className={"button-green"}>
  122. {
  123. i18n.t("bindPhone.btn_submit")
  124. }
  125. </button>
  126. <span className={styles.tips}>{i18n.t("bindPhone.tips")}</span>
  127. </form>
  128. </div>
  129. </Popup>
  130. )
  131. }
  132. export default WBindPhone;