diff --git a/src/app/add-listing/[[...stepIndex]]/PageAddListing1.tsx b/src/app/add-listing/[[...stepIndex]]/PageAddListing1.tsx index 7e9b305..169603e 100644 --- a/src/app/add-listing/[[...stepIndex]]/PageAddListing1.tsx +++ b/src/app/add-listing/[[...stepIndex]]/PageAddListing1.tsx @@ -9,7 +9,7 @@ import ConfirmModal from "../../../shared/popUp"; import axiosInstance from "@/components/api/axios"; import PassengerTable from "@/app/(account-pages)/passengers-list/PassengerTable"; import { useUserContext } from "@/components/contexts/userContext"; -import { useRouter } from "next/router"; +import { useRouter } from "next/navigation"; export interface PageAddListing1Props { Passenger: any; @@ -38,6 +38,7 @@ const PageAddListing1: FC = ({ const [savedPassengers, setSavedPassengers] = useState([]); + const [loading, setLoading] = useState(false); if(!Object.keys(user).length){ router.replace("/") @@ -61,10 +62,12 @@ const PageAddListing1: FC = ({ console.log(savedPassengers); const handleFileChange = async (e: React.ChangeEvent) => { + setLoading(true) const file = e.target.files?.[0]; if (file) { const uploadedFile = await getImageURL(file); setNewPassenger((prev) => ({ ...prev, passport_image: uploadedFile.url })); + setLoading(false) } }; @@ -169,10 +172,12 @@ const PageAddListing1: FC = ({ + {loading &&

loading ...

} {errors.image && (

{errors.image}

)} @@ -180,7 +185,7 @@ const PageAddListing1: FC = ({ ) : ( -

{selectedPassenger.fullname}

+

{selectedPassenger.fullname}

) ); }; diff --git a/src/app/add-listing/[[...stepIndex]]/page.tsx b/src/app/add-listing/[[...stepIndex]]/page.tsx index bbf2017..68409ca 100644 --- a/src/app/add-listing/[[...stepIndex]]/page.tsx +++ b/src/app/add-listing/[[...stepIndex]]/page.tsx @@ -3,7 +3,6 @@ import React, { useContext, useState, useEffect } from "react"; import { FC } from "react"; import ButtonPrimary from "@/shared/ButtonPrimary"; -import ButtonSecondary from "@/shared/ButtonSecondary"; import PageAddListing1 from "./PageAddListing1"; import validatePassenger from "@/hooks/passengerValidation"; import { Context } from "@/components/contexts/tourDetails"; @@ -20,8 +19,7 @@ export interface CommonLayoutProps { const CommonLayout: FC = ({ params }) => { const router = useRouter(); - const {user} =useUserContext() - + const { user } = useUserContext(); const [index, setIndex] = useState(1); const [passengers, setPassengers] = useState([]); @@ -35,13 +33,14 @@ const CommonLayout: FC = ({ params }) => { }); const [passengerID, setPassengerID] = useState([]); const [selectedPassenger, setSelectedPassenger] = useState(null); + const [redirecting, setRedirecting] = useState(false); // New state for redirection const tourID = params.stepIndex[0]; const totalPassengers = useContext(Context).passengers; const nextHref = () => setIndex((prev) => prev + 1); const backtHref = () => (index > 1 ? setIndex((prev) => prev - 1) : index); - const nextBtnText = index > totalPassengers ? "Save Passengers" : "Continue"; + const nextBtnText = index === totalPassengers ? "Save Passengers" : "Continue"; const sendPassengers = async () => { try { @@ -57,29 +56,38 @@ const CommonLayout: FC = ({ params }) => { { headers: { Authorization: `token ${user.token}`, - 'Content-Type': 'application/json', + "Content-Type": "application/json", }, } ); console.log(response); - router.replace("/my-trips"); + setRedirecting(true); // Set redirecting state to true } catch (error) { + backtHref(); console.error("Error submitting passengers:", error); } }; + // Use useEffect to handle the redirect after setting redirecting to true + useEffect(() => { + if (redirecting) { + router.replace("/my-trips"); + } + }, [redirecting, router]); + useEffect(() => { - if (index > totalPassengers && passengers.length === totalPassengers) { + if (index > totalPassengers) { sendPassengers(); } - }, [passengers, index, totalPassengers]); + }, [index, totalPassengers]); const nextHandler = () => { const validationErrors = validatePassenger(newPassenger); - if (Object.keys(validationErrors).length > 0) { + if (Object.keys(validationErrors).length > 0 && passengerID.length < 0) { setErrors(validationErrors); - console.log("Validation errors:", validationErrors); + console.log("Validation errors:", validationErrors, passengerID); + console.log(passengerID.length > 0); return; } @@ -96,9 +104,13 @@ const CommonLayout: FC = ({ params }) => { setErrors({}); nextHref(); - }; - + + // Prevent rendering while redirecting + if (redirecting) { + return null; + } + return (
@@ -126,9 +138,7 @@ const CommonLayout: FC = ({ params }) => { {/* {index > 1 && ( Go back )} */} - - {nextBtnText} - + {nextBtnText}
diff --git a/src/app/blog/page.tsx b/src/app/blog/page.tsx index 461c270..cf7218a 100644 --- a/src/app/blog/page.tsx +++ b/src/app/blog/page.tsx @@ -16,24 +16,17 @@ const MAGAZINE1_POSTS = POSTS.filter((_, i) => i >= 0 && i < 8); const BlogPage: React.FC = () => { return (
- {/* ======== BG GLASS ======== */} - {/* ======== ALL SECTIONS ======== */} - {/* ======= START CONTAINER ============= */}
- {/* === SECTION 1 === */}
- - {/* === SECTION 1 === */} +{/* - {/* === SECTION 8 === */} - {/* === SECTION 1 === */} - + */}
); diff --git a/src/app/custom-trip/page.tsx b/src/app/custom-trip/page.tsx index 44652e6..c997533 100644 --- a/src/app/custom-trip/page.tsx +++ b/src/app/custom-trip/page.tsx @@ -22,9 +22,9 @@ interface Country { interface CommonLayoutProps {} const CommonLayout: FC = () => { - const {user} = useUserContext() + const { user } = useUserContext(); - const router = useRouter() + const router = useRouter(); const [countries, setCountries] = useState([]); const [startCity, setStartCity] = useState(""); @@ -45,6 +45,7 @@ const CommonLayout: FC = () => { }[] >([]); const [isFormValid, setIsFormValid] = useState(false); + const [isContinueValid, setIsContinueValid] = useState(false); var special = [ "Zeroth", "First", @@ -96,7 +97,9 @@ const CommonLayout: FC = () => { if (lastDestination?.endCity) { axiosInstance .get( - `/api/trip/custom/transport/?from_city=${startCity.split("/")[2].trim()}&to_city=${lastDestination.endCity.split("/")[2].trim()}` + `/api/trip/custom/transport/?from_city=${startCity + .split("/")[2] + .trim()}&to_city=${lastDestination.endCity.split("/")[2].trim()}` ) .then((response) => setTransport(response.data)) .catch((error) => @@ -104,7 +107,9 @@ const CommonLayout: FC = () => { ); axiosInstance - .get(`/api/trip/hotels/${lastDestination.endCity.split("/")[2].trim()}/`) + .get( + `/api/trip/hotels/${lastDestination.endCity.split("/")[2].trim()}/` + ) .then((response) => setHotel(response.data.results)) .catch((error) => console.error("Error fetching hotels:", error)); } @@ -143,6 +148,22 @@ const CommonLayout: FC = () => { ); setIsFormValid(isValid); }; + const validateContinue = () => { + const isValid = + startCity && + startDate && + passengers && + destinations.length > 0 && + destinations.every( + (destination) => + destination.endCity && + destination.transport && + destination.hotel && + destination.duration > 0 && + destination.finishDate + ); + setIsContinueValid(isValid); + }; const addDestination = () => { setDestinations([ @@ -198,26 +219,33 @@ const CommonLayout: FC = () => { setDestinations(updatedDestinations); validateForm(); + validateContinue(); }; console.log(destinations); const submitTour = async () => { const formData = { destinations: destinations.map((destination, index) => ({ - name: `${destination.endCity.split("/")[0].trim()}-${destination.endCity.split("/")[1].trim()} `, + name: `${destination.endCity.split("/")[0].trim()}-${destination.endCity + .split("/")[1] + .trim()} `, })), price_estimate: JSON.stringify(estimatedCost), - detail: JSON.stringify({ + detail: JSON.stringify({ "1": { title: "Begin Trip", - city: `${startCity.split("/")[0].trim()}-${startCity.split("/")[1].trim()} `, + city: `${startCity.split("/")[0].trim()}-${startCity + .split("/")[1] + .trim()} `, number_passenger: `${passengers}`, start_date: startDate.replace(/-/g, "/"), }, ...destinations.reduce((acc, destination, index) => { acc[index + 2] = { title: `${stringifyNumber(index + 1)} Destination`, - city:`${destination.endCity.split("/")[0].trim()}-${destination.endCity.split("/")[1].trim()} `, + city: `${destination.endCity + .split("/")[0] + .trim()}-${destination.endCity.split("/")[1].trim()} `, transportation: destination.transport, hotel: destination.hotel, duration: `${destination.duration}day`, @@ -235,22 +263,17 @@ const CommonLayout: FC = () => { }), }; try { - const response = await axiosInstance.post( - "/api/trip/custom/", - formData, - { - headers: { - Authorization: `token ${user.token}`, - "Content-Type": "application/json", - "X-CSRFToken": - "HaqCxkS63ejsvwmlmk360sbFowGtwfNS06vGDYMIfWmHTWzJdod7x0zMEeC9gBSX", - Accept: "application/json", - }, - } - ); + const response = await axiosInstance.post("/api/trip/custom/", formData, { + headers: { + Authorization: `token ${user.token}`, + "Content-Type": "application/json", + "X-CSRFToken": + "HaqCxkS63ejsvwmlmk360sbFowGtwfNS06vGDYMIfWmHTWzJdod7x0zMEeC9gBSX", + Accept: "application/json", + }, + }); console.log("Response:", response.data); - router.push("/custom-history") - + router.push("/custom-history"); } catch (error) { console.error("Error sending trip details:", error); } @@ -282,7 +305,10 @@ const CommonLayout: FC = () => { {countries.flatMap((country) => country.city.map((city) => ( - )) @@ -313,7 +339,9 @@ const CommonLayout: FC = () => { {destinations.map((destination, index) => (
-

{stringifyNumber(index + 1)} Destination

+

+ {stringifyNumber(index + 1)} Destination{" "} +

| setPhoneNumber(e.target.value)} - type="text" + type="number" placeholder="26363687" className="[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none flex-1 p-2 border-none outline-none focus:ring-0 focus:border-none bg-transparent text-neutral-800 dark:text-neutral-200" /> diff --git a/src/app/signup/page.tsx b/src/app/signup/page.tsx index c90522a..5c6923e 100644 --- a/src/app/signup/page.tsx +++ b/src/app/signup/page.tsx @@ -97,17 +97,17 @@ const PageSignUp: FC = () => { | setPhoneNumber(e.target.value)} - type="text" - className="flex-1 p-2 no-border-on-focus border-none outline-none bg-transparent text-neutral-800 dark:text-neutral-200" + type="number" + className="[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none flex-1 p-2 no-border-on-focus border-none outline-none bg-transparent text-neutral-800 dark:text-neutral-200" />
{errors.countryCode &&

{errors.countryCode}

} diff --git a/src/data/navigation.ts b/src/data/navigation.ts index 1c2524c..a63d98a 100644 --- a/src/data/navigation.ts +++ b/src/data/navigation.ts @@ -173,7 +173,7 @@ export const NAVIGATION_DEMO: NavItemType[] = [ }, { id: ncNanoId(), - href: "/", + href: "/tours", name: "All Tours", type: "dropdown", children: demoChildMenus, @@ -181,20 +181,20 @@ export const NAVIGATION_DEMO: NavItemType[] = [ }, { id: ncNanoId(), - href: "/", + href: "/blog", name: "Blogs", type: "megaMenu", megaMenu: megaMenuDemo, }, { id: ncNanoId(), - href: "/", + href: "/contact", name: "FAQ", type: "none", }, { id: ncNanoId(), - href: "/", + href: "/about", name: "AboutUs", type: "none", },