@open-mercato/core 0.6.4-develop.4339.1.fad812f76f → 0.6.4-develop.4358.1.233d5675c7

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.
Files changed (25) hide show
  1. package/dist/modules/customers/components/detail/ConfirmDealLostDialog.js +15 -10
  2. package/dist/modules/customers/components/detail/ConfirmDealLostDialog.js.map +2 -2
  3. package/dist/modules/customers/components/detail/ScheduleActivityDialog.js +2 -6
  4. package/dist/modules/customers/components/detail/ScheduleActivityDialog.js.map +2 -2
  5. package/dist/modules/sales/components/documents/AdjustmentDialog.js +10 -12
  6. package/dist/modules/sales/components/documents/AdjustmentDialog.js.map +2 -2
  7. package/dist/modules/sales/components/documents/LineItemDialog.js +10 -10
  8. package/dist/modules/sales/components/documents/LineItemDialog.js.map +2 -2
  9. package/dist/modules/sales/components/documents/PaymentDialog.js +8 -15
  10. package/dist/modules/sales/components/documents/PaymentDialog.js.map +2 -2
  11. package/dist/modules/sales/components/documents/ShipmentDialog.js +10 -14
  12. package/dist/modules/sales/components/documents/ShipmentDialog.js.map +2 -2
  13. package/dist/modules/workflows/components/EdgeEditDialog.js +3 -9
  14. package/dist/modules/workflows/components/EdgeEditDialog.js.map +2 -2
  15. package/dist/modules/workflows/components/NodeEditDialog.js +3 -9
  16. package/dist/modules/workflows/components/NodeEditDialog.js.map +2 -2
  17. package/package.json +7 -7
  18. package/src/modules/customers/components/detail/ConfirmDealLostDialog.tsx +15 -10
  19. package/src/modules/customers/components/detail/ScheduleActivityDialog.tsx +2 -6
  20. package/src/modules/sales/components/documents/AdjustmentDialog.tsx +11 -12
  21. package/src/modules/sales/components/documents/LineItemDialog.tsx +11 -10
  22. package/src/modules/sales/components/documents/PaymentDialog.tsx +9 -16
  23. package/src/modules/sales/components/documents/ShipmentDialog.tsx +10 -14
  24. package/src/modules/workflows/components/EdgeEditDialog.tsx +3 -9
  25. package/src/modules/workflows/components/NodeEditDialog.tsx +3 -9
@@ -8,6 +8,7 @@ import { Alert, AlertDescription, AlertTitle } from '@open-mercato/ui/primitives
8
8
  import { Button } from '@open-mercato/ui/primitives/button'
9
9
  import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@open-mercato/ui/primitives/dialog'
10
10
  import { Textarea } from '@open-mercato/ui/primitives/textarea'
11
+ import { useDialogKeyHandler } from '@open-mercato/ui/hooks/useDialogKeyHandler'
11
12
 
