From bfac63ee2215354643114569d2401a0037bcc95f Mon Sep 17 00:00:00 2001 From: Valimp Date: Mon, 21 Oct 2024 16:06:06 +0200 Subject: [PATCH] fix: use x-www-urlencoded instead of json --- src/components/DeleteButton.tsx | 16 ++++++++++++++-- src/components/InfoModal.tsx | 20 ++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/components/DeleteButton.tsx b/src/components/DeleteButton.tsx index 1108e12..0d0c365 100644 --- a/src/components/DeleteButton.tsx +++ b/src/components/DeleteButton.tsx @@ -2,7 +2,7 @@ import Button from '@mui/material/Button'; import DeleteIcon from '@mui/icons-material/Delete'; import CheckIcon from '@mui/icons-material/Check'; import { useState } from 'react'; -import axios from 'axios'; +import axios, { AxiosResponse } from 'axios'; interface DeleteButtonProps { barcode: string; @@ -18,8 +18,20 @@ const DeleteButton = ({ barcode, imgids }: DeleteButtonProps) => { if (!isConfirmed) { setIsConfirmed(true) } else { + const data = new URLSearchParams() + data.append('code', barcode) + data.append('imgids', imgids) + data.append('move_to_override', 'trash') try { - axios.delete(deleteUrl) + axios.post( + deleteUrl, + data, + { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + ) } catch (err) { console.error(err) } diff --git a/src/components/InfoModal.tsx b/src/components/InfoModal.tsx index e8a927d..3caeac0 100644 --- a/src/components/InfoModal.tsx +++ b/src/components/InfoModal.tsx @@ -45,12 +45,12 @@ export default function ModalInfo({barcode}: ModalInfoProps) { return `${import.meta.env.VITE_PO_IMAGE_URL}/images/products/${part1}/${part2}/${part3}/${part4}/${imageId}.${def}.jpg`; } const handleTicketInfo = () => { - axios.get(`${import.meta.env.VITE_PO_URL}/api/v2/product/${barcode}.json`).then((res) => { + axios.get(`${import.meta.env.VITE_PO_URL}/api/v2/product/${barcode}.json`).then((res) => { + console.log(res.data) const usedData: any = { name: res.data.product.product_name || null, barcode: res.data.code || null, images: {}, - selectedImages: [], brands: res.data.product.brands || null, editors_tags: res.data.product.editors_tags || null, categories: [], @@ -66,19 +66,6 @@ export default function ModalInfo({barcode}: ModalInfoProps) { } }); } - // loop through the selected images and keep only the url - const selectedImages = res.data.product.selected_images; - if (selectedImages) { - for (const key in selectedImages) { - if (selectedImages[key].thumb ) { - for (const lang in selectedImages[key].thumb) { - if (selectedImages[key].thumb[lang]) { - usedData.selectedImages.push(selectedImages[key].thumb[lang]); - } - } - } - } - } // loop through the ingredients and keep only the text const ingredients = res.data.product.ingredients; if (ingredients) { @@ -97,6 +84,7 @@ export default function ModalInfo({barcode}: ModalInfoProps) { } } } + console.log(usedData) setTicketInfo(usedData); setIsLoaded(true); }).catch((err) => { @@ -154,7 +142,7 @@ export default function ModalInfo({barcode}: ModalInfoProps) { style={{objectFit: 'contain'}} /> - + ))}