login seitentexte verbessert und event selector gefixt. allgemeine event-landingpage schickt gemacht.
This commit is contained in:
@@ -2,6 +2,7 @@ import React from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { getEvents, type TenantEvent } from '../api';
|
||||
import { useAuth } from '../auth/context';
|
||||
|
||||
const STORAGE_KEY = 'tenant-admin.active-event';
|
||||
|
||||
@@ -15,6 +16,7 @@ export interface EventContextValue {
|
||||
const EventContext = React.createContext<EventContextValue | undefined>(undefined);
|
||||
|
||||
export function EventProvider({ children }: { children: React.ReactNode }) {
|
||||
const { status } = useAuth();
|
||||
const [storedSlug, setStoredSlug] = React.useState<string | null>(() => {
|
||||
if (typeof window === 'undefined') {
|
||||
return null;
|
||||
@@ -22,20 +24,29 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
|
||||
return window.localStorage.getItem(STORAGE_KEY);
|
||||
});
|
||||
|
||||
const { data: events = [], isLoading } = useQuery<TenantEvent[]>({
|
||||
const authReady = status === 'authenticated';
|
||||
|
||||
const {
|
||||
data: fetchedEvents = [],
|
||||
isLoading: queryLoading,
|
||||
} = useQuery<TenantEvent[]>({
|
||||
queryKey: ['tenant-events'],
|
||||
queryFn: async () => {
|
||||
try {
|
||||
return await getEvents();
|
||||
} catch (error) {
|
||||
console.warn('[EventContext] Failed to fetch events', error);
|
||||
return [];
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
staleTime: 60 * 1000,
|
||||
cacheTime: 5 * 60 * 1000,
|
||||
enabled: authReady,
|
||||
});
|
||||
|
||||
const events = authReady ? fetchedEvents : [];
|
||||
const isLoading = authReady ? queryLoading : status === 'loading';
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!storedSlug && events.length === 1 && events[0]?.slug && typeof window !== 'undefined') {
|
||||
setStoredSlug(events[0].slug);
|
||||
|
||||
Reference in New Issue
Block a user