Browse Source

bugs fixed

main
sina_sajjadi 4 days ago
parent
commit
3a97b1ac95
  1. 9
      src/app/add-listing/[[...stepIndex]]/PageAddListing1.tsx
  2. 38
      src/app/add-listing/[[...stepIndex]]/page.tsx
  3. 11
      src/app/blog/page.tsx
  4. 69
      src/app/custom-trip/page.tsx
  5. 4
      src/app/forgot-password/page.tsx
  6. 8
      src/app/signup/page.tsx
  7. 8
      src/data/navigation.ts

9
src/app/add-listing/[[...stepIndex]]/PageAddListing1.tsx

@ -9,7 +9,7 @@ import ConfirmModal from "../../../shared/popUp";
import axiosInstance from "@/components/api/axios"; import axiosInstance from "@/components/api/axios";
import PassengerTable from "@/app/(account-pages)/passengers-list/PassengerTable"; import PassengerTable from "@/app/(account-pages)/passengers-list/PassengerTable";
import { useUserContext } from "@/components/contexts/userContext"; import { useUserContext } from "@/components/contexts/userContext";
import { useRouter } from "next/router";
import { useRouter } from "next/navigation";
export interface PageAddListing1Props { export interface PageAddListing1Props {
Passenger: any; Passenger: any;
@ -38,6 +38,7 @@ const PageAddListing1: FC<PageAddListing1Props> = ({
const [savedPassengers, setSavedPassengers] = useState([]); const [savedPassengers, setSavedPassengers] = useState([]);
const [loading, setLoading] = useState(false);
if(!Object.keys(user).length){ if(!Object.keys(user).length){
router.replace("/") router.replace("/")
@ -61,10 +62,12 @@ const PageAddListing1: FC<PageAddListing1Props> = ({
console.log(savedPassengers); console.log(savedPassengers);
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => { const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
setLoading(true)
const file = e.target.files?.[0]; const file = e.target.files?.[0];
if (file) { if (file) {
const uploadedFile = await getImageURL(file); const uploadedFile = await getImageURL(file);
setNewPassenger((prev) => ({ ...prev, passport_image: uploadedFile.url })); setNewPassenger((prev) => ({ ...prev, passport_image: uploadedFile.url }));
setLoading(false)
} }
}; };
@ -169,10 +172,12 @@ const PageAddListing1: FC<PageAddListing1Props> = ({
</FormItem> </FormItem>
<FormItem label="Upload Passport image Here" desc=""> <FormItem label="Upload Passport image Here" desc="">
<Input <Input
type="file" type="file"
onChange={handleFileChange} onChange={handleFileChange}
placeholder="Passport" placeholder="Passport"
/> />
{loading && <p>loading ...</p>}
{errors.image && ( {errors.image && (
<p className="text-xs text-red-500"> {errors.image} </p> <p className="text-xs text-red-500"> {errors.image} </p>
)} )}
@ -180,7 +185,7 @@ const PageAddListing1: FC<PageAddListing1Props> = ({
</div> </div>
</> </>
) : ( ) : (
<p className="text-xs text-red-500"> {selectedPassenger.fullname}</p>
<p> {selectedPassenger.fullname}</p>
) )
); );
}; };

38
src/app/add-listing/[[...stepIndex]]/page.tsx

@ -3,7 +3,6 @@
import React, { useContext, useState, useEffect } from "react"; import React, { useContext, useState, useEffect } from "react";
import { FC } from "react"; import { FC } from "react";
import ButtonPrimary from "@/shared/ButtonPrimary"; import ButtonPrimary from "@/shared/ButtonPrimary";
import ButtonSecondary from "@/shared/ButtonSecondary";
import PageAddListing1 from "./PageAddListing1"; import PageAddListing1 from "./PageAddListing1";
import validatePassenger from "@/hooks/passengerValidation"; import validatePassenger from "@/hooks/passengerValidation";
import { Context } from "@/components/contexts/tourDetails"; import { Context } from "@/components/contexts/tourDetails";
@ -20,8 +19,7 @@ export interface CommonLayoutProps {
const CommonLayout: FC<CommonLayoutProps> = ({ params }) => { const CommonLayout: FC<CommonLayoutProps> = ({ params }) => {
const router = useRouter(); const router = useRouter();
const {user} =useUserContext()
const { user } = useUserContext();
const [index, setIndex] = useState(1); const [index, setIndex] = useState(1);
const [passengers, setPassengers] = useState([]); const [passengers, setPassengers] = useState([]);
@ -35,13 +33,14 @@ const CommonLayout: FC<CommonLayoutProps> = ({ params }) => {
}); });
const [passengerID, setPassengerID] = useState([]); const [passengerID, setPassengerID] = useState([]);
const [selectedPassenger, setSelectedPassenger] = useState(null); const [selectedPassenger, setSelectedPassenger] = useState(null);
const [redirecting, setRedirecting] = useState(false); // New state for redirection
const tourID = params.stepIndex[0]; const tourID = params.stepIndex[0];
const totalPassengers = useContext(Context).passengers; const totalPassengers = useContext(Context).passengers;
const nextHref = () => setIndex((prev) => prev + 1); const nextHref = () => setIndex((prev) => prev + 1);
const backtHref = () => (index > 1 ? setIndex((prev) => prev - 1) : index); 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 () => { const sendPassengers = async () => {
try { try {
@ -57,29 +56,38 @@ const CommonLayout: FC<CommonLayoutProps> = ({ params }) => {
{ {
headers: { headers: {
Authorization: `token ${user.token}`, Authorization: `token ${user.token}`,
'Content-Type': 'application/json',
"Content-Type": "application/json",
}, },
} }
); );
console.log(response); console.log(response);
router.replace("/my-trips");
setRedirecting(true); // Set redirecting state to true
} catch (error) { } catch (error) {
backtHref();
console.error("Error submitting passengers:", error); console.error("Error submitting passengers:", error);
} }
}; };
// Use useEffect to handle the redirect after setting redirecting to true
useEffect(() => { useEffect(() => {
if (index > totalPassengers && passengers.length === totalPassengers) {
if (redirecting) {
router.replace("/my-trips");
}
}, [redirecting, router]);
useEffect(() => {
if (index > totalPassengers) {
sendPassengers(); sendPassengers();
} }
}, [passengers, index, totalPassengers]);
}, [index, totalPassengers]);
const nextHandler = () => { const nextHandler = () => {
const validationErrors = validatePassenger(newPassenger); const validationErrors = validatePassenger(newPassenger);
if (Object.keys(validationErrors).length > 0) {
if (Object.keys(validationErrors).length > 0 && passengerID.length < 0) {
setErrors(validationErrors); setErrors(validationErrors);
console.log("Validation errors:", validationErrors);
console.log("Validation errors:", validationErrors, passengerID);
console.log(passengerID.length > 0);
return; return;
} }
@ -96,9 +104,13 @@ const CommonLayout: FC<CommonLayoutProps> = ({ params }) => {
setErrors({}); setErrors({});
nextHref(); nextHref();
}; };
// Prevent rendering while redirecting
if (redirecting) {
return null;
}
return ( return (
<div className={`nc-PageAddListing1 px-4 max-w-3xl mx-auto pb-24 pt-14 sm:py-24 lg:pb-32`}> <div className={`nc-PageAddListing1 px-4 max-w-3xl mx-auto pb-24 pt-14 sm:py-24 lg:pb-32`}>
<div className="space-y-11"> <div className="space-y-11">
@ -126,9 +138,7 @@ const CommonLayout: FC<CommonLayoutProps> = ({ params }) => {
{/* {index > 1 && ( {/* {index > 1 && (
<ButtonSecondary onClick={backtHref}>Go back</ButtonSecondary> <ButtonSecondary onClick={backtHref}>Go back</ButtonSecondary>
)} */} )} */}
<ButtonPrimary onClick={nextHandler}>
{nextBtnText}
</ButtonPrimary>
<ButtonPrimary onClick={nextHandler}>{nextBtnText}</ButtonPrimary>
</div> </div>
</div> </div>
</div> </div>

11
src/app/blog/page.tsx

@ -16,24 +16,17 @@ const MAGAZINE1_POSTS = POSTS.filter((_, i) => i >= 0 && i < 8);
const BlogPage: React.FC = () => { const BlogPage: React.FC = () => {
return ( return (
<div className="nc-BlogPage overflow-hidden relative"> <div className="nc-BlogPage overflow-hidden relative">
{/* ======== BG GLASS ======== */}
<BgGlassmorphism /> <BgGlassmorphism />
{/* ======== ALL SECTIONS ======== */}
{/* ======= START CONTAINER ============= */}
<div className="container relative"> <div className="container relative">
{/* === SECTION 1 === */}
<div className="pt-12 pb-16 lg:pb-28"> <div className="pt-12 pb-16 lg:pb-28">
<SectionMagazine5 posts={MAGAZINE1_POSTS} /> <SectionMagazine5 posts={MAGAZINE1_POSTS} />
</div> </div>
{/* === SECTION 1 === */}
{/*
<SectionAds /> <SectionAds />
{/* === SECTION 8 === */}
<SectionLatestPosts className="py-16 lg:py-28" /> <SectionLatestPosts className="py-16 lg:py-28" />
{/* === SECTION 1 === */}
<SectionSubscribe2 className="pb-16 lg:pb-28" />
<SectionSubscribe2 className="pb-16 lg:pb-28" /> */}
</div> </div>
</div> </div>
); );

69
src/app/custom-trip/page.tsx

@ -22,9 +22,9 @@ interface Country {
interface CommonLayoutProps {} interface CommonLayoutProps {}
const CommonLayout: FC<CommonLayoutProps> = () => { const CommonLayout: FC<CommonLayoutProps> = () => {
const {user} = useUserContext()
const { user } = useUserContext();
const router = useRouter()
const router = useRouter();
const [countries, setCountries] = useState<Country[]>([]); const [countries, setCountries] = useState<Country[]>([]);
const [startCity, setStartCity] = useState<string>(""); const [startCity, setStartCity] = useState<string>("");
@ -45,6 +45,7 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
}[] }[]
>([]); >([]);
const [isFormValid, setIsFormValid] = useState<boolean>(false); const [isFormValid, setIsFormValid] = useState<boolean>(false);
const [isContinueValid, setIsContinueValid] = useState<boolean>(false);
var special = [ var special = [
"Zeroth", "Zeroth",
"First", "First",
@ -96,7 +97,9 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
if (lastDestination?.endCity) { if (lastDestination?.endCity) {
axiosInstance axiosInstance
.get( .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)) .then((response) => setTransport(response.data))
.catch((error) => .catch((error) =>
@ -104,7 +107,9 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
); );
axiosInstance 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)) .then((response) => setHotel(response.data.results))
.catch((error) => console.error("Error fetching hotels:", error)); .catch((error) => console.error("Error fetching hotels:", error));
} }
@ -143,6 +148,22 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
); );
setIsFormValid(isValid); 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 = () => { const addDestination = () => {
setDestinations([ setDestinations([
@ -198,26 +219,33 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
setDestinations(updatedDestinations); setDestinations(updatedDestinations);
validateForm(); validateForm();
validateContinue();
}; };
console.log(destinations); console.log(destinations);
const submitTour = async () => { const submitTour = async () => {
const formData = { const formData = {
destinations: destinations.map((destination, index) => ({ 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), price_estimate: JSON.stringify(estimatedCost),
detail: JSON.stringify({ detail: JSON.stringify({
"1": { "1": {
title: "Begin Trip", title: "Begin Trip",
city: `${startCity.split("/")[0].trim()}-${startCity.split("/")[1].trim()} `,
city: `${startCity.split("/")[0].trim()}-${startCity
.split("/")[1]
.trim()} `,
number_passenger: `${passengers}`, number_passenger: `${passengers}`,
start_date: startDate.replace(/-/g, "/"), start_date: startDate.replace(/-/g, "/"),
}, },
...destinations.reduce((acc, destination, index) => { ...destinations.reduce((acc, destination, index) => {
acc[index + 2] = { acc[index + 2] = {
title: `${stringifyNumber(index + 1)} Destination`, 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, transportation: destination.transport,
hotel: destination.hotel, hotel: destination.hotel,
duration: `${destination.duration}day`, duration: `${destination.duration}day`,
@ -235,10 +263,7 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
}), }),
}; };
try { try {
const response = await axiosInstance.post(
"/api/trip/custom/",
formData,
{
const response = await axiosInstance.post("/api/trip/custom/", formData, {
headers: { headers: {
Authorization: `token ${user.token}`, Authorization: `token ${user.token}`,
"Content-Type": "application/json", "Content-Type": "application/json",
@ -246,11 +271,9 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
"HaqCxkS63ejsvwmlmk360sbFowGtwfNS06vGDYMIfWmHTWzJdod7x0zMEeC9gBSX", "HaqCxkS63ejsvwmlmk360sbFowGtwfNS06vGDYMIfWmHTWzJdod7x0zMEeC9gBSX",
Accept: "application/json", Accept: "application/json",
}, },
}
);
});
console.log("Response:", response.data); console.log("Response:", response.data);
router.push("/custom-history")
router.push("/custom-history");
} catch (error) { } catch (error) {
console.error("Error sending trip details:", error); console.error("Error sending trip details:", error);
} }
@ -282,7 +305,10 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
<option value="">Select City</option> <option value="">Select City</option>
{countries.flatMap((country) => {countries.flatMap((country) =>
country.city.map((city) => ( country.city.map((city) => (
<option key={city.name} value={`${country.name} / ${city.name} / ${city.slug}`}>
<option
key={city.name}
value={`${country.name} / ${city.name} / ${city.slug}`}
>
{`${country.name} - ${city.name}`} {`${country.name} - ${city.name}`}
</option> </option>
)) ))
@ -313,7 +339,9 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
{destinations.map((destination, index) => ( {destinations.map((destination, index) => (
<div key={index} className="space-y-8"> <div key={index} className="space-y-8">
<p className="text-bronze text-xs">{stringifyNumber(index + 1)} Destination </p>
<p className="text-bronze text-xs">
{stringifyNumber(index + 1)} Destination{" "}
</p>
<FormItem label="" desc=""> <FormItem label="" desc="">
<Select <Select
value={destination.endCity} value={destination.endCity}
@ -324,7 +352,10 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
<option value="">Select City</option> <option value="">Select City</option>
{countries.flatMap((country) => {countries.flatMap((country) =>
country.city.map((city) => ( country.city.map((city) => (
<option key={city.name} value={`${country.name} / ${city.name} / ${city.slug}`}>
<option
key={city.name}
value={`${country.name} / ${city.name} / ${city.slug}`}
>
{`${country.name} - ${city.name}`} {`${country.name} - ${city.name}`}
</option> </option>
)) ))
@ -406,7 +437,7 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
<ButtonPrimary <ButtonPrimary
onClick={submitTour} onClick={submitTour}
type="button" type="button"
disabled={!isFormValid}
disabled={!isContinueValid}
> >
Continue Continue
</ButtonPrimary> </ButtonPrimary>

4
src/app/forgot-password/page.tsx

@ -78,7 +78,7 @@ const PageSignUp: FC<PageSignUpProps> = ({}) => {
<input <input
value={countryCode} value={countryCode}
onChange={countryCodeHandler} onChange={countryCodeHandler}
type="text"
type="number"
placeholder="98" placeholder="98"
maxLength={3} maxLength={3}
className="w-[50px] [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none p-2 mr-[-10px] text-center border-none outline-none focus:ring-0 focus:border-none bg-transparent text-neutral-800 dark:text-neutral-200" className="w-[50px] [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none p-2 mr-[-10px] text-center border-none outline-none focus:ring-0 focus:border-none bg-transparent text-neutral-800 dark:text-neutral-200"
@ -87,7 +87,7 @@ const PageSignUp: FC<PageSignUpProps> = ({}) => {
<input <input
value={phoneNumber} value={phoneNumber}
onChange={(e) => setPhoneNumber(e.target.value)} onChange={(e) => setPhoneNumber(e.target.value)}
type="text"
type="number"
placeholder="26363687" 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" 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"
/> />

8
src/app/signup/page.tsx

@ -97,17 +97,17 @@ const PageSignUp: FC<PageSignUpProps> = () => {
<input <input
value={countryCode} value={countryCode}
onChange={countryCodeHandler} onChange={countryCodeHandler}
type="text"
type="number"
placeholder="000" placeholder="000"
maxLength={3} maxLength={3}
className="w-[50px] no-border-on-focus p-2 mr-[-10px] shadow-none text-center border-none outline-none bg-transparent text-neutral-800 dark:text-neutral-200"
className="w-[50px] [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none no-border-on-focus p-2 mr-[-10px] shadow-none text-center border-none outline-none bg-transparent text-neutral-800 dark:text-neutral-200"
/> />
<span className="px-2 text-neutral-500">|</span> <span className="px-2 text-neutral-500">|</span>
<input <input
value={phoneNumber} value={phoneNumber}
onChange={(e) => setPhoneNumber(e.target.value)} onChange={(e) => 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"
/> />
</div> </div>
{errors.countryCode && <p className="text-xs text-red-600">{errors.countryCode}</p>} {errors.countryCode && <p className="text-xs text-red-600">{errors.countryCode}</p>}

8
src/data/navigation.ts

@ -173,7 +173,7 @@ export const NAVIGATION_DEMO: NavItemType[] = [
}, },
{ {
id: ncNanoId(), id: ncNanoId(),
href: "/",
href: "/tours",
name: "All Tours", name: "All Tours",
type: "dropdown", type: "dropdown",
children: demoChildMenus, children: demoChildMenus,
@ -181,20 +181,20 @@ export const NAVIGATION_DEMO: NavItemType[] = [
}, },
{ {
id: ncNanoId(), id: ncNanoId(),
href: "/",
href: "/blog",
name: "Blogs", name: "Blogs",
type: "megaMenu", type: "megaMenu",
megaMenu: megaMenuDemo, megaMenu: megaMenuDemo,
}, },
{ {
id: ncNanoId(), id: ncNanoId(),
href: "/",
href: "/contact",
name: "FAQ", name: "FAQ",
type: "none", type: "none",
}, },
{ {
id: ncNanoId(), id: ncNanoId(),
href: "/",
href: "/about",
name: "AboutUs", name: "AboutUs",
type: "none", type: "none",
}, },

Loading…
Cancel
Save