Client: minor refactor (user)
This commit is contained in:
parent
cd90c802b5
commit
1c570ab320
@ -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') {
|
||||
|
@ -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 && (
|
||||
<img
|
||||
alt="Profile"
|
||||
src={`${mpwoApi.getApiUrl()}users/${props.user.id}/picture` +
|
||||
src={`${apiUrl}users/${props.user.id}/picture` +
|
||||
`?${Date.now()}`}
|
||||
className="img-fluid App-nav-profile-img"
|
||||
/>
|
||||
|
@ -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 }) {
|
||||
<div>
|
||||
<img
|
||||
alt="Profile"
|
||||
src={`${mpwoApi.getApiUrl()}users/${user.id}/picture` +
|
||||
src={`${apiUrl}users/${user.id}/picture` +
|
||||
`?${Date.now()}`}
|
||||
className="img-fluid App-profile-img-small"
|
||||
/>
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
export const apiUrl = `${process.env.REACT_APP_API_URL}/api/`
|
||||
|
||||
export const isLoggedIn = () => !!window.localStorage.authToken
|
||||
|
||||
export function generateIds(arr) {
|
||||
|
Loading…
Reference in New Issue
Block a user