chore: update space admin

This commit is contained in:
2026-03-04 00:16:31 +01:00
parent 0073f80a48
commit 06cfbae4e1
2 changed files with 50 additions and 3 deletions
+1
View File
@@ -95,6 +95,7 @@ export interface Product {
description?: string; description?: string;
category: string; category: string;
stock: number; stock: number;
unit: string;
prices?: Array<{ quantity: number; price: number }>; prices?: Array<{ quantity: number; price: number }>;
media?: Array<{ url: string; type: string; id?: number; created_at?: string }>; media?: Array<{ url: string; type: string; id?: number; created_at?: string }>;
created_at?: string; created_at?: string;
@@ -60,11 +60,22 @@ const CATEGORIES = [
{ value: "gros&semi", label: "Gros & Semi" }, { value: "gros&semi", label: "Gros & Semi" },
]; ];
const UNITS = [
{ value: "u", label: "u" },
{ value: "kg", label: "kg" },
{ value: "g", label: "g" },
{ value: "bag", label: "bag" },
{ value: "l", label: "l" },
{ value: "cl", label: "cl" },
{ value: "pcs", label: "pcs" },
];
interface FormState { interface FormState {
name: string; name: string;
category: string; category: string;
description: string; description: string;
stock: string; stock: string;
unit: string;
prices: PriceRow[]; prices: PriceRow[];
} }
@@ -73,6 +84,7 @@ const emptyForm = (): FormState => ({
category: "weed&hash", category: "weed&hash",
description: "", description: "",
stock: "", stock: "",
unit: "u",
prices: [{ quantity: "1", price: "" }], prices: [{ quantity: "1", price: "" }],
}); });
@@ -142,6 +154,7 @@ export default function ProductsScreen() {
category: product.category, category: product.category,
description: product.description || "", description: product.description || "",
stock: product.stock.toString(), stock: product.stock.toString(),
unit: product.unit || "u",
prices: prices:
product.prices && product.prices.length > 0 product.prices && product.prices.length > 0
? product.prices.map((p) => ({ ? product.prices.map((p) => ({
@@ -299,6 +312,7 @@ export default function ProductsScreen() {
category: form.category, category: form.category,
description: form.description.trim(), description: form.description.trim(),
stock: parseFloat(form.stock), stock: parseFloat(form.stock),
unit: form.unit,
prices, prices,
}); });
productId = editingProduct.id; productId = editingProduct.id;
@@ -309,6 +323,7 @@ export default function ProductsScreen() {
fd.append("category", form.category); fd.append("category", form.category);
fd.append("description", form.description.trim()); fd.append("description", form.description.trim());
fd.append("stock", form.stock); fd.append("stock", form.stock);
fd.append("unit", form.unit);
// ✅ FIX PRINCIPAL : Envoyer les prix au format que Go attend // ✅ FIX PRINCIPAL : Envoyer les prix au format que Go attend
// Backend attend : prices[0][quantity], prices[0][price], etc. // Backend attend : prices[0][quantity], prices[0][price], etc.
@@ -773,11 +788,11 @@ export default function ProductsScreen() {
)} )}
</View> </View>
)} )}
<Text style={styles.info}>Stock: {item.stock}g</Text> <Text style={styles.info}>Stock: {item.stock} {item.unit || "u"}</Text>
{item.prices && item.prices.length > 0 && ( {item.prices && item.prices.length > 0 && (
<Text style={styles.info}> <Text style={styles.info}>
{item.prices {item.prices
.map((p) => `${p.quantity}g = ${p.price}`) .map((p) => `${p.quantity}${item.unit || "u"} = ${p.price}`)
.join(" | ")} .join(" | ")}
</Text> </Text>
)} )}
@@ -925,7 +940,7 @@ export default function ProductsScreen() {
/> />
{/* Stock */} {/* Stock */}
<Text style={styles.label}>Stock (grammes) *</Text> <Text style={styles.label}>Stock *</Text>
<RNTextInput <RNTextInput
style={styles.input} style={styles.input}
value={form.stock} value={form.stock}
@@ -937,6 +952,37 @@ export default function ProductsScreen() {
keyboardType="numeric" keyboardType="numeric"
/> />
{/* Unité de mesure */}
<Text style={styles.label}>Unité de mesure *</Text>
<View style={styles.catRow}>
{UNITS.map((u) => (
<TouchableOpacity
key={u.value}
style={[
styles.catBtn,
form.unit === u.value &&
styles.catBtnActive,
]}
onPress={() =>
setForm((f) => ({
...f,
unit: u.value,
}))
}
>
<Text
style={[
styles.catBtnText,
form.unit === u.value &&
styles.catBtnTextActive,
]}
>
{u.label}
</Text>
</TouchableOpacity>
))}
</View>
{/* Prix */} {/* Prix */}
<View style={styles.sectionHeader}> <View style={styles.sectionHeader}>
<Text style={styles.label}>Tarifs *</Text> <Text style={styles.label}>Tarifs *</Text>