Route SKU actions to focused editors

This commit is contained in:
Cauê Faleiros
2026-07-14 13:24:25 -03:00
parent bc05fb4504
commit 63efb47e77
4 changed files with 116 additions and 43 deletions

View File

@@ -146,7 +146,7 @@ const Registrations = () => {
const sku = (searchParams.get('sku') || '').trim();
if (!sku && !(requestedTab === 'products' || requestedTab === 'categories' || requestedTab === 'references')) return;
const prefillKey = `${sku}|${searchParams.get('name') || ''}|${catalog.products.length}`;
const prefillKey = `${requestedTab || ''}|${sku}|${searchParams.get('name') || ''}|${searchParams.get('color') || ''}|${catalog.products.length}`;
if (appliedSkuPrefillRef.current === prefillKey) return;
appliedSkuPrefillRef.current = prefillKey;
@@ -158,10 +158,22 @@ const Registrations = () => {
if (!sku) return;
const existingProduct = catalog.products.find(product => product.sku.toLowerCase() === sku.toLowerCase());
setActiveTab('products');
setProductFilter('all');
setStatus('idle');
if (requestedTab === 'references' && existingProduct) {
setActiveTab('references');
setReferenceForm(current => ({
...current,
productId: String(existingProduct.id),
color: searchParams.get('color') || existingProduct.color || current.color
}));
setFeedback(`Criando referência de consumo para SKU ${existingProduct.sku}.`);
return;
}
setActiveTab('products');
if (existingProduct) {
setProductForm({
type: existingProduct.type,
@@ -189,7 +201,11 @@ const Registrations = () => {
color: searchParams.get('color') || '',
sizes: requestedSize ? [requestedSize] : defaultProductForm.sizes
});
setFeedback(`Novo cadastro para SKU ${sku}.`);
setFeedback(
requestedTab === 'references'
? `Cadastre o SKU ${sku} antes de criar a referência de consumo.`
: `Novo cadastro para SKU ${sku}.`
);
});
}, [catalog.products, searchParams]);