Commit 1ea2548f authored by PDuarte's avatar PDuarte

sending menu playlist to api

parent e5549631
...@@ -363,11 +363,7 @@ return ( ...@@ -363,11 +363,7 @@ return (
) )
} }
<TabPane tabId={dataElement ? dataElement.menu_page_layouts.length : 0}> <TabPane tabId={dataElement ? dataElement.menu_page_layouts.length : 0}>
<div <div></div>
// selectedUser={store.selectedUser}
>
</div>
</TabPane> </TabPane>
</TabContent> </TabContent>
</CardBody> </CardBody>
......
...@@ -27,25 +27,31 @@ const serverSideColumns = [ ...@@ -27,25 +27,31 @@ const serverSideColumns = [
] ]
const ManagePlaylist = (dataElement) => { const ManagePlaylist = ({dataElement, selectedDataElement, handleChange}) => {
const store = useSelector(state => state.playlists), const store = useSelector(state => state.playlists),
storeMenuPages = useSelector(state => state.menupages),
[selectedPlaylists, setSelectedPlaylists] = useState(null),
[avaliablePlaylists, setavaliablePlaylists] = useState([]), [avaliablePlaylists, setavaliablePlaylists] = useState([]),
[selectedPlaylists, setSelectedPlaylists] = useState([]),
dispatch = useDispatch() dispatch = useDispatch()
const handleAdd = (value) => { const handleAdd = (value) => {
const newValue = selectedPlaylists.concat(value) const newValue = selectedPlaylists.concat(value)
setSelectedPlaylists(newValue) setSelectedPlaylists(newValue)
handleChange(newValue)
} }
const handleRemove = (value) => { const handleRemove = (value) => {
const newValue = selectedPlaylists.filter(element => element.id !== value.id) const newValue = selectedPlaylists.filter(element => element.id !== value.id)
setSelectedPlaylists(newValue) setSelectedPlaylists(newValue)
handleChange(newValue)
} }
const getData_selectedPlaylists = (params) => { const getData_selectedPlaylists = (params) => {
return (dispatch) => { return (dispatch) => {
if (params.q === null || params.q === '') { if (params.q === null || params.q === '') {
setSelectedPlaylists(dataElement.dataElement) setSelectedPlaylists(dataElement)
return return
} }
const newValue = dataElement.dataElement.filter(element => element.title.includes(params.q)) const newValue = dataElement.dataElement.filter(element => element.title.includes(params.q))
...@@ -54,6 +60,7 @@ const ManagePlaylist = (dataElement) => { ...@@ -54,6 +60,7 @@ const ManagePlaylist = (dataElement) => {
} }
const getData_avaliablePlaylists = (params) => { const getData_avaliablePlaylists = (params) => {
return (dispatch) => { return (dispatch) => {
if (selectedPlaylists === null) return
const Ids = selectedPlaylists.map(elem => elem.id), const Ids = selectedPlaylists.map(elem => elem.id),
tabPlaylists = store.allDataPlaylists.filter(element => !Ids.includes(element.id)) tabPlaylists = store.allDataPlaylists.filter(element => !Ids.includes(element.id))
...@@ -68,20 +75,21 @@ const ManagePlaylist = (dataElement) => { ...@@ -68,20 +75,21 @@ const ManagePlaylist = (dataElement) => {
} }
useEffect(() => { useEffect(() => {
if (typeof selectedPlaylists === 'undefined' || selectedPlaylists === null) return
const Ids = selectedPlaylists.map(elem => elem.id) const Ids = selectedPlaylists.map(elem => elem.id)
const filtered = store.allDataPlaylists.filter(element => !Ids.includes(element.id)) const filtered = store.allDataPlaylists.filter(element => !Ids.includes(element.id))
setavaliablePlaylists(filtered) setavaliablePlaylists(filtered)
}, [store.allDataPlaylists]) }, [store.allDataPlaylists])
useEffect(() => { useEffect(() => {
if (selectedPlaylists === null) return if (typeof selectedPlaylists === 'undefined' || selectedPlaylists === null) return
const Ids = selectedPlaylists.map(elem => elem.id) const Ids = selectedPlaylists.map(elem => elem.id)
const filtered = store.allDataPlaylists.filter(element => !Ids.includes(element.id)) const filtered = store.allDataPlaylists.filter(element => !Ids.includes(element.id))
setavaliablePlaylists(filtered) setavaliablePlaylists(filtered)
}, [selectedPlaylists]) }, [selectedPlaylists])
useEffect(() => { useEffect(() => {
if (dataElement !== null && dataElement.dataElement !== null) { if (dataElement !== null && dataElement !== null) {
setSelectedPlaylists(dataElement.dataElement) setSelectedPlaylists(dataElement)
} }
}, [dataElement]) }, [dataElement])
......
...@@ -25,10 +25,23 @@ const TabLayoutPlaylist = ({block, selectedDataElement, setElementData}) => { ...@@ -25,10 +25,23 @@ const TabLayoutPlaylist = ({block, selectedDataElement, setElementData}) => {
mpagelayout[field] = value mpagelayout[field] = value
} }
}) })
setElementData(
{
...selectedDataElement
})
},
handlePLLChange = (value) => {
const newData = selectedDataElement.menu_page_layouts.map((mpagelayout) => {
if (mpagelayout.id === block.id) {
mpagelayout.playlists = value
}
})
setElementData( setElementData(
{ {
...selectedDataElement ...selectedDataElement
}) })
// handleDetailChange(value, 'playlists')
} }
useEffect(() => { useEffect(() => {
...@@ -112,7 +125,11 @@ const TabLayoutPlaylist = ({block, selectedDataElement, setElementData}) => { ...@@ -112,7 +125,11 @@ const TabLayoutPlaylist = ({block, selectedDataElement, setElementData}) => {
</div> </div>
</div> </div>
<ManagePlaylist dataElement={dataElement && dataElement.playlists} /> <ManagePlaylist
dataElement={dataElement && dataElement.playlists}
selectedDataElement={dataElement}
handleChange={handlePLLChange}
/>
</Col> </Col>
......
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