@fayz-ai/pos 0.22.4 → 0.23.0

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { haptic, createKeymap, directionOf, moveFocus } from '@fayz-ai/core/interaction';
2
2
  export { comboOf, createKeymap, haptic, setHapticsEnabled } from '@fayz-ai/core/interaction';
3
3
  import { forwardRef, memo, useState, useRef, useCallback, useEffect, useMemo, useReducer, Fragment as Fragment$1 } from 'react';
4
- import { UserPlus, X, Check, Phone, User, Receipt, RotateCcw, FileCheck, FileWarning, ChevronDown, Pencil, ChevronLeft, ChevronRight, Plus, ChevronUp, ChefHat, AlertTriangle, Printer, Percent, QrCode, CreditCard, Banknote, Trash2, Clock, Minus, Bike, PackageCheck, CheckCheck, Package, MapPin, ShieldCheck, Keyboard, CalendarClock, Users, UserRound, Search, Utensils, BellRing, UserX, UserCheck, Delete, UtensilsCrossed, Info, ClipboardList, LayoutGrid, ShoppingBag, ConciergeBell, Map as Map$1, Settings2, Square, Circle, PenLine, MoreHorizontal, Store, Tag, Star, Ticket, Ban, ArrowLeftRight, Gift, UserMinus, CheckCircle2, Crosshair, Unlink, MousePointerClick, PencilRuler, MapPinOff, Eye, EyeOff, Undo2, TriangleAlert, ArrowRight, Pizza, Wheat, Sandwich, IceCreamCone, CakeSlice, Coffee, Croissant, CupSoda, Salad, Beef, Wine, GlassWater, Soup, Fish, Wrench, CalendarCheck } from 'lucide-react';
4
+ import { UserPlus, X, Check, Phone, User, Receipt, RotateCcw, FileCheck, FileWarning, ChevronDown, Pencil, ChevronLeft, ChevronRight, Plus, ChevronUp, ChefHat, AlertTriangle, Printer, Percent, QrCode, CreditCard, Banknote, Trash2, Clock, Minus, Bike, PackageCheck, CheckCheck, Package, MapPin, ShieldCheck, Keyboard, CalendarClock, Users, UserRound, Search, Utensils, BellRing, UserX, UserCheck, Delete, UtensilsCrossed, Info, ClipboardList, LayoutGrid, ShoppingBag, ConciergeBell, Map as Map$1, Settings2, Square, Circle, PenLine, MoreHorizontal, Store, Tag, Star, Ticket, Ban, Loader2, ArrowLeftRight, Gift, UserMinus, CheckCircle2, Crosshair, Unlink, MousePointerClick, PencilRuler, MapPinOff, Eye, EyeOff, Undo2, TriangleAlert, ArrowRight, Pizza, Wheat, Sandwich, IceCreamCone, CakeSlice, Coffee, Croissant, CupSoda, Salad, Beef, Wine, GlassWater, Soup, Fish, Wrench, CalendarCheck } from 'lucide-react';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
6
  import { describeError, channelOfOrder } from '@fayz-ai/core';
7
7
  import { createPortal } from 'react-dom';
