2 Commits

Author SHA1 Message Date
sina_sajjadi ab56296049 Merge branch 'main' of https://git.nwhco.ir/sina_sajjadi/AqilaFrontend 2 months ago
sina_sajjadi 3a97b1ac95 bugs fixed 2 months ago
  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. 85
      src/app/custom-trip/page.tsx
  5. 6
      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 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<PageAddListing1Props> = ({
const [savedPassengers, setSavedPassengers] = useState([]);
const [loading, setLoading] = useState(false);
if(!Object.keys(user).length){
router.replace("/")
@ -61,10 +62,12 @@ const PageAddListing1: FC<PageAddListing1Props> = ({
console.log(savedPassengers);
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
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<PageAddListing1Props> = ({
</FormItem>
<FormItem label="Upload Passport image Here" desc="">
<Input
type="file"
onChange={handleFileChange}
placeholder="Passport"
/>
{loading && <p>loading ...</p>}
{errors.image && (
<p className="text-xs text-red-500"> {errors.image} </p>
)}
@ -180,7 +185,7 @@ const PageAddListing1: FC<PageAddListing1Props> = ({
</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 { 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<CommonLayoutProps> = ({ 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<CommonLayoutProps> = ({ 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<CommonLayoutProps> = ({ 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<CommonLayoutProps> = ({ params }) => {
setErrors({});
nextHref();
};
// Prevent rendering while redirecting
if (redirecting) {
return null;
}
return (
<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">
@ -126,9 +138,7 @@ const CommonLayout: FC<CommonLayoutProps> = ({ params }) => {
{/* {index > 1 && (
<ButtonSecondary onClick={backtHref}>Go back</ButtonSecondary>
)} */}
<ButtonPrimary onClick={nextHandler}>
{nextBtnText}
</ButtonPrimary>
<ButtonPrimary onClick={nextHandler}>{nextBtnText}</ButtonPrimary>
</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 = () => {
return (
<div className="nc-BlogPage overflow-hidden relative">
{/* ======== BG GLASS ======== */}
<BgGlassmorphism />
{/* ======== ALL SECTIONS ======== */}
{/* ======= START CONTAINER ============= */}
<div className="container relative">
{/* === SECTION 1 === */}
<div className="pt-12 pb-16 lg:pb-28">
<SectionMagazine5 posts={MAGAZINE1_POSTS} />
</div>
{/* === SECTION 1 === */}
{/*
<SectionAds />
{/* === SECTION 8 === */}
<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>
);

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

@ -22,9 +22,9 @@ interface Country {
interface CommonLayoutProps {}
const CommonLayout: FC<CommonLayoutProps> = () => {
const {user} = useUserContext()
const { user } = useUserContext();
const router = useRouter()
const router = useRouter();
const [countries, setCountries] = useState<Country[]>([]);
const [startCity, setStartCity] = useState<string>("");
@ -45,6 +45,7 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
}[]
>([]);
const [isFormValid, setIsFormValid] = useState<boolean>(false);
const [isContinueValid, setIsContinueValid] = useState<boolean>(false);
var special = [
"Zeroth",
"First",
@ -96,7 +97,9 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
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<CommonLayoutProps> = () => {
);
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<CommonLayoutProps> = () => {
);
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<CommonLayoutProps> = () => {
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<CommonLayoutProps> = () => {
}),
};
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<CommonLayoutProps> = () => {
<option value="">Select City</option>
{countries.flatMap((country) =>
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}`}
</option>
))
@ -313,7 +339,9 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
{destinations.map((destination, index) => (
<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="">
<Select
value={destination.endCity}
@ -324,7 +352,10 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
<option value="">Select City</option>
{countries.flatMap((country) =>
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}`}
</option>
))
@ -406,7 +437,7 @@ const CommonLayout: FC<CommonLayoutProps> = () => {
<ButtonPrimary
onClick={submitTour}
type="button"
disabled={!isFormValid}
disabled={!isContinueValid}
>
Continue
</ButtonPrimary>

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

@ -78,16 +78,16 @@ const PageSignUp: FC<PageSignUpProps> = ({}) => {
<input
value={countryCode}
onChange={countryCodeHandler}
type="text"
type="number"
placeholder="98"
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"
/>
<span className="px-2 text-neutral-500">|</span>
<input
value={phoneNumber}
onChange={(e) => 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"
/>

8
src/app/signup/page.tsx

@ -97,17 +97,17 @@ const PageSignUp: FC<PageSignUpProps> = () => {
<input
value={countryCode}
onChange={countryCodeHandler}
type="text"
type="number"
placeholder="000"
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>
<input
value={phoneNumber}
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>
{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(),
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",
},

Loading…
Cancel
Save