@feedmepos/mf-order-setting 0.0.102 → 0.0.103

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 (139) hide show
  1. package/dist/{DisplaySystemView-jnt6letY.js → DisplaySystemView-BBiZqcWq.js} +1497 -1468
  2. package/dist/{FoodCourtInvitationsView-DoynqFWB.js → FoodCourtInvitationsView-DwOkVs9m.js} +4 -4
  3. package/dist/{FoodCourtOrderSettingsView-DYZLhTHy.js → FoodCourtOrderSettingsView-C9Ag5Bsg.js} +1 -1
  4. package/dist/FoodCourtOrdersView-y4EwK3sn.js +1173 -0
  5. package/dist/{FoodCourtStallsView-CRMTt5BB.js → FoodCourtStallsView-Bi8H-yR7.js} +2 -2
  6. package/dist/{FoodCourtStatusView-C-b-eI-8.js → FoodCourtStatusView-jugAzTKg.js} +1 -1
  7. package/dist/KioskDevicesView-CYiew4X5.js +4 -0
  8. package/dist/KioskDevicesView.vue_vue_type_script_setup_true_lang-BCvbeo7R.js +1497 -0
  9. package/dist/KioskSettingView-AKBiij9a.js +1124 -0
  10. package/dist/KioskView-zKB6mC8I.js +765 -0
  11. package/dist/{OrderSettingsView-BBCnekaj.js → OrderSettingsView-CoV_yX3m.js} +22064 -21635
  12. package/dist/{RestaurantSelector.vue_vue_type_script_setup_true_lang-DjoTyV6m.js → RestaurantSelector.vue_vue_type_script_setup_true_lang-KSMU_jGl.js} +1 -1
  13. package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
  14. package/dist/{app-Dvk30CIa.js → app-CmuI6uSl.js} +3589 -2902
  15. package/dist/app.js +1 -1
  16. package/dist/{dayjs.min-DUFHhM7O.js → dayjs.min-B3MssMma.js} +1 -1
  17. package/dist/{featureFlag-BvcirzHS.js → featureFlag-CWvkPOBY.js} +123 -130
  18. package/dist/frontend/mf-order/src/api/food-court/index.d.ts +51 -0
  19. package/dist/frontend/mf-order/src/api/kiosk/index.d.ts +4 -0
  20. package/dist/frontend/mf-order/src/api/payment/index.d.ts +8 -0
  21. package/dist/frontend/mf-order/src/api/queue/index.d.ts +13 -0
  22. package/dist/frontend/mf-order/src/api/restaurant-setting/index.d.ts +9 -1
  23. package/dist/frontend/mf-order/src/app.d.ts +687 -0
  24. package/dist/frontend/mf-order/src/main.d.ts +687 -0
  25. package/dist/frontend/mf-order/src/modules/display-system/interface.d.ts +5 -0
  26. package/dist/frontend/mf-order/src/modules/kiosk/interface.d.ts +4 -0
  27. package/dist/frontend/mf-order/src/modules/kiosk/license.d.ts +92 -0
  28. package/dist/frontend/mf-order/src/modules/kiosk/outletLoad.d.ts +15 -0
  29. package/dist/frontend/mf-order/src/modules/kiosk/settingsSections.d.ts +24 -0
  30. package/dist/frontend/mf-order/src/modules/kiosk/useKioskSettings.d.ts +29 -0
  31. package/dist/frontend/mf-order/src/modules/payment/paymentDevice.d.ts +58 -0
  32. package/dist/frontend/mf-order/src/stores/kiosk/index.d.ts +67 -1
  33. package/dist/frontend/mf-order/src/stores/order-setting/index.d.ts +19 -10
  34. package/dist/frontend/mf-order/src/stores/payment/index.d.ts +59 -1
  35. package/dist/frontend/mf-order/src/views/food-court/food-court-export.d.ts +38 -0
  36. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskDeviceCard.vue.d.ts +3 -0
  37. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskDevicesView.vue.d.ts +7 -0
  38. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskLicenseSummary.vue.d.ts +7 -0
  39. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskLicensesView.vue.d.ts +6 -0
  40. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskOtpDialog.vue.d.ts +3 -0
  41. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskPaymentDeviceCard.vue.d.ts +17 -0
  42. package/dist/frontend/mf-order/src/views/kiosk/settings/KioskSettingView.vue.d.ts +5 -2
  43. package/dist/frontend/mf-order/src/views/order-settings/pickup/PickUpSettingDialogContent.vue.d.ts +0 -9
  44. package/dist/frontend/mf-order/src/views/order-settings/pos-status/PosOrderingStatus.vue.d.ts +17 -0
  45. package/dist/frontend/mf-order/src/views/order-settings/pos-status/pos-status.d.ts +44 -0
  46. package/dist/frontend/mf-order/src/views/order-settings/queue/called-message.d.ts +1 -0
  47. package/dist/frontend/mf-order/src/views/order-settings/queue/phone-join-mode.d.ts +25 -0
  48. package/dist/frontend/mf-order/tsconfig.app.tsbuildinfo +1 -1
  49. package/dist/{index-C4n5H7t3.js → index-BQa8AudZ.js} +3 -3
  50. package/dist/index-CMOvrim4.js +147 -0
  51. package/dist/{index-CW4VlFWz.js → index-D5qh2_4b.js} +1 -1
  52. package/dist/{index-C5n6lil6.js → index-Dup6kWLX.js} +6 -6
  53. package/dist/{index-CGxCWKHB.js → index-wuFIsXHT.js} +188 -179
  54. package/dist/{order.dto-Cb_gh3iB.js → order.dto-BD9raQG5.js} +2782 -2735
  55. package/dist/package/entity/display/blocks.d.ts +12 -2
  56. package/dist/package/entity/marketing/marketing.dto.d.ts +18 -18
  57. package/dist/package/entity/order-platform/external/reconciliation/external-reconciliation.do.d.ts +24 -24
  58. package/dist/package/entity/order-platform/menu.dto.d.ts +20 -20
  59. package/dist/package/entity/order-setting/order-setting.do.d.ts +10 -0
  60. package/dist/package/entity/order-setting/order-setting.dto.d.ts +26 -0
  61. package/dist/package/entity/order-setting/queue/queue.do.d.ts +23 -0
  62. package/dist/package/entity/order-setting/queue/queue.dto.d.ts +14 -0
  63. package/dist/package/entity/queue/queue.do.d.ts +153 -0
  64. package/dist/package/entity/queue/queue.dto.d.ts +221 -2
  65. package/dist/package/entity/queue/queue.enum.d.ts +5 -0
  66. package/dist/package/entity/restaurant/restaurant.dto.d.ts +20 -0
  67. package/dist/style.css +1 -1
  68. package/dist/{index-ILnighyU.js → useInternalUser-CHtaur9A.js} +93 -81
  69. package/package.json +2 -1
  70. package/src/api/food-court/index.ts +63 -0
  71. package/src/api/kiosk/index.ts +8 -0
  72. package/src/api/payment/index.ts +18 -1
  73. package/src/api/queue/index.ts +39 -0
  74. package/src/api/restaurant-setting/index.ts +14 -0
  75. package/src/locales/en-US.json +197 -26
  76. package/src/locales/ja-JP.json +193 -23
  77. package/src/locales/th-TH.json +193 -21
  78. package/src/locales/zh-CN.json +197 -23
  79. package/src/modules/display-system/interface.spec.ts +26 -1
  80. package/src/modules/display-system/interface.ts +20 -0
  81. package/src/modules/kiosk/interface.ts +4 -0
  82. package/src/modules/kiosk/license.spec.ts +167 -0
  83. package/src/modules/kiosk/license.ts +175 -0
  84. package/src/modules/kiosk/outletLoad.spec.ts +25 -0
  85. package/src/modules/kiosk/outletLoad.ts +19 -0
  86. package/src/modules/kiosk/settingsSections.spec.ts +85 -0
  87. package/src/modules/kiosk/settingsSections.ts +82 -0
  88. package/src/modules/kiosk/useKioskSettings.spec.ts +157 -0
  89. package/src/modules/kiosk/useKioskSettings.ts +61 -0
  90. package/src/modules/payment/paymentDevice.spec.ts +175 -0
  91. package/src/modules/payment/paymentDevice.ts +156 -0
  92. package/src/stores/kiosk/index.ts +16 -1
  93. package/src/stores/kiosk/mapper.ts +2 -0
  94. package/src/stores/order-setting/index.spec.ts +83 -0
  95. package/src/stores/order-setting/index.ts +49 -27
  96. package/src/stores/payment/index.spec.ts +86 -0
  97. package/src/stores/payment/index.ts +48 -2
  98. package/src/views/display-system/DisplayInspector.vue +17 -8
  99. package/src/views/display-system/DisplayTemplateEditor.vue +3 -1
  100. package/src/views/food-court/FoodCourtOrdersView.vue +46 -1
  101. package/src/views/food-court/food-court-export.spec.ts +151 -0
  102. package/src/views/food-court/food-court-export.ts +283 -0
  103. package/src/views/kiosk/KioskStatePanel.vue +2 -2
  104. package/src/views/kiosk/KioskView.vue +219 -82
  105. package/src/views/kiosk/devices/KioskDeviceCard.vue +148 -23
  106. package/src/views/kiosk/devices/KioskDevicesView.vue +48 -10
  107. package/src/views/kiosk/devices/KioskLicenseSummary.vue +79 -0
  108. package/src/views/kiosk/devices/KioskLicensesView.vue +152 -0
  109. package/src/views/kiosk/devices/KioskOtpDialog.vue +41 -1
  110. package/src/views/kiosk/devices/KioskPaymentDeviceCard.spec.ts +97 -0
  111. package/src/views/kiosk/devices/KioskPaymentDeviceCard.vue +221 -0
  112. package/src/views/kiosk/settings/KioskPaymentTypeSection.vue +1 -1
  113. package/src/views/kiosk/settings/KioskSettingView.vue +702 -419
  114. package/src/views/order-settings/delivery/DeliverySetting.vue +4 -0
  115. package/src/views/order-settings/dine-in/DineInSetting.vue +4 -0
  116. package/src/views/order-settings/pickup/PickUpSetting.vue +4 -4
  117. package/src/views/order-settings/pickup/PickUpSettingDialogContent.vue +0 -23
  118. package/src/views/order-settings/pos-status/PosOrderingStatus.spec.ts +207 -0
  119. package/src/views/order-settings/pos-status/PosOrderingStatus.vue +209 -0
  120. package/src/views/order-settings/pos-status/pos-status.spec.ts +103 -0
  121. package/src/views/order-settings/pos-status/pos-status.ts +86 -0
  122. package/src/views/order-settings/queue/QueueSetting.source.spec.ts +43 -0
  123. package/src/views/order-settings/queue/QueueSetting.vue +289 -15
  124. package/src/views/order-settings/queue/called-message.spec.ts +29 -1
  125. package/src/views/order-settings/queue/called-message.ts +18 -0
  126. package/src/views/order-settings/queue/phone-join-mode.spec.ts +90 -0
  127. package/src/views/order-settings/queue/phone-join-mode.ts +49 -0
  128. package/dist/FoodCourtOrdersView-CAPOycT3.js +0 -544
  129. package/dist/KioskDevicesView-B0U9JxRl.js +0 -4
  130. package/dist/KioskDevicesView.vue_vue_type_script_setup_true_lang-V3ai4FVI.js +0 -937
  131. package/dist/KioskSettingView-rdom_aS8.js +0 -880
  132. package/dist/KioskView-DOON9zR6.js +0 -516
  133. package/dist/frontend/mf-order/src/views/kiosk/settings/KioskDisplayStandSection.vue.d.ts +0 -10
  134. package/dist/frontend/mf-order/src/views/kiosk/settings/KioskInstructionSection.vue.d.ts +0 -15
  135. package/dist/frontend/mf-order/src/views/kiosk/settings/KioskPickAtCounterSection.vue.d.ts +0 -10
  136. package/dist/index-CaHG3M7C.js +0 -135
  137. package/src/views/kiosk/settings/KioskDisplayStandSection.vue +0 -189
  138. package/src/views/kiosk/settings/KioskInstructionSection.vue +0 -40
  139. package/src/views/kiosk/settings/KioskPickAtCounterSection.vue +0 -68
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Kiosk and tablet licences on the Devices page. The rules on the backend side
3
+ * (KL-1..KL-9) are in backend/apps/kiosk-backend/KIOSK-LICENCES.md; this file
4
+ * only turns the licence list and a device's licence into what the page shows.
5
+ */
6
+
7
+ export type MfKioskLicenseType = 'KIOSK' | 'TABLET'
8
+ export type MfKioskLicenseStatus = 'FREE' | 'IN_USE' | 'EXPIRED'
9
+
10
+ /** Shape of `GET /restaurants/:rid/kiosk/licenses` (kiosk-backend PortalKioskLicenseList). */
11
+ export interface MfKioskLicenseList {
12
+ /** False when the licence service could not be read; `licenses` is then empty. */
13
+ verified: boolean
14
+ /** The business needs no licence to bind devices. */
15
+ unlimited: boolean
16
+ /** A tablet may use a free kiosk licence when no tablet licence is free. */
17
+ tabletMayUseKioskLicense: boolean
18
+ licenses: MfKioskLicense[]
19
+ }
20
+
21
+ export interface MfKioskLicense {
22
+ id: string
23
+ type: MfKioskLicenseType
24
+ expiredAt: string
25
+ status: MfKioskLicenseStatus
26
+ device: {
27
+ machineId: string
28
+ name?: string | null
29
+ restaurantId: string
30
+ restaurantName?: string | null
31
+ deviceAppType?: string | null
32
+ lastStartup?: string | null
33
+ } | null
34
+ }
35
+
36
+ /** A licence that ends within this many days is shown in amber. */
37
+ export const EXPIRING_SOON_DAYS = 30
38
+
39
+ const DAY_MS = 24 * 60 * 60 * 1000
40
+
41
+ export type DeviceLicenseState =
42
+ | { kind: 'none' }
43
+ | { kind: 'active'; expiredAt: Date }
44
+ | { kind: 'expiring'; expiredAt: Date; daysLeft: number }
45
+ | { kind: 'expired'; expiredAt: Date }
46
+
47
+ /**
48
+ * The state of the licence a device holds. A device without a licence id was
49
+ * bound before licensing (or for an unlimited business): it is never blocked.
50
+ * A licence id without a date is treated the same way, because the kiosk
51
+ * itself only stops on a date that has passed.
52
+ */
53
+ export function deviceLicenseState(
54
+ device: { licenseId?: string | null; expiredAt?: Date | null },
55
+ now: Date = new Date()
56
+ ): DeviceLicenseState {
57
+ if (!device.licenseId || !device.expiredAt) return { kind: 'none' }
58
+ const expiredAt = device.expiredAt
59
+ const msLeft = expiredAt.getTime() - now.getTime()
60
+ if (msLeft <= 0) return { kind: 'expired', expiredAt }
61
+ const daysLeft = Math.ceil(msLeft / DAY_MS)
62
+ if (daysLeft <= EXPIRING_SOON_DAYS) return { kind: 'expiring', expiredAt, daysLeft }
63
+ return { kind: 'active', expiredAt }
64
+ }
65
+
66
+ export type ChipVariant = 'success' | 'warning' | 'critical' | 'plain' | 'info'
67
+
68
+ export interface LicenseChip {
69
+ variant: ChipVariant
70
+ labelKey: string
71
+ params: Record<string, string | number>
72
+ }
73
+
74
+ /** Chip for a device's licence line: green, amber, red, or grey (`plain`) for no licence. */
75
+ export function deviceLicenseChip(
76
+ state: DeviceLicenseState,
77
+ formatDate: (d: Date) => string
78
+ ): LicenseChip {
79
+ switch (state.kind) {
80
+ case 'active':
81
+ return {
82
+ variant: 'success',
83
+ labelKey: 'order.licenseActiveUntil',
84
+ params: { date: formatDate(state.expiredAt) }
85
+ }
86
+ case 'expiring':
87
+ return {
88
+ variant: 'warning',
89
+ labelKey: state.daysLeft === 1 ? 'order.licenseExpiresInOneDay' : 'order.licenseExpiresInDays',
90
+ params: { days: state.daysLeft }
91
+ }
92
+ case 'expired':
93
+ return { variant: 'critical', labelKey: 'order.licenseExpired', params: {} }
94
+ default:
95
+ return { variant: 'plain', labelKey: 'order.licenseNone', params: {} }
96
+ }
97
+ }
98
+
99
+ /** Chip for a row of the Licences tab. */
100
+ export function licenseRowChip(license: MfKioskLicense, now: Date = new Date()): LicenseChip {
101
+ if (license.status === 'EXPIRED') return { variant: 'critical', labelKey: 'order.licenseExpired', params: {} }
102
+ if (license.status === 'FREE') return { variant: 'info', labelKey: 'order.licenseFree', params: {} }
103
+ const state = deviceLicenseState(
104
+ { licenseId: license.id, expiredAt: new Date(license.expiredAt) },
105
+ now
106
+ )
107
+ return state.kind === 'expiring'
108
+ ? { variant: 'warning', labelKey: 'order.licenseInUseExpiringSoon', params: {} }
109
+ : { variant: 'success', labelKey: 'order.licenseInUse', params: {} }
110
+ }
111
+
112
+ /**
113
+ * The device holds a licence of the other type. Only a tablet on a kiosk
114
+ * licence is expected (the fallback); the other way should never happen, but
115
+ * a licence's type can be changed in the licence portal after binding.
116
+ */
117
+ export function licenseMismatchKey(
118
+ deviceAppType: string | undefined | null,
119
+ licenseType: MfKioskLicenseType | undefined
120
+ ): string | null {
121
+ if (!licenseType) return null
122
+ const isTablet = deviceAppType === 'TABLET_APP'
123
+ if (isTablet && licenseType === 'KIOSK') return 'order.licenseUsesKioskLicense'
124
+ if (!isTablet && licenseType === 'TABLET') return 'order.licenseUsesTabletLicense'
125
+ return null
126
+ }
127
+
128
+ export interface LicenseSummary {
129
+ type: MfKioskLicenseType
130
+ /** Unexpired licences of this type. */
131
+ total: number
132
+ used: number
133
+ free: number
134
+ /** Earliest end date among the unexpired licences, if any. */
135
+ nextExpiry: Date | null
136
+ }
137
+
138
+ export function summariseLicenses(
139
+ list: MfKioskLicense[],
140
+ type: MfKioskLicenseType
141
+ ): LicenseSummary {
142
+ const active = list.filter((l) => l.type === type && l.status !== 'EXPIRED')
143
+ const used = active.filter((l) => l.status === 'IN_USE').length
144
+ const nextExpiry = active.reduce<Date | null>((min, l) => {
145
+ const d = new Date(l.expiredAt)
146
+ return !min || d < min ? d : min
147
+ }, null)
148
+ return { type, total: active.length, used, free: active.length - used, nextExpiry }
149
+ }
150
+
151
+ /**
152
+ * Which licence a new device of each kind will use, for the bind dialog.
153
+ * 'none' means the bind will be refused.
154
+ */
155
+ export function bindLicensePlan(list: MfKioskLicenseList): {
156
+ kiosk: 'KIOSK' | 'none'
157
+ tablet: MfKioskLicenseType | 'none'
158
+ } {
159
+ const freeKiosk = summariseLicenses(list.licenses, 'KIOSK').free
160
+ const freeTablet = summariseLicenses(list.licenses, 'TABLET').free
161
+ return {
162
+ kiosk: freeKiosk > 0 ? 'KIOSK' : 'none',
163
+ tablet:
164
+ freeTablet > 0
165
+ ? 'TABLET'
166
+ : list.tabletMayUseKioskLicense && freeKiosk > 0
167
+ ? 'KIOSK'
168
+ : 'none'
169
+ }
170
+ }
171
+
172
+ /** Last six characters: enough to tell licences apart when talking to support. */
173
+ export function shortLicenseId(id: string): string {
174
+ return id.length > 6 ? `…${id.slice(-6)}` : id
175
+ }
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { outletToLoad } from './outletLoad'
3
+
4
+ describe('outletToLoad', () => {
5
+ it('waits for the sign-in token', () => {
6
+ expect(outletToLoad({ hasToken: false, restaurantId: 'r1' }, null)).toBeNull()
7
+ })
8
+
9
+ it('waits for an outlet', () => {
10
+ expect(outletToLoad({ hasToken: true, restaurantId: undefined }, null)).toBeNull()
11
+ expect(outletToLoad({ hasToken: true, restaurantId: '' }, null)).toBeNull()
12
+ })
13
+
14
+ it('loads the outlet once both are ready', () => {
15
+ expect(outletToLoad({ hasToken: true, restaurantId: 'r1' }, null)).toBe('r1')
16
+ })
17
+
18
+ it('does not load the same outlet again (a token refresh is not a new outlet)', () => {
19
+ expect(outletToLoad({ hasToken: true, restaurantId: 'r1' }, 'r1')).toBeNull()
20
+ })
21
+
22
+ it('loads a different outlet after a switch', () => {
23
+ expect(outletToLoad({ hasToken: true, restaurantId: 'r2' }, 'r1')).toBe('r2')
24
+ })
25
+ })
@@ -0,0 +1,19 @@
1
+ /**
2
+ * When the Kiosk / Tablet page may load an outlet's devices and settings.
3
+ *
4
+ * The portal can mount this page before the signed-in user's token is ready.
5
+ * Calling the API then throws before any request is sent (`baseClientInstance`:
6
+ * "Unauthorized request"), and the page used to show "Couldn't load devices"
7
+ * and default settings. So the page waits until it has both a token and an
8
+ * outlet, and loads each outlet once.
9
+ */
10
+ export interface OutletLoadInput {
11
+ hasToken: boolean
12
+ restaurantId: string | null | undefined
13
+ }
14
+
15
+ /** The outlet to load now, or null when not ready yet or already loaded. */
16
+ export function outletToLoad(input: OutletLoadInput, loadedFor: string | null): string | null {
17
+ if (!input.hasToken || !input.restaurantId) return null
18
+ return input.restaurantId === loadedFor ? null : input.restaurantId
19
+ }
@@ -0,0 +1,85 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { F_ORDER_PAYMENT_TYPE } from '@entity'
3
+ import type { MfKioskOrderSettingForm } from '@/modules/order-setting/kiosk/interface'
4
+ import {
5
+ hasCustomMessages,
6
+ invalidSettingsSections,
7
+ MAX_MIN_WEIGH_GRAMS,
8
+ visibleSettingsSections
9
+ } from './settingsSections'
10
+
11
+ function validForm(): MfKioskOrderSettingForm {
12
+ return {
13
+ dineIn: {
14
+ enabled: true,
15
+ pickUp: { enabled: true, submitOrderInstruction: { payAtCounter: null, paid: null } },
16
+ displayStand: {
17
+ enabled: true,
18
+ prefix: 'T',
19
+ padDigit: 2,
20
+ standSlotRange: { min: 1, max: 20 },
21
+ submitOrderInstruction: { payAtCounter: null, paid: null }
22
+ }
23
+ },
24
+ takeaway: { enabled: true, submitOrderInstruction: { payAtCounter: null, paid: null } },
25
+ paymentSetting: { paymentTypes: [], offlinePaymentTypes: [], ePaymentTypes: {} },
26
+ languages: null,
27
+ minWeighGrams: null
28
+ } as unknown as MfKioskOrderSettingForm
29
+ }
30
+
31
+ describe('Kiosk / Tablet settings sections', () => {
32
+ it('shows Updates to admins only', () => {
33
+ expect(visibleSettingsSections(false)).toEqual(['ordering', 'look', 'payment'])
34
+ expect(visibleSettingsSections(true)).toEqual(['ordering', 'look', 'payment', 'updates'])
35
+ })
36
+
37
+ it('a valid form has no section to fix', () => {
38
+ expect(invalidSettingsSections(validForm())).toEqual([])
39
+ })
40
+
41
+ it('a display stand range that ends before it starts is an Ordering error', () => {
42
+ const f = validForm()
43
+ f.dineIn.displayStand.standSlotRange = { min: 10, max: 5 }
44
+ expect(invalidSettingsSections(f)).toEqual(['ordering'])
45
+ // ...but only while dine-in and the display stand are on.
46
+ f.dineIn.displayStand.enabled = false
47
+ expect(invalidSettingsSections(f)).toEqual([])
48
+ })
49
+
50
+ it('a minimum weight that is not a whole number of grams from 1 is an Ordering error', () => {
51
+ for (const grams of [0, 1.5, MAX_MIN_WEIGH_GRAMS + 1]) {
52
+ const f = validForm()
53
+ f.minWeighGrams = grams
54
+ expect(invalidSettingsSections(f)).toEqual(['ordering'])
55
+ }
56
+ })
57
+
58
+ it('a language restriction with no language is a Look and photos error', () => {
59
+ const f = validForm()
60
+ f.languages = []
61
+ expect(invalidSettingsSections(f)).toEqual(['look'])
62
+ })
63
+
64
+ it('e-payment with no way to take it is a Payment error', () => {
65
+ const f = validForm()
66
+ f.paymentSetting.paymentTypes = [F_ORDER_PAYMENT_TYPE.enum.ePayment]
67
+ expect(invalidSettingsSections(f)).toEqual(['payment'])
68
+ f.paymentSetting.ePaymentTypes = { card: { terminal: true } } as never
69
+ expect(invalidSettingsSections(f)).toEqual([])
70
+ })
71
+
72
+ it('lists every section with an error, in menu order (Save opens the first)', () => {
73
+ const f = validForm()
74
+ f.paymentSetting.paymentTypes = [F_ORDER_PAYMENT_TYPE.enum.ePayment]
75
+ f.languages = []
76
+ f.minWeighGrams = 0
77
+ expect(invalidSettingsSections(f)).toEqual(['ordering', 'look', 'payment'])
78
+ })
79
+
80
+ it('custom messages: any non-blank text counts', () => {
81
+ expect(hasCustomMessages(undefined)).toBe(false)
82
+ expect(hasCustomMessages({ payAtCounter: null, paid: ' ' })).toBe(false)
83
+ expect(hasCustomMessages({ payAtCounter: 'Pay at the counter', paid: null })).toBe(true)
84
+ })
85
+ })
@@ -0,0 +1,82 @@
1
+ import { F_ORDER_PAYMENT_TYPE } from '@entity'
2
+ import type {
3
+ MfKioskOrderSettingForm,
4
+ MfKioskSubmitOrderInstruction
5
+ } from '@/modules/order-setting/kiosk/interface'
6
+
7
+ /**
8
+ * The Kiosk / Tablet Settings tab shows one section at a time (a section menu on
9
+ * the left, a row of section buttons on phones), so the merchant scrolls one short
10
+ * section instead of the whole form.
11
+ *
12
+ * - ordering: dine-in, takeaway, order number, guests, menu items, minimum weight
13
+ * - look: languages and cover images (kiosks and tablets)
14
+ * - payment: payment methods (kiosk only; tablets are paid at the counter)
15
+ * - updates: the OTA channel (admins only)
16
+ */
17
+ export type KioskSettingsSection = 'ordering' | 'look' | 'payment' | 'updates'
18
+
19
+ const ALL_SECTIONS: KioskSettingsSection[] = ['ordering', 'look', 'payment', 'updates']
20
+
21
+ /** Sections this user can see, in menu order. Updates is for admins only. */
22
+ export function visibleSettingsSections(isAdmin: boolean): KioskSettingsSection[] {
23
+ return ALL_SECTIONS.filter((s) => s !== 'updates' || isAdmin)
24
+ }
25
+
26
+ /** Largest minimum weight (grams) a merchant may set; 100 kg is far above any kiosk scale. */
27
+ export const MAX_MIN_WEIGH_GRAMS = 100000
28
+
29
+ /**
30
+ * Sections whose fields cannot be saved as they are, in menu order. Save refuses
31
+ * while this is not empty and opens the first one, so the merchant sees the error
32
+ * even when it is in a section that is not on screen.
33
+ */
34
+ export function invalidSettingsSections(f: MfKioskOrderSettingForm): KioskSettingsSection[] {
35
+ const invalid = new Set<KioskSettingsSection>()
36
+
37
+ // Display stand numbers, when both dine-in and the display stand are on.
38
+ if (f.dineIn.enabled && f.dineIn.displayStand.enabled) {
39
+ const { padDigit, standSlotRange } = f.dineIn.displayStand
40
+ const isValid =
41
+ padDigit != null &&
42
+ padDigit >= 0 &&
43
+ standSlotRange.min != null &&
44
+ standSlotRange.max != null &&
45
+ standSlotRange.min <= standSlotRange.max
46
+ if (!isValid) invalid.add('ordering')
47
+ }
48
+
49
+ // A minimum weight must be a whole number of grams, at least 1 (KDI-5138).
50
+ if (
51
+ f.minWeighGrams != null &&
52
+ (!Number.isInteger(f.minWeighGrams) ||
53
+ f.minWeighGrams < 1 ||
54
+ f.minWeighGrams > MAX_MIN_WEIGH_GRAMS)
55
+ ) {
56
+ invalid.add('ordering')
57
+ }
58
+
59
+ // A restriction that allows no language would leave the kiosk with nothing to
60
+ // render. Saving it would also be a no-op, since [] round-trips as null.
61
+ if (f.languages != null && f.languages.length === 0) invalid.add('look')
62
+
63
+ // E-payment needs at least one way to take it.
64
+ const payment = f.paymentSetting
65
+ if (payment?.paymentTypes?.includes(F_ORDER_PAYMENT_TYPE.enum.ePayment)) {
66
+ const ePayment = payment.ePaymentTypes
67
+ const hasCard = ePayment?.card?.terminal || ePayment?.card?.nfc
68
+ const hasWallet =
69
+ ePayment?.eWallet?.qrPay ||
70
+ ePayment?.eWallet?.scanPay ||
71
+ ePayment?.eWallet?.terminalScanPay ||
72
+ ePayment?.eWallet?.terminalQrPay
73
+ if (!ePayment || (!hasCard && !hasWallet && !ePayment.terminal)) invalid.add('payment')
74
+ }
75
+
76
+ return ALL_SECTIONS.filter((s) => invalid.has(s))
77
+ }
78
+
79
+ /** True when the merchant wrote their own text for either "submit order" message. */
80
+ export function hasCustomMessages(instruction: MfKioskSubmitOrderInstruction | undefined): boolean {
81
+ return !!(instruction?.payAtCounter?.trim() || instruction?.paid?.trim())
82
+ }
@@ -0,0 +1,157 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { createPinia, setActivePinia } from 'pinia'
3
+
4
+ // The real order-setting store; only the HTTP calls and the current outlet are faked.
5
+ const api = vi.hoisted(() => ({
6
+ getOrderSetting: vi.fn(),
7
+ updateOrderSetting: vi.fn()
8
+ }))
9
+ const outlet = vi.hoisted(() => ({ id: 'A' as string | null }))
10
+
11
+ vi.mock('@/api/order-setting', () => ({ OrderSettingApi: api }))
12
+ vi.mock('@/api', () => ({ SvcConfig: { getRestaurantId: () => outlet.id } }))
13
+ vi.mock('@/stores/order-setting/mapper', () => ({
14
+ OrderSettingMapper: {
15
+ convertOrderSettingDto: (dto: { _id: string }) => ({ kiosk: { from: dto._id } }),
16
+ toOrderKioskSettingsDto: (kiosk: unknown) => ({ kioskSettings: kiosk }),
17
+ toKioskSequenceSettings: () => ({})
18
+ }
19
+ }))
20
+
21
+ import { useOrderSettings } from '@/stores/order-setting'
22
+ import { useKioskSettings } from './useKioskSettings'
23
+ import type { MfKioskOrderSetting } from '@/modules/order-setting/kiosk/interface'
24
+
25
+ const edited = { edited: true } as unknown as MfKioskOrderSetting
26
+
27
+ function deferred<T>() {
28
+ let resolve!: (v: T) => void
29
+ let reject!: (e: unknown) => void
30
+ const promise = new Promise<T>((res, rej) => {
31
+ resolve = res
32
+ reject = rej
33
+ })
34
+ return { promise, resolve, reject }
35
+ }
36
+
37
+ function setup() {
38
+ const notify = { onSaved: vi.fn(), onFailed: vi.fn() }
39
+ const settings = useKioskSettings(useOrderSettings(), notify)
40
+ return { settings, notify }
41
+ }
42
+
43
+ describe('Kiosk / Tablet settings: load and save rules', () => {
44
+ beforeEach(() => {
45
+ setActivePinia(createPinia())
46
+ api.getOrderSetting.mockReset()
47
+ api.updateOrderSetting.mockReset()
48
+ outlet.id = 'A'
49
+ })
50
+
51
+ it('clears the previous outlet’s settings as soon as another outlet starts loading', async () => {
52
+ const { settings } = setup()
53
+ api.getOrderSetting.mockResolvedValueOnce({ _id: 'settings-A' })
54
+ await settings.load()
55
+ expect(settings.form.value).toEqual({ from: 'settings-A' })
56
+
57
+ outlet.id = 'B'
58
+ const b = deferred<unknown>()
59
+ api.getOrderSetting.mockReturnValueOnce(b.promise)
60
+ const loading = settings.load()
61
+ // While B loads, nothing of A is shown or kept.
62
+ expect(settings.status.value).toBe('loading')
63
+ expect(settings.form.value).toBeNull()
64
+ expect(useOrderSettings().state.orderSetting).toBeUndefined()
65
+ b.resolve({ _id: 'settings-B' })
66
+ await loading
67
+ expect(settings.form.value).toEqual({ from: 'settings-B' })
68
+ })
69
+
70
+ it('renders and saves only after this outlet’s settings loaded', async () => {
71
+ const { settings, notify } = setup()
72
+ expect(settings.form.value).toBeNull() // idle: no defaults to render
73
+ await expect(settings.save(edited)).rejects.toThrow()
74
+ expect(api.updateOrderSetting).not.toHaveBeenCalled()
75
+ expect(notify.onSaved).not.toHaveBeenCalled()
76
+
77
+ api.getOrderSetting.mockRejectedValueOnce(new Error('Unauthorized request'))
78
+ await settings.load()
79
+ expect(settings.status.value).toBe('error')
80
+ expect(settings.form.value).toBeNull()
81
+ await expect(settings.save(edited)).rejects.toThrow()
82
+ expect(api.updateOrderSetting).not.toHaveBeenCalled()
83
+ })
84
+
85
+ it('shows the load error and Retry really loads again', async () => {
86
+ const { settings } = setup()
87
+ api.getOrderSetting.mockRejectedValueOnce(new Error('network'))
88
+ await settings.load()
89
+ expect(settings.status.value).toBe('error')
90
+
91
+ api.getOrderSetting.mockResolvedValueOnce({ _id: 'settings-A' })
92
+ await settings.load() // the Retry button
93
+ expect(api.getOrderSetting).toHaveBeenCalledTimes(2)
94
+ expect(settings.status.value).toBe('ready')
95
+ expect(settings.form.value).toEqual({ from: 'settings-A' })
96
+ })
97
+
98
+ it('says "saved" only after the PUT succeeded', async () => {
99
+ const { settings, notify } = setup()
100
+ api.getOrderSetting.mockResolvedValue({ _id: 'settings-A', sequenceSettings: {} })
101
+ await settings.load()
102
+
103
+ const put = deferred<unknown>()
104
+ api.updateOrderSetting.mockReturnValueOnce(put.promise)
105
+ const saving = settings.save(edited)
106
+ await new Promise((r) => setTimeout(r, 0))
107
+ expect(api.updateOrderSetting).toHaveBeenCalledTimes(1)
108
+ expect(notify.onSaved).not.toHaveBeenCalled() // PUT still open
109
+ put.resolve({ _id: 'settings-A-saved' })
110
+ await saving
111
+ expect(notify.onSaved).toHaveBeenCalledTimes(1)
112
+ expect(notify.onFailed).not.toHaveBeenCalled()
113
+ })
114
+
115
+ it('a failed PUT says "failed", not "saved", and keeps the edits unsaved (rethrows)', async () => {
116
+ const { settings, notify } = setup()
117
+ api.getOrderSetting.mockResolvedValue({ _id: 'settings-A', sequenceSettings: {} })
118
+ await settings.load()
119
+ api.updateOrderSetting.mockRejectedValueOnce(new Error('500'))
120
+ await expect(settings.save(edited)).rejects.toThrow('500')
121
+ expect(notify.onFailed).toHaveBeenCalledTimes(1)
122
+ expect(notify.onSaved).not.toHaveBeenCalled()
123
+ expect(settings.form.value).toEqual({ from: 'settings-A' })
124
+ })
125
+
126
+ it('never writes outlet A’s settings into outlet B (switch, B fails to load, then save)', async () => {
127
+ const { settings, notify } = setup()
128
+ api.getOrderSetting.mockResolvedValueOnce({ _id: 'settings-A', sequenceSettings: {} })
129
+ await settings.load()
130
+
131
+ outlet.id = 'B'
132
+ api.getOrderSetting.mockRejectedValueOnce(new Error('timeout')) // B's load fails...
133
+ await settings.load()
134
+ api.getOrderSetting.mockResolvedValue({ _id: 'settings-B', sequenceSettings: {} }) // ...then the API works again
135
+
136
+ await expect(settings.save(edited)).rejects.toThrow()
137
+ // Even calling the store directly cannot send A's settings to B.
138
+ await expect(useOrderSettings().updateKioskSetting(edited)).rejects.toThrow()
139
+ expect(api.updateOrderSetting).not.toHaveBeenCalled()
140
+ expect(notify.onSaved).not.toHaveBeenCalled()
141
+ })
142
+
143
+ it('drops a slow response for outlet A that arrives after outlet B loaded', async () => {
144
+ const { settings } = setup()
145
+ const a = deferred<unknown>()
146
+ api.getOrderSetting.mockReturnValueOnce(a.promise)
147
+ const loadingA = settings.load()
148
+
149
+ outlet.id = 'B'
150
+ api.getOrderSetting.mockResolvedValueOnce({ _id: 'settings-B' })
151
+ await settings.load()
152
+ a.resolve({ _id: 'settings-A' })
153
+ await loadingA
154
+ expect(settings.status.value).toBe('ready')
155
+ expect(settings.form.value).toEqual({ from: 'settings-B' })
156
+ })
157
+ })
@@ -0,0 +1,61 @@
1
+ import { computed, ref } from 'vue'
2
+ import type { MfKioskOrderSetting } from '@/modules/order-setting/kiosk/interface'
3
+
4
+ /** The parts of the order-setting store this page uses (see `stores/order-setting`). */
5
+ export interface KioskSettingsStore {
6
+ state: { kiosk?: MfKioskOrderSetting }
7
+ reset(): void
8
+ getSetting(isCurrent?: () => boolean): Promise<void>
9
+ updateKioskSetting(kiosk: MfKioskOrderSetting): Promise<void>
10
+ }
11
+
12
+ export type KioskSettingsStatus = 'idle' | 'loading' | 'error' | 'ready'
13
+
14
+ /**
15
+ * The Settings tab's load and save rules for one outlet at a time:
16
+ * - `load()` (on every outlet change, and Retry) clears the previous outlet's
17
+ * settings first, and drops a response that arrives after a newer load started;
18
+ * - `form` is set only while this outlet's settings are loaded ('ready'), so the
19
+ * page never renders defaults or another outlet's values;
20
+ * - `save()` refuses unless 'ready', and calls `onSaved` only after the backend
21
+ * accepted the update (`onFailed` + rethrow otherwise, so edits stay unsaved).
22
+ */
23
+ export function useKioskSettings(
24
+ store: KioskSettingsStore,
25
+ notify: { onSaved: () => void; onFailed: () => void }
26
+ ) {
27
+ const status = ref<KioskSettingsStatus>('idle')
28
+ let request = 0
29
+
30
+ async function load(): Promise<void> {
31
+ const mine = ++request
32
+ const isCurrent = () => mine === request
33
+ store.reset()
34
+ status.value = 'loading'
35
+ try {
36
+ await store.getSetting(isCurrent)
37
+ if (isCurrent()) status.value = 'ready'
38
+ } catch {
39
+ if (isCurrent()) status.value = 'error'
40
+ }
41
+ }
42
+
43
+ const form = computed<MfKioskOrderSetting | null>(() =>
44
+ status.value === 'ready' ? store.state.kiosk ?? null : null
45
+ )
46
+
47
+ async function save(kiosk: MfKioskOrderSetting): Promise<void> {
48
+ try {
49
+ if (status.value !== 'ready') {
50
+ throw new Error('Kiosk settings are not loaded for this outlet')
51
+ }
52
+ await store.updateKioskSetting(kiosk)
53
+ } catch (e) {
54
+ notify.onFailed()
55
+ throw e
56
+ }
57
+ notify.onSaved()
58
+ }
59
+
60
+ return { status, form, load, save }
61
+ }