fix: Add WNW_CONFIG type definitions and fix TypeScript errors

This commit is contained in:
dwindown
2025-11-05 12:05:29 +07:00
parent af3ae9d1fb
commit 855f3fcae5
3 changed files with 34 additions and 6 deletions

View File

@@ -266,7 +266,7 @@ function Header({ onFullscreen, fullscreen, showToggle = true }: { onFullscreen:
const handleLogout = async () => {
try {
await fetch(window.WNW_CONFIG.restUrl + '/auth/logout', {
await fetch((window.WNW_CONFIG?.restUrl || '') + '/auth/logout', {
method: 'POST',
credentials: 'include',
});
@@ -465,7 +465,7 @@ function AuthWrapper() {
// In standalone mode, trust the initial PHP auth check
// PHP uses wp_signon which sets proper WordPress cookies
if (window.WNW_CONFIG?.standaloneMode) {
setIsAuthenticated(window.WNW_CONFIG.isAuthenticated);
setIsAuthenticated(window.WNW_CONFIG.isAuthenticated ?? false);
setIsChecking(false);
} else {
// In wp-admin mode, always authenticated

View File

@@ -20,7 +20,7 @@ export function Login() {
setError('');
try {
const response = await fetch(window.WNW_CONFIG.restUrl + '/auth/login', {
const response = await fetch((window.WNW_CONFIG?.restUrl || '') + '/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -118,7 +118,7 @@ export function Login() {
{/* Footer Links */}
<div className="mt-6 space-y-3">
<a
href={window.WNW_CONFIG.wpAdminUrl}
href={window.WNW_CONFIG?.wpAdminUrl || '/wp-admin'}
className="flex items-center justify-center gap-2 text-sm text-blue-600 hover:text-blue-700 dark:text-blue-400 transition-colors"
>
<ArrowLeft className="w-4 h-4" />
@@ -127,7 +127,7 @@ export function Login() {
<div className="text-center">
<a
href={window.WNW_CONFIG.siteUrl + '/wp-login.php?action=lostpassword'}
href={(window.WNW_CONFIG?.siteUrl || '') + '/wp-login.php?action=lostpassword'}
className="text-sm text-gray-600 hover:text-gray-700 dark:text-gray-400 transition-colors"
>
{__('Forgot password?')}
@@ -138,7 +138,7 @@ export function Login() {
{/* Site Info */}
<div className="text-center mt-6 text-sm text-gray-600 dark:text-gray-400">
{window.WNW_CONFIG.siteName}
{window.WNW_CONFIG?.siteName || 'WooNooW'}
</div>
</div>
</div>

View File

@@ -16,11 +16,39 @@ interface WNW_WC_MENUS {
items?: any[];
}
interface WNW_CONFIG {
standaloneMode?: boolean;
restUrl?: string;
wpAdminUrl?: string;
siteUrl?: string;
siteName?: string;
isAuthenticated?: boolean;
currentUser?: {
id: number;
name: string;
email: string;
};
user?: {
id: number;
name: string;
email: string;
};
store?: {
currency: string;
currencySymbol: string;
currencyPosition: string;
thousandSeparator: string;
decimalSeparator: string;
decimals: number;
};
}
declare global {
interface Window {
WNW_API?: WNW_API_Config;
wnw?: WNW_Config;
WNW_WC_MENUS?: WNW_WC_MENUS;
WNW_CONFIG?: WNW_CONFIG;
}
}