feat(complex-selection): enhance auto-selection logic and error handling for complex selection
This commit is contained in:
@@ -49,8 +49,14 @@ export function HomePage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function autoSelect() {
|
async function autoSelect() {
|
||||||
if (myComplexesQuery.data && myComplexesQuery.data.length === 1) {
|
if (myComplexesQuery.data && myComplexesQuery.data.length === 1) {
|
||||||
await apiClient.complexes.select({ complexId: myComplexesQuery.data[0].id });
|
try {
|
||||||
queryClient.invalidateQueries({ queryKey: ['current-complex'] });
|
const result = await apiClient.complexes.select({
|
||||||
|
complexId: myComplexesQuery.data[0].id,
|
||||||
|
});
|
||||||
|
queryClient.setQueryData(['current-complex'], result);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error al auto-seleccionar complejo:', error);
|
||||||
|
}
|
||||||
} else if (
|
} else if (
|
||||||
myComplexesQuery.data &&
|
myComplexesQuery.data &&
|
||||||
myComplexesQuery.data.length > 1 &&
|
myComplexesQuery.data.length > 1 &&
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { apiClient } from '@/lib/api-client';
|
import { apiClient } from '@/lib/api-client';
|
||||||
import type { ComplexWithRole } from '@repo/api-contract';
|
import type { ComplexWithRole } from '@repo/api-contract';
|
||||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import { useNavigate } from '@tanstack/react-router';
|
import { useNavigate } from '@tanstack/react-router';
|
||||||
import { Building2, Loader2 } from 'lucide-react';
|
import { Building2, Loader2 } from 'lucide-react';
|
||||||
|
|
||||||
@@ -13,12 +13,15 @@ export function SelectComplexPage() {
|
|||||||
queryFn: () => apiClient.complexes.listMine(),
|
queryFn: () => apiClient.complexes.listMine(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const selectMutation = useMutation({
|
const selectMutation = useMutation({
|
||||||
mutationFn: async (complexId: string) => {
|
mutationFn: async (complexId: string) => {
|
||||||
const response = await apiClient.complexes.select({ complexId });
|
const response = await apiClient.complexes.select({ complexId });
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: (data) => {
|
||||||
|
queryClient.setQueryData(['current-complex'], data);
|
||||||
navigate({ to: '/' });
|
navigate({ to: '/' });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user