chore: fix create product
This commit is contained in:
@@ -260,6 +260,8 @@ export default function ProductsScreen() {
|
||||
// --------------------------------------------------
|
||||
// Submit
|
||||
// --------------------------------------------------
|
||||
// Dans ProductsScreen.tsx, remplace le bloc handleSubmit par celui-ci :
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const err = validate();
|
||||
if (err) {
|
||||
@@ -301,17 +303,23 @@ export default function ProductsScreen() {
|
||||
});
|
||||
productId = editingProduct.id;
|
||||
} else {
|
||||
// Create product
|
||||
// ✅ FIX : Création avec FormData au bon format pour le backend Go
|
||||
const fd = new FormData();
|
||||
fd.append("name", form.name.trim());
|
||||
fd.append("category", form.category);
|
||||
fd.append("description", form.description.trim());
|
||||
fd.append("stock", form.stock);
|
||||
fd.append("prices", JSON.stringify(prices));
|
||||
|
||||
// Attach pending media directly to creation FormData
|
||||
pendingMedia.forEach((m, i) => {
|
||||
fd.append("files", {
|
||||
// ✅ FIX PRINCIPAL : Envoyer les prix au format que Go attend
|
||||
// Backend attend : prices[0][quantity], prices[0][price], etc.
|
||||
prices.forEach((p, i) => {
|
||||
fd.append(`prices[${i}][quantity]`, String(p.quantity));
|
||||
fd.append(`prices[${i}][price]`, String(p.price));
|
||||
});
|
||||
|
||||
// Attacher les médias en attente
|
||||
pendingMedia.forEach((m) => {
|
||||
fd.append("media", {
|
||||
uri: m.uri,
|
||||
name: m.fileName,
|
||||
type: m.mimeType,
|
||||
@@ -322,7 +330,7 @@ export default function ProductsScreen() {
|
||||
productId = createRes.data?.id;
|
||||
}
|
||||
|
||||
// 3) Upload new media for existing product edits
|
||||
// 3) Upload new media pour les produits existants (mode edit)
|
||||
if (editingProduct && pendingMedia.length > 0) {
|
||||
setUploadingMedia(true);
|
||||
for (const m of pendingMedia) {
|
||||
@@ -354,7 +362,6 @@ export default function ProductsScreen() {
|
||||
setUploadingMedia(false);
|
||||
}
|
||||
};
|
||||
|
||||
// --------------------------------------------------
|
||||
// Delete product
|
||||
// --------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user