import axios from 'axios'; import React from 'react'; import { Col, Form, Row } from 'react-bootstrap'; import { useForm } from 'react-hook-form'; import toast from 'react-hot-toast'; import swal from 'sweetalert'; import { useAppContext } from '../../../context'; const MakeAdmin = () => { const { state:{ user: {email}}} = useAppContext() const { register, handleSubmit, formState: { errors }, reset} = useForm(); const onSubmit = data => { const loading = toast.loading('Please wait...') if(email === "test@admin.com"){ toast.dismiss(loading) swal("Permission restriction!", "As a test admin, You haven't permission to add a new admin", "info"); } else { axios.post('https://immense-river-40491.herokuapp.com/addAdmin',{email: data.email}) .then(res => { toast.dismiss(loading) toast.success('One admin added successfully') reset(); }) .catch(err => { toast.dismiss(loading) toast.error(err.message) }) } }; return (
Email {errors.email && This field is required}
) }; export default MakeAdmin;