diff --git a/mpwo_client/src/actions/index.js b/mpwo_client/src/actions/index.js index 4ef0424a..ea4e9d0a 100644 --- a/mpwo_client/src/actions/index.js +++ b/mpwo_client/src/actions/index.js @@ -1,4 +1,4 @@ -import mpwoApi from '../mpwoApi' +import mpwoApiUser from '../mwpoApi/user' import { history } from '../index' import { generateIds } from '../utils' @@ -48,7 +48,7 @@ export const updateProfileFormData = (target, value) => ({ }) export function getProfile(dispatch) { - return mpwoApi + return mpwoApiUser .getProfile() .then(ret => { if (ret.status === 'success') { @@ -64,7 +64,7 @@ export function getProfile(dispatch) { export function register(formData) { return function(dispatch) { - return mpwoApi + return mpwoApiUser .register( formData.username, formData.email, @@ -86,7 +86,7 @@ export function register(formData) { export function login(formData) { return function(dispatch) { - return mpwoApi + return mpwoApiUser .login(formData.email, formData.password) .then(ret => { if (ret.status === 'success') { @@ -165,7 +165,7 @@ export function handleProfileFormSubmit(event) { 'Password and password confirmation don\'t match.' )) } else { - return mpwoApi + return mpwoApiUser .updateProfile(state.formProfile.formProfile) .then(ret => { if (ret.status === 'success') { @@ -189,7 +189,7 @@ export function uploadPicture (event) { form.append('file', event.target.picture.files[0]) event.target.reset() return function(dispatch) { - return mpwoApi + return mpwoApiUser .updatePicture(form) .then(ret => { if (ret.status === 'success') { @@ -206,7 +206,7 @@ export function uploadPicture (event) { export function deletePicture() { return function(dispatch) { - return mpwoApi + return mpwoApiUser .deletePicture() .then(ret => { if (ret.status === 'success') { diff --git a/mpwo_client/src/components/NavBar/index.jsx b/mpwo_client/src/components/NavBar/index.jsx index 51343ecb..9c097264 100644 --- a/mpwo_client/src/components/NavBar/index.jsx +++ b/mpwo_client/src/components/NavBar/index.jsx @@ -2,7 +2,7 @@ import React from 'react' import { connect } from 'react-redux' import { Link } from 'react-router-dom' -import mpwoApi from '../../mpwoApi' +import { apiUrl } from '../../utils' function NavBar (props) { @@ -74,7 +74,7 @@ function NavBar (props) { {props.user.picture === true && ( Profile diff --git a/mpwo_client/src/components/User/Profile.jsx b/mpwo_client/src/components/User/Profile.jsx index 63551098..ce225889 100644 --- a/mpwo_client/src/components/User/Profile.jsx +++ b/mpwo_client/src/components/User/Profile.jsx @@ -4,8 +4,8 @@ import { Helmet } from 'react-helmet' import { connect } from 'react-redux' import { Link } from 'react-router-dom' -import mpwoApi from '../../mpwoApi' import { deletePicture, uploadPicture } from '../../actions' +import { apiUrl } from '../../utils' function Profile ({ message, onDeletePicture, onUploadPicture, user }) { return ( @@ -49,7 +49,7 @@ function Profile ({ message, onDeletePicture, onUploadPicture, user }) {
Profile diff --git a/mpwo_client/src/mpwoApi.js b/mpwo_client/src/mwpoApi/user.js similarity index 95% rename from mpwo_client/src/mpwoApi.js rename to mpwo_client/src/mwpoApi/user.js index 73d83fb4..37f55d2b 100644 --- a/mpwo_client/src/mpwoApi.js +++ b/mpwo_client/src/mwpoApi/user.js @@ -1,6 +1,7 @@ -const apiUrl = `${process.env.REACT_APP_API_URL}/api/` +import { apiUrl } from '../utils' + +export default class MpwoApiUser { -export default class MpwoApi { static login(email, password) { const request = new Request(`${apiUrl}auth/login`, { method: 'POST', @@ -16,6 +17,7 @@ export default class MpwoApi { .then(response => response.json()) .catch(error => error) } + static register(username, email, password, passwordConf) { const request = new Request(`${apiUrl}auth/register`, { method: 'POST', @@ -33,6 +35,7 @@ export default class MpwoApi { .then(response => response.json()) .catch(error => error) } + static getProfile() { const request = new Request(`${apiUrl}auth/profile`, { method: 'GET', @@ -45,6 +48,7 @@ export default class MpwoApi { .then(response => response.json()) .catch(error => error) } + static updateProfile(form) { const request = new Request(`${apiUrl}auth/profile/edit`, { method: 'POST', @@ -66,6 +70,7 @@ export default class MpwoApi { .then(response => response.json()) .catch(error => error) } + static updatePicture(form) { const request = new Request(`${apiUrl}auth/picture`, { method: 'POST', @@ -78,6 +83,7 @@ export default class MpwoApi { .then(response => response.json()) .catch(error => error) } + static deletePicture() { const request = new Request(`${apiUrl}auth/picture`, { method: 'DELETE', @@ -89,7 +95,4 @@ export default class MpwoApi { .then(response => response.json()) .catch(error => error) } - static getApiUrl() { - return apiUrl - } } diff --git a/mpwo_client/src/utils.js b/mpwo_client/src/utils.js index a2c9a5c1..78c1eafe 100644 --- a/mpwo_client/src/utils.js +++ b/mpwo_client/src/utils.js @@ -1,3 +1,5 @@ +export const apiUrl = `${process.env.REACT_APP_API_URL}/api/` + export const isLoggedIn = () => !!window.localStorage.authToken export function generateIds(arr) {