diff --git a/next.config.js b/next.config.js
index 03a332a..b9f4bb2 100644
--- a/next.config.js
+++ b/next.config.js
@@ -2,6 +2,7 @@
module.exports = {
+
typescript: {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
@@ -9,12 +10,13 @@ module.exports = {
// !! WARN !!
ignoreBuildErrors: true,
},
- ignoreBuildErrors: true,
eslint: {
ignoreDuringBuilds: true,
},
- typescript: {
- ignoreBuildErrors: true,
+ i18n: {
+ locales: ['en'], // List all the languages you want to support
+ defaultLocale: 'en', // The default language of the website
+ localeDetection: true, // Enable or disable automatic locale detection based on browser settings
},
images: {
remotePatterns: [
diff --git a/package-lock.json b/package-lock.json
index 929369c..91b5516 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -26,6 +26,7 @@
"google-map-react": "^2.2.1",
"lodash": "^4.17.21",
"next": "^13.4.3",
+ "next-i18next": "^15.3.1",
"rc-slider": "^10.1.1",
"react": "^18.2.0",
"react-datepicker": "^4.11.0",
@@ -59,12 +60,11 @@
}
},
"node_modules/@babel/runtime": {
- "version": "7.21.5",
- "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.5.tgz",
- "integrity": "sha512-8jI69toZqqcsnqGGqwGS4Qb1VwLOEp4hz+CXPywcvjs60u3B4Pom/U/7rm4W8tMOYEB+E9wgD0mW1l3r8qlI9Q==",
- "license": "MIT",
+ "version": "7.25.6",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.6.tgz",
+ "integrity": "sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ==",
"dependencies": {
- "regenerator-runtime": "^0.13.11"
+ "regenerator-runtime": "^0.14.0"
},
"engines": {
"node": ">=6.9.0"
@@ -579,6 +579,15 @@
"@types/react": "*"
}
},
+ "node_modules/@types/hoist-non-react-statics": {
+ "version": "3.3.5",
+ "resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.5.tgz",
+ "integrity": "sha512-SbcrWzkKBw2cdwRTwQAswfpB9g9LJWfjtUeW/jvNwbhC8cpmmNYVePa+ncbUe0rGTQ7G3Ff6mYUN2VMfLVr+Sg==",
+ "dependencies": {
+ "@types/react": "*",
+ "hoist-non-react-statics": "^3.3.0"
+ }
+ },
"node_modules/@types/js-cookie": {
"version": "2.2.7",
"resolved": "https://registry.npmjs.org/@types/js-cookie/-/js-cookie-2.2.7.tgz",
@@ -1348,6 +1357,16 @@
"toggle-selection": "^1.0.6"
}
},
+ "node_modules/core-js": {
+ "version": "3.38.1",
+ "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.38.1.tgz",
+ "integrity": "sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw==",
+ "hasInstallScript": true,
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/core-js"
+ }
+ },
"node_modules/cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@@ -2679,6 +2698,23 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/hoist-non-react-statics": {
+ "version": "3.3.2",
+ "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz",
+ "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==",
+ "dependencies": {
+ "react-is": "^16.7.0"
+ }
+ },
+ "node_modules/html-parse-stringify": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/html-parse-stringify/-/html-parse-stringify-3.0.1.tgz",
+ "integrity": "sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg==",
+ "peer": true,
+ "dependencies": {
+ "void-elements": "3.1.0"
+ }
+ },
"node_modules/human-signals": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.1.tgz",
@@ -2694,6 +2730,34 @@
"integrity": "sha512-ygGZLjmXfPHj+ZWh6LwbC37l43MhfztxetbFCoYTM2VjkIUpeHgSNn7QIyVFj7YQ1Wl9Cbw5sholVJPzWvC2MQ==",
"license": "BSD-3-Clause"
},
+ "node_modules/i18next": {
+ "version": "23.15.1",
+ "resolved": "https://registry.npmjs.org/i18next/-/i18next-23.15.1.tgz",
+ "integrity": "sha512-wB4abZ3uK7EWodYisHl/asf8UYEhrI/vj/8aoSsrj/ZDxj4/UXPOa1KvFt1Fq5hkUHquNqwFlDprmjZ8iySgYA==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://locize.com"
+ },
+ {
+ "type": "individual",
+ "url": "https://locize.com/i18next.html"
+ },
+ {
+ "type": "individual",
+ "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project"
+ }
+ ],
+ "peer": true,
+ "dependencies": {
+ "@babel/runtime": "^7.23.2"
+ }
+ },
+ "node_modules/i18next-fs-backend": {
+ "version": "2.3.2",
+ "resolved": "https://registry.npmjs.org/i18next-fs-backend/-/i18next-fs-backend-2.3.2.tgz",
+ "integrity": "sha512-LIwUlkqDZnUI8lnUxBnEj8K/FrHQTT/Sc+1rvDm9E8YvvY5YxzoEAASNx+W5M9DfD5s77lI5vSAFWeTp26B/3Q=="
+ },
"node_modules/ignore": {
"version": "5.2.4",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz",
@@ -3548,6 +3612,41 @@
}
}
},
+ "node_modules/next-i18next": {
+ "version": "15.3.1",
+ "resolved": "https://registry.npmjs.org/next-i18next/-/next-i18next-15.3.1.tgz",
+ "integrity": "sha512-+pa2pZJb7B6k5PKW3TLVMmAodqkNaOBWVYlpWX56mgcEJz0UMW+MKSdKM9Z72CHp6Bp48g7OWwDnLqxXNp/84w==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://locize.com/i18next.html"
+ },
+ {
+ "type": "individual",
+ "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project"
+ },
+ {
+ "type": "individual",
+ "url": "https://locize.com"
+ }
+ ],
+ "dependencies": {
+ "@babel/runtime": "^7.23.2",
+ "@types/hoist-non-react-statics": "^3.3.4",
+ "core-js": "^3",
+ "hoist-non-react-statics": "^3.3.2",
+ "i18next-fs-backend": "^2.3.2"
+ },
+ "engines": {
+ "node": ">=14"
+ },
+ "peerDependencies": {
+ "i18next": ">= 23.7.13",
+ "next": ">= 12.0.0",
+ "react": ">= 17.0.2",
+ "react-i18next": ">= 13.5.0"
+ }
+ },
"node_modules/next/node_modules/postcss": {
"version": "8.4.14",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz",
@@ -4213,6 +4312,28 @@
"react": ">=16.8.0"
}
},
+ "node_modules/react-i18next": {
+ "version": "15.0.2",
+ "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-15.0.2.tgz",
+ "integrity": "sha512-z0W3/RES9Idv3MmJUcf0mDNeeMOUXe+xoL0kPfQPbDoZHmni/XsIoq5zgT2MCFUiau283GuBUK578uD/mkAbLQ==",
+ "peer": true,
+ "dependencies": {
+ "@babel/runtime": "^7.25.0",
+ "html-parse-stringify": "^3.0.1"
+ },
+ "peerDependencies": {
+ "i18next": ">= 23.2.3",
+ "react": ">= 16.8.0"
+ },
+ "peerDependenciesMeta": {
+ "react-dom": {
+ "optional": true
+ },
+ "react-native": {
+ "optional": true
+ }
+ }
+ },
"node_modules/react-icons": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.3.0.tgz",
@@ -4346,10 +4467,9 @@
}
},
"node_modules/regenerator-runtime": {
- "version": "0.13.11",
- "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
- "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==",
- "license": "MIT"
+ "version": "0.14.1",
+ "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz",
+ "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw=="
},
"node_modules/regexp.prototype.flags": {
"version": "1.5.0",
@@ -5311,6 +5431,15 @@
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
"license": "MIT"
},
+ "node_modules/void-elements": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-3.1.0.tgz",
+ "integrity": "sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==",
+ "peer": true,
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
"node_modules/warning": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/warning/-/warning-4.0.3.tgz",
diff --git a/package.json b/package.json
index 14b6411..eae0e20 100644
--- a/package.json
+++ b/package.json
@@ -33,6 +33,7 @@
"google-map-react": "^2.2.1",
"lodash": "^4.17.21",
"next": "^13.4.3",
+ "next-i18next": "^15.3.1",
"rc-slider": "^10.1.1",
"react": "^18.2.0",
"react-datepicker": "^4.11.0",
diff --git a/public/favicon.ico b/public/favicon.ico
index 718d6fe..dbcafd7 100644
Binary files a/public/favicon.ico and b/public/favicon.ico differ
diff --git a/src/app/(account-pages)/(components)/Nav.tsx b/src/app/(account-pages)/(components)/Nav.tsx
index 1633962..5ea1fff 100644
--- a/src/app/(account-pages)/(components)/Nav.tsx
+++ b/src/app/(account-pages)/(components)/Nav.tsx
@@ -11,7 +11,6 @@ export const Nav = () => {
const listNav: Route[] = [
"/account",
"/my-trips",
- "/account-password",
"/passengers-list",
];
diff --git a/src/app/(account-pages)/account-password/page.tsx b/src/app/(account-pages)/account-password/page.tsx
deleted file mode 100644
index 5bc23bb..0000000
--- a/src/app/(account-pages)/account-password/page.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-import React from "react";
-import Label from "@/components/Label";
-import ButtonPrimary from "@/shared/ButtonPrimary";
-import Input from "@/shared/Input";
-
-const AccountPass = () => {
- return (
-
- {/* HEADING */}
-
Update your password
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Update password
-
-
-
- );
-};
-
-export default AccountPass;
diff --git a/src/app/(account-pages)/account/page.tsx b/src/app/(account-pages)/account/page.tsx
index e65cfca..ab4e60e 100644
--- a/src/app/(account-pages)/account/page.tsx
+++ b/src/app/(account-pages)/account/page.tsx
@@ -94,47 +94,62 @@ const AccountPage: FC = () => {
const changeHandler = async (): Promise => {
setError("");
setLoading({ change: true });
-
+
const formData = new FormData();
- formData.append("fullname", name);
- formData.append("email", email);
+
+ if (name !== user.fullname) {
+ formData.append("fullname", name);
+ }
+
+ if (email !== user.email) {
+ formData.append("email", email);
+ }
+
if (imageURL) {
formData.append("avatar", imageURL);
}
-
- try {
- const response = await axiosInstance.put(
- `/api/account/profile/update/`,
- formData,
- {
- headers: {
- Authorization: `token ${user.token}`,
- "Content-Type": "multipart/form-data",
- },
+
+ if (formData.has("fullname") || formData.has("email") || formData.has("avatar")) {
+ try {
+ const response = await axiosInstance.put(
+ `/api/account/profile/update/`,
+ formData,
+ {
+ headers: {
+ Authorization: `token ${user.token}`,
+ "Content-Type": "multipart/form-data",
+ },
+ }
+ );
+ if (response.status === 200) {
+ console.log(response);
+
+ toast.success("Updated successfully");
+ setUser({
+ ...user,
+ avatar: response.data.avatar,
+ email: response.data.email,
+ fullname: response.data.fullname,
+ phone_number: response.data.phone_number,
+ });
+ } else {
+ setError("Something went wrong");
}
- );
- if (response.status === 200) {
- toast.success("Updated successfully")
- setUser({
- ...user,
- avatar: response.data.avatar,
- email: response.data.email,
- fullname: response.data.fullname,
- phone_number: response.data.phone_number,
- });
- } else {
- setError("Something went wrong");
- }
- } catch (error: unknown) {
- if (error instanceof Error) {
- setError(error.message);
- } else {
- setError("An unknown error occurred");
+ } catch (error: unknown) {
+ if (error instanceof Error) {
+ setError(error.message);
+ } else {
+ setError("An unknown error occurred");
+ }
+ } finally {
+ setLoading({ change: false });
}
- } finally {
+ } else {
+ toast.info("No changes detected");
setLoading({ change: false });
}
};
+
const handleFileChange = async (e: ChangeEvent): Promise => {
const file : File | undefined = e.target.files?.[0];
diff --git a/src/app/(account-pages)/my-trips/page.tsx b/src/app/(account-pages)/my-trips/page.tsx
index e07b98d..f087405 100644
--- a/src/app/(account-pages)/my-trips/page.tsx
+++ b/src/app/(account-pages)/my-trips/page.tsx
@@ -9,7 +9,7 @@ import {
DEMO_EXPERIENCES_LISTINGS,
DEMO_STAY_LISTINGS,
} from "@/data/listings";
-import React, { Fragment, useEffect, useState } from "react";
+import React, { Fragment, use, useEffect, useState } from "react";
import ButtonSecondary from "@/shared/ButtonSecondary";
import axiosInstance from "@/components/api/axios";
import StayCard2 from "@/components/StayCard2";
diff --git a/src/app/(account-pages)/passengers-list/PassengerTable.tsx b/src/app/(account-pages)/passengers-list/PassengerTable.tsx
index 3401402..0a3052f 100644
--- a/src/app/(account-pages)/passengers-list/PassengerTable.tsx
+++ b/src/app/(account-pages)/passengers-list/PassengerTable.tsx
@@ -1,15 +1,17 @@
"use client";
import axiosInstance from "@/components/api/axios";
import { useUserContext } from "@/components/contexts/userContext";
+import { useRouter } from "next/navigation";
import React, { useEffect, useState } from "react";
import { IoMdTrash } from "react-icons/io";
import { MdEdit } from "react-icons/md";
const PassengerTable = ({ data }) => {
const { user } = useUserContext();
-
+ const router = useRouter()
const [show, setShow] = useState(true);
+
const deletHandler = async () => {
try {
const response = await axiosInstance.delete(
@@ -43,13 +45,11 @@ const PassengerTable = ({ data }) => {
{/* Action Icons */}
-
diff --git a/src/app/(account-pages)/passengers-list/[id]/page.tsx b/src/app/(account-pages)/passengers-list/[id]/page.tsx
new file mode 100644
index 0000000..7862b5e
--- /dev/null
+++ b/src/app/(account-pages)/passengers-list/[id]/page.tsx
@@ -0,0 +1,270 @@
+"use client";
+
+import React, { useEffect, useState } from "react";
+import { FC } from "react";
+import ButtonPrimary from "@/shared/ButtonPrimary";
+import Input from "@/shared/Input";
+import FormItem from "@/app/add-listing/FormItem";
+import getImageURL from "@/components/api/getImageURL";
+import axiosInstance from "@/components/api/axios";
+import { useRouter } from "next/navigation";
+import { useUserContext } from "@/components/contexts/userContext";
+import { toast } from "react-toastify"; // Import toast
+
+export interface CommonLayoutProps {
+ params: {
+ id: string;
+ };
+}
+
+const EditPassenger: FC = ({ params }) => {
+ const { user } = useUserContext();
+ const router = useRouter();
+
+ const [passenger, setPassenger] = useState({
+ name: "",
+ passport: "",
+ number: "",
+ date: "",
+ image: "",
+ });
+
+ const [originalPassenger, setOriginalPassenger] = useState({
+ name: "",
+ passport: "",
+ number: "",
+ date: "",
+ image: "",
+ });
+
+ const [loading, setLoading] = useState(false);
+
+ useEffect(() => {
+ if (Object.keys(user).length) {
+ axiosInstance
+ .get(`/api/account/passengers/${params.id}/`, {
+ headers: {
+ Authorization: `token ${user.token}`,
+ "Content-Type": "application/json",
+ "X-CSRFToken": "oli8in4JPf6taFVzg7tsY2g9Xpmox45yOBp1LrgU20tUFL5K4VkOrx7quXvOLUwW",
+ },
+ })
+ .then((response) => {
+ const passengerData = {
+ name: response.data.fullname,
+ passport: response.data.passport_number,
+ date: response.data.birthdate,
+ number: response.data.phone_number.replace(/\D/g, ""),
+ image: response.data.passport_image,
+ };
+ setPassenger(passengerData);
+ setOriginalPassenger(passengerData); // Save original data for comparison
+ })
+ .catch((error) => {
+ toast.error(error.message);
+ });
+ }
+ }, [user]);
+
+ const handleFileChange = async (e: React.ChangeEvent) => {
+ setLoading(true);
+ const file = e.target.files?.[0];
+ if (file) {
+ try {
+ const image = await getImageURL(file);
+ setPassenger((prev) => ({ ...prev, image: image.url }));
+ toast.success("Image uploaded successfully!");
+ } catch (error) {
+ toast.error("Error uploading image.");
+ } finally {
+ setLoading(false);
+ }
+ }
+ };
+
+ const validateForm = () => {
+ let formIsValid = true;
+
+ if (!passenger.name) {
+ formIsValid = false;
+ toast.error("Full Name is required.");
+ }
+
+ if (!passenger.passport) {
+ formIsValid = false;
+ toast.error("Passport Number is required.");
+ } else if (!/^\d+$/.test(passenger.passport)) {
+ formIsValid = false;
+ toast.error("Passport Number must be numeric.");
+ }
+
+ if (!passenger.date) {
+ formIsValid = false;
+ toast.error("Date of Birth is required.");
+ }
+
+ if (!passenger.number) {
+ formIsValid = false;
+ toast.error("Phone Number is required.");
+ } else if (!/^\d+$/.test(passenger.number)) {
+ formIsValid = false;
+ toast.error("Phone Number must be numeric.");
+ }
+
+ if (!passenger.image) {
+ formIsValid = false;
+ toast.error("Passport image is required.");
+ }
+
+ return formIsValid;
+ };
+
+ const handleSavePassenger = async () => {
+ if (!validateForm()) return;
+
+ const updatedFields: Partial = {};
+
+ // Only add fields that were changed
+ if (passenger.name !== originalPassenger.name) {
+ updatedFields.fullname = passenger.name;
+ }
+ if (passenger.passport !== originalPassenger.passport) {
+ updatedFields.passport_number = passenger.passport;
+ }
+ if (passenger.date !== originalPassenger.date) {
+ updatedFields.birthdate = passenger.date;
+ }
+ if (passenger.number !== originalPassenger.number) {
+ updatedFields.phone_number = passenger.number;
+ }
+ if (passenger.image !== originalPassenger.image) {
+ updatedFields.passport_image = passenger.image;
+ }
+
+ if (Object.keys(updatedFields).length === 0) {
+ toast.info("No changes to update.");
+ return;
+ }
+
+ try {
+ const response = await axiosInstance.patch(
+ `https://aqila.nwhco.ir/api/account/passengers/${params.id}/`,
+ updatedFields,
+ {
+ headers: {
+ Authorization: `token ${user.token}`,
+ "Content-Type": "application/json",
+ "X-CSRFToken": "oli8in4JPf6taFVzg7tsY2g9Xpmox45yOBp1LrgU20tUFL5K4VkOrx7quXvOLUwW",
+ },
+ }
+ );
+
+ if (response.status === 200) {
+ toast.success("Passenger details updated successfully!");
+ router.push("/passengers-list");
+ }
+ } catch (error) {
+ toast.error("Error saving passenger details.");
+ }
+ };
+
+ return (
+
+ );
+};
+
+export default EditPassenger;
diff --git a/src/app/(account-pages)/passengers-list/page.tsx b/src/app/(account-pages)/passengers-list/page.tsx
index 60762fc..04e54e3 100644
--- a/src/app/(account-pages)/passengers-list/page.tsx
+++ b/src/app/(account-pages)/passengers-list/page.tsx
@@ -6,10 +6,18 @@ import { IoPersonAddOutline } from "react-icons/io5";
import axiosInstance from "@/components/api/axios";
import Link from "next/link";
import { useUserContext } from "@/components/contexts/userContext";
+import { useRouter } from "next/navigation";
const PassengersList = () => {
const [passengers , setPassenger ] = useState([])
const {user} = useUserContext()
+const router = useRouter()
+
+useEffect(() => {
+ if (!Object.keys(user).length) {
+ router.replace("/");
+ }
+}, [user, router]);
useEffect(()=>{
axiosInstance.get("/api/account/passengers/" ,{
diff --git a/src/app/(client-components)/(Header)/MainNav1.tsx b/src/app/(client-components)/(Header)/MainNav1.tsx
index 77c7eaa..cee1d5c 100644
--- a/src/app/(client-components)/(Header)/MainNav1.tsx
+++ b/src/app/(client-components)/(Header)/MainNav1.tsx
@@ -20,6 +20,7 @@ export interface MainNav1Props {
const MainNav1: FC = ({ className = "" }) => {
const {user} = useUserContext()
+console.log(Object.keys(user).length);
return (
diff --git a/src/app/(client-components)/(HeroSearchForm)/GuestsInput.tsx b/src/app/(client-components)/(HeroSearchForm)/GuestsInput.tsx
index 004800f..3cb55a9 100644
--- a/src/app/(client-components)/(HeroSearchForm)/GuestsInput.tsx
+++ b/src/app/(client-components)/(HeroSearchForm)/GuestsInput.tsx
@@ -80,7 +80,7 @@ const GuestsInput: FC
= ({
{/* BUTTON SUBMIT OF FORM */}
{hasButtonSubmit && (
-
+
)}
diff --git a/src/app/(listing-detail)/(components)/MobileFooterSticky.tsx b/src/app/(listing-detail)/(components)/MobileFooterSticky.tsx
index a6ad8fc..410dc5a 100644
--- a/src/app/(listing-detail)/(components)/MobileFooterSticky.tsx
+++ b/src/app/(listing-detail)/(components)/MobileFooterSticky.tsx
@@ -62,13 +62,9 @@ const MobileFooterSticky = ({ data }) => {
className={`${
data?.status === "AVAILABLE" && passengers
? ""
- : "opacity-60 cursor-not-allowed"
- }`}
- href={`${
- data?.status === "AVAILABLE" && passengers
- ? `/add-listing/${id}`
- : `/tours/${data?.slug}-${id}`
+ : "opacity-60 pointer-events-none"
}`}
+ href={`/add-listing/${id}`}
>
Reserve
diff --git a/src/app/add-listing/[[...stepIndex]]/page.tsx b/src/app/add-listing/[[...stepIndex]]/page.tsx
index bf1ce2d..c1b59f5 100644
--- a/src/app/add-listing/[[...stepIndex]]/page.tsx
+++ b/src/app/add-listing/[[...stepIndex]]/page.tsx
@@ -1,5 +1,4 @@
-"use client";
-
+"use client"
import React, { useContext, useState, useEffect } from "react";
import { FC } from "react";
import ButtonPrimary from "@/shared/ButtonPrimary";
@@ -34,7 +33,7 @@ const CommonLayout: FC = ({ params }) => {
});
const [passengerID, setPassengerID] = useState([]);
const [selectedPassenger, setSelectedPassenger] = useState(null);
- const [redirecting, setRedirecting] = useState(false); // New state for redirection
+ const [redirecting, setRedirecting] = useState(false);
const tourID = params.stepIndex[0];
const totalPassengers = useContext(Context).passengers;
@@ -43,32 +42,30 @@ const CommonLayout: FC = ({ params }) => {
const backtHref = () => (index > 1 ? setIndex((prev) => prev - 1) : index);
const nextBtnText = index === totalPassengers ? "Save Passengers" : "Continue";
- useEffect(()=>{
+ useEffect(() => {
Object.values(errors).forEach((error) => {
toast.error(error, {
position: "top-right",
autoClose: 5000,
- hideProgressBar: false,
- closeOnClick: true,
- pauseOnHover: true,
- draggable: true,
- progress: undefined,
- theme: "light",
});
});
- } , [errors])
-
+ }, [errors]);
+
const sendPassengers = async () => {
+ const dataToSend = {
+ tour_id: tourID,
+ passengers: {
+ passenger_ids: passengerID,
+ new_passengers: passengers,
+ },
+ };
+
+ console.log("Data being sent:", dataToSend);
+
try {
const response = await axiosInstance.post(
"/api/tours/orders/purchase/",
- {
- tour_id: tourID,
- passengers: {
- passenger_ids: passengerID,
- new_passengers: passengers,
- },
- },
+ dataToSend,
{
headers: {
Authorization: `token ${user.token}`,
@@ -77,7 +74,7 @@ const CommonLayout: FC = ({ params }) => {
}
);
console.log(response);
- setRedirecting(true);
+ setRedirecting(true);
} catch (error) {
backtHref();
console.error("Error submitting passengers:", error);
@@ -87,7 +84,7 @@ const CommonLayout: FC = ({ params }) => {
useEffect(() => {
if (redirecting) {
router.replace("/my-trips");
- toast.success("Purchased Successfully ")
+ toast.success("Purchased Successfully ");
}
}, [redirecting, router]);
@@ -100,15 +97,20 @@ const CommonLayout: FC = ({ params }) => {
const nextHandler = () => {
const validationErrors = validatePassenger(newPassenger);
- if (Object.keys(validationErrors).length > 0 && passengerID.length < 0) {
+ if (Object.keys(validationErrors).length > 0 && passengerID.length === 0) {
setErrors(validationErrors);
console.log("Validation errors:", validationErrors, passengerID);
- console.log(passengerID.length > 0);
return;
}
- setSelectedPassenger(null);
+ if (selectedPassenger) {
+ // If an existing passenger is selected
+ setSelectedPassenger(null);
+ nextHref();
+ return;
+ }
+ // Add new passenger
setPassengers((prevPassengers) => [...prevPassengers, newPassenger]);
setNewPassenger({
fullname: "",
@@ -122,7 +124,6 @@ const CommonLayout: FC = ({ params }) => {
nextHref();
};
- // Prevent rendering while redirecting
if (redirecting) {
return null;
}
@@ -151,9 +152,6 @@ const CommonLayout: FC = ({ params }) => {
- {/* {index > 1 && (
- Go back
- )} */}
{nextBtnText}
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index d3d6e73..819b32f 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -12,6 +12,9 @@ import Footer from "@/components/Footer";
import FooterNav from "@/components/FooterNav";
import { UserProvider } from "@/components/contexts/userContext";
import { ToastContainer } from "react-toastify";
+import { appWithTranslation } from "next-i18next";
+import "react-toastify/dist/ReactToastify.css";
+
const poppins = Poppins({
subsets: ["latin"],
@@ -19,7 +22,7 @@ const poppins = Poppins({
weight: ["300", "400", "500", "600", "700"],
});
-export default function RootLayout({
+function RootLayout({
children,
params,
}: {
@@ -54,3 +57,4 @@ export default function RootLayout({