ok i will post the rest of the code here
import React, { useState } from 'react'
import Sidebar from '../../components/sidebar/Sidebar'
import Navbar from '../../components/navbar/Navbar'
import './create.scss'
import DriveFolderUploadOutlinedIcon from '@mui/icons-material/DriveFolderUploadOutlined'
import usePost from '../../hooks/usePost'
import { logDOM } from '@testing-library/react'
const Create = ({ inputs, title }) => {
const userUrl = 'http://localhost:4000/api/v1/auth/register'
const [data, post, loading, error] = usePost(userUrl)
const [file, setFile] = useState('')
const [createData, setCreateData] = useState({
username: 'cdscsd',
name: 'sdffds',
email: 'cdscs',
phone: 'csdc',
password: 'csdcs',
address: 'csdc',
})
const handleInput = (e) => {
e.preventDefault()
const { name, value } = e.target
setCreateData((prev) => ({ ...prev, [name]: value }))
}
const handleSubmit = (e) => {
e.preventDefault()
const sendCreateData = {
name: createData.name,
email: createData.email,
password: createData.password,
role: 'user',
}
post(sendCreateData)
}
return (
<div className='create'>
<Sidebar />
<div className='createContainer'>
<Navbar />
<div className='top'>{title}</div>
<div className='bottom'>
<div className='left'>
<img
src={
file
? URL.createObjectURL(file)
: `https://icon-library.com/images/no-image-icon/no-image-icon-0.jpg`
}
alt='avatar'
/>
</div>
<div className='right'>
<form>
<div className='formInput'>
<label>
Image: <DriveFolderUploadOutlinedIcon className='icon' />
</label>
<input
type='file'
id='file'
onChange={(e) => setFile(e.target.files[0])}
style={{ display: 'none' }}
/>
</div>
{inputs.map((input) => {
console.log(input.value)
return (
<div className='formInputs' key={input.id}>
<label>{input.label}</label>
<input
name={input.name}
type={input.type}
placeholder={input.placeholder}
onChange={handleInput}
value={input.value}
></input>
</div>
)
})}
<button onClick={handleSubmit}>Send</button>
</form>
</div>
</div>
</div>
</div>
)
}
export default Create
export const userInputs = [
{
id: 1,
label: 'Username',
type: 'text',
placeholder: 'john_doe',
name: 'username',
value: createData.username,
},
{
id: 2,
label: 'Name and surname',
type: 'text',
placeholder: 'John Doe',
name: 'name',
value: createData.name,
},
{
id: 3,
label: 'Email',
type: 'mail',
placeholder: 'john_doe@gmail.com',
name: 'email',
value: createData.email,
},
{
id: 4,
label: 'Phone',
type: 'text',
placeholder: '+1 234 567 89',
name: 'phone',
value: createData.phone,
},
{
id: 5,
label: 'Password',
type: 'password',
name: 'password',
value: createData.password,
},
{
id: 6,
label: 'Address',
type: 'text',
placeholder: 'Elton St. 216 NewYork',
name: 'address',
value: createData.address,
},
{
id: 7,
label: 'Country',
type: 'text',
placeholder: 'USA',
name: 'country',
value: createData.country,
},
]