Fix types

This commit is contained in:
april
2024-01-04 13:44:04 -06:00
parent 4e84dc842a
commit 783bf668d1
5 changed files with 52 additions and 25 deletions

View File

@@ -13,21 +13,17 @@ import {
import { Link, useLocation, useNavigate } from "@remix-run/react";
import { IconPlus } from "@tabler/icons-react";
import { useQuery } from "@tanstack/react-query";
import { AxiosError } from "axios";
import { useEffect } from "react";
export function FlightsList() {
// const flights = useQuery({
// queryKey: ["flights-list"],
// queryFn: () => client.get(`/flights`).then((res) => res.data),
// });
const location = useLocation();
const page = location.pathname.split("/")[3];
const flights = useQuery({
queryKey: ["flights-list"],
queryFn: async () => await client.get(`/flights`).then((res) => res.data),
retry: (failureCount, error) => {
retry: (failureCount, error: AxiosError) => {
return !error || error.response?.status !== 401;
},
});
@@ -36,7 +32,11 @@ export function FlightsList() {
const { clearUser } = useAuth();
useEffect(() => {
if (flights.isError && flights.error.response.status === 401) {
if (
flights.isError &&
flights.error instanceof AxiosError &&
flights.error.response?.status === 401
) {
clearUser();
navigate("/login");
}
@@ -76,15 +76,30 @@ export function FlightsList() {
}
export function MobileFlightsList() {
const flights = useQuery({
queryKey: ["flights-list"],
queryFn: () => client.get(`/flights`).then((res) => res.data),
});
const location = useLocation();
const page = location.pathname.split("/")[3];
const flights = useQuery({
queryKey: ["flights-list"],
queryFn: async () => await client.get(`/flights`).then((res) => res.data),
retry: (failureCount, error: AxiosError) => {
return !error || error.response?.status !== 401;
},
});
const navigate = useNavigate();
const { clearUser } = useAuth();
useEffect(() => {
if (
flights.isError &&
flights.error instanceof AxiosError &&
flights.error.response?.status === 401
) {
clearUser();
navigate("/login");
}
}, [flights]);
return (
<Stack p="0" m="0" justify="space-between" h="calc(100vh - 95px)">