// AdForm.js
// imports
import toast from "react-hot-toast";
import axios from "axios";
import { useNavigate } from "react-router-dom";

const navigate = useNavigate();

const handleSubmit = async (e) => {
  e.preventDefault();
  try {
    setAd({ ...ad, loading: true });
    const { data } = await axios.post("/ad", ad);
    if (data?.error) {
      toast.error(data.error);
      setAd({ ...ad, loading: false });
    } else {
      // console.log("ad create response => ", data);
      toast.success("Ad created successfully");
      navigate("/dashboard");
    }
  } catch (err) {
    console.log(err);
    setAd({ ...ad, loading: false });
  }
};