Skip to content

Commit

Permalink
course creation/edition
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed May 6, 2024
1 parent de83c7c commit 599a9c0
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 191 deletions.
57 changes: 57 additions & 0 deletions src/plugin/cursus/Resources/modules/course/components/creation.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react'
import {PropTypes as T} from 'prop-types'

import {trans} from '#/main/app/intl/translation'
import {LINK_BUTTON} from '#/main/app/buttons'
import {ToolPage} from '#/main/core/tool/containers/page'
import {CourseForm} from '#/plugin/cursus/course/containers/form'

import {selectors} from '#/plugin/cursus/course/store'
import {connect} from "react-redux";
import {selectors as toolSelectors} from "#/main/core/tool/store";
import {selectors as formSelectors} from "#/main/app/content/form/store";

const CourseCreationComponent = (props) =>
<ToolPage
path={[{
type: LINK_BUTTON,
label: trans('catalog', {}, 'cursus'),
target: props.path + '/catalog'
}, {
type: LINK_BUTTON,
label: trans('new_course', {}, 'cursus'),
target: '' // current page, no need to add a link
}]}
title={trans('trainings', {}, 'tools')}
subtitle={trans('new_course', {}, 'cursus')}
primaryAction="add"
actions={[{
name: 'add',
type: LINK_BUTTON,
icon: 'fa fa-fw fa-plus',
label: trans('add_course', {}, 'cursus'),
target: `${props.path}/catalog/new`,
group: trans('management'),
primary: true
}]}
>
<CourseForm
path={props.path + '/catalog'}
name={selectors.FORM_NAME}
/>
</ToolPage>

CourseCreationComponent.propTypes = {
path: T.string.isRequired
}

const CourseCreation = connect(
(state) => ({
path: toolSelectors.path(state),
course: formSelectors.data(formSelectors.form(state, selectors.FORM_NAME))
})
)(CourseCreationComponent)

export {
CourseCreation
}
47 changes: 47 additions & 0 deletions src/plugin/cursus/Resources/modules/course/components/edit.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import {connect} from 'react-redux'
import {PropTypes as T} from 'prop-types'

import {trans} from '#/main/app/intl/translation'
import {LINK_BUTTON} from '#/main/app/buttons'
import {Course as CourseTypes} from '#/plugin/cursus/prop-types'
import {CoursePage} from '#/plugin/cursus/course/components/page'
import {CourseForm} from '#/plugin/cursus/course/containers/form'

import {selectors} from '#/plugin/cursus/course/store'
import {selectors as toolSelectors} from '#/main/core/tool/store'
import {selectors as formSelectors} from '#/main/app/content/form/store'

const CourseEditComponent = (props) =>
<CoursePage
path={props.path}
breadcrumb={[{
type: LINK_BUTTON,
label: trans('edition'),
target: '' // current page, link is not needed
}]}
course={props.course}
>
<CourseForm
path={props.path + '/catalog'}
name={selectors.FORM_NAME}
/>
</CoursePage>

CourseEditComponent.propTypes = {
path: T.string.isRequired,
course: T.shape(
CourseTypes.propTypes
)
}

const CourseEdit = connect(
(state) => ({
path: toolSelectors.path(state),
course: formSelectors.data(formSelectors.form(state, selectors.FORM_NAME))
})
)(CourseEditComponent)

