✨ feat(affiliate): Add Affiliate component with commission display and invite link functionality
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { NEXT_PUBLIC_API_URL, NEXT_PUBLIC_SITE_URL } from '@/config/constants';
|
||||
import { getTranslations } from '@/locales/utils';
|
||||
import { isBrowser } from '@workspace/ui/utils';
|
||||
import requset, { InternalAxiosRequestConfig } from 'axios';
|
||||
import axios, { InternalAxiosRequestConfig } from 'axios';
|
||||
import { toast } from 'sonner';
|
||||
import { getAuthorization, Logout } from './common';
|
||||
|
||||
@@ -10,6 +10,7 @@ async function handleError(response: any) {
|
||||
if ([40002, 40003, 40004].includes(code)) return Logout();
|
||||
if (response?.config?.skipErrorHandler) return;
|
||||
if (!isBrowser()) return;
|
||||
|
||||
const t = await getTranslations('common');
|
||||
const message =
|
||||
t(`request.${code}`) !== `request.${code}`
|
||||
@@ -19,21 +20,24 @@ async function handleError(response: any) {
|
||||
toast.error(message);
|
||||
}
|
||||
|
||||
requset.defaults.baseURL = NEXT_PUBLIC_API_URL || NEXT_PUBLIC_SITE_URL;
|
||||
// axios.defaults.withCredentials = true;
|
||||
// axios.defaults.timeout = 10000;
|
||||
const requset = axios.create({
|
||||
baseURL: NEXT_PUBLIC_API_URL || NEXT_PUBLIC_SITE_URL,
|
||||
// timeout: 10000,
|
||||
// withCredentials: true,
|
||||
});
|
||||
|
||||
requset.interceptors.request.use(
|
||||
async (
|
||||
config: InternalAxiosRequestConfig & {
|
||||
Authorization?: string;
|
||||
skipErrorHandler?: boolean;
|
||||
},
|
||||
) => {
|
||||
const Authorization = getAuthorization(config.Authorization);
|
||||
if (Authorization) config.headers.Authorization = Authorization;
|
||||
return config;
|
||||
},
|
||||
(error) => Promise.reject(error),
|
||||
(error) => Promise.reject(new Error(error)),
|
||||
);
|
||||
|
||||
requset.interceptors.response.use(
|
||||
@@ -47,7 +51,7 @@ requset.interceptors.response.use(
|
||||
},
|
||||
async (error) => {
|
||||
await handleError(error);
|
||||
return Promise.reject(error);
|
||||
return Promise.reject(new Error(error));
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user