|
@@ -1,14 +1,34 @@
|
|
|
-import { FC, PropsWithChildren } from "react";
|
|
|
+"use client";
|
|
|
+import { FC, PropsWithChildren, useState } from "react";
|
|
|
import ButtonOwn from "@/components/ButtonOwn";
|
|
|
import './page.scss'
|
|
|
import { useTranslations } from "next-intl";
|
|
|
+import { getUserRechargeApi } from "@/api/user";
|
|
|
+import { useGlobalStore } from '@/stores';
|
|
|
+import { Toast } from 'antd-mobile'
|
|
|
|
|
|
interface Props {}
|
|
|
|
|
|
+let amountList = [10,20,50,100,200,500,1000,5000,10000]
|
|
|
+
|
|
|
const Deposit: FC<PropsWithChildren<Props>> = () => {
|
|
|
const t = useTranslations("DepositPage");
|
|
|
- let amount = 50
|
|
|
- let amountList = [10,20,50,100,200,500,1000,5000,10000]
|
|
|
+ const { userInfo } = useGlobalStore();
|
|
|
+
|
|
|
+ let [amount, setAmount] = useState(0)
|
|
|
+ const ChangeAmount = (e: any) => {
|
|
|
+ let newAmount = e.target.value.replace(/[^0-9]/g, '')
|
|
|
+ setAmount(newAmount)
|
|
|
+ }
|
|
|
+
|
|
|
+ const userRechargeRequest = async () => {
|
|
|
+ if(amount < 10) return
|
|
|
+ let res = await getUserRechargeApi({amount: parseInt(amount as any), user_id: userInfo.id})
|
|
|
+ if(res.code == 200) {
|
|
|
+ setAmount(0)
|
|
|
+ Toast.show({ icon: 'success', content: t("RechargeSuc"), maskClickable: false })
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
|
<div className="deposit-box">
|
|
@@ -16,13 +36,13 @@ const Deposit: FC<PropsWithChildren<Props>> = () => {
|
|
|
<p className="btn-box" color="primary">PIX Ⅰ</p>
|
|
|
<div className="amount-box">
|
|
|
<span>{t('Montante')} (BRL):</span>
|
|
|
- <input type="number" placeholder="Mín. 10.00"/>
|
|
|
+ <input type="number" value={amount} onChange={ChangeAmount} placeholder="Mín. 10.00"/>
|
|
|
</div>
|
|
|
<ul className="ul-box">
|
|
|
{
|
|
|
amountList.map((item, index) => (
|
|
|
- <li className={amount==item?'active':''} key={index}>
|
|
|
- <span className="hot"></span>
|
|
|
+ <li className={amount==item?'active':''} key={index} onClick={() => setAmount(item)}>
|
|
|
+ { (index == 2 || index == 3 || index == 6) && <span className="hot"></span> }
|
|
|
<div className="amountContent">
|
|
|
{/* <span className="iconfont icon-unit-brl"></span> */}
|
|
|
<span className="iconfont">R$</span>
|
|
@@ -34,7 +54,7 @@ const Deposit: FC<PropsWithChildren<Props>> = () => {
|
|
|
}
|
|
|
</ul>
|
|
|
<div className="topUp">
|
|
|
- <ButtonOwn active={amount>0?true:false}>{t('DepositarAgora')}</ButtonOwn>
|
|
|
+ <ButtonOwn active={amount>=10?true:false} callbackFun={userRechargeRequest}>{t('DepositarAgora')}</ButtonOwn>
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|