diff --git a/apps/user/src/sections/user/affiliate/index.tsx b/apps/user/src/sections/user/affiliate/index.tsx index f36b62a1..1131f968 100644 --- a/apps/user/src/sections/user/affiliate/index.tsx +++ b/apps/user/src/sections/user/affiliate/index.tsx @@ -1,6 +1,6 @@ "use client"; -import { useMutation, useQuery } from "@tanstack/react-query"; +import { useQuery } from "@tanstack/react-query"; import { Button } from "@workspace/ui/components/button"; import { Card, @@ -9,26 +9,13 @@ import { CardHeader, CardTitle, } from "@workspace/ui/components/card"; -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@workspace/ui/components/dialog"; -import { Input } from "@workspace/ui/components/input"; -import { Textarea } from "@workspace/ui/components/textarea"; import { ProList } from "@workspace/ui/composed/pro-list/pro-list"; import { - commissionWithdraw, queryUserAffiliate, queryUserAffiliateList, } from "@workspace/ui/services/user/user"; import { formatDate } from "@workspace/ui/utils/formatting"; import { Copy } from "lucide-react"; -import { type FormEvent, useState } from "react"; import { CopyToClipboard } from "react-copy-to-clipboard"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; @@ -37,59 +24,14 @@ import { useGlobalStore } from "@/stores/global"; export default function Affiliate() { const { t } = useTranslation("affiliate"); - const { user, common, getUserInfo } = useGlobalStore(); - const [withdrawOpen, setWithdrawOpen] = useState(false); - const [withdrawAmount, setWithdrawAmount] = useState(""); - const [withdrawContent, setWithdrawContent] = useState(""); - const { data, refetch } = useQuery({ + const { user, common } = useGlobalStore(); + const { data } = useQuery({ queryKey: ["queryUserAffiliate"], queryFn: async () => { const response = await queryUserAffiliate(); return response.data.data; }, }); - const availableCommission = user?.commission ?? data?.total_commission ?? 0; - const withdrawMutation = useMutation({ - mutationFn: commissionWithdraw, - onSuccess: async () => { - toast.success(t("withdrawSuccess", "Withdrawal request submitted")); - setWithdrawAmount(""); - setWithdrawContent(""); - setWithdrawOpen(false); - await Promise.all([refetch(), getUserInfo()]); - }, - onError: () => { - toast.error(t("withdrawFailed", "Failed to submit withdrawal request")); - }, - }); - - const handleWithdraw = (event: FormEvent) => { - event.preventDefault(); - const amount = Number(withdrawAmount); - const content = withdrawContent.trim(); - - if (!Number.isFinite(amount) || amount <= 0) { - toast.error(t("invalidWithdrawAmount", "Please enter a valid amount")); - return; - } - - if (amount > availableCommission) { - toast.error( - t("withdrawAmountExceeds", "Amount exceeds available commission") - ); - return; - } - - if (!content) { - toast.error(t("withdrawContentRequired", "Please enter withdrawal info")); - return; - } - - withdrawMutation.mutate({ - amount, - content, - }); - }; return (
@@ -101,85 +43,15 @@ export default function Affiliate() { -
-
- - - - - ({t("commissionRate", "Commission Rate")}:{" "} - {user?.referral_percentage || - common?.invite?.referral_percentage} - %) - -
- - - - - -
- - - {t("withdrawCommission", "Withdraw Commission")} - - - {t( - "withdrawDescription", - "Submit a commission withdrawal request for admin review." - )} - - -
-
- - - setWithdrawAmount(event.target.value) - } - placeholder={t("withdrawAmount", "Withdrawal Amount")} - step="0.01" - type="number" - value={withdrawAmount} - /> -

- {t("availableCommission", "Available Commission")}:{" "} - -

-
-
- -