refactor Create.js -> generateUrlCode.js && simply fix in FormGenerator.js -> AbstractUtils

develop
TBS093A 2020-08-12 15:11:15 +02:00
parent 03f4d8065b
commit 8396f1918f
3 changed files with 36 additions and 30 deletions

View File

@ -0,0 +1,22 @@
export const generateUrlCode = ( type ) => {
let code = 'op?' + type + '='
let hash = [
'!', '@', '#', '$', '%', '^', '&', '*',
'Q', 'W', 'X', 'S', 'q', 'w', 'x', 's'
]
code += hash[ randomInt(7, 14) ]
+ hash[ randomInt(7, 14) ]
+ hash[ randomInt(7, 14) ]
+ hash[ randomInt(0, 7) ]
+ hash[ randomInt(0, 7) ]
+ hash[ randomInt(0, 7) ]
+ randomInt(0, 9)
+ randomInt(0, 9)
+ randomInt(0, 9)
return code
}
const randomInt = (min, max) => {
return min + Math.floor((max - min) * Math.random())
}

View File

@ -40,6 +40,7 @@ const FormGenerator = ({
* {
* type: 'text',
* name: 'name',
* endpoint: 'Album',
* ref: React.createRef()
* } } input - basic text input
*/
@ -50,7 +51,7 @@ const TextInputGenerator = ({
<div>
{ input.name + ':' }
<input
id={ input.name + 'Input' }
id={ input.name + input.endpoint + 'Input' }
autoComplete='off'
ref={ input.ref }
/>
@ -64,7 +65,8 @@ const TextInputGenerator = ({
* {
* type: 'file',
* name: 'name',
* fileType: 'image',
* endpoint: 'Album',
* fileType: 'image' or 'audio',
* dropInfo: dropInfo, setDropInfo: setDropInfo(), #useState
* file: file, setFile: setFile() #useState
* } } input -
@ -112,9 +114,10 @@ const UploadInputGenerator = ({
</pre>
<input
style={ { marginTop: '-55px' } }
id={ input.name + 'Input' }
id={ input.name + input.endpoint + 'Input' }
className='uploadInput'
type='file'
accept={ input.fileType + '/*' }
autoComplete='off'
onChange={ event => onLoadFile( event ) }
/>

View File

@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'
import { connect } from 'react-redux'
import { createAlbum } from '../../../../../../stores/album/duck/operations'
import { generateUrlCode } from '../../../../../generateUrlCode'
import FormGenerator from '../Abstract Utils/FormGenerator'
@ -23,17 +24,20 @@ const AlbumCreate = ({
let inputList = [
{
type: 'text',
name: 'titleAlbum',
name: 'title',
endpoint: 'Album',
ref: titleInput
},
{
type: 'text',
name: 'descriptionAlbum',
name: 'description',
endpoint: 'Album',
ref: descriptionInput
},
{
type: 'file',
name: 'imageAlbum',
name: 'image',
endpoint: 'Album',
fileType: 'image',
dropInfo: imageInfo,
setDropInfo: setImageInfo,
@ -59,7 +63,7 @@ const AlbumCreate = ({
title: title,
description: description,
image: image,
url_code: generateUrlCode(),
url_code: generateUrlCode( 'album' ),
}
await createAlbum(
album,
@ -68,29 +72,6 @@ const AlbumCreate = ({
setMessage( response['info'] + '\n' )
})
}
const generateUrlCode = () => {
let code = 'op?album='
let hash = [
'!', '@', '#', '$', '%', '^', '&', '*',
'Q', 'W', 'X', 'S', 'q', 'w', 'x', 's'
]
code +=
+ hash[ randomInt(7, 14) ]
+ hash[ randomInt(7, 14) ]
+ hash[ randomInt(7, 14) ]
+ hash[ randomInt(0, 7) ]
+ hash[ randomInt(0, 7) ]
+ hash[ randomInt(0, 7) ]
+ randomInt(0, 9)
+ randomInt(0, 9)
+ randomInt(0, 9)
return code
}
const randomInt = (min, max) => {
return min + Math.floor((max - min) * Math.random())
}
useEffect(
() => {