12
13
  type LossReasonOption = {
13
14
  id: string
@@ -39,6 +40,7 @@ export function ConfirmDealLostDialog({
39
40
  const [lossReasons, setLossReasons] = React.useState<LossReasonOption[]>([])
40
41
  const [reasonListOpen, setReasonListOpen] = React.useState(false)
41
42
  const [error, setError] = React.useState('')
43
+ const [isConfirming, setIsConfirming] = React.useState(false)
42
44
 
43
45
  React.useEffect(() => {
44
46
  if (!open) return
@@ -74,18 +76,21 @@ export function ConfirmDealLostDialog({
74
76
  setError(t('customers.deals.detail.lost.reasonRequired', 'Please select a loss reason'))
75
77
  return
76
78
  }
77
- await onConfirm({
78
- lossReasonId,
79
- lossNotes: lossNotes.trim() || undefined,
80
- })
79
+ setIsConfirming(true)
80
+ try {
81
+ await onConfirm({
82
+ lossReasonId,
83
+ lossNotes: lossNotes.trim() || undefined,
84
+ })
85
+ } finally {
86
+ setIsConfirming(false)
87
+ }
81
88
  }, [lossNotes, lossReasonId, onConfirm, t])
82
89
 
83
- const handleKeyDown = React.useCallback((event: React.KeyboardEvent) => {
84
- if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
85
- event.preventDefault()
86
- void handleConfirm()
87
- }
88
- }, [handleConfirm])
90
+ const handleKeyDown = useDialogKeyHandler({
91
+ onConfirm: () => void handleConfirm(),
92
+ disabled: isConfirming,
93
+ })
89
94
 
90
95
  return (
91
96
  <Dialog open={open} onOpenChange={(nextOpen) => { if (!nextOpen) onClose() }}>
@@ -13,6 +13,7 @@ import { Alert, AlertDescription, AlertTitle } from '@open-mercato/ui/primitives
13
13
  import { Button } from '@open-mercato/ui/primitives/button'
14
14
  import { IconButton } from '@open-mercato/ui/primitives/icon-button'
15
15
  import { Dialog, DialogContent, DialogTitle } from '@open-mercato/ui/primitives/dialog'
16
+ import { useDialogKeyHandler } from '@open-mercato/ui/hooks/useDialogKeyHandler'
16
17
  import { VisuallyHidden } from '@radix-ui/react-visually-hidden'
17
18
  import { PhoneNumberField, SwitchableMarkdownInput } from '@open-mercato/ui/backend/inputs'
18
19
  import { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'
@@ -444,12 +445,7 @@ export function ScheduleActivityDialog({
444
445
  }
445
446
  }, [callDirection, callOutcome, callPhoneInvalidMessage, callPhoneNumber, isDateMissing, isTimeMissing, state.activityType, state.allDay, state.date, state.description, dealId, state.duration, editData, entityId, state.guestPermissions, state.linkedEntities, state.location, onActivityCreated, onClose, state.participants, state.recurrenceCount, state.recurrenceDays, state.recurrenceEnabled, state.recurrenceEndDate, state.recurrenceEndType, state.reminderMinutes, runGuardedMutation, state.startTime, t, taskPriority, state.title, translateErrorMessage, trimmedCallPhone, trimmedDate, trimmedStartTime, state.visibility, visibleFields]) // eslint-disable-line react-hooks/exhaustive-deps
446
447
 
447
- const handleKeyDown = React.useCallback((e: React.KeyboardEvent) => {
448
- if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
449
- e.preventDefault()
450
- handleSave()
451
- }
452
- }, [handleSave])
448
+ const handleKeyDown = useDialogKeyHandler({ onConfirm: handleSave })
453
449
 
454
450
  return (
455
451
  <Dialog open={open} onOpenChange={(o) => { if (!o) void guardedClose() }}>
@@ -4,6 +4,7 @@
4
4
 
5
5
  import * as React from 'react'
6
6
  import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@open-mercato/ui/primitives/dialog'
7
+ import { useDialogKeyHandler } from '@open-mercato/ui/hooks/useDialogKeyHandler'
7
8
  import { Badge } from '@open-mercato/ui/primitives/badge'
8
9
  import { Button } from '@open-mercato/ui/primitives/button'
9
10
  import { Input } from '@open-mercato/ui/primitives/input'
@@ -716,22 +717,20 @@ export function AdjustmentDialog({
716
717
  ]
717
718
  )
718
719
 
720
+ const handleSubmitForm = React.useCallback(
721
+ () => dialogContentRef.current?.querySelector('form')?.requestSubmit(),
722
+ [],
723
+ )
724
+ const handleKeyDown = useDialogKeyHandler({
725
+ onConfirm: handleSubmitForm,
726
+ onCancel: () => onOpenChange(false),
727
+ })
728
+
719
729
  return (
720
730
  <Dialog open={open} onOpenChange={onOpenChange}>
721
731
  <DialogContent
722
732
  className="sm:max-w-5xl"
723
- onKeyDown={(event) => {
724
- if (event.key === 'Escape') {
725
- event.preventDefault()
726
- onOpenChange(false)
727
- return
728
- }
729
- if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
730
- event.preventDefault()
731
- const form = dialogContentRef.current?.querySelector('form')
732
- form?.requestSubmit()
733
- }
734
- }}
733
+ onKeyDown={handleKeyDown}
735
734
  ref={dialogContentRef}
736
735
  >
737
736
  <DialogHeader>
@@ -21,6 +21,7 @@ import {
21
21
  DialogHeader,
22
22
  DialogTitle,
23
23
  } from "@open-mercato/ui/primitives/dialog";
24
+ import { useDialogKeyHandler } from "@open-mercato/ui/hooks/useDialogKeyHandler";
24
25
  import { Button } from "@open-mercato/ui/primitives/button";
25
26
  import { Input } from "@open-mercato/ui/primitives/input";
26
27
  import {
@@ -2795,6 +2796,15 @@ export function LineItemDialog({
2795
2796
  resetForm,
2796
2797
  ]);
2797
2798
 
2799
+ const handleSubmitForm = React.useCallback(
2800
+ () => dialogContentRef.current?.querySelector("form")?.requestSubmit(),
2801
+ [],
2802
+ )
2803
+ const handleKeyDown = useDialogKeyHandler({
2804
+ onConfirm: handleSubmitForm,
2805
+ onCancel: closeDialog,
2806
+ })
2807
+
2798
2808
  return (
2799
2809
  <Dialog
2800
2810
  open={open}
@@ -2803,16 +2813,7 @@ export function LineItemDialog({
2803
2813
  <DialogContent
2804
2814
  className="sm:max-w-5xl"
2805
2815
  ref={dialogContentRef}
2806
- onKeyDown={(event) => {
2807
- if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
2808
- event.preventDefault();
2809
- dialogContentRef.current?.querySelector("form")?.requestSubmit();
2810
- }
2811
- if (event.key === "Escape") {
2812
- event.preventDefault();
2813
- closeDialog();
2814
- }
2815
- }}
2816
+ onKeyDown={handleKeyDown}
2816
2817
  >
2817
2818
  <DialogHeader>
2818
2819
  <DialogTitle>
@@ -9,6 +9,7 @@ import { collectCustomFieldValues } from '@open-mercato/ui/backend/utils/customF
9
9
  import { createCrud, updateCrud } from '@open-mercato/ui/backend/utils/crud'
10
10
  import { createCrudFormError } from '@open-mercato/ui/backend/utils/serverErrors'
11
11
  import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@open-mercato/ui/primitives/dialog'
12
+ import { useDialogKeyHandler } from '@open-mercato/ui/hooks/useDialogKeyHandler'
12
13
  import { Input } from '@open-mercato/ui/primitives/input'
13
14
  import { Spinner } from '@open-mercato/ui/primitives/spinner'
14
15
  import { E } from '#generated/entities.ids.generated'
@@ -552,29 +553,21 @@ export function PaymentDialog({
552
553
  [currencyCode, mode, onOpenChange, onSaved, orderId, organizationId, payment?.id, t, tenantId]
553
554
  )
554
555
 
555
- const handleShortcutSubmit = React.useCallback(
556
- (event: React.KeyboardEvent<HTMLDivElement>) => {
557
- if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
558
- event.preventDefault()
559
- const form = dialogContentRef.current?.querySelector('form')
560
- form?.requestSubmit()
561
- }
562
- },
563
- []
556
+ const handleSubmitForm = React.useCallback(
557
+ () => dialogContentRef.current?.querySelector('form')?.requestSubmit(),
558
+ [],
564
559
  )
560
+ const handleKeyDown = useDialogKeyHandler({
561
+ onConfirm: handleSubmitForm,
562
+ onCancel: () => onOpenChange(false),
563
+ })
565
564
 
566
565
  return (
567
566
  <Dialog open={open} onOpenChange={onOpenChange}>
568
567
  <DialogContent
569
568
  ref={dialogContentRef}
570
569
  className="sm:max-w-5xl"
571
- onKeyDown={(event) => {
572
- if (event.key === 'Escape') {
573
- event.preventDefault()
574
- onOpenChange(false)
575
- }
576
- handleShortcutSubmit(event)
577
- }}
570
+ onKeyDown={handleKeyDown}
578
571
  >
579
572
  <DialogHeader>
580
573
  <DialogTitle>
@@ -3,6 +3,7 @@
3
3
  import * as React from 'react'
4
4
  import { MapPin, Truck } from 'lucide-react'
5
5
  import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@open-mercato/ui/primitives/dialog'
6
+ import { useDialogKeyHandler } from '@open-mercato/ui/hooks/useDialogKeyHandler'
6
7
  import { Input } from '@open-mercato/ui/primitives/input'
7
8
  import { Textarea } from '@open-mercato/ui/primitives/textarea'
8
9
  import { Label } from '@open-mercato/ui/primitives/label'
@@ -1109,13 +1110,14 @@ export function ShipmentDialog({
1109
1110
  ],
1110
1111
  )
1111
1112
 
1112
- const handleShortcutSubmit = React.useCallback((event: React.KeyboardEvent<HTMLDivElement>) => {
1113
- if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
1114
- event.preventDefault()
1115
- const form = dialogContentRef.current?.querySelector('form')
1116
- form?.requestSubmit()
1117
- }
1118
- }, [])
1113
+ const handleSubmitForm = React.useCallback(
1114
+ () => dialogContentRef.current?.querySelector('form')?.requestSubmit(),
1115
+ [],
1116
+ )
1117
+ const handleKeyDown = useDialogKeyHandler({
1118
+ onConfirm: handleSubmitForm,
1119
+ onCancel: onClose,
1120
+ })
1119
1121
 
1120
1122
  const fields = React.useMemo<CrudField[]>(() => {
1121
1123
  const shippingAdjustmentLabel = t(
@@ -1523,13 +1525,7 @@ export function ShipmentDialog({
1523
1525
  <DialogContent
1524
1526
  ref={dialogContentRef}
1525
1527
  className="sm:max-w-5xl"
1526
- onKeyDown={(event) => {
1527
- if (event.key === 'Escape') {
1528
- event.preventDefault()
1529
- onClose()
1530
- }
1531
- handleShortcutSubmit(event)
1532
- }}
1528
+ onKeyDown={handleKeyDown}
1533
1529
  >
1534
1530
  <DialogHeader>
1535
1531
  <DialogTitle>
@@ -26,6 +26,7 @@ import {Plus, Trash2} from 'lucide-react'
26
26
  import {type BusinessRule, BusinessRulesSelector} from './BusinessRulesSelector'
27
27
  import {JsonBuilder} from '@open-mercato/ui/backend/JsonBuilder'
28
28
  import {useT} from '@open-mercato/shared/lib/i18n/context'
29
+ import {useDialogKeyHandler} from '@open-mercato/ui/hooks/useDialogKeyHandler'
29
30
  import {useConfirmDialog} from '@open-mercato/ui/backend/confirm-dialog'
30
31
 
31
32
  export interface EdgeEditDialogProps {
@@ -302,14 +303,7 @@ export function EdgeEditDialog({ edge, isOpen, onClose, onSave, onDelete }: Edge
302
303
  onDelete(edge.id)
303
304
  }
304
305
 
305
- const handleKeyDown = (e: React.KeyboardEvent) => {
306
- if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
307
- handleSave()
308
- }
309
- if (e.key === 'Escape') {
310
- onClose()
311
- }
312
- }
306
+ const handleKeyDown = useDialogKeyHandler({ onConfirm: handleSave, onCancel: onClose })
313
307
 
314
308
  if (!isOpen || !edge) return null
315
309
 
@@ -317,7 +311,7 @@ export function EdgeEditDialog({ edge, isOpen, onClose, onSave, onDelete }: Edge
317
311
 
318
312
  return (
319
313
  <Dialog open={isOpen} onOpenChange={onClose}>
320
- <DialogContent className="sm:max-w-4xl max-h-[90vh] overflow-y-auto">
314
+ <DialogContent className="sm:max-w-4xl max-h-[90vh] overflow-y-auto" onKeyDown={handleKeyDown}>
321
315
  <DialogHeader>
322
316
  <div className="flex items-center gap-2 mb-2">
323
317
  <DialogTitle>{t('workflows.edgeEditor.title')}</DialogTitle>
@@ -20,6 +20,7 @@ import {WorkflowDefinition, WorkflowSelector} from './WorkflowSelector'
20
20
  import {JsonBuilder} from '@open-mercato/ui/backend/JsonBuilder'
21
21
  import {StartPreConditionsEditor, type StartPreCondition} from './fields/StartPreConditionsEditor'
22
22
  import {useT} from '@open-mercato/shared/lib/i18n/context'
23
+ import {useDialogKeyHandler} from '@open-mercato/ui/hooks/useDialogKeyHandler'
23
24
  import {useConfirmDialog} from '@open-mercato/ui/backend/confirm-dialog'
24
25
  import {isFutureIsoDateString, isValidDurationString} from '../data/validators'
25
26
 
@@ -485,14 +486,7 @@ export function NodeEditDialog({ node, isOpen, onClose, onSave, onDelete }: Node
485
486
  onDelete(node.id)
486
487
  }
487
488
 
488
- const handleKeyDown = (e: React.KeyboardEvent) => {
489
- if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
490
- handleSave()
491
- }
492
- if (e.key === 'Escape') {
493
- onClose()
494
- }
495
- }
489
+ const handleKeyDown = useDialogKeyHandler({ onConfirm: handleSave, onCancel: onClose })
496
490
 
497
491
  if (!isOpen || !node) return null
498
492
 
@@ -518,7 +512,7 @@ export function NodeEditDialog({ node, isOpen, onClose, onSave, onDelete }: Node
518
512
 
519
513
  return (
520
514
  <Dialog open={isOpen} onOpenChange={onClose}>
521
- <DialogContent className="sm:max-w-2xl max-h-[90vh] overflow-y-auto">
515
+ <DialogContent className="sm:max-w-2xl max-h-[90vh] overflow-y-auto" onKeyDown={handleKeyDown}>
522
516
  <DialogHeader>
523
517
  <div className="flex items-center gap-2 mb-2">
524
518
  <DialogTitle>{t('workflows.nodeEditor.title')}</DialogTitle>