Skip to content

Commit c75b936

Browse files
Deployed site on heroku
1 parent d9cc062 commit c75b936

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1613
-1330
lines changed

client/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

client/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
"@stripe/stripe-js": "^1.8.0",
1111
"axios": "^0.19.2",
1212
"env-cmd": "^10.1.0",
13+
"express": "^4.17.1",
1314
"fontsource-roboto": "^2.1.3",
1415
"js-base64": "^2.5.2",
1516
"js-cookie": "^2.2.1",
1617
"lodash": "^4.17.15",
1718
"loglevel": "^1.6.8",
1819
"node-sass": "^4.14.1",
20+
"path": "^0.12.7",
1921
"prop-types": "^15.7.2",
2022
"react": "latest",
2123
"react-dom": "latest",
@@ -29,13 +31,13 @@
2931
"redux-form": "^8.3.6",
3032
"redux-thunk": "^2.3.0",
3133
"semantic-ui-css": "^2.4.1",
34+
"semantic-ui-react": "^0.88.2",
3235
"stripe": "^8.78.0",
3336
"styled-components": "^5.1.1",
34-
"swiper": "^5.4.2",
35-
"semantic-ui-react": "^0.88.2"
37+
"swiper": "^5.4.2"
3638
},
3739
"scripts": {
38-
"start": "react-scripts start",
40+
"start": "node server.js",
3941
"build": "react-scripts build",
4042
"start_dev": "./node_modules/.bin/env-cmd -f .env react-scripts start",
4143
"build_dev": "./node_modules/.bin/env-cmd -f .env react-scripts build",

client/server.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const express = require('express');
2+
const path = require('path');
3+
const port = process.env.PORT || 3000;
4+
const app = express();
5+
6+
// the __dirname is the current directory from where the script is running
7+
app.use(express.static(__dirname));
8+
app.use(express.static(path.join(__dirname, 'build')));
9+
app.get('/ping', function (req, res) {
10+
return res.send('pong');
11+
});
12+
app.get('/*', function (req, res) {
13+
res.sendFile(path.join(__dirname, 'build', 'index.html'));
14+
});
15+
app.listen(port);

client/src/ErrorBoundary.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React, {Component} from "react";
2+
import {Grid} from "@material-ui/core";
3+
4+
class ErrorBoundary extends Component {
5+
6+
constructor(props) {
7+
super(props);
8+
9+
this.state = {
10+
hasError: false
11+
}
12+
}
13+
14+
static getDerivedStateFromError(error) {
15+
return {
16+
hasError: true
17+
}
18+
}
19+
20+
componentDidCatch(error, errorInfo) {
21+
// You can also log the error to an error reporting service
22+
// logErrorToMyService(error, errorInfo);
23+
console.log(`error = ${error}, errorInfo = ${JSON.stringify(errorInfo)}`)
24+
}
25+
26+
render() {
27+
if (this.state.hasError) {
28+
return (
29+
<Grid container justify="center" style={{paddingTop: "2rem", fontSize: "3rem"}}>
30+
<p>Oops! Something went wrong....</p>
31+
</Grid>
32+
)
33+
}
34+
return this.props.children
35+
}
36+
}
37+
38+
export default ErrorBoundary;

client/src/actions/index.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SAVE_QUERY_STATUS,
99
SHIPPING_ADDRESS_CONFIRMED,
1010
PAYMENT_INFO_CONFIRMED,
11-
PAYMENT_RESPONSE, CART_TOTAL, HANDLE_SIGN_UP_RESET, HANDLE_GOOGLE_AUTH_SIGN_IN, HANDLE_GOOGLE_AUTH_SIGN_OUT,
11+
PAYMENT_RESPONSE, CART_TOTAL, RESET_SIGN_UP, HANDLE_GOOGLE_AUTH_SIGN_IN, HANDLE_GOOGLE_AUTH_SIGN_OUT,
1212
} from './types';
1313
import {INTERNAL_SERVER_ERROR_CODE, BAD_REQUEST_ERROR_CODE} from '../constants/http_error_codes'
1414
import {SHOPPERS_PRODUCT_INFO_COOKIE, CART_TOTAL_COOKIE, AUTH_DETAILS_COOKIE} from '../constants/cookies'
@@ -48,7 +48,6 @@ export const signIn = formValues => async dispatch => {
4848

4949
const hash = Base64.encode(`${formValues.username}:${formValues.password}`);
5050
authServiceAPI.defaults.headers.common['Authorization'] = `Basic ${hash}`
51-
authServiceAPI.defaults.timeout = 5000;
5251
const response = await authServiceAPI.post('/authenticate').catch(err => {
5352
log.info(`[ACTION]: dispatch HANDLE_SIGN_IN_ERROR err.message = ${err.message}`)
5453
dispatch({type: HANDLE_SIGN_IN_ERROR, payload: err.message});
@@ -101,7 +100,6 @@ export const signInUsingOAuth = googleAuth => async dispatch => {
101100
// try {
102101
// let userProfile = googleAuth.currentUser.get().getBasicProfile()
103102
// if (userProfile) {
104-
// authServiceAPI.defaults.timeout = 15000;
105103
// const response = await authServiceAPI.post('/signin-using-google-auth', {
106104
// 'id': userProfile.getId(),
107105
// 'firstname': userProfile.getGivenName(),
@@ -165,17 +163,9 @@ export const signOutUsingOAuth = googleAuth => async dispatch => {
165163
}
166164
}
167165

168-
169-
export const resetSignUp = () => {
170-
return {
171-
type: HANDLE_SIGN_UP_RESET
172-
}
173-
}
174-
175166
export const signUp = formValues => async dispatch => {
176167
log.info(`[ACTION]: signUp API = ${JSON.stringify(formValues)}.`)
177168

178-
authServiceAPI.defaults.timeout = 15000;
179169
const response = await authServiceAPI.post('/signup', {
180170
'username': formValues.username,
181171
'password': formValues.password,
@@ -203,9 +193,10 @@ export const sendPaymentToken = (token) => async dispatch => {
203193
log.info(`Token = ${JSON.stringify(token)}`)
204194
let config = {
205195
method: 'post',
206-
url: `http://localhost:${process.env.REACT_APP_PAYMENT_SERVICE_PORT}/payment`,
196+
url: `${process.env.REACT_APP_PAYMENT_SERVICE_URL}/payment`
197+
|| `http://localhost:${process.env.REACT_APP_PAYMENT_SERVICE_PORT}/payment`,
207198
headers: {
208-
'Content-Type': 'application/json'
199+
'Content-Type': 'application/json',
209200
},
210201
data: JSON.stringify(token)
211202
};
@@ -225,11 +216,6 @@ export const sendPaymentToken = (token) => async dispatch => {
225216
history.push(`/checkout/success-payment/${response.data.charge_id}`)
226217
Cookies.remove(CART_TOTAL_COOKIE)
227218
Cookies.remove(SHOPPERS_PRODUCT_INFO_COOKIE)
228-
229-
dispatch({
230-
type: CART_TOTAL,
231-
payload: 0
232-
})
233219
}
234220

235221
dispatch({
@@ -239,11 +225,12 @@ export const sendPaymentToken = (token) => async dispatch => {
239225

240226
})
241227
.catch(function (error) {
242-
console.log(error);
228+
log.error(`[sendPaymentToken]: Error = ${error} `)
243229
dispatch({
244230
type: PAYMENT_RESPONSE,
245231
payload: {error: true}
246232
})
233+
return false
247234
});
248235
}
249236

@@ -252,7 +239,6 @@ export const getDataViaAPI = (type, uri) => async dispatch => {
252239
log.info(`[ACTION]: invokeAndDispatchAPIData Calling API = ${uri}.`)
253240

254241
if (uri) {
255-
commonServiceAPI.defaults.timeout = 15000;
256242
uri = uri.replace(/\s/g, '')
257243
let responseError = false
258244
const response = await commonServiceAPI.get(uri)

client/src/actions/types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
export const HANDLE_SIGN_IN= "HANDLE_SIGN_IN";
44
export const HANDLE_SIGN_OUT= "HANDLE_SIGN_OUT";
55
export const HANDLE_SIGN_IN_ERROR= "HANDLE_SIGN_IN_ERROR";
6+
export const RESET_SIGN_IN_ERROR = "RESET_SIGN_IN_ERROR";
67
export const SET_GOOGLE_AUTH= "SET_GOOGLE_AUTH";
78
export const HANDLE_GOOGLE_AUTH_SIGN_IN= "HANDLE_GOOGLE_AUTH_SIGN_IN";
89
export const HANDLE_GOOGLE_AUTH_SIGN_OUT= "HANDLE_GOOGLE_AUTH_SIGN_OUT";
910
export const HANDLE_SIGN_UP_ERROR= "HANDLE_SIGN_UP_ERROR";
10-
export const HANDLE_SIGN_UP_RESET= "HANDLE_SIGN_UP_RESET";
11+
export const RESET_SIGN_UP= "RESET_SIGN_UP";
1112
export const HANDLE_TAB_HOVER_EVENT = "HANDLE_TAB_HOVER_EVENT";
1213

1314
export const LOAD_HOME_PAGE = "LOAD_HOME_PAGE";

client/src/api/service_api.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import axios from 'axios';
22

33
const {
44
REACT_APP_COMMON_DATA_SERVICE_PORT,
5-
REACT_APP_AUTHENTICATION_SERVICE_PORT
5+
REACT_APP_AUTHENTICATION_SERVICE_PORT,
6+
REACT_APP_COMMON_DATA_SERVICE_URL,
7+
REACT_APP_AUTHENTICATION_SERVICE_URL,
68
} = process.env
79

810
export const authServiceAPI = axios.create({
9-
baseURL: `http://localhost:${REACT_APP_AUTHENTICATION_SERVICE_PORT}`
11+
baseURL: REACT_APP_AUTHENTICATION_SERVICE_URL || `http://localhost:${REACT_APP_AUTHENTICATION_SERVICE_PORT}`
1012
})
1113

1214
export const commonServiceAPI = axios.create({
13-
baseURL: `http://localhost:${REACT_APP_COMMON_DATA_SERVICE_PORT}`
15+
baseURL: REACT_APP_COMMON_DATA_SERVICE_URL || `http://localhost:${REACT_APP_COMMON_DATA_SERVICE_PORT}`
1416
})

client/src/components/routes/checkout/paymentButton.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class PaymentButton extends Component {
1717
}
1818

1919
componentDidMount() {
20+
log.info(`[PaymentButton] Component Did Mount...paymentResponse = ${JSON.stringify(this.props.paymentResponse)}`)
2021
if(this.props.paymentResponse && this.props.paymentResponse.hasOwnProperty("error")) {
2122
this.setState({paymentBtnClicked: true})
2223
}
@@ -31,18 +32,22 @@ class PaymentButton extends Component {
3132

3233
this.setState({paymentBtnClicked: true})
3334

34-
this.props.sendPaymentToken({
35+
let value = this.props.sendPaymentToken({
3536
...token,
3637
amount: this._GrandTotal,
3738
currency: "USD",
3839
address: this.props.shippingAddressForm.values,
3940
addToCart: this.props.addToCart,
4041
shippingOption: this.props.shippingOption
4142
})
43+
44+
if(value) {
45+
this.setState({paymentBtnClicked: false})
46+
}
4247
}
4348

4449
renderButton = () => {
45-
log.info(`[PaymentButton] renderButton....`)
50+
log.info(`[PaymentButton] renderButton.....`)
4651
return (
4752
<Grid container justify="center" style={{padding: "2rem 0 2rem 0"}}>
4853
<Grid item lg={9}>

client/src/components/routes/navbar/navBar.js

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,26 @@ const NavBar = props => {
8181
*/
8282
useEffect(() => {
8383
log.info(`[NavBar]: Component did update.`)
84-
84+
8585
if (!googleAuthReducer.oAuth) {
86-
try {
87-
window.gapi.load('client:auth2', () => {
88-
window.gapi.client.init({
89-
clientId: process.env.REACT_APP_GOOGLE_AUTH_CLIENT_ID,
90-
scope: 'profile'
91-
}).then(() => {
92-
const auth = window.gapi.auth2.getAuthInstance();
93-
dispatch({
94-
type: SET_GOOGLE_AUTH,
95-
payload: {
96-
firstName: auth.currentUser.get().getBasicProfile() ?
97-
auth.currentUser.get().getBasicProfile().getGivenName() : null,
98-
oAuth: auth
99-
}
100-
})
101-
});
102-
});
103-
} catch (e) {
104-
log.info(`[Navbar] Failed to load google OAuth.`)
105-
}
86+
window.gapi.load('client:auth2', () => {
87+
window.gapi.client.init({
88+
clientId: process.env.REACT_APP_GOOGLE_AUTH_CLIENT_ID,
89+
scope: 'profile'
90+
}).then(() => {
91+
const auth = window.gapi.auth2.getAuthInstance();
92+
dispatch({
93+
type: SET_GOOGLE_AUTH,
94+
payload: {
95+
firstName: auth.currentUser.get().getBasicProfile() ?
96+
auth.currentUser.get().getBasicProfile().getGivenName() : null,
97+
oAuth: auth
98+
}
99+
})
100+
}).catch(function (e) {
101+
log.error(`[Navbar] Failed to load google OAuth`)
102+
})
103+
});
106104
}
107105

108106
if (isSignedIn === null) {
@@ -160,10 +158,15 @@ const NavBar = props => {
160158
fName = "S"
161159
}
162160

163-
authIcon = <Avatar className={classes.orange} sizes="small"
164-
style={{width: 20, height: 20, marginBottom: 3}}>
165-
{fName.charAt(0).toUpperCase()}
166-
</Avatar>
161+
authIcon = <Avatar sizes="small"
162+
style={{
163+
width: 20, height: 20,
164+
backgroundColor: "orange",
165+
filter: "saturate(5)"
166+
}}>
167+
168+
{fName.charAt(0).toUpperCase()}
169+
</Avatar>
167170
authLabel = "Sign Out"
168171
} else {
169172
authIcon = <AccountCircle/>
@@ -260,12 +263,12 @@ const NavBar = props => {
260263
setHamburgerBtnState(false)
261264
}
262265

263-
const renderIndependentElem = (eventHandler, icon, label) => {
266+
const renderIndependentElem = (eventHandler, icon, label, paddingTop) => {
264267
return (
265268
<Grid item>
266269
<Grid container direction="column" alignItems="center"
267270
onClick={eventHandler} style={{cursor: 'pointer'}}>
268-
<Grid item style={{height: 21, width: 21}}>
271+
<Grid item style={{height: 21, width: 21, paddingTop: paddingTop}}>
269272
{icon}
270273
</Grid>
271274
<Grid item style={{color: "black", fontSize: "0.8rem", fontWeight: 'bold'}}>
@@ -335,11 +338,13 @@ const NavBar = props => {
335338
<div className={classes.growHalf}/>
336339

337340
<Hidden xsDown>
338-
{renderIndependentElem(changeAuthStatusHandler, authIcon, authLabel)}
341+
{renderIndependentElem(changeAuthStatusHandler, authIcon, authLabel,
342+
2)}
339343

340344
<div className={classes.growQuarter}/>
341345

342-
{renderIndependentElem(changePageToShoppingBagHandler, <BagButton/>, "Bag")}
346+
{renderIndependentElem(changePageToShoppingBagHandler, <BagButton/>,
347+
"Bag", 0)}
343348
</Hidden>
344349

345350

client/src/components/routes/signin/signIn.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import log from "loglevel";
55
import {Divider} from "semantic-ui-react";
66
import {Link} from "react-router-dom";
77
import {Dimmer, Loader} from 'semantic-ui-react'
8-
import {useSelector} from "react-redux";
8+
import {useDispatch, useSelector} from "react-redux";
99
import GoogleAuthButton from "./GoogleAuthButton";
1010
import {DocumentTitle} from "../../ui/documentTitle";
11+
import {RESET_SIGN_IN_ERROR} from "../../../actions/types";
1112

1213
const SignIn = () => {
1314
const [isLoading, setIsLoading] = useState(false);
1415
const {isSignedIn, timestamp} = useSelector(state => state.signInReducer)
1516
const {isSignedInUsingOAuth} = useSelector(state => state.googleAuthReducer)
17+
const dispatch = useDispatch()
1618

1719
const setIsLoadingState = () => {
1820
setIsLoading(true);
@@ -25,6 +27,18 @@ const SignIn = () => {
2527
// eslint-disable-next-line
2628
}, [timestamp])
2729

30+
useEffect(() => {
31+
32+
return () => {
33+
log.info(`[SignIn] Component will unmount...`)
34+
dispatch({
35+
type: RESET_SIGN_IN_ERROR
36+
})
37+
}
38+
39+
// eslint-disable-next-line
40+
}, [])
41+
2842
if ((isSignedIn !== null && isSignedIn)
2943
|| (isSignedInUsingOAuth !== null && isSignedInUsingOAuth)) {
3044
log.info(`[SignIn] Already signed In...`)

0 commit comments

Comments
 (0)