codex has reworked checkout, but frontend doesnt work

This commit is contained in:
Codex Agent
2025-10-05 20:39:30 +02:00
parent fdaa2bec62
commit d70faf7a9d
35 changed files with 2105 additions and 430 deletions

View File

@@ -0,0 +1,64 @@
import { useMemo } from 'react';
import { usePage } from '@inertiajs/react';
declare const route: ((name: string, params?: Record<string, unknown>, absolute?: boolean) => string) | undefined;
type PageProps = {
locale?: string;
url?: string;
};
export const useLocalizedRoutes = () => {
const page = usePage<PageProps>();
const currentUrl = page.url ?? (typeof window !== 'undefined' ? window.location.pathname : '/') ?? '/';
return useMemo(() => {
let locale = page.props.locale;
if (!locale) {
if (currentUrl.startsWith('/en')) {
locale = 'en';
} else if (currentUrl.startsWith('/de')) {
locale = 'de';
}
}
if (!locale) {
locale = 'de';
}
const localePrefix = locale ? `/${locale}` : '';
const localizedPath = (path = '/') => {
if (!path || path === '/') {
return localePrefix || '/';
}
const normalized = path.startsWith('/') ? path : `/${path}`;
const result = `${localePrefix}${normalized}`;
return result.replace(/\/+$/, '').replace(/\/+/g, '/');
};
const localizedRoute = (name: string, params: Record<string, unknown> = {}, absolute = false) => {
if (typeof route === 'function') {
const payload = locale ? { locale, ...params } : params;
try {
return route(name, payload, absolute);
} catch (error) {
console.warn('Failed to resolve route', name, error);
}
}
return localizedPath(name.startsWith('/') ? name : `/${name}`);
};
return {
locale,
localePrefix,
localizedPath,
localizedRoute,
};
}, [page.props.locale, currentUrl]);
};