diff --git a/src/app/(account-pages)/my-trips/page.tsx b/src/app/(account-pages)/my-trips/page.tsx index 3bc0104..e07b98d 100644 --- a/src/app/(account-pages)/my-trips/page.tsx +++ b/src/app/(account-pages)/my-trips/page.tsx @@ -14,18 +14,18 @@ import ButtonSecondary from "@/shared/ButtonSecondary"; import axiosInstance from "@/components/api/axios"; import StayCard2 from "@/components/StayCard2"; import { useRouter } from "next/navigation"; +import { useUserContext } from "@/components/contexts/userContext"; const MyTrips = () => { const router = useRouter() - let [categories] = useState(["Stays", "Experiences", "Cars"]); let [tours , setTours] = useState([]); - const [ user ] =useState() - - if(!user){ - router.replace("/") - return null - } + const { user } =useUserContext() + useEffect(() => { + if (!Object.keys(user).length) { + router.replace("/"); + } + }, [user, router]); useEffect(() => { axiosInstance .get("/api/tours/orders/", { diff --git a/src/app/signup/methodes/page.tsx b/src/app/signup/methodes/page.tsx index 0818fae..2ba409a 100644 --- a/src/app/signup/methodes/page.tsx +++ b/src/app/signup/methodes/page.tsx @@ -4,26 +4,29 @@ import axiosInstance from "@/components/api/axios"; import { useUserContext } from "@/components/contexts/userContext"; import ButtonPrimary from "@/shared/ButtonPrimary"; import { useRouter } from "next/navigation"; -import { useContext, useState } from "react"; +import { useEffect, useState } from "react"; import { FaWhatsapp } from "react-icons/fa"; import { MdOutlineTextsms } from "react-icons/md"; function SelectMethods() { const router = useRouter(); - const { user } = useUserContext(); - // if (Object.keys(user).length) { - // return router.replace("/"); - // } - const { form } = useUserContext(); + const { user, form } = useUserContext(); + const [selectedMethod, setSelectedMethod] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); - const enabled = { - watsapp: form.verification_methodes.join().includes("watsapp"), - sms: form.verification_methodes.join().includes("sms"), - }; + // Initialize 'enabled' with default values + const [enabled, setEnabled] = useState({ watsapp: false, sms: false }); + useEffect(() => { + // Safely access 'form.verification_methods' and update 'enabled' + setEnabled({ + watsapp: form.verification_methodes?.includes("watsapp") ?? false, + sms: form.verification_methodes?.includes("sms") ?? false, + }); + }, []); + const handleMethodChange = (e) => { if (!enabled.watsapp && !enabled.sms) { setSelectedMethod(""); @@ -35,65 +38,46 @@ function SelectMethods() { setSelectedMethod(e.target.value); } }; - console.log(form); const handleSubmit = async () => { setLoading(true); - switch (form.method) { - case "register": - try { - const response = await axiosInstance.post( - `/api/account/register/`, - { - fullname: form.name, - phone_number: form.phoneNumber, - verification_method: selectedMethod, - range_phone: form.countryCode, - password: form.password, - password_confirmation: form.confirmPassword, - }, - { - headers: { - Accept: "application/json", - }, - } - ); - response.status === 202 && - (setLoading(false), router.replace("signup/otp-code")); - } catch (error) { - setError(error); - console.log(error); + try { + const payload = { + phone_number: form.phoneNumber, + verification_method: selectedMethod, + range_phone: form.countryCode, + }; + + if (form.method === "register") { + payload.fullname = form.name; + payload.password = form.password; + payload.password_confirmation = form.confirmPassword; + + const response = await axiosInstance.post(`/api/account/register/`, payload, { + headers: { Accept: "application/json" }, + }); + + if (response.status === 202) { setLoading(false); + router.replace("signup/otp-code"); } - break; - case "reset": - try { - const response = await axiosInstance.post( - `/api/account/recover/`, - { - phone_number: form.phoneNumber, - verification_method: selectedMethod, - range_phone: form.countryCode, - password: form.password, - password_confirmation: form.confirmPassword, - }, - { - headers: { - Accept: "application/json", - }, - } - ); - response.status === 202 && - (setLoading(false), router.replace("signup/otp-code")); - } catch (error) { - setError(error); - console.log(error); + } else if (form.method === "reset") { + payload.password = form.password; + payload.password_confirmation = form.confirmPassword; + + const response = await axiosInstance.post(`/api/account/recover/`, payload, { + headers: { Accept: "application/json" }, + }); + + if (response.status === 202) { setLoading(false); + router.replace("signup/otp-code"); } - break; - - default: - break; + } + } catch (error) { + setError(error); + console.log(error); + setLoading(false); } }; @@ -104,6 +88,7 @@ function SelectMethods() {
+ {/* WhatsApp Option */}
handleMethodChange(e)} + onChange={handleMethodChange} disabled={!enabled.watsapp} className="cursor-pointer form-radio accent-black text-black focus:ring-primary-500 focus:ring-2" />
+ {/* SMS Option */}
handleMethodChange(e)} + onChange={handleMethodChange} disabled={!enabled.sms} className="cursor-pointer form-radio accent-black text-black focus:ring-primary-500 focus:ring-2" />
- {/* Continue Button */} + {/* Error Message */} {error &&

{error.message}

} + + {/* Continue Button */} { diff --git a/tsconfig.json b/tsconfig.json index 44a8e25..443a6f0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,11 @@ { "compilerOptions": { "target": "es5", - "lib": ["dom", "dom.iterable", "esnext"], + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], "allowJs": true, "skipLibCheck": true, "strict": true, @@ -16,19 +20,48 @@ // "paths": { // }, "incremental": true, + "paths": { + "@/*": [ + "./src/*" + ], + "@components/*": [ + "src/components/*" + ], + "@containers/*": [ + "src/containers/*" + ], + "@contexts/*": [ + "src/contexts/*" + ], + "@framework/*": [ + "src/framework/basic-rest/*" + ], + "@settings/*": [ + "src/settings/*" + ], + "@styles/*": [ + "src/styles/*" + ], + "@utils/*": [ + "src/utils/*" + ] + }, "baseUrl": ".", "plugins": [ { "name": "next" } - ], + ] }, // "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "include": [ "next-env.d.ts", "additional.d.ts", "src/**/*.ts", - "src/**/*.tsx" + "src/**/*.tsx", + ".next/types/**/*.ts" ], - "exclude": ["node_modules"] + "exclude": [ + "node_modules" + ] }