feat: add setting to enable/disable email alert

This commit is contained in:
bsourisse 2023-01-16 18:28:54 +01:00
parent 46c41f9b66
commit 6409975a6e
2 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1,91 @@
//Lib
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import classes from '../UserSettings.module.css';
import { useState } from 'react';
import { SpinnerDotted } from 'spinners-react';
//Components
import Error from '../../../Components/UI/Error/Error';
import Switch from '../../../Components/UI/Switch/Switch';
export default function EmailAlertSettings(props) {
//Var
const toastOptions = {
position: 'top-right',
autoClose: 8000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
};
////State
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState();
////Functions
//Form submit Handler for ADD a repo
// const formSubmitHandler = async (data) => {
// console.log(data);
// //Remove old error
// setError();
// //Loading button on submit to avoid multiple send.
// setIsLoading(true);
// //POST API to send the new and old password
// const response = await fetch('/api/account/updateEmail', {
// method: 'PUT',
// headers: {
// 'Content-type': 'application/json',
// },
// body: JSON.stringify(data),
// });
// const result = await response.json();
// if (!response.ok) {
// setIsLoading(false);
// reset();
// setError(result.message);
// setTimeout(() => setError(), 4000);
// } else {
// reset();
// setIsLoading(false);
// setInfo(true);
// toast.success('Email edited !', {
// position: 'top-right',
// autoClose: 5000,
// hideProgressBar: false,
// closeOnClick: true,
// pauseOnHover: true,
// draggable: true,
// progress: undefined,
// });
// }
// };
const onChangeSwitchHandler = (e) => {
console.log(e);
};
return (
<>
{/* EMAIL ALERT */}
<div className={classes.containerSetting}>
<div className={classes.settingCategory}>
<h2>Alerting</h2>
</div>
<div className={classes.setting}>
<div className={classes.bwFormWrapper}>
<Switch
switchName='Email'
switchDescription='You will receive an alert every 24H if you have a down status.'
onChange={(e) =>
onChangeSwitchHandler({ emailAlert: e })
}
/>
</div>
</div>
</div>
</>
);
}

View file

@ -6,6 +6,7 @@ import classes from './UserSettings.module.css';
import EmailSettings from './EmailSettings/EmailSettings';
import PasswordSettings from './PasswordSettings/PasswordSettings';
import UsernameSettings from './UsernameSettings/UsernameSettings';
import EmailAlertSettings from './EmailAlertSettings/EmailAlertSettings';
export default function UserSettings(props) {
return (
@ -21,6 +22,7 @@ export default function UserSettings(props) {
<PasswordSettings username={props.data.user.name} />
<EmailSettings email={props.data.user.email} />
<UsernameSettings username={props.data.user.name} />
<EmailAlertSettings />
</div>
);
}