fix and update
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { apiFetch } from '@/lib/api';
|
||||
import { DEFAULT_PUBLIC_API_URL, DEFAULT_PUBLIC_FRONTEND_URL, inferApiBaseFromProjectDomain } from '@/lib/project-domains';
|
||||
|
||||
interface PublicSettingsContextValue {
|
||||
projectName: string;
|
||||
projectTagline: string;
|
||||
publicApiUrl: string;
|
||||
publicFrontendUrl: string;
|
||||
ldapEnabled: boolean;
|
||||
ldapUseLdaps: boolean;
|
||||
isLoading: boolean;
|
||||
@@ -15,6 +18,8 @@ interface PublicSettingsContextValue {
|
||||
const PublicSettingsContext = createContext<PublicSettingsContextValue>({
|
||||
projectName: 'MVK ID',
|
||||
projectTagline: 'Единый аккаунт для сервисов Lendry',
|
||||
publicApiUrl: DEFAULT_PUBLIC_API_URL,
|
||||
publicFrontendUrl: DEFAULT_PUBLIC_FRONTEND_URL,
|
||||
ldapEnabled: false,
|
||||
ldapUseLdaps: false,
|
||||
isLoading: true,
|
||||
@@ -41,17 +46,29 @@ export function PublicSettingsProvider({ children }: { children: React.ReactNode
|
||||
void refreshPublicSettings();
|
||||
}, [refreshPublicSettings]);
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
const value = useMemo(() => {
|
||||
const projectDomain = settings.PROJECT_DOMAIN?.trim();
|
||||
const inferredApi = projectDomain ? inferApiBaseFromProjectDomain(projectDomain) : null;
|
||||
const publicApiUrl = settings.PUBLIC_API_URL?.trim() || inferredApi || DEFAULT_PUBLIC_API_URL;
|
||||
const publicFrontendUrl =
|
||||
settings.PUBLIC_FRONTEND_URL?.trim() ||
|
||||
(projectDomain
|
||||
? projectDomain.startsWith('http')
|
||||
? projectDomain.replace(/\/+$/, '')
|
||||
: `https://${projectDomain.replace(/^\/+/, '')}`
|
||||
: DEFAULT_PUBLIC_FRONTEND_URL);
|
||||
|
||||
return {
|
||||
projectName: settings.PROJECT_NAME || 'MVK ID',
|
||||
projectTagline: settings.PROJECT_TAGLINE || 'Единый аккаунт для сервисов Lendry',
|
||||
publicApiUrl: publicApiUrl.replace(/\/+$/, ''),
|
||||
publicFrontendUrl: publicFrontendUrl.replace(/\/+$/, ''),
|
||||
ldapEnabled: ['true', '1', 'yes'].includes((settings.LDAP_ENABLED ?? '').trim().toLowerCase()),
|
||||
ldapUseLdaps: ['true', '1', 'yes'].includes((settings.LDAP_USE_LDAPS ?? '').trim().toLowerCase()),
|
||||
isLoading,
|
||||
refreshPublicSettings
|
||||
}),
|
||||
[isLoading, refreshPublicSettings, settings.LDAP_ENABLED, settings.LDAP_USE_LDAPS, settings.PROJECT_NAME, settings.PROJECT_TAGLINE]
|
||||
);
|
||||
};
|
||||
}, [isLoading, refreshPublicSettings, settings]);
|
||||
|
||||
return <PublicSettingsContext.Provider value={value}>{children}</PublicSettingsContext.Provider>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user