import axios from "axios"; import React, { useCallback, useEffect, useState } from "react"; import { API } from "../../data"; import { isAutheticated } from "../../auth"; import ClipLoader from "react-spinners/ClipLoader"; import { useHistory } from "react-router-dom"; import swal from 'sweetalert'; import { CButton, CCard, CCardBody, CCol, CContainer, CForm, CFormInput, CInputGroup, CInputGroupText, CRow, } from '@coreui/react' import CIcon from '@coreui/icons-react' import { cilPencil, cilSettings, cilLockLocked, cilUser, cilBell, cilLocationPin, cilAudioDescription, cilCalendar, cilWatch, cilAlarm } from '@coreui/icons' const AddEvent = () => { const token = isAutheticated(); let history = useHistory(); const [image, setImage] = useState(""); const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [location, setLocation] = useState(""); const [date, setDate] = useState(new Date()); const [time, setTime] = useState(''); const [loading, setLoading] = useState(false); const handleSubmit = async () => { if (!(title && description && image && location && time && date)) { alert("Please fill All required field "); return; } const myForm = new FormData(); myForm.set("title", title); myForm.set("description", description); myForm.set("location", location); myForm.set("date", date) myForm.set("time", time) myForm.set("image", image); setLoading({ loading: true }); // console.log(image) try { let res = await axios.post( `/api/event/create`, myForm, { headers: { "Content-Type": 'multipart/form-data', Authorization: `Bearer ${token}`, }, } ); // console.log(res.data) if (res.data) { swal("success!", "Event Added Successfully!", "success"); setLoading(false); history.goBack(); } } catch (error) { alert("Something went Wrong") setLoading(false); } }; const handleImage = (e) => { const files = e.target.files[0]; // console.log(files) setImage(files); }; // const onCancel = () => { // window.location = "/comproducts"; history.goBack() }; return ( <>