Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
1.5 kB
13
Indexable
Never
import { send_reminder } from "../services/Apis";

const StaffReminder = () => {
  const [loading, setLoading] = useState(false);
  const [message, setMessage] = useState("");
  var [emailContent, setEmailContent] = useState("");

  const sendEmail = async () => {
    try {
      setLoading(true);
      
      const data = {
          emailContent : emailContent
      }
      console.log(data);
      const response = await send_reminder("/user/st_reminder", { data });
      setMessage(response.data.message);
    } catch (error) {
      setMessage("Failed to send email.");
    } finally {
      setLoading(false);
    }
  };
  

  const handleEmailContentChange = (event) => {
    setEmailContent(event.target.value);
  };
//-------------------API---------------------------

export const send_reminder = async(data)=>{
    return await commonrequest("POST",`${BACKEND_URL}/user/st_reminder`,data)
}

//------------------ROUTER---------------------------

router.post("/user/st_reminder", controllers.send_mail);

//-----------------CONTROLLER-----------------------


exports.send_mail = async (req, res) => {
    try {
       
        const {mes} = req.body;
        console.log(mes);
        
        res.status(200).json({ message: 'Email sent successfully.' });
    } catch (error) {
        console.error(error);
        res.status(500).json({ message: 'An error occurred while sending email.' });
    }
};