Client: refactor (wip)
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
import { format } from 'date-fns'
|
||||
import { routerReducer } from 'react-router-redux'
|
||||
import { combineReducers } from 'redux'
|
||||
|
||||
@ -52,51 +51,6 @@ const chartData = (state = initial.chartData, action) => {
|
||||
}
|
||||
}
|
||||
|
||||
const formData = (state = initial.formData, action) => {
|
||||
switch (action.type) {
|
||||
case 'UPDATE_USER_FORMDATA':
|
||||
return {
|
||||
formData: {
|
||||
...state.formData,
|
||||
[action.target]: action.value
|
||||
},
|
||||
}
|
||||
case 'PROFILE_SUCCESS':
|
||||
case 'EMPTY_USER_FORMDATA':
|
||||
return initial.formData
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
const formProfile = (state = initial.formProfile, action) => {
|
||||
switch (action.type) {
|
||||
case 'UPDATE_PROFILE_FORMDATA':
|
||||
return {
|
||||
formProfile: {
|
||||
...state.formProfile,
|
||||
[action.target]: action.value
|
||||
},
|
||||
}
|
||||
case 'INIT_PROFILE_FORM':
|
||||
return {
|
||||
formProfile: {
|
||||
...state.formProfile,
|
||||
firstName: action.user.firstName,
|
||||
lastName: action.user.lastName,
|
||||
birthDate: action.user.birthDate,
|
||||
location: action.user.location,
|
||||
bio: action.user.bio,
|
||||
timezone: action.user.timezone,
|
||||
},
|
||||
}
|
||||
case 'PROFILE_SUCCESS':
|
||||
return initial.formProfile
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
const gpx = (state = initial.gpx, action) => {
|
||||
switch (action.type) {
|
||||
case 'SET_GPX':
|
||||
@ -160,40 +114,7 @@ const user = (state = initial.user, action) => {
|
||||
window.localStorage.removeItem('authToken')
|
||||
return initial.user
|
||||
case 'PROFILE_SUCCESS':
|
||||
return {
|
||||
id: action.message.data.id,
|
||||
username: action.message.data.username,
|
||||
email: action.message.data.email,
|
||||
isAdmin: action.message.data.admin,
|
||||
createdAt: action.message.data.created_at,
|
||||
isAuthenticated: true,
|
||||
firstName: action.message.data.first_name
|
||||
? action.message.data.first_name
|
||||
: '',
|
||||
lastName: action.message.data.last_name
|
||||
? action.message.data.last_name
|
||||
: '',
|
||||
bio: action.message.data.bio
|
||||
? action.message.data.bio
|
||||
: '',
|
||||
location: action.message.data.location
|
||||
? action.message.data.location
|
||||
: '',
|
||||
birthDate: action.message.data.birth_date
|
||||
? format(new Date(action.message.data.birth_date),
|
||||
'DD/MM/YYYY')
|
||||
: '',
|
||||
picture: action.message.data.picture === true
|
||||
? action.message.data.picture
|
||||
: false,
|
||||
timezone: action.message.data.timezone
|
||||
? action.message.data.timezone
|
||||
: '',
|
||||
nbActivities: action.message.data.nb_activities,
|
||||
nbSports: action.message.data.nb_sports,
|
||||
totalDistance: action.message.data.total_distance,
|
||||
totalDuration: action.message.data.total_duration,
|
||||
}
|
||||
return action.profil
|
||||
default:
|
||||
return state
|
||||
}
|
||||
@ -206,8 +127,6 @@ const reducers = combineReducers({
|
||||
activities,
|
||||
calendarActivities,
|
||||
chartData,
|
||||
formData,
|
||||
formProfile,
|
||||
gpx,
|
||||
loading,
|
||||
message,
|
||||
|
@ -6,37 +6,7 @@ export default {
|
||||
message: '',
|
||||
messages: [],
|
||||
user: {
|
||||
id: '',
|
||||
username: '',
|
||||
email: '',
|
||||
createdAt: '',
|
||||
isAdmin: false,
|
||||
isAuthenticated: false,
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
bio: '',
|
||||
location: '',
|
||||
birthDate: '',
|
||||
picture: false
|
||||
},
|
||||
formData: {
|
||||
formData: {
|
||||
username: '',
|
||||
email: '',
|
||||
password: '',
|
||||
passwordConf: '',
|
||||
}
|
||||
},
|
||||
formProfile: {
|
||||
formProfile: {
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
bio: '',
|
||||
location: '',
|
||||
birthDate: '',
|
||||
password: '',
|
||||
passwordConf: '',
|
||||
}
|
||||
},
|
||||
activities: {
|
||||
...emptyData,
|
||||
|
Reference in New Issue
Block a user