generated from goitacademy/react-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from 001elijah/sidebar
sendEmail logic/svg fix/styles fix
- Loading branch information
Showing
4 changed files
with
57 additions
and
12 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,41 @@ import flower1x from 'assets/images/flower-min.png'; | |
import flower2x from 'assets/images/[email protected]'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
import { useState } from 'react'; | ||
import { Modal } from '../Modal/Modal'; | ||
import { useState, useEffect } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { sendEmail } from 'redux/Auth/authOperations'; | ||
|
||
export const HelpWindow = ({ theme }) => { | ||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
const dispatch = useDispatch(); | ||
|
||
const onOpen = () => { | ||
setIsModalOpen(true); | ||
}; | ||
|
||
const onClose = () => { | ||
setIsModalOpen(false); | ||
}; | ||
|
||
const onSubmit = e => { | ||
e.preventDefault(); | ||
|
||
const email = e.target.email.value; | ||
const comment = e.target.comment.value; | ||
|
||
dispatch(sendEmail({ email, comment })); | ||
onClose(); | ||
}; | ||
|
||
useEffect(() => { | ||
document.body.classList.toggle('no-scroll', isModalOpen); | ||
|
||
return () => { | ||
document.body.classList.remove('body-scroll-lock'); | ||
}; | ||
}, [isModalOpen]); | ||
|
||
return ( | ||
<div className={clsx(s.container, s[theme])}> | ||
<div className={s.imageContainer}> | ||
|
@@ -32,9 +57,7 @@ export const HelpWindow = ({ theme }) => { | |
<button | ||
type="button" | ||
className={clsx(s.button, s[theme])} | ||
onClick={() => { | ||
setIsModalOpen(true); | ||
}} | ||
onClick={onOpen} | ||
> | ||
<svg className={clsx(s.icon, s[theme])}> | ||
<use href={`${sprite}#icon-help`}></use> | ||
|
@@ -43,14 +66,16 @@ export const HelpWindow = ({ theme }) => { | |
</button> | ||
{isModalOpen && ( | ||
<Modal title="Need help" onClose={onClose} className={s.modal}> | ||
<form> | ||
<form onSubmit={onSubmit}> | ||
<input | ||
type="email" | ||
name="email" | ||
placeholder="Email address" | ||
className={s.emailInput} | ||
/> | ||
<textarea | ||
type="text" | ||
name="comment" | ||
placeholder="Comment" | ||
className={s.commentInput} | ||
/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters