more
This commit is contained in:
@@ -1,38 +1,32 @@
|
||||
import { useReducer } from "react"
|
||||
|
||||
const UserAuthContext = createContext();
|
||||
|
||||
export const initialState = {
|
||||
user: null,
|
||||
tier: null,
|
||||
authUser: null,
|
||||
AuthTier: null
|
||||
};
|
||||
|
||||
const shopReducer = (state, action) => {
|
||||
const { name, payload } = action;
|
||||
const authReducer = (state, action) => {
|
||||
const { type, payload = "FREE_TIER" } = action
|
||||
|
||||
switch (type) {
|
||||
case "ADD_TO_CART":
|
||||
console.log("ADD_TO_CART", payload);
|
||||
|
||||
case "ADD_AUTH_USER":
|
||||
console.log("ADD_AUTH_USER", payload);
|
||||
return {
|
||||
...state,
|
||||
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
|
||||
auth: payload
|
||||
};
|
||||
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