@feedmepos/mf-order-setting 0.0.95 → 0.0.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{DisplaySystemView-rCw3DE0u.js → DisplaySystemView-BH8SkCOF.js} +4 -4
- package/dist/FoodCourtInvitationsView-3cA0Z-5m.js +383 -0
- package/dist/FoodCourtOrderSettingsView-DysrLZJD.js +294 -0
- package/dist/FoodCourtOrdersView-CbZqHIXO.js +544 -0
- package/dist/FoodCourtStallsView-CTZzPUQ6.js +635 -0
- package/dist/FoodCourtStatusView-C71y7ghx.js +113 -0
- package/dist/{KioskDevicesView-B4dgvMq_.js → KioskDevicesView-BJpbuSzp.js} +1 -1
- package/dist/{KioskDevicesView.vue_vue_type_script_setup_true_lang-B-Oi8ZLq.js → KioskDevicesView.vue_vue_type_script_setup_true_lang-CQFpwn28.js} +7 -6
- package/dist/{KioskSettingView-DXx6wQQQ.js → KioskSettingView-CJxhMf7N.js} +3 -3
- package/dist/{KioskView-BmSHCl13.js → KioskView-BZsdRID1.js} +6 -6
- package/dist/{OrderSettingsView-9NOSAxLf.js → OrderSettingsView-gnyXaJjf.js} +10631 -10601
- package/dist/{app-y20uA-tu.js → app-CeEFBB-w.js} +4484 -3672
- package/dist/app.js +1 -1
- package/dist/dayjs.min-zBHHlxAP.js +285 -0
- package/dist/{featureFlag-GHmH1G2d.js → featureFlag-BTY_R78k.js} +1 -1
- package/dist/food-court-member-piX3gesl.js +212 -0
- package/dist/frontend/mf-order/src/api/food-court/index.d.ts +269 -0
- package/dist/frontend/mf-order/src/api/food-court/invitation.d.ts +55 -0
- package/dist/frontend/mf-order/src/app.d.ts +676 -0
- package/dist/frontend/mf-order/src/main.d.ts +676 -0
- package/dist/frontend/mf-order/src/stores/business/index.d.ts +3 -3
- package/dist/frontend/mf-order/src/stores/order-setting/index.d.ts +6 -0
- package/dist/frontend/mf-order/src/utils/constants/route.d.ts +4 -0
- package/dist/frontend/mf-order/src/views/food-court/FoodCourtInvitationsView.vue.d.ts +2 -0
- package/dist/frontend/mf-order/src/views/food-court/FoodCourtOrdersView.vue.d.ts +2 -0
- package/dist/frontend/mf-order/src/views/food-court/FoodCourtStallsView.vue.d.ts +2 -0
- package/dist/frontend/mf-order/src/views/food-court/FoodCourtStatusView.vue.d.ts +2 -0
- package/dist/frontend/mf-order/src/views/food-court/food-court-member.d.ts +150 -0
- package/dist/frontend/mf-order/src/views/food-court/food-court-order.d.ts +66 -0
- package/dist/frontend/mf-order/src/views/food-court/invitations/JoinFoodCourtCard.vue.d.ts +13 -0
- package/dist/frontend/mf-order/src/views/food-court/invitations/MembershipRowActions.vue.d.ts +11 -0
- package/dist/frontend/mf-order/src/views/food-court/orders/FoodCourtOrderSheet.vue.d.ts +16 -0
- package/dist/frontend/mf-order/src/views/food-court/stalls/EditStallSheet.vue.d.ts +15 -0
- package/dist/frontend/mf-order/src/views/food-court/stalls/GenerateJoinCodeSheet.vue.d.ts +21 -0
- package/dist/frontend/mf-order/src/views/food-court/stalls/StallAssignmentFields.vue.d.ts +16 -0
- package/dist/frontend/mf-order/src/views/food-court/stalls/StallRowActions.vue.d.ts +11 -0
- package/dist/frontend/mf-order/tsconfig.app.tsbuildinfo +1 -1
- package/dist/{index-CmdP_QXF.js → index-601eG3_R.js} +1 -1
- package/dist/index-BeBZTUcq.js +122 -0
- package/dist/index-BtudnkMi.js +1065 -0
- package/dist/{index-BlG6mIU4.js → index-CGiWgTn1.js} +38 -37
- package/dist/{index-wMygvJpP.js → index-D5nv3ncu.js} +2 -2
- package/dist/index-DLDihONy.js +25142 -0
- package/dist/order.dto-JM_fmWnQ.js +14842 -0
- package/dist/package/entity/food-court/food-court.do.d.ts +1 -1
- package/dist/package/entity/food-court/food-court.dto.d.ts +7 -7
- package/dist/package/entity/food-court/order-v2.dto.d.ts +4 -4
- package/dist/package/entity/order-platform/order-platform.dto.d.ts +190 -92
- package/dist/package/entity/order-setting/order-setting.do.d.ts +10 -0
- package/dist/package/entity/order-setting/order-setting.dto.d.ts +20 -0
- package/dist/package/entity/order-setting/queue/queue.do.d.ts +22 -0
- package/dist/package/entity/order-setting/queue/queue.dto.d.ts +7 -0
- package/dist/package/entity/queue/queue.do.d.ts +1 -0
- package/dist/package/entity/queue/queue.dto.d.ts +8 -8
- package/dist/package/entity/restaurant/restaurant.dto.d.ts +20 -0
- package/dist/search-BAPEUu1R.js +15 -0
- package/dist/useFoodCourtContext-2p5sJMcB.js +16 -0
- package/package.json +3 -3
- package/src/api/food-court/index.ts +357 -0
- package/src/api/food-court/invitation.ts +81 -0
- package/src/locales/en-US.json +171 -2
- package/src/locales/ja-JP.json +171 -2
- package/src/locales/th-TH.json +171 -2
- package/src/locales/zh-CN.json +171 -2
- package/src/router/routes.ts +44 -0
- package/src/utils/constants/route.ts +8 -0
- package/src/views/food-court/FoodCourtInvitationsView.vue +187 -0
- package/src/views/food-court/FoodCourtOrdersView.vue +263 -0
- package/src/views/food-court/FoodCourtStallsView.vue +369 -0
- package/src/views/food-court/FoodCourtStatusView.vue +111 -0
- package/src/views/food-court/food-court-member.spec.ts +339 -0
- package/src/views/food-court/food-court-member.ts +397 -0
- package/src/views/food-court/food-court-order.spec.ts +137 -0
- package/src/views/food-court/food-court-order.ts +206 -0
- package/src/views/food-court/invitations/JoinFoodCourtCard.vue +201 -0
- package/src/views/food-court/invitations/MembershipRowActions.vue +19 -0
- package/src/views/food-court/orders/FoodCourtOrderSheet.vue +226 -0
- package/src/views/food-court/stalls/EditStallSheet.vue +91 -0
- package/src/views/food-court/stalls/GenerateJoinCodeSheet.vue +281 -0
- package/src/views/food-court/stalls/StallAssignmentFields.vue +36 -0
- package/src/views/food-court/stalls/StallRowActions.vue +31 -0
- package/src/views/order-settings/OrderSettingsView.vue +2 -4
- package/src/views/order-settings/dine-in/DineInSetting.vue +1 -4
- package/src/views/order-settings/queue/QueueSetting.vue +27 -0
- package/src/views/order-settings/reservation/ReservationSetting.vue +8 -0
- package/dist/FoodCourtOrderSettingsView-DUQXCKzB.js +0 -323
- package/dist/index-CUI1lL9F.js +0 -1347
- package/dist/order.dto-CyHtvyly.js +0 -38829
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import type { FmChipVariant } from '@feedmepos/ui-library'
|
|
2
|
+
import type {
|
|
3
|
+
FoodCourtJoinCodeListItem,
|
|
4
|
+
FoodCourtJoinCodeStatus,
|
|
5
|
+
FoodCourtMember,
|
|
6
|
+
FoodCourtMemberListItem,
|
|
7
|
+
FoodCourtMemberStatus,
|
|
8
|
+
FoodCourtStall
|
|
9
|
+
} from '@/api/food-court'
|
|
10
|
+
import type { FoodCourtAddress, FoodCourtMembership } from '@/api/food-court/invitation'
|
|
11
|
+
|
|
12
|
+
/** A status chip: its colour and the i18n key of its label. */
|
|
13
|
+
export interface StatusChip {
|
|
14
|
+
variant: FmChipVariant
|
|
15
|
+
labelKey: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* What the Stalls list shows. A member row: ACTIVE and visible = ACTIVE,
|
|
20
|
+
* ACTIVE and paused by the owner (`visible: false`) = INACTIVE, a legacy
|
|
21
|
+
* INVITED row (from before join codes) = INVITED. A join code: a stall's
|
|
22
|
+
* request waiting for the owner = PENDING_APPROVAL, a code no stall has used
|
|
23
|
+
* yet = CODE_ISSUED.
|
|
24
|
+
*/
|
|
25
|
+
export type StallListStatus =
|
|
26
|
+
'ACTIVE' | 'INACTIVE' | 'INVITED' | 'DECLINED' | 'PENDING_APPROVAL' | 'CODE_ISSUED'
|
|
27
|
+
|
|
28
|
+
interface StallRowBase {
|
|
29
|
+
/** Unique across member and join code rows. */
|
|
30
|
+
key: string
|
|
31
|
+
listStatus: StallListStatus
|
|
32
|
+
unitNo: string | null
|
|
33
|
+
/** Null: the court shows the outlet's own name. */
|
|
34
|
+
displayName: string | null
|
|
35
|
+
/** The outlet's own name; null once the restaurant no longer exists, or before a stall used the code. */
|
|
36
|
+
restaurantName: string | null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** One member row of the court, as the owner sees it (KDI-4915 + KDI-4919). */
|
|
40
|
+
export interface MemberStallRow extends StallRowBase {
|
|
41
|
+
kind: 'member'
|
|
42
|
+
memberId: string
|
|
43
|
+
restaurantId: string
|
|
44
|
+
status: FoodCourtMemberStatus
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A join code the list still shows: a stall's request to approve, or a code not used yet. */
|
|
48
|
+
export interface JoinCodeStallRow extends StallRowBase {
|
|
49
|
+
kind: 'joinCode'
|
|
50
|
+
joinCodeId: string
|
|
51
|
+
status: 'OPEN' | 'PENDING'
|
|
52
|
+
/** The outlet that asked to join; null for an OPEN code. */
|
|
53
|
+
restaurantId: string | null
|
|
54
|
+
businessName: string | null
|
|
55
|
+
expiresAt: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type StallRow = MemberStallRow | JoinCodeStallRow
|
|
59
|
+
|
|
60
|
+
/** The Stalls list status of a member row, or null for a row the list hides (REVOKED, REMOVED). */
|
|
61
|
+
export function stallListStatus(
|
|
62
|
+
member: Pick<FoodCourtMember, 'status' | 'visible'>
|
|
63
|
+
): StallListStatus | null {
|
|
64
|
+
switch (member.status) {
|
|
65
|
+
case 'ACTIVE':
|
|
66
|
+
return member.visible === false ? 'INACTIVE' : 'ACTIVE'
|
|
67
|
+
case 'INVITED':
|
|
68
|
+
return 'INVITED'
|
|
69
|
+
case 'DECLINED':
|
|
70
|
+
return 'DECLINED'
|
|
71
|
+
default:
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The Stalls list status of a join code, or null for a code the list hides:
|
|
78
|
+
* an approved one is listed as its member row; a declined, cancelled or
|
|
79
|
+
* expired one can no longer be used.
|
|
80
|
+
*/
|
|
81
|
+
export function joinCodeListStatus(status: FoodCourtJoinCodeStatus): StallListStatus | null {
|
|
82
|
+
switch (status) {
|
|
83
|
+
case 'PENDING':
|
|
84
|
+
return 'PENDING_APPROVAL'
|
|
85
|
+
case 'OPEN':
|
|
86
|
+
return 'CODE_ISSUED'
|
|
87
|
+
default:
|
|
88
|
+
return null
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function toMemberRows(items: FoodCourtMemberListItem[]): MemberStallRow[] {
|
|
93
|
+
const rows: MemberStallRow[] = []
|
|
94
|
+
for (const { member, restaurant } of items) {
|
|
95
|
+
const listStatus = stallListStatus(member)
|
|
96
|
+
if (!listStatus) continue
|
|
97
|
+
rows.push({
|
|
98
|
+
kind: 'member',
|
|
99
|
+
key: `member:${member._id}`,
|
|
100
|
+
memberId: member._id,
|
|
101
|
+
restaurantId: member.restaurantId,
|
|
102
|
+
restaurantName: restaurant?.name || null,
|
|
103
|
+
status: member.status,
|
|
104
|
+
listStatus,
|
|
105
|
+
unitNo: member.stall?.unitNo ?? null,
|
|
106
|
+
displayName: member.stall?.displayName ?? null
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
return rows
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function toJoinCodeRows(items: FoodCourtJoinCodeListItem[]): JoinCodeStallRow[] {
|
|
113
|
+
const rows: JoinCodeStallRow[] = []
|
|
114
|
+
for (const { joinCode, restaurant } of items) {
|
|
115
|
+
const listStatus = joinCodeListStatus(joinCode.status)
|
|
116
|
+
if (!listStatus) continue
|
|
117
|
+
rows.push({
|
|
118
|
+
kind: 'joinCode',
|
|
119
|
+
key: `joinCode:${joinCode._id}`,
|
|
120
|
+
joinCodeId: joinCode._id,
|
|
121
|
+
status: joinCode.status === 'PENDING' ? 'PENDING' : 'OPEN',
|
|
122
|
+
listStatus,
|
|
123
|
+
restaurantId: joinCode.restaurantId ?? restaurant?._id ?? null,
|
|
124
|
+
restaurantName: restaurant?.name || null,
|
|
125
|
+
businessName: restaurant?.businessName || null,
|
|
126
|
+
unitNo: joinCode.stall?.unitNo ?? null,
|
|
127
|
+
displayName: joinCode.stall?.displayName ?? null,
|
|
128
|
+
expiresAt: joinCode.expiresAt
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
// Requests to approve first, then codes not used yet; each keeps the backend's newest-first order.
|
|
132
|
+
return [
|
|
133
|
+
...rows.filter((row) => row.status === 'PENDING'),
|
|
134
|
+
...rows.filter((row) => row.status === 'OPEN')
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The owner's Stalls list: join requests to approve, then issued codes, then
|
|
140
|
+
* the member rows in court order. Cancelled and removed members are left out,
|
|
141
|
+
* and so are approved, declined, cancelled and expired codes.
|
|
142
|
+
*/
|
|
143
|
+
export function toStallRows(
|
|
144
|
+
members: FoodCourtMemberListItem[],
|
|
145
|
+
joinCodes: FoodCourtJoinCodeListItem[] = []
|
|
146
|
+
): StallRow[] {
|
|
147
|
+
return [...toJoinCodeRows(joinCodes), ...toMemberRows(members)]
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Stalls list (Figma 1.20): Active green, Inactive grey, Pending approval orange, Declined red. */
|
|
151
|
+
export const STALL_STATUS_CHIP: Record<StallListStatus, StatusChip> = {
|
|
152
|
+
ACTIVE: { variant: 'success', labelKey: 'order.foodCourt.stalls.statusActive' },
|
|
153
|
+
INACTIVE: { variant: 'neutral', labelKey: 'order.foodCourt.stalls.statusInactive' },
|
|
154
|
+
INVITED: { variant: 'neutral', labelKey: 'order.foodCourt.stalls.statusInvited' },
|
|
155
|
+
DECLINED: { variant: 'critical', labelKey: 'order.foodCourt.stalls.statusDeclined' },
|
|
156
|
+
PENDING_APPROVAL: {
|
|
157
|
+
variant: 'warning',
|
|
158
|
+
labelKey: 'order.foodCourt.stalls.statusPendingApproval'
|
|
159
|
+
},
|
|
160
|
+
CODE_ISSUED: { variant: 'info', labelKey: 'order.foodCourt.stalls.statusCodeIssued' }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** The name the court shows for a stall: its court display name, else the outlet's own; '' for neither. */
|
|
164
|
+
export function stallName(
|
|
165
|
+
row: Pick<StallRow, 'displayName' | 'restaurantName' | 'restaurantId'>
|
|
166
|
+
): string {
|
|
167
|
+
return row.displayName || row.restaurantName || row.restaurantId || ''
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Who asked to join with a code: the outlet, with its business when known. */
|
|
171
|
+
export function requesterName(
|
|
172
|
+
row: Pick<JoinCodeStallRow, 'restaurantName' | 'businessName' | 'restaurantId'>
|
|
173
|
+
): string {
|
|
174
|
+
const outlet = row.restaurantName || row.restaurantId || ''
|
|
175
|
+
return row.businessName && row.businessName !== outlet
|
|
176
|
+
? `${outlet} (${row.businessName})`
|
|
177
|
+
: outlet
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** A Stalls row ⋮ menu item. */
|
|
181
|
+
export type StallAction =
|
|
182
|
+
| 'edit'
|
|
183
|
+
| 'deactivate'
|
|
184
|
+
| 'activate'
|
|
185
|
+
| 'remove'
|
|
186
|
+
| 'cancelInvite'
|
|
187
|
+
| 'approve'
|
|
188
|
+
| 'decline'
|
|
189
|
+
| 'cancelCode'
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Which actions each Stalls row offers (Figma 1.20-1.32; D1: the owner pauses
|
|
193
|
+
* with `visible`). A legacy invitation can only be cancelled; a declined one
|
|
194
|
+
* is listed without actions: the stall rejoins with a join code.
|
|
195
|
+
*/
|
|
196
|
+
export const STALL_ACTIONS: Record<StallListStatus, StallAction[]> = {
|
|
197
|
+
ACTIVE: ['edit', 'deactivate', 'remove'],
|
|
198
|
+
INACTIVE: ['edit', 'activate', 'remove'],
|
|
199
|
+
INVITED: ['edit', 'cancelInvite'],
|
|
200
|
+
DECLINED: [],
|
|
201
|
+
PENDING_APPROVAL: ['approve', 'decline'],
|
|
202
|
+
CODE_ISSUED: ['cancelCode']
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export const STALL_ACTION_LABEL_KEY: Record<StallAction, string> = {
|
|
206
|
+
edit: 'order.edit',
|
|
207
|
+
deactivate: 'order.foodCourt.stalls.actionDeactivate',
|
|
208
|
+
activate: 'order.foodCourt.stalls.actionActivate',
|
|
209
|
+
remove: 'order.foodCourt.stalls.actionRemove',
|
|
210
|
+
cancelInvite: 'order.foodCourt.stalls.actionCancelInvite',
|
|
211
|
+
approve: 'order.foodCourt.stalls.actionApprove',
|
|
212
|
+
decline: 'order.foodCourt.stalls.actionDecline',
|
|
213
|
+
cancelCode: 'order.foodCourt.stalls.actionCancelCode'
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The characters a join code is made of: no 0, 1, I, L or O. */
|
|
217
|
+
export const JOIN_CODE_ALPHABET = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789'
|
|
218
|
+
export const JOIN_CODE_LENGTH = 10
|
|
219
|
+
|
|
220
|
+
/** A typed or pasted code as the backend reads it: upper case, without spaces or `-`. */
|
|
221
|
+
export function normalizeJoinCode(input: string | null | undefined): string {
|
|
222
|
+
return (input ?? '').toUpperCase().replace(/[\s-]/g, '')
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Whether the input can be a join code at all. A malformed code is never
|
|
227
|
+
* sent: the backend counts it as a failed attempt, and 10 in 15 minutes lock
|
|
228
|
+
* the user out.
|
|
229
|
+
*/
|
|
230
|
+
export function isWellFormedJoinCode(input: string | null | undefined): boolean {
|
|
231
|
+
const code = normalizeJoinCode(input)
|
|
232
|
+
return (
|
|
233
|
+
code.length === JOIN_CODE_LENGTH && [...code].every((char) => JOIN_CODE_ALPHABET.includes(char))
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** A code as it is shown and shared: `ABCDE-FGHJK`. Anything else is returned normalized. */
|
|
238
|
+
export function formatJoinCode(input: string | null | undefined): string {
|
|
239
|
+
const code = normalizeJoinCode(input)
|
|
240
|
+
if (code.length !== JOIN_CODE_LENGTH) return code
|
|
241
|
+
const half = JOIN_CODE_LENGTH / 2
|
|
242
|
+
return `${code.slice(0, half)}-${code.slice(half)}`
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** How many join codes the owner can generate at once; the backend refuses any other count (400). */
|
|
246
|
+
export const JOIN_CODE_COUNT = { min: 1, max: 50 } as const
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* How many join codes to generate: a whole number from 1 to 50. Blank is 1, a
|
|
250
|
+
* fraction is cut to its whole part, and anything out of range is brought to
|
|
251
|
+
* the nearest end.
|
|
252
|
+
*/
|
|
253
|
+
export function clampJoinCodeCount(input: number | null | undefined): number {
|
|
254
|
+
if (typeof input !== 'number' || Number.isNaN(input)) return JOIN_CODE_COUNT.min
|
|
255
|
+
return Math.min(JOIN_CODE_COUNT.max, Math.max(JOIN_CODE_COUNT.min, Math.trunc(input)))
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** "Copy all": every code as it is shown, one per line. */
|
|
259
|
+
export function joinCodesCopyText(codes: readonly (string | null | undefined)[]): string {
|
|
260
|
+
return codes
|
|
261
|
+
.map((code) => formatJoinCode(code))
|
|
262
|
+
.filter(Boolean)
|
|
263
|
+
.join('\n')
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** The join code errors the stall can hit, each with its own message. */
|
|
267
|
+
export const JOIN_CODE_ERROR_KEY: Record<string, string> = {
|
|
268
|
+
JOIN_CODE_INVALID: 'order.foodCourt.joinErrors.invalid',
|
|
269
|
+
JOIN_CODE_EXPIRED: 'order.foodCourt.joinErrors.expired',
|
|
270
|
+
JOIN_CODE_USED: 'order.foodCourt.joinErrors.used',
|
|
271
|
+
TOO_MANY_ATTEMPTS: 'order.foodCourt.joinErrors.tooManyAttempts',
|
|
272
|
+
MEMBER_EXISTS: 'order.foodCourt.joinErrors.memberExists',
|
|
273
|
+
JOIN_REQUEST_EXISTS: 'order.foodCourt.joinErrors.requestExists',
|
|
274
|
+
RESTAURANT_NOT_MANAGEABLE: 'order.foodCourt.joinErrors.notManageable'
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** The i18n key for a failed preview or redeem, or null to show the backend's own message. */
|
|
278
|
+
export function joinCodeErrorKey(e: unknown): string | null {
|
|
279
|
+
const code = typeof e === 'object' && e !== null ? (e as { code?: unknown }).code : undefined
|
|
280
|
+
return typeof code === 'string' && Object.prototype.hasOwnProperty.call(JOIN_CODE_ERROR_KEY, code)
|
|
281
|
+
? JOIN_CODE_ERROR_KEY[code]
|
|
282
|
+
: null
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** A court as the stall's Food Courts list shows its row there. */
|
|
286
|
+
export type FoodCourtMembershipStatus = 'INVITED' | 'JOINED' | 'DECLINED' | 'CANCELLED' | 'LEFT'
|
|
287
|
+
|
|
288
|
+
/** One court the restaurant has a row in, stall side (KDI-4915). */
|
|
289
|
+
export interface FoodCourtMembershipView {
|
|
290
|
+
foodCourtId: string
|
|
291
|
+
memberId: string
|
|
292
|
+
courtName: string | null
|
|
293
|
+
courtAddress: string | null
|
|
294
|
+
status: FoodCourtMembershipStatus
|
|
295
|
+
unitNo: string | null
|
|
296
|
+
/** Null: the court shows the restaurant's own name. */
|
|
297
|
+
displayName: string | null
|
|
298
|
+
joinedAt: string | null
|
|
299
|
+
/** When the row last started: joined, else invited (legacy rows). Sorts the list. */
|
|
300
|
+
since: string | null
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const MEMBERSHIP_STATUS: Record<FoodCourtMemberStatus, FoodCourtMembershipStatus> = {
|
|
304
|
+
INVITED: 'INVITED',
|
|
305
|
+
ACTIVE: 'JOINED',
|
|
306
|
+
DECLINED: 'DECLINED',
|
|
307
|
+
REVOKED: 'CANCELLED',
|
|
308
|
+
REMOVED: 'LEFT'
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* The court's address on one line: line1, city and state joined by ", ",
|
|
313
|
+
* skipping blanks. A part that already ends with a comma is not given a
|
|
314
|
+
* second one.
|
|
315
|
+
*/
|
|
316
|
+
export function formatCourtAddress(address: FoodCourtAddress | null | undefined): string | null {
|
|
317
|
+
const parts = [address?.line1, address?.city, address?.state]
|
|
318
|
+
.map((part) => (part ?? '').trim())
|
|
319
|
+
.filter(Boolean)
|
|
320
|
+
if (!parts.length) return null
|
|
321
|
+
return parts.reduce((line, part) => `${line}${line.endsWith(',') ? ' ' : ', '}${part}`)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** The restaurant's courts, one row each, the most recently joined (or invited) first. */
|
|
325
|
+
export function toMembershipViews(memberships: FoodCourtMembership[]): FoodCourtMembershipView[] {
|
|
326
|
+
const views = memberships.map(({ foodCourtId, profile, member }): FoodCourtMembershipView => ({
|
|
327
|
+
foodCourtId,
|
|
328
|
+
memberId: member._id,
|
|
329
|
+
courtName: profile?.name || null,
|
|
330
|
+
courtAddress: formatCourtAddress(profile?.address),
|
|
331
|
+
status: MEMBERSHIP_STATUS[member.status] ?? 'CANCELLED',
|
|
332
|
+
unitNo: member.stall?.unitNo ?? null,
|
|
333
|
+
displayName: member.stall?.displayName ?? null,
|
|
334
|
+
joinedAt: member.joinedAt ?? null,
|
|
335
|
+
since: member.joinedAt ?? member.invitedAt ?? null
|
|
336
|
+
}))
|
|
337
|
+
const time = (view: FoodCourtMembershipView) => (view.since ? Date.parse(view.since) || 0 : 0)
|
|
338
|
+
return views.sort((a, b) => time(b) - time(a))
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** Food Courts list, stall side. A legacy invitation can no longer be accepted. */
|
|
342
|
+
export const MEMBERSHIP_STATUS_CHIP: Record<FoodCourtMembershipStatus, StatusChip> = {
|
|
343
|
+
JOINED: { variant: 'success', labelKey: 'order.foodCourt.invitations.statusJoined' },
|
|
344
|
+
INVITED: { variant: 'neutral', labelKey: 'order.foodCourt.invitations.statusInvited' },
|
|
345
|
+
DECLINED: { variant: 'critical', labelKey: 'order.foodCourt.invitations.statusDeclined' },
|
|
346
|
+
CANCELLED: { variant: 'neutral', labelKey: 'order.foodCourt.invitations.statusCancelled' },
|
|
347
|
+
LEFT: { variant: 'neutral', labelKey: 'order.foodCourt.invitations.statusLeft' }
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** The backend refuses a longer stall number or display name (400). */
|
|
351
|
+
export const STALL_TEXT_MAX_LENGTH = 60
|
|
352
|
+
|
|
353
|
+
/** Trimmed text, or null when blank. */
|
|
354
|
+
export function blankToNull(value: string | null | undefined): string | null {
|
|
355
|
+
const trimmed = (value ?? '').trim()
|
|
356
|
+
return trimmed ? trimmed : null
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* The display name to save. The field is prefilled with the outlet's own name,
|
|
361
|
+
* so an unchanged (or blank) value is sent as null: the court then keeps
|
|
362
|
+
* following the outlet's name if the outlet renames (A10).
|
|
363
|
+
*/
|
|
364
|
+
export function displayNameToSave(
|
|
365
|
+
input: string | null | undefined,
|
|
366
|
+
outletName: string | null | undefined
|
|
367
|
+
): string | null {
|
|
368
|
+
const value = blankToNull(input)
|
|
369
|
+
return value === blankToNull(outletName) ? null : value
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** The stall number and display name to save; both are always sent, as `stall` replaces both. */
|
|
373
|
+
export function stallToSave(
|
|
374
|
+
unitNo: string | null | undefined,
|
|
375
|
+
displayName: string | null | undefined,
|
|
376
|
+
outletName: string | null | undefined
|
|
377
|
+
): FoodCourtStall {
|
|
378
|
+
return { unitNo: blankToNull(unitNo), displayName: displayNameToSave(displayName, outletName) }
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* The stall a new join code carries, or null when both fields are blank. No
|
|
383
|
+
* outlet is known yet, so nothing is compared with its name: the backend
|
|
384
|
+
* stores a display name equal to the outlet's own as null when it approves.
|
|
385
|
+
*/
|
|
386
|
+
export function joinCodeStall(
|
|
387
|
+
unitNo: string | null | undefined,
|
|
388
|
+
displayName: string | null | undefined
|
|
389
|
+
): FoodCourtStall | null {
|
|
390
|
+
const stall = { unitNo: blankToNull(unitNo), displayName: blankToNull(displayName) }
|
|
391
|
+
return stall.unitNo || stall.displayName ? stall : null
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** What a failed request says: the backend's message, without the error class name. */
|
|
395
|
+
export function errorMessage(e: unknown): string {
|
|
396
|
+
return e instanceof Error && e.message ? e.message : String(e)
|
|
397
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import dayjs from 'dayjs'
|
|
3
|
+
import type { FoodCourtBill, FoodCourtOrderReceipt, FoodCourtStallOrder } from '@/api/food-court'
|
|
4
|
+
import { orderListWindow, stallOrderChip, stallOrderViews } from './food-court-order'
|
|
5
|
+
|
|
6
|
+
const rm = (amount: number) => ({ amount, precision: 2, currency: 'MYR' }) as const
|
|
7
|
+
|
|
8
|
+
function bill(over: Partial<FoodCourtBill> = {}): FoodCourtBill {
|
|
9
|
+
return {
|
|
10
|
+
_id: 'b1',
|
|
11
|
+
status: 'BILLED',
|
|
12
|
+
items: {
|
|
13
|
+
a: {
|
|
14
|
+
product: { name: 'Nasi Lemak' },
|
|
15
|
+
quantity: 2,
|
|
16
|
+
nettTotal: rm(3000),
|
|
17
|
+
subItems: [
|
|
18
|
+
{ name: 'Extra sambal', quantity: 1, price: rm(200) },
|
|
19
|
+
{ name: 'Less spicy', quantity: 1, price: rm(0) }
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
b: { product: { name: 'Old item' }, quantity: 1, status: 'VOIDED', nettTotal: rm(500) },
|
|
23
|
+
c: { product: { name: 'Teh Tarik' }, quantity: 1, nettTotal: rm(450), remark: 'Less sugar' }
|
|
24
|
+
},
|
|
25
|
+
grossTotal: rm(3450),
|
|
26
|
+
adjustedTotal: rm(3100),
|
|
27
|
+
nettTaxes: {
|
|
28
|
+
SST: { name: 'SST (6%)', total: rm(186) },
|
|
29
|
+
INC: { name: 'Inclusive tax', inclusive: true, total: rm(50) },
|
|
30
|
+
ZERO: { name: 'Zero tax', total: rm(0) }
|
|
31
|
+
},
|
|
32
|
+
rounding: rm(-1),
|
|
33
|
+
nettTotal: rm(3285),
|
|
34
|
+
...over
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function stallOrder(over: Partial<FoodCourtStallOrder> = {}): FoodCourtStallOrder {
|
|
39
|
+
return { _id: 'o1', restaurant: 'r1', status: 'ACCEPTED', orderAt: '', bill: bill(), ...over }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('orderListWindow', () => {
|
|
43
|
+
it('covers the whole picked days, the end day included', () => {
|
|
44
|
+
const w = orderListWindow({ startDate: '2026-10-28', endDate: '2026-10-29' })
|
|
45
|
+
expect(dayjs(w.from).format('YYYY-MM-DD HH:mm')).toBe('2026-10-28 00:00')
|
|
46
|
+
expect(dayjs(w.to).format('YYYY-MM-DD HH:mm')).toBe('2026-10-30 00:00')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('is one day when only the start is picked, and today with nothing picked', () => {
|
|
50
|
+
const one = orderListWindow({ startDate: '2026-10-28', endDate: null })
|
|
51
|
+
expect(dayjs(one.to).diff(dayjs(one.from), 'hour')).toBe(24)
|
|
52
|
+
const now = dayjs('2026-10-29T15:30:00')
|
|
53
|
+
const today = orderListWindow({ startDate: null, endDate: null }, now)
|
|
54
|
+
expect(dayjs(today.from).format('YYYY-MM-DD HH:mm')).toBe('2026-10-29 00:00')
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
describe('stallOrderChip', () => {
|
|
59
|
+
it('shows a refunded or voided bill over the order state', () => {
|
|
60
|
+
expect(stallOrderChip(stallOrder({ bill: bill({ status: 'REFUNDED' }) })).labelKey).toBe(
|
|
61
|
+
'order.foodCourt.orders.stallRefunded'
|
|
62
|
+
)
|
|
63
|
+
expect(stallOrderChip(stallOrder({ bill: bill({ status: 'VOIDED' }) })).labelKey).toBe(
|
|
64
|
+
'order.foodCourt.orders.stallVoided'
|
|
65
|
+
)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('maps the order state, and copes with a missing order', () => {
|
|
69
|
+
expect(stallOrderChip(stallOrder({ status: 'NEW' })).variant).toBe('warning')
|
|
70
|
+
expect(stallOrderChip(stallOrder({ status: 'DECLINED' })).variant).toBe('critical')
|
|
71
|
+
expect(stallOrderChip(stallOrder()).variant).toBe('success')
|
|
72
|
+
expect(stallOrderChip(null).labelKey).toBe('order.foodCourt.orders.stallUnknown')
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('stallOrderViews', () => {
|
|
77
|
+
const receipt = (over: Partial<FoodCourtOrderReceipt> = {}): FoodCourtOrderReceipt => ({
|
|
78
|
+
_id: 'c1',
|
|
79
|
+
foodCourtId: 'f1',
|
|
80
|
+
status: 'PAID',
|
|
81
|
+
orderNumber: 'FC-013',
|
|
82
|
+
total: rm(3785),
|
|
83
|
+
stalls: [
|
|
84
|
+
{ orderId: 'o2', restaurantId: 'r2', unitNo: 'L1-04', displayName: null, amount: rm(500) },
|
|
85
|
+
{
|
|
86
|
+
orderId: 'o1',
|
|
87
|
+
restaurantId: 'r1',
|
|
88
|
+
unitNo: 'L1-03',
|
|
89
|
+
displayName: 'Nasi Bar',
|
|
90
|
+
amount: rm(3285)
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
pf_orders: [
|
|
94
|
+
stallOrder(),
|
|
95
|
+
stallOrder({ _id: 'o2', restaurant: 'r2', bill: null, status: 'NEW' })
|
|
96
|
+
],
|
|
97
|
+
...over
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('keeps the checkout order and matches each stall to its order by id', () => {
|
|
101
|
+
const views = stallOrderViews(receipt())
|
|
102
|
+
expect(views.map((v) => v.key)).toEqual(['o2', 'o1'])
|
|
103
|
+
expect(views[0].name).toBe('r2')
|
|
104
|
+
expect(views[0].order?.status).toBe('NEW')
|
|
105
|
+
expect(views[0].items).toEqual([])
|
|
106
|
+
expect(views[0].totals).toEqual([])
|
|
107
|
+
expect(views[1].name).toBe('Nasi Bar')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('lists items with their add-ons and leaves voided items out', () => {
|
|
111
|
+
const [, view] = stallOrderViews(receipt())
|
|
112
|
+
expect(view.items.map((l) => [l.name, l.sub, l.amount?.amount ?? null])).toEqual([
|
|
113
|
+
['Nasi Lemak', false, 3000],
|
|
114
|
+
['Extra sambal', true, 200],
|
|
115
|
+
['Less spicy', true, null],
|
|
116
|
+
['Teh Tarik', false, 450]
|
|
117
|
+
])
|
|
118
|
+
expect(view.items[3].remark).toBe('Less sugar')
|
|
119
|
+
expect(view.itemCount).toBe(3)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('shows the discount, the taxes charged on top and the rounding', () => {
|
|
123
|
+
const [, view] = stallOrderViews(receipt())
|
|
124
|
+
expect(view.totals.map((l) => [l.label, l.amount.amount])).toEqual([
|
|
125
|
+
['order.foodCourt.orders.subtotal', 3450],
|
|
126
|
+
['order.foodCourt.orders.discount', -350],
|
|
127
|
+
['SST (6%)', 186],
|
|
128
|
+
['order.foodCourt.orders.rounding', -1]
|
|
129
|
+
])
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('has a card even when the receipt lacks the stall order', () => {
|
|
133
|
+
const views = stallOrderViews(receipt({ pf_orders: [] }))
|
|
134
|
+
expect(views).toHaveLength(2)
|
|
135
|
+
expect(views[1].order).toBeNull()
|
|
136
|
+
})
|
|
137
|
+
})
|