diff --git a/.env b/.env index 2172812..1f2fb8d 100644 --- a/.env +++ b/.env @@ -6,8 +6,8 @@ VITE_DANAK_BASE_URL ='https://api.danakcorp.com' VITE_SOCKET_URL = 'wss://dmail-api.danakcorp.com/email' # VITE_SOCKET_URL = 'ws://192.168.1.118:4000/email' -# VITE_BASE_URL = 'https://dmail-api.danakcorp.com' -VITE_BASE_URL = 'http://192.168.1.101:4000' +VITE_BASE_URL = 'https://dmail-api.danakcorp.com' +# VITE_BASE_URL = 'http://192.168.1.101:4000' VITE_SERVICE_ID = 'e51afdc3-ea0b-49cf-8f49-2a6f131b024e' diff --git a/src/langs/fa.json b/src/langs/fa.json index 035042f..d976f5b 100644 --- a/src/langs/fa.json +++ b/src/langs/fa.json @@ -150,7 +150,11 @@ "2fa_step_2": "QR Code را اسکن کنید یا کد را به صورت دستی وارد کنید", "2fa_step_3": "کد 6 رقمی تولید شده توسط برنامه را وارد کنید", "note": "توجه", - "2fa_note": "کد های پشتیبان خود را در مکانی امن نگهداری کنید" + "2fa_note": "کد های پشتیبان خود را در مکانی امن نگهداری کنید", + "disable_2fa": "غیر فعال کردن دو مرحله ای", + "enter_2fa_code": "کد دو مرحله ای خود را وارد کنید", + "cancel": "انصراف", + "confirm_disable": "تایید غیر فعال سازی" }, "success": "عملیات با موفقیت انجام شد", "attachment_select": "اضافه کردن فایل ضمیمه", diff --git a/src/pages/setting/components/Enabled.tsx b/src/pages/setting/components/Enabled.tsx new file mode 100644 index 0000000..a0a8574 --- /dev/null +++ b/src/pages/setting/components/Enabled.tsx @@ -0,0 +1,103 @@ +import { FC, useState } from 'react' +import { useTranslation } from 'react-i18next' +import { Logout, TickCircle } from 'iconsax-react' +import Button from '@/components/Button' +import Input from '@/components/Input' +import { clx } from '@/helpers/utils' +import { toast } from '@/components/Toast' +import { ErrorType } from '@/helpers/types' +import { useDisableTwoFactor } from '../hooks/useSettingData' + +const Enabled: FC = () => { + + const { t } = useTranslation() + const [show, setShow] = useState(false) + const [token, setToken] = useState('') + const { mutate: disableTwoFactor } = useDisableTwoFactor() + + const handleDisableTwoFactor = () => { + if (token.length !== 6) { + toast(t('setting.invalid_code_length'), 'error') + return + } + + disableTwoFactor(token, { + onSuccess: () => { + setShow(false) + setToken('') + window.location.reload() + }, + onError: (error: ErrorType) => { + toast(error.response?.data?.error?.message[0] || t('setting.2fa_disabled_failed'), 'error') + } + }) + } + + return ( +
+
+
+
+ +
+

+ {t('setting.2fa_enabled_successfully')} +

+
+ + { + show && ( +
+ setToken(e.target.value)} + maxLength={6} + /> +
+ ) + } + +
+ {!show ? ( + + ) : ( +
+ + +
+ )} +
+
+
+ ) +} + +export default Enabled \ No newline at end of file diff --git a/src/pages/setting/components/TwoFactor.tsx b/src/pages/setting/components/TwoFactor.tsx index 4214d38..134768e 100644 --- a/src/pages/setting/components/TwoFactor.tsx +++ b/src/pages/setting/components/TwoFactor.tsx @@ -8,6 +8,7 @@ import { ErrorType } from '../../../helpers/types' import { TickCircle, Scan, Key } from 'iconsax-react' import { TwoFactorSetupResponseType } from '../types/SettingTypes' import { useGetProfile } from '@/pages/profile/hooks/useProfileData' +import Enabled from './Enabled' const TwoFactor: FC = () => { @@ -68,16 +69,7 @@ const TwoFactor: FC = () => { if (isEnabled) { return ( -
-
-
- -
-

- {t('setting.2fa_enabled_successfully')} -

-
-
+ ) } diff --git a/src/pages/setting/hooks/useSettingData.ts b/src/pages/setting/hooks/useSettingData.ts index 1c7bd17..f62cdab 100644 --- a/src/pages/setting/hooks/useSettingData.ts +++ b/src/pages/setting/hooks/useSettingData.ts @@ -38,3 +38,9 @@ export const useEnableTwoFactor = () => { mutationFn: (token: string) => api.enableTwoFactor(token), }); }; + +export const useDisableTwoFactor = () => { + return useMutation({ + mutationFn: (token: string) => api.disableTwoFactor(token), + }); +}; diff --git a/src/pages/setting/service/SettingService.ts b/src/pages/setting/service/SettingService.ts index 847e0f0..05ad560 100644 --- a/src/pages/setting/service/SettingService.ts +++ b/src/pages/setting/service/SettingService.ts @@ -30,3 +30,10 @@ export const enableTwoFactor = async ( const { data } = await axios.post(`/auth/2fa/enable`, { token }); return data; }; + +export const disableTwoFactor = async ( + token: string +): Promise => { + const { data } = await axios.post(`/auth/2fa/disable `, { token }); + return data; +};