Skip to content

Commit

Permalink
fix: use x-www-urlencoded instead of json
Browse files Browse the repository at this point in the history
  • Loading branch information
Valimp committed Oct 21, 2024
1 parent 853a2fc commit bfac63e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
16 changes: 14 additions & 2 deletions src/components/DeleteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
}
Expand Down
20 changes: 4 additions & 16 deletions src/components/InfoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -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) {
Expand All @@ -97,6 +84,7 @@ export default function ModalInfo({barcode}: ModalInfoProps) {
}
}
}
console.log(usedData)
setTicketInfo(usedData);
setIsLoaded(true);
}).catch((err) => {
Expand Down Expand Up @@ -154,7 +142,7 @@ export default function ModalInfo({barcode}: ModalInfoProps) {
style={{objectFit: 'contain'}}
/>

<DeleteButton barcode={ticketInfo.barcode} imgids={ticketInfo.image_id} />
<DeleteButton barcode={ticketInfo.barcode} imgids={ticketInfo.key} />

</Grid>
))}
Expand Down

0 comments on commit bfac63e

Please sign in to comment.