|
@@ -9,12 +9,16 @@ import { Works } from '../../components/Works/Works';
|
|
import { MainLayout } from '../../layouts/MainLayout';
|
|
import { MainLayout } from '../../layouts/MainLayout';
|
|
import { PopupWrapper } from '../../components/PopupWrapper/PopupWrapper';
|
|
import { PopupWrapper } from '../../components/PopupWrapper/PopupWrapper';
|
|
import { Input } from '../../components/Input/Input';
|
|
import { Input } from '../../components/Input/Input';
|
|
|
|
+import { useInput } from '../../hooks/useInput';
|
|
|
|
+import { createWork } from '../../store/works/actions/createWork';
|
|
|
|
|
|
export const YourWorksPage = () => {
|
|
export const YourWorksPage = () => {
|
|
const dispatch = useDispatch();
|
|
const dispatch = useDispatch();
|
|
const { isAuth } = useSelector((state) => state.auth);
|
|
const { isAuth } = useSelector((state) => state.auth);
|
|
const { isLoading } = useSelector((state) => state.works);
|
|
const { isLoading } = useSelector((state) => state.works);
|
|
const newPenPopup = usePopup();
|
|
const newPenPopup = usePopup();
|
|
|
|
+ const title = useInput();
|
|
|
|
+ const description = useInput();
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (isAuth) {
|
|
if (isAuth) {
|
|
@@ -24,6 +28,18 @@ export const YourWorksPage = () => {
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
|
+ const handleCreate = (e) => {
|
|
|
|
+ e.preventDefault();
|
|
|
|
+ const newWork = {
|
|
|
|
+ title: title.value,
|
|
|
|
+ description: description.value,
|
|
|
|
+ };
|
|
|
|
+ dispatch(createWork(newWork));
|
|
|
|
+ newPenPopup.close();
|
|
|
|
+ title.setValue('');
|
|
|
|
+ description.setValue('');
|
|
|
|
+ };
|
|
|
|
+
|
|
if (isLoading) return <LoadingPage />;
|
|
if (isLoading) return <LoadingPage />;
|
|
return (
|
|
return (
|
|
<MainLayout className={style.yourWorks}>
|
|
<MainLayout className={style.yourWorks}>
|
|
@@ -44,10 +60,18 @@ export const YourWorksPage = () => {
|
|
isOpen={newPenPopup.isPopupVisible}
|
|
isOpen={newPenPopup.isPopupVisible}
|
|
close={newPenPopup.close}
|
|
close={newPenPopup.close}
|
|
>
|
|
>
|
|
- <form>
|
|
|
|
- <Input title="Pen title" />
|
|
|
|
- <Input title="Pen description" />
|
|
|
|
- <button>Create</button>
|
|
|
|
|
|
+ <form onSubmit={handleCreate}>
|
|
|
|
+ <Input
|
|
|
|
+ value={title.value}
|
|
|
|
+ onChange={title.onChange}
|
|
|
|
+ title="Pen title"
|
|
|
|
+ />
|
|
|
|
+ <Input
|
|
|
|
+ value={description.value}
|
|
|
|
+ onChange={description.onChange}
|
|
|
|
+ title="Pen description"
|
|
|
|
+ />
|
|
|
|
+ <button type="submit">Create</button>
|
|
</form>
|
|
</form>
|
|
</PopupWrapper>
|
|
</PopupWrapper>
|
|
</MainLayout>
|
|
</MainLayout>
|