Skip to content

Commit

Permalink
Merge pull request #27 from 001elijah/sidebar
Browse files Browse the repository at this point in the history
sendEmail logic/svg fix/styles fix
  • Loading branch information
001elijah authored Jun 26, 2023
2 parents 4013c59 + 5708179 commit 5fa886c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/assets/icons/sprite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 30 additions & 5 deletions src/components/HelpWindow/HelpWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand All @@ -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>
Expand All @@ -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}
/>
Expand Down
13 changes: 13 additions & 0 deletions src/redux/Auth/authOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
currentUserApi,
logoutUserApi,
themeChangeUserApi,
sendEmailApi,
updateUserApi,
} from 'services/backendAPI';

Expand Down Expand Up @@ -119,3 +120,15 @@ export const updateUser = createAsyncThunk(
}
},
);

export const sendEmail = createAsyncThunk(
'auth/sendEmail',
async (email, { rejectWithValue }) => {
try {
await sendEmailApi(email);
return Notify.success('Email sent');
} catch (error) {
return rejectWithValue(error.message);
}
},
);
7 changes: 7 additions & 0 deletions src/services/backendAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ export const getListOfBoardsApi = async userToken => {
return data;
};

//---------------------------------------------EMAIL---------------------//

export const sendEmailApi = async userEmail => {
const { data } = await axios.post('user/sendEmail', userEmail);
return data.message;
};

// export const addColumn = async board => {
// const { data } = await axios.post('board/column');
// console.log(data);
Expand Down

0 comments on commit 5fa886c

Please sign in to comment.