@feedmepos/mf-order-setting 0.0.98 → 0.0.99

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 (66) hide show
  1. package/dist/{DisplaySystemView-B3xrnpj3.js → DisplaySystemView-Brrexhuz.js} +4 -4
  2. package/dist/FoodCourtInvitationsView-wmZ1J7dm.js +402 -0
  3. package/dist/{FoodCourtOrderSettingsView-BR5PgIx5.js → FoodCourtOrderSettingsView-CNZs4q-x.js} +1 -1
  4. package/dist/{FoodCourtOrdersView-BZ8YxJ9y.js → FoodCourtOrdersView-DMvZ_Z_C.js} +4 -4
  5. package/dist/{FoodCourtStallsView-zZyzPDe2.js → FoodCourtStallsView-B3egjtKo.js} +3 -3
  6. package/dist/{FoodCourtStatusView-D42wymS-.js → FoodCourtStatusView-YdiL94wn.js} +2 -2
  7. package/dist/{KioskDevicesView-PuAwkC1s.js → KioskDevicesView-DsXy1LWl.js} +1 -1
  8. package/dist/{KioskDevicesView.vue_vue_type_script_setup_true_lang-CUriyLui.js → KioskDevicesView.vue_vue_type_script_setup_true_lang-Byoci4Fo.js} +5 -5
  9. package/dist/{KioskSettingView-CuA3Lvdr.js → KioskSettingView-DqUpOq_Y.js} +3 -3
  10. package/dist/{KioskView-E5ePu5Zf.js → KioskView-CdRnNSU0.js} +6 -6
  11. package/dist/{OrderSettingsView-DZP2aZ58.js → OrderSettingsView-CjXph68w.js} +21844 -21729
  12. package/dist/RestaurantSelector.vue_vue_type_script_setup_true_lang-BG71fNkx.js +92 -0
  13. package/dist/{app-CWx14lJE.js → app-moKDIx07.js} +413 -353
  14. package/dist/app.js +1 -1
  15. package/dist/common/queue/called-sms.d.ts +45 -0
  16. package/dist/common/sms/sms-parts.d.ts +23 -0
  17. package/dist/{dayjs.min-sDkYDUoj.js → dayjs.min-DQqlQ2dX.js} +1 -1
  18. package/dist/{featureFlag-Dh37Fdlx.js → featureFlag-qLUdllY9.js} +1 -1
  19. package/dist/{food-court-member-piX3gesl.js → food-court-member-CfV5vmHz.js} +24 -20
  20. package/dist/frontend/mf-order/src/app.d.ts +60 -0
  21. package/dist/frontend/mf-order/src/main.d.ts +60 -0
  22. package/dist/frontend/mf-order/src/stores/order-setting/index.d.ts +3 -0
  23. package/dist/frontend/mf-order/src/views/food-court/food-court-member.d.ts +5 -0
  24. package/dist/frontend/mf-order/src/views/order-settings/components/RestaurantSelector.vue.d.ts +7 -1
  25. package/dist/frontend/mf-order/src/views/order-settings/dine-in/reservation-pos.d.ts +8 -0
  26. package/dist/frontend/mf-order/src/views/order-settings/queue/auto-cancel-minutes.d.ts +2 -2
  27. package/dist/frontend/mf-order/src/views/order-settings/queue/called-message.d.ts +31 -0
  28. package/dist/frontend/mf-order/src/views/order-settings/reservation/CopySettingsSheet.vue.d.ts +8 -0
  29. package/dist/frontend/mf-order/tsconfig.app.tsbuildinfo +1 -1
  30. package/dist/{index-dcHvfBC0.js → index-BDgJZqqD.js} +4 -4
  31. package/dist/{index-BsryfWF5.js → index-BthRwhFh.js} +1 -1
  32. package/dist/{index-EXn8TQyw.js → index-By3yKf-8.js} +1 -1
  33. package/dist/{index-EVX4Oil9.js → index-C44A5dgm.js} +1 -1
  34. package/dist/{index-D5bW0yrg.js → index-D5T7zJ3M.js} +1 -1
  35. package/dist/{index-DToeF1mu.js → index-Dy5GRKwA.js} +2 -2
  36. package/dist/{order.dto-DewGFVgb.js → order.dto-DvP9y_72.js} +850 -832
  37. package/dist/package/entity/order-setting/order-setting.do.d.ts +39 -0
  38. package/dist/package/entity/order-setting/order-setting.dto.d.ts +10 -0
  39. package/dist/package/entity/order-setting/queue/queue.do.d.ts +12 -0
  40. package/dist/package/entity/order-setting/queue/queue.dto.d.ts +3 -0
  41. package/dist/package/entity/order-setting/reservationV2/reservation.do.d.ts +56 -0
  42. package/dist/package/entity/queue/queue.dto.d.ts +2 -2
  43. package/dist/package/entity/reservation/reservation-pos.do.d.ts +5 -0
  44. package/dist/package/entity/reservation/reservation.dto.d.ts +9 -0
  45. package/dist/package/entity/restaurant/restaurant.dto.d.ts +10 -0
  46. package/package.json +1 -1
  47. package/src/locales/en-US.json +16 -1
  48. package/src/locales/ja-JP.json +16 -1
  49. package/src/locales/th-TH.json +16 -1
  50. package/src/locales/zh-CN.json +16 -1
  51. package/src/views/food-court/FoodCourtInvitationsView.vue +72 -38
  52. package/src/views/food-court/food-court-member.spec.ts +11 -0
  53. package/src/views/food-court/food-court-member.ts +10 -0
  54. package/src/views/order-settings/OrderSettingsView.vue +5 -2
  55. package/src/views/order-settings/components/RestaurantSelector.vue +11 -3
  56. package/src/views/order-settings/dine-in/DineInSetting.vue +19 -1
  57. package/src/views/order-settings/dine-in/reservation-pos.spec.ts +27 -0
  58. package/src/views/order-settings/dine-in/reservation-pos.ts +17 -0
  59. package/src/views/order-settings/queue/QueueSetting.source.spec.ts +1 -1
  60. package/src/views/order-settings/queue/QueueSetting.vue +111 -3
  61. package/src/views/order-settings/queue/auto-cancel-minutes.ts +2 -4
  62. package/src/views/order-settings/queue/called-message.spec.ts +124 -0
  63. package/src/views/order-settings/queue/called-message.ts +84 -0
  64. package/src/views/order-settings/reservation/CopySettingsSheet.vue +4 -1
  65. package/src/views/order-settings/reservation/ReservationSetting.vue +54 -1
  66. package/dist/FoodCourtInvitationsView-D9rNuL-B.js +0 -383
@@ -0,0 +1,124 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { checkCalledMessage, previewQueueCode, withAutoCancelToken } from './called-message'
3
+
4
+ /**
5
+ * The preview must be exactly what queue-backend sends (both use
6
+ * common/queue/called-sms.ts), and the counts must match what sms-backend bills
7
+ * (common/sms/sms-parts.ts), so a merchant sees the real cost before saving.
8
+ */
9
+ const base = { restaurantName: 'Gepuklah', queueCode: 'A012', country: 'MY' }
10
+
11
+ describe('previewQueueCode', () => {
12
+ it('is the longest code the outlet can issue, as newCode pads it', () => {
13
+ expect(previewQueueCode(undefined)).toBe('01')
14
+ expect(previewQueueCode([{ prefix: null, end: 99 }])).toBe('01')
15
+ expect(
16
+ previewQueueCode([
17
+ { prefix: 'A', end: 99 },
18
+ { prefix: 'VIP-', end: 999 }
19
+ ])
20
+ ).toBe('VIP-001')
21
+ })
22
+
23
+ it('counts with that code, so a long prefix can tip the SMS into 2 parts', () => {
24
+ const line = 'x'.repeat(102)
25
+ expect(checkCalledMessage({ ...base, queueCode: '01', calledMessage: line }).parts).toBe(1)
26
+ expect(checkCalledMessage({ ...base, queueCode: 'VIP-001', calledMessage: line }).parts).toBe(2)
27
+ })
28
+ })
29
+
30
+ describe('checkCalledMessage', () => {
31
+ it('previews today’s message when nothing is set', () => {
32
+ const check = checkCalledMessage(base)
33
+ expect(check.preview).toBe(
34
+ '[FEEDME] - Calling From Gepuklah\n\nQueue Code #A012\nPlease travel to the restaurant now to be served.'
35
+ )
36
+ expect(check.parts).toBe(1)
37
+ expect(check.warnings).toEqual([])
38
+ })
39
+
40
+ it('previews the merchant line with the minutes filled in', () => {
41
+ const check = checkCalledMessage({
42
+ ...base,
43
+ calledMessage: 'Please come within {{autoCancelMinutes}} mins or we will cancel your queue.',
44
+ autoCancelCalledMinutes: 15
45
+ })
46
+ expect(check.preview.endsWith('Please come within 15 mins or we will cancel your queue.')).toBe(
47
+ true
48
+ )
49
+ expect(check.warnings).toEqual([])
50
+ })
51
+
52
+ it('warns when the timer is on but the line does not mention it', () => {
53
+ expect(
54
+ checkCalledMessage({
55
+ ...base,
56
+ calledMessage: 'Come now please.',
57
+ autoCancelCalledMinutes: 15
58
+ }).warnings
59
+ ).toEqual(['timerNotMentioned'])
60
+ })
61
+
62
+ it('warns that the placeholder line is not sent while the timer is off', () => {
63
+ const check = checkCalledMessage({
64
+ ...base,
65
+ calledMessage: 'Come within {{autoCancelMinutes}} mins.',
66
+ autoCancelCalledMinutes: 0
67
+ })
68
+ expect(check.warnings).toEqual(['placeholderWhileTimerOff'])
69
+ expect(check.preview.endsWith('Please travel to the restaurant now to be served.')).toBe(true)
70
+ })
71
+
72
+ it('warns about cost when the message needs more than one SMS', () => {
73
+ const check = checkCalledMessage({ ...base, calledMessage: 'x'.repeat(120) })
74
+ expect(check.parts).toBe(2)
75
+ expect(check.warnings).toContain('multiPart')
76
+ })
77
+
78
+ it('warns that a curly quote switches to the 70-character limit', () => {
79
+ // 69 characters in 70-character mode still fits; one more sentence does not.
80
+ expect(checkCalledMessage({ ...base, calledMessage: 'We’ll hold it.' }).warnings).toEqual([
81
+ 'notSevenBit'
82
+ ])
83
+ expect(
84
+ checkCalledMessage({ ...base, calledMessage: 'We’ll hold your table for a while.' }).warnings
85
+ ).toEqual(['multiPart', 'notSevenBit'])
86
+ })
87
+
88
+ it('warns about links and phone numbers for Malaysia only', () => {
89
+ const line = 'Call 012-345 6789 if late.'
90
+ expect(checkCalledMessage({ ...base, calledMessage: line }).warnings).toContain('linkOrPhone')
91
+ expect(
92
+ checkCalledMessage({ ...base, country: 'SG', calledMessage: line }).warnings
93
+ ).not.toContain('linkOrPhone')
94
+ expect(
95
+ checkCalledMessage({ ...base, calledMessage: 'See www.gepuklah.my' }).warnings
96
+ ).toContain('linkOrPhone')
97
+ for (const phone of ['(03) 1234 5678', '03.1234.5678', '+60 12 345 6789']) {
98
+ expect(checkCalledMessage({ ...base, calledMessage: `Call ${phone}` }).warnings).toContain(
99
+ 'linkOrPhone'
100
+ )
101
+ }
102
+ })
103
+
104
+ it('does not take a 2-digit minute count for a phone number', () => {
105
+ expect(checkCalledMessage({ ...base, calledMessage: 'Come within 15 mins.' }).warnings).toEqual(
106
+ []
107
+ )
108
+ })
109
+
110
+ it('lists placeholders it cannot fill', () => {
111
+ expect(checkCalledMessage({ ...base, calledMessage: 'Hi {{name}}' }).unknownTokens).toEqual([
112
+ 'name'
113
+ ])
114
+ })
115
+ })
116
+
117
+ describe('withAutoCancelToken', () => {
118
+ it('appends the placeholder with one space', () => {
119
+ expect(withAutoCancelToken('')).toBe('{{autoCancelMinutes}}')
120
+ expect(withAutoCancelToken(null)).toBe('{{autoCancelMinutes}}')
121
+ expect(withAutoCancelToken('within')).toBe('within {{autoCancelMinutes}}')
122
+ expect(withAutoCancelToken('within ')).toBe('within {{autoCancelMinutes}}')
123
+ })
124
+ })
@@ -0,0 +1,84 @@
1
+ import {
2
+ AUTO_CANCEL_MINUTES_TOKEN,
3
+ calledLine,
4
+ queueSmsHeader,
5
+ unknownQueueSmsTokens,
6
+ usesAutoCancelMinutes,
7
+ isAutoCancelOn
8
+ } from '@common/queue/called-sms'
9
+ import { countSmsParts } from '@common/sms/sms-parts'
10
+
11
+ export const AUTO_CANCEL_TOKEN = `{{${AUTO_CANCEL_MINUTES_TOKEN}}}`
12
+
13
+ /**
14
+ * Links and phone numbers: Malaysian carriers are reported to block SMS carrying either.
15
+ * Phone numbers as merchants write them: `012-345 6789`, `+60 12 345 6789`,
16
+ * `(03) 1234 5678`, `03.1234.5678`.
17
+ */
18
+ const LINK_OR_PHONE = /https?:\/\/|www\.|\+?\(?\d[\d\s().-]{6,}\d/i
19
+
20
+ /**
21
+ * The longest code this outlet can issue: the longest segment prefix plus the
22
+ * running number padded to its segment's `end`, as queue-backend's `newCode`
23
+ * does. Counting with it keeps the SMS count from undershooting the real bill.
24
+ */
25
+ export function previewQueueCode(
26
+ codeSettings: { prefix?: string | null; end?: number | null }[] | null | undefined
27
+ ): string {
28
+ const codes = (codeSettings ?? []).map(
29
+ (s) => `${s.prefix ?? ''}${'1'.padStart((s.end ?? 99).toString().length, '0')}`
30
+ )
31
+ return codes.reduce((longest, code) => (code.length > longest.length ? code : longest), '01')
32
+ }
33
+
34
+ export type CalledMessageWarning =
35
+ 'multiPart' | 'notSevenBit' | 'linkOrPhone' | 'timerNotMentioned' | 'placeholderWhileTimerOff'
36
+
37
+ export type CalledMessageCheck = {
38
+ /** The whole SMS as queue-backend would send it, with the outlet's longest code. */
39
+ preview: string
40
+ length: number
41
+ parts: number
42
+ /** Placeholders we do not fill; saving is refused while there are any. */
43
+ unknownTokens: string[]
44
+ warnings: CalledMessageWarning[]
45
+ }
46
+
47
+ /** What the merchant's called line turns into, and what they should know before saving it. */
48
+ export function checkCalledMessage({
49
+ calledMessage,
50
+ autoCancelCalledMinutes,
51
+ restaurantName,
52
+ queueCode = '01',
53
+ country
54
+ }: {
55
+ calledMessage?: string | null
56
+ autoCancelCalledMinutes?: number | null
57
+ restaurantName: string
58
+ /** See `previewQueueCode`. */
59
+ queueCode?: string
60
+ country?: string | null
61
+ }): CalledMessageCheck {
62
+ const preview =
63
+ queueSmsHeader(restaurantName, queueCode) +
64
+ calledLine({ calledMessage, autoCancelCalledMinutes })
65
+ const { length, parts, sevenBit } = countSmsParts(preview, country)
66
+ const custom = calledMessage?.trim() ?? ''
67
+ const timerOn = isAutoCancelOn(autoCancelCalledMinutes)
68
+
69
+ const warnings: CalledMessageWarning[] = []
70
+ if (parts > 1) warnings.push('multiPart')
71
+ if (!sevenBit) warnings.push('notSevenBit')
72
+ if (country === 'MY' && LINK_OR_PHONE.test(custom)) warnings.push('linkOrPhone')
73
+ if (custom && timerOn && !usesAutoCancelMinutes(custom)) warnings.push('timerNotMentioned')
74
+ if (custom && !timerOn && usesAutoCancelMinutes(custom)) warnings.push('placeholderWhileTimerOff')
75
+
76
+ return { preview, length, parts, unknownTokens: unknownQueueSmsTokens(custom), warnings }
77
+ }
78
+
79
+ /** `line` with the auto-cancel placeholder added at the end. */
80
+ export function withAutoCancelToken(line: string | null | undefined): string {
81
+ const text = line ?? ''
82
+ if (!text) return AUTO_CANCEL_TOKEN
83
+ return /\s$/.test(text) ? `${text}${AUTO_CANCEL_TOKEN}` : `${text} ${AUTO_CANCEL_TOKEN}`
84
+ }
@@ -194,8 +194,11 @@ async function handleApply() {
194
194
  }
195
195
 
196
196
  if (configOptions.value.preorder) {
197
- // Copy preorder setting
197
+ // Copy preorder setting, with the cancel window that only pre-orders have
198
198
  updatedRange.enablePreorder = sourceRange.enablePreorder
199
+ updatedRange.freeCancellationBefore = sourceRange.freeCancellationBefore
200
+ ? { ...sourceRange.freeCancellationBefore }
201
+ : null
199
202
  }
200
203
 
201
204
  if (configOptions.value.guestPreferences) {
@@ -80,7 +80,10 @@ function createDefaultRange(index = 0): FdoReservationRange {
80
80
  ...generateRangeDefaults(index),
81
81
  enable: false,
82
82
  bookingDuration: 90,
83
- enablePreorder: true,
83
+ // Off until the merchant chooses it: since KDI-4039 the switch really
84
+ // lets guests pre-order (it did nothing before).
85
+ enablePreorder: false,
86
+ freeCancellationBefore: null,
84
87
  minLeadDuration: {
85
88
  value: 0,
86
89
  unit: 'day'
@@ -553,6 +556,24 @@ function updateMaxLeadPreset(value: number | 'custom') {
553
556
  }
554
557
  }
555
558
 
559
+ /** Pre-order bookings only; off (null) means guests may always cancel online. */
560
+ function toggleFreeCancellation(enabled: boolean) {
561
+ rangeSetting.value.freeCancellationBefore = enabled ? { value: 1, unit: 'day' } : null
562
+ }
563
+
564
+ function updateFreeCancellationValue(value: number) {
565
+ if (rangeSetting.value.freeCancellationBefore) {
566
+ // At least 1: a typed 0 would put the deadline after the booking, so it never locks.
567
+ rangeSetting.value.freeCancellationBefore.value = Math.max(1, Math.floor(Number(value) || 0))
568
+ }
569
+ }
570
+
571
+ function updateFreeCancellationUnit(unit: 'hour' | 'day') {
572
+ if (rangeSetting.value.freeCancellationBefore) {
573
+ rangeSetting.value.freeCancellationBefore.unit = unit
574
+ }
575
+ }
576
+
556
577
  function updateMinLeadValue(value: number) {
557
578
  rangeSetting.value.minLeadDuration.value = value
558
579
  }
@@ -1308,6 +1329,38 @@ function handleCopySettings(copiedSettings: Partial<FdoOrderReservationSettingsV
1308
1329
  :model-value="rangeSetting.enablePreorder"
1309
1330
  @update:model-value="(v: boolean) => (rangeSetting.enablePreorder = v)"
1310
1331
  />
1332
+ <!-- Also shown while a window is stored with pre-order off: the server still applies
1333
+ it to bookings that already carry a pre-order, so it must stay visible to turn off. -->
1334
+ <div
1335
+ v-if="rangeSetting.enablePreorder || rangeSetting.freeCancellationBefore"
1336
+ class="ml-32 mt-12 p-16 border rounded-md bg-fm-color-neutral-gray-50"
1337
+ >
1338
+ <FmSwitch
1339
+ label-placement="right"
1340
+ :label="'Limit online cancellation'"
1341
+ :sublabel="'Guests with a pre-order can cancel online only until this long before their booking. After that they need to call the outlet. Staff can still cancel on the POS.'"
1342
+ :model-value="!!rangeSetting.freeCancellationBefore"
1343
+ @update:model-value="(v: boolean) => toggleFreeCancellation(v)"
1344
+ />
1345
+ <div v-if="rangeSetting.freeCancellationBefore" class="flex items-center gap-8 mt-12">
1346
+ <div class="fm-typo-en-body-md-600">Free cancellation until</div>
1347
+ <FmStepperField
1348
+ :model-value="rangeSetting.freeCancellationBefore.value"
1349
+ @update:model-value="(v: number) => updateFreeCancellationValue(v)"
1350
+ :min="1"
1351
+ />
1352
+ <FmSelect
1353
+ :model-value="rangeSetting.freeCancellationBefore.unit"
1354
+ @update:model-value="(v: 'hour' | 'day') => updateFreeCancellationUnit(v)"
1355
+ :items="[
1356
+ { label: 'Hours', value: 'hour' },
1357
+ { label: 'Days', value: 'day' }
1358
+ ]"
1359
+ class="w-120"
1360
+ />
1361
+ <div class="fm-typo-en-body-md-400">before the booking</div>
1362
+ </div>
1363
+ </div>
1311
1364
  </div>
1312
1365
 
1313
1366
  <div class="flex flex-col">
@@ -1,383 +0,0 @@
1
- import { defineComponent as K, resolveComponent as C, openBlock as u, createBlock as P, withCtx as D, createVNode as y, unref as r, createCommentVNode as S, ref as b, computed as F, watch as Y, createElementVNode as d, toDisplayString as p, createElementBlock as m, Fragment as N, withKeys as G, h as R, isRef as O } from "vue";
2
- import { d as W } from "./dayjs.min-sDkYDUoj.js";
3
- import { useI18n as H, useCoreStore as Q } from "@feedmepos/mf-common";
4
- import { useDialog as X, components as Z } from "@feedmepos/ui-library";
5
- import { u as ee } from "./snackbar-DZQ0_reQ.js";
6
- import { u as te } from "./search-BAPEUu1R.js";
7
- import { g as $, b as q } from "./index-BsryfWF5.js";
8
- import { f as oe } from "./index-EXn8TQyw.js";
9
- import { i as ae, n as V, k as ne, l as re, e as E, M as se, m as le } from "./food-court-member-piX3gesl.js";
10
- const U = () => q("/foodcourt-v2/join-codes"), J = {
11
- /** One item per court that has a row for this restaurant. */
12
- async listMemberships(v) {
13
- return $(
14
- await q(`/restaurants/${v}/foodcourt-memberships`).get("")
15
- );
16
- },
17
- /** Leave a food court this restaurant has joined; rejoining needs a new join code. */
18
- async leaveFoodCourt(v, t) {
19
- return $(
20
- await oe(v).post("/members/leave", { memberId: t })
21
- );
22
- },
23
- /** Which court a code belongs to. A wrong code counts as a failed attempt. */
24
- async previewJoinCode(v) {
25
- return $(
26
- await U().post("/preview", { code: v })
27
- );
28
- },
29
- /** Ask to join the code's court as `restaurantId`; the owner then approves or declines. */
30
- async redeemJoinCode(v, t) {
31
- return $(
32
- await U().post("/redeem", { code: v, restaurantId: t })
33
- );
34
- }
35
- }, ie = /* @__PURE__ */ K({
36
- __name: "MembershipRowActions",
37
- props: {
38
- status: {}
39
- },
40
- emits: ["leave"],
41
- setup(v, { emit: t }) {
42
- const l = t, { t: f } = H();
43
- return (h, i) => {
44
- const s = C("FmButton"), _ = C("FmMenuItem"), c = C("FmMenu");
45
- return v.status === "JOINED" ? (u(), P(c, {
46
- key: 0,
47
- "stop-click-propagation": ""
48
- }, {
49
- "menu-button": D(() => [
50
- y(s, {
51
- variant: "tertiary",
52
- icon: "more_vert"
53
- })
54
- ]),
55
- default: D(() => [
56
- y(_, {
57
- label: r(f)("order.foodCourt.invitations.leave"),
58
- onClick: i[0] || (i[0] = (B) => l("leave"))
59
- }, null, 8, ["label"])
60
- ]),
61
- _: 1
62
- })) : S("", !0);
63
- };
64
- }
65
- }), ue = { class: "flex flex-col gap-1" }, de = { class: "fm-typo-en-title-sm-600" }, ce = {
66
- key: 0,
67
- class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
68
- }, me = { class: "flex flex-col gap-1 p-3 rounded-lg bg-fm-color-neutral-gray-100 min-w-0" }, ve = { class: "fm-typo-en-body-lg-600 break-words" }, fe = {
69
- key: 0,
70
- class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary break-words"
71
- }, pe = {
72
- key: 1,
73
- class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
74
- }, ye = {
75
- key: 0,
76
- class: "fm-typo-en-body-md-400 text-fm-color-typo-error"
77
- }, _e = { class: "flex gap-8 flex-wrap" }, Ce = { class: "flex items-start gap-3" }, he = { class: "flex flex-col gap-1 min-w-0" }, be = { class: "fm-typo-en-body-lg-600" }, ge = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary break-words" }, xe = /* @__PURE__ */ K({
78
- __name: "JoinFoodCourtCard",
79
- props: {
80
- restaurantId: {},
81
- restaurantName: {}
82
- },
83
- setup(v) {
84
- const t = v, { t: l } = H(), f = b("enter"), h = b(""), i = b(!1), s = b(null), _ = b(null), c = b(""), B = F(() => t.restaurantName || t.restaurantId), g = F(() => {
85
- var o;
86
- return ae((o = _.value) == null ? void 0 : o.address);
87
- }), x = F(() => {
88
- var e;
89
- const o = (e = _.value) == null ? void 0 : e.stall, n = [
90
- o != null && o.unitNo ? l("order.foodCourt.invitations.stallBadge", { number: o.unitNo }) : null,
91
- (o == null ? void 0 : o.displayName) || null
92
- ].filter(Boolean);
93
- return n.length ? l("order.foodCourt.invitations.joinAsStall", { stall: n.join(" · ") }) : null;
94
- });
95
- function k(o) {
96
- const n = re(o);
97
- return n ? l(n) : E(o);
98
- }
99
- function w() {
100
- f.value = "enter", h.value = "", s.value = null, _.value = null;
101
- }
102
- Y(
103
- () => t.restaurantId,
104
- () => w()
105
- );
106
- async function A() {
107
- if (i.value) return;
108
- if (!ne(h.value)) {
109
- s.value = l("order.foodCourt.joinErrors.malformed");
110
- return;
111
- }
112
- const o = t.restaurantId;
113
- i.value = !0, s.value = null;
114
- try {
115
- const n = await J.previewJoinCode(V(h.value));
116
- if (o !== t.restaurantId) return;
117
- _.value = n, f.value = "preview";
118
- } catch (n) {
119
- if (o !== t.restaurantId) return;
120
- s.value = k(n);
121
- } finally {
122
- i.value = !1;
123
- }
124
- }
125
- async function M() {
126
- const o = _.value;
127
- if (!o || i.value) return;
128
- const n = t.restaurantId;
129
- i.value = !0, s.value = null;
130
- try {
131
- const e = await J.redeemJoinCode(
132
- V(h.value),
133
- n
134
- );
135
- if (n !== t.restaurantId) return;
136
- c.value = e.name || o.name, f.value = "sent";
137
- } catch (e) {
138
- if (n !== t.restaurantId) return;
139
- s.value = k(e);
140
- } finally {
141
- i.value = !1;
142
- }
143
- }
144
- return (o, n) => {
145
- const e = C("FmTextField"), a = C("FmButton"), j = C("FmIcon"), T = C("FmCard");
146
- return u(), P(T, {
147
- variant: "outlined",
148
- class: "p-16 flex flex-col gap-16 max-w-[560px]"
149
- }, {
150
- default: D(() => [
151
- d("div", ue, [
152
- d("span", de, p(r(l)("order.foodCourt.invitations.joinTitle")), 1),
153
- f.value === "enter" ? (u(), m("span", ce, p(r(l)("order.foodCourt.invitations.joinIntro")), 1)) : S("", !0)
154
- ]),
155
- f.value === "enter" ? (u(), m(N, { key: 0 }, [
156
- y(e, {
157
- modelValue: h.value,
158
- "onUpdate:modelValue": [
159
- n[0] || (n[0] = (I) => h.value = I),
160
- n[1] || (n[1] = (I) => s.value = null)
161
- ],
162
- label: r(l)("order.foodCourt.invitations.joinCode"),
163
- placeholder: "ABCDE-FGHJK",
164
- "max-length": 24,
165
- formatter: (I) => I.toUpperCase(),
166
- "helper-text": s.value ?? "",
167
- "helper-state": s.value ? "error" : "none",
168
- invalid: !!s.value,
169
- disabled: i.value,
170
- onKeydown: G(A, ["enter"])
171
- }, null, 8, ["modelValue", "label", "formatter", "helper-text", "helper-state", "invalid", "disabled"]),
172
- d("div", null, [
173
- y(a, {
174
- variant: "primary",
175
- label: r(l)("order.foodCourt.invitations.preview"),
176
- disabled: i.value || !r(V)(h.value),
177
- onClick: A
178
- }, null, 8, ["label", "disabled"])
179
- ])
180
- ], 64)) : f.value === "preview" && _.value ? (u(), m(N, { key: 1 }, [
181
- d("div", me, [
182
- d("span", ve, p(_.value.name), 1),
183
- g.value ? (u(), m("span", fe, p(g.value), 1)) : S("", !0),
184
- x.value ? (u(), m("span", pe, p(x.value), 1)) : S("", !0)
185
- ]),
186
- s.value ? (u(), m("span", ye, p(s.value), 1)) : S("", !0),
187
- d("div", _e, [
188
- y(a, {
189
- variant: "primary",
190
- label: r(l)("order.foodCourt.invitations.requestToJoin", { restaurant: B.value }),
191
- disabled: i.value,
192
- onClick: M
193
- }, null, 8, ["label", "disabled"]),
194
- y(a, {
195
- variant: "secondary",
196
- label: r(l)("order.foodCourt.invitations.useAnotherCode"),
197
- disabled: i.value,
198
- onClick: w
199
- }, null, 8, ["label", "disabled"])
200
- ])
201
- ], 64)) : f.value === "sent" ? (u(), m(N, { key: 2 }, [
202
- d("div", Ce, [
203
- y(j, {
204
- name: "check_circle",
205
- size: "lg",
206
- color: "system-success-300"
207
- }),
208
- d("div", he, [
209
- d("span", be, p(r(l)("order.foodCourt.invitations.requestSent")), 1),
210
- d("span", ge, p(r(l)("order.foodCourt.invitations.requestSentDetail", { court: c.value })), 1)
211
- ])
212
- ]),
213
- d("div", null, [
214
- y(a, {
215
- variant: "secondary",
216
- label: r(l)("order.foodCourt.invitations.joinAnother"),
217
- onClick: w
218
- }, null, 8, ["label"])
219
- ])
220
- ], 64)) : S("", !0)
221
- ]),
222
- _: 1
223
- });
224
- };
225
- }
226
- }), we = { class: "py-[1.5rem]" }, Fe = {
227
- key: 0,
228
- class: "px-[1.5rem] fm-typo-en-body-md-400 text-fm-color-typo-secondary"
229
- }, ke = {
230
- key: 1,
231
- class: "px-[1.5rem] flex flex-col gap-6"
232
- }, Ie = { class: "flex flex-col gap-16" }, Se = { class: "fm-typo-en-title-sm-600" }, Ae = {
233
- key: 0,
234
- class: "flex flex-col gap-3 items-start"
235
- }, Me = { class: "fm-typo-en-body-md-400" }, je = {
236
- key: 1,
237
- class: "text-center py-32 text-fm-color-typo-tertiary fm-typo-en-body-md-400"
238
- }, Pe = /* @__PURE__ */ K({
239
- __name: "FoodCourtInvitationsView",
240
- setup(v) {
241
- const { t } = H(), { showSuccess: l, showError: f } = ee(), h = X(), { currentRestaurant: i } = Q(), { searchKey: s, filter: _ } = te(), c = F(() => {
242
- var e;
243
- return ((e = i.value) == null ? void 0 : e._id) ?? null;
244
- }), B = F(() => {
245
- var e, a;
246
- return ((a = (e = i.value) == null ? void 0 : e.profile) == null ? void 0 : a.name) ?? null;
247
- }), g = b([]), x = b(!1), k = b(!1), w = (e) => e.courtName || t("order.foodCourt.invitations.unnamedCourt"), A = F(
248
- () => g.value.filter((e) => _([w(e), e.courtAddress ?? ""]))
249
- );
250
- async function M() {
251
- const e = c.value;
252
- if (k.value = !1, !e) {
253
- g.value = [];
254
- return;
255
- }
256
- x.value = !0;
257
- try {
258
- const a = le(await J.listMemberships(e));
259
- e === c.value && (g.value = a);
260
- } catch (a) {
261
- if (e !== c.value) return;
262
- k.value = !0, f(E(a));
263
- } finally {
264
- e === c.value && (x.value = !1);
265
- }
266
- }
267
- Y(
268
- c,
269
- () => {
270
- g.value = [], M();
271
- },
272
- { immediate: !0 }
273
- );
274
- function o(e) {
275
- const a = c.value;
276
- a && h.open({
277
- title: t("order.foodCourt.invitations.leaveTitle"),
278
- message: t("order.foodCourt.invitations.leaveMessage", { court: w(e) }),
279
- primaryActions: {
280
- text: t("order.foodCourt.invitations.leaveConfirm"),
281
- variant: "destructive",
282
- close: !0
283
- },
284
- secondaryActions: { text: t("order.cancel"), variant: "tertiary", close: !0 }
285
- }).onPrimary(async () => {
286
- if (a === c.value) {
287
- try {
288
- await J.leaveFoodCourt(e.foodCourtId, e.memberId), l(t("order.foodCourt.invitations.left"));
289
- } catch (j) {
290
- f(E(j));
291
- }
292
- await M();
293
- }
294
- });
295
- }
296
- const n = F(() => [
297
- {
298
- id: "courtName",
299
- header: () => t("order.foodCourt.invitations.columnFoodCourt"),
300
- cell: ({ row: e }) => w(e.original),
301
- enableSorting: !1
302
- },
303
- {
304
- id: "courtAddress",
305
- header: () => t("order.foodCourt.invitations.columnLocation"),
306
- cell: ({ row: e }) => e.original.courtAddress || "-",
307
- enableSorting: !1
308
- },
309
- {
310
- id: "joinedAt",
311
- header: () => t("order.foodCourt.invitations.columnJoined"),
312
- cell: ({ row: e }) => e.original.joinedAt ? W(e.original.joinedAt).format("DD MMM YYYY") : "-",
313
- enableSorting: !1
314
- },
315
- {
316
- id: "status",
317
- header: () => t("order.foodCourt.invitations.columnStatus"),
318
- cell: ({ row: e }) => {
319
- const a = se[e.original.status];
320
- return a ? R(Z.FmChip, { variant: a.variant, label: t(a.labelKey) }) : "-";
321
- },
322
- enableSorting: !1
323
- },
324
- {
325
- id: "actions",
326
- header: () => "",
327
- cell: ({ row: e }) => R(ie, {
328
- status: e.original.status,
329
- onLeave: () => o(e.original)
330
- }),
331
- enableSorting: !1,
332
- meta: { width: "64px" }
333
- }
334
- ]);
335
- return (e, a) => {
336
- const j = C("FmPageHead"), T = C("FmButton"), I = C("FmSearch"), z = C("FmTable");
337
- return u(), m(N, null, [
338
- d("div", we, [
339
- y(j, {
340
- title: r(t)("order.foodCourt.invitations.title"),
341
- "line-height": 1.7
342
- }, null, 8, ["title"])
343
- ]),
344
- c.value ? (u(), m("div", ke, [
345
- y(xe, {
346
- "restaurant-id": c.value,
347
- "restaurant-name": B.value
348
- }, null, 8, ["restaurant-id", "restaurant-name"]),
349
- d("div", Ie, [
350
- d("span", Se, p(r(t)("order.foodCourt.invitations.listTitle")), 1),
351
- k.value ? (u(), m("div", Ae, [
352
- d("span", Me, p(r(t)("order.foodCourt.invitations.loadFailed")), 1),
353
- y(T, {
354
- variant: "secondary",
355
- label: r(t)("order.foodCourt.retry"),
356
- onClick: M
357
- }, null, 8, ["label"])
358
- ])) : (u(), m(N, { key: 1 }, [
359
- y(I, {
360
- modelValue: r(s),
361
- "onUpdate:modelValue": a[0] || (a[0] = (L) => O(s) ? s.value = L : null),
362
- class: "max-w-[400px]",
363
- placeholder: r(t)("order.foodCourt.invitations.searchPlaceholder")
364
- }, null, 8, ["modelValue", "placeholder"]),
365
- x.value || A.value.length ? (u(), P(z, {
366
- key: 0,
367
- "row-data": A.value,
368
- "column-defs": n.value,
369
- loading: x.value,
370
- "hide-footer": !0,
371
- "page-size": 1e3,
372
- class: "w-full"
373
- }, null, 8, ["row-data", "column-defs", "loading"])) : (u(), m("div", je, p(g.value.length ? r(t)("order.foodCourt.invitations.noMatch") : r(t)("order.foodCourt.invitations.empty")), 1))
374
- ], 64))
375
- ])
376
- ])) : (u(), m("div", Fe, p(r(t)("order.foodCourt.invitations.noRestaurant")), 1))
377
- ], 64);
378
- };
379
- }
380
- });
381
- export {
382
- Pe as default
383
- };