diff --git a/src/app/admin/(pos-system)/pos/(product)/product-list/page.jsx b/src/app/admin/(pos-system)/pos/(product)/product-list/page.jsx index a9e49d4..8071eab 100644 --- a/src/app/admin/(pos-system)/pos/(product)/product-list/page.jsx +++ b/src/app/admin/(pos-system)/pos/(product)/product-list/page.jsx @@ -8,7 +8,8 @@ import PageNoData from "@/components/common-component/PageNoData"; import Breadcrumb from "@/components/Breadcrumb"; import Link from "next/link"; import { useRouter } from "next/navigation"; -import { ImageBase } from "@utils/BaseUrl.utils"; +import { Baseurl, ImageBase } from "@utils/BaseUrl.utils"; +import axios from "axios"; const ProductListInner = () => { @@ -44,7 +45,7 @@ const ProductListInner = () => { is_active: 0, }); - const [menuItemDeleteConfirm, setMenuItemDeleteConfirm] = useState({ show: false, id: null, isDeleted: null }); + const [menuItemDeleteConfirm, setMenuItemDeleteConfirm] = useState({ show: false, id: null, isDeleted: null, menu: null }); const [restaruntBranch, setRestaruntBranch] = useState("") @@ -69,7 +70,7 @@ const ProductListInner = () => { try { const res = await client?.get(`/Dine360 Menu?fields=["*"]&limit_page_length=100`); setCatMenu(res?.data?.data || []); - setCatMenuActive(res?.data?.data[0]?.name || []); + setCatMenuActive(res?.data?.data[0]?.menuname || []); } catch (error) { console.error("Error fetching menu list:", error); } @@ -77,7 +78,7 @@ const ProductListInner = () => { useEffect(() => { if (catMenu?.length > 0) { - getMenuCategoryItems(catMenu[0]?.menuname); + getMenuCategoryItems(catMenu[0]?.name); } }, [catMenu]); @@ -109,7 +110,7 @@ const ProductListInner = () => { const categories = await Promise.all(menuCategoryPromises); const validCategories = categories.filter(Boolean); - + console.log("validCategories", validCategories) setMenuData(validCategories); } catch (error) { console.error("Error fetching menu categories:", error); @@ -131,12 +132,13 @@ const ProductListInner = () => { } }; - const handleCatMenuClick = async (menuname) => { - await getMenuCategoryItems(menuname); - setCatMenuActive(menuname); + const handleCatMenuClick = async (menu) => { + await getMenuCategoryItems(menu.name); + setCatMenuActive(menu.name); }; const handleMenuClick = async (menu) => { + console.log("menu", menu) try { const res = await client.get( `/Dine360%20Menu%20Category/${menu.name}?fields=["*"]&limit_page_length=100` @@ -320,7 +322,7 @@ const ProductListInner = () => { const handleMenuCategoryDelete = async () => { try { const Body = { - isdelete: menuCategoryDeleteConfirm.isDeleted == 0 ? 1 : 0 + isdeleted: menuCategoryDeleteConfirm.isDeleted == 0 ? 1 : 0 } // await client.delete(`/Dine360%20Menu%20Category%20Link/${catMenuActive} - ${menuCategoryDeleteConfirm.id}`) @@ -341,28 +343,92 @@ const ProductListInner = () => { }; + const handleMenuItemDelete = async () => { try { const body = { - isdelete: menuItemDeleteConfirm?.isDeleted == 0 ? 1 : 0 - } - await client.put(`/Dine360%20Menu%20Category/${activeCategory}/${menuItemDeleteConfirm.id}`, body); - setMenuItemDeleteConfirm({ show: false, id: null, isDeleted: null }); + name: menuItemDeleteConfirm?.menu?.name || '', + menuitemname: menuItemDeleteConfirm?.menu?.menuitemname || '', + price: menuItemDeleteConfirm?.menu?.price || 0, + is_active: menuItemDeleteConfirm?.menu?.is_active ? 1 : 0, + is_special: menuItemDeleteConfirm?.menu?.is_special ? 1 : 0, + availability_time: menuItemDeleteConfirm?.menu?.availability_time || '', + preparation_time: menuItemDeleteConfirm?.menu?.preparation_time || '', + description: menuItemDeleteConfirm?.menu?.description || '', + isdeleted: menuItemDeleteConfirm?.isDeleted == 0 ? 1 : 0 + }; + + // // ✅ Convert image to File using Axios with arraybuffer + // async function getImageAsFile(imageUrl, fileName) { + // try { + // const response = await axios.get(imageUrl, { + // responseType: "arraybuffer", // Important for binary data + // }); + // const mimeType = response.headers["content-type"] || "image/jpeg"; + // const blob = new Blob([response.data], { type: mimeType }); + // return new File([blob], fileName || "image.jpg", { type: mimeType }); + // } catch (err) { + // console.error("Image fetch error:", err); + // return null; + // } + // } + + // Prepare image if exists + // let imageFile = null; + // if (menuItemDeleteConfirm?.menu?.item_image) { + // const fullUrl = `${ImageBase}${menuItemDeleteConfirm.menu.item_image}`; + // const fileName = menuItemDeleteConfirm.menu.item_image.split("/").pop(); + // imageFile = await getImageAsFile(fullUrl, fileName); + // } + + // Prepare FormData + const formDataToSend = new FormData(); + formDataToSend.append("endpoint", "Dine360 Menu Category"); + // if (imageFile) { + // formDataToSend.append("file", imageFile); + // formDataToSend.append("fileid", "item_image"); + // } + formDataToSend.append("childjson", JSON.stringify(body)); + formDataToSend.append("childkey", "menuitems_child"); + formDataToSend.append("docname", activeCategory); + formDataToSend.append("isimageupdateorcreate", 0); + + // Send request + const response = await axios.post( + `${Baseurl}/Upload-Image-To-Frappe/parent-child`, + formDataToSend, + { + headers: { + Authorization: "token 482beca79d9c005:b8778f51fcca82b", + }, + } + ); + + console.log("response", response.data); + + setMenuItemDeleteConfirm({ show: false, id: null, isDeleted: null, menu: null }); getMenuItem(); + } catch (error) { if ( error?.response?.data?.exception?.includes("DuplicateEntryError") || error?.response?.data?.message?.includes("Duplicate entry") ) { alert("Menu Name already exists. Please use a different name."); - } else if (error?.response?.data?.exception?.includes("LinkExistsError") || - error?.response?.data?.message?.includes("LinkExistsError")) { - alert("Cannot delete or cancel because Dine360 Menu three is linked with Dine360 Menu Category "); + } else if ( + error?.response?.data?.exception?.includes("LinkExistsError") || + error?.response?.data?.message?.includes("LinkExistsError") + ) { + alert("Cannot delete or cancel because Dine360 Menu three is linked with Dine360 Menu Category"); + } else { + console.error("Unexpected error:", error); + alert("Something went wrong. Please try again."); } } }; + const renderMenuItem = (menu) => (
@@ -380,7 +446,7 @@ const ProductListInner = () => {
{ - menu?.isdelete == 1 && () @@ -417,10 +483,10 @@ const ProductListInner = () => { onClick={(e) => { e.preventDefault(); e.stopPropagation(); // optional - setMenuItemDeleteConfirm({ show: true, id: menu.name, isDeleted: menu.isdelete }); + setMenuItemDeleteConfirm({ show: true, id: menu.name, isDeleted: menu.isdeleted, menu: menu }); }} > - {menu.isdelete == 1 ? ( + {menu.isdeleted == 1 ? ( <> Restore @@ -440,6 +506,8 @@ const ProductListInner = () => { ); + console.log("menuData", menuData) + console.log("activecategory", activeCategory) return ( <> @@ -468,7 +536,7 @@ const ProductListInner = () => { className={`nav-item border rounded-2 px-3 py-3 bg-border-theme d-flex align-items-center gap-3 position-relative ${catMenuActive === menu.menuname ? "bg-theme" : "" }`} role="presentation" - onClick={() => handleCatMenuClick(menu?.menuname)} + onClick={() => handleCatMenuClick(menu)} style={{ cursor: "pointer" }} > {menu.isdeleted !== 1 ? ( @@ -560,7 +628,7 @@ const ProductListInner = () => { > {/* Left: Icon and Name */}
- {menu.isdelete == 0 ? ( + {menu.isdeleted == 0 ? ( menu { href="#" onClick={(e) => { e.preventDefault(); - setMenuCategoryDeleteConfirm({ show: true, id: menu.name, isDeleted: menu.isdelete }); // 👈 use menu + setMenuCategoryDeleteConfirm({ show: true, id: menu.name, isDeleted: menu.isdeleted }); // 👈 use menu }} > - {menu.isdelete == 1 ? ( + {menu.isdeleted == 1 ? ( <> Restore @@ -867,7 +935,7 @@ const ProductListInner = () => {

@@ -878,7 +946,7 @@ const ProductListInner = () => {

diff --git a/src/app/admin/(pos-system)/pos/(product)/update-product/page.jsx b/src/app/admin/(pos-system)/pos/(product)/update-product/page.jsx index 3be62c6..de6ead6 100644 --- a/src/app/admin/(pos-system)/pos/(product)/update-product/page.jsx +++ b/src/app/admin/(pos-system)/pos/(product)/update-product/page.jsx @@ -131,12 +131,16 @@ const UpdateProduct = () => { try { const formDataToSend = new FormData(); formDataToSend.append("endpoint", "Dine360 Menu Category"); - formDataToSend.append("file", imageFile); // ✅ use imageFile formDataToSend.append("fileid", "item_image"); formDataToSend.append("childjson", JSON.stringify(body)) formDataToSend.append("childkey", "menuitems_child"); formDataToSend.append("docname", category); - formDataToSend.append("isimageupdateorcreate", 1); + if (imageFile) { + formDataToSend.append("isimageupdateorcreate", 1); // ✅ new image uploaded + formDataToSend.append("file", imageFile); + } else { + formDataToSend.append("isimageupdateorcreate", 0); // ✅ keep old image + } console.log(formDataToSend) const response = await axios.post(`${Baseurl}/Upload-Image-To-Frappe/parent-child`, formDataToSend, { headers: {