From 03a018a551345ba757dc3d180ab445e95f929065 Mon Sep 17 00:00:00 2001 From: sina_sajjadi Date: Mon, 16 Sep 2024 13:35:31 +0330 Subject: [PATCH] build bugs fixed --- src/app/(account-pages)/account/page.tsx | 143 +-- .../(client-components)/(Header)/MainNav1.tsx | 19 +- .../SectionGridFilterCard.tsx | 105 --- src/app/(flight-listings)/TabFilters.tsx | 858 ------------------ .../listing-flights/page.tsx | 47 - src/app/forgot-password/page.tsx | 4 +- src/app/login/page.tsx | 4 +- src/app/signup/methodes/page.tsx | 4 +- src/app/signup/otp-code/page.tsx | 4 +- src/app/signup/page.tsx | 4 +- src/components/contexts/userContext.tsx | 39 +- 11 files changed, 130 insertions(+), 1101 deletions(-) delete mode 100644 src/app/(flight-listings)/SectionGridFilterCard.tsx delete mode 100644 src/app/(flight-listings)/TabFilters.tsx delete mode 100644 src/app/(flight-listings)/listing-flights/page.tsx diff --git a/src/app/(account-pages)/account/page.tsx b/src/app/(account-pages)/account/page.tsx index 4d9a106..dcf5072 100644 --- a/src/app/(account-pages)/account/page.tsx +++ b/src/app/(account-pages)/account/page.tsx @@ -1,5 +1,5 @@ "use client"; -import React, { useContext, useState } from "react"; +import React, { useState, ChangeEvent, FC } from "react"; import Label from "@/components/Label"; import Avatar from "@/shared/Avatar"; import ButtonPrimary from "@/shared/ButtonPrimary"; @@ -7,69 +7,91 @@ import Input from "@/shared/Input"; import ButtonSecondary from "@/shared/ButtonSecondary"; import axiosInstance from "@/components/api/axios"; import { useRouter } from "next/navigation"; -import { user as UserContext } from "@/components/contexts/userContext"; +import { useUserContext } from "@/components/contexts/userContext"; import getImageURL from "@/components/api/getImageURL"; export interface AccountPageProps {} -const AccountPage = () => { +interface User { + fullname: string; + email: string; + phone_number: string; + avatar: string; + token: string; +} + +interface LoadingState { + delete?: boolean; + change?: boolean; +} + +interface APIResponse { + data: { + avatar: string; + email: string; + fullname: string; + phone_number: string; + }; +} + +const AccountPage: FC = () => { const router = useRouter(); - const User = JSON.parse(localStorage.getItem("user")); - let user = JSON.parse(localStorage.getItem("user")); + const storedUser = localStorage.getItem("user"); + let user: User | null = storedUser ? JSON.parse(storedUser) : null; + if (!user) { - return router.replace("/"); + router.replace("/"); + return null; // Prevent rendering if no user data is found } - const { setStatus } = useContext(UserContext); - const [name, setName] = useState(user.fullname || ""); - const [email, setEmail] = useState(user.email || ""); - const [number, setNumber] = useState(user.phone_number || ""); - const [password, setPassword] = useState(""); + const { setStatus } = useUserContext(); + + const [name, setName] = useState(user.fullname || ""); + const [email, setEmail] = useState(user.email || ""); + const [number, setNumber] = useState(user.phone_number || ""); + const [password, setPassword] = useState(""); const [image, setImage] = useState(null); const [imageURL, setImageURL] = useState(null); - const [error, setError] = useState(""); - const [loading, setLoading] = useState({}); + const [error, setError] = useState(""); + const [loading, setLoading] = useState({}); - const deleteHandler = async () => { + const deleteHandler = async (): Promise => { setError(""); - setLoading({delete : true}) + setLoading({ delete: true }); try { - const response = await axiosInstance.delete( - `/api/account/profile/delete/`, - { - headers: { - Authorization: `token ${user.token}`, - }, - } - ); + const response = await axiosInstance.delete(`/api/account/profile/delete/`, { + headers: { + Authorization: `token ${user?.token}`, + }, + }); if (response.status === 204) { localStorage.removeItem("user"); setStatus(false); - router.replace("/"); } else { setError("Something went wrong"); } - } catch (error) { - setError(error.message); - - } finally{ - setLoading({delete : false}) - - + } catch (error: unknown) { + if (error instanceof Error) { + setError(error.message); + } else { + setError("An unknown error occurred"); } + } finally { + setLoading({ delete: false }); + } }; - const signOutHandler = () => { + + const signOutHandler = (): void => { localStorage.removeItem("user"); setStatus(false); - router.replace("/"); }; - const changeHandler = async () => { + const changeHandler = async (): Promise => { setError(""); - setLoading({change : true}) + setLoading({ change: true }); const formData = new FormData(); formData.append("fullname", name); @@ -80,7 +102,7 @@ const AccountPage = () => { } try { - const response = await axiosInstance.put( + const response = await axiosInstance.put( `/api/account/profile/update/`, formData, { @@ -91,36 +113,34 @@ const AccountPage = () => { } ); if (response.status === 200) { - console.log(response); - - user.avatar = response.data.avatar; - user.email = response.data.email; - user.fullname = response.data.fullname; - user.phone_number = response.data.phone_number; - + user = { + ...user, + avatar: response.data.avatar, + email: response.data.email, + fullname: response.data.fullname, + phone_number: response.data.phone_number, + }; localStorage.setItem("user", JSON.stringify(user)); - } else { setError("Something went wrong"); - } - } catch (error) { - setError(error.message); - - } finally{ - setLoading({change : false}) - + } catch (error: unknown) { + if (error instanceof Error) { + setError(error.message); + } else { + setError("An unknown error occurred"); + } + } finally { + setLoading({ change: false }); } }; - const handleFileChange = async (e: React.ChangeEvent) => { + const handleFileChange = async (e: ChangeEvent): Promise => { const file = e.target.files?.[0]; if (file) { const uploadedFile = await getImageURL(file); - setImageURL(uploadedFile.url); } - setImage(file); }; @@ -132,9 +152,7 @@ const AccountPage = () => {
@@ -199,17 +217,16 @@ const AccountPage = () => { className="mt-1.5" />
- {error &&

{error}

} -
- + {error &&

{error}

} +
+ Update info - - {" "} + Sign out diff --git a/src/app/(client-components)/(Header)/MainNav1.tsx b/src/app/(client-components)/(Header)/MainNav1.tsx index f43f1d6..f924621 100644 --- a/src/app/(client-components)/(Header)/MainNav1.tsx +++ b/src/app/(client-components)/(Header)/MainNav1.tsx @@ -11,21 +11,22 @@ import HeroSearchForm2MobileFactory from "../(HeroSearchForm2Mobile)/HeroSearchF import { MdOutlineLanguage } from "react-icons/md"; import Avatar from "@/shared/Avatar"; import Link from "next/link"; -import { user } from "@/components/contexts/userContext"; +import { useUserContext } from "@/components/contexts/userContext"; export interface MainNav1Props { className?: string; } const MainNav1: FC = ({ className = "" }) => { - const { status, setStatus } = useContext(user); + const { status, setStatus } =useUserContext(); + const [userData , setUserData] =useState({}) + + useEffect(()=>{ + setUserData(JSON.parse(localStorage.getItem("user"))) + userData? setStatus(true) : setStatus(false) - const User = JSON.parse(localStorage.getItem("user")) - -useEffect(()=>{ - User? setStatus(true) : setStatus(false) - -} , []) +} , [status]) +console.log(status); return (
@@ -51,7 +52,7 @@ useEffect(()=>{
{status ? ( diff --git a/src/app/(flight-listings)/SectionGridFilterCard.tsx b/src/app/(flight-listings)/SectionGridFilterCard.tsx deleted file mode 100644 index b7fdb57..0000000 --- a/src/app/(flight-listings)/SectionGridFilterCard.tsx +++ /dev/null @@ -1,105 +0,0 @@ -import React, { FC } from "react"; -import TabFilters from "./TabFilters"; -import Heading2 from "@/shared/Heading2"; -import FlightCard, { FlightCardProps } from "@/components/FlightCard"; -import ButtonPrimary from "@/shared/ButtonPrimary"; - -export interface SectionGridFilterCardProps { - className?: string; -} - -const DEMO_DATA: FlightCardProps["data"][] = [ - { - id: "1", - price: "$4,100", - airlines: { - logo: "https://www.gstatic.com/flights/airline_logos/70px/KE.png", - name: "Korean Air", - }, - }, - { - id: "2", - price: "$3,380", - airlines: { - logo: "https://www.gstatic.com/flights/airline_logos/70px/SQ.png", - name: "Singapore Airlines", - }, - }, - { - id: "3", - price: "$2,380", - airlines: { - logo: "https://www.gstatic.com/flights/airline_logos/70px/multi.png", - name: "Philippine Airlines", - }, - }, - { - id: "1", - price: "$4,100", - airlines: { - logo: "https://www.gstatic.com/flights/airline_logos/70px/KE.png", - name: "Korean Air", - }, - }, - { - id: "2", - price: "$3,380", - airlines: { - logo: "https://www.gstatic.com/flights/airline_logos/70px/SQ.png", - name: "Singapore Airlines", - }, - }, - { - id: "1", - price: "$4,100", - airlines: { - logo: "https://www.gstatic.com/flights/airline_logos/70px/KE.png", - name: "Korean Air", - }, - }, - { - id: "2", - price: "$3,380", - airlines: { - logo: "https://www.gstatic.com/flights/airline_logos/70px/SQ.png", - name: "Singapore Airlines", - }, - }, -]; - -const SectionGridFilterCard: FC = ({ - className = "", -}) => { - return ( -
- - 22 flights - · - round trip - ·2 Guests - - } - /> -
- -
-
- {DEMO_DATA.map((item, index) => ( - - ))} - -
- Show more -
-
-
- ); -}; - -export default SectionGridFilterCard; diff --git a/src/app/(flight-listings)/TabFilters.tsx b/src/app/(flight-listings)/TabFilters.tsx deleted file mode 100644 index 3496c85..0000000 --- a/src/app/(flight-listings)/TabFilters.tsx +++ /dev/null @@ -1,858 +0,0 @@ -"use client"; - -import React, { Fragment, useState } from "react"; -import { Dialog, Popover, Tab, Transition } from "@headlessui/react"; -import ButtonPrimary from "@/shared/ButtonPrimary"; -import ButtonThird from "@/shared/ButtonThird"; -import ButtonClose from "@/shared/ButtonClose"; -import Checkbox from "@/shared/Checkbox"; -import convertNumbThousand from "@/utils/convertNumbThousand"; -import Slider from "rc-slider"; -import { XMarkIcon } from "@heroicons/react/24/outline"; - -// DEMO DATA -const typeOfAirlines = [ - { - name: "Star Alliance", - }, - { - name: "Air China", - }, - { - name: "Air India", - }, - { - name: "Air New Zealand", - }, - { - name: "Asiana", - }, - { - name: "Bangkok Airways", - }, -]; -const stopPoints = [ - { - name: "Nonstop", - }, - { - name: "Up to 1 stops", - }, - { - name: "Up to 2 stops", - }, - { - name: "Any number of stops", - }, -]; - -// -const TabFilters = () => { - const [isOpenMoreFilter, setisOpenMoreFilter] = useState(false); - // - const [isOnSale, setIsOnSale] = useState(true); - const [rangePrices, setRangePrices] = useState([100, 5000]); - const [tripTimes, setTripTimes] = useState(10); - const [stopPontsStates, setStopPontsStates] = useState([]); - const [airlinesStates, setAirlinesStates] = useState([]); - - // - let [catTimes, setCatTimes] = useState({ - "Take Off": { - Departure: [0, 24], - Arrival: [0, 24], - }, - Landing: { - Departure: [0, 24], - Arrival: [0, 24], - }, - }); - - // - const closeModalMoreFilter = () => setisOpenMoreFilter(false); - const openModalMoreFilter = () => setisOpenMoreFilter(true); - - // - const handleChangeStopPoint = (checked: boolean, name: string) => { - checked - ? setStopPontsStates([...stopPontsStates, name]) - : setStopPontsStates(stopPontsStates.filter((i) => i !== name)); - }; - - const handleChangeAirlines = (checked: boolean, name: string) => { - checked - ? setAirlinesStates([...airlinesStates, name]) - : setAirlinesStates(airlinesStates.filter((i) => i !== name)); - }; - - // - - const renderXClear = () => { - return ( - - - - ); - }; - - const renderTabsTimeFlightTab = () => { - return ( -
- - - {Object.keys(catTimes).map((category) => ( - - `w-full py-2.5 text-sm leading-5 font-medium text-primary-700 dark:text-primary-400 rounded-lg focus:outline-none focus:ring-2 ring-offset-2 ring-offset-blue-400 ring-white ring-opacity-60 ${ - selected - ? "bg-white dark:bg-neutral-800 shadow" - : " hover:bg-white/[0.15] dark:hover:bg-neutral-800" - }` - } - > - {category} - - ))} - - - {Object.values(catTimes).map((posts, idx) => { - return ( - - - {idx ? " Tokyo to Singapore" : " Singapore to Tokyo"} - -
-
-
- - Departure time: - - {posts.Departure[0]}:00 - {posts.Departure[1]} - :00 - -
- - setCatTimes((catTimes) => - !idx - ? { - ...catTimes, - "Take Off": { - ...posts, - Departure: val as [number, number], - }, - } - : { - ...catTimes, - Landing: { - ...posts, - Departure: val as [number, number], - }, - } - ) - } - allowCross={false} - /> -
-
-
- - Arrival time: - - {posts.Arrival[0]}:00 - {posts.Arrival[1]}:00 - -
- - setCatTimes((catTimes) => - !idx - ? { - ...catTimes, - "Take Off": { - ...posts, - Arrival: val as [number, number], - }, - } - : { - ...catTimes, - Landing: { - ...posts, - Arrival: val as [number, number], - }, - } - ) - } - allowCross={false} - /> -
-
- ); - })} -
-
-
- ); - }; - - const renderTabsTypeOfAirlines = () => { - return ( - - {({ open, close }) => ( - <> - - Airlines - {!airlinesStates.length ? ( - - ) : ( - setAirlinesStates([])}> - {renderXClear()} - - )} - - - -
-
- - handleChangeAirlines(checked, "All Airlines") - } - /> -
- {typeOfAirlines.map((item) => ( -
- - handleChangeAirlines(checked, item.name) - } - /> -
- ))} -
-
- { - close(); - setAirlinesStates([]); - }} - sizeClass="px-4 py-2 sm:px-5" - > - Clear - - - Apply - -
-
-
-
- - )} -
- ); - }; - - const renderTabsStopPoints = () => { - return ( - - {({ open, close }) => ( - <> - - Stop points - {!stopPontsStates.length ? ( - - ) : ( - setStopPontsStates([])}> - {renderXClear()} - - )} - - - -
-
- {stopPoints.map((item) => ( -
- - handleChangeStopPoint(checked, item.name) - } - /> -
- ))} -
-
- { - close(); - setStopPontsStates([]); - }} - sizeClass="px-4 py-2 sm:px-5" - > - Clear - - - Apply - -
-
-
-
- - )} -
- ); - }; - - const renderTabsTimeFlight = () => { - return ( - - {({ open, close }) => ( - <> - - Flight time - - - - -
-
- {renderTabsTimeFlightTab()} -
-
- - Clear - - - Apply - -
-
-
-
- - )} -
- ); - }; - - const renderTabsTripTime = () => { - return ( - - {({ open, close }) => ( - <> - - less than {tripTimes} hours - {renderXClear()} - - - -
-
-
-
- Trip time: - {` <${tripTimes} hours`} -
- - setTripTimes(e as number)} - /> -
-
-
- - Clear - - - Apply - -
-
-
-
- - )} -
- ); - }; - - const renderTabsPriceRage = () => { - return ( - - {({ open, close }) => ( - <> - - - {`$${convertNumbThousand( - rangePrices[0] - )} - $${convertNumbThousand(rangePrices[1])}`}{" "} - - {renderXClear()} - - - -
-
-
- Price per person - setRangePrices(e as number[])} - /> -
- -
-
- -
-
- - $ - -
- -
-
-
- -
-
- - $ - -
- -
-
-
-
-
- - Clear - - - Apply - -
-
-
-
- - )} -
- ); - }; - - const renderTabOnSale = () => { - return ( -
setIsOnSale(!isOnSale)} - > - On sale - {isOnSale && renderXClear()} -
- ); - }; - - const renderMoreFilterItem = ( - data: { - name: string; - description?: string; - defaultChecked?: boolean; - }[] - ) => { - const list1 = data.filter((_, i) => i < data.length / 2); - const list2 = data.filter((_, i) => i >= data.length / 2); - return ( -
-
- {list1.map((item) => ( - - ))} -
-
- {list2.map((item) => ( - - ))} -
-
- ); - }; - - // FOR RESPONSIVE MOBILE - const renderTabMobileFilter = () => { - return ( -
-
- - Flights filters (3) - - {renderXClear()} -
- - - -
- - - - - {/* This element is to trick the browser into centering the modal contents. */} - - -
-
- - Flight filters - - - - -
- -
-
- {/* --------- */} - {/* ---- */} -
-

Airlines

-
- {renderMoreFilterItem(typeOfAirlines)} -
-
- {/* --------- */} - {/* ---- */} -
-

Stop points

-
- {renderMoreFilterItem(stopPoints)} -
-
- - {/* --------- */} - {/* ---- */} -
-

Range Prices

-
-
-
- setRangePrices(e as number[])} - /> -
- -
-
- -
-
- - $ - -
- -
-
-
- -
-
- - $ - -
- -
-
-
-
-
-
- - {/* --------- */} - {/* ---- */} -
-

- Strip times - {` <${tripTimes} hours`} -

-
- setTripTimes(e as number)} - /> -
-
- - {/* --------- */} - {/* ---- */} -
-

Flight times

-
- {renderTabsTimeFlightTab()} -
-
-
-
- -
- - Clear - - - Apply - -
-
-
-
-
-
-
- ); - }; - - return ( -
- {/* FOR DESKTOP */} -
- {renderTabsTypeOfAirlines()} - {renderTabsTripTime()} - {renderTabsStopPoints()} - {renderTabsPriceRage()} - {renderTabsTimeFlight()} - {renderTabOnSale()} -
- - {/* FOR RESPONSIVE MOBILE */} -
- {renderTabMobileFilter()} - {renderTabOnSale()} -
-
- ); -}; - -export default TabFilters; diff --git a/src/app/(flight-listings)/listing-flights/page.tsx b/src/app/(flight-listings)/listing-flights/page.tsx deleted file mode 100644 index 19ad9a9..0000000 --- a/src/app/(flight-listings)/listing-flights/page.tsx +++ /dev/null @@ -1,47 +0,0 @@ -import SectionHeroArchivePage from "@/app/(server-components)/SectionHeroArchivePage"; -import BgGlassmorphism from "@/components/BgGlassmorphism"; -import SectionSliderNewCategories from "@/components/SectionSliderNewCategories"; -import SectionSubscribe2 from "@/components/SectionSubscribe2"; -import React, { FC } from "react"; -import SectionGridFilterCard from "../SectionGridFilterCard"; - -export interface ListingFlightsPageProps {} - -const ListingFlightsPage: FC = ({}) => { - return ( -
- - -
- {/* SECTION HERO */} - - - 1599 flights - - } - className="pt-10 pb-24 lg:pb-28 lg:pt-16 " - /> - - {/* SECTION */} - - - {/* SECTION 1 */} - - - {/* SECTION */} - -
-
- ); -}; - -export default ListingFlightsPage; diff --git a/src/app/forgot-password/page.tsx b/src/app/forgot-password/page.tsx index e81b59c..f5309ef 100644 --- a/src/app/forgot-password/page.tsx +++ b/src/app/forgot-password/page.tsx @@ -9,7 +9,7 @@ import ButtonPrimary from "@/shared/ButtonPrimary"; import Image from "next/image"; import Link from "next/link"; import axiosInstance from "@/components/api/axios"; -import { user } from "@/components/contexts/userContext"; +import { useUserContext } from "@/components/contexts/userContext"; import useFormValidation from "@/hooks/FormValidation"; import { useRouter } from "next/navigation"; @@ -19,7 +19,7 @@ const PageSignUp: FC = ({}) => { const router = useRouter() - const { setForm , setMethod } = useContext(user); + const { setForm , setMethod } = useUserContext(); const [name, setName] = useState(''); const [countryCode, setCountryCode] = useState(''); diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index b2ec43b..c6e316e 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -8,7 +8,7 @@ import Image from "next/image"; import Link from "next/link"; import axiosInstance from "@/components/api/axios"; import { useRouter } from "next/navigation"; -import { user as UserContext } from "@/components/contexts/userContext"; +import { useUserContext } from "@/components/contexts/userContext"; export interface PageLoginProps {} const PageLogin: FC = ({}) => { @@ -18,7 +18,7 @@ const PageLogin: FC = ({}) => { if (user) { return router.replace("/") } - const { setStatus } = useContext(UserContext); + const { setStatus } = useUserContext(); const [phoneNumber, setPhoneNumber] = useState(""); const [password, setPassword] = useState(""); diff --git a/src/app/signup/methodes/page.tsx b/src/app/signup/methodes/page.tsx index 0b50a26..3747bb4 100644 --- a/src/app/signup/methodes/page.tsx +++ b/src/app/signup/methodes/page.tsx @@ -1,7 +1,7 @@ "use client"; import axiosInstance from "@/components/api/axios"; -import { user } from "@/components/contexts/userContext"; +import { useUserContext } from "@/components/contexts/userContext"; import ButtonPrimary from "@/shared/ButtonPrimary"; import { useRouter } from "next/navigation"; import { useContext, useState } from "react"; @@ -14,7 +14,7 @@ function SelectMethods() { if (User) { return router.replace("/"); } - const { method, form } = useContext(user); + const { method, form } = useUserContext(); const [selectedMethod, setSelectedMethod] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(""); diff --git a/src/app/signup/otp-code/page.tsx b/src/app/signup/otp-code/page.tsx index 1b700d1..530a0a4 100644 --- a/src/app/signup/otp-code/page.tsx +++ b/src/app/signup/otp-code/page.tsx @@ -3,7 +3,7 @@ import React, { FC, useContext, useState, useEffect, useRef } from "react"; import ButtonPrimary from "@/shared/ButtonPrimary"; import axiosInstance from "@/components/api/axios"; -import { user as userContext } from "@/components/contexts/userContext"; +import { useUserContext } from "@/components/contexts/userContext"; import useFormValidation from "@/hooks/FormValidation"; import { useRouter } from "next/navigation"; @@ -12,7 +12,7 @@ export interface PageSignUpProps {} const PageSignUp: FC = () => { const router = useRouter(); const user = JSON.parse(localStorage.getItem("user")); - const { form, setMethod, setStatus } = useContext(userContext); + const { form, setMethod, setStatus } = useUserContext(); const [otp, setOtp] = useState(["", "", "", "", ""]); diff --git a/src/app/signup/page.tsx b/src/app/signup/page.tsx index 3d4099e..13f9ff4 100644 --- a/src/app/signup/page.tsx +++ b/src/app/signup/page.tsx @@ -5,7 +5,7 @@ import Input from "@/shared/Input"; import ButtonPrimary from "@/shared/ButtonPrimary"; import Link from "next/link"; import axiosInstance from "@/components/api/axios"; -import { user as UserContext } from "@/components/contexts/userContext"; +import { useUserContext } from "@/components/contexts/userContext"; import useFormValidation from "@/hooks/FormValidation"; import { useRouter } from "next/navigation"; @@ -20,7 +20,7 @@ const PageSignUp: FC = () => { return null; // Avoid rendering the component if the user is already logged in } - const { setForm, setMethod } = useContext(UserContext); + const { setForm, setMethod } = useUserContext(); const [name, setName] = useState(""); const [countryCode, setCountryCode] = useState(""); diff --git a/src/components/contexts/userContext.tsx b/src/components/contexts/userContext.tsx index 3fe5034..9e2182c 100644 --- a/src/components/contexts/userContext.tsx +++ b/src/components/contexts/userContext.tsx @@ -1,16 +1,29 @@ "use client"; -import axiosInstance from "../api/axios"; -import React, { createContext, useEffect, useState } from "react"; -export const user = createContext(); +import React, { createContext, useContext, useState, ReactNode } from "react"; -export const UserProvider = ({ children }) => { - const [status, setStatus] = useState(false); - const [form, setForm] = useState({}); - const [method, setMethod] = useState([]); +type UserContextType = { + status: boolean; + setStatus: (status: boolean) => void; + form: Record; + setForm: (form: Record) => void; + method: any[]; + setMethod: (method: any[]) => void; +}; + +const UserContext = createContext(undefined); + +type UserProviderProps = { + children: ReactNode; +}; + +export const UserProvider: React.FC = ({ children }) => { + const [status, setStatus] = useState(false); + const [form, setForm] = useState>({}); + const [method, setMethod] = useState([]); return ( - { }} > {children} - + ); }; + +export const useUserContext = () => { + const context = useContext(UserContext); + if (!context) { + throw new Error("useUserContext must be used within a UserProvider"); + } + return context; +};