import axios from "axios"; import React from "react"; import swal from "sweetalert"; import { isAutheticated } from "src/auth"; const ProductDetails = (props) => { const token = isAutheticated(); const { data, setData } = props.data; const { productId, setProductId } = props.ProductId; const { loading, setLoading } = props.loading; const categories = props?.categories || []; const handleChange = (e) => { if (e.target.id === "master_price" && /^\D+$/.test(e.target.value)) return; if (e.target.id === "discontinue_on") { if (new Date(e.target.value) < new Date()) { return setData((prev) => ({ ...prev, [e.target.id]: new Date().toISOString().slice(0, 10), })); } } setData((prev) => ({ ...prev, [e.target.id]: e.target.value })); }; const handleSubmit = () => { if ( data.name.trim() === "" || // data.master_price.trim() === "" || data.category === "" || data.description === "" || data.product_Status === "" // data.sku === "" || // data.hsn_code === "" ) { swal({ title: "Warning", text: "Fill all mandatory fields", icon: "warning", button: "Return", }); return; } setLoading(true); axios .post( `/api/product/create/`, { ...data, product_id: productId }, { headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, } ) .then((res) => { swal({ title: "Saved", text: "Product details saved successfully!", icon: "success", button: "Close", }); setProductId(res.data.product_id); setLoading(false); }) .catch((err) => { const msg = err?.response?.data?.message || "Something went wrong!"; swal({ title: "Warning", text: msg, icon: "warning", button: "Close", }); setLoading(false); }); }; return ( <>