Fix types
This commit is contained in:
@@ -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)">
|
||||
|
Reference in New Issue
Block a user