diff --git a/src/components/index/indexConsole/commands/fetchCommands/Album/Update.js b/src/components/index/indexConsole/commands/fetchCommands/Album/Update.js index 4c3e027..7dc6df8 100644 --- a/src/components/index/indexConsole/commands/fetchCommands/Album/Update.js +++ b/src/components/index/indexConsole/commands/fetchCommands/Album/Update.js @@ -67,6 +67,14 @@ const AlbumUpdate = ({ setFile: setImage } ] + + const resetState = () => { + setConsoleHistory( consoleHistory + message ) + setComponentVisible( false ) + setImage('') + setImageInfo('Drop/Click\nfor upload album image...') + setMessage('') + } const updateFetch = async ( refs ) => { let album = validate( inputList ) @@ -78,14 +86,6 @@ const AlbumUpdate = ({ setMessage( response['info'] + '\n' ) }) } - - const resetState = () => { - setConsoleHistory( consoleHistory + message ) - setComponentVisible( false ) - setImage('') - setImageInfo('Drop/Click\nfor upload album image...') - setMessage('') - } return (
diff --git a/src/components/index/indexConsole/commands/fetchCommands/Track/Update.js b/src/components/index/indexConsole/commands/fetchCommands/Track/Update.js index e69de29..b5891cd 100644 --- a/src/components/index/indexConsole/commands/fetchCommands/Track/Update.js +++ b/src/components/index/indexConsole/commands/fetchCommands/Track/Update.js @@ -0,0 +1,144 @@ +import React, { useState } from 'react' +import { connect } from 'react-redux' + +import { updateTrack } from '../../../../../../stores/track/duck/operations' +import { FormGenerator } from '../Abstract Utils/FormGenerator' +import { ResetComponent } from '../Abstract Utils/ResetComponent' +import { validate } from '../Abstract Utils/AbstractUpdate' + + +const TrackUpdate = ({ + user, + updateTrack, + consoleHistory, setConsoleHistory, + componentVisible, setComponentVisible, + activateConsoleInput +}) => { + + const [message, setMessage] = useState('') + + const [image, setImage] = useState('') + const [imageInfo, setImageInfo] = useState('Drop/Click\nfor upload track image...') + const [audio, setAudio] = useState('') + const [audioInfo, setAudioInfo] = useState('Drop/Click\nfor upload track audio...') + + const idInput = React.createRef() + const userInput = React.createRef() + const albumIdInput = React.createRef() + const titleInput = React.createRef() + const descriptionInput = React.createRef() + const textInput = React.createRef() + + let refList = [ + idInput, + userInput, + albumIdInput, + titleInput, + descriptionInput, + textInput + ] + + let inputList = [ + { + type: 'info', + action: 'Create', + endpoint: 'Track' + }, + { + type: 'text', + name: 'id', + ref: idInput + }, + { + type: 'text', + name: 'user', + ref: userInput + }, + { + type: 'text', + name: 'albumID', + ref: albumIdInput + }, + { + type: 'text', + name: 'title', + ref: titleInput + }, + { + type: 'text', + name: 'description', + ref: descriptionInput + }, + { + type: 'text', + name: 'text', + ref: textInput + }, + { + type: 'file', + name: 'image', + fileType: 'image', + dropInfo: imageInfo, + setDropInfo: setImageInfo, + file: image, + setFile: setImage + }, + { + type: 'file', + name: 'audio', + fileType: 'audio', + dropInfo: audioInfo, + setDropInfo: setAudioInfo, + file: audio, + setFile: setAudio + } + ] + + const resetState = () => { + setConsoleHistory( consoleHistory + message ) + setComponentVisible( false ) + setImage('') + setImageInfo('Drop/Click\nfor upload track image...') + setAudio('') + setAudioInfo('Drop/Click\nfor upload track audio...') + setMessage('') + } + + const updateFetch = async ( refs ) => { + let track = validate( inputList ) + await updateTrack( + track.id, + track, + user.token + ).then( response => { + setMessage( response['info'] + '\n' ) + }) + } + + return ( +
+ + +
+ ) +} + +const mapStateToProps = state => ({ + user: state.user +}) + +const mapDispatchToProps = dispatch => ({ + updateTrack: (track, token) => updateTrack(track, token) +}) + +export default connect(mapStateToProps, mapDispatchToProps)(TrackUpdate) \ No newline at end of file