Fix types
This commit is contained in:
parent
4e84dc842a
commit
783bf668d1
@ -12,16 +12,10 @@ import {
|
|||||||
Scripts,
|
Scripts,
|
||||||
ScrollRestoration,
|
ScrollRestoration,
|
||||||
isRouteErrorResponse,
|
isRouteErrorResponse,
|
||||||
redirect,
|
|
||||||
useNavigate,
|
|
||||||
useRouteError,
|
useRouteError,
|
||||||
} from "@remix-run/react";
|
} from "@remix-run/react";
|
||||||
|
|
||||||
import {
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
QueryCache,
|
|
||||||
QueryClient,
|
|
||||||
QueryClientProvider,
|
|
||||||
} from "@tanstack/react-query";
|
|
||||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -4,6 +4,7 @@ import { Center, Container, List, Loader, Stack, Text } from "@mantine/core";
|
|||||||
import { useNavigate, useParams } from "@remix-run/react";
|
import { useNavigate, useParams } from "@remix-run/react";
|
||||||
import { IconAlertTriangle } from "@tabler/icons-react";
|
import { IconAlertTriangle } from "@tabler/icons-react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { AxiosError } from "axios";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export default function Flight() {
|
export default function Flight() {
|
||||||
@ -13,7 +14,7 @@ export default function Flight() {
|
|||||||
queryKey: [params.id],
|
queryKey: [params.id],
|
||||||
queryFn: async () =>
|
queryFn: async () =>
|
||||||
await client.get(`/flights/${params.id}`).then((res) => res.data),
|
await client.get(`/flights/${params.id}`).then((res) => res.data),
|
||||||
retry: (failureCount, error) => {
|
retry: (failureCount, error: AxiosError) => {
|
||||||
return !error || error.response?.status !== 401;
|
return !error || error.response?.status !== 401;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -22,7 +23,11 @@ export default function Flight() {
|
|||||||
const { clearUser } = useAuth();
|
const { clearUser } = useAuth();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (flight.isError && flight.error.response.status === 401) {
|
if (
|
||||||
|
flight.isError &&
|
||||||
|
flight.error instanceof AxiosError &&
|
||||||
|
flight.error.response?.status === 401
|
||||||
|
) {
|
||||||
clearUser();
|
clearUser();
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ import ListInput from "@/ui/form/list-input";
|
|||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { client } from "@/util/api";
|
import { client } from "@/util/api";
|
||||||
import { useNavigate } from "@remix-run/react";
|
import { useNavigate } from "@remix-run/react";
|
||||||
|
import { useAuth } from "@/util/auth";
|
||||||
|
import { AxiosError } from "axios";
|
||||||
|
|
||||||
export default function NewFlight() {
|
export default function NewFlight() {
|
||||||
const form = useForm<FlightFormSchema>({
|
const form = useForm<FlightFormSchema>({
|
||||||
@ -78,6 +80,8 @@ export default function NewFlight() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const { clearUser } = useAuth();
|
||||||
|
|
||||||
const createFlight = useMutation({
|
const createFlight = useMutation({
|
||||||
mutationFn: async (values: FlightFormSchema) => {
|
mutationFn: async (values: FlightFormSchema) => {
|
||||||
const newFlight = flightCreateHelper(values);
|
const newFlight = flightCreateHelper(values);
|
||||||
@ -85,11 +89,15 @@ export default function NewFlight() {
|
|||||||
console.log(res);
|
console.log(res);
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
retry: (failureCount, error) => {
|
retry: (failureCount, error: AxiosError) => {
|
||||||
return !error || error.response?.status !== 401;
|
return !error || error.response?.status !== 401;
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error: AxiosError) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
if (error.response?.status === 401) {
|
||||||
|
clearUser();
|
||||||
|
navigate("/login");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onSuccess: async (data: { id: string }) => {
|
onSuccess: async (data: { id: string }) => {
|
||||||
await queryClient.invalidateQueries({ queryKey: ["flights-list"] });
|
await queryClient.invalidateQueries({ queryKey: ["flights-list"] });
|
||||||
|
@ -13,21 +13,17 @@ import {
|
|||||||
import { Link, useLocation, useNavigate } from "@remix-run/react";
|
import { Link, useLocation, useNavigate } from "@remix-run/react";
|
||||||
import { IconPlus } from "@tabler/icons-react";
|
import { IconPlus } from "@tabler/icons-react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { AxiosError } from "axios";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export function FlightsList() {
|
export function FlightsList() {
|
||||||
// const flights = useQuery({
|
|
||||||
// queryKey: ["flights-list"],
|
|
||||||
// queryFn: () => client.get(`/flights`).then((res) => res.data),
|
|
||||||
// });
|
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const page = location.pathname.split("/")[3];
|
const page = location.pathname.split("/")[3];
|
||||||
|
|
||||||
const flights = useQuery({
|
const flights = useQuery({
|
||||||
queryKey: ["flights-list"],
|
queryKey: ["flights-list"],
|
||||||
queryFn: async () => await client.get(`/flights`).then((res) => res.data),
|
queryFn: async () => await client.get(`/flights`).then((res) => res.data),
|
||||||
retry: (failureCount, error) => {
|
retry: (failureCount, error: AxiosError) => {
|
||||||
return !error || error.response?.status !== 401;
|
return !error || error.response?.status !== 401;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -36,7 +32,11 @@ export function FlightsList() {
|
|||||||
const { clearUser } = useAuth();
|
const { clearUser } = useAuth();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (flights.isError && flights.error.response.status === 401) {
|
if (
|
||||||
|
flights.isError &&
|
||||||
|
flights.error instanceof AxiosError &&
|
||||||
|
flights.error.response?.status === 401
|
||||||
|
) {
|
||||||
clearUser();
|
clearUser();
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
}
|
}
|
||||||
@ -76,15 +76,30 @@ export function FlightsList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function MobileFlightsList() {
|
export function MobileFlightsList() {
|
||||||
const flights = useQuery({
|
|
||||||
queryKey: ["flights-list"],
|
|
||||||
queryFn: () => client.get(`/flights`).then((res) => res.data),
|
|
||||||
});
|
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const page = location.pathname.split("/")[3];
|
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 navigate = useNavigate();
|
||||||
|
const { clearUser } = useAuth();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
flights.isError &&
|
||||||
|
flights.error instanceof AxiosError &&
|
||||||
|
flights.error.response?.status === 401
|
||||||
|
) {
|
||||||
|
clearUser();
|
||||||
|
navigate("/login");
|
||||||
|
}
|
||||||
|
}, [flights]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack p="0" m="0" justify="space-between" h="calc(100vh - 95px)">
|
<Stack p="0" m="0" justify="space-between" h="calc(100vh - 95px)">
|
||||||
|
@ -3,13 +3,14 @@ import { useAuth } from "@/util/auth";
|
|||||||
import { Container, Text, Title } from "@mantine/core";
|
import { Container, Text, Title } from "@mantine/core";
|
||||||
import { useNavigate } from "@remix-run/react";
|
import { useNavigate } from "@remix-run/react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { AxiosError } from "axios";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export default function Me() {
|
export default function Me() {
|
||||||
const user = useQuery({
|
const user = useQuery({
|
||||||
queryKey: ["user"],
|
queryKey: ["user"],
|
||||||
queryFn: async () => await client.get(`users/me`).then((res) => res.data),
|
queryFn: async () => await client.get(`users/me`).then((res) => res.data),
|
||||||
retry: (failureCount, error) => {
|
retry: (failureCount, error: AxiosError) => {
|
||||||
return !error || error.response?.status !== 401;
|
return !error || error.response?.status !== 401;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -18,7 +19,11 @@ export default function Me() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user.isError && user.error.response?.status === 401) {
|
if (
|
||||||
|
user.isError &&
|
||||||
|
user.error instanceof AxiosError &&
|
||||||
|
user.error.response?.status === 401
|
||||||
|
) {
|
||||||
clearUser();
|
clearUser();
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user