upgrade abstraction -> AbstractDelete.js && modify GetOne.js

develop
TBS093A 2020-08-17 15:35:44 +02:00
parent aceb9d92c5
commit 0bdc490e38
5 changed files with 81 additions and 55 deletions

View File

@ -0,0 +1,27 @@
/**
* Delete one row
* @param {*} refList
* @param {*} consoleHistory
* @param {*} setConsoleHistory
* @param {*} setMessage
* @param {*} deleteAction
* @param {*} token
*/
export const AbstractDelete = async (
refList,
consoleHistory, setConsoleHistory,
setMessage,
deleteAction,
token
) => {
let id = refList[0].current.value
setConsoleHistory( consoleHistory + 'id: ' + id + '\n')
if ( id >= 0 ) {
deleteAction(
id,
token
).then( response => {
setMessage( response['info'] + '\n' )
})
}
}

View File

@ -15,7 +15,7 @@ export const AbstractGetOne = async (
mapping,
) => {
let inputValue = refList[0].current.value
setConsoleHistory( consoleHistory + 'album id: ' + inputValue + '\n')
setConsoleHistory( consoleHistory + 'id: ' + inputValue + '\n')
if ( inputValue >= 0 ) {
await getOneAction( inputValue ).then( response => {
if ( response['info'] !== 'Not found.' ){

View File

@ -2,7 +2,9 @@ import React, { useState, useEffect } from 'react'
import { connect } from 'react-redux'
import { deleteAlbum } from '../../../../../../stores/album/duck/operations'
import { AbstractDelete } from '../Abstract Utils/AbstractDelete'
import { FormGenerator } from '../Abstract Utils/FormGenerator'
import { ResetComponent } from '../Abstract Utils/ResetComponent'
const AlbumDelete = ({
user,
@ -16,49 +18,50 @@ const AlbumDelete = ({
const idInput = React.createRef()
let refList = [
idInput
]
let inputList = [
{
type: 'text',
name: 'idDelete',
endpoint: 'Album',
ref: idInput
}
]
const deleteFetch = (event) => {
event.preventDefault()
let id = idInput.current.value
setConsoleHistory( consoleHistory + 'album id: ' + id + '\n')
if ( id >= 0 ) {
deleteAlbum(
id,
AbstractDelete(
refList,
consoleHistory,
setConsoleHistory,
setMessage,
deleteAlbum,
user.token
).then( response => {
setMessage( response['info'] + '\n' )
})
}
)
}
useEffect(
() => {
if ( componentVisible ) {
document.getElementById('idAlbumDeleteInput').focus()
} else {
activateConsoleInput()
}
if ( message !== '' ) {
idInput.current.value = ''
const resetState = () => {
setConsoleHistory( consoleHistory + message )
setComponentVisible( false )
setMessage('')
}
}
)
return (
<div>
<form onSubmit={ deleteFetch }>
album id:
<input
id='idAlbumDeleteInput'
autoComplete='off'
ref={ idInput }
<FormGenerator
inputList={ inputList }
refList={ refList }
action={ deleteFetch }
/>
<ResetComponent
resetState={ resetState }
refList={ refList }
message={ message }
componentVisible={ componentVisible }
activateConsoleInput={ activateConsoleInput }
/>
<button type='submit' />
</form>
</div>
)
}

View File

@ -26,7 +26,7 @@ const AlbumGetOne = ({
let inputList = [
{
type: 'text',
name: 'id',
name: 'idGetOne',
endpoint: 'Album',
ref: getOneInput
}
@ -42,7 +42,7 @@ const AlbumGetOne = ({
return mapRowToString( album, mapFields )
}
const getOneAlbumFetch = (event) => {
const getOneAlbumFetch = () => {
AbstractGetOne(
refList,
consoleHistory,
@ -77,16 +77,6 @@ const AlbumGetOne = ({
)
}
{/* <form onSubmit={ getOne }>
album id:
<input
id='getOneAlbumInput'
autoComplete='off'
ref={ getOneInput }
/>
<button type='submit' />
</form> */}
const mapStateToProps = state => ({
album: state.album
})

View File

@ -84,10 +84,16 @@ const responseGD = async (address, method, token) => {
"Content-Type": "application/json"
}
})
if ( method === 'GET' )
return await responseExceptions(
await response.json(),
response.status
)
else
return await responseExceptions(
await response,
response.status
)
} catch (error) {
return { info: error }
}