-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from sentry-demos/kelly/implement-redux
feat: Implement redux
- Loading branch information
Showing
12 changed files
with
11,402 additions
and
7,133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
REACT_APP_BACKEND=https://neilmanvar-flask-m3uuizd7iq-uc.a.run.app | ||
REACT_APP_BACKEND=https://mikaelacarino-flask-errors-m3uuizd7iq-uc.a.run.app | ||
REACT_APP_ENVIRONMENT=prod | ||
# REACT_APP_WORKFLOW=false # To enable checkout flow | ||
REACT_APP_WORKFLOW=false |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { createStore } from 'redux'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import './index.css'; | ||
import App from './components/App'; | ||
import registerServiceWorker from './registerServiceWorker'; | ||
import reducer from './store/reducers/app'; | ||
|
||
const store = createStore(reducer); | ||
|
||
ReactDOM.render(<App /> , document.getElementById('root')); | ||
ReactDOM.render(<Provider store={store}><App /></Provider> , document.getElementById('root')); | ||
|
||
registerServiceWorker(); |
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,2 @@ | ||
export const BUY_ITEM = 'BUY_ITEM'; | ||
export const RESET_CART = 'RESET_CART'; |
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,14 @@ | ||
import * as actionTypes from './actionTypes'; | ||
|
||
export const buyItem = (item) => { | ||
return { | ||
type: actionTypes.BUY_ITEM, | ||
item: item | ||
}; | ||
}; | ||
|
||
export const resetCart = () => { | ||
return { | ||
type: actionTypes.RESET_CART, | ||
} | ||
} |
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,4 @@ | ||
export { | ||
buyItem, | ||
resetCart | ||
} from './app'; |
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,51 @@ | ||
/*global Sentry*/ | ||
import * as actionTypes from '../actions/actionTypes'; | ||
|
||
const initialState = { | ||
cart: [], | ||
}; | ||
|
||
const buyItem = (state, action) => { | ||
const cart = [].concat(state.cart); | ||
cart.push(action.item); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setExtra('cart', JSON.stringify(cart)); | ||
}); | ||
Sentry.addBreadcrumb({ | ||
category: 'cart', | ||
message: 'User added ' + action.item.name + ' to cart', | ||
level: 'info' | ||
}); | ||
|
||
return { | ||
...state, | ||
cart: cart | ||
} | ||
} | ||
|
||
const resetCart = (state, action) => { | ||
Sentry.configureScope(scope => { | ||
scope.setExtra('cart', ''); | ||
}); | ||
Sentry.addBreadcrumb({ | ||
category: 'cart', | ||
message: 'User emptied cart', | ||
level: 'info' | ||
}); | ||
return { | ||
...state, | ||
cart: [], | ||
} | ||
} | ||
|
||
const reducer = ( state = initialState, action ) => { | ||
switch ( action.type ) { | ||
case actionTypes.BUY_ITEM: return buyItem(state, action); | ||
case actionTypes.RESET_CART: return resetCart(state, action); | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default reducer; |