import React, {useState, useEffect} from 'react' import Layout from '../Partials/Layout' import { Link, useNavigate, useLocation, useParams } from 'react-router-dom' // import { toast } from 'react-toastify'; import InputCom from "../Helpers/Inputs/InputCom"; import Calendar from 'react-calendar'; import 'react-calendar/dist/Calendar.css'; import usersService from "../../services/UsersService"; export default function AddEditReminder({ className }) { let navigate = useNavigate() const api = new usersService(); let {reminder_uuid} = useParams() // uuid of single reminder let location = useLocation() const [startDate, setStartDate] = useState(new Date()); const [endDate, setEndDate] = useState(new Date()); const [mode, setMode] = useState([]) // for setting mode option display, content is updated when page loads const [category, setCategory] = useState([]) // for setting category option display, content is updated when page loads const [success, setSuccess] = useState(false) const [message, setMessage]=useState({ status: false, message: '' }) const [reminder, setReminder]=useState({ 'member_id': localStorage.getItem('member_id'), description: location.state?.reminder.description || '', note: location.state?.reminder.note || '', category: location.state?.reminder.category || '', mode: location.state?.reminder.mode || '', 'start_date': location.state? new Date(location.state?.reminder.start_date) : startDate, 'end_date': location.state? new Date(location.state?.reminder.end_date) : endDate }) const onReminderInputChange = ({target:{name,value}}) => { //function to run when user changes any input on the add reminder page setReminder(prev=>( {...prev, [name]:value} )) } const getUserMode = async () => { try { const res = await api.getUserModeCategory('remmode'); setMode(res.data); } catch (error) { console.log("Error getting mode"); } }; const getUserCategory = async () => { try { const res = await api.getUserModeCategory('remcategory'); setCategory(res.data); } catch (error) { console.log("Error getting user category"); } }; const handleAddReminder = async () => { // function to add reminder, after all test cases are met // toast('Reminder Added') if(location.state){ reminder.uuid = reminder_uuid } setSuccess(true) setMessage({status: true, message: ''}) let {description, note, category, mode} = reminder //CHECKING IF AN EMPTY FIELD WAS PASSED if(!description || !note || !category || !mode){ setSuccess(false) setMessage({status: false, message: 'All fields must be filled'}) return } try { const res = await api.addReminder(reminder); if(res && res.status == 200){ setSuccess(false) setMessage({status: true, message: 'Reminder successfully'}) setTimeout(()=>{ navigate('/reminders', {replace: true}) }, 2000) return } setSuccess(false) setMessage({status: false, message: `Opps, couldn't perform action`}) } catch (error) { setSuccess(false) setMessage({status: false, message: 'An error occurred'}) } } useEffect(() => { getUserMode(); getUserCategory() }, []); return ( <>
{/*description */}
{/* first name and last name */}
{/* */}
{/* */}
{/* */}
{/* */}
{/* bio */}

Optional Details