From c2897b7edc0021d6f0403183eb958bc3963c4183 Mon Sep 17 00:00:00 2001 From: Jackson Stone Date: Sun, 28 Jan 2024 04:42:40 -0600 Subject: [PATCH] cleanup itineraries --- pages/itineraries/create.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pages/itineraries/create.tsx b/pages/itineraries/create.tsx index 59eccd7..57d316d 100644 --- a/pages/itineraries/create.tsx +++ b/pages/itineraries/create.tsx @@ -4,6 +4,7 @@ import {Airport, Flight, Route, User} from "@prisma/client"; import {useUser} from "@auth0/nextjs-auth0/client"; import {FlightAdd} from "@/components/itinerary/flightadd"; import {Button} from "@/components/ui/button"; +import {useRouter} from "next/router"; const Create = () => { const [routes, setRoutes] = useState<{ originCode: string, destinationCode: string }[]>([]); @@ -15,6 +16,8 @@ const Create = () => { const { user, isLoading } = useUser(); const [wingmanUser, setWingmanUser] = useState(null); + const router = useRouter(); + useEffect(() => { if (!isLoading && user) { fetch(`/api/users/${user?.sub}`).then(res => res.json()).then(data => { @@ -66,7 +69,9 @@ const Create = () => { } // If there's no starting point, the route is circular and not contiguous - if (start === null) return false; + if (start === null) { + return false; + } // Step 4: Follow the route let count = 0; @@ -101,6 +106,10 @@ const Create = () => { }).then(res => res.json()).then(data => { console.log(data); }) + router.push('/itineraries'); + } else { + console.log('Invalid route'); + alert('There is an issue in your route! Please make sure that your route is contiguous and your return flights are in a separate itinerary.') } };