mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
V2 Show enterprise demo messages for audit and usage (#5226)
## Summary - show demo data for audit and usage sections when enterprise licensing is unavailable - add enterprise-required banner messaging and reuse demo content instead of erroring - update translations for the new enterprise notice ## Testing - Not run (not requested) ------ [Codex Task](https://chatgpt.com/codex/tasks/task_b_693af73ad9248328885eb8bb81ccf51a)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useAppConfig } from '@app/contexts/AppConfigContext';
|
||||
import { alert } from '@app/components/toast';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -14,30 +15,30 @@ export function useLoginRequired() {
|
||||
/**
|
||||
* Show alert when user tries to modify settings with login disabled
|
||||
*/
|
||||
const showLoginRequiredAlert = () => {
|
||||
const showLoginRequiredAlert = useCallback(() => {
|
||||
alert({
|
||||
alertType: 'warning',
|
||||
title: t('admin.error', 'Error'),
|
||||
body: t('admin.settings.loginRequired', 'Login mode must be enabled to modify admin settings'),
|
||||
});
|
||||
};
|
||||
}, [t]);
|
||||
|
||||
/**
|
||||
* Validate that login is enabled before allowing action
|
||||
* Returns true if login is enabled, false otherwise (and shows alert)
|
||||
*/
|
||||
const validateLoginEnabled = (): boolean => {
|
||||
const validateLoginEnabled = useCallback((): boolean => {
|
||||
if (!loginEnabled) {
|
||||
showLoginRequiredAlert();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}, [loginEnabled, showLoginRequiredAlert]);
|
||||
|
||||
/**
|
||||
* Wrap an async handler to check login state before executing
|
||||
*/
|
||||
const withLoginCheck = <T extends (...args: any[]) => Promise<any>>(
|
||||
const withLoginCheck = useCallback(<T extends (...args: any[]) => Promise<any>>(
|
||||
handler: T
|
||||
): T => {
|
||||
return (async (...args: any[]) => {
|
||||
@@ -46,12 +47,12 @@ export function useLoginRequired() {
|
||||
}
|
||||
return handler(...args);
|
||||
}) as T;
|
||||
};
|
||||
}, [validateLoginEnabled]);
|
||||
|
||||
/**
|
||||
* Get styles for disabled inputs (cursor not-allowed)
|
||||
*/
|
||||
const getDisabledStyles = () => {
|
||||
const getDisabledStyles = useCallback(() => {
|
||||
if (!loginEnabled) {
|
||||
return {
|
||||
input: { cursor: 'not-allowed' },
|
||||
@@ -60,12 +61,12 @@ export function useLoginRequired() {
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
}, [loginEnabled]);
|
||||
|
||||
/**
|
||||
* Wrap fetch function to skip API call when login disabled
|
||||
*/
|
||||
const withLoginCheckForFetch = <T extends (...args: any[]) => Promise<any>>(
|
||||
const withLoginCheckForFetch = useCallback(<T extends (...args: any[]) => Promise<any>>(
|
||||
fetchHandler: T,
|
||||
skipWhenDisabled: boolean = true
|
||||
): T => {
|
||||
@@ -76,7 +77,7 @@ export function useLoginRequired() {
|
||||
}
|
||||
return fetchHandler(...args);
|
||||
}) as T;
|
||||
};
|
||||
}, [loginEnabled]);
|
||||
|
||||
return {
|
||||
loginEnabled,
|
||||
|
||||
Reference in New Issue
Block a user