-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
407 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ADD_STRIPE_SECRET, ADD_TO_CART, CLEAR_CART, REMOVE_FROM_CART } from "./cartActions"; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
const cartInitialState = createInitialCart(); | ||
|
||
function createInitialCart() { | ||
return { | ||
orderId: uuidv4(), | ||
items: [] | ||
}; | ||
} | ||
|
||
export const cart = (state = cartInitialState, action) => { | ||
switch (action.type) { | ||
case ADD_TO_CART: | ||
return { | ||
...state, | ||
items: [ | ||
...state.items, | ||
action.payload | ||
] | ||
} | ||
case REMOVE_FROM_CART: { | ||
let item = action.payload; | ||
let newItemList = state.items.filter(e => e.itemUUID !== item.itemUUID); | ||
return { | ||
...state, | ||
items: newItemList | ||
} | ||
} | ||
case ADD_STRIPE_SECRET: | ||
return { | ||
...state, | ||
clientSecret: action.payload | ||
}; | ||
case CLEAR_CART: | ||
return createInitialCart(); | ||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.