Commit e319af13 authored by PDuarte's avatar PDuarte

* adding laout menu edit

*  module optimizations
parent 9d35f392
...@@ -16,6 +16,13 @@ const ScreensRoutes = [ ...@@ -16,6 +16,13 @@ const ScreensRoutes = [
navLink: '/screens/layoutmenus/add' navLink: '/screens/layoutmenus/add'
} }
}, },
{
path: '/screens/layoutmenus/edit/:id',
component: lazy(() => import('../../views/screens/layoutmenus/edit')),
meta: {
navLink: '/screens/layoutmenus/edit'
}
},
{ {
path: '/screens/layoutmenus', path: '/screens/layoutmenus',
component: lazy(() => import('../../views/screens/layoutmenus')) component: lazy(() => import('../../views/screens/layoutmenus'))
......
...@@ -12,7 +12,8 @@ import Breadcrumbs from '@components/breadcrumbs' ...@@ -12,7 +12,8 @@ import Breadcrumbs from '@components/breadcrumbs'
// ** Third Party Components // ** Third Party Components
import { Row, Col } from 'reactstrap' import { Row, Col } from 'reactstrap'
// module settings
import moduleSettings from '../module'
// ** Tables // ** Tables
import ElementCard from '../card' import ElementCard from '../card'
// ** Styles // ** Styles
...@@ -22,9 +23,9 @@ const Tables = () => { ...@@ -22,9 +23,9 @@ const Tables = () => {
const dispatch = useDispatch() const dispatch = useDispatch()
const onSubmitHandler = values => { const onSubmitHandler = values => {
dispatch( dispatch(
addlayoutmenu({ addlayoutmenu({
id: values.id, name: values.name,
name: values.name slug: values.slug
}) })
) )
...@@ -32,19 +33,19 @@ const Tables = () => { ...@@ -32,19 +33,19 @@ const Tables = () => {
return ( return (
<Fragment> <Fragment>
<Breadcrumbs breadCrumbTitle='Screens' breadCrumbParent='Screens' breadCrumbActive='Layout menus' /> <Breadcrumbs breadCrumbTitle='Screens' breadCrumbParent='Screens' breadCrumbActive={moduleSettings.mainTitle} />
<Row> <Row>
<Col sm='12'> <Col sm='12'>
<Link to="/screens/layoutmenus">Back to layout menus</Link> <Link to={moduleSettings.baseURL}>Back to {moduleSettings.mainTitle}</Link>
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col sm='12'> <Col sm='12'>
<div class="card"> <div className="card">
<div class="card-header"> <div className="card-header">
<h4 class="card-title">New layout menu</h4> <h4 className="card-title">New {moduleSettings.mainTitleSingle}</h4>
</div> </div>
<div class="card-body"> <div className="card-body">
<ElementCard selectedProject={{ <ElementCard selectedProject={{
id: '<generate>', id: '<generate>',
name: '', name: '',
......
...@@ -39,7 +39,7 @@ const SuccessProgressToast = () => ( ...@@ -39,7 +39,7 @@ const SuccessProgressToast = () => (
) )
const ElementCard = ({ selectedProject, onSubmitHandler }) => { const ElementCard = ({ selectedElement, onSubmitHandler }) => {
const store = useSelector(state => state.projectsettings) const store = useSelector(state => state.projectsettings)
const [PlatformName, setPlatformName] = useState('Web') const [PlatformName, setPlatformName] = useState('Web')
...@@ -58,25 +58,29 @@ const handleError = (text) => { ...@@ -58,25 +58,29 @@ const handleError = (text) => {
}) })
} }
const [dataProject, setProjectData] = useState(null), const [dataElement, setElementData] = useState(null),
{ register, errors, handleSubmit } = useForm(), { register, errors, handleSubmit } = useForm(),
dispatch = useDispatch(), dispatch = useDispatch(),
notifySuccessProgress = () => toast.success(<SuccessProgressToast />), notifySuccessProgress = () => toast.success(<SuccessProgressToast />),
onSubmit = values => { onSubmit = values => {
if (isObjEmpty(errors)) { if (isObjEmpty(errors)) {
onSubmitHandler({
id: null, const submitElement = {
name :PlatformName ...dataElement,
}) name: values.name,
slug: values.slug
}
onSubmitHandler(submitElement)
} }
} }
useEffect(() => { useEffect(() => {
if (selectedProject !== null || (selectedProject !== null && dataProject !== null && selectedProject.id !== dataProject.id)) { if (selectedElement !== null || (selectedElement !== null && dataElement !== null && selectedElement.id !== dataElement.id)) {
return setProjectData(selectedProject) return setElementData(selectedElement)
} }
}, [selectedProject]) }, [selectedElement])
useEffect(() => { useEffect(() => {
if (store.errorMsg !== '') { if (store.errorMsg !== '') {
...@@ -106,10 +110,9 @@ return ( ...@@ -106,10 +110,9 @@ return (
readOnly={true} readOnly={true}
type='text' type='text'
name='id' name='id'
id='id' id='id'
innerRef={register({ required: true })}
placeholder='id' placeholder='id'
defaultValue={dataProject && dataProject.id} defaultValue={dataElement && dataElement.id}
/> />
</FormGroup> </FormGroup>
</Col> </Col>
...@@ -122,7 +125,7 @@ return ( ...@@ -122,7 +125,7 @@ return (
id='name' id='name'
innerRef={register({ required: true })} innerRef={register({ required: true })}
placeholder='Name' placeholder='Name'
defaultValue={dataProject && dataProject.name} defaultValue={dataElement && dataElement.name}
className={classnames({ 'is-invalid': errors['name'] })} className={classnames({ 'is-invalid': errors['name'] })}
/> />
</FormGroup> </FormGroup>
...@@ -136,7 +139,7 @@ return ( ...@@ -136,7 +139,7 @@ return (
id='slug' id='slug'
innerRef={register({ required: true })} innerRef={register({ required: true })}
placeholder='Slug' placeholder='Slug'
defaultValue={dataProject && dataProject.slug} defaultValue={dataElement && dataElement.slug}
className={classnames({ 'is-invalid': errors['slug'] })} className={classnames({ 'is-invalid': errors['slug'] })}
/> />
</FormGroup> </FormGroup>
...@@ -150,7 +153,7 @@ return ( ...@@ -150,7 +153,7 @@ return (
{/* <Col md='4' sm='12'> {/* <Col md='4' sm='12'>
<FormGroup> <FormGroup>
<Label for='name'>Name</Label> <Label for='name'>Name</Label>
<Input type='select' name='name' id='name' defaultValue={dataProject && dataProject.name} onChange={e => setPlatformName(e.target.value)}> <Input type='select' name='name' id='name' defaultValue={dataElement && dataElement.name} onChange={e => setPlatformName(e.target.value)}>
<option value='Web'>Web</option> <option value='Web'>Web</option>
<option value='iOS Phone'>iOS Phone</option> <option value='iOS Phone'>iOS Phone</option>
<option value='iOS Tablet'>iOS Tablet</option> <option value='iOS Tablet'>iOS Tablet</option>
...@@ -165,7 +168,7 @@ return ( ...@@ -165,7 +168,7 @@ return (
<Button.Ripple className='mb-1 mb-sm-0 mr-0 mr-sm-1' type='submit' color='primary'> <Button.Ripple className='mb-1 mb-sm-0 mr-0 mr-sm-1' type='submit' color='primary'>
Save Changes Save Changes
</Button.Ripple> </Button.Ripple>
{/* <Button.Ripple color='secondary' outline onClick={() => dispatch(getPlatform(selectedProject.id))} > {/* <Button.Ripple color='secondary' outline onClick={() => dispatch(getPlatform(selectedElement.id))} >
Reset Reset
</Button.Ripple> */} </Button.Ripple> */}
</Col> </Col>
......
// ** React Imports
import { Link } from 'react-router-dom'
// ** Custom Components // ** Custom Components
import Avatar from '@components/avatar' import Avatar from '@components/avatar'
// module settings
import moduleSettings from './module'
// ** Third Party Components // ** Third Party Components
import axios from 'axios' import axios from 'axios'
...@@ -212,7 +217,22 @@ export const serverSideColumns = [ ...@@ -212,7 +217,22 @@ export const serverSideColumns = [
name: 'Name', name: 'Name',
selector: 'name', selector: 'name',
sortable: true, sortable: true,
minWidth: '225px' minWidth: '225px',
cell: row => (
<div className='d-flex justify-content-left align-items-center'>
<div className='d-flex flex-column'>
<Link
to={`${moduleSettings.baseURL}/edit/${row.id}`}
className='user-name text-truncate mb-0'
// onClick={() => store.dispatch(cleanProject(row.id))}
>
<span className='font-weight-bold'>{row.name}</span>
</Link>
<small className='text-truncate text-muted mb-0'>edit</small>
</div>
</div>
)
}, },
{ {
name: 'Slug', name: 'Slug',
......
...@@ -9,27 +9,29 @@ import Breadcrumbs from '@components/breadcrumbs' ...@@ -9,27 +9,29 @@ import Breadcrumbs from '@components/breadcrumbs'
import { Row, Col } from 'reactstrap' import { Row, Col } from 'reactstrap'
// ** Tables // ** Tables
import ProjectsEdit from './main' import ElementEdit from './main'
// ** Styles // ** Styles
import '@styles/react/libs/tables/react-dataTable-component.scss' import '@styles/react/libs/tables/react-dataTable-component.scss'
// module settings
import moduleSettings from '../module'
const Tables = () => { const Tables = () => {
return ( return (
<Fragment> <Fragment>
<Breadcrumbs breadCrumbTitle='Settings' breadCrumbParent='Settings' breadCrumbActive='Platforms' /> <Breadcrumbs breadCrumbTitle='Screens' breadCrumbParent='Screens' breadCrumbActive={moduleSettings.mainTitle} />
<Row> <Row>
<Col sm='12'> <Col sm='12'>
<Link to="/settings/platforms">Back to Platforms</Link> <Link to={moduleSettings.baseURL}>Back to {moduleSettings.mainTitleSingle}</Link>
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col sm='12'> <Col sm='12'>
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h4 class="card-title">Platform</h4> <h4 class="card-title">{moduleSettings.mainTitleSingle}</h4>
</div> </div>
<div class="card-body"> <div class="card-body">
<ProjectsEdit /> <ElementEdit />
</div> </div>
</div> </div>
......
...@@ -2,27 +2,30 @@ import { useState, useEffect, Fragment } from 'react' ...@@ -2,27 +2,30 @@ import { useState, useEffect, Fragment } from 'react'
import { useParams, Link } from 'react-router-dom' import { useParams, Link } from 'react-router-dom'
// ** Store & Actions // ** Store & Actions
import { getProject, updateProject } from '../../store/actions' import { getLayoutMenu, updateLayoutMenu } from '../../store/actions'
import { useSelector, useDispatch } from 'react-redux' import { useSelector, useDispatch } from 'react-redux'
import { Alert } from 'reactstrap' import { Alert } from 'reactstrap'
import ElementCard from '../card' import ElementCard from '../card'
// module settings
import moduleSettings from '../module'
const ProjectsEdit = () => {
const ElementEdit = () => {
// ** States & Vars // ** States & Vars
const store = useSelector(state => state.projectsettings), const store = useSelector(state => state.projectsettings),
[dataProject, setProjectData] = useState(null), [dataElement, setElementData] = useState(null),
dispatch = useDispatch(), dispatch = useDispatch(),
{ id } = useParams() { id } = useParams()
const onSubmitHandler = values => { const onSubmitHandler = values => {
dispatch( dispatch(
updateProject({ updateLayoutMenu({
id: values.id, id: values.id,
app_name: values.app_name, name: values.name,
customer_name: values.customer_name slug: values.slug
}) })
) )
...@@ -30,31 +33,31 @@ const ProjectsEdit = () => { ...@@ -30,31 +33,31 @@ const ProjectsEdit = () => {
// ** Function to get user on mount // ** Function to get user on mount
useEffect(() => { useEffect(() => {
dispatch(getProject(id)) dispatch(getLayoutMenu(id))
}, [dispatch]) }, [dispatch])
// ** Update user image on mount or change // ** Update user image on mount or change
useEffect(() => { useEffect(() => {
if (store.selectedProject !== null || (store.selectedProject !== null && dataProject !== null && store.selectedProject.id !== dataProject.id)) { if (store.selectedElement !== null || (store.selectedElement !== null && dataElement !== null && store.selectedElement.id !== dataElement.id)) {
return setProjectData(store.selectedProject) return setElementData(store.selectedElement)
} }
}, [store.selectedProject]) }, [store.selectedElement])
return store.selectedProject !== null && store.selectedProject !== undefined ? ( return store.selectedElement !== null && store.selectedElement !== undefined ? (
<ElementCard <ElementCard
selectedProject={store.selectedProject} selectedElement={store.selectedElement}
onSubmitHandler={onSubmitHandler} onSubmitHandler={onSubmitHandler}
/> />
) : ( ) : (
<Alert color='info'> <Alert color='info'>
<h4 className='alert-heading'>Loading Project</h4> <h4 className='alert-heading'>Loading {moduleSettings.mainTitleSingle}</h4>
<div className='alert-body'> <div className='alert-body'>
If Project with id: {id} doesn't exist. Check list of all Projects: <Link to='/settings/projects'>Projects List</Link> If {moduleSettings.mainTitleSingle} with id: {id} doesn't exist. Check list of all {moduleSettings.mainTitle}: <Link to={moduleSettings.baseURL}>{moduleSettings.mainTitle} List</Link>
</div> </div>
</Alert> </Alert>
) )
} }
export default ProjectsEdit export default ElementEdit
import {Media, Button, Label, Form, FormGroup, Input, Table, CustomInput, Card, CardBody, Row, Col, Nav, NavItem, NavLink, TabContent, TabPane, Alert } from 'reactstrap'
import { Lock, Edit, Trash2 } from 'react-feather'
const ProjectPlatform = ({dataElement}) => {
console.log(dataElement)
return (
<div clssName='permissions border mt-1'>
<h6 className='py-1 mx-1 mb-0 font-medium-2'>
<Lock size={18} className='mr-25' />
<span className='align-middle'>Platforms</span>
</h6>
<Table borderless striped responsive>
<thead className='thead-light'>
<tr>
<th>Platforms</th>
<th>Locked</th>
<th>Menu start status</th>
<th>Min version</th>
<th>Menu orientation</th>
</tr>
</thead>
<tbody>
<tr>
<td>IOS</td>
<td>
<CustomInput type='checkbox' id='admin-1' label='' defaultChecked />
</td>
</tr>
<tr>
<td>Android</td>
<td>
<CustomInput type='checkbox' id='staff-1' label='' />
</td>
</tr>
<tr>
<td>Android Tv</td>
<td>
<CustomInput type='checkbox' id='author-1' label='' defaultChecked />
</td>
</tr>
<tr>
<td>Roku</td>
<td>
<CustomInput type='checkbox' id='contributor-1' label='' />
</td>
</tr>
<tr>
<td>STV</td>
<td>
<CustomInput type='checkbox' id='user-1' label='' />
</td>
</tr>
</tbody>
</Table>
</div>
)
}
export default ProjectPlatform
...@@ -11,11 +11,13 @@ import { Row, Col } from 'reactstrap' ...@@ -11,11 +11,13 @@ import { Row, Col } from 'reactstrap'
import DataTable from './table' import DataTable from './table'
// ** Styles // ** Styles
import '@styles/react/libs/tables/react-dataTable-component.scss' import '@styles/react/libs/tables/react-dataTable-component.scss'
// module settings
import moduleSettings from './module'
const Tables = () => { const Tables = () => {
return ( return (
<Fragment> <Fragment>
<Breadcrumbs breadCrumbTitle='Screens' breadCrumbParent='Screens' breadCrumbActive='Layout Menus' /> <Breadcrumbs breadCrumbTitle='Screens' breadCrumbParent='Screens' breadCrumbActive={moduleSettings.mainTitle} />
<Row> <Row>
<Col sm='12'> <Col sm='12'>
<DataTable /> <DataTable />
......
const moduleSettings = {
mainTitle: 'Layout Menus',
mainTitleSingle: 'Layout Menu',
baseURL: '/screens/layoutmenus'
}
export default moduleSettings
\ No newline at end of file
...@@ -7,7 +7,8 @@ import { getData_layoutmenus } from '../store/actions' ...@@ -7,7 +7,8 @@ import { getData_layoutmenus } from '../store/actions'
import { useSelector, useDispatch } from 'react-redux' import { useSelector, useDispatch } from 'react-redux'
import DataTableServerSide from '@components/datatable' import DataTableServerSide from '@components/datatable'
// module settings
import moduleSettings from './module'
const DataTable = () => { const DataTable = () => {
// ** Store Vars // ** Store Vars
const dispatch = useDispatch() const dispatch = useDispatch()
...@@ -15,11 +16,11 @@ const DataTable = () => { ...@@ -15,11 +16,11 @@ const DataTable = () => {
return ( return (
<DataTableServerSide <DataTableServerSide
cardTitle='Layout Menus' cardTitle={moduleSettings.mainTitle}
allData={store.allDataLayoutMenus} allData={store.allDataLayoutMenus}
getData={getData_layoutmenus} getData={getData_layoutmenus}
serverSideColumns={serverSideColumns} serverSideColumns={serverSideColumns}
linkAddButton='/screens/layoutmenus/add' linkAddButton={`${moduleSettings.baseURL}/add`}
total={store.totalLayoutMenus} total={store.totalLayoutMenus}
/> />
......
import axios from 'axios' import axios from 'axios'
export const setSaveSatus = params => {
return async dispatch => {
dispatch({
type: 'SAVE_STATUS',
status: params
})
}
}
export const setErrorMsg = params => {
return async dispatch => {
dispatch({
type: 'SAVE_ERROR',
errorMsg: params
})
}
}
export const resetResults = id => { export const resetResults = id => {
return async dispatch => { return async dispatch => {
dispatch({ dispatch({
...@@ -44,9 +62,45 @@ export const getData_layoutmenus = params => { ...@@ -44,9 +62,45 @@ export const getData_layoutmenus = params => {
// dispatch(getData_layoumenus()) // dispatch(getData_layoumenus())
}) })
.catch(err => { .catch(err => {
dispatch(setErrorMsg(err.response.data.message))
console.log(err.response.data) console.log(err.response.data)
dispatch(setErrorMsg(err.response.data.message))
})
}
}
export const getLayoutMenu = id => {
return async dispatch => {
await axios
.get(`${process.env.REACT_APP_API}/api/layoutmenus/${id}`)
.then(response => {
// console.log('leu')
// console.log(response)
dispatch({
type: 'GET_LAYOUTMENU',
data: response.data.data
})
}) })
.catch(err => console.log(err))
} }
} }
\ No newline at end of file export const updateLayoutMenu = layoumenu => {
return (dispatch, getState) => {
axios
.put(`${process.env.REACT_APP_API}/api/layoumenus/${layoumenu.id}`, project)
.then(response => {
dispatch({
type: 'UPDATE_LAYOUTMENU',
layoumenu
})
})
.then(() => {
dispatch(setSaveSatus(true))
})
.catch(err => {
dispatch(setErrorMsg(err.response.data.message))
console.log(err.response.data)
})
}
}
\ No newline at end of file
...@@ -51,8 +51,18 @@ const screens = (state = initialState, action) => { ...@@ -51,8 +51,18 @@ const screens = (state = initialState, action) => {
totalLayoutMenus: action.totalPages, totalLayoutMenus: action.totalPages,
paramsLayoutMenus: action.params paramsLayoutMenus: action.params
} }
case 'ADD_LAYOUTMENU': case 'ADD_LAYOUTMENU':
return { ...state } return { ...state }
case 'GET_PROJECT':
return { ...state,
selectedLayoutMenu : action.data
}
case 'UPDATE_LAYOUTMENU':
return { ...state }
case 'ADD_LAYOUTMENU':
return { ...state }
default: default:
return state return state
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment