@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
@@ -7,6 +7,9 @@
7
7
  class="mx-5 xs:my-3 xs:order-1"
8
8
  />
9
9
  </div>
10
+ <div class="mx-5 mt-5 lg:w-2/3">
11
+ <PosOrderingStatus channel="delivery" />
12
+ </div>
10
13
  <div class="block">
11
14
  <FmPageHead
12
15
  class="flex-grow"
@@ -193,6 +196,7 @@
193
196
  <script setup lang="ts">
194
197
  import { computed, h, ref, watch } from 'vue'
195
198
  import RestaurantSelector from '../components/RestaurantSelector.vue'
199
+ import PosOrderingStatus from '../pos-status/PosOrderingStatus.vue'
196
200
  import { type ColumnDef, useDialog } from '@feedmepos/ui-library'
197
201
  import type {
198
202
  FdoDeliverooSettings,
@@ -2,6 +2,9 @@
2
2
  <div class="flex justify-between items-center">
3
3
  <RestaurantSelector />
4
4
  </div>
5
+ <div class="px-[1.5rem] mx-5 mt-5 w-2/3 xs:w-auto">
6
+ <PosOrderingStatus channel="dineIn" />
7
+ </div>
5
8
  <div v-if="!isLoading">
6
9
  <div class="p-[1.5rem] flex flex-col gap-5 m-5 w-2/3">
7
10
  <div class="flex-grow fm-typo-en-title-sm-600">{{ t('order.generalSetting') }}</div>
@@ -200,6 +203,7 @@ import {
200
203
  type FdoRestaurantDineIn
201
204
  } from '@feedmepos/core/entity'
202
205
  import RestaurantSelector from '../components/RestaurantSelector.vue'
206
+ import PosOrderingStatus from '../pos-status/PosOrderingStatus.vue'
203
207
  import { computed, onMounted, ref, watch } from 'vue'
204
208
  import { useRestaurantStore } from '@/stores/restaurant'
205
209
  import { useLoading } from '@/composables/loading'
@@ -2,13 +2,15 @@
2
2
  <div class="flex justify-between items-center">
3
3
  <RestaurantSelector />
4
4
  </div>
5
+ <div class="px-[1.5rem] mx-5 mt-5 w-2/3 xs:w-auto max-w-4xl">
6
+ <PosOrderingStatus channel="pickup" />
7
+ </div>
5
8
  <div v-if="isReady">
6
9
  <div class="p-[1.5rem] flex flex-col m-5 w-2/3 max-w-4xl">
7
10
  <PickUpSettingDialogContent
8
11
  :pickup="pickupSetting"
9
12
  :order-pickup-settings="orderPickupSettings"
10
13
  :channel-auto-accept="orderSetting?.channelAutoAccept?.pickup ?? null"
11
- :accept-pickup="acceptPickup"
12
14
  @update-pickup="updatePickupSetting"
13
15
  @update-order-settings="updateOrderPickupSettings"
14
16
  />
@@ -38,6 +40,7 @@ import { utils } from '@feedmepos/core'
38
40
  import { F_ORDER_PAYMENT_TYPE, FdoRestaurantPickup } from '@feedmepos/core/entity'
39
41
  import type { OrderPickupSettingsDto, OrderSettingsDto } from '@entity'
40
42
  import RestaurantSelector from '../components/RestaurantSelector.vue'
43
+ import PosOrderingStatus from '../pos-status/PosOrderingStatus.vue'
41
44
  import PickUpSettingDialogContent from './PickUpSettingDialogContent.vue'
42
45
  import { MAX_PREORDER_DAYS } from './Preorder.vue'
43
46
  import { useRestaurantStore } from '@/stores/restaurant'
@@ -52,7 +55,6 @@ const { isLoading, startAsyncCallWithErr } = useLoading()
52
55
  const { showSuccess, showError } = useSnackbarFunctions()
53
56
 
54
57
  const pickupSetting = ref<FdoRestaurantPickup>(initDefaultPickupSetting())
55
- const acceptPickup = ref<boolean>(false)
56
58
  // The form (and its Save) must only render once BOTH fetches completed for the
57
59
  // restaurant that is still selected — otherwise a failed or raced load exposes
58
60
  // an editable default form whose Save would overwrite the real config.
@@ -82,7 +84,6 @@ async function loadSetting() {
82
84
  loadedForId.value = null
83
85
  loadError.value = false
84
86
  pickupSetting.value = initDefaultPickupSetting()
85
- acceptPickup.value = false
86
87
  orderSetting.value = undefined
87
88
  orderPickupSettings.value = {}
88
89
  try {
@@ -91,7 +92,6 @@ async function loadSetting() {
91
92
  // The selector stays clickable while requests are in flight — a late response
92
93
  // for a restaurant the user already switched away from must not land.
93
94
  if (currentRestaurant.value?._id !== restaurant._id) return
94
- acceptPickup.value = !!restaurantSetting?.acceptPickup
95
95
  // Clone: the form's in-place edits must never mutate the store-cached
96
96
  // setting doc or the core-store restaurant object.
97
97
  pickupSetting.value = utils.clone(
@@ -1,16 +1,5 @@
1
1
  <template>
2
2
  <div class="flex-grow fm-typo-en-title-sm-600 mb-5">{{ t('order.generalSetting') }}</div>
3
- <div class="flex flex-col mb-5">
4
- <div class="flex items-center gap-3">
5
- <span class="fm-typo-en-body-md-600">{{ t('order.online') }}</span>
6
- <div :class="getClassForOnline(acceptPickup)">
7
- {{ acceptPickup ? t('order.activated') : t('order.inactive') }}
8
- </div>
9
- </div>
10
- <span class="fm-typo-en-body-sm-400 text-fm-color-typo-secondary">
11
- {{ t('order.onlineFromPos') }}
12
- </span>
13
- </div>
14
3
  <FmSwitch
15
4
  :model-value="pickupSetting.ignoreStock ?? false"
16
5
  value="ignoreStock"
@@ -147,21 +136,9 @@ const props = defineProps({
147
136
  channelAutoAccept: {
148
137
  type: Object as PropType<OrderSettingChannelAutoAccept | null>,
149
138
  default: null
150
- },
151
- // Read-only pickup online status (restaurant-level `acceptPickup`); shown as a
152
- // labeled row at the top of this section, not editable here.
153
- acceptPickup: {
154
- type: Boolean,
155
- default: false
156
139
  }
157
140
  })
158
141
 
159
- const getClassForOnline = (enabled: boolean) => {
160
- return enabled
161
- ? 'bg-fm-color-system-success-100 text-fm-color-system-success-400 fm-typo-en-body-md-600 border fm-corner-radius-lg w-max p-4'
162
- : 'bg-fm-color-neutral-gray-100 text-fm-color-typo-neutral fm-typo-en-body-md-600 border fm-corner-radius-lg w-max p-4'
163
- }
164
-
165
142
  // Select + auto-close coupling live in one shared implementation; this view only
166
143
  // says how to PERSIST a change. `null` stays unset so the backend keeps
167
144
  // inheriting `setting.pickup`'s auto-accept — writing `false` would pin it.
@@ -0,0 +1,207 @@
1
+ // @vitest-environment happy-dom
2
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
3
+ import { flushPromises, mount } from '@vue/test-utils'
4
+ import { defineComponent, h, ref } from 'vue'
5
+
6
+ const RID_A = '63faf1798d8ba8001b84a07b'
7
+ const RID_B = '65b87a2833c130001b7b350a'
8
+ const currentRestaurant = ref<{ _id: string } | null>({ _id: RID_A })
9
+ const readRestaurantPosState = vi.fn()
10
+ const readRestaurantSetting = vi.fn()
11
+
12
+ vi.mock('@feedmepos/mf-common', () => ({
13
+ useI18n: () => ({
14
+ t: (key: string, params?: Record<string, string>) =>
15
+ params ? `${key}(${Object.values(params).join('|')})` : key
16
+ }),
17
+ useCoreStore: () => ({ currentRestaurant })
18
+ }))
19
+ vi.mock('@/api/restaurant-setting', () => ({
20
+ restaurantApi: { readRestaurantPosState: (id: string) => readRestaurantPosState(id) }
21
+ }))
22
+ vi.mock('@/stores/restaurant', () => ({
23
+ useRestaurantStore: () => ({ readRestaurantSetting: (id: string) => readRestaurantSetting(id) })
24
+ }))
25
+
26
+ import PosOrderingStatus from './PosOrderingStatus.vue'
27
+
28
+ const FmButton = defineComponent({
29
+ props: { label: String, disabled: Boolean },
30
+ emits: ['click'],
31
+ setup:
32
+ (props, { emit, attrs }) =>
33
+ () =>
34
+ h('button', { ...attrs, disabled: props.disabled, onClick: () => emit('click') }, props.label)
35
+ })
36
+ const FmCircularProgress = defineComponent({ setup: () => () => h('div', { class: 'spinner' }) })
37
+ const FmCard = defineComponent({
38
+ setup:
39
+ (_, { slots, attrs }) =>
40
+ () =>
41
+ h('div', attrs, slots.default?.())
42
+ })
43
+ const FmChip = defineComponent({
44
+ props: { label: String, variant: String, compact: Boolean },
45
+ setup: (props) => () => h('span', { class: 'chip', 'data-variant': props.variant }, props.label)
46
+ })
47
+ const FmIcon = defineComponent({ setup: () => () => h('i') })
48
+ const FmTooltip = defineComponent({
49
+ props: { content: String },
50
+ setup:
51
+ (props, { slots }) =>
52
+ () =>
53
+ h('div', { 'data-tooltip': props.content }, slots.default?.())
54
+ })
55
+
56
+ function mountStatus(channel: 'dineIn' | 'pickup' | 'delivery' = 'dineIn') {
57
+ return mount(PosOrderingStatus, {
58
+ props: { channel },
59
+ global: { components: { FmButton, FmCircularProgress, FmCard, FmChip, FmIcon, FmTooltip } }
60
+ })
61
+ }
62
+
63
+ const chip = (wrapper: ReturnType<typeof mountStatus>, row: string) =>
64
+ wrapper.get(`[data-testid="${row}"] .chip`)
65
+
66
+ const freshHeartbeat = () => new Date(Date.now() - 10_000).toISOString()
67
+
68
+ describe('PosOrderingStatus', () => {
69
+ beforeEach(() => {
70
+ currentRestaurant.value = { _id: RID_A }
71
+ readRestaurantPosState.mockReset()
72
+ readRestaurantSetting.mockReset()
73
+ })
74
+
75
+ it('shows the Hock Kee case: POS online but dine-in turned off on the POS', async () => {
76
+ readRestaurantPosState.mockResolvedValue({
77
+ _id: RID_A,
78
+ posHeartbeat: freshHeartbeat(),
79
+ posVersion: '8.0.2'
80
+ })
81
+ readRestaurantSetting.mockResolvedValue({ acceptDineIn: false, acceptPickup: true })
82
+ const wrapper = mountStatus('dineIn')
83
+ await flushPromises()
84
+
85
+ expect(readRestaurantPosState).toHaveBeenCalledWith(RID_A)
86
+ expect(readRestaurantSetting).toHaveBeenCalledWith(RID_A)
87
+ expect(chip(wrapper, 'pos-status-heartbeat').text()).toBe('order.posStatus.posOnline')
88
+ expect(chip(wrapper, 'pos-status-heartbeat').attributes('data-variant')).toBe('success')
89
+ expect(chip(wrapper, 'pos-status-accept').text()).toBe('order.posStatus.accept.dineIn.off')
90
+ expect(chip(wrapper, 'pos-status-accept').attributes('data-variant')).toBe('critical')
91
+ // One notice, holding only the toggle problem.
92
+ expect(wrapper.findAll('[data-testid="pos-status-notice"]')).toHaveLength(1)
93
+ expect(wrapper.get('[data-testid="pos-status-accept-off-hint"]').text()).toBe(
94
+ 'order.posStatus.acceptOffHint.dineIn'
95
+ )
96
+ expect(wrapper.find('[data-testid="pos-status-offline-hint"]').exists()).toBe(false)
97
+ })
98
+
99
+ it('shows an offline POS with its last-seen time and no hint for an "on" toggle', async () => {
100
+ readRestaurantPosState.mockResolvedValue({
101
+ _id: RID_A,
102
+ posHeartbeat: new Date(Date.now() - 31_000).toISOString(),
103
+ posVersion: '7.12.36'
104
+ })
105
+ readRestaurantSetting.mockResolvedValue({ acceptPickup: true })
106
+ const wrapper = mountStatus('pickup')
107
+ await flushPromises()
108
+
109
+ expect(chip(wrapper, 'pos-status-heartbeat').text()).toBe('order.posStatus.posOffline')
110
+ expect(chip(wrapper, 'pos-status-heartbeat').attributes('data-variant')).toBe('critical')
111
+ expect(wrapper.get('[data-testid="pos-status-last-seen"]').text()).toContain(
112
+ 'order.posStatus.lastSeen('
113
+ )
114
+ expect(wrapper.find('[data-testid="pos-status-offline-hint"]').exists()).toBe(true)
115
+ expect(chip(wrapper, 'pos-status-accept').text()).toBe('order.posStatus.accept.pickup.on')
116
+ expect(wrapper.find('[data-testid="pos-status-accept-off-hint"]').exists()).toBe(false)
117
+ })
118
+
119
+ it('says "unknown" for a failed read and still shows the other value', async () => {
120
+ readRestaurantPosState.mockRejectedValue(new Error('500'))
121
+ readRestaurantSetting.mockResolvedValue({ acceptDelivery: false })
122
+ const wrapper = mountStatus('delivery')
123
+ await flushPromises()
124
+
125
+ expect(chip(wrapper, 'pos-status-heartbeat').text()).toBe('order.posStatus.posUnknown')
126
+ expect(chip(wrapper, 'pos-status-heartbeat').attributes('data-variant')).toBe('neutral')
127
+ expect(wrapper.find('[data-testid="pos-status-load-failed"]').exists()).toBe(true)
128
+ expect(wrapper.find('[data-testid="pos-status-offline-hint"]').exists()).toBe(false)
129
+ expect(wrapper.get('[data-testid="pos-status-accept-off-hint"]').text()).toBe(
130
+ 'order.posStatus.acceptOffHint.delivery'
131
+ )
132
+ })
133
+
134
+ it('warns when the POS clock is ahead instead of showing "0 s ago"', async () => {
135
+ const future = new Date(Date.now() + 170 * 86400_000).toISOString()
136
+ readRestaurantPosState.mockResolvedValue({ _id: RID_A, posHeartbeat: future, posVersion: '7.12.40' })
137
+ readRestaurantSetting.mockResolvedValue({ acceptDineIn: false })
138
+ const wrapper = mountStatus('dineIn')
139
+ await flushPromises()
140
+
141
+ expect(chip(wrapper, 'pos-status-heartbeat').text()).toBe('order.posStatus.posOnline')
142
+ expect(wrapper.get('[data-testid="pos-status-last-seen"]').text()).toContain(
143
+ 'order.posStatus.lastSeenAt('
144
+ )
145
+ expect(wrapper.get('[data-testid="pos-status-clock-hint"]').text()).toBe(
146
+ 'order.posStatus.futureHeartbeatHint'
147
+ )
148
+ })
149
+
150
+ it('reads again on Refresh and when the outlet changes, dropping a late answer', async () => {
151
+ readRestaurantPosState.mockResolvedValue({ _id: RID_A, posHeartbeat: freshHeartbeat() })
152
+ readRestaurantSetting.mockResolvedValue({ acceptDineIn: true })
153
+ const wrapper = mountStatus('dineIn')
154
+ await flushPromises()
155
+ expect(readRestaurantSetting).toHaveBeenCalledTimes(1)
156
+
157
+ await wrapper.get('[data-testid="pos-status-refresh"]').trigger('click')
158
+ await flushPromises()
159
+ expect(readRestaurantSetting).toHaveBeenCalledTimes(2)
160
+
161
+ // Outlet A's read hangs; the user switches to B, then A's answer lands late.
162
+ let resolveA: (v: unknown) => void = () => {}
163
+ readRestaurantSetting.mockImplementationOnce(() => new Promise((r) => (resolveA = r)))
164
+ await wrapper.get('[data-testid="pos-status-refresh"]').trigger('click')
165
+ readRestaurantPosState.mockResolvedValue({ _id: RID_B, posHeartbeat: freshHeartbeat() })
166
+ readRestaurantSetting.mockResolvedValue({ acceptDineIn: true })
167
+ currentRestaurant.value = { _id: RID_B }
168
+ await flushPromises()
169
+ resolveA({ acceptDineIn: false })
170
+ await flushPromises()
171
+
172
+ expect(readRestaurantSetting).toHaveBeenLastCalledWith(RID_B)
173
+ expect(wrapper.find('[data-testid="pos-status-accept-off-hint"]').exists()).toBe(false)
174
+ expect(chip(wrapper, 'pos-status-accept').text()).toBe('order.posStatus.accept.dineIn.on')
175
+ })
176
+
177
+ it('stays quiet when all is fine: no notice, no hints', async () => {
178
+ readRestaurantPosState.mockResolvedValue({
179
+ _id: RID_A,
180
+ posHeartbeat: freshHeartbeat(),
181
+ posVersion: '8.0.2'
182
+ })
183
+ readRestaurantSetting.mockResolvedValue({ acceptDelivery: true })
184
+ const wrapper = mountStatus('delivery')
185
+ await flushPromises()
186
+
187
+ expect(chip(wrapper, 'pos-status-heartbeat').text()).toBe('order.posStatus.posOnline')
188
+ expect(chip(wrapper, 'pos-status-accept').text()).toBe('order.posStatus.accept.delivery.on')
189
+ expect(wrapper.find('[data-testid="pos-status-notice"]').exists()).toBe(false)
190
+ expect(wrapper.find('[data-testid="pos-status-clock-hint"]').exists()).toBe(false)
191
+ expect(wrapper.find('[data-testid="pos-status-load-failed"]').exists()).toBe(false)
192
+ })
193
+
194
+ it('puts both problems in the one notice when the POS is offline and the toggle is off', async () => {
195
+ readRestaurantPosState.mockResolvedValue({ _id: RID_A, posHeartbeat: null })
196
+ readRestaurantSetting.mockResolvedValue({ acceptDineIn: false })
197
+ const wrapper = mountStatus('dineIn')
198
+ await flushPromises()
199
+
200
+ expect(wrapper.findAll('[data-testid="pos-status-notice"]')).toHaveLength(1)
201
+ expect(wrapper.find('[data-testid="pos-status-accept-off-hint"]').exists()).toBe(true)
202
+ expect(wrapper.find('[data-testid="pos-status-offline-hint"]').exists()).toBe(true)
203
+ expect(wrapper.get('[data-testid="pos-status-last-seen"]').text()).toBe(
204
+ 'order.posStatus.neverSeen'
205
+ )
206
+ })
207
+ })
@@ -0,0 +1,209 @@
1
+ <template>
2
+ <FmCard variant="outlined" class="p-[16px]" data-testid="pos-status">
3
+ <div class="flex items-start gap-3">
4
+ <FmCircularProgress v-if="!checkedAt" size="md" />
5
+ <div v-else class="flex flex-col gap-2 min-w-0 flex-1">
6
+ <div class="flex items-center gap-x-3 gap-y-1 flex-wrap" data-testid="pos-status-heartbeat">
7
+ <FmChip compact :variant="onlineChip.variant" :label="onlineChip.label" />
8
+ <span
9
+ v-if="posState"
10
+ class="fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
11
+ data-testid="pos-status-last-seen"
12
+ >
13
+ {{ lastSeenText }}
14
+ </span>
15
+ </div>
16
+ <div class="flex items-center gap-x-3 gap-y-1 flex-wrap" data-testid="pos-status-accept">
17
+ <FmChip compact :variant="acceptChip.variant" :label="acceptChip.label" />
18
+ <span class="fm-typo-en-body-sm-400 text-fm-color-typo-secondary">
19
+ {{ t('order.posStatus.setOnPos') }}
20
+ </span>
21
+ </div>
22
+
23
+ <div
24
+ v-if="problems.length"
25
+ class="flex items-start gap-2 p-3 rounded-lg bg-fm-color-system-warning-100 fm-typo-en-body-sm-400 text-fm-color-typo-warning"
26
+ data-testid="pos-status-notice"
27
+ >
28
+ <FmIcon name="warning" size="sm" color="typo-warning" class="shrink-0" />
29
+ <div class="flex flex-col gap-1">
30
+ <span v-for="problem in problems" :key="problem.key" :data-testid="problem.testId">
31
+ {{ problem.text }}
32
+ </span>
33
+ </div>
34
+ </div>
35
+
36
+ <span
37
+ v-if="heartbeatInFuture"
38
+ class="fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
39
+ data-testid="pos-status-clock-hint"
40
+ >
41
+ {{ t('order.posStatus.futureHeartbeatHint') }}
42
+ </span>
43
+ <span
44
+ v-if="online === null || accept === 'unknown'"
45
+ class="fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
46
+ data-testid="pos-status-load-failed"
47
+ >
48
+ {{ t('order.posStatus.loadFailed') }}
49
+ </span>
50
+ </div>
51
+ <FmTooltip :content="refreshTooltip" :zIndex="1000">
52
+ <FmButton
53
+ variant="tertiary"
54
+ icon="refresh"
55
+ :disabled="loading"
56
+ data-testid="pos-status-refresh"
57
+ @click="load"
58
+ />
59
+ </FmTooltip>
60
+ </div>
61
+ </FmCard>
62
+ </template>
63
+
64
+ <script setup lang="ts">
65
+ /**
66
+ * Read-only POS facts that make the server refuse an online order for this
67
+ * channel: Main POS heartbeat and the POS-side accept toggle. Nothing here
68
+ * writes; both values belong to the POS. Rules live in `./pos-status.ts`.
69
+ *
70
+ * Quiet when all is fine (two status chips); one notice appears only when
71
+ * something blocks orders, naming the customer's error and the fix.
72
+ */
73
+ import { computed, ref, watch, type PropType } from 'vue'
74
+ import dayjs from 'dayjs'
75
+ import type { FmChipVariant } from '@feedmepos/ui-library'
76
+ import { useCoreStore, useI18n } from '@feedmepos/mf-common'
77
+ import { restaurantApi, type RestaurantPosState } from '@/api/restaurant-setting'
78
+ import { useRestaurantStore } from '@/stores/restaurant'
79
+ import {
80
+ channelAcceptState,
81
+ formatAge,
82
+ isHeartbeatInFuture,
83
+ isPosOnline,
84
+ type AcceptState,
85
+ type PosOrderChannel
86
+ } from './pos-status'
87
+
88
+ const props = defineProps({
89
+ channel: { type: String as PropType<PosOrderChannel>, required: true }
90
+ })
91
+
92
+ const { t } = useI18n()
93
+ const { currentRestaurant } = useCoreStore()
94
+ const restaurantStore = useRestaurantStore()
95
+
96
+ const loading = ref(false)
97
+ const checkedAt = ref<number | null>(null)
98
+ const posState = ref<RestaurantPosState | null>(null)
99
+ const accept = ref<AcceptState>('unknown')
100
+ let requestSeq = 0
101
+
102
+ // Judged once, at read time: the heartbeat itself is only as fresh as the read,
103
+ // so re-judging it against a ticking clock would turn a live POS "offline".
104
+ const online = computed<boolean | null>(() =>
105
+ posState.value && checkedAt.value !== null
106
+ ? isPosOnline(posState.value.posHeartbeat, posState.value.posVersion, checkedAt.value)
107
+ : null
108
+ )
109
+
110
+ const heartbeatInFuture = computed(() =>
111
+ isHeartbeatInFuture(posState.value?.posHeartbeat, checkedAt.value ?? Date.now())
112
+ )
113
+
114
+ type Chip = { variant: FmChipVariant; label: string }
115
+
116
+ const onlineChip = computed<Chip>(() => {
117
+ if (online.value === null) return { variant: 'neutral', label: t('order.posStatus.posUnknown') }
118
+ return online.value
119
+ ? { variant: 'success', label: t('order.posStatus.posOnline') }
120
+ : { variant: 'critical', label: t('order.posStatus.posOffline') }
121
+ })
122
+
123
+ const acceptChip = computed<Chip>(() => {
124
+ const label = t(`order.posStatus.accept.${props.channel}.${accept.value}`)
125
+ if (accept.value === 'on') return { variant: 'success', label }
126
+ if (accept.value === 'off') return { variant: 'critical', label }
127
+ return { variant: 'neutral', label }
128
+ })
129
+
130
+ const problems = computed(() => {
131
+ const list: { key: string; testId: string; text: string }[] = []
132
+ if (accept.value === 'off') {
133
+ list.push({
134
+ key: 'accept',
135
+ testId: 'pos-status-accept-off-hint',
136
+ text: t(`order.posStatus.acceptOffHint.${props.channel}`)
137
+ })
138
+ }
139
+ if (online.value === false) {
140
+ list.push({
141
+ key: 'offline',
142
+ testId: 'pos-status-offline-hint',
143
+ text: t('order.posStatus.offlineHint')
144
+ })
145
+ }
146
+ return list
147
+ })
148
+
149
+ const lastSeenText = computed(() => {
150
+ const heartbeat = posState.value?.posHeartbeat
151
+ if (!heartbeat || Number.isNaN(new Date(heartbeat).getTime())) {
152
+ return t('order.posStatus.neverSeen')
153
+ }
154
+ const time = formatTime(heartbeat, 'D MMM YYYY, HH:mm')
155
+ if (heartbeatInFuture.value) return t('order.posStatus.lastSeenAt', { time })
156
+ return t('order.posStatus.lastSeen', {
157
+ time,
158
+ age: formatAge(heartbeat, checkedAt.value ?? Date.now())
159
+ })
160
+ })
161
+
162
+ const refreshTooltip = computed(() =>
163
+ checkedAt.value === null
164
+ ? t('order.posStatus.refresh')
165
+ : t('order.posStatus.refreshCheckedAt', { time: formatTime(checkedAt.value, 'HH:mm:ss') })
166
+ )
167
+
168
+ function formatTime(value: string | number, format: string) {
169
+ return dayjs(value).format(format)
170
+ }
171
+
172
+ async function load() {
173
+ const restaurantId = currentRestaurant.value?._id
174
+ const seq = ++requestSeq
175
+ if (!restaurantId) {
176
+ posState.value = null
177
+ accept.value = 'unknown'
178
+ checkedAt.value = null
179
+ return
180
+ }
181
+ loading.value = true
182
+ // Each read stands alone: a failed heartbeat read must not hide the toggle,
183
+ // and the reverse. A failed read shows "unknown", never a guess.
184
+ const [pos, setting] = await Promise.allSettled([
185
+ restaurantApi.readRestaurantPosState(restaurantId),
186
+ restaurantStore.readRestaurantSetting(restaurantId)
187
+ ])
188
+ // The outlet selector stays clickable: drop a late answer for another outlet.
189
+ if (seq !== requestSeq || currentRestaurant.value?._id !== restaurantId) return
190
+ posState.value = pos.status === 'fulfilled' ? pos.value : null
191
+ accept.value = channelAcceptState(
192
+ setting.status === 'fulfilled' ? setting.value : null,
193
+ props.channel
194
+ )
195
+ checkedAt.value = Date.now()
196
+ loading.value = false
197
+ }
198
+
199
+ watch(
200
+ () => currentRestaurant.value?._id,
201
+ () => {
202
+ checkedAt.value = null
203
+ load()
204
+ },
205
+ { immediate: true }
206
+ )
207
+
208
+ defineExpose({ load })
209
+ </script>
@@ -0,0 +1,103 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ channelAcceptState,
4
+ formatAge,
5
+ isHeartbeatInFuture,
6
+ isPosOnline,
7
+ posHeartbeatTimeoutSeconds
8
+ } from './pos-status'
9
+
10
+ const NOW = Date.parse('2026-11-05T02:51:00.000Z')
11
+ const secondsAgo = (s: number) => new Date(NOW - s * 1000).toISOString()
12
+
13
+ describe('posHeartbeatTimeoutSeconds (mirrors Restaurant.isHeartbeatExpired)', () => {
14
+ it('gives POS v8, pre-releases included, 120 seconds', () => {
15
+ expect(posHeartbeatTimeoutSeconds('8.0.2')).toBe(120)
16
+ expect(posHeartbeatTimeoutSeconds('8.0.0-beta.29')).toBe(120)
17
+ })
18
+
19
+ it('gives v7, other majors and unreadable versions 30 seconds', () => {
20
+ expect(posHeartbeatTimeoutSeconds('7.12.36+7.12.36')).toBe(30)
21
+ expect(posHeartbeatTimeoutSeconds('9.0.0')).toBe(30)
22
+ // semver.parse is strict on the server, so a loose version is not "v8".
23
+ expect(posHeartbeatTimeoutSeconds('8.0.2 (123)')).toBe(30)
24
+ expect(posHeartbeatTimeoutSeconds('')).toBe(30)
25
+ expect(posHeartbeatTimeoutSeconds(null)).toBe(30)
26
+ expect(posHeartbeatTimeoutSeconds(undefined)).toBe(30)
27
+ })
28
+ })
29
+
30
+ describe('isPosOnline', () => {
31
+ it('is online inside the timeout and offline at the exact boundary', () => {
32
+ expect(isPosOnline(secondsAgo(29), '7.12.36', NOW)).toBe(true)
33
+ expect(isPosOnline(secondsAgo(30), '7.12.36', NOW)).toBe(false)
34
+ expect(isPosOnline(secondsAgo(119), '8.0.2', NOW)).toBe(true)
35
+ expect(isPosOnline(secondsAgo(120), '8.0.2', NOW)).toBe(false)
36
+ })
37
+
38
+ it('reads a v8 POS 60 seconds old as online but a v7 POS as offline', () => {
39
+ expect(isPosOnline(secondsAgo(60), '8.0.0', NOW)).toBe(true)
40
+ expect(isPosOnline(secondsAgo(60), '7.9.9', NOW)).toBe(false)
41
+ })
42
+
43
+ it('treats a missing or unreadable heartbeat as offline', () => {
44
+ expect(isPosOnline(undefined, '8.0.2', NOW)).toBe(false)
45
+ expect(isPosOnline(null, '8.0.2', NOW)).toBe(false)
46
+ expect(isPosOnline('', '8.0.2', NOW)).toBe(false)
47
+ expect(isPosOnline('invalid', '8.0.2', NOW)).toBe(false)
48
+ })
49
+
50
+ it('accepts a Date heartbeat', () => {
51
+ expect(isPosOnline(new Date(NOW - 5_000), '8.0.2', NOW)).toBe(true)
52
+ })
53
+ })
54
+
55
+ describe('channelAcceptState', () => {
56
+ it('reads the toggle of each channel', () => {
57
+ const setting = { acceptDineIn: false, acceptPickup: true, acceptDelivery: true }
58
+ expect(channelAcceptState(setting, 'dineIn')).toBe('off')
59
+ expect(channelAcceptState(setting, 'pickup')).toBe('on')
60
+ expect(channelAcceptState(setting, 'delivery')).toBe('on')
61
+ })
62
+
63
+ it('counts a missing toggle as off, like the submit gate', () => {
64
+ expect(channelAcceptState({}, 'dineIn')).toBe('off')
65
+ expect(channelAcceptState({ acceptDineIn: null }, 'dineIn')).toBe('off')
66
+ })
67
+
68
+ it('is unknown when the setting could not be read', () => {
69
+ expect(channelAcceptState(null, 'dineIn')).toBe('unknown')
70
+ expect(channelAcceptState(undefined, 'pickup')).toBe('unknown')
71
+ })
72
+ })
73
+
74
+ describe('formatAge', () => {
75
+ it('uses the largest whole unit', () => {
76
+ expect(formatAge(secondsAgo(45), NOW)).toBe('45 s')
77
+ expect(formatAge(secondsAgo(12 * 60 + 5), NOW)).toBe('12 min')
78
+ expect(formatAge(secondsAgo(3 * 3600), NOW)).toBe('3 h')
79
+ expect(formatAge(secondsAgo(9 * 86400), NOW)).toBe('9 d')
80
+ })
81
+
82
+ it('never shows a negative age for a clock ahead of ours', () => {
83
+ expect(formatAge(new Date(NOW + 10_000).toISOString(), NOW)).toBe('0 s')
84
+ })
85
+ })
86
+
87
+ describe('isHeartbeatInFuture', () => {
88
+ it('flags a heartbeat more than a minute ahead of our clock', () => {
89
+ expect(isHeartbeatInFuture('2027-04-24T04:38:30.000Z', NOW)).toBe(true)
90
+ expect(isHeartbeatInFuture(new Date(NOW + 61_000), NOW)).toBe(true)
91
+ })
92
+
93
+ it('allows small clock drift and ignores past, missing or bad values', () => {
94
+ expect(isHeartbeatInFuture(new Date(NOW + 30_000), NOW)).toBe(false)
95
+ expect(isHeartbeatInFuture(secondsAgo(5), NOW)).toBe(false)
96
+ expect(isHeartbeatInFuture(undefined, NOW)).toBe(false)
97
+ expect(isHeartbeatInFuture('invalid', NOW)).toBe(false)
98
+ })
99
+
100
+ it('still reads as online on the server rule, which is why it is flagged', () => {
101
+ expect(isPosOnline('2027-04-24T04:38:30.000Z', '7.12.40', NOW)).toBe(true)
102
+ })
103
+ })