|
@@ -1,111 +1,26 @@
|
|
|
-import { useEffect } from 'react';
|
|
|
-import hookForm from 'hook-easy-form';
|
|
|
+import { useEffect, useState } from 'react';
|
|
|
import { useSelector, useDispatch } from 'react-redux';
|
|
|
|
|
|
-import { setData, getUsers } from 'store/counter/actions';
|
|
|
+import { uploadPicture } from 'store/user/actions';
|
|
|
|
|
|
import classes from './index.module.scss';
|
|
|
|
|
|
-const form = [
|
|
|
- {
|
|
|
- name: 'first_name',
|
|
|
- value: '',
|
|
|
- required: true,
|
|
|
- options: {
|
|
|
- type: 'text',
|
|
|
- label: 'First Name'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'last_name',
|
|
|
- value: '',
|
|
|
- required: true,
|
|
|
- options: {
|
|
|
- type: 'text',
|
|
|
- label: 'Last Name'
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'age',
|
|
|
- value: '',
|
|
|
- required: true,
|
|
|
- options: {
|
|
|
- type: 'number',
|
|
|
- label: 'Your Age'
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'gender',
|
|
|
- value: '',
|
|
|
- required: true,
|
|
|
- options: {
|
|
|
- type: 'select',
|
|
|
- label: 'Pick your gender',
|
|
|
- options: [
|
|
|
- { id: 'none', text: '' },
|
|
|
- { id: 'male', text: 'Male' },
|
|
|
- { id: 'female', text: 'Female' }
|
|
|
- ]
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'bio',
|
|
|
- value: '',
|
|
|
- required: true,
|
|
|
- options: {
|
|
|
- type: 'text-area',
|
|
|
- label: 'Tell us about yourself'
|
|
|
- },
|
|
|
- },
|
|
|
-]
|
|
|
-
|
|
|
-
|
|
|
const Main = () => {
|
|
|
+ const [file, setFile] = useState(null);
|
|
|
const dispatch = useDispatch();
|
|
|
- const { formArray, updateEvent, submitEvent, setValueManually } = hookForm({ initialForm: form })
|
|
|
-
|
|
|
- const user = useSelector((s) => s.auth.user);
|
|
|
+ console.log('file', file);
|
|
|
|
|
|
- const submit = submitEvent((d) => dispatch(setData(d)));
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- dispatch(getUsers())
|
|
|
- }, [dispatch])
|
|
|
+ const uploadHandler = () => {
|
|
|
+ dispatch(uploadPicture(file))
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
|
<div>
|
|
|
<h1>MAIN PAGE</h1>
|
|
|
-
|
|
|
- <form onSubmit={submit} className={classes.form}>
|
|
|
- {formArray.map(el => {
|
|
|
- if (el.options.type === 'text' || el.options.type === 'number') {
|
|
|
- return <label key={el.name} className={classes.label}>
|
|
|
- <span>{el.options.label}</span>
|
|
|
- <input name={el.name} type={el.options.type} value={el.value} onChange={updateEvent} />
|
|
|
- </label>
|
|
|
- }
|
|
|
- if (el.options.type === 'text-area') {
|
|
|
- return <label key={el.name} className={classes.label}>
|
|
|
- <span>{el.options.label}</span>
|
|
|
- <textarea name={el.name} value={el.value} onChange={updateEvent} />
|
|
|
- </label>
|
|
|
- }
|
|
|
- if (el.options.type === 'select') {
|
|
|
- return <label key={el.name} className={classes.label}>
|
|
|
- <span>{el.options.label}</span>
|
|
|
- <select name={el.name} value={el.value} onChange={(e) => setValueManually(el.name, e.target.value)} >
|
|
|
- {el.options.options.map(e => <option key={e.id} value={e.id}>{e.text}</option>)}
|
|
|
- </select>
|
|
|
- </label>
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
- })}
|
|
|
|
|
|
- <button type="submit">Submit</button>
|
|
|
- </form>
|
|
|
+ <input type="file" onChange={(e) => setFile(e.target.files[0])} />
|
|
|
|
|
|
- <pre>{JSON.stringify(user, null, 2)}</pre>
|
|
|
+ <button onClick={uploadHandler}>UPLOAD</button>
|
|
|
</div>
|
|
|
)
|
|
|
}
|