feat(F-081): completed feature
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
'use client';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { productsApi, inventoryApi, pricingApi } from '@/lib/api-client';
|
||||
import type { ProductVariant, VariantPrice, StockAvailability } from '@/types';
|
||||
|
||||
@@ -20,6 +20,18 @@ function formatCents(cents: number): string {
|
||||
return `€${(cents / 100).toFixed(2)}`;
|
||||
}
|
||||
|
||||
function centsToEur(cents: number): string {
|
||||
return (cents / 100).toFixed(2);
|
||||
}
|
||||
|
||||
function eurToCents(input: string): number {
|
||||
if (!input) return 0;
|
||||
const normalized = String(input).replace(',', '.');
|
||||
const val = parseFloat(normalized);
|
||||
if (isNaN(val)) return 0;
|
||||
return Math.round(val * 100);
|
||||
}
|
||||
|
||||
function StockStatusBadge({ available, quantity }: { available: boolean; quantity: number }) {
|
||||
if (!available || quantity === 0) {
|
||||
return (
|
||||
@@ -129,7 +141,7 @@ export function InventorySection({ productId }: InventorySectionProps) {
|
||||
...current,
|
||||
price,
|
||||
loadingPrice: false,
|
||||
priceValue: String(price.netUnitAmountCents),
|
||||
priceValue: centsToEur(price.netUnitAmountCents),
|
||||
vatRate: price.vatRate,
|
||||
},
|
||||
};
|
||||
@@ -174,7 +186,7 @@ export function InventorySection({ productId }: InventorySectionProps) {
|
||||
[variantId]: {
|
||||
...r,
|
||||
editingPrice: false,
|
||||
priceValue: String(r.price?.netUnitAmountCents ?? 0),
|
||||
priceValue: centsToEur(r.price?.netUnitAmountCents ?? 0),
|
||||
vatRate: r.price?.vatRate ?? 'general',
|
||||
},
|
||||
}));
|
||||
@@ -210,8 +222,8 @@ export function InventorySection({ productId }: InventorySectionProps) {
|
||||
|
||||
const savePrice = async (variantId: string) => {
|
||||
const r = rows[variantId];
|
||||
const cents = parseInt(r.priceValue, 10);
|
||||
if (isNaN(cents) || cents < 0) return;
|
||||
const cents = eurToCents(r.priceValue);
|
||||
if (cents < 0) return;
|
||||
setSavingVariant(variantId);
|
||||
setSaveMsg((prev) => ({ ...prev, [variantId]: '' }));
|
||||
try {
|
||||
@@ -222,6 +234,7 @@ export function InventorySection({ productId }: InventorySectionProps) {
|
||||
...prev[variantId],
|
||||
price: result,
|
||||
editingPrice: false,
|
||||
priceValue: centsToEur(result.netUnitAmountCents),
|
||||
},
|
||||
}));
|
||||
setSaveMsg((prev) => ({ ...prev, [variantId]: '✓ Guardado' }));
|
||||
@@ -284,6 +297,7 @@ export function InventorySection({ productId }: InventorySectionProps) {
|
||||
const grossPrice = r.price
|
||||
? (r.price.netUnitAmountCents * (r.price.vatRate === 'super-reduced' ? 1.04 : r.price.vatRate === 'general' ? 1.21 : 1.1)) / 100
|
||||
: null;
|
||||
void grossPrice;
|
||||
|
||||
return (
|
||||
<tr key={variant.id} className="hover:bg-gray-50/50 transition-colors">
|
||||
@@ -301,8 +315,8 @@ export function InventorySection({ productId }: InventorySectionProps) {
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-gray-400">€</span>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
value={r.priceValue}
|
||||
onChange={(e) =>
|
||||
setRows((prev) => ({
|
||||
|
||||
Reference in New Issue
Block a user