Skip to content

Commit

Permalink
Merge pull request #38 from jeevan-aj/update
Browse files Browse the repository at this point in the history
doseCleanup for addProductModal
  • Loading branch information
jeevan-aj authored Apr 7, 2024
2 parents 52e4104 + ab1aa58 commit 15dea3d
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions client/src/pages/admin/components/AddProductModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,27 @@ import { Button, Modal } from "flowbite-react";
import { useDispatch, useSelector } from "react-redux";
import {
addVehicleClicked,
setEditData,
// setEditData,
} from "../../../redux/adminSlices/actions";
import { useForm, Controller } from "react-hook-form";
import { useLocation, useNavigate } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import toast, { Toaster } from "react-hot-toast";

const AddProductModal = () => {
const { register, handleSubmit, reset, control } = useForm();
const navigate = useNavigate();

const dispatch = useDispatch();
const { isAddVehicleClicked, editData } = useSelector(
const { isAddVehicleClicked } = useSelector(
(state) => state.addVehicle
);

//get vehicle id from request
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const vehicle_id = queryParams.get("vehicle_id");



const onSubmit = async (data) => {

try {
if (editData) {
const formData = data;
dispatch(setEditData({ _id: vehicle_id, ...formData }));
await fetch(`/api/admin/editVehicle/${editData._id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ formData }),
});
dispatch(setEditData(null));
} else {

const formData = new FormData();

formData.append("registeration_number", data.registeration_number);
Expand Down Expand Up @@ -78,7 +62,7 @@ const AddProductModal = () => {
toast.success("added");
toast.dismiss(tostID);
}
}

reset();
} catch (error) {
console.log(error);
Expand Down

0 comments on commit 15dea3d

Please sign in to comment.