Commit 1ba9f2d3 authored by PDuarte's avatar PDuarte

locations and genres fix

parent bed28d62
...@@ -177,5 +177,7 @@ ...@@ -177,5 +177,7 @@
"User Interface": "User Interface", "User Interface": "User Interface",
"Misc": "Misc", "Misc": "Misc",
"Platforms": "Platforms", "Platforms": "Platforms",
"Page types": "Page types" "Page types": "Page types",
"locations": "locations",
"genres": "genres"
} }
import { Package, Briefcase, HardDrive, Globe, Flag } from 'react-feather' import { Package, Briefcase, HardDrive, Globe, Flag, Tag, File } from 'react-feather'
export default [ export default [
{ {
...@@ -21,7 +21,7 @@ export default [ ...@@ -21,7 +21,7 @@ export default [
{ {
id: 'pagetypesDash', id: 'pagetypesDash',
title: 'Page types', title: 'Page types',
icon: <HardDrive />, icon: <File />,
navLink: '/settings/pagetypes' navLink: '/settings/pagetypes'
}, },
{ {
...@@ -29,6 +29,12 @@ export default [ ...@@ -29,6 +29,12 @@ export default [
title: 'locations', title: 'locations',
icon: <Globe />, icon: <Globe />,
navLink: '/settings/locations' navLink: '/settings/locations'
},
{
id: 'genresDash',
title: 'genres',
icon: <Tag />,
navLink: '/settings/genres'
} }
// { // {
// id: 'contriesDash', // id: 'contriesDash',
......
import { Package, Briefcase, HardDrive, Globe, Flag } from 'react-feather' import { Package, Briefcase, HardDrive, Globe, Flag, Tag, File } from 'react-feather'
export default [ export default [
{ {
...@@ -21,16 +21,22 @@ export default [ ...@@ -21,16 +21,22 @@ export default [
{ {
id: 'pagetypesDash', id: 'pagetypesDash',
title: 'pagetypes', title: 'pagetypes',
icon: <HardDrive />, icon: <File />,
navLink: '/settings/pagetypes' navLink: '/settings/pagetypes'
},
{
id: 'locationsDash',
title: 'locations',
icon: <Globe />,
navLink: '/settings/locations'
},
{
id: 'genresDash',
title: 'genres',
icon: <Tag />,
navLink: '/settings/genres'
} }
// { // {
// id: 'locationsDash',
// title: 'locations',
// icon: <Globe />,
// navLink: '/settings/locations'
// },
// {
// id: 'contriesDash', // id: 'contriesDash',
// title: 'Contries', // title: 'Contries',
// icon: <Flag />, // icon: <Flag />,
......
...@@ -54,6 +54,23 @@ const SettingsRoutes = [ ...@@ -54,6 +54,23 @@ const SettingsRoutes = [
component: lazy(() => import('../../views/settings/locations/add')), component: lazy(() => import('../../views/settings/locations/add')),
exact: true exact: true
}, },
{
path: '/settings/genres',
component: lazy(() => import('../../views/settings/genres')),
exact: true
},
{
path: '/settings/genres/edit/:id',
component: lazy(() => import('../../views/settings/genres/edit')),
meta: {
navLink: '/settings/genres/edit'
}
},
{
path: '/settings/genres/add',
component: lazy(() => import('../../views/settings/genres/add')),
exact: true
},
{ {
path: '/settings/contries', path: '/settings/contries',
component: lazy(() => import('../../views/settings/contries')), component: lazy(() => import('../../views/settings/contries')),
......
// ** React Imports
import { Fragment } from 'react'
import { Link } from 'react-router-dom'
// ** Store & Actions
import { addgenre } from '../../store/actions'
import { useDispatch, useSelector } from 'react-redux'
// ** Custom Components
import Breadcrumbs from '@components/breadcrumbs'
// ** Third Party Components
import { Row, Col } from 'reactstrap'
// module settings
import moduleSettings from '../module'
// ** Tables
import ElementCard from '../card'
// ** Styles
import '@styles/react/libs/tables/react-dataTable-component.scss'
const Tables = () => {
const dispatch = useDispatch()
const storeNavbar = useSelector(state => state.navbar)
const onSubmitHandler = (values) => {
dispatch(
addgenre({
idproject: values.idproject,
name: values.name
}
)
)
}
return (
<Fragment>
<Breadcrumbs breadCrumbTitle='Settings' breadCrumbParent='Settings' breadCrumbActive={moduleSettings.mainTitle} />
<Row>
<Col sm='12'>
<Link to={moduleSettings.baseURL}>Back to {moduleSettings.mainTitle}</Link>
</Col>
</Row>
<Row>
<Col sm='12'>
<div className="card">
<div className="card-header">
<h4 className="card-title">New {moduleSettings.mainTitleSingle}</h4>
</div>
<div className="card-body">
{storeNavbar.projectCurrent === null ? <div>
Select Project
</div> : <ElementCard selectedElement={{
id: '<generate>',
idproject: storeNavbar.projectCurrent.value,
name: '',
order: 1,
country: '',
state: '',
city: '',
ip: '',
polyline: ''
}}
onSubmitHandler={onSubmitHandler}
/>
}
</div>
</div>
</Col>
</Row>
</Fragment>
)
}
export default Tables
// ** React Imports
import { useState, useEffect, Fragment } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { toast } from 'react-toastify'
import Avatar from '@components/avatar'
import Select, { components } from 'react-select'
import {Media, Button, Label, Form, FormGroup, Input, Table, CustomInput, Card, CardBody, Row, Col, Nav, NavItem, NavLink, TabContent, TabPane, Alert, CardHeader, CardTitle, CardText } from 'reactstrap'
import { isObjEmpty, selectThemeColors } from '@utils'
import { Bell, Check, Hash, X, AlertTriangle, Info } from 'react-feather'
// ** Store & Actions
import {resetResults} from '../../store/actions'
import { getData_pagetypes } from '../../../settings/store/actions'
import { getData_layoutPlaylists } from '../../../screens/store/actions'
import { useForm } from 'react-hook-form'
import classnames from 'classnames'
import Swal from 'sweetalert2'
import withReactContent from 'sweetalert2-react-content'
import countries from '@assets/data/countries'
// ** Styles
import '@styles/react/apps/app-users.scss'
import '@styles/react/libs/flatpickr/flatpickr.scss'
import '@styles/react/libs/maps/map-leaflet.scss'
import { point } from 'leaflet'
const SuccessProgressToast = () => (
<Fragment>
<div className='toastify-header'>
<div className='title-wrapper'>
<Avatar size='sm' color='success' icon={<Check size={12} />} />
<h6 className='toast-title'>Saved !</h6>
</div>
<small className='text-muted'></small>
</div>
<div className='toastify-body'>
<span role='img' aria-label='toast-text'>
👋 Good job.
</span>
</div>
</Fragment>
)
const ElementCard = ({ selectedElement, onSubmitHandler }) => {
const store = useSelector(state => state.projectsettings)
const [gis, setGis] = useState([])
const [PlatformName, setPlatformName] = useState('Web')
const MySwal = withReactContent(Swal)
const handleError = (text) => {
return MySwal.fire({
title: 'Error!',
text,
icon: 'error',
customClass: {
confirmButton: 'btn btn-primary'
},
buttonsStyling: false
})
}
const [dataElement, setElementData] = useState(null),
[genresAllOptions, setGenresAllOptions] = useState([]),
{ register, errors, handleSubmit } = useForm(),
settingStore = useSelector(state => state.projectsettings),
screensStore = useSelector(state => state.screens),
//
dispatch = useDispatch(),
notifySuccessProgress = () => toast.success(<SuccessProgressToast />),
onSubmit = values => {
if (isObjEmpty(errors)) {
const submitElement = {
...dataElement,
idproject: values.idproject,
name: values.name
}
onSubmitHandler(submitElement)
}
},
handleGis = (value) => {
setGis(value)
}
useEffect(() => {
if (selectedElement !== null || (selectedElement !== null && dataElement !== null && selectedElement.id !== dataElement.id)) {
if (selectedElement.polyline !== null && selectedElement.polyline !== undefined && selectedElement.polyline !== '') {
console.log(selectedElement.polylineis)
const regExp = /(-?\d+(\.\d+)?)\s*(-?\d+(\.\d+)?)(\,?)/gm
const matches = selectedElement.polyline.match(regExp)
const polygon = []
matches.map(point => {
const cords = point.replace(',', '').split(' ')
// polygon.push(cords)
polygon.push({
lat: cords[0],
lng: cords[1]
})
console.log(cords)
})
console.log(matches)
handleGis(polygon)
}
return setElementData(selectedElement)
}
}, [selectedElement])
useEffect(() => {
if (store.errorMsg !== '') {
handleError(store.errorMsg)
dispatch(resetResults())
}
}, [store.errorMsg])
useEffect(() => {
if (store.saveSucces) {
notifySuccessProgress()
dispatch(resetResults())
}
}, [store.saveSucces])
// populate page types
useEffect(() => {
if (!settingStore.allDataPagetypes || settingStore.allDataPagetypes.length < 1) {
dispatch(getData_pagetypes({
start: 1,
length: 1000,
q: null
}))
}
}, [dispatch])
useEffect(() => {
if (!settingStore.selectedProject) return
console.log(settingStore.selectedProject)
const genres = settingStore.selectedProject.genres.map(elm => {
return {
value: elm.id,
label: elm.name
}
})
setGenresAllOptions(genres)
}, [settingStore.selectedProject])
// populate layout menus
useEffect(() => {
if (!screensStore.allDataLayoutPlaylists || screensStore.allDataLayoutPlaylists.length < 1) {
dispatch(getData_layoutPlaylists({
start: 1,
length: 1000,
q: null
}))
}
}, [dispatch])
return (
<Fragment>
<Form
onSubmit={handleSubmit(onSubmit)}
>
<Row>
<Col md='4' sm='12'>
<FormGroup>
<Label for='id'>ID</Label>
<Input
readOnly={true}
type='text'
name='id'
id='id'
placeholder='id'
defaultValue={dataElement && dataElement.id}
/>
</FormGroup>
</Col>
<Col md='4' sm='12'>
<FormGroup>
<Label for='idproject'>Project ID</Label>
<Input
readOnly={true}
type='text'
name='idproject'
id='idproject'
innerRef={register({ required: true })}
placeholder='idproject'
defaultValue={dataElement && dataElement.idproject}
className={classnames({ 'is-invalid': errors['idproject'] })}
/>
</FormGroup>
</Col>
<Col md='4' sm='12'>
<FormGroup>
<Label for='name'>Name</Label>
<Input
type='text'
name='name'
id='name'
innerRef={register({ required: true })}
placeholder='name'
defaultValue={dataElement && dataElement.name}
className={classnames({ 'is-invalid': errors['name'] })}
/>
</FormGroup>
</Col>
</Row>
<Row className='app-user-edit'>
<Col className='d-flex flex-sm-row flex-column mt-2' sm='12'>
<Button.Ripple className='mb-1 mb-sm-0 mr-0 mr-sm-1' type='submit' color='primary'>
Save Changes
</Button.Ripple>
{/* <Button.Ripple color='secondary' outline onClick={() => dispatch(getPlatform(selectedElement.id))} >
Reset
</Button.Ripple> */}
</Col>
</Row>
</Form>
</Fragment>
)
}
export default ElementCard
\ No newline at end of file
// ** React Imports
import { Link } from 'react-router-dom'
// ** Store & Actions
import { cleanGenre } from '../store/actions'
import { store } from '@store/storeConfig/store'
// ** Custom Components
import Avatar from '@components/avatar'
// ** Third Party Components
import axios from 'axios'
import { MoreVertical, Edit, FileText, Archive, Trash } from 'react-feather'
import { Badge, UncontrolledDropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'
import moduleSettings from './module'
// ** Vars
const states = ['success', 'danger', 'warning', 'info', 'dark', 'primary', 'secondary']
const status = {
1: { title: 'Current', color: 'light-primary' },
2: { title: 'Professional', color: 'light-success' },
3: { title: 'Rejected', color: 'light-danger' },
4: { title: 'Resigned', color: 'light-warning' },
5: { title: 'Applied', color: 'light-info' }
}
export let data
// ** Get initial Data
axios.get('/api/datatables/initial-data').then(response => {
data = response.data
})
// ** Table Zero Config Column
export const basicColumns = [
{
name: 'ID',
selector: 'id',
sortable: true,
maxWidth: '100px'
},
{
name: 'Name',
selector: 'full_name',
sortable: true,
minWidth: '225px'
},
{
name: 'Email',
selector: 'email',
sortable: true,
minWidth: '310px'
},
{
name: 'Position',
selector: 'post',
sortable: true,
minWidth: '250px'
},
{
name: 'Age',
selector: 'age',
sortable: true,
minWidth: '100px'
},
{
name: 'Salary',
selector: 'salary',
sortable: true,
minWidth: '175px'
}
]
// ** Expandable table component
const ExpandableTable = ({ data }) => {
return (
<div className='expandable-content p-2'>
<p>
<span className='font-weight-bold'>City:</span> {data.city}
</p>
<p>
<span className='font-weight-bold'>Experience:</span> {data.experience}
</p>
<p className='m-0'>
<span className='font-weight-bold'>Post:</span> {data.post}
</p>
</div>
)
}
// ** Table Common Column
export const columns = [
{
name: 'Name',
selector: 'full_name',
sortable: true,
minWidth: '250px',
cell: row => (
<div className='d-flex align-items-center'>
{row.avatar === '' ? (
<Avatar color={`light-${states[row.status]}`} content={row.full_name} initials />
) : (
<Avatar img={require(`@src/assets/images/portrait/small/avatar-s-${row.avatar}`).default} />
)}
<div className='user-info text-truncate ml-1'>
<span className='d-block font-weight-bold text-truncate'>{row.full_name}</span>
<small>{row.post}</small>
</div>
</div>
)
},
{
name: 'Email',
selector: 'email',
sortable: true,
minWidth: '250px'
},
{
name: 'Date',
selector: 'start_date',
sortable: true,
minWidth: '150px'
},
{
name: 'Salary',
selector: 'salary',
sortable: true,
minWidth: '150px'
},
{
name: 'Age',
selector: 'age',
sortable: true,
minWidth: '100px'
},
{
name: 'Status',
selector: 'status',
sortable: true,
minWidth: '150px',
cell: row => {
return (
<Badge color={status[row.status].color} pill>
{status[row.status].title}
</Badge>
)
}
},
{
name: 'Actions',
allowOverflow: true,
cell: row => {
return (
<div className='d-flex'>
<UncontrolledDropdown>
<DropdownToggle className='pr-1' tag='span'>
<MoreVertical size={15} />
</DropdownToggle>
<DropdownMenu right>
<DropdownItem tag='a' href='/' className='w-100' onClick={e => e.preventDefault()}>
<FileText size={15} />
<span className='align-middle ml-50'>Details</span>
</DropdownItem>
<DropdownItem tag='a' href='/' className='w-100' onClick={e => e.preventDefault()}>
<Archive size={15} />
<span className='align-middle ml-50'>Archive</span>
</DropdownItem>
<DropdownItem tag='a' href='/' className='w-100' onClick={e => e.preventDefault()}>
<Trash size={15} />
<span className='align-middle ml-50'>Delete</span>
</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
<Edit size={15} />
</div>
)
}
}
]
// ** Table Intl Column
export const multiLingColumns = [
{
name: 'Name',
selector: 'full_name',
sortable: true,
minWidth: '200px'
},
{
name: 'Position',
selector: 'post',
sortable: true,
minWidth: '250px'
},
{
name: 'Status',
selector: 'status',
sortable: true,
minWidth: '150px',
cell: row => {
return (
<Badge color={status[row.status].color} pill>
{status[row.status].title}
</Badge>
)
}
},
{
name: 'Actions',
allowOverflow: true,
cell: row => {
return (
<div className='d-flex'>
<UncontrolledDropdown>
<DropdownToggle className='pr-1' tag='span'>
<MoreVertical size={15} />
</DropdownToggle>
<DropdownMenu right>
<DropdownItem>
<FileText size={15} />
<span className='align-middle ml-50'>Details</span>
</DropdownItem>
<DropdownItem>
<Archive size={15} />
<span className='align-middle ml-50'>Archive</span>
</DropdownItem>
<DropdownItem>
<Trash size={15} />
<span className='align-middle ml-50'>Delete</span>
</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
<Edit size={15} />
</div>
)
}
}
]
// ** Table Server Side Column
export const serverSideColumns = [
{
name: 'Location ID',
selector: 'id',
sortable: true,
minWidth: '225px'
},
{
name: 'Location Name',
selector: 'name',
sortable: true,
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(cleanGenre(row.id))}
>
<span className='font-weight-bold'>{row.name}</span>
</Link>
<small className='text-truncate text-muted mb-0'>@{row.name}</small>
</div>
</div>
)
},
{
name: 'Order',
selector: 'order',
sortable: true,
minWidth: '225px'
}
]
// ** Table Adv Search Column
export const advSearchColumns = [
{
name: 'Name',
selector: 'full_name',
sortable: true,
minWidth: '200px'
},
{
name: 'Email',
selector: 'email',
sortable: true,
minWidth: '250px'
},
{
name: 'Post',
selector: 'post',
sortable: true,
minWidth: '250px'
},
{
name: 'City',
selector: 'city',
sortable: true,
minWidth: '150px'
},
{
name: 'Date',
selector: 'start_date',
sortable: true,
minWidth: '150px'
},
{
name: 'Salary',
selector: 'salary',
sortable: true,
minWidth: '100px'
}
]
export default ExpandableTable
// ** React Imports
import { Fragment } from 'react'
import { Link } from 'react-router-dom'
// ** Custom Components
import Breadcrumbs from '@components/breadcrumbs'
// ** Third Party Components
import { Row, Col } from 'reactstrap'
// ** Tables
import ElementEdit from './main'
// ** Styles
import '@styles/react/libs/tables/react-dataTable-component.scss'
// module settings
import moduleSettings from '../module'
const Tables = () => {
return (
<Fragment>
<Breadcrumbs breadCrumbTitle='Settings' breadCrumbParent='Settings' breadCrumbActive={moduleSettings.mainTitle} />
<Row>
<Col sm='12'>
<Link to={moduleSettings.baseURL}>Back to {moduleSettings.mainTitleSingle}</Link>
</Col>
</Row>
<Row>
<Col sm='12'>
<div className="card">
<div className="card-header">
<h4 className="card-title">{moduleSettings.mainTitleSingle}</h4>
</div>
<div className="card-body">
<ElementEdit />
</div>
</div>
</Col>
</Row>
</Fragment>
)
}
export default Tables
import { useState, useEffect, Fragment } from 'react'
import { useParams, Link } from 'react-router-dom'
// ** Store & Actions
import { getGenre, updateGenre } from '../../store/actions'
import { useSelector, useDispatch } from 'react-redux'
import { Alert } from 'reactstrap'
import ElementCard from '../card'
// module settings
import moduleSettings from '../module'
import { Upload } from 'react-feather'
import _ from 'lodash'
const ElementEdit = () => {
// ** States & Vars
const store = useSelector(state => state.projectsettings),
[dataElement, setElementData] = useState(null),
dispatch = useDispatch(),
{ id } = useParams()
const onSubmitHandler = (values) => {
// console.log(values)
// console.log(uploadFile)
dispatch(
updateGenre({
...dataElement,
idproject: values.idproject,
name: values.name
})
)
}
// ** Function to get user on mount
useEffect(() => {
dispatch(getGenre(id))
}, [dispatch])
// ** Update user image on mount or change
useEffect(() => {
if (store.selectedGenre !== null || (store.selectedGenre !== null && dataElement !== null && store.selectedGenre.id !== dataElement.id)) {
return setElementData(store.selectedGenre)
}
}, [store.selectedGenre])
return store.selectedGenre !== null && store.selectedGenre !== undefined ? (
<ElementCard
selectedElement={store.selectedGenre}
onSubmitHandler={onSubmitHandler}
/>
) : (
<Alert color='info'>
<h4 className='alert-heading'>Loading {moduleSettings.mainTitleSingle}</h4>
<div className='alert-body'>
If {moduleSettings.mainTitleSingle} with id: {id} doesn't exist. Check list of all {moduleSettings.mainTitle}: <Link to={moduleSettings.baseURL}>{moduleSettings.mainTitle} List</Link>
</div>
</Alert>
)
}
export default ElementEdit
// ** React Imports
import { Fragment } from 'react'
// ** Custom Components
import Breadcrumbs from '@components/breadcrumbs'
// ** Third Party Components
import { Row, Col } from 'reactstrap'
// ** Tables
import DataTable from './table'
import moduleSettings from './module'
// ** Styles
import '@styles/react/libs/tables/react-dataTable-component.scss'
const Tables = () => {
return (
<Fragment>
<Breadcrumbs breadCrumbTitle='Settings' breadCrumbParent='Settings' breadCrumbActive={moduleSettings.mainTitleSingle} />
<Row>
<Col sm='12'>
<DataTable />
</Col>
</Row>
</Fragment>
)
}
export default Tables
const moduleSettings = {
mainTitle: 'Genres',
mainTitleSingle: 'Genre',
apiBaseURL: '/api/genres',
baseURL: '/settings/genres',
newElement: {
slug: 0,
type: 0
},
elementsOption: {
}
}
export default moduleSettings
\ No newline at end of file
import { Fragment, useState, useEffect, memo } from 'react'
// ** Table Columns
import { serverSideColumns } from './data'
// ** Store & Actions
import { getData_genres } from '../store/actions'
import { useSelector, useDispatch } from 'react-redux'
import DataTableServerSide from '@components/datatable'
import moduleSettings from './module'
const DataTable = () => {
// ** Store Vars
const dispatch = useDispatch()
const store = useSelector(state => state.projectsettings)
const storeNavbar = useSelector(state => state.navbar)
useEffect(() => {
dispatch(getData_genres({
start: 0,
length: 1000
}))
}, [storeNavbar.projectCurrent])
return (
<DataTableServerSide
cardTitle={moduleSettings.mainTitle}
allData={store.allDataGenres}
getData={getData_genres}
serverSideColumns={serverSideColumns}
linkAddButton={`${moduleSettings.baseURL}/add`}
total={store.totalGenres}
/>
)
}
export default memo(DataTable)
...@@ -12,6 +12,15 @@ const DataTable = () => { ...@@ -12,6 +12,15 @@ const DataTable = () => {
// ** Store Vars // ** Store Vars
const dispatch = useDispatch() const dispatch = useDispatch()
const store = useSelector(state => state.projectsettings) const store = useSelector(state => state.projectsettings)
const storeNavbar = useSelector(state => state.navbar)
useEffect(() => {
dispatch(getData_locations({
start: 0,
length: 1000
}))
}, [storeNavbar.projectCurrent])
return ( return (
<DataTableServerSide <DataTableServerSide
......
import axios from 'axios' import axios from 'axios'
import { platform } from 'chart.js' import { platform } from 'chart.js'
import {store} from '@store/storeConfig/store'
export * from './pagetypes' export * from './pagetypes'
...@@ -176,7 +178,7 @@ export const addPlatform = platform => { ...@@ -176,7 +178,7 @@ export const addPlatform = platform => {
} }
// ** Get table Data locations // ** Get table Data locations
export const getData_locations = params => { const _getData_locations = params => {
return async dispatch => { return async dispatch => {
await axios.get(`${process.env.REACT_APP_API}/api/locations`, {params} await axios.get(`${process.env.REACT_APP_API}/api/locations`, {params}
).then(response => { ).then(response => {
...@@ -191,6 +193,14 @@ export const getData_locations = params => { ...@@ -191,6 +193,14 @@ export const getData_locations = params => {
} }
} }
export const getData_locations = params => {
const currentProject = store.getState().navbar.projectCurrent
const newparams = {
...params,
idproject: !currentProject ? '%' : currentProject.value
}
return _getData_locations(newparams)
}
export const addlocation = location => { export const addlocation = location => {
return (dispatch, getState) => { return (dispatch, getState) => {
axios axios
...@@ -254,3 +264,98 @@ export const cleanLocation = id => { ...@@ -254,3 +264,98 @@ export const cleanLocation = id => {
}) })
} }
} }
// ** Get table Data genres
const _getData_genres = params => {
return async dispatch => {
await axios.get(`${process.env.REACT_APP_API}/api/genres`, {params}
).then(response => {
dispatch({
type: 'GET_DATA_GENRES',
allData: response.data.data,
// data: response.data.invoices,
totalPages: response.data.recordsTotal,
params: response.data.params
})
})
}
}
export const getData_genres = params => {
const currentProject = store.getState().navbar.projectCurrent
const newparams = {
...params,
idproject: !currentProject ? '%' : currentProject.value
}
return _getData_genres(newparams)
}
export const addgenre = genre => {
return (dispatch, getState) => {
axios
.post(`${process.env.REACT_APP_API}/api/genres`, genre)
.then(response => {
dispatch({
type: 'ADD_GENRE',
platform
})
})
.then(() => {
dispatch(setSaveSatus(true))
})
.catch(err => {
// dispatch(setErrorMsg(err.response.data.message))
dispatch(setErrorMsg(err))
console.log(err)
})
}
}
export const getGenre = id => {
return async dispatch => {
await axios
.get(`${process.env.REACT_APP_API}/api/genres/${id}`)
.then(response => {
dispatch({
type: 'GET_GENRE',
data: response.data.data
})
})
.catch(err => console.log(err))
}
}
export const updateGenre = genre => {
return (dispatch, getState) => {
axios
.put(`${process.env.REACT_APP_API}/api/genres/${genre.id}`, genre)
.then(response => {
dispatch({
type: 'UPDATE_GENRE',
genre
})
})
.then(() => {
dispatch(setSaveSatus(true))
})
.catch(err => {
dispatch(setErrorMsg(err.response.data.message))
console.log(err.response.data)
})
}
}
export const cleanGenre = id => {
return async dispatch => {
dispatch({
type: 'GET_GENRE',
data: null
})
}
}
...@@ -29,7 +29,13 @@ const initialState = { ...@@ -29,7 +29,13 @@ const initialState = {
totalPagetypes: 1, totalPagetypes: 1,
paramsPagetypes: {}, paramsPagetypes: {},
allDataPagetypes: [], allDataPagetypes: [],
selectedPagetype: null selectedPagetype: null,
dataGenres: [],
totalGenres: 1,
paramsGenres: {},
allDataGenres: [],
selectedGenre: null
} }
const settings = (state = initialState, action) => { const settings = (state = initialState, action) => {
...@@ -125,6 +131,24 @@ const settings = (state = initialState, action) => { ...@@ -125,6 +131,24 @@ const settings = (state = initialState, action) => {
} }
case 'UPDATE_LOCATION': case 'UPDATE_LOCATION':
return { ...state } return { ...state }
case 'GET_DATA_GENRES':
return {
...state,
allDataGenres: action.allData,
dataGenres: action.data,
totalGenres: action.totalPages,
paramsGenres: action.params
}
case 'ADD_GENRE':
return { ...state }
case 'GET_GENRE':
return { ...state,
selectedGenre : action.data
}
case 'UPDATE_GENRE':
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