Browse Source

myTrip bugs fixed

main
sina_sajjadi 3 months ago
parent
commit
de5bcf1faa
  1. 14
      src/app/(account-pages)/my-trips/page.tsx
  2. 118
      src/app/signup/methodes/page.tsx
  3. 41
      tsconfig.json

14
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/", {

118
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() {
</h2>
<form className="grid grid-cols-1 gap-6">
{/* WhatsApp Option */}
<div
className={`${
!enabled.watsapp ? "opacity-40" : ""
@ -126,12 +111,13 @@ function SelectMethods() {
name="method"
value="whatsapp"
checked={selectedMethod === "whatsapp"}
onChange={(e) => handleMethodChange(e)}
onChange={handleMethodChange}
disabled={!enabled.watsapp}
className="cursor-pointer form-radio accent-black text-black focus:ring-primary-500 focus:ring-2"
/>
</div>
{/* SMS Option */}
<div
className={`${
!enabled.sms ? "opacity-40" : ""
@ -154,14 +140,16 @@ function SelectMethods() {
name="method"
value="sms"
checked={selectedMethod === "sms"}
onChange={(e) => handleMethodChange(e)}
onChange={handleMethodChange}
disabled={!enabled.sms}
className="cursor-pointer form-radio accent-black text-black focus:ring-primary-500 focus:ring-2"
/>
</div>
{/* Continue Button */}
{/* Error Message */}
{error && <p className="text-xs text-red-500">{error.message}</p>}
{/* Continue Button */}
<ButtonPrimary
loading={loading}
onClick={(e) => {

41
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"
]
}
Loading…
Cancel
Save