Skip to content

Commit

Permalink
[Home] adds app menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Dec 15, 2020
1 parent fd8a502 commit a09164e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 25 deletions.
3 changes: 1 addition & 2 deletions main/app/Resources/modules/layout/components/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ const LayoutMain = props =>
// and it cannot be set to exact: true because it contains sub routes for maintenance, login and registration.
{
path: '/',
component: HomeMenu,
disabled: true
component: HomeMenu
}
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import {PropTypes as T} from 'prop-types'
import {PageSimple} from '#/main/app/page/components/simple'
import {ToolMain} from '#/main/core/tool/containers/main'

import {constants} from '#/main/app/layout/sections/home/constants'

const HomeContent = props => {
switch (props.type) {
case 'html':
case constants.HOME_TYPE_HTML:
return (
<PageSimple>
{props.content}
</PageSimple>
)

case 'tool':
case constants.HOME_TYPE_TOOL:
return (
<ToolMain />
)
Expand Down
120 changes: 108 additions & 12 deletions main/app/Resources/modules/layout/sections/home/components/menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,122 @@ import React from 'react'
import {PropTypes as T} from 'prop-types'

import {trans} from '#/main/app/intl'
import {User as UserTypes} from '#/main/core/user/prop-types'
import {Routes} from '#/main/app/router'
import {Toolbar} from '#/main/app/action/components/toolbar'
import {LINK_BUTTON} from '#/main/app/buttons'

import {MenuMain} from '#/main/app/layout/menu/containers/main'
import {MenuSection} from '#/main/app/layout/menu/components/section'
import {ToolMenu} from '#/main/core/tool/containers/menu'

const HomeMenu = () =>
<MenuMain
title={trans('home')}
actions={[]}
import {constants} from '#/main/app/layout/sections/home/constants'

const HomeSection = (props) =>
<Routes
routes={[
{
path: '/home',
render: () => (
<ToolMenu
opened={true}
toggle={() => true}
autoClose={props.autoClose}
/>
),
disabled: constants.HOME_TYPE_TOOL !== props.homeType
}, {
path: '/#',
render: () => (
<MenuSection
title={trans('login')}
opened={true}
toggle={() => true}
autoClose={props.autoClose}
/>
)
}, {
path: '/registration',
render: () => (
<MenuSection
title={trans('registration')}
opened={true}
toggle={() => true}
autoClose={props.autoClose}
/>
)
}, {
path: '/',
render: () => (
<MenuSection
title={trans('home', {}, 'tools')}
opened={true}
toggle={() => true}
autoClose={props.autoClose}
/>
)
}
]}
/>

HomeMenu.propTypes = {
currentUser: T.shape(
UserTypes.propTypes
),
section: T.string,
changeSection: T.func.isRequired
HomeSection.propTypes = {
homeType: T.string.isRequired,

// from menu
autoClose: T.func
}

const HomeActions = (props) =>
<Toolbar
id="app-menu-actions"
className="list-group"
buttonName="list-group-item"
actions={[
{
name: 'login',
type: LINK_BUTTON,
label: trans('login', {}, 'actions'),
target: '/#',
displayed: !props.authenticated
}, {
name: 'self-register',
type: LINK_BUTTON,
label: trans('self-register', {}, 'actions'),
target: '/registration',
displayed: props.selfRegistration && !props.authenticated && !props.unavailable
}
]}
onClick={props.autoClose}
/>

HomeActions.propTypes = {
unavailable: T.bool.isRequired,
selfRegistration: T.bool.isRequired,
authenticated: T.bool.isRequired,

// from menu
autoClose: T.func
}

HomeMenu.defaultProps = {
const HomeMenu = (props) =>
<MenuMain
title={trans('home')}
>
<HomeSection
homeType={props.homeType}
/>

<HomeActions
unavailable={props.unavailable}
selfRegistration={props.selfRegistration}
authenticated={props.authenticated}
/>
</MenuMain>

HomeMenu.propTypes = {
homeType: T.string.isRequired,
unavailable: T.bool.isRequired,
selfRegistration: T.bool.isRequired,
authenticated: T.bool.isRequired
}

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ import {connect} from 'react-redux'

import {selectors as configSelectors} from '#/main/app/config/store'
import {selectors as securitySelectors} from '#/main/app/security/store'
import {selectors as layoutSelectors} from '#/main/app/layout/store'

import {HomeMenu as HomeMenuComponent} from '#/main/app/layout/sections/home/components/menu'
import {actions as menuActions, selectors as menuSelectors} from '#/main/app/layout/menu/store'
import {selectors} from '#/main/app/layout/sections/home/store'

const HomeMenu = connect(
(state) => ({
currentUser: securitySelectors.currentUser(state),
registration: configSelectors.param(state, 'selfRegistration'),
section: menuSelectors.openedSection(state)
}),
(dispatch) => ({
changeSection(section) {
dispatch(menuActions.changeSection(section))
}
selfRegistration: configSelectors.param(state, 'selfRegistration'),
authenticated: securitySelectors.isAuthenticated(state),
unavailable: layoutSelectors.unavailable(state),
homeType: selectors.homeType(state)
})
)(HomeMenuComponent)

Expand Down

0 comments on commit a09164e

Please # to comment.