@fayz-ai/plugin-shop 0.27.0 → 0.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ProductListingTab-FEIOXECV.js +4 -0
- package/dist/{ProductListingTab-7DBLFDBH.js.map → ProductListingTab-FEIOXECV.js.map} +1 -1
- package/dist/{chunk-IECL5S7D.js → chunk-OMJ57KEX.js} +26 -13
- package/dist/chunk-OMJ57KEX.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/views/ProductListingTab.d.ts +0 -13
- package/dist/views/ProductListingTab.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/ProductListingTab-7DBLFDBH.js +0 -4
- package/dist/chunk-IECL5S7D.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"ProductListingTab-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"ProductListingTab-FEIOXECV.js"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorMessage } from './chunk-2MXOKJQO.js';
|
|
2
2
|
import { useState, useEffect } from 'react';
|
|
3
|
-
import { Skeleton,
|
|
3
|
+
import { Skeleton, Button, Badge, Switch, TreeSelect } from '@fayz-ai/ui';
|
|
4
4
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
var NO_CATEGORY = "__none__";
|
|
@@ -9,6 +9,7 @@ var STATUS_LABEL = {
|
|
|
9
9
|
draft: { label: "Rascunho", variant: "secondary" },
|
|
10
10
|
archived: { label: "Fora da loja", variant: "outline" }
|
|
11
11
|
};
|
|
12
|
+
var bySortOrder = (a, b) => a.sortOrder - b.sortOrder || a.name.localeCompare(b.name);
|
|
12
13
|
function ProductListingTab({ item, getProvider }) {
|
|
13
14
|
const catalog = item ?? {};
|
|
14
15
|
const catalogId = catalog.id;
|
|
@@ -101,16 +102,28 @@ function ProductListingTab({ item, getProvider }) {
|
|
|
101
102
|
}
|
|
102
103
|
const categoryPicker = /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
103
104
|
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-muted-foreground", children: "Categoria na loja" }),
|
|
104
|
-
/* @__PURE__ */
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
/* @__PURE__ */ jsx(
|
|
106
|
+
TreeSelect,
|
|
107
|
+
{
|
|
108
|
+
variant: "field",
|
|
109
|
+
nodes: categories,
|
|
110
|
+
getId: (c) => c.id,
|
|
111
|
+
getParentId: (c) => c.parentId,
|
|
112
|
+
getName: (c) => c.name,
|
|
113
|
+
compare: bySortOrder,
|
|
114
|
+
value: categoryId === NO_CATEGORY ? "" : categoryId,
|
|
115
|
+
onChange: (id) => {
|
|
116
|
+
const v = id || NO_CATEGORY;
|
|
117
|
+
if (listing) void changeCategory(v);
|
|
118
|
+
else setCategoryId(v);
|
|
119
|
+
},
|
|
120
|
+
placeholder: "Sem categoria",
|
|
121
|
+
allLabel: "Sem categoria",
|
|
122
|
+
searchPlaceholder: "Buscar categoria\u2026",
|
|
123
|
+
noResultsLabel: "Nenhuma categoria encontrada",
|
|
124
|
+
className: "w-full sm:w-72"
|
|
125
|
+
}
|
|
126
|
+
)
|
|
114
127
|
] });
|
|
115
128
|
if (!listing) {
|
|
116
129
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
@@ -161,5 +174,5 @@ function ProductListingTab({ item, getProvider }) {
|
|
|
161
174
|
}
|
|
162
175
|
|
|
163
176
|
export { ProductListingTab };
|
|
164
|
-
//# sourceMappingURL=chunk-
|
|
165
|
-
//# sourceMappingURL=chunk-
|
|
177
|
+
//# sourceMappingURL=chunk-OMJ57KEX.js.map
|
|
178
|
+
//# sourceMappingURL=chunk-OMJ57KEX.js.map
|
|
@@ -0,0 +1 @@
|
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,CAAA;AAAA,sBACA,GAAA;AAAA,QAAC,MAAA;AAAA,QAAA;AAAA,UACC,OAAA,EAAS,QAAQ,UAAA,KAAe,IAAA;AAAA,UAChC,QAAA,EAAU,SAAA;AAAA,UACV,eAAA,EAAiB,CAAC,CAAA,KAAM;AAAE,YAAA,KAAK,eAAe,CAAC,CAAA;AAAA,UAAE,CAAA;AAAA,UACjD,YAAA,EAAW;AAAA;AAAA;AACb,KAAA,EACF,CAAA;AAAA,IACC,KAAA,oBAAS,GAAA,CAAC,GAAA,EAAA,EAAE,SAAA,EAAU,4BAA4B,QAAA,EAAA,KAAA,EAAM;AAAA,GAAA,EAC3D,CAAA;AAEJ","file":"chunk-OMJ57KEX.js","sourcesContent":["import React, { useEffect, useState } from 'react'\nimport { Badge, Button, Skeleton, Switch, TreeSelect } from '@fayz-ai/ui'\nimport type { Category, Product, ShopProvider } from '@fayz-ai/shop'\nimport { errorMessage } from '../settings/error-message'\n\nconst NO_CATEGORY = '__none__'\n\n/** What the tab reads off the stock's product record. */\ninterface CatalogItem {\n id?: string\n name?: string\n description?: string | null\n sku?: string | null\n salePrice?: number | null\n price?: number | null\n isActive?: boolean\n}\n\nconst STATUS_LABEL: Record<string, { label: string; variant: 'success' | 'secondary' | 'outline' }> = {\n active: { label: 'À venda na loja', variant: 'success' },\n draft: { label: 'Rascunho', variant: 'secondary' },\n archived: { label: 'Fora da loja', variant: 'outline' },\n}\n\n/**\n * Loja — whether a CATALOGUE product is sold in the store, and the one thing\n * the listing owns that the record does not: its category in the store menu.\n *\n * Mounted on the product record of whichever plugin owns the catalogue (stock,\n * in the Control app), where the shop's own Produtos screen is off. Without it\n * a product created in the stock had no way into the store: the listing row\n * (`plg_shop_products`) was only ever born from the shop's screen.\n *\n * Name, price, SKU and description are NOT edited here: the database mirrors\n * them from the record both ways, and so does the status — the record's Ativo\n * switch is what takes a product out of the store and puts it back.\n */\n// The storefront's own order, then the name.\nconst bySortOrder = (a: Category, b: Category) => a.sortOrder - b.sortOrder || a.name.localeCompare(b.name)\n\nexport function ProductListingTab({ item, getProvider }: {\n item: unknown\n getProvider: () => ShopProvider\n}) {\n const catalog = (item ?? {}) as CatalogItem\n const catalogId = catalog.id\n const [listing, setListing] = useState<Product | null | undefined>(undefined)\n const [categories, setCategories] = useState<Category[]>([])\n const [categoryId, setCategoryId] = useState<string>(NO_CATEGORY)\n const [busy, setBusy] = useState(false)\n const [featuring, setFeaturing] = useState(false)\n const [error, setError] = useState<string | null>(null)\n\n useEffect(() => {\n if (!catalogId) { setListing(null); return }\n let alive = true\n setListing(undefined)\n const provider = getProvider()\n const lookup = provider.getProductByCatalogId\n ? provider.getProductByCatalogId(catalogId)\n : Promise.resolve(null)\n Promise.all([lookup, provider.listCategories().catch(() => [] as Category[])])\n .then(([found, cats]) => {\n if (!alive) return\n setListing(found)\n setCategories(cats)\n setCategoryId(found?.categoryId ?? NO_CATEGORY)\n })\n .catch((err: unknown) => { if (alive) { setListing(null); setError(errorMessage(err)) } })\n return () => { alive = false }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [catalogId])\n\n async function publish() {\n if (!catalogId || !catalog.name) return\n setBusy(true)\n setError(null)\n try {\n const created = await getProvider().createProduct({\n catalogProductId: catalogId,\n name: catalog.name,\n description: catalog.description ?? undefined,\n sku: catalog.sku ?? undefined,\n price: Number(catalog.salePrice ?? catalog.price ?? 0),\n // An inactive record goes in as a draft: listed, not sold, until the\n // record's Ativo switch is turned on.\n status: catalog.isActive === false ? 'draft' : 'active',\n categoryId: categoryId === NO_CATEGORY ? undefined : categoryId,\n })\n setListing(created)\n } catch (err) {\n setError(errorMessage(err))\n } finally {\n setBusy(false)\n }\n }\n\n async function changeCategory(next: string) {\n if (!listing) return\n const previous = categoryId\n setCategoryId(next)\n setError(null)\n try {\n const updated = await getProvider().updateProduct(listing.id, { categoryId: next === NO_CATEGORY ? null : next })\n setListing(updated)\n } catch (err) {\n setCategoryId(previous)\n setError(errorMessage(err))\n }\n }\n\n /** «Destaque no site» (shop 0136): the listing leads the storefront's\n * «Destaques», in the store's own order. Optimistic, reverted on failure. */\n async function changeFeatured(next: boolean) {\n if (!listing) return\n const previous = listing\n setListing({ ...listing, isFeatured: next })\n setFeaturing(true)\n setError(null)\n try {\n setListing(await getProvider().updateProduct(listing.id, { isFeatured: next }))\n } catch (err) {\n setListing(previous)\n setError(errorMessage(err))\n } finally {\n setFeaturing(false)\n }\n }\n\n if (listing === undefined) {\n return (\n <div className=\"space-y-3\" aria-busy=\"true\">\n <Skeleton className=\"h-5 w-48\" />\n <Skeleton className=\"h-24 w-full\" />\n </div>\n )\n }\n\n const categoryPicker = (\n <div className=\"space-y-1.5\">\n <p className=\"text-xs font-medium text-muted-foreground\">Categoria na loja</p>\n <TreeSelect\n variant=\"field\"\n nodes={categories}\n getId={(c) => c.id}\n getParentId={(c) => c.parentId}\n getName={(c) => c.name}\n compare={bySortOrder}\n value={categoryId === NO_CATEGORY ? '' : categoryId}\n onChange={(id) => { const v = id || NO_CATEGORY; if (listing) void changeCategory(v); else setCategoryId(v) }}\n placeholder=\"Sem categoria\"\n allLabel=\"Sem categoria\"\n searchPlaceholder=\"Buscar categoria…\"\n noResultsLabel=\"Nenhuma categoria encontrada\"\n className=\"w-full sm:w-72\"\n />\n </div>\n )\n\n if (!listing) {\n return (\n <div className=\"space-y-4\">\n <div>\n <h3 className=\"text-sm font-semibold\">Loja e delivery</h3>\n <p className=\"mt-0.5 text-xs text-muted-foreground\">\n Este produto ainda não está na loja. Ao colocar, ele aparece no site e no delivery com o nome, o preço e a\n descrição deste cadastro{catalog.isActive === false ? ' — como rascunho, até o produto ser ativado' : ''}.\n </p>\n </div>\n {categoryPicker}\n {error && <p className=\"text-sm text-destructive\">{error}</p>}\n <Button onClick={() => { void publish() }} disabled={busy || !catalog.name}>\n {busy ? 'Colocando…' : 'Colocar na loja'}\n </Button>\n </div>\n )\n }\n\n const status = STATUS_LABEL[listing.status] ?? { label: listing.status, variant: 'outline' as const }\n return (\n <div className=\"space-y-4\">\n <div>\n <div className=\"flex items-center gap-2\">\n <h3 className=\"text-sm font-semibold\">Loja e delivery</h3>\n <Badge variant={status.variant}>{status.label}</Badge>\n </div>\n <p className=\"mt-0.5 text-xs text-muted-foreground\">\n Nome, preço e descrição vêm deste cadastro. Para tirar o produto da loja, desative-o no cadastro; ativá-lo de\n novo o devolve à venda. Fotos ficam na aba Conteúdo.\n </p>\n </div>\n {categoryPicker}\n {/* The store that runs its site from here chooses its «Destaques» here\n too: the Cardápio star only reaches products that have a menu item. */}\n <label className=\"flex max-w-xl cursor-pointer items-start justify-between gap-4 rounded-lg border px-3 py-2.5\">\n <span className=\"min-w-0\">\n <span className=\"block text-sm\">Destaque no site</span>\n <span className=\"block text-[11px] leading-snug text-muted-foreground\">\n {listing.status === 'active'\n ? 'Aparece em «Destaques», no topo do cardápio do site, na ordem da loja.'\n : 'Fora da venda não aparece em «Destaques» — ative o produto para ele aparecer.'}\n </span>\n </span>\n <Switch\n checked={listing.isFeatured === true}\n disabled={featuring}\n onCheckedChange={(v) => { void changeFeatured(v) }}\n aria-label=\"Destaque no site\"\n />\n </label>\n {error && <p className=\"text-sm text-destructive\">{error}</p>}\n </div>\n )\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { shippingRegistryPath } from './chunk-6V2VAUWP.js';
|
|
|
2
2
|
import { ProductImagesTab } from './chunk-JYT6BTRE.js';
|
|
3
3
|
export { ProductContentTab } from './chunk-JYT6BTRE.js';
|
|
4
4
|
export { ProductMarketPricesTab } from './chunk-MFEOIJI7.js';
|
|
5
|
-
export { ProductListingTab } from './chunk-
|
|
5
|
+
export { ProductListingTab } from './chunk-OMJ57KEX.js';
|
|
6
6
|
import { shopCustomerLookup, resolveTerm, candidateMeta } from './chunk-TDV3SFXT.js';
|
|
7
7
|
import { PACKAGES_REGISTRY, SHIPPING_ZONES_REGISTRY, SHIPPING_PROFILES_REGISTRY, packageMeasureLabel, packagesRegistry } from './chunk-STZYH32S.js';
|
|
8
8
|
import { resolve, invalidateProductLists, listProductsDetailed, applyQuery, listProductsCached } from './chunk-YUG6XQHJ.js';
|
|
@@ -6548,7 +6548,7 @@ function shopProductMarketPricesTab(options) {
|
|
|
6548
6548
|
props: { getProvider: options.provider, settingsHref: options.settingsHref ?? "#/settings/shop-markets" }
|
|
6549
6549
|
};
|
|
6550
6550
|
}
|
|
6551
|
-
var ProductListingTabView = lazyComponent(() => import('./ProductListingTab-
|
|
6551
|
+
var ProductListingTabView = lazyComponent(() => import('./ProductListingTab-FEIOXECV.js').then((m) => m.ProductListingTab));
|
|
6552
6552
|
var ContentPage = React.lazy(() => import('./ContentPage-2PHOZSFZ.js').then((m) => ({ default: m.ContentPage })));
|
|
6553
6553
|
var StoreGeneralSettings = lazyComponent(() => import('./StoreGeneralSettings-DEZ2CMVG.js').then((m) => m.StoreGeneralSettings));
|
|
6554
6554
|
var PaymentsSettings = lazyComponent(() => import('./PaymentsSettings-5CI74TY2.js').then((m) => m.PaymentsSettings));
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ShopProvider } from '@fayz-ai/shop';
|
|
3
|
-
/**
|
|
4
|
-
* Loja — whether a CATALOGUE product is sold in the store, and the one thing
|
|
5
|
-
* the listing owns that the record does not: its category in the store menu.
|
|
6
|
-
*
|
|
7
|
-
* Mounted on the product record of whichever plugin owns the catalogue (stock,
|
|
8
|
-
* in the Control app), where the shop's own Produtos screen is off. Without it
|
|
9
|
-
* a product created in the stock had no way into the store: the listing row
|
|
10
|
-
* (`plg_shop_products`) was only ever born from the shop's screen.
|
|
11
|
-
*
|
|
12
|
-
* Name, price, SKU and description are NOT edited here: the database mirrors
|
|
13
|
-
* them from the record both ways, and so does the status — the record's Ativo
|
|
14
|
-
* switch is what takes a product out of the store and puts it back.
|
|
15
|
-
*/
|
|
16
3
|
export declare function ProductListingTab({ item, getProvider }: {
|
|
17
4
|
item: unknown;
|
|
18
5
|
getProvider: () => ShopProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductListingTab.d.ts","sourceRoot":"","sources":["../../src/views/ProductListingTab.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAqB,YAAY,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"ProductListingTab.d.ts","sourceRoot":"","sources":["../../src/views/ProductListingTab.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAqB,YAAY,EAAE,MAAM,eAAe,CAAA;AAsCpE,wBAAgB,iBAAiB,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE;IACvD,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,MAAM,YAAY,CAAA;CAChC,qBA0KA"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"status": "preview",
|
|
5
5
|
"dependencies": []
|
|
6
6
|
},
|
|
7
|
-
"version": "0.27.
|
|
7
|
+
"version": "0.27.1",
|
|
8
8
|
"description": "[experimental] Fayz SDK — plugin-shop plugin",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"sideEffects": false,
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@tanstack/react-table": "^8.20.0",
|
|
35
|
-
"@fayz-ai/admin": "^0.72.
|
|
36
|
-
"@fayz-ai/core": "^0.
|
|
37
|
-
"@fayz-ai/financial": "^0.3.
|
|
38
|
-
"@fayz-ai/inventory": "^0.3.
|
|
35
|
+
"@fayz-ai/admin": "^0.72.3",
|
|
36
|
+
"@fayz-ai/core": "^0.72.3",
|
|
37
|
+
"@fayz-ai/financial": "^0.3.1",
|
|
38
|
+
"@fayz-ai/inventory": "^0.3.2",
|
|
39
39
|
"@fayz-ai/shop": "^0.72.0",
|
|
40
|
-
"@fayz-ai/ui": "^0.
|
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OAAA,EAAS,QAAQ,UAAA,KAAe,IAAA;AAAA,UAChC,QAAA,EAAU,SAAA;AAAA,UACV,eAAA,EAAiB,CAAC,CAAA,KAAM;AAAE,YAAA,KAAK,eAAe,CAAC,CAAA;AAAA,UAAE,CAAA;AAAA,UACjD,YAAA,EAAW;AAAA;AAAA;AACb,KAAA,EACF,CAAA;AAAA,IACC,KAAA,oBAAS,GAAA,CAAC,GAAA,EAAA,EAAE,SAAA,EAAU,4BAA4B,QAAA,EAAA,KAAA,EAAM;AAAA,GAAA,EAC3D,CAAA;AAEJ","file":"chunk-IECL5S7D.js","sourcesContent":["import React, { useEffect, useState } from 'react'\nimport { Badge, Button, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Skeleton, Switch } from '@fayz-ai/ui'\nimport type { Category, Product, ShopProvider } from '@fayz-ai/shop'\nimport { errorMessage } from '../settings/error-message'\n\nconst NO_CATEGORY = '__none__'\n\n/** What the tab reads off the stock's product record. */\ninterface CatalogItem {\n id?: string\n name?: string\n description?: string | null\n sku?: string | null\n salePrice?: number | null\n price?: number | null\n isActive?: boolean\n}\n\nconst STATUS_LABEL: Record<string, { label: string; variant: 'success' | 'secondary' | 'outline' }> = {\n active: { label: 'À venda na loja', variant: 'success' },\n draft: { label: 'Rascunho', variant: 'secondary' },\n archived: { label: 'Fora da loja', variant: 'outline' },\n}\n\n/**\n * Loja — whether a CATALOGUE product is sold in the store, and the one thing\n * the listing owns that the record does not: its category in the store menu.\n *\n * Mounted on the product record of whichever plugin owns the catalogue (stock,\n * in the Control app), where the shop's own Produtos screen is off. Without it\n * a product created in the stock had no way into the store: the listing row\n * (`plg_shop_products`) was only ever born from the shop's screen.\n *\n * Name, price, SKU and description are NOT edited here: the database mirrors\n * them from the record both ways, and so does the status — the record's Ativo\n * switch is what takes a product out of the store and puts it back.\n */\nexport function ProductListingTab({ item, getProvider }: {\n item: unknown\n getProvider: () => ShopProvider\n}) {\n const catalog = (item ?? {}) as CatalogItem\n const catalogId = catalog.id\n const [listing, setListing] = useState<Product | null | undefined>(undefined)\n const [categories, setCategories] = useState<Category[]>([])\n const [categoryId, setCategoryId] = useState<string>(NO_CATEGORY)\n const [busy, setBusy] = useState(false)\n const [featuring, setFeaturing] = useState(false)\n const [error, setError] = useState<string | null>(null)\n\n useEffect(() => {\n if (!catalogId) { setListing(null); return }\n let alive = true\n setListing(undefined)\n const provider = getProvider()\n const lookup = provider.getProductByCatalogId\n ? provider.getProductByCatalogId(catalogId)\n : Promise.resolve(null)\n Promise.all([lookup, provider.listCategories().catch(() => [] as Category[])])\n .then(([found, cats]) => {\n if (!alive) return\n setListing(found)\n setCategories(cats)\n setCategoryId(found?.categoryId ?? NO_CATEGORY)\n })\n .catch((err: unknown) => { if (alive) { setListing(null); setError(errorMessage(err)) } })\n return () => { alive = false }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [catalogId])\n\n async function publish() {\n if (!catalogId || !catalog.name) return\n setBusy(true)\n setError(null)\n try {\n const created = await getProvider().createProduct({\n catalogProductId: catalogId,\n name: catalog.name,\n description: catalog.description ?? undefined,\n sku: catalog.sku ?? undefined,\n price: Number(catalog.salePrice ?? catalog.price ?? 0),\n // An inactive record goes in as a draft: listed, not sold, until the\n // record's Ativo switch is turned on.\n status: catalog.isActive === false ? 'draft' : 'active',\n categoryId: categoryId === NO_CATEGORY ? undefined : categoryId,\n })\n setListing(created)\n } catch (err) {\n setError(errorMessage(err))\n } finally {\n setBusy(false)\n }\n }\n\n async function changeCategory(next: string) {\n if (!listing) return\n const previous = categoryId\n setCategoryId(next)\n setError(null)\n try {\n const updated = await getProvider().updateProduct(listing.id, { categoryId: next === NO_CATEGORY ? null : next })\n setListing(updated)\n } catch (err) {\n setCategoryId(previous)\n setError(errorMessage(err))\n }\n }\n\n /** «Destaque no site» (shop 0136): the listing leads the storefront's\n * «Destaques», in the store's own order. Optimistic, reverted on failure. */\n async function changeFeatured(next: boolean) {\n if (!listing) return\n const previous = listing\n setListing({ ...listing, isFeatured: next })\n setFeaturing(true)\n setError(null)\n try {\n setListing(await getProvider().updateProduct(listing.id, { isFeatured: next }))\n } catch (err) {\n setListing(previous)\n setError(errorMessage(err))\n } finally {\n setFeaturing(false)\n }\n }\n\n if (listing === undefined) {\n return (\n <div className=\"space-y-3\" aria-busy=\"true\">\n <Skeleton className=\"h-5 w-48\" />\n <Skeleton className=\"h-24 w-full\" />\n </div>\n )\n }\n\n const categoryPicker = (\n <div className=\"space-y-1.5\">\n <p className=\"text-xs font-medium text-muted-foreground\">Categoria na loja</p>\n <Select value={categoryId} onValueChange={(v) => { if (listing) void changeCategory(v); else setCategoryId(v) }}>\n <SelectTrigger className=\"w-72\"><SelectValue placeholder=\"Sem categoria\" /></SelectTrigger>\n <SelectContent>\n <SelectItem value={NO_CATEGORY}>Sem categoria</SelectItem>\n {categories.map((c) => <SelectItem key={c.id} value={c.id}>{c.name}</SelectItem>)}\n </SelectContent>\n </Select>\n </div>\n )\n\n if (!listing) {\n return (\n <div className=\"space-y-4\">\n <div>\n <h3 className=\"text-sm font-semibold\">Loja e delivery</h3>\n <p className=\"mt-0.5 text-xs text-muted-foreground\">\n Este produto ainda não está na loja. Ao colocar, ele aparece no site e no delivery com o nome, o preço e a\n descrição deste cadastro{catalog.isActive === false ? ' — como rascunho, até o produto ser ativado' : ''}.\n </p>\n </div>\n {categoryPicker}\n {error && <p className=\"text-sm text-destructive\">{error}</p>}\n <Button onClick={() => { void publish() }} disabled={busy || !catalog.name}>\n {busy ? 'Colocando…' : 'Colocar na loja'}\n </Button>\n </div>\n )\n }\n\n const status = STATUS_LABEL[listing.status] ?? { label: listing.status, variant: 'outline' as const }\n return (\n <div className=\"space-y-4\">\n <div>\n <div className=\"flex items-center gap-2\">\n <h3 className=\"text-sm font-semibold\">Loja e delivery</h3>\n <Badge variant={status.variant}>{status.label}</Badge>\n </div>\n <p className=\"mt-0.5 text-xs text-muted-foreground\">\n Nome, preço e descrição vêm deste cadastro. Para tirar o produto da loja, desative-o no cadastro; ativá-lo de\n novo o devolve à venda. Fotos ficam na aba Conteúdo.\n </p>\n </div>\n {categoryPicker}\n {/* The store that runs its site from here chooses its «Destaques» here\n too: the Cardápio star only reaches products that have a menu item. */}\n <label className=\"flex max-w-xl cursor-pointer items-start justify-between gap-4 rounded-lg border px-3 py-2.5\">\n <span className=\"min-w-0\">\n <span className=\"block text-sm\">Destaque no site</span>\n <span className=\"block text-[11px] leading-snug text-muted-foreground\">\n {listing.status === 'active'\n ? 'Aparece em «Destaques», no topo do cardápio do site, na ordem da loja.'\n : 'Fora da venda não aparece em «Destaques» — ative o produto para ele aparecer.'}\n </span>\n </span>\n <Switch\n checked={listing.isFeatured === true}\n disabled={featuring}\n onCheckedChange={(v) => { void changeFeatured(v) }}\n aria-label=\"Destaque no site\"\n />\n </label>\n {error && <p className=\"text-sm text-destructive\">{error}</p>}\n </div>\n )\n}\n"]}
|