more
This commit is contained in:
@@ -1,38 +1,32 @@
|
|||||||
import { useReducer } from "react"
|
import { useReducer } from "react"
|
||||||
|
|
||||||
|
const UserAuthContext = createContext();
|
||||||
|
|
||||||
export const initialState = {
|
export const initialState = {
|
||||||
user: null,
|
authUser: null,
|
||||||
tier: null,
|
AuthTier: null
|
||||||
};
|
};
|
||||||
|
|
||||||
const shopReducer = (state, action) => {
|
const authReducer = (state, action) => {
|
||||||
const { name, payload } = action;
|
const { type, payload = "FREE_TIER" } = action
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "ADD_TO_CART":
|
case "ADD_AUTH_USER":
|
||||||
console.log("ADD_TO_CART", payload);
|
console.log("ADD_AUTH_USER", payload);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
products: payload.products
|
auth: payload
|
||||||
};
|
|
||||||
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 in shopReducer.`);
|
throw new Error(`No case for type ${type} found.`);
|
||||||
}
|
}
|
||||||
};
|
switch (type) {
|
||||||
|
case "DELETE_AUTH_USER":
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
users: state.users.filter(user => user.id !== action.userIdToDelete)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default shopReducer;
|
export default shopReducer
|
||||||
Reference in New Issue
Block a user