feat: implement onboarding flow with complex creation and email verification, and add Zustand for state management
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { ApiClientError, apiClient } from '@/lib/api-client';
|
||||
import { useCurrentComplexStore } from '@/lib/stores/current-complex-store';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import type { AdminBooking } from '@repo/api-contract';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
@@ -136,6 +137,24 @@ export function HomePage() {
|
||||
queryFn: () => apiClient.complexes.getCurrent(),
|
||||
});
|
||||
|
||||
const { setCurrentComplex } = useCurrentComplexStore();
|
||||
|
||||
useEffect(() => {
|
||||
if (currentComplexQuery.data) {
|
||||
setCurrentComplex(currentComplexQuery.data.complexSlug);
|
||||
}
|
||||
}, [currentComplexQuery.data, setCurrentComplex]);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = useCurrentComplexStore.subscribe((state, prevState) => {
|
||||
if (state.currentComplexSlug !== prevState.currentComplexSlug) {
|
||||
queryClient.invalidateQueries({ queryKey: ['current-complex'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['admin-bookings'] });
|
||||
}
|
||||
});
|
||||
return unsubscribe;
|
||||
}, [queryClient]);
|
||||
|
||||
const myComplexesQuery = useQuery({
|
||||
queryKey: ['my-complexes'],
|
||||
queryFn: () => apiClient.complexes.listMine(),
|
||||
@@ -146,7 +165,11 @@ export function HomePage() {
|
||||
if (myComplexesQuery.data && myComplexesQuery.data.length === 1) {
|
||||
await apiClient.complexes.select({ complexId: myComplexesQuery.data[0].id });
|
||||
queryClient.invalidateQueries({ queryKey: ['current-complex'] });
|
||||
} else if (myComplexesQuery.data && myComplexesQuery.data.length > 1 && !currentComplexQuery.data) {
|
||||
} else if (
|
||||
myComplexesQuery.data &&
|
||||
myComplexesQuery.data.length > 1 &&
|
||||
!currentComplexQuery.data
|
||||
) {
|
||||
navigate({ to: '/select-complex' });
|
||||
}
|
||||
}
|
||||
@@ -154,7 +177,13 @@ export function HomePage() {
|
||||
if (!currentComplexQuery.isLoading && !currentComplexQuery.data && myComplexesQuery.data) {
|
||||
autoSelect();
|
||||
}
|
||||
}, [currentComplexQuery.isLoading, currentComplexQuery.data, myComplexesQuery.data, navigate, queryClient]);
|
||||
}, [
|
||||
currentComplexQuery.isLoading,
|
||||
currentComplexQuery.data,
|
||||
myComplexesQuery.data,
|
||||
navigate,
|
||||
queryClient,
|
||||
]);
|
||||
|
||||
const selectedComplex = currentComplexQuery.data ?? null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user