ui: add B2B olmayan stok (orphans) page
This commit is contained in:
+31
-1
@@ -3,6 +3,7 @@ import qs from 'qs'
|
||||
import { useAuthStore } from 'stores/authStore'
|
||||
import { DEFAULT_LOCALE, normalizeLocale } from 'src/i18n/languages'
|
||||
import { slog } from 'src/utils/slog'
|
||||
import { formatDataSourceLabel } from 'src/utils/formatters'
|
||||
|
||||
const rawBaseUrl =
|
||||
(typeof process !== 'undefined' && process.env?.VITE_API_BASE_URL) || '/api'
|
||||
@@ -63,7 +64,7 @@ function sanitizeApiErrorDetail(detail, status) {
|
||||
return `Unexpected HTML error response (${status || '-'})`
|
||||
}
|
||||
|
||||
const compact = normalized.replace(/\s+/g, ' ').trim()
|
||||
const compact = normalizeTechnicalSourceLabels(normalized.replace(/\s+/g, ' ').trim())
|
||||
if (compact.length > 320) {
|
||||
return `${compact.slice(0, 320)}...`
|
||||
}
|
||||
@@ -71,6 +72,17 @@ function sanitizeApiErrorDetail(detail, status) {
|
||||
return compact
|
||||
}
|
||||
|
||||
function normalizeTechnicalSourceLabels(text) {
|
||||
return String(text || '')
|
||||
.replace(/\bPostgreSQL\b/gi, formatDataSourceLabel('postgresql'))
|
||||
.replace(/\bPostgres\b/gi, formatDataSourceLabel('postgres'))
|
||||
.replace(/\bpostgre\b/gi, formatDataSourceLabel('postgre'))
|
||||
.replace(/\bPG\b/g, formatDataSourceLabel('pg'))
|
||||
.replace(/\bMSSQL\b/gi, formatDataSourceLabel('mssql'))
|
||||
.replace(/\bBAGGI_V3\b/gi, formatDataSourceLabel('BAGGI_V3'))
|
||||
.replace(/\bURETIM\b/g, formatDataSourceLabel('URETIM'))
|
||||
}
|
||||
|
||||
function redirectToLogin() {
|
||||
if (typeof window === 'undefined') return
|
||||
if (window.location.hash === '#/login') return
|
||||
@@ -203,6 +215,8 @@ api.interceptors.response.use(
|
||||
requestUrl.startsWith('/me/password')
|
||||
const isPublicRequest = isPublicPath(requestUrl)
|
||||
|
||||
normalizeErrorResponsePayload(error)
|
||||
|
||||
if ((status >= 500 || hasBlob) && error) {
|
||||
const method = String(requestConfig.method || 'GET').toUpperCase()
|
||||
const detail = sanitizeApiErrorDetail(
|
||||
@@ -262,6 +276,22 @@ api.interceptors.response.use(
|
||||
}
|
||||
)
|
||||
|
||||
function normalizeErrorResponsePayload(error) {
|
||||
const data = error?.response?.data
|
||||
if (!data || typeof Blob !== 'undefined' && data instanceof Blob) return
|
||||
if (typeof data === 'string') {
|
||||
error.response.data = normalizeTechnicalSourceLabels(data)
|
||||
return
|
||||
}
|
||||
if (typeof data === 'object') {
|
||||
for (const key of ['detail', 'message', 'error']) {
|
||||
if (typeof data[key] === 'string') {
|
||||
data[key] = normalizeTechnicalSourceLabels(data[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const get = (u, p = {}, c = {}) =>
|
||||
api.get(u, { params: p, ...c }).then(r => r.data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user