From 2b6946e0b2f00894c5870980f13584c44e462d6f Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 14 Jul 2025 09:29:54 +0330 Subject: [PATCH] convert number --- src/App.tsx | 2 ++ src/hooks/useConvertNumbers.ts | 38 ++++++++++++++++++++++++++++++ src/langs/fa.json | 5 +++- src/pages/home/Home.tsx | 11 +-------- src/shared/components/BuySpace.tsx | 26 +++++++++++++++++++- 5 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 src/hooks/useConvertNumbers.ts diff --git a/src/App.tsx b/src/App.tsx index f1650fa..91b0196 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,6 +14,7 @@ import ToastContainer from './components/Toast'; import { getRefreshToken, removeRefreshToken, removeToken, setRefreshToken, setToken } from './config/func'; import { refreshToken } from './pages/auth/service/Service'; import BuySpace from './shared/components/BuySpace' +import useConvertNumbers from './hooks/useConvertNumbers' declare global { interface Window { @@ -96,6 +97,7 @@ const queryClient = new QueryClient({ }); const App: FC = () => { + useConvertNumbers() return ( diff --git a/src/hooks/useConvertNumbers.ts b/src/hooks/useConvertNumbers.ts new file mode 100644 index 0000000..d598da6 --- /dev/null +++ b/src/hooks/useConvertNumbers.ts @@ -0,0 +1,38 @@ +import { useEffect } from "react"; + +const toPersianDigits = (text: string): string => { + return text.replace(/\d/g, (d) => "۰۱۲۳۴۵۶۷۸۹"[parseInt(d, 10)]); +}; + +const convertNumbersInDOM = (node: Node): void => { + if (node.nodeType === Node.TEXT_NODE) { + node.nodeValue = toPersianDigits(node.nodeValue || ""); + } else if (node.nodeType === Node.ELEMENT_NODE) { + // Skip conversion if element has 'en' class + if ((node as Element).classList?.contains("en")) { + return; + } + node.childNodes.forEach(convertNumbersInDOM); + } +}; + +const useConvertNumbers = (): void => { + useEffect(() => { + const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + if (mutation.type === "childList") { + mutation.addedNodes.forEach(convertNumbersInDOM); + } + }); + }); + + observer.observe(document.body, { childList: true, subtree: true }); + + // اجرای اولیه روی کل صفحه + convertNumbersInDOM(document.body); + + return () => observer.disconnect(); + }, []); +}; + +export default useConvertNumbers; diff --git a/src/langs/fa.json b/src/langs/fa.json index e34f008..00c2a36 100644 --- a/src/langs/fa.json +++ b/src/langs/fa.json @@ -17,7 +17,10 @@ "add_space": "اضافه کردن فضا" }, "space": { - "title": "خرید فضای ذخیره سازی" + "title": "خرید فضای ذخیره سازی", + "select_space": "لطفا یک فضا انتخاب کنید", + "enter_space": "فضای دلخواه‌", + "price": "قیمت :" }, "header": { "search": "جستجو" diff --git a/src/pages/home/Home.tsx b/src/pages/home/Home.tsx index 23630ea..a8e18f5 100644 --- a/src/pages/home/Home.tsx +++ b/src/pages/home/Home.tsx @@ -42,7 +42,7 @@ const Home: FC = () => { onClick={() => handleChangeWorkspace(item.id)} >
- {item.businessName} + {item.businessName + ' ( ' + item.slug + ' )'}
@@ -58,15 +58,6 @@ const Home: FC = () => {
-
- - { - e.stopPropagation() - }} target='_blank' href={`${import.meta.env.VITE_DZONE_URL}/${item.slug}`}> - {`${import.meta.env.VITE_DZONE_URL}/${item.slug}`} - -
- ) diff --git a/src/shared/components/BuySpace.tsx b/src/shared/components/BuySpace.tsx index e58adb5..5e0de92 100644 --- a/src/shared/components/BuySpace.tsx +++ b/src/shared/components/BuySpace.tsx @@ -2,6 +2,8 @@ import DefaulModal from '@/components/DefaulModal' import { useSharedStore } from '@/shared/store/sharedStore' import { useTranslation } from 'react-i18next' import { FC } from 'react' +import { clx } from '@/helpers/utils' +import Input from '@/components/Input' const BuySpace: FC = () => { @@ -16,8 +18,30 @@ const BuySpace: FC = () => { isHeader={true} title_header={t('space.title')} > -
+
+
+ {t('space.select_space')} +
+
+
+ {'1000000'.toLocaleString()} تومان +
+
+
+ +
+ +
+
{t('space.price')}
+
{'1000000'.toLocaleString()} تومان
+
)