export {
CourseEdit
}
74 changes: 36 additions & 38 deletions src/plugin/cursus/Resources/modules/course/components/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,43 @@ const Course = (props) =>
course={props.course}
activeSession={props.activeSession}
>
{props.path &&
<Routes
path={props.path}
routes={[
{
path: '/:id?',
onEnter: (params = {}) => {
if (params.id && !['sessions', 'participants', 'pending', 'events', 'about', 'desktop'].includes(params.id)) {
props.openSession(params.id)
} else {
props.openSession(get(props.defaultSession, 'id') || null)
}
},
render: (routerProps) => (
<CourseDetails
path={props.path + (routerProps.match.params.id && !['sessions', 'participants', 'pending', 'events', 'about', 'desktop'].includes(routerProps.match.params.id) ? '/' + routerProps.match.params.id : '')}
history={props.history}
course={props.course}
activeSession={props.activeSession}
availableSessions={props.availableSessions}
registrations={props.registrations}
participantsView={props.participantsView}
switchParticipantsView={props.switchParticipantsView}
reload={props.reload}
register={(course, sessionId = null, registrationData = null) => {
props.register(course, sessionId, registrationData).then(() => {
props.reload(course.slug)
<Routes
path={props.path}
routes={[
{
path: '/:id?',
onEnter: (params = {}) => {
if (params.id && !['sessions', 'participants', 'pending', 'events', 'about', 'desktop'].includes(params.id)) {
props.openSession(params.id)
} else {
props.openSession(get(props.defaultSession, 'id') || null)
}
},
render: (routerProps) => (
<CourseDetails
path={props.path + (routerProps.match.params.id && !['sessions', 'participants', 'pending', 'events', 'about', 'desktop'].includes(routerProps.match.params.id) ? '/' + routerProps.match.params.id : '')}
history={props.history}
course={props.course}
activeSession={props.activeSession}
availableSessions={props.availableSessions}
registrations={props.registrations}
participantsView={props.participantsView}
switchParticipantsView={props.switchParticipantsView}
reload={props.reload}
register={(course, sessionId = null, registrationData = null) => {
props.register(course, sessionId, registrationData).then(() => {
props.reload(course.slug)

if (!isEmpty(sessionId)) {
props.history.push(route(course, {id: sessionId}))
}
})
}}
/>
)
}
]}
/>
}
if (!isEmpty(sessionId)) {
props.history.push(route(course, {id: sessionId}))
}
})
}}
/>
)
}
]}
/>
</CoursePage>

Course.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Course = (props) => {
}
].concat(props.course ? props.breadcrumb : [])}
primaryAction="edit"
actions={getActions([props.course], {}, props.path, props.currentUser, props.activeSession)}
actions={getActions([props.course], {}, '', props.currentUser)}
>
{props.children}
</ToolPage>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {Routes} from '#/main/app/router'
import {route} from '#/plugin/cursus/routing'
import {Course} from '#/plugin/cursus/course/containers/main'
import {Course as CourseTypes} from '#/plugin/cursus/prop-types'
import {CatalogEdit} from '#/plugin/cursus/tools/trainings/catalog/containers/edit'
import {CourseEdit} from '#/plugin/cursus/course/components/edit'
import {CatalogList} from '#/plugin/cursus/tools/trainings/catalog/components/list'
import {CatalogCreation} from '#/plugin/cursus/tools/trainings/catalog/components/creation'
import {CourseCreation} from '#/plugin/cursus/course/components/creation'

const CatalogMain = (props) =>
<Routes
path={`${props.path}/catalog`}
path={props.path+'/catalog'}
routes={[
{
path: '/',
Expand All @@ -24,13 +24,11 @@ const CatalogMain = (props) =>
path: '/new',
onEnter: () => props.openForm(null, CourseTypes.defaultProps),
disabled: !props.canEdit,
render: () => (
<CatalogCreation path={props.path} />
)
component: CourseCreation
}, {
path: '/:slug/edit',
onEnter: (params = {}) => props.openForm(params.slug),
component: CatalogEdit
component: CourseEdit
}, {
path: '/:slug',
onEnter: (params = {}) => props.open(params.slug),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {withReducer} from '#/main/app/store/reducer'

import {selectors as toolSelectors} from '#/main/core/tool/store'
import {actions as courseActions} from '#/plugin/cursus/course/store'
import {actions, reducer, selectors} from '#/plugin/cursus/tools/trainings/catalog/store'
import {reducer, selectors} from '#/plugin/cursus/tools/trainings/catalog/store'
import {CatalogMain as CatalogMainComponent} from '#/plugin/cursus/tools/trainings/catalog/components/main'

const CatalogMain = withReducer(selectors.STORE_NAME, reducer)(
Expand All @@ -20,7 +20,7 @@ const CatalogMain = withReducer(selectors.STORE_NAME, reducer)(
dispatch(courseActions.open(slug))
},
openForm(slug, defaultProps) {
dispatch(actions.openForm(slug, defaultProps))
dispatch(courseActions.openForm(slug, defaultProps))
}
})
)(CatalogMainComponent)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {actions} from '#/plugin/cursus/tools/trainings/catalog/store/actions'
import {reducer} from '#/plugin/cursus/tools/trainings/catalog/store/reducer'
import {selectors} from '#/plugin/cursus/tools/trainings/catalog/store/selectors'

export {
actions,
reducer,
selectors
}
Loading

0 comments on commit 599a9c0

Please sign in to comment.