Updated group_editor redux to include new keys
• Updated: - group_editor redux to include new keys: tags, category, isPrivate, isVisible, slug
This commit is contained in:
@@ -11,7 +11,13 @@ import {
|
||||
GROUP_EDITOR_TITLE_CHANGE,
|
||||
GROUP_EDITOR_DESCRIPTION_CHANGE,
|
||||
GROUP_EDITOR_COVER_IMAGE_CHANGE,
|
||||
GROUP_EDITOR_ID_CHANGE,
|
||||
GROUP_EDITOR_TAGS_CHANGE,
|
||||
GROUP_EDITOR_CATEGORY_CHANGE,
|
||||
GROUP_EDITOR_IS_PRIVATE_CHANGE,
|
||||
GROUP_EDITOR_IS_VISIBLE_CHANGE,
|
||||
} from '../actions/group_editor'
|
||||
import slugify from '../utils/slugify'
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
groupId: null,
|
||||
@@ -19,7 +25,12 @@ const initialState = ImmutableMap({
|
||||
isChanged: false,
|
||||
title: '',
|
||||
description: '',
|
||||
id: '',
|
||||
tags: '',
|
||||
category: '',
|
||||
coverImage: null,
|
||||
isPrivate: false,
|
||||
isVisible: true,
|
||||
})
|
||||
|
||||
export default function groupEditorReducer(state = initialState, action) {
|
||||
@@ -27,30 +38,67 @@ export default function groupEditorReducer(state = initialState, action) {
|
||||
case GROUP_EDITOR_RESET:
|
||||
return initialState
|
||||
case GROUP_EDITOR_SETUP:
|
||||
return state.withMutations(map => {
|
||||
let tags
|
||||
try {
|
||||
tags = action.group.get('tags').toJS().join(', ')
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
|
||||
return state.withMutations((map) => {
|
||||
map.set('groupId', action.group.get('id'))
|
||||
map.set('title', action.group.get('title'))
|
||||
map.set('description', action.group.get('description'))
|
||||
map.set('tags', tags)
|
||||
map.set('isPrivate', action.group.get('is_private'))
|
||||
map.set('isVisible', action.group.get('is_visible'))
|
||||
map.set('id', action.group.get('slug'))
|
||||
map.set('category', action.group.get('category'))
|
||||
map.set('isSubmitting', false)
|
||||
})
|
||||
case GROUP_EDITOR_TITLE_CHANGE:
|
||||
return state.withMutations(map => {
|
||||
return state.withMutations((map) => {
|
||||
map.set('title', action.title)
|
||||
map.set('isChanged', true)
|
||||
})
|
||||
case GROUP_EDITOR_DESCRIPTION_CHANGE:
|
||||
return state.withMutations(map => {
|
||||
return state.withMutations((map) => {
|
||||
map.set('description', action.description)
|
||||
map.set('isChanged', true)
|
||||
})
|
||||
case GROUP_EDITOR_COVER_IMAGE_CHANGE:
|
||||
return state.withMutations(map => {
|
||||
return state.withMutations((map) => {
|
||||
map.set('coverImage', action.value)
|
||||
map.set('isChanged', true)
|
||||
})
|
||||
case GROUP_EDITOR_ID_CHANGE:
|
||||
return state.withMutations((map) => {
|
||||
map.set('id', slugify(action.idValue || ''))
|
||||
map.set('isChanged', true)
|
||||
})
|
||||
case GROUP_EDITOR_TAGS_CHANGE:
|
||||
return state.withMutations((map) => {
|
||||
map.set('tags', action.tags)
|
||||
map.set('isChanged', true)
|
||||
})
|
||||
case GROUP_EDITOR_CATEGORY_CHANGE:
|
||||
return state.withMutations((map) => {
|
||||
map.set('category', action.category)
|
||||
map.set('isChanged', true)
|
||||
})
|
||||
case GROUP_EDITOR_IS_PRIVATE_CHANGE:
|
||||
return state.withMutations((map) => {
|
||||
map.set('isPrivate', action.isPrivate)
|
||||
map.set('isChanged', true)
|
||||
})
|
||||
case GROUP_EDITOR_IS_VISIBLE_CHANGE:
|
||||
return state.withMutations((map) => {
|
||||
map.set('isVisible', action.isVisible)
|
||||
map.set('isChanged', true)
|
||||
})
|
||||
case GROUP_CREATE_REQUEST:
|
||||
case GROUP_UPDATE_REQUEST:
|
||||
return state.withMutations(map => {
|
||||
return state.withMutations((map) => {
|
||||
map.set('isSubmitting', true)
|
||||
map.set('isChanged', false)
|
||||
})
|
||||
@@ -59,7 +107,7 @@ export default function groupEditorReducer(state = initialState, action) {
|
||||
return state.set('isSubmitting', false)
|
||||
case GROUP_CREATE_SUCCESS:
|
||||
case GROUP_UPDATE_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
return state.withMutations((map) => {
|
||||
map.set('isSubmitting', false)
|
||||
map.set('groupId', action.group.id)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user