more
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { Routes, Route, Navigate } from "react-router-dom";
|
import { Routes, Route, Navigate } from "react-router-dom";
|
||||||
import { useAuth } from "./contexts/AuthContext";
|
import { useAuth } from "./contexts/AuthContext";
|
||||||
|
import { useContext } from 'react'
|
||||||
import Navbar from "./components/Navbar";
|
import Navbar from "./components/Navbar";
|
||||||
import Login from "./pages/login/Login";
|
import Login from "./pages/login/Login";
|
||||||
import Signup from "./pages/Signup";
|
import Signup from "./pages/Signup";
|
||||||
@@ -8,9 +9,11 @@ import Addresses from "./pages/addresses/Addresses";
|
|||||||
import Alerts from "./pages/alerts/Alerts";
|
import Alerts from "./pages/alerts/Alerts";
|
||||||
import AlertHistory from "./pages/alertHistory/AlertHistory";
|
import AlertHistory from "./pages/alertHistory/AlertHistory";
|
||||||
import Account from "./pages/user_account/Account";
|
import Account from "./pages/user_account/Account";
|
||||||
|
import { AuthProvider } from "./ShopContext";
|
||||||
|
import useAuth from "./ShopContext";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const { currentUser, isSubscribed } = useAuth();
|
const { context } = useContext(ShopContext)
|
||||||
|
|
||||||
if (!currentUser) {
|
if (!currentUser) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -33,13 +33,15 @@ export const AuthProvider = ({ children }) => {
|
|||||||
|
|
||||||
|
|
||||||
const value = {
|
const value = {
|
||||||
user: state.name,
|
authUser: state.name,
|
||||||
user: state.tier
|
authUserTier: state.tier,
|
||||||
|
addAuthUser,
|
||||||
|
logoutAuthUser
|
||||||
};
|
};
|
||||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useAuthContext = () => {
|
const useAuth = () => {
|
||||||
const context = useContext(ShopContext);
|
const context = useContext(ShopContext);
|
||||||
|
|
||||||
if (context === undefined) {
|
if (context === undefined) {
|
||||||
@@ -49,4 +51,4 @@ const useAuthContext = () => {
|
|||||||
return context;
|
return context;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useAuthContext;
|
export default useAuth;
|
||||||
|
|||||||
@@ -1,25 +1,38 @@
|
|||||||
import { useReducer } from "react"
|
import { useReducer } from "react"
|
||||||
|
|
||||||
const UserAuthContext = createContext();
|
|
||||||
|
|
||||||
export const initialState = {
|
export const initialState = {
|
||||||
authUser: null,
|
user: null,
|
||||||
AuthTier: null
|
tier: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const authReducer = (state, action) => {
|
const shopReducer = (state, action) => {
|
||||||
const { type, payload = "FREE_TIER" } = action
|
const { name, payload } = action;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "ADD_AUTH_USER":
|
case "ADD_TO_CART":
|
||||||
console.log("ADD_AUTH_USER", payload);
|
console.log("ADD_TO_CART", payload);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
auth: payload
|
products: payload.products
|
||||||
|
};
|
||||||
|
case "REMOVE_FROM_CART":
|
||||||
|
console.log("REMOVE_FROM_CART", payload);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
products: payload.products
|
||||||
|
};
|
||||||
|
case "UPDATE_PRICE":
|
||||||
|
console.log("UPDATE_PRICE", payload);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
total: payload.total
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
throw new Error(`No case for type ${type} found.`);
|
throw new Error(`No case for type ${type} found in shopReducer.`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export default shopReducer
|
export default shopReducer;
|
||||||
Reference in New Issue
Block a user