Commit 1b4cec82 authored by PDuarte's avatar PDuarte

season create

parent bb90ae79
......@@ -3,7 +3,7 @@ import { Fragment } from 'react'
import { Link } from 'react-router-dom'
// ** Store & Actions
import { addasset } from '../../store/actions'
import { addseason } from '../../store/actions'
import { useDispatch, useSelector } from 'react-redux'
// ** Custom Components
......@@ -24,10 +24,12 @@ const Tables = () => {
const storeNavbar = useSelector(state => state.navbar)
const onSubmitHandler = (values, uploadFile) => {
dispatch(
addasset({
addseason({
projectid: values.projectid,
title: values.title,
parentid: values.parentid,
seriesid: values.seriesid,
seasonNumber: values.seasonNumber,
parenttype: values.parenttype,
external_id: values.external_id,
external_url: values.external_url,
......@@ -66,6 +68,8 @@ const Tables = () => {
parenttype: null,
external_id: '',
external_url: '',
seriesID: 0,
seasonNumber: 1,
textual: [],
genres: [],
subgenres: [],
......
......@@ -93,6 +93,7 @@ const handleError = (text) => {
idproject: values.idproject,
title: values.title,
seriesid: values.seriesid,
seasonNumber: values.seasonNumber,
parentid: values.parentid,
parenttype: values.parenttype,
external_id: values.external_id,
......@@ -387,15 +388,29 @@ return (
defaultValue={dataElement && dataElement.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}
selected={option.id === dataElement.seriesid ? option.id : ''}
selected={option.id === dataElement.seriesID ? option.id : ''}
value={option.id}>{option.title}</option>
}) : <option>Loading</option> }
</Input>
</FormGroup>
</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'>
<FormGroup>
<Label for='external_id'>External Id</Label>
......
......@@ -2,7 +2,7 @@ import { useState, useEffect, Fragment } from 'react'
import { useParams, Link } from 'react-router-dom'
// ** Store & Actions
import { getasset, updateseasons, deleteasset } from '../../store/actions'
import { getseason, updateseasons, deleteasset } from '../../store/actions'
import { useSelector, useDispatch } from 'react-redux'
......@@ -31,6 +31,7 @@ const ElementEdit = () => {
idproject: values.idproject,
title: values.title,
seriesid: values.seriesid,
seasonNumber: values.seasonNumber,
parentid: values.parentid,
parenttype: values.parenttype,
external_id: values.external_id,
......@@ -51,21 +52,22 @@ const ElementEdit = () => {
}
// ** Function to get user on mount
useEffect(() => {
dispatch(getasset(id))
dispatch(getseason(id))
}, [dispatch])
// ** Update user image on mount or change
useEffect(() => {
if (store.selectedAsset !== null || (store.selectedAsset !== null && dataElement !== null && store.selectedAsset.id !== dataElement.id)) {
return setElementData(store.selectedAsset)
console.log(store.selectedSeason)
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
selectedElement={store.selectedAsset}
selectedElement={store.selectedSeason}
onSubmitHandler={onSubmitHandler}
handelDelete={handelDelete}
/>
......
......@@ -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) => {
totalSeasons: action.totalPages,
paramsSeasons: action.params
}
case 'GET_SEASON':
return { ...state,
selectedSeason : action.data
}
// 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