@@ -7490,6 +7490,8 @@ function PosScreen({
7490
7490
  onWaitlistLookupPhone,
7491
7491
  onReservationArrived,
7492
7492
  connection = "online",
7493
+ initialMenuId,
7494
+ onMenuChange,
7493
7495
  operatorId,
7494
7496
  onAction,
7495
7497
  onOpenPosition,
@@ -7565,7 +7567,12 @@ function PosScreen({
7565
7567
  }
7566
7568
  return seeded;
7567
7569
  });
7568
- const [menuId, setMenuId] = useState(config.menus[0]?.id);
7570
+ const [menuId, setMenuId] = useState(() => config.menus.some((m) => m.id === initialMenuId && !m.hidden) ? initialMenuId : config.menus[0]?.id);
7571
+ const onMenuChangeRef = useRef(onMenuChange);
7572
+ onMenuChangeRef.current = onMenuChange;
7573
+ useEffect(() => {
7574
+ if (menuId) onMenuChangeRef.current?.(menuId);
7575
+ }, [menuId]);
7569
7576
  useEffect(() => {
7570
7577
  if (!initialTickets) return;
7571
7578
  dispatchBook({ type: "hydrate", tickets: initialTickets, at: new Date(now).toISOString() });
@@ -10204,8 +10211,12 @@ function MarketplaceCancelSheet({ provider, orderLabel, loadReasons, onConfirm,
10204
10211
  const [failed, setFailed] = useState(false);
10205
10212
  const [chosen, setChosen] = useState(null);
10206
10213
  const [sending, setSending] = useState(false);
10214
+ const [attempt, setAttempt] = useState(0);
10215
+ const list = useRef(null);
10207
10216
  useEffect(() => {
10208
10217
  let alive = true;
10218
+ setFailed(false);
10219
+ setReasons(null);
10209
10220
  loadReasons().then((r) => {
10210
10221
  if (alive) setReasons(r);
10211
10222
  }).catch(() => {
@@ -10214,53 +10225,76 @@ function MarketplaceCancelSheet({ provider, orderLabel, loadReasons, onConfirm,
10214
10225
  return () => {
10215
10226
  alive = false;
10216
10227
  };
10217
- }, [loadReasons]);
10228
+ }, [loadReasons, attempt]);
10218
10229
  const reason = reasons?.find((r) => r.code === chosen);
10230
+ const onKey = (e) => {
10231
+ if (!reasons?.length || !["ArrowDown", "ArrowUp", "ArrowRight", "ArrowLeft"].includes(e.key)) return;
10232
+ e.preventDefault();
10233
+ const at = Math.max(0, reasons.findIndex((r) => r.code === chosen));
10234
+ const step = e.key === "ArrowDown" || e.key === "ArrowRight" ? 1 : -1;
10235
+ const next = reasons[(at + step + reasons.length) % reasons.length];
10236
+ setChosen(next.code);
10237
+ list.current?.querySelector(`[data-code="${CSS.escape(next.code)}"]`)?.focus();
10238
+ };
10219
10239
  return /* @__PURE__ */ jsxs(PosSheet, { label: "Cancelar pedido", onDismiss: onCancel, children: [
10220
10240
  /* @__PURE__ */ jsxs("div", { className: "pos-sheet__head", children: [
10221
- /* @__PURE__ */ jsxs("h2", { className: "pos-sheet__title", children: [
10222
- /* @__PURE__ */ jsx(Ban, { size: 18, strokeWidth: 2.2, "aria-hidden": true }),
10223
- " Cancelar ",
10224
- orderLabel
10241
+ /* @__PURE__ */ jsxs("div", { className: "pos-mcs__headtext", children: [
10242
+ /* @__PURE__ */ jsxs("h2", { className: "pos-sheet__title", children: [
10243
+ /* @__PURE__ */ jsx(Ban, { size: 18, strokeWidth: 2.2, "aria-hidden": true }),
10244
+ " Cancelar ",
10245
+ orderLabel
10246
+ ] }),
10247
+ /* @__PURE__ */ jsxs("p", { className: "pos-sheet__sub", children: [
10248
+ "O ",
10249
+ provider,
10250
+ " decide o cancelamento. Escolha um dos motivos que ele aceita para este pedido."
10251
+ ] })
10225
10252
  ] }),
10226
10253
  /* @__PURE__ */ jsx(PosButton, { className: "pos-sheet__x", onClick: onCancel, "aria-label": "Fechar", children: /* @__PURE__ */ jsx(X, { size: 20 }) })
10227
10254
  ] }),
10228
- /* @__PURE__ */ jsxs("p", { className: "pos-sheet__sub", children: [
10229
- "O ",
10230
- provider,
10231
- " decide o cancelamento. Escolha um dos motivos que ele aceita para este pedido."
10232
- ] }),
10233
- /* @__PURE__ */ jsx("div", { className: "pos-sheet__body", role: "radiogroup", "aria-label": `Motivos do ${provider}`, children: failed ? /* @__PURE__ */ jsxs("p", { className: "pos-empty__t", role: "alert", children: [
10234
- "N\xE3o foi poss\xEDvel buscar os motivos no ",
10235
- provider,
10236
- ". Tente de novo."
10237
- ] }) : reasons === null ? /* @__PURE__ */ jsxs("p", { className: "pos-empty__h", children: [
10238
- "Buscando os motivos no ",
10255
+ /* @__PURE__ */ jsx("div", { className: "pos-sheet__body pos-mcs__body", children: failed ? /* @__PURE__ */ jsxs("div", { className: "pos-mcs__state", role: "alert", children: [
10256
+ /* @__PURE__ */ jsxs("p", { children: [
10257
+ "N\xE3o foi poss\xEDvel buscar os motivos no ",
10258
+ provider,
10259
+ "."
10260
+ ] }),
10261
+ /* @__PURE__ */ jsx(PosButton, { className: "pos-mcs__btn", onClick: () => setAttempt((n) => n + 1), children: "Tentar de novo" })
10262
+ ] }) : reasons === null ? /* @__PURE__ */ jsxs("div", { className: "pos-mcs__state", "aria-live": "polite", children: [
10263
+ /* @__PURE__ */ jsx(Loader2, { size: 18, className: "pos-mcs__spin", "aria-hidden": true }),
10264
+ " Buscando os motivos no ",
10239
10265
  provider,
10240
10266
  "\u2026"
10241
- ] }) : reasons.length === 0 ? /* @__PURE__ */ jsxs("p", { className: "pos-empty__t", children: [
10267
+ ] }) : reasons.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "pos-mcs__state", children: [
10242
10268
  "O ",
10243
10269
  provider,
10244
10270
  " n\xE3o aceita cancelar este pedido agora."
10245
- ] }) : reasons.map((r) => /* @__PURE__ */ jsx(
10246
- PosButton,
10247
- {
10248
- role: "radio",
10249
- "aria-checked": chosen === r.code,
10250
- className: `pos-btn pos-btn--ghost${chosen === r.code ? " is-active" : ""}`,
10251
- style: { width: "100%", justifyContent: "flex-start", marginBottom: "var(--pos-1x)" },
10252
- onClick: () => setChosen(r.code),
10253
- children: r.description
10254
- },
10255
- r.code
10256
- )) }),
10257
- /* @__PURE__ */ jsxs("div", { className: "pos-sheet__foot", children: [
10258
- /* @__PURE__ */ jsx(PosButton, { className: "pos-btn pos-btn--ghost", onClick: onCancel, children: "Voltar" }),
10259
- /* @__PURE__ */ jsx(
10271
+ ] }) : /* @__PURE__ */ jsx("div", { ref: list, className: "pos-mcs__list", role: "radiogroup", "aria-label": `Motivos do ${provider}`, onKeyDown: onKey, children: reasons.map((r, i) => {
10272
+ const on = chosen === r.code;
10273
+ return /* @__PURE__ */ jsxs(
10260
10274
  PosButton,
10261
10275
  {
10262
- className: "pos-btn",
10276
+ "data-code": r.code,
10277
+ role: "radio",
10278
+ "aria-checked": on,
10279
+ tabIndex: on || !chosen && i === 0 ? 0 : -1,
10280
+ className: `pos-mcs__opt${on ? " is-on" : ""}`,
10281
+ onClick: () => setChosen(r.code),
10282
+ children: [
10283
+ /* @__PURE__ */ jsx("span", { className: "pos-mcs__dot", "aria-hidden": true }),
10284
+ /* @__PURE__ */ jsx("span", { children: r.description })
10285
+ ]
10286
+ },
10287
+ r.code
10288
+ );
10289
+ }) }) }),
10290
+ /* @__PURE__ */ jsxs("div", { className: "pos-mcs__foot", children: [
10291
+ /* @__PURE__ */ jsx(PosButton, { className: "pos-mcs__btn", onClick: onCancel, disabled: sending, children: "Voltar" }),
10292
+ /* @__PURE__ */ jsxs(
10293
+ PosButton,
10294
+ {
10295
+ className: "pos-mcs__btn pos-mcs__btn--danger",
10263
10296
  disabled: !reason || sending,
10297
+ "aria-busy": sending,
10264
10298
  onClick: async () => {
10265
10299
  if (!reason) return;
10266
10300
  setSending(true);
@@ -10270,7 +10304,10 @@ function MarketplaceCancelSheet({ provider, orderLabel, loadReasons, onConfirm,
10270
10304
  setSending(false);
10271
10305
  }
10272
10306
  },
10273
- children: sending ? "Enviando\u2026" : `Pedir cancelamento ao ${provider}`
10307
+ children: [
10308
+ sending && /* @__PURE__ */ jsx(Loader2, { size: 16, className: "pos-mcs__spin", "aria-hidden": true }),
10309
+ sending ? "Enviando\u2026" : `Pedir cancelamento ao ${provider}`
10310
+ ]
10274
10311
  }
10275
10312
  )
10276
10313
  ] })