diff --git a/src/components/UploadForm.tsx b/src/components/UploadForm.tsx index 12bfef4..f85992d 100644 --- a/src/components/UploadForm.tsx +++ b/src/components/UploadForm.tsx @@ -1,8 +1,10 @@ import { memo, useCallback, useEffect, useMemo, useState } from 'react' -import { Upload, Button } from 'antd' -import { UploadOutlined } from '@ant-design/icons' import { UploadFile } from 'antd/lib/upload/interface' +import { UploadOutlined } from '@ant-design/icons' import { RcFile } from 'antd/lib/upload' +import { Upload, Button } from 'antd' + +import { isDev } from '@utils' import { notify, upload } from './factory' import { ErrorFetch } from './ErrorFetch' @@ -53,7 +55,7 @@ export const UploadForm = memo(({ url, disabled, style, formDat onUploadSuccess?.() } } catch(error) { - if(process.env.NODE_ENV === 'development') + if(isDev()) console.error(error) onUploadError?.(error) } finally { diff --git a/src/components/factory.ts b/src/components/factory.ts index 635b2c2..3083ac4 100755 --- a/src/components/factory.ts +++ b/src/components/factory.ts @@ -1,8 +1,9 @@ import { notification } from 'antd' import { Dispatch, ReactNode, SetStateAction } from 'react' -import { ApiError, FileInfoDto } from '@api' +import { isDev } from '@utils' import { getUserToken } from '@utils/storage' +import { ApiError, FileInfoDto } from '@api' const notificationTypeDictionary = new Map([ ['error' , { notifyInstance: notification.error , caption: 'Ошибка' }], @@ -45,7 +46,7 @@ export const invokeWebApiWrapperAsync = async ( try{ await funcAsync() } catch (ex) { - if(process.env.NODE_ENV === 'development') + if(isDev()) console.error(ex) if (ex instanceof ApiError && ex.status === 403) { if (actionName) diff --git a/src/services/signalr/index.ts b/src/services/signalr/index.ts index b55982a..5afede2 100755 --- a/src/services/signalr/index.ts +++ b/src/services/signalr/index.ts @@ -1,6 +1,8 @@ -import { getUserToken } from '@asb/utils/storage' import { HubConnection, HubConnectionBuilder, HubConnectionState } from '@microsoft/signalr' +import { getUserToken } from '@utils/storage' +import { isDev } from '@utils' + // SignalR js api: //https://docs.microsoft.com/ru-ru/javascript/api/@aspnet/signalr/?view=signalr-js-latest @@ -12,7 +14,7 @@ const ConnectionOptions = { type ConnectionsDict = Record //var baseUrl = `http://192.168.1.70:5000` -const baseUrl = process.env.NODE_ENV === 'development' ? require('../../../package.json').proxy : '' +const baseUrl = isDev() ? require('../../../package.json').proxy : '' const Connections: ConnectionsDict = { 'hubs/telemetry': new HubConnectionBuilder() diff --git a/src/utils/index.ts b/src/utils/index.ts index 51732bc..4ef3299 100755 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -62,3 +62,5 @@ export const range = (end: number, start: number = 0) => Array.from({ length: en * @returns Общий тип с полным `T` и несовпадающими полями из `R` */ export type OmitExtends = T & Omit + +export const isDev = () => process.env.NODE_ENV === 'development' diff --git a/src/utils/permissions.ts b/src/utils/permissions.ts index 43444b6..dd7ad6e 100755 --- a/src/utils/permissions.ts +++ b/src/utils/permissions.ts @@ -1,3 +1,4 @@ +import { isDev } from '.' import { getUserLogin, getUserPermissions, getUserRoles } from './storage' export type Role = string @@ -17,7 +18,7 @@ export const getPermissions = (...values: PermissionRequest[]) => { const [service, type] = key.toLowerCase().split('.') if (!isRequestType(type)) return permissions[service] = permissions[service] ?? {} - permissions[service][type] = getUserLogin() === 'dev' || hasPermission(key) + permissions[service][type] = hasPermission(key) || (isDev() && getUserLogin() === 'dev') }) return permissions }