2024-04-25 16:01:08: merge [main:7f9a52684105c7ff0a068812245c462ceb6d553e];
This commit is contained in:
1 parent
5a5f104174
commit
a31c44eb7b
121 files changed
+14802
-84
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { BaseQueryFn, retry } from '@reduxjs/toolkit/query/react'
|
||||
import { AxiosError, AxiosRequestConfig } from 'axios'
|
||||
|
||||
import { apiService } from '@services/apiService.ts'
|
||||
|
||||
import { MSPError } from '@type/index.ts'
|
||||
|
||||
export const axiosBaseQuery =
|
||||
(
|
||||
{ baseUrl }: { baseUrl: string } = { baseUrl: '' }
|
||||
): BaseQueryFn<
|
||||
{
|
||||
url: string
|
||||
method?: AxiosRequestConfig['method']
|
||||
data?: AxiosRequestConfig['data']
|
||||
params?: AxiosRequestConfig['params']
|
||||
},
|
||||
unknown,
|
||||
unknown
|
||||
> =>
|
||||
async ({ url, method = 'post', data, params }) => {
|
||||
try {
|
||||
const result = await apiService({
|
||||
url: baseUrl + url,
|
||||
method,
|
||||
data,
|
||||
params
|
||||
})
|
||||
return { data: result.data }
|
||||
} catch (axiosError) {
|
||||
const err = axiosError as AxiosError<MSPError>
|
||||
return {
|
||||
error: { ...err.response }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const staggeredBaseQueryWithBailOut = (baseUrl: string) =>
|
||||
retry(
|
||||
async (args: string | AxiosRequestConfig['data'], api, extraOptions) => {
|
||||
const result = await axiosBaseQuery({ baseUrl })(args, api, extraOptions)
|
||||
const error = result.error as AxiosError<MSPError>
|
||||
if (error && error?.status === 400) {
|
||||
retry.fail(result.error)
|
||||
}
|
||||
|
||||
return result
|
||||
},
|
||||
{
|
||||
maxRetries: 5
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,31 @@
|
||||
import { NavigateFunction, SetURLSearchParams } from 'react-router-dom'
|
||||
|
||||
export const setSelectedItemId = (
|
||||
path: string,
|
||||
id: string,
|
||||
searchParams: string,
|
||||
navigate: NavigateFunction
|
||||
): void => {
|
||||
navigate(
|
||||
{
|
||||
pathname: `${path}/${id}`,
|
||||
search: searchParams
|
||||
},
|
||||
{ replace: true }
|
||||
)
|
||||
}
|
||||
|
||||
export const setSearchValue = (
|
||||
value: string,
|
||||
setSearchParams: SetURLSearchParams,
|
||||
prefix: string = 'search'
|
||||
) => {
|
||||
setSearchParams((prev) => {
|
||||
if (!value) {
|
||||
prev.delete(prefix)
|
||||
} else {
|
||||
prev.set(prefix, value)
|
||||
}
|
||||
return prev
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
declare global {
|
||||
interface Window {
|
||||
config: { [key: string]: any };
|
||||
}
|
||||
}
|
||||
|
||||
export const getConfigProperty = (property: string, defaultValue: any) => {
|
||||
if (
|
||||
window.config &&
|
||||
Object.prototype.hasOwnProperty.call(window.config, property)
|
||||
) {
|
||||
return window.config[property]
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type'
|
||||
|
||||
export const filterFirstColumnItems = <T extends NonNullable<unknown>>(
|
||||
listItems: ColumnItem<T>[],
|
||||
searchValue: string
|
||||
): ColumnItem<T>[] =>
|
||||
listItems
|
||||
? listItems.filter((el) =>
|
||||
el.name.toLowerCase().trim().includes(searchValue.toLowerCase().trim())
|
||||
)
|
||||
: []
|
||||
@@ -0,0 +1,20 @@
|
||||
export const LocalStorage = {
|
||||
set(key: string, value: any): void {
|
||||
const item = typeof value === 'string' ? value : JSON.stringify(value)
|
||||
localStorage.setItem(key, item)
|
||||
},
|
||||
get(key: string): any | null {
|
||||
const value = localStorage.getItem(key)
|
||||
try {
|
||||
return value ? JSON.parse(value) : null
|
||||
} catch (error) {
|
||||
return value
|
||||
}
|
||||
},
|
||||
remove(key: string): void {
|
||||
localStorage.removeItem(key)
|
||||
},
|
||||
clear(): void {
|
||||
localStorage.clear()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { RoleType } from '@type/roles.type.ts'
|
||||
|
||||
export const findExclusiveRole = (
|
||||
roles: RoleType[],
|
||||
watchRoles: number[] = []
|
||||
) => {
|
||||
let firstExclusiveElement = null
|
||||
for (let i = 0; i < roles.length; i++) {
|
||||
const item = roles[i]
|
||||
if (item.exclusive === true && watchRoles.includes(item.id)) {
|
||||
firstExclusiveElement = item
|
||||
break
|
||||
}
|
||||
}
|
||||
return firstExclusiveElement
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { UserType } from '@type/user.type.ts'
|
||||
|
||||
export const getUserFullName = (user: UserType): string =>
|
||||
user ? `${user.lastName} ${user.firstName}` : ''
|
||||
Reference in new issue
Block a user