fix bug toast and do not change slug id

This commit is contained in:
hamid zarghami
2025-05-21 16:12:38 +03:30
parent 836c1168b2
commit 495e59bec4
9 changed files with 54 additions and 28 deletions
+2 -2
View File
@@ -3,10 +3,10 @@ import LogoImage from '../../assets/images/logo.svg'
import LogoSmallImage from '../../assets/images/logo-small.svg'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom'
import { Pages } from '../../config/Pages'
import RegisterStep1 from './components/RegisterStep1'
import { useAuthStore } from './store/AuthStore'
import RegisterStep2 from './components/RegisterStep2'
import { buildPath } from '../../helpers/utils'
const Register: FC = () => {
@@ -48,7 +48,7 @@ const Register: FC = () => {
<p className='text-description'>
{t('auth.before_registered')}
</p>
<Link to={Pages.auth.login}>
<Link to={buildPath('auth/login')}>
<div>{t('auth.login')}</div>
</Link>
</div>
+2 -2
View File
@@ -8,7 +8,7 @@ import { useAuthStore } from '../store/AuthStore'
import Error from '../../../components/Error'
import Button from '../../../components/Button'
import { useCheckHasAccountRegister, useLoginWithOtp } from '../hooks/useAuthData'
import { toast } from 'react-toastify'
import { toast } from '../../../components/Toast'
import { ErrorType } from '../../../helpers/types'
const RegisterStep1: FC = () => {
@@ -33,7 +33,7 @@ const RegisterStep1: FC = () => {
setStepLogin(2)
},
onError(error: ErrorType) {
toast.error(error?.response?.data?.error?.message[0])
toast(error?.response?.data?.error?.message[0], 'error')
},
})
},
+2 -2
View File
@@ -9,7 +9,7 @@ import DatePickerComponent from '../../../components/DatePicker'
import Button from '../../../components/Button'
import { useRegister } from '../hooks/useAuthData'
import { ErrorType } from '../../../helpers/types'
import { toast } from 'react-toastify'
import { toast } from '../../../components/Toast'
import { Pages } from '../../../config/Pages'
import { setToken } from '../../../config/func'
import { setRefreshToken } from '../../../config/func'
@@ -56,7 +56,7 @@ const RegisterStep2: FC = () => {
window.location.href = `/${slug}/${Pages.dashboard}`
},
onError(error: ErrorType) {
toast.error(error?.response?.data?.error?.message[0])
toast(error?.response?.data?.error?.message[0], 'error')
},
})
},
+3 -3
View File
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next'
import Button from '../../../components/Button'
import { useCheckUserName, useUpdateProfile } from '../hooks/useProfileData'
import { CheckUserNameType, UpdateProfileType } from '../types/ProfileTypes'
import { toast } from 'react-toastify'
import { toast } from '../../../components/Toast'
import { ErrorType } from '../../../helpers/types'
type Props = {
@@ -54,13 +54,13 @@ const Username: FC<Props> = (props: Props) => {
updateProfile.mutate(params, {
onSuccess: () => {
toast.success(t('profile.username_save_success'))
toast('نام کاربری با موفقیت تغییر کرد', 'success')
setCanEdit(false)
setCanSave(false)
setStatus('')
},
onError(error: ErrorType) {
toast.error(error.response?.data?.error?.message?.[0])
toast(error?.response?.data?.message || 'خطا در تغییر نام کاربری', 'error')
},
})
}
+5 -5
View File
@@ -10,7 +10,7 @@ import Button from '../../components/Button'
import ApproveInvoice from './components/ApproveInvoice'
import PayInvoice from './components/PayInvoice'
import Input from '../../components/Input'
import { toast } from 'react-toastify'
import { toast } from '../../components/Toast'
import { ErrorType } from '../../helpers/types'
// import PDFGenerator from '../../components/PDFGenerator'
import { useGetGetWays } from './hooks/useReceiptData'
@@ -34,11 +34,11 @@ const ReceiptsDetail: FC = () => {
}
applyDiscount.mutate(params, {
onSuccess: () => {
toast.success(t('receip.discount_applied'))
toast('فاکتور با موفقیت پرداخت شد', 'success')
getInvoce.refetch()
},
onError: (error: ErrorType) => {
toast.error(error?.response?.data?.error?.message[0])
toast(error?.response?.data?.message || 'خطا در پرداخت فاکتور', 'error')
}
})
}
@@ -46,11 +46,11 @@ const ReceiptsDetail: FC = () => {
const handleRemoveDiscount = () => {
removeDiscount.mutate({ id: id ? id : '' }, {
onSuccess: () => {
toast.success(t('receip.discount_removed'))
toast('فاکتور با موفقیت پرداخت شد', 'success')
getInvoce.refetch()
},
onError: (error: ErrorType) => {
toast.error(error?.response?.data?.error?.message[0])
toast(error?.response?.data?.message || 'خطا در پرداخت فاکتور', 'error')
}
})
}
@@ -4,7 +4,7 @@ import { TickCircle } from 'iconsax-react'
import { useTranslation } from 'react-i18next'
import { useApproveInvoice, useRequestApprove } from '../hooks/useReceiptData'
import { ErrorType } from '../../../helpers/types'
import { toast } from 'react-toastify'
import { toast } from '../../../components/Toast'
import { clx } from '../../../helpers/utils'
import { useGetProfile } from '../../profile/hooks/useProfileData'
import { RequestApproveInvoiceType } from '../types/ReceiptTypes'
@@ -31,12 +31,12 @@ const ApproveInvoice: FC<Props> = ({ id, refetch, status }) => {
const handleConfrim = () => {
approveInvoce.mutate({ code: code, id: id, phone: getProfile.data?.data?.user?.phone }, {
onSuccess: () => {
toast.success(t('success'))
toast('فاکتور با موفقیت تایید شد', 'success')
refetch()
setShowModal(false)
},
onError: (error: ErrorType) => {
toast.error(error.response?.data?.error.message[0])
toast(error?.response?.data?.message || 'خطا در تایید فاکتور', 'error')
}
})
}
@@ -52,7 +52,7 @@ const ApproveInvoice: FC<Props> = ({ id, refetch, status }) => {
reset()
},
onError: (error: ErrorType) => {
toast.error(error.response?.data?.error.message[0])
toast(error?.response?.data?.message || 'خطا در تایید فاکتور', 'error')
}
})
}
+4 -6
View File
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next'
import { useFormik } from 'formik'
import * as Yup from 'yup'
import { useState } from 'react'
import { toast } from 'react-toastify'
import { toast } from '../../components/Toast'
import { ErrorType } from '../../helpers/types'
import { Pages } from '../../config/Pages'
import { useNavigate, useParams } from 'react-router-dom'
@@ -69,7 +69,7 @@ const Request: FC = () => {
}),
onSubmit: async (values) => {
if (!profileImage || !coverImage) {
toast.error('لطفا تصاویر را انتخاب کنید')
toast('لطفا تصاویر را انتخاب کنید', 'error')
return
}
@@ -112,15 +112,13 @@ const Request: FC = () => {
createCompany.mutate(values, {
onSuccess: () => {
toast.success('درخواست با موفقیت ثبت شد')
toast('درخواست با موفقیت ثبت شد', 'success')
navigate(buildPath(Pages.dashboard, slug))
},
onError: (error: ErrorType) => {
toast.error(error.response?.data?.error.message[0])
toast(error?.response?.data?.message || 'خطا در ارسال درخواست', 'error')
}
})
toast.success('درخواست با موفقیت ثبت شد')
// navigate(Pages.request.list)
}
})
+30 -2
View File
@@ -1,10 +1,38 @@
import { FC } from 'react'
import { Route, Routes } from 'react-router-dom'
import { FC, useEffect } from 'react'
import { Route, Routes, useParams } from 'react-router-dom'
import { Pages } from '../config/Pages'
import Login from '../pages/auth/Login'
import Register from '../pages/auth/Register'
import { useGetSlugId } from '../pages/home/hooks/useHomeData'
import { ErrorType } from '../helpers/types'
import { toast } from '../components/Toast'
const AuthRouter: FC = () => {
const { slug } = useParams()
const getSlugId = useGetSlugId()
useEffect(() => {
if (slug) {
const slug_id = localStorage.getItem(import.meta.env.VITE_SLUG_ID)
const slug_parse = slug_id ? JSON.parse(slug_id) : null
if (slug_parse && slug_parse.slug === slug) {
return
} else {
getSlugId.mutate(slug, {
onSuccess: (data) => {
localStorage.setItem(import.meta.env.VITE_SLUG_ID, JSON.stringify(data?.data?.business))
window.location.reload()
},
onError: (error: ErrorType) => {
toast(error?.response?.data?.error?.message[0] || 'خطا در دریافت اطلاعات', 'error')
// window.location.href = 'https://danakcorp.com'
}
})
}
}
}, [slug])
return (
<Routes>
<Route path={Pages.auth.login} element={<Login />} />
+2 -2
View File
@@ -18,7 +18,7 @@ import CompanyDetail from "../pages/company/Detail"
import { useEffect } from "react"
import { useGetSlugId } from "../pages/home/hooks/useHomeData"
import { ErrorType } from "../helpers/types"
import { toast } from "react-toastify"
import { toast } from "../components/Toast"
import Request from "../pages/request/Request"
import TicketList from "../pages/ticket/TicketList"
import TicketCreate from "../pages/ticket/CreateTicket"
@@ -43,7 +43,7 @@ const MainRouter = () => {
window.location.reload()
},
onError: (error: ErrorType) => {
toast.error(error.response?.data?.error.message[0])
toast(error?.response?.data?.error?.message[0] || 'خطا در دریافت اطلاعات', 'error')
// window.location.href = 'https://danakcorp.com'
}
})