Skip to content

Commit cb3fcb3

Browse files
authored
Merge pull request #23 from urlDev/update-api-url
Update API URL
2 parents d350174 + 2143efb commit cb3fcb3

File tree

2 files changed

+63
-65
lines changed

2 files changed

+63
-65
lines changed

src/redux/actions/favorite.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import axios from "axios";
2-
import toaster from "toasted-notes";
1+
import axios from 'axios';
2+
import toaster from 'toasted-notes';
33

4-
import NotificationComponent from "../../components/notification-component/NotificationComponent";
4+
import NotificationComponent from '../../components/notification-component/NotificationComponent';
55

6-
const url = "https://urldev-mern-react-times-api.herokuapp.com";
7-
// const url = `http://localhost:3000`;
6+
const url = process.env.REACT_APP_API_URL;
87

9-
export const GET_FAVORITE = "GET_FAVORITE";
10-
export const ADD_FAVORITE = "ADD_FAVORITE";
11-
export const DELETE_FAVORITE = "DELETE_FAVORITE";
12-
export const FETCH_FAVORITE_ERROR = "FETCH_FAVORITE_ERROR";
13-
export const CLEAN_FAVORITE_STATE = "CLEAN_FAVORITE_STATE";
8+
export const GET_FAVORITE = 'GET_FAVORITE';
9+
export const ADD_FAVORITE = 'ADD_FAVORITE';
10+
export const DELETE_FAVORITE = 'DELETE_FAVORITE';
11+
export const FETCH_FAVORITE_ERROR = 'FETCH_FAVORITE_ERROR';
12+
export const CLEAN_FAVORITE_STATE = 'CLEAN_FAVORITE_STATE';
1413

1514
export const getFavorite = (stock) => ({
1615
type: GET_FAVORITE,
@@ -37,7 +36,7 @@ export const cleanFavoriteState = () => ({
3736
});
3837

3938
export const fetchGetFavorites = () => async (dispatch) => {
40-
const token = JSON.parse(localStorage.getItem("token"));
39+
const token = JSON.parse(localStorage.getItem('token'));
4140

4241
const config = {
4342
headers: { Authorization: `Bearer ${token}` },
@@ -56,7 +55,7 @@ export const fetchAddFavorites = (stock) => async (dispatch) => {
5655
symbol: stock,
5756
};
5857

59-
const token = JSON.parse(localStorage.getItem("token"));
58+
const token = JSON.parse(localStorage.getItem('token'));
6059

6160
const config = {
6261
headers: { Authorization: `Bearer ${token}` },
@@ -72,8 +71,8 @@ export const fetchAddFavorites = (stock) => async (dispatch) => {
7271
<NotificationComponent
7372
success={true}
7473
text={`You added ${data.symbol[0].name
75-
.split("^")
76-
.join("")} to your favorites successfully.`}
74+
.split('^')
75+
.join('')} to your favorites successfully.`}
7776
/>
7877
),
7978
{ duration: 1500 }
@@ -96,7 +95,7 @@ export const fetchAddFavorites = (stock) => async (dispatch) => {
9695
};
9796

9897
export const fetchDeleteFavorite = (id) => async (dispatch) => {
99-
const token = JSON.parse(localStorage.getItem("token"));
98+
const token = JSON.parse(localStorage.getItem('token'));
10099

101100
const config = {
102101
headers: { Authorization: `Bearer ${token}` },
@@ -111,8 +110,8 @@ export const fetchDeleteFavorite = (id) => async (dispatch) => {
111110
<NotificationComponent
112111
success={true}
113112
text={`You deleted ${data.symbol[0].name
114-
.split("^")
115-
.join("")} from your favorites.`}
113+
.split('^')
114+
.join('')} from your favorites.`}
116115
/>
117116
),
118117
{ duration: 1500 }

src/redux/actions/user.js

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
import axios from "axios";
2-
import toaster from "toasted-notes";
3-
import { push } from "connected-react-router";
4-
5-
import NotificationComponent from "../../components/notification-component/NotificationComponent";
6-
7-
const url = "https://urldev-mern-react-times-api.herokuapp.com";
8-
// const url = `http://localhost:3000`;
9-
10-
export const REGISTER_USER = "REGISTER_USER";
11-
export const LOGOUT_USER = "LOGOUT_USER";
12-
export const LOGIN_USER = "LOGIN_USER";
13-
export const DELETE_USER = "DELETE_USER";
14-
export const UPDATE_USER = "UPDATE_USER";
15-
export const GET_USER = "GET_USER";
16-
export const SET_TOKEN = "SET_TOKEN";
17-
export const USER_FETCH_ERROR = "USER_FETCH_ERROR";
18-
export const USER_LOADING = "USER_LOADING";
19-
export const USER_LOADING_END = "USER_LOADING_END";
20-
export const USER_MODAL_OPEN = "USER_MODAL_OPEN";
21-
export const USER_MODAL_CLOSE = "USER_MODAL_CLOSE";
22-
export const DELETE_MODAL_OPEN = "DELETE_MODAL_OPEN";
23-
export const DELETE_MODAL_CLOSE = "DELETE_MODAL_CLOSE";
24-
export const UPLOAD_AVATAR = "UPLOAD_AVATAR";
1+
import axios from 'axios';
2+
import toaster from 'toasted-notes';
3+
import { push } from 'connected-react-router';
4+
5+
import NotificationComponent from '../../components/notification-component/NotificationComponent';
6+
7+
const url = process.env.REACT_APP_API_URL;
8+
9+
export const REGISTER_USER = 'REGISTER_USER';
10+
export const LOGOUT_USER = 'LOGOUT_USER';
11+
export const LOGIN_USER = 'LOGIN_USER';
12+
export const DELETE_USER = 'DELETE_USER';
13+
export const UPDATE_USER = 'UPDATE_USER';
14+
export const GET_USER = 'GET_USER';
15+
export const SET_TOKEN = 'SET_TOKEN';
16+
export const USER_FETCH_ERROR = 'USER_FETCH_ERROR';
17+
export const USER_LOADING = 'USER_LOADING';
18+
export const USER_LOADING_END = 'USER_LOADING_END';
19+
export const USER_MODAL_OPEN = 'USER_MODAL_OPEN';
20+
export const USER_MODAL_CLOSE = 'USER_MODAL_CLOSE';
21+
export const DELETE_MODAL_OPEN = 'DELETE_MODAL_OPEN';
22+
export const DELETE_MODAL_CLOSE = 'DELETE_MODAL_CLOSE';
23+
export const UPLOAD_AVATAR = 'UPLOAD_AVATAR';
2524

2625
export const registerUser = (user) => ({
2726
type: REGISTER_USER,
@@ -99,9 +98,9 @@ export const fetchRegisterUser = (user) => async (dispatch) => {
9998
dispatch(registerUser(data.user)),
10099
dispatch(userLoadingEnd()),
101100
dispatch(setToken(data.token)),
102-
localStorage.setItem("token", JSON.stringify(data.token)),
103-
localStorage.setItem("user", JSON.stringify(data.user)),
104-
dispatch(push("/")),
101+
localStorage.setItem('token', JSON.stringify(data.token)),
102+
localStorage.setItem('user', JSON.stringify(data.user)),
103+
dispatch(push('/')),
105104
toaster.notify(
106105
() => (
107106
<NotificationComponent
@@ -119,7 +118,7 @@ export const fetchRegisterUser = (user) => async (dispatch) => {
119118
toaster.notify(
120119
() => (
121120
<NotificationComponent
122-
text={"Oops! Something went wrong!"}
121+
text={'Oops! Something went wrong!'}
123122
success={false}
124123
/>
125124
),
@@ -130,7 +129,7 @@ export const fetchRegisterUser = (user) => async (dispatch) => {
130129
};
131130

132131
export const fetchLogoutUser = () => async (dispatch) => {
133-
const token = JSON.parse(localStorage.getItem("token"));
132+
const token = JSON.parse(localStorage.getItem('token'));
134133

135134
const config = {
136135
headers: { Authorization: `Bearer ${token}` },
@@ -142,10 +141,10 @@ export const fetchLogoutUser = () => async (dispatch) => {
142141
await axios.post(`${url}/profile/logout`, null, config);
143142

144143
return [
145-
path.includes("profile") && dispatch(push("/home")),
144+
path.includes('profile') && dispatch(push('/home')),
146145
dispatch(logOutUser()),
147146
toaster.notify(
148-
() => <NotificationComponent text={"Buh-Bye!"} success={true} />,
147+
() => <NotificationComponent text={'Buh-Bye!'} success={true} />,
149148
{ duration: 1500 }
150149
),
151150
];
@@ -163,9 +162,9 @@ export const fetchLoginUser = (user) => async (dispatch) => {
163162
dispatch(loginUser(data.user)),
164163
dispatch(userLoadingEnd()),
165164
dispatch(setToken(data.token)),
166-
localStorage.setItem("token", JSON.stringify(data.token)),
167-
localStorage.setItem("user", JSON.stringify(data.user)),
168-
dispatch(push("/home")),
165+
localStorage.setItem('token', JSON.stringify(data.token)),
166+
localStorage.setItem('user', JSON.stringify(data.user)),
167+
dispatch(push('/home')),
169168
toaster.notify(
170169
() => (
171170
<NotificationComponent
@@ -183,7 +182,7 @@ export const fetchLoginUser = (user) => async (dispatch) => {
183182
toaster.notify(
184183
() => (
185184
<NotificationComponent
186-
text={"Oops! Something went wrong!"}
185+
text={'Oops! Something went wrong!'}
187186
success={false}
188187
/>
189188
),
@@ -199,7 +198,7 @@ export const fetchLoginUser = (user) => async (dispatch) => {
199198
// so there will be no need for this.
200199
// Adding just in case.
201200
export const fetchUser = () => async (dispatch) => {
202-
const token = JSON.parse(localStorage.getItem("token"));
201+
const token = JSON.parse(localStorage.getItem('token'));
203202

204203
const config = {
205204
headers: { Authorization: `Bearer ${token}` },
@@ -212,16 +211,16 @@ export const fetchUser = () => async (dispatch) => {
212211
dispatch(registerUser(data.user)),
213212
dispatch(userLoadingEnd()),
214213
dispatch(setToken(data.token)),
215-
localStorage.setItem("token", JSON.stringify(data.token)),
216-
localStorage.setItem("user", JSON.stringify(data.user)),
214+
localStorage.setItem('token', JSON.stringify(data.token)),
215+
localStorage.setItem('user', JSON.stringify(data.user)),
217216
];
218217
} catch (error) {
219218
return [dispatch(userFetchError(error)), dispatch(userLoadingEnd())];
220219
}
221220
};
222221

223222
export const fetchUpdateUser = (user) => async (dispatch) => {
224-
const token = JSON.parse(localStorage.getItem("token"));
223+
const token = JSON.parse(localStorage.getItem('token'));
225224

226225
const config = {
227226
headers: { Authorization: `Bearer ${token}` },
@@ -231,8 +230,8 @@ export const fetchUpdateUser = (user) => async (dispatch) => {
231230
const data = await response.data;
232231
return [
233232
dispatch(updateUser(data)),
234-
localStorage.setItem("user", JSON.stringify(data)),
235-
dispatch(push("/")),
233+
localStorage.setItem('user', JSON.stringify(data)),
234+
dispatch(push('/')),
236235
toaster.notify(
237236
() => (
238237
<NotificationComponent
@@ -249,7 +248,7 @@ export const fetchUpdateUser = (user) => async (dispatch) => {
249248
toaster.notify(
250249
() => (
251250
<NotificationComponent
252-
text={"Oops! Something went wrong!"}
251+
text={'Oops! Something went wrong!'}
253252
success={false}
254253
/>
255254
),
@@ -260,7 +259,7 @@ export const fetchUpdateUser = (user) => async (dispatch) => {
260259
};
261260

262261
export const fetchDeleteUser = () => async (dispatch) => {
263-
const token = JSON.parse(localStorage.getItem("token"));
262+
const token = JSON.parse(localStorage.getItem('token'));
264263

265264
const config = {
266265
headers: { Authorization: `Bearer ${token}` },
@@ -269,7 +268,7 @@ export const fetchDeleteUser = () => async (dispatch) => {
269268
await axios.delete(`${url}/profile`, config);
270269
return [
271270
localStorage.clear(),
272-
dispatch(push("/")),
271+
dispatch(push('/')),
273272
dispatch(deleteUser()),
274273
toaster.notify(
275274
() => <NotificationComponent success={true} text={`Buh-bye!`} />,
@@ -293,7 +292,7 @@ export const fetchDeleteUser = () => async (dispatch) => {
293292
};
294293

295294
export const fetchUploadAvatar = (input) => async (dispatch) => {
296-
const token = JSON.parse(localStorage.getItem("token"));
295+
const token = JSON.parse(localStorage.getItem('token'));
297296

298297
const config = {
299298
headers: { Authorization: `Bearer ${token}` },
@@ -304,11 +303,11 @@ export const fetchUploadAvatar = (input) => async (dispatch) => {
304303
const data = await response.data;
305304
return [
306305
dispatch(uploadAvatar(data)),
307-
localStorage.setItem("user", JSON.stringify(data)),
306+
localStorage.setItem('user', JSON.stringify(data)),
308307
toaster.notify(
309308
() => (
310309
<NotificationComponent
311-
text={"Avatar is changed! Wow, that looks amazing! ;)"}
310+
text={'Avatar is changed! Wow, that looks amazing! ;)'}
312311
success={true}
313312
/>
314313
),
@@ -321,7 +320,7 @@ export const fetchUploadAvatar = (input) => async (dispatch) => {
321320
toaster.notify(
322321
() => (
323322
<NotificationComponent
324-
text={"Oops! Something went wrong!"}
323+
text={'Oops! Something went wrong!'}
325324
success={false}
326325
/>
327326
),

0 commit comments

Comments
 (0)