From 66b1dc15d8371911f0096cc63e738c10c0e26320 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 14 Jul 2025 12:29:36 +0330 Subject: [PATCH] add space --- .env | 3 +- src/langs/fa.json | 3 +- src/shared/components/BuySpace.tsx | 52 ++++++++++++++++++++++++++---- src/shared/hooks/useShareData.ts | 8 +++++ src/shared/service/Service.ts | 8 +++++ 5 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 src/shared/hooks/useShareData.ts create mode 100644 src/shared/service/Service.ts diff --git a/.env b/.env index 55b7799..cbb7fa7 100644 --- a/.env +++ b/.env @@ -1,8 +1,9 @@ VITE_TOKEN_NAME = 'dsc_token' VITE_REFRESH_TOKEN_NAME = 'dsc_refresh_token' VITE_DANAK_BASE_URL ='https://api.danakcorp.com' -# VITE_BASE_URL = 'http://192.168.1.134:4000' +# VITE_BASE_URL = 'http://192.168.1.113:4000' VITE_BASE_URL = 'https://dmail-api.danakcorp.com' VITE_SERVICE_ID = 'e51afdc3-ea0b-49cf-8f49-2a6f131b024e' VITE_LOGIN_URL = 'https://console.danakcorp.com/auth/login' +VITE_CONSOLE_URL = 'https://console.danakcorp.com' \ No newline at end of file diff --git a/src/langs/fa.json b/src/langs/fa.json index 00c2a36..a90e032 100644 --- a/src/langs/fa.json +++ b/src/langs/fa.json @@ -20,7 +20,8 @@ "title": "خرید فضای ذخیره سازی", "select_space": "لطفا یک فضا انتخاب کنید", "enter_space": "فضای دلخواه‌", - "price": "قیمت :" + "price": "قیمت :", + "invoice_created": "صدور صورتحساب" }, "header": { "search": "جستجو" diff --git a/src/shared/components/BuySpace.tsx b/src/shared/components/BuySpace.tsx index 4e82525..8345006 100644 --- a/src/shared/components/BuySpace.tsx +++ b/src/shared/components/BuySpace.tsx @@ -5,12 +5,31 @@ import { FC, useState } from 'react' import { clx } from '@/helpers/utils' import Input from '@/components/Input' import { NumberFormat } from '@/config/func' +import { useGetSpace } from '@/pages/setting/domain/hooks/useDomainData' +import { useBuySpace } from '../hooks/useShareData' +import Button from '@/components/Button' +import { Receipt1 } from 'iconsax-react' +import { toast } from '@/components/Toast' const BuySpace: FC = () => { const { t } = useTranslation() const { openBuySpace, setOpenBuySpace } = useSharedStore() const [spaceSelected, setSpaceSelected] = useState(1) + const { data: spaceData } = useGetSpace() + const { mutate: buySpace, isPending } = useBuySpace() + const price = spaceData?.data?.quota?.quotaPricePerGB + + const gigs = [5, 10, 20, 30, 40, 50] + + const handleBuySpace = () => { + buySpace(spaceSelected * 1024 * 1024 * 1024, { + onSuccess(data) { + toast(data?.data?.message, 'success') + window.location.href = import.meta.env.VITE_CONSOLE_URL + '/receipts/' + data?.data?.invoice?.id + }, + }) + } return ( { {t('space.select_space')}
-
setSpaceSelected(1)} className={clx( - 'bg-[#EBEDF5] border border-[#EBEDF5] cursor-pointer flex items-center text-xs h-10 px-6 rounded-lg', - spaceSelected === 1 && 'border-black' - )}> - 1 گیگبایت -
+ {gigs.map((gig) => ( +
setSpaceSelected(gig)} className={clx( + 'bg-[#EBEDF5] border border-[#EBEDF5] cursor-pointer flex items-center text-xs h-10 px-6 rounded-lg', + spaceSelected === gig && 'border-black' + )}> + {gig} گیگبایت +
+ ))}
setSpaceSelected(Number(e.target.value))} />
{t('space.price')}
-
{NumberFormat(1000000)} تومان
+
{NumberFormat(spaceSelected * price)} تومان
+
+ + +
+
diff --git a/src/shared/hooks/useShareData.ts b/src/shared/hooks/useShareData.ts new file mode 100644 index 0000000..3d7668e --- /dev/null +++ b/src/shared/hooks/useShareData.ts @@ -0,0 +1,8 @@ +import { useMutation } from "@tanstack/react-query"; +import { buySpace } from "../service/Service"; + +export const useBuySpace = () => { + return useMutation({ + mutationFn: buySpace, + }); +}; diff --git a/src/shared/service/Service.ts b/src/shared/service/Service.ts new file mode 100644 index 0000000..9b2ee14 --- /dev/null +++ b/src/shared/service/Service.ts @@ -0,0 +1,8 @@ +import axios from "@/config/axios"; + +export const buySpace = async (space: number) => { + const response = await axios.post("/business/quota/purchase", { + quota: space, + }); + return response.data; +};