Commit 1b4cec82 authored by PDuarte's avatar PDuarte

season create

parent bb90ae79
...@@ -3,7 +3,7 @@ import { Fragment } from 'react' ...@@ -3,7 +3,7 @@ import { Fragment } from 'react'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
// ** Store & Actions // ** Store & Actions
import { addasset } from '../../store/actions' import { addseason } from '../../store/actions'
import { useDispatch, useSelector } from 'react-redux' import { useDispatch, useSelector } from 'react-redux'
// ** Custom Components // ** Custom Components
...@@ -24,10 +24,12 @@ const Tables = () => { ...@@ -24,10 +24,12 @@ const Tables = () => {
const storeNavbar = useSelector(state => state.navbar) const storeNavbar = useSelector(state => state.navbar)
const onSubmitHandler = (values, uploadFile) => { const onSubmitHandler = (values, uploadFile) => {
dispatch( dispatch(
addasset({ addseason({
projectid: values.projectid, projectid: values.projectid,
title: values.title, title: values.title,
parentid: values.parentid, parentid: values.parentid,
seriesid: values.seriesid,
seasonNumber: values.seasonNumber,
parenttype: values.parenttype, parenttype: values.parenttype,
external_id: values.external_id, external_id: values.external_id,
external_url: values.external_url, external_url: values.external_url,
...@@ -66,6 +68,8 @@ const Tables = () => { ...@@ -66,6 +68,8 @@ const Tables = () => {
parenttype: null, parenttype: null,
external_id: '', external_id: '',
external_url: '', external_url: '',
seriesID: 0,
seasonNumber: 1,
textual: [], textual: [],
genres: [], genres: [],
subgenres: [], subgenres: [],
......
...@@ -93,6 +93,7 @@ const handleError = (text) => { ...@@ -93,6 +93,7 @@ const handleError = (text) => {
idproject: values.idproject, idproject: values.idproject,
title: values.title, title: values.title,
seriesid: values.seriesid, seriesid: values.seriesid,
seasonNumber: values.seasonNumber,
parentid: values.parentid, parentid: values.parentid,
parenttype: values.parenttype, parenttype: values.parenttype,
external_id: values.external_id, external_id: values.external_id,
...@@ -387,15 +388,29 @@ return ( ...@@ -387,15 +388,29 @@ return (
defaultValue={dataElement && dataElement.seriesid} defaultValue={dataElement && dataElement.seriesid}
className={classnames({ 'is-invalid': errors['seriesid'] })} className={classnames({ 'is-invalid': errors['seriesid'] })}
> >
{!!projectAssets.allDataSeries ? projectAssets.allDataSeries.map(option => { {!!projectAssets.allDataSeries && !!dataElement ? projectAssets.allDataSeries.map(option => {
return <option key={option.id} return <option key={option.id}
selected={option.id === dataElement.seriesid ? option.id : ''} selected={option.id === dataElement.seriesID ? option.id : ''}
value={option.id}>{option.title}</option> value={option.id}>{option.title}</option>
}) : <option>Loading</option> } }) : <option>Loading</option> }
</Input> </Input>
</FormGroup> </FormGroup>
</Col> </Col>
<Col md='4' sm='12'>
<FormGroup>
<Label for='seasonNumber'>Season number</Label>
<Input
type='text'
name='seasonNumber'
id='seasonNumber'
innerRef={register({ required: false })}
placeholder='seasonNumber'
defaultValue={dataElement && dataElement.seasonNumber}
className={classnames({ 'is-invalid': errors['seasonNumber'] })}
/>
</FormGroup>
</Col>
<Col md='4' sm='12'> <Col md='4' sm='12'>
<FormGroup> <FormGroup>
<Label for='external_id'>External Id</Label> <Label for='external_id'>External Id</Label>
......
...@@ -2,7 +2,7 @@ import { useState, useEffect, Fragment } from 'react' ...@@ -2,7 +2,7 @@ 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 { getasset, updateseasons, deleteasset } from '../../store/actions' import { getseason, updateseasons, deleteasset } from '../../store/actions'
import { useSelector, useDispatch } from 'react-redux' import { useSelector, useDispatch } from 'react-redux'
...@@ -31,6 +31,7 @@ const ElementEdit = () => { ...@@ -31,6 +31,7 @@ const ElementEdit = () => {
idproject: values.idproject, idproject: values.idproject,
title: values.title, title: values.title,
seriesid: values.seriesid, seriesid: values.seriesid,
seasonNumber: values.seasonNumber,
parentid: values.parentid, parentid: values.parentid,
parenttype: values.parenttype, parenttype: values.parenttype,
external_id: values.external_id, external_id: values.external_id,
...@@ -51,21 +52,22 @@ const ElementEdit = () => { ...@@ -51,21 +52,22 @@ const ElementEdit = () => {
} }
// ** Function to get user on mount // ** Function to get user on mount
useEffect(() => { useEffect(() => {
dispatch(getasset(id)) dispatch(getseason(id))
}, [dispatch]) }, [dispatch])
// ** Update user image on mount or change // ** Update user image on mount or change
useEffect(() => { useEffect(() => {
if (store.selectedAsset !== null || (store.selectedAsset !== null && dataElement !== null && store.selectedAsset.id !== dataElement.id)) { console.log(store.selectedSeason)
return setElementData(store.selectedAsset) if (store.selectedSeason !== null || (store.selectedSeason !== null && dataElement !== null && store.selectedSeason.id !== dataElement.id)) {
return setElementData(store.selectedSeason)
} }
}, [store.selectedAsset]) }, [store.selectedSeason])
return store.selectedAsset !== null && store.selectedAsset !== undefined ? ( return store.selectedSeason !== null && store.selectedSeason !== undefined ? (
<ElementCard <ElementCard
selectedElement={store.selectedAsset} selectedElement={store.selectedSeason}
onSubmitHandler={onSubmitHandler} onSubmitHandler={onSubmitHandler}
handelDelete={handelDelete} handelDelete={handelDelete}
/> />
......
...@@ -59,3 +59,40 @@ export const getData_seasons = params => { ...@@ -59,3 +59,40 @@ export const getData_seasons = params => {
} }
} }
export const getseason = id => {
return async dispatch => {
await axios
.get(`${process.env.REACT_APP_API}${moduleSettings.apiBaseURL}/${id}`)
.then(response => {
// console.log('leu')
// console.log(response)
dispatch({
type: 'GET_SEASON',
data: response.data.data
})
})
.catch(err => console.log(err))
}
}
export const addseason = params => {
return (dispatch, getState) => {
axios
.post(`${process.env.REACT_APP_API}${moduleSettings.apiBaseURL}`, params)
.then(response => {
dispatch({
type: 'ADD_ASSET',
params
})
})
.then(() => {
dispatch(setSaveSatus(true))
})
.catch(err => {
const errosMsg = !err.response ? 'error' : err.response.data.message
console.log(errosMsg)
dispatch(setErrorMsg(errosMsg))
})
}
}
\ No newline at end of file
...@@ -103,6 +103,10 @@ const assets = (state = initialState, action) => { ...@@ -103,6 +103,10 @@ const assets = (state = initialState, action) => {
totalSeasons: action.totalPages, totalSeasons: action.totalPages,
paramsSeasons: action.params paramsSeasons: action.params
} }
case 'GET_SEASON':
return { ...state,
selectedSeason : action.data
}
// default // default
default: default:
......
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