@burdenoff/microfe-kadaikodi 2026.1124.1 → 2026.1126.1
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/kadaikodi/components/AppointmentSettingsSection.d.ts +13 -0
- package/dist/kadaikodi/components/AppointmentSettingsSection.js +206 -0
- package/dist/kadaikodi/components/AppointmentSettingsSection.js.map +1 -0
- package/dist/kadaikodi/components/AppointmentSlotPicker.d.ts +19 -0
- package/dist/kadaikodi/components/AppointmentSlotPicker.js +106 -0
- package/dist/kadaikodi/components/AppointmentSlotPicker.js.map +1 -0
- package/dist/kadaikodi/components/ProviderAppointmentQueue.d.ts +15 -0
- package/dist/kadaikodi/components/ProviderAppointmentQueue.js +179 -0
- package/dist/kadaikodi/components/ProviderAppointmentQueue.js.map +1 -0
- package/dist/kadaikodi/hooks/useAppointmentsApi.d.ts +122 -0
- package/dist/kadaikodi/hooks/useAppointmentsApi.js +184 -0
- package/dist/kadaikodi/hooks/useAppointmentsApi.js.map +1 -0
- package/dist/kadaikodi/hooks/useKadaikodiApi.d.ts +3 -0
- package/dist/kadaikodi/hooks/useKadaikodiApi.js +5 -4
- package/dist/kadaikodi/hooks/useKadaikodiApi.js.map +1 -1
- package/dist/kadaikodi/pages/cart-owner/CartOwnerDashboard.js +97 -94
- package/dist/kadaikodi/pages/cart-owner/CartOwnerDashboard.js.map +1 -1
- package/dist/kadaikodi/pages/cart-owner/CartServiceConfigPage.js +172 -170
- package/dist/kadaikodi/pages/cart-owner/CartServiceConfigPage.js.map +1 -1
- package/dist/kadaikodi/pages/cart-owner/OrderManagementPage.js +250 -241
- package/dist/kadaikodi/pages/cart-owner/OrderManagementPage.js.map +1 -1
- package/dist/kadaikodi/pages/customer/BookingDetailsPage.d.ts +3 -1
- package/dist/kadaikodi/pages/customer/BookingDetailsPage.js +317 -178
- package/dist/kadaikodi/pages/customer/BookingDetailsPage.js.map +1 -1
- package/dist/kadaikodi/pages/customer/DirectServiceBookingPage.d.ts +3 -3
- package/dist/kadaikodi/pages/customer/DirectServiceBookingPage.js +307 -338
- package/dist/kadaikodi/pages/customer/DirectServiceBookingPage.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Appointment Settings Section (BOFF-3965)
|
|
3
|
+
* @module kadaikodi/components
|
|
4
|
+
*
|
|
5
|
+
* Lets the cart owner shape service appointment slots inside the operating
|
|
6
|
+
* hours above: slot length, how many customers can be served at once, buffer,
|
|
7
|
+
* minimum notice, how far ahead customers may book, the customer cancellation
|
|
8
|
+
* cutoff, auto-confirmation and closed dates. Saved separately from the rest of
|
|
9
|
+
* the service configuration because it is stored by its own API.
|
|
10
|
+
*/
|
|
11
|
+
export declare function AppointmentSettingsSection({ providerId }: {
|
|
12
|
+
providerId: string;
|
|
13
|
+
}): import('react').JSX.Element;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { useAppointmentSettings as e, useUpsertAppointmentSettings as t } from "../hooks/useAppointmentsApi.js";
|
|
2
|
+
import { useState as n } from "react";
|
|
3
|
+
import { CalendarClock as r, Loader2 as i, Plus as a, Save as o, Trash2 as s } from "lucide-react";
|
|
4
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
5
|
+
// src/kadaikodi/components/AppointmentSettingsSection.tsx
|
|
6
|
+
var u = [
|
|
7
|
+
{
|
|
8
|
+
key: "slotIntervalMinutes",
|
|
9
|
+
label: "Slot interval (min)",
|
|
10
|
+
hint: "How often a slot starts",
|
|
11
|
+
min: 5,
|
|
12
|
+
max: 240
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
key: "capacityPerSlot",
|
|
16
|
+
label: "Customers at once",
|
|
17
|
+
hint: "Parallel appointments you can serve",
|
|
18
|
+
min: 1,
|
|
19
|
+
max: 50
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
key: "bufferMinutes",
|
|
23
|
+
label: "Buffer (min)",
|
|
24
|
+
hint: "Gap kept before and after each booking",
|
|
25
|
+
min: 0,
|
|
26
|
+
max: 240
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "minLeadMinutes",
|
|
30
|
+
label: "Minimum notice (min)",
|
|
31
|
+
hint: "Earliest slot from now",
|
|
32
|
+
min: 0,
|
|
33
|
+
max: 10080
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: "advanceBookingDays",
|
|
37
|
+
label: "Book ahead (days)",
|
|
38
|
+
hint: "How far ahead customers can book",
|
|
39
|
+
min: 1,
|
|
40
|
+
max: 90
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
key: "cancellationCutoffHours",
|
|
44
|
+
label: "Change cutoff (hours)",
|
|
45
|
+
hint: "Customers cannot cancel or reschedule after this",
|
|
46
|
+
min: 0,
|
|
47
|
+
max: 168
|
|
48
|
+
}
|
|
49
|
+
], d = "w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]";
|
|
50
|
+
function f({ providerId: f }) {
|
|
51
|
+
let { data: p, isLoading: m, isError: h, refetch: g, isFetching: _ } = e(f), v = t(), [y, b] = n(null), [x, S] = n(""), [C, w] = n(null), T = y ?? (p ? {
|
|
52
|
+
slotIntervalMinutes: p.slotIntervalMinutes,
|
|
53
|
+
capacityPerSlot: p.capacityPerSlot,
|
|
54
|
+
bufferMinutes: p.bufferMinutes,
|
|
55
|
+
minLeadMinutes: p.minLeadMinutes,
|
|
56
|
+
advanceBookingDays: p.advanceBookingDays,
|
|
57
|
+
cancellationCutoffHours: p.cancellationCutoffHours,
|
|
58
|
+
autoConfirm: p.autoConfirm,
|
|
59
|
+
blackoutDates: p.blackoutDates
|
|
60
|
+
} : null), E = (e) => {
|
|
61
|
+
T && b({
|
|
62
|
+
...T,
|
|
63
|
+
...e
|
|
64
|
+
});
|
|
65
|
+
}, D = T ? u.filter((e) => !Number.isInteger(T[e.key]) || T[e.key] < e.min || T[e.key] > e.max).map((e) => `${e.label} must be a whole number between ${e.min} and ${e.max}`) : [];
|
|
66
|
+
return /* @__PURE__ */ l("section", {
|
|
67
|
+
className: "rounded-lg border border-border-subtle bg-bg-surface p-6 shadow-sm",
|
|
68
|
+
children: [
|
|
69
|
+
/* @__PURE__ */ l("div", {
|
|
70
|
+
className: "mb-4 flex flex-wrap items-center justify-between gap-3",
|
|
71
|
+
children: [/* @__PURE__ */ l("h2", {
|
|
72
|
+
className: "text-lg font-semibold text-text-primary flex items-center gap-2",
|
|
73
|
+
children: [/* @__PURE__ */ c(r, { className: "h-5 w-5 text-text-secondary" }), "Appointment Slots"]
|
|
74
|
+
}), /* @__PURE__ */ l("button", {
|
|
75
|
+
type: "button",
|
|
76
|
+
onClick: () => {
|
|
77
|
+
!T || D.length > 0 || (w(null), v.mutate({
|
|
78
|
+
providerId: f,
|
|
79
|
+
input: T
|
|
80
|
+
}, {
|
|
81
|
+
onSuccess: () => {
|
|
82
|
+
b(null), w({
|
|
83
|
+
text: "Appointment settings saved.",
|
|
84
|
+
ok: !0
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
onError: (e) => w({
|
|
88
|
+
text: e.message || "Could not save appointment settings.",
|
|
89
|
+
ok: !1
|
|
90
|
+
})
|
|
91
|
+
}));
|
|
92
|
+
},
|
|
93
|
+
disabled: !T || D.length > 0 || v.isPending,
|
|
94
|
+
className: "inline-flex items-center gap-2 rounded-md border border-border-subtle px-3 py-1.5 text-sm font-medium text-text-primary hover:bg-accent transition-colors disabled:opacity-60 disabled:cursor-not-allowed",
|
|
95
|
+
children: [v.isPending ? /* @__PURE__ */ c(i, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ c(o, { className: "h-4 w-4" }), "Save Slots"]
|
|
96
|
+
})]
|
|
97
|
+
}),
|
|
98
|
+
/* @__PURE__ */ l("p", {
|
|
99
|
+
className: "mb-4 text-sm text-text-secondary",
|
|
100
|
+
children: [
|
|
101
|
+
"Customers book service appointments inside your operating hours. These rules decide which slots they see",
|
|
102
|
+
p ? ` (times in ${p.timezone})` : "",
|
|
103
|
+
".",
|
|
104
|
+
p && !p.isCustomized && " You are using the default rules."
|
|
105
|
+
]
|
|
106
|
+
}),
|
|
107
|
+
!p && h ? /* @__PURE__ */ l("div", {
|
|
108
|
+
className: "flex flex-wrap items-center gap-3 text-sm text-status-error-text",
|
|
109
|
+
children: ["Could not load your appointment settings.", /* @__PURE__ */ c("button", {
|
|
110
|
+
type: "button",
|
|
111
|
+
onClick: () => void g(),
|
|
112
|
+
disabled: _,
|
|
113
|
+
className: "rounded-md border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed",
|
|
114
|
+
children: "Retry"
|
|
115
|
+
})]
|
|
116
|
+
}) : m || !T ? /* @__PURE__ */ l("div", {
|
|
117
|
+
className: "flex items-center gap-2 text-sm text-text-secondary",
|
|
118
|
+
children: [/* @__PURE__ */ c(i, { className: "h-4 w-4 animate-spin" }), "Loading appointment settings..."]
|
|
119
|
+
}) : /* @__PURE__ */ l("div", {
|
|
120
|
+
className: "space-y-5",
|
|
121
|
+
children: [
|
|
122
|
+
/* @__PURE__ */ c("div", {
|
|
123
|
+
className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",
|
|
124
|
+
children: u.map((e) => /* @__PURE__ */ l("div", { children: [
|
|
125
|
+
/* @__PURE__ */ c("label", {
|
|
126
|
+
htmlFor: `appt-${e.key}`,
|
|
127
|
+
className: "block text-sm font-medium text-text-primary mb-1",
|
|
128
|
+
children: e.label
|
|
129
|
+
}),
|
|
130
|
+
/* @__PURE__ */ c("input", {
|
|
131
|
+
id: `appt-${e.key}`,
|
|
132
|
+
type: "number",
|
|
133
|
+
min: e.min,
|
|
134
|
+
max: e.max,
|
|
135
|
+
value: T[e.key],
|
|
136
|
+
onChange: (t) => E({ [e.key]: Number(t.target.value) }),
|
|
137
|
+
className: d
|
|
138
|
+
}),
|
|
139
|
+
/* @__PURE__ */ c("p", {
|
|
140
|
+
className: "mt-1 text-xs text-text-secondary",
|
|
141
|
+
children: e.hint
|
|
142
|
+
})
|
|
143
|
+
] }, e.key))
|
|
144
|
+
}),
|
|
145
|
+
/* @__PURE__ */ l("label", {
|
|
146
|
+
className: "flex items-center gap-2 cursor-pointer",
|
|
147
|
+
children: [/* @__PURE__ */ c("input", {
|
|
148
|
+
type: "checkbox",
|
|
149
|
+
checked: T.autoConfirm,
|
|
150
|
+
onChange: (e) => E({ autoConfirm: e.target.checked }),
|
|
151
|
+
className: "h-4 w-4 rounded border-border-subtle"
|
|
152
|
+
}), /* @__PURE__ */ c("span", {
|
|
153
|
+
className: "text-sm text-text-primary",
|
|
154
|
+
children: "Confirm new bookings automatically"
|
|
155
|
+
})]
|
|
156
|
+
}),
|
|
157
|
+
/* @__PURE__ */ l("div", { children: [/* @__PURE__ */ c("p", {
|
|
158
|
+
className: "text-sm font-medium text-text-primary mb-2",
|
|
159
|
+
children: "Closed dates"
|
|
160
|
+
}), /* @__PURE__ */ l("div", {
|
|
161
|
+
className: "flex flex-wrap items-center gap-2",
|
|
162
|
+
children: [
|
|
163
|
+
T.blackoutDates.map((e) => /* @__PURE__ */ l("span", {
|
|
164
|
+
className: "inline-flex items-center gap-1 rounded-full bg-bg-sunken px-3 py-1 text-xs text-text-primary",
|
|
165
|
+
children: [e, /* @__PURE__ */ c("button", {
|
|
166
|
+
type: "button",
|
|
167
|
+
"aria-label": `Remove ${e}`,
|
|
168
|
+
onClick: () => E({ blackoutDates: T.blackoutDates.filter((t) => t !== e) }),
|
|
169
|
+
className: "text-text-secondary hover:text-status-error-text",
|
|
170
|
+
children: /* @__PURE__ */ c(s, { className: "h-3 w-3" })
|
|
171
|
+
})]
|
|
172
|
+
}, e)),
|
|
173
|
+
/* @__PURE__ */ c("input", {
|
|
174
|
+
type: "date",
|
|
175
|
+
"aria-label": "Closed date",
|
|
176
|
+
value: x,
|
|
177
|
+
onChange: (e) => S(e.target.value),
|
|
178
|
+
className: "rounded-md border border-border-subtle bg-bg-surface px-2 py-1 text-xs text-text-primary"
|
|
179
|
+
}),
|
|
180
|
+
/* @__PURE__ */ l("button", {
|
|
181
|
+
type: "button",
|
|
182
|
+
disabled: !x,
|
|
183
|
+
onClick: () => {
|
|
184
|
+
T.blackoutDates.includes(x) || E({ blackoutDates: [...T.blackoutDates, x].sort((e, t) => e.localeCompare(t)) }), S("");
|
|
185
|
+
},
|
|
186
|
+
className: "inline-flex items-center gap-1 rounded-md border border-border-subtle px-2 py-1 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60",
|
|
187
|
+
children: [/* @__PURE__ */ c(a, { className: "h-3 w-3" }), "Add"]
|
|
188
|
+
})
|
|
189
|
+
]
|
|
190
|
+
})] }),
|
|
191
|
+
D.length > 0 && /* @__PURE__ */ c("ul", {
|
|
192
|
+
className: "space-y-1 text-sm text-status-error-text",
|
|
193
|
+
children: D.map((e) => /* @__PURE__ */ c("li", { children: e }, e))
|
|
194
|
+
}),
|
|
195
|
+
C && /* @__PURE__ */ c("p", {
|
|
196
|
+
className: C.ok ? "text-sm text-status-success-text" : "text-sm text-status-error-text",
|
|
197
|
+
children: C.text
|
|
198
|
+
})
|
|
199
|
+
]
|
|
200
|
+
})
|
|
201
|
+
]
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
export { f as AppointmentSettingsSection };
|
|
205
|
+
|
|
206
|
+
//# sourceMappingURL=AppointmentSettingsSection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppointmentSettingsSection.js","names":["NUMERIC_FIELDS","inputClass","AppointmentSettingsSection","settings","settingsFailed","refetchSettings","settingsFetching","useAppointmentSettings","providerId","upsert","useUpsertAppointmentSettings","draft","setDraft","useState","newBlackout","setNewBlackout","message","setMessage","form","patch","changes","errors","field","CalendarClock","error","Loader2","Save","isLoading","e","date","d","Trash2","a","b","Plus"],"sources":["../../../src/kadaikodi/components/AppointmentSettingsSection.tsx"],"sourcesContent":["/**\n * Appointment Settings Section (BOFF-3965)\n * @module kadaikodi/components\n *\n * Lets the cart owner shape service appointment slots inside the operating\n * hours above: slot length, how many customers can be served at once, buffer,\n * minimum notice, how far ahead customers may book, the customer cancellation\n * cutoff, auto-confirmation and closed dates. Saved separately from the rest of\n * the service configuration because it is stored by its own API.\n */\n\nimport { useState } from 'react';\nimport { CalendarClock, Loader2, Plus, Save, Trash2 } from 'lucide-react';\nimport {\n type AppointmentSettingsInput,\n useAppointmentSettings,\n useUpsertAppointmentSettings,\n} from '../hooks/useAppointmentsApi';\n\ninterface NumericField {\n key:\n | 'slotIntervalMinutes'\n | 'capacityPerSlot'\n | 'bufferMinutes'\n | 'minLeadMinutes'\n | 'advanceBookingDays'\n | 'cancellationCutoffHours';\n label: string;\n hint: string;\n min: number;\n max: number;\n}\n\n// Bounds mirror APPOINTMENT_RULE_BOUNDS in wspace-kadaikodi-svc; the service re-validates.\nconst NUMERIC_FIELDS: NumericField[] = [\n {\n key: 'slotIntervalMinutes',\n label: 'Slot interval (min)',\n hint: 'How often a slot starts',\n min: 5,\n max: 240,\n },\n {\n key: 'capacityPerSlot',\n label: 'Customers at once',\n hint: 'Parallel appointments you can serve',\n min: 1,\n max: 50,\n },\n {\n key: 'bufferMinutes',\n label: 'Buffer (min)',\n hint: 'Gap kept before and after each booking',\n min: 0,\n max: 240,\n },\n {\n key: 'minLeadMinutes',\n label: 'Minimum notice (min)',\n hint: 'Earliest slot from now',\n min: 0,\n max: 10080,\n },\n {\n key: 'advanceBookingDays',\n label: 'Book ahead (days)',\n hint: 'How far ahead customers can book',\n min: 1,\n max: 90,\n },\n {\n key: 'cancellationCutoffHours',\n label: 'Change cutoff (hours)',\n hint: 'Customers cannot cancel or reschedule after this',\n min: 0,\n max: 168,\n },\n];\n\ntype FormState = Required<Omit<AppointmentSettingsInput, 'timezone'>>;\n\nconst inputClass =\n 'w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]';\n\nexport function AppointmentSettingsSection({ providerId }: { providerId: string }) {\n const {\n data: settings,\n isLoading,\n isError: settingsFailed,\n refetch: refetchSettings,\n isFetching: settingsFetching,\n } = useAppointmentSettings(providerId);\n const upsert = useUpsertAppointmentSettings();\n const [draft, setDraft] = useState<FormState | null>(null);\n const [newBlackout, setNewBlackout] = useState('');\n const [message, setMessage] = useState<{ text: string; ok: boolean } | null>(null);\n\n // Unsaved edits live in `draft`; until the owner edits anything the form\n // shows the stored settings (no effect needed to seed it).\n const form: FormState | null =\n draft ??\n (settings\n ? {\n slotIntervalMinutes: settings.slotIntervalMinutes,\n capacityPerSlot: settings.capacityPerSlot,\n bufferMinutes: settings.bufferMinutes,\n minLeadMinutes: settings.minLeadMinutes,\n advanceBookingDays: settings.advanceBookingDays,\n cancellationCutoffHours: settings.cancellationCutoffHours,\n autoConfirm: settings.autoConfirm,\n blackoutDates: settings.blackoutDates,\n }\n : null);\n const patch = (changes: Partial<FormState>) => {\n if (form) setDraft({ ...form, ...changes });\n };\n\n const errors = form\n ? NUMERIC_FIELDS.filter(\n (field) =>\n !Number.isInteger(form[field.key]) ||\n form[field.key] < field.min ||\n form[field.key] > field.max\n ).map(\n (field) => `${field.label} must be a whole number between ${field.min} and ${field.max}`\n )\n : [];\n\n const save = () => {\n if (!form || errors.length > 0) return;\n setMessage(null);\n upsert.mutate(\n { providerId, input: form },\n {\n onSuccess: () => {\n setDraft(null);\n setMessage({ text: 'Appointment settings saved.', ok: true });\n },\n onError: (error) =>\n setMessage({ text: error.message || 'Could not save appointment settings.', ok: false }),\n }\n );\n };\n\n return (\n <section className=\"rounded-lg border border-border-subtle bg-bg-surface p-6 shadow-sm\">\n <div className=\"mb-4 flex flex-wrap items-center justify-between gap-3\">\n <h2 className=\"text-lg font-semibold text-text-primary flex items-center gap-2\">\n <CalendarClock className=\"h-5 w-5 text-text-secondary\" />\n Appointment Slots\n </h2>\n <button\n type=\"button\"\n onClick={save}\n disabled={!form || errors.length > 0 || upsert.isPending}\n className=\"inline-flex items-center gap-2 rounded-md border border-border-subtle px-3 py-1.5 text-sm font-medium text-text-primary hover:bg-accent transition-colors disabled:opacity-60 disabled:cursor-not-allowed\"\n >\n {upsert.isPending ? (\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n ) : (\n <Save className=\"h-4 w-4\" />\n )}\n Save Slots\n </button>\n </div>\n <p className=\"mb-4 text-sm text-text-secondary\">\n Customers book service appointments inside your operating hours. These rules decide which\n slots they see{settings ? ` (times in ${settings.timezone})` : ''}.\n {settings && !settings.isCustomized && ' You are using the default rules.'}\n </p>\n\n {!settings && settingsFailed ? (\n <div className=\"flex flex-wrap items-center gap-3 text-sm text-status-error-text\">\n Could not load your appointment settings.\n <button\n type=\"button\"\n onClick={() => void refetchSettings()}\n disabled={settingsFetching}\n className=\"rounded-md border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed\"\n >\n Retry\n </button>\n </div>\n ) : isLoading || !form ? (\n <div className=\"flex items-center gap-2 text-sm text-text-secondary\">\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n Loading appointment settings...\n </div>\n ) : (\n <div className=\"space-y-5\">\n <div className=\"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4\">\n {NUMERIC_FIELDS.map((field) => (\n <div key={field.key}>\n <label\n htmlFor={`appt-${field.key}`}\n className=\"block text-sm font-medium text-text-primary mb-1\"\n >\n {field.label}\n </label>\n <input\n id={`appt-${field.key}`}\n type=\"number\"\n min={field.min}\n max={field.max}\n value={form[field.key]}\n onChange={(e) => patch({ [field.key]: Number(e.target.value) })}\n className={inputClass}\n />\n <p className=\"mt-1 text-xs text-text-secondary\">{field.hint}</p>\n </div>\n ))}\n </div>\n\n <label className=\"flex items-center gap-2 cursor-pointer\">\n <input\n type=\"checkbox\"\n checked={form.autoConfirm}\n onChange={(e) => patch({ autoConfirm: e.target.checked })}\n className=\"h-4 w-4 rounded border-border-subtle\"\n />\n <span className=\"text-sm text-text-primary\">Confirm new bookings automatically</span>\n </label>\n\n <div>\n <p className=\"text-sm font-medium text-text-primary mb-2\">Closed dates</p>\n <div className=\"flex flex-wrap items-center gap-2\">\n {form.blackoutDates.map((date) => (\n <span\n key={date}\n className=\"inline-flex items-center gap-1 rounded-full bg-bg-sunken px-3 py-1 text-xs text-text-primary\"\n >\n {date}\n <button\n type=\"button\"\n aria-label={`Remove ${date}`}\n onClick={() =>\n patch({ blackoutDates: form.blackoutDates.filter((d) => d !== date) })\n }\n className=\"text-text-secondary hover:text-status-error-text\"\n >\n <Trash2 className=\"h-3 w-3\" />\n </button>\n </span>\n ))}\n <input\n type=\"date\"\n aria-label=\"Closed date\"\n value={newBlackout}\n onChange={(e) => setNewBlackout(e.target.value)}\n className=\"rounded-md border border-border-subtle bg-bg-surface px-2 py-1 text-xs text-text-primary\"\n />\n <button\n type=\"button\"\n disabled={!newBlackout}\n onClick={() => {\n if (!form.blackoutDates.includes(newBlackout)) {\n patch({\n blackoutDates: [...form.blackoutDates, newBlackout].sort((a, b) =>\n a.localeCompare(b)\n ),\n });\n }\n setNewBlackout('');\n }}\n className=\"inline-flex items-center gap-1 rounded-md border border-border-subtle px-2 py-1 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60\"\n >\n <Plus className=\"h-3 w-3\" />\n Add\n </button>\n </div>\n </div>\n\n {errors.length > 0 && (\n <ul className=\"space-y-1 text-sm text-status-error-text\">\n {errors.map((error) => (\n <li key={error}>{error}</li>\n ))}\n </ul>\n )}\n {message && (\n <p\n className={\n message.ok ? 'text-sm text-status-success-text' : 'text-sm text-status-error-text'\n }\n >\n {message.text}\n </p>\n )}\n </div>\n )}\n </section>\n );\n}\n"],"mappings":";;;;;AAkCA,IAAMA,IAAiC;CACrC;EACE,KAAK;EACL,OAAO;EACP,MAAM;EACN,KAAK;EACL,KAAK;CACP;CACA;EACE,K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U;OACX,CAAA;OACD,kBAAC,UAAD;QACE,MAAK;QACL,UAAU,CAACD;QACX,eAAe;SAQb,AAPKI,EAAK,cAAc,SAASJ,CAAW,KAC1CK,EAAM,EACJ,eAAe,CAAC,GAAGD,EAAK,eAAeJ,CAAW,CAAC,CAAC,MAAM,GAAG,MAC3DkB,EAAE,cAAcC,CAAC,CACnB,EACF,CAAC,GAEHlB,EAAe,EAAE;QACnB;QACA,WAAU;QAbZ,UAAA,CAeE,kBAACmB,GAAD,EAAM,WAAU,UAAW,CAAA,GAAC,KAEtB;;MACL;KACF,CAAA,CAAA,EAAA,CAAA;KAEJb,EAAO,SAAS,KACf,kBAAC,MAAD;MAAI,WAAU;MACX,UAAAA,EAAO,KAAK,MACX,kBAAC,MAAD,EAAA,UAAiBG,EAAU,GAAlBA,CAAkB,CAC5B;KACC,CAAA;KAELR,KACC,kBAAC,KAAD;MACE,WACEA,EAAQ,KAAK,qCAAqC;MAGnD,UAAAA,EAAQ;KACR,CAAA;IAEF;;EAEA;;AAEb"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Appointment Slot Picker (BOFF-3965)
|
|
3
|
+
* @module kadaikodi/components
|
|
4
|
+
*
|
|
5
|
+
* Day chips (from the provider's bookable days) plus the real slots the
|
|
6
|
+
* service returns for the chosen day. Full or too-soon slots are shown greyed
|
|
7
|
+
* out; times are rendered in the provider's timezone.
|
|
8
|
+
*/
|
|
9
|
+
interface AppointmentSlotPickerProps {
|
|
10
|
+
providerId: string;
|
|
11
|
+
offeringId: string;
|
|
12
|
+
/** Selected slot start (ISO string from the service), or empty. */
|
|
13
|
+
value: string;
|
|
14
|
+
onChange: (startsAt: string) => void;
|
|
15
|
+
/** Slot start to hide from the list (e.g. the appointment's current time while rescheduling). */
|
|
16
|
+
excludeStartsAt?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function AppointmentSlotPicker({ providerId, offeringId, value, onChange, excludeStartsAt, }: AppointmentSlotPickerProps): import('react').JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { calendarDateIn as e, formatAppointmentTime as t, useAppointmentSettings as n, useAvailableSlots as r } from "../hooks/useAppointmentsApi.js";
|
|
2
|
+
import { cn as i } from "../utils/cn.js";
|
|
3
|
+
import { useMemo as a, useState as o } from "react";
|
|
4
|
+
import { Loader2 as s } from "lucide-react";
|
|
5
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
6
|
+
// src/kadaikodi/components/AppointmentSlotPicker.tsx
|
|
7
|
+
var u = 7, d = (e, t) => {
|
|
8
|
+
let n = /* @__PURE__ */ new Date(`${e}T12:00:00Z`);
|
|
9
|
+
return n.setUTCDate(n.getUTCDate() + t), n.toISOString().slice(0, 10);
|
|
10
|
+
}, f = (e, t) => e === t ? "Today" : e === d(t, 1) ? "Tomorrow" : (/* @__PURE__ */ new Date(`${e}T12:00:00Z`)).toLocaleDateString("en-IN", {
|
|
11
|
+
weekday: "short",
|
|
12
|
+
day: "numeric",
|
|
13
|
+
timeZone: "UTC"
|
|
14
|
+
});
|
|
15
|
+
function p({ providerId: d, offeringId: p, value: m, onChange: h, excludeStartsAt: g }) {
|
|
16
|
+
let { data: _, isLoading: v, isError: y, refetch: b, isFetching: x } = n(d), S = a(() => _?.bookableDays ?? [], [_]), [C, w] = o(u), T = a(() => S.slice(0, C), [S, C]), [E, D] = o(""), O = E && T.includes(E) ? E : T[0] ?? "", { data: k, isLoading: A, isError: j, refetch: M, isFetching: N } = r(p, O || void 0), P = (k?.slots ?? []).filter((e) => e.startsAt !== g), F = k?.timezone ?? _?.timezone ?? "Asia/Kolkata", I = e(F);
|
|
17
|
+
return v ? /* @__PURE__ */ l("div", {
|
|
18
|
+
className: "flex items-center gap-2 text-sm text-text-secondary",
|
|
19
|
+
children: [/* @__PURE__ */ c(s, { className: "h-4 w-4 animate-spin" }), "Loading availability..."]
|
|
20
|
+
}) : !_ && y ? /* @__PURE__ */ l("div", {
|
|
21
|
+
className: "flex flex-wrap items-center gap-3 text-sm text-status-error-text",
|
|
22
|
+
children: ["Could not load this cart's availability.", /* @__PURE__ */ c("button", {
|
|
23
|
+
type: "button",
|
|
24
|
+
onClick: () => void b(),
|
|
25
|
+
disabled: x,
|
|
26
|
+
className: "rounded-md border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed",
|
|
27
|
+
children: "Try again"
|
|
28
|
+
})]
|
|
29
|
+
}) : T.length === 0 ? /* @__PURE__ */ c("p", {
|
|
30
|
+
className: "text-sm text-text-secondary",
|
|
31
|
+
children: "This cart is not taking appointments in the coming days."
|
|
32
|
+
}) : /* @__PURE__ */ l("div", {
|
|
33
|
+
className: "space-y-4",
|
|
34
|
+
children: [/* @__PURE__ */ l("div", { children: [
|
|
35
|
+
/* @__PURE__ */ c("label", {
|
|
36
|
+
className: "block text-sm font-medium text-text-primary mb-1.5",
|
|
37
|
+
children: "Day"
|
|
38
|
+
}),
|
|
39
|
+
/* @__PURE__ */ c("div", {
|
|
40
|
+
className: "grid grid-cols-4 sm:grid-cols-7 gap-2",
|
|
41
|
+
children: T.map((e) => /* @__PURE__ */ c("button", {
|
|
42
|
+
type: "button",
|
|
43
|
+
onClick: () => {
|
|
44
|
+
D(e), h("");
|
|
45
|
+
},
|
|
46
|
+
className: i("rounded-lg border py-2 px-2 text-xs font-medium transition-colors", O === e ? "border-action-primary-bg bg-[var(--color-accent-soft)] text-accent-primary" : "border-border-subtle text-text-secondary hover:bg-accent hover:text-text-primary"),
|
|
47
|
+
children: f(e, I)
|
|
48
|
+
}, e))
|
|
49
|
+
}),
|
|
50
|
+
S.length > C && /* @__PURE__ */ c("button", {
|
|
51
|
+
type: "button",
|
|
52
|
+
onClick: () => w((e) => e + u),
|
|
53
|
+
className: "mt-2 text-xs font-medium text-accent-primary hover:underline",
|
|
54
|
+
children: "Show more days"
|
|
55
|
+
})
|
|
56
|
+
] }), /* @__PURE__ */ l("div", { children: [
|
|
57
|
+
/* @__PURE__ */ l("label", {
|
|
58
|
+
className: "block text-sm font-medium text-text-primary mb-1.5",
|
|
59
|
+
children: ["Time Slot ", /* @__PURE__ */ c("span", {
|
|
60
|
+
className: "text-status-error-text",
|
|
61
|
+
children: "*"
|
|
62
|
+
})]
|
|
63
|
+
}),
|
|
64
|
+
A ? /* @__PURE__ */ l("div", {
|
|
65
|
+
className: "flex items-center gap-2 text-sm text-text-secondary",
|
|
66
|
+
children: [/* @__PURE__ */ c(s, { className: "h-4 w-4 animate-spin" }), "Loading slots..."]
|
|
67
|
+
}) : j ? /* @__PURE__ */ l("div", {
|
|
68
|
+
className: "flex flex-wrap items-center gap-3 text-sm text-status-error-text",
|
|
69
|
+
children: ["Could not load slots for this day.", /* @__PURE__ */ c("button", {
|
|
70
|
+
type: "button",
|
|
71
|
+
onClick: () => void M(),
|
|
72
|
+
disabled: N,
|
|
73
|
+
className: "rounded-md border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed",
|
|
74
|
+
children: "Try again"
|
|
75
|
+
})]
|
|
76
|
+
}) : P.length === 0 ? /* @__PURE__ */ c("p", {
|
|
77
|
+
className: "text-sm text-text-secondary",
|
|
78
|
+
children: "No slots left on this day."
|
|
79
|
+
}) : /* @__PURE__ */ c("div", {
|
|
80
|
+
className: "grid grid-cols-3 sm:grid-cols-4 gap-2",
|
|
81
|
+
role: "listbox",
|
|
82
|
+
"aria-label": "Time slots",
|
|
83
|
+
children: P.map((e) => /* @__PURE__ */ c("button", {
|
|
84
|
+
type: "button",
|
|
85
|
+
role: "option",
|
|
86
|
+
"aria-selected": m === e.startsAt,
|
|
87
|
+
disabled: !e.available,
|
|
88
|
+
onClick: () => h(e.startsAt),
|
|
89
|
+
className: i("rounded-lg border py-2 px-2 text-xs font-medium transition-colors", e.available ? m === e.startsAt ? "border-action-primary-bg bg-[var(--color-accent-soft)] text-accent-primary" : "border-border-subtle text-text-secondary hover:bg-accent hover:text-text-primary" : "border-border-subtle text-text-secondary/50 line-through cursor-not-allowed"),
|
|
90
|
+
children: t(e.startsAt, F)
|
|
91
|
+
}, e.startsAt))
|
|
92
|
+
}),
|
|
93
|
+
k && /* @__PURE__ */ l("p", {
|
|
94
|
+
className: "mt-2 text-xs text-text-secondary",
|
|
95
|
+
children: [
|
|
96
|
+
k.durationMinutes,
|
|
97
|
+
"-minute appointment · times shown in ",
|
|
98
|
+
F
|
|
99
|
+
]
|
|
100
|
+
})
|
|
101
|
+
] })]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export { p as AppointmentSlotPicker };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=AppointmentSlotPicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppointmentSlotPicker.js","names":["VISIBLE_DAYS","addDays","shifted","date","days","dayLabel","today","AppointmentSlotPicker","settings","settingsLoading","settingsFailed","refetchSettings","settingsFetching","useAppointmentSettings","providerId","allDays","useMemo","visibleCount","setVisibleCount","useState","pickedDay","setSelectedDay","selectedDay","available","slotsLoading","refetchSlots","slotsFetching","useAvailableSlots","offeringId","slots","slot","excludeStartsAt","timezone","calendarDateIn","Loader2","day","onChange","cn","count","isError","value","formatAppointmentTime"],"sources":["../../../src/kadaikodi/components/AppointmentSlotPicker.tsx"],"sourcesContent":["/**\n * Appointment Slot Picker (BOFF-3965)\n * @module kadaikodi/components\n *\n * Day chips (from the provider's bookable days) plus the real slots the\n * service returns for the chosen day. Full or too-soon slots are shown greyed\n * out; times are rendered in the provider's timezone.\n */\n\nimport { useMemo, useState } from 'react';\nimport { Loader2 } from 'lucide-react';\nimport {\n calendarDateIn,\n formatAppointmentTime,\n useAppointmentSettings,\n useAvailableSlots,\n} from '../hooks/useAppointmentsApi';\nimport { cn } from '../utils/cn';\n\nconst VISIBLE_DAYS = 7;\n\ninterface AppointmentSlotPickerProps {\n providerId: string;\n offeringId: string;\n /** Selected slot start (ISO string from the service), or empty. */\n value: string;\n onChange: (startsAt: string) => void;\n /** Slot start to hide from the list (e.g. the appointment's current time while rescheduling). */\n excludeStartsAt?: string;\n}\n\n/** `date` shifted by `days` calendar days (timezone-free date arithmetic). */\nconst addDays = (date: string, days: number): string => {\n const shifted = new Date(`${date}T12:00:00Z`);\n shifted.setUTCDate(shifted.getUTCDate() + days);\n return shifted.toISOString().slice(0, 10);\n};\n\n/**\n * Chip label for a bookable day. Relative labels come from comparing the date\n * with today in the provider's timezone, never from the chip's position: the\n * bookable days skip closed and blacked-out dates.\n */\nconst dayLabel = (date: string, today: string): string => {\n if (date === today) return 'Today';\n if (date === addDays(today, 1)) return 'Tomorrow';\n // Calendar days are timezone-free; format at UTC noon so the label never shifts a day.\n return new Date(`${date}T12:00:00Z`).toLocaleDateString('en-IN', {\n weekday: 'short',\n day: 'numeric',\n timeZone: 'UTC',\n });\n};\n\nexport function AppointmentSlotPicker({\n providerId,\n offeringId,\n value,\n onChange,\n excludeStartsAt,\n}: AppointmentSlotPickerProps) {\n const {\n data: settings,\n isLoading: settingsLoading,\n isError: settingsFailed,\n refetch: refetchSettings,\n isFetching: settingsFetching,\n } = useAppointmentSettings(providerId);\n const allDays = useMemo(() => settings?.bookableDays ?? [], [settings]);\n // The provider's horizon can run up to 90 days: show a week at a time.\n const [visibleCount, setVisibleCount] = useState(VISIBLE_DAYS);\n const days = useMemo(() => allDays.slice(0, visibleCount), [allDays, visibleCount]);\n const [pickedDay, setSelectedDay] = useState('');\n // Default to the first bookable day until the customer picks one.\n const selectedDay = pickedDay && days.includes(pickedDay) ? pickedDay : (days[0] ?? '');\n\n const {\n data: available,\n isLoading: slotsLoading,\n isError,\n refetch: refetchSlots,\n isFetching: slotsFetching,\n } = useAvailableSlots(offeringId, selectedDay || undefined);\n const slots = (available?.slots ?? []).filter((slot) => slot.startsAt !== excludeStartsAt);\n const timezone = available?.timezone ?? settings?.timezone ?? 'Asia/Kolkata';\n const today = calendarDateIn(timezone);\n\n if (settingsLoading) {\n return (\n <div className=\"flex items-center gap-2 text-sm text-text-secondary\">\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n Loading availability...\n </div>\n );\n }\n\n // A failed availability lookup is not an empty calendar: offer a retry.\n if (!settings && settingsFailed) {\n return (\n <div className=\"flex flex-wrap items-center gap-3 text-sm text-status-error-text\">\n Could not load this cart's availability.\n <button\n type=\"button\"\n onClick={() => void refetchSettings()}\n disabled={settingsFetching}\n className=\"rounded-md border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed\"\n >\n Try again\n </button>\n </div>\n );\n }\n\n if (days.length === 0) {\n return (\n <p className=\"text-sm text-text-secondary\">\n This cart is not taking appointments in the coming days.\n </p>\n );\n }\n\n return (\n <div className=\"space-y-4\">\n <div>\n <label className=\"block text-sm font-medium text-text-primary mb-1.5\">Day</label>\n <div className=\"grid grid-cols-4 sm:grid-cols-7 gap-2\">\n {days.map((day) => (\n <button\n key={day}\n type=\"button\"\n onClick={() => {\n setSelectedDay(day);\n onChange('');\n }}\n className={cn(\n 'rounded-lg border py-2 px-2 text-xs font-medium transition-colors',\n selectedDay === day\n ? 'border-action-primary-bg bg-[var(--color-accent-soft)] text-accent-primary'\n : 'border-border-subtle text-text-secondary hover:bg-accent hover:text-text-primary'\n )}\n >\n {dayLabel(day, today)}\n </button>\n ))}\n </div>\n {allDays.length > visibleCount && (\n <button\n type=\"button\"\n onClick={() => setVisibleCount((count) => count + VISIBLE_DAYS)}\n className=\"mt-2 text-xs font-medium text-accent-primary hover:underline\"\n >\n Show more days\n </button>\n )}\n </div>\n\n <div>\n <label className=\"block text-sm font-medium text-text-primary mb-1.5\">\n Time Slot <span className=\"text-status-error-text\">*</span>\n </label>\n {slotsLoading ? (\n <div className=\"flex items-center gap-2 text-sm text-text-secondary\">\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n Loading slots...\n </div>\n ) : isError ? (\n <div className=\"flex flex-wrap items-center gap-3 text-sm text-status-error-text\">\n Could not load slots for this day.\n <button\n type=\"button\"\n onClick={() => void refetchSlots()}\n disabled={slotsFetching}\n className=\"rounded-md border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed\"\n >\n Try again\n </button>\n </div>\n ) : slots.length === 0 ? (\n <p className=\"text-sm text-text-secondary\">No slots left on this day.</p>\n ) : (\n <div\n className=\"grid grid-cols-3 sm:grid-cols-4 gap-2\"\n role=\"listbox\"\n aria-label=\"Time slots\"\n >\n {slots.map((slot) => (\n <button\n key={slot.startsAt}\n type=\"button\"\n role=\"option\"\n aria-selected={value === slot.startsAt}\n disabled={!slot.available}\n onClick={() => onChange(slot.startsAt)}\n className={cn(\n 'rounded-lg border py-2 px-2 text-xs font-medium transition-colors',\n !slot.available\n ? 'border-border-subtle text-text-secondary/50 line-through cursor-not-allowed'\n : value === slot.startsAt\n ? 'border-action-primary-bg bg-[var(--color-accent-soft)] text-accent-primary'\n : 'border-border-subtle text-text-secondary hover:bg-accent hover:text-text-primary'\n )}\n >\n {formatAppointmentTime(slot.startsAt, timezone)}\n </button>\n ))}\n </div>\n )}\n {available && (\n <p className=\"mt-2 text-xs text-text-secondary\">\n {available.durationMinutes}-minute appointment · times shown in {timezone}\n </p>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;AAmBA,IAAMA,IAAe,GAafC,KAAW,GAAc,MAAyB;CACtD,IAAMC,oBAAU,IAAI,KAAK,GAAGC,EAAK,WAAW;CAE5C,OADAD,EAAQ,WAAWA,EAAQ,WAAW,IAAIE,CAAI,GACvCF,EAAQ,YAAY,CAAC,CAAC,MAAM,GAAG,EAAE;AAC1C,GAOMG,KAAY,GAAc,MAC1BF,MAASG,IAAc,UACvBH,MAASF,EAAQK,GAAO,CAAC,IAAU,8BAEhC,IAAI,KAAK,GAAGH,EAAK,WAAW,EAAA,CAAE,mBAAmB,SAAS;CAC/D,SAAS;CACT,KAA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sBX,EAAK,UAAUE,CAAQ;IACxC,GAhBDF,EAAK,QAgBJ,CACT;GACE,CAAA;GAENP,KACC,kBAAC,KAAD;IAAG,WAAU;IAAb,UAAA;KACGA,EAAU;KAAgB;KAAsCS;IAChE;;EAEF,EAAA,CAAA,CACF;;AAET"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Appointment Queue (BOFF-3965)
|
|
3
|
+
* @module kadaikodi/components
|
|
4
|
+
*
|
|
5
|
+
* Upcoming service appointments for the cart owner, kept separate from the
|
|
6
|
+
* product order board. Each row offers only the transitions the appointment
|
|
7
|
+
* state machine allows: confirm or decline a new booking, start or mark a
|
|
8
|
+
* no-show once confirmed, and complete one in progress.
|
|
9
|
+
*/
|
|
10
|
+
interface ProviderAppointmentQueueProps {
|
|
11
|
+
providerId: string;
|
|
12
|
+
onMessage: (text: string, type: 'success' | 'error') => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function ProviderAppointmentQueue({ providerId, onMessage }: ProviderAppointmentQueueProps): import('react').JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { StatusBadge as e } from "./StatusBadge.js";
|
|
2
|
+
import { ACTIVE_APPOINTMENT_STATUSES as t, formatAppointmentTime as n, formatServiceAddress as r, useAppointmentSettings as i, useProviderAppointments as a, useUpdateAppointmentStatus as o } from "../hooks/useAppointmentsApi.js";
|
|
3
|
+
import { cn as s } from "../utils/cn.js";
|
|
4
|
+
import { useEffect as c, useMemo as l, useState as u } from "react";
|
|
5
|
+
import { CalendarClock as d, Loader2 as f, MapPin as p } from "lucide-react";
|
|
6
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
7
|
+
// src/kadaikodi/components/ProviderAppointmentQueue.tsx
|
|
8
|
+
var g = 9e5, _ = 3e4, v = (e, t) => {
|
|
9
|
+
let n = t >= new Date(e.endsAt).getTime();
|
|
10
|
+
switch (e.status) {
|
|
11
|
+
case "BOOKED": {
|
|
12
|
+
let e = [];
|
|
13
|
+
return n || e.push({
|
|
14
|
+
status: "CONFIRMED",
|
|
15
|
+
label: "Confirm",
|
|
16
|
+
done: "Appointment confirmed.",
|
|
17
|
+
tone: "primary"
|
|
18
|
+
}), e.push({
|
|
19
|
+
status: "CANCELLED",
|
|
20
|
+
label: "Decline",
|
|
21
|
+
done: "Appointment declined.",
|
|
22
|
+
tone: "danger"
|
|
23
|
+
}), e;
|
|
24
|
+
}
|
|
25
|
+
case "CONFIRMED": {
|
|
26
|
+
let r = new Date(e.scheduledAt).getTime(), i = [];
|
|
27
|
+
return !n && t >= r - g && i.push({
|
|
28
|
+
status: "IN_PROGRESS",
|
|
29
|
+
label: "Start",
|
|
30
|
+
done: "Service started.",
|
|
31
|
+
tone: "primary"
|
|
32
|
+
}), t >= r && i.push({
|
|
33
|
+
status: "NO_SHOW",
|
|
34
|
+
label: "No-show",
|
|
35
|
+
done: "Marked as no-show.",
|
|
36
|
+
tone: "neutral"
|
|
37
|
+
}), i.push({
|
|
38
|
+
status: "CANCELLED",
|
|
39
|
+
label: "Cancel",
|
|
40
|
+
done: "Appointment cancelled.",
|
|
41
|
+
tone: "danger"
|
|
42
|
+
}), i;
|
|
43
|
+
}
|
|
44
|
+
case "IN_PROGRESS": return [{
|
|
45
|
+
status: "COMPLETED",
|
|
46
|
+
label: "Complete",
|
|
47
|
+
done: "Appointment completed.",
|
|
48
|
+
tone: "primary"
|
|
49
|
+
}];
|
|
50
|
+
default: return [];
|
|
51
|
+
}
|
|
52
|
+
}, y = {
|
|
53
|
+
primary: "bg-foreground text-background hover:opacity-90",
|
|
54
|
+
neutral: "border border-border-subtle text-text-primary hover:bg-accent",
|
|
55
|
+
danger: "border border-status-error-text/30 bg-status-error-bg-subtle text-status-error-text hover:opacity-90"
|
|
56
|
+
};
|
|
57
|
+
function b({ providerId: g, onMessage: b }) {
|
|
58
|
+
let { data: x, isError: S, refetch: C, isFetching: w } = i(g), T = o(), E = x?.timezone, [D, O] = u(() => Date.now());
|
|
59
|
+
c(() => {
|
|
60
|
+
let e = window.setInterval(() => O(Date.now()), _);
|
|
61
|
+
return () => window.clearInterval(e);
|
|
62
|
+
}, []);
|
|
63
|
+
let { data: k = [], isLoading: A, isError: j, refetch: M, isFetching: N } = a(g), P = A, F = l(() => k.filter((e) => t.includes(e.status)), [k]), I = (e, t) => {
|
|
64
|
+
let n;
|
|
65
|
+
if (t.status === "CANCELLED") {
|
|
66
|
+
let e = window.prompt("Reason for cancelling this appointment (shared with the customer):");
|
|
67
|
+
if (e === null) return;
|
|
68
|
+
n = e.trim() || void 0;
|
|
69
|
+
}
|
|
70
|
+
T.mutate({
|
|
71
|
+
id: e.id,
|
|
72
|
+
status: t.status,
|
|
73
|
+
reason: n
|
|
74
|
+
}, {
|
|
75
|
+
onSuccess: () => b(t.done, "success"),
|
|
76
|
+
onError: (e) => b(e.message || "Could not update the appointment.", "error")
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
return /* @__PURE__ */ h("section", {
|
|
80
|
+
"aria-labelledby": "appointment-queue-heading",
|
|
81
|
+
className: "rounded-lg border border-border-subtle bg-bg-surface p-4 shadow-sm",
|
|
82
|
+
children: [/* @__PURE__ */ h("div", {
|
|
83
|
+
className: "mb-3 flex items-center justify-between gap-3",
|
|
84
|
+
children: [/* @__PURE__ */ h("h2", {
|
|
85
|
+
id: "appointment-queue-heading",
|
|
86
|
+
className: "flex items-center gap-2 text-base font-semibold text-text-primary",
|
|
87
|
+
children: [/* @__PURE__ */ m(d, { className: "h-4 w-4" }), "Service Appointments"]
|
|
88
|
+
}), E && /* @__PURE__ */ h("span", {
|
|
89
|
+
className: "text-xs text-text-secondary",
|
|
90
|
+
children: [
|
|
91
|
+
F.length,
|
|
92
|
+
" upcoming · times in ",
|
|
93
|
+
E
|
|
94
|
+
]
|
|
95
|
+
})]
|
|
96
|
+
}), !E && S ? /* @__PURE__ */ h("div", {
|
|
97
|
+
className: "flex flex-wrap items-center gap-3 py-4 text-sm text-status-error-text",
|
|
98
|
+
children: ["Could not load this cart's appointment settings, so the queue cannot be shown.", /* @__PURE__ */ m("button", {
|
|
99
|
+
type: "button",
|
|
100
|
+
onClick: () => void C(),
|
|
101
|
+
disabled: w,
|
|
102
|
+
className: "rounded-md border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed",
|
|
103
|
+
children: "Retry"
|
|
104
|
+
})]
|
|
105
|
+
}) : j ? /* @__PURE__ */ h("div", {
|
|
106
|
+
className: "flex flex-wrap items-center gap-3 py-4 text-sm text-status-error-text",
|
|
107
|
+
children: ["Could not load your appointments.", /* @__PURE__ */ m("button", {
|
|
108
|
+
type: "button",
|
|
109
|
+
onClick: () => void M(),
|
|
110
|
+
disabled: N,
|
|
111
|
+
className: "rounded-md border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed",
|
|
112
|
+
children: "Retry"
|
|
113
|
+
})]
|
|
114
|
+
}) : P || !E ? /* @__PURE__ */ h("div", {
|
|
115
|
+
className: "flex items-center gap-2 py-4 text-sm text-text-secondary",
|
|
116
|
+
children: [/* @__PURE__ */ m(f, { className: "h-4 w-4 animate-spin" }), "Loading appointments..."]
|
|
117
|
+
}) : F.length === 0 ? /* @__PURE__ */ m("p", {
|
|
118
|
+
className: "py-4 text-sm text-text-secondary",
|
|
119
|
+
children: "No upcoming appointments. New service bookings appear here."
|
|
120
|
+
}) : /* @__PURE__ */ m("ul", {
|
|
121
|
+
className: "divide-y divide-border-subtle",
|
|
122
|
+
children: F.map((t) => /* @__PURE__ */ h("li", {
|
|
123
|
+
className: "flex flex-col gap-3 py-3 sm:flex-row sm:items-center sm:justify-between",
|
|
124
|
+
children: [/* @__PURE__ */ h("div", {
|
|
125
|
+
className: "min-w-0",
|
|
126
|
+
children: [
|
|
127
|
+
/* @__PURE__ */ h("p", {
|
|
128
|
+
className: "text-sm font-medium text-text-primary",
|
|
129
|
+
children: [
|
|
130
|
+
n(t.scheduledAt, E, {
|
|
131
|
+
weekday: "short",
|
|
132
|
+
day: "numeric",
|
|
133
|
+
month: "short",
|
|
134
|
+
hour: "numeric",
|
|
135
|
+
minute: "2-digit"
|
|
136
|
+
}),
|
|
137
|
+
" ",
|
|
138
|
+
"· ",
|
|
139
|
+
t.durationMinutes,
|
|
140
|
+
" min",
|
|
141
|
+
t.timing === "COME_NOW" && /* @__PURE__ */ m("span", {
|
|
142
|
+
className: "ml-2 text-xs text-status-warning-text",
|
|
143
|
+
children: "Come now"
|
|
144
|
+
})
|
|
145
|
+
]
|
|
146
|
+
}),
|
|
147
|
+
/* @__PURE__ */ h("p", {
|
|
148
|
+
className: "truncate text-xs text-text-secondary",
|
|
149
|
+
children: [
|
|
150
|
+
t.offering?.name ?? "Service",
|
|
151
|
+
t.contactPhone ? ` · ${t.contactPhone}` : "",
|
|
152
|
+
t.notes ? ` · ${t.notes}` : ""
|
|
153
|
+
]
|
|
154
|
+
}),
|
|
155
|
+
r(t.serviceAddress) && /* @__PURE__ */ h("p", {
|
|
156
|
+
className: "mt-0.5 flex items-start gap-1 text-xs text-text-secondary",
|
|
157
|
+
children: [/* @__PURE__ */ m(p, { className: "mt-0.5 h-3 w-3 shrink-0" }), /* @__PURE__ */ m("span", {
|
|
158
|
+
className: "break-words",
|
|
159
|
+
children: r(t.serviceAddress)
|
|
160
|
+
})]
|
|
161
|
+
})
|
|
162
|
+
]
|
|
163
|
+
}), /* @__PURE__ */ h("div", {
|
|
164
|
+
className: "flex flex-wrap items-center gap-2",
|
|
165
|
+
children: [/* @__PURE__ */ m(e, { status: t.status }), v(t, D).map((e) => /* @__PURE__ */ m("button", {
|
|
166
|
+
type: "button",
|
|
167
|
+
disabled: T.isPending,
|
|
168
|
+
onClick: () => I(t, e),
|
|
169
|
+
className: s("rounded-md px-3 py-1.5 text-xs font-medium transition-opacity disabled:opacity-60 disabled:cursor-not-allowed", y[e.tone]),
|
|
170
|
+
children: e.label
|
|
171
|
+
}, e.status))]
|
|
172
|
+
})]
|
|
173
|
+
}, t.id))
|
|
174
|
+
})]
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
export { b as ProviderAppointmentQueue };
|
|
178
|
+
|
|
179
|
+
//# sourceMappingURL=ProviderAppointmentQueue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderAppointmentQueue.js","names":["EARLY_START_GRACE_MS","CLOCK_TICK_MS","actionsFor","windowElapsed","now","appointment","actions","startsAt","toneClass","ProviderAppointmentQueue","settings","settingsFailed","refetchSettings","settingsFetching","useAppointmentSettings","providerId","updateStatus","useUpdateAppointmentStatus","timezone","setNow","useState","timer","appointments","appointmentsLoading","appointmentsFailed","refetchAppointments","appointmentsFetching","useProviderAppointments","isLoading","active","useMemo","ACTIVE_APPOINTMENT_STATUSES","a","runAction","reason","action","answer","onMessage","error","CalendarClock","Loader2","formatAppointmentTime","formatServiceAddress","MapPin","StatusBadge","cn"],"sources":["../../../src/kadaikodi/components/ProviderAppointmentQueue.tsx"],"sourcesContent":["/**\n * Provider Appointment Queue (BOFF-3965)\n * @module kadaikodi/components\n *\n * Upcoming service appointments for the cart owner, kept separate from the\n * product order board. Each row offers only the transitions the appointment\n * state machine allows: confirm or decline a new booking, start or mark a\n * no-show once confirmed, and complete one in progress.\n */\n\nimport { useEffect, useMemo, useState } from 'react';\nimport { CalendarClock, Loader2, MapPin } from 'lucide-react';\nimport { StatusBadge } from './StatusBadge';\nimport {\n type ProviderAppointmentStatus,\n type ServiceAppointment,\n ACTIVE_APPOINTMENT_STATUSES,\n formatAppointmentTime,\n formatServiceAddress,\n useAppointmentSettings,\n useProviderAppointments,\n useUpdateAppointmentStatus,\n} from '../hooks/useAppointmentsApi';\nimport { cn } from '../utils/cn';\n\ninterface QueueAction {\n status: ProviderAppointmentStatus;\n label: string;\n /** Message shown once the transition succeeds. */\n done: string;\n tone: 'primary' | 'neutral' | 'danger';\n}\n\n/** Mirrors EARLY_START_GRACE_MINUTES in wspace-kadaikodi-svc. */\nconst EARLY_START_GRACE_MS = 15 * 60_000;\n\n/** How often time-gated actions (Start, No-show, window expiry) are re-evaluated. */\nconst CLOCK_TICK_MS = 30_000;\n\nconst actionsFor = (appointment: ServiceAppointment, now: number): QueueAction[] => {\n // Mirrors the service: an appointment past its window can no longer be\n // confirmed or started, only declined/cancelled or marked as a no-show.\n const windowElapsed = now >= new Date(appointment.endsAt).getTime();\n switch (appointment.status) {\n case 'BOOKED': {\n const actions: QueueAction[] = [];\n if (!windowElapsed) {\n actions.push({\n status: 'CONFIRMED',\n label: 'Confirm',\n done: 'Appointment confirmed.',\n tone: 'primary',\n });\n }\n actions.push({\n status: 'CANCELLED',\n label: 'Decline',\n done: 'Appointment declined.',\n tone: 'danger',\n });\n return actions;\n }\n case 'CONFIRMED': {\n const startsAt = new Date(appointment.scheduledAt).getTime();\n const actions: QueueAction[] = [];\n // The service accepts IN_PROGRESS from 15 minutes before the slot and NO_SHOW once it started.\n if (!windowElapsed && now >= startsAt - EARLY_START_GRACE_MS) {\n actions.push({\n status: 'IN_PROGRESS',\n label: 'Start',\n done: 'Service started.',\n tone: 'primary',\n });\n }\n if (now >= startsAt) {\n actions.push({\n status: 'NO_SHOW',\n label: 'No-show',\n done: 'Marked as no-show.',\n tone: 'neutral',\n });\n }\n actions.push({\n status: 'CANCELLED',\n label: 'Cancel',\n done: 'Appointment cancelled.',\n tone: 'danger',\n });\n return actions;\n }\n case 'IN_PROGRESS':\n return [\n { status: 'COMPLETED', label: 'Complete', done: 'Appointment completed.', tone: 'primary' },\n ];\n default:\n return [];\n }\n};\n\nconst toneClass: Record<QueueAction['tone'], string> = {\n primary: 'bg-foreground text-background hover:opacity-90',\n neutral: 'border border-border-subtle text-text-primary hover:bg-accent',\n danger:\n 'border border-status-error-text/30 bg-status-error-bg-subtle text-status-error-text hover:opacity-90',\n};\n\ninterface ProviderAppointmentQueueProps {\n providerId: string;\n onMessage: (text: string, type: 'success' | 'error') => void;\n}\n\nexport function ProviderAppointmentQueue({ providerId, onMessage }: ProviderAppointmentQueueProps) {\n const {\n data: settings,\n isError: settingsFailed,\n refetch: refetchSettings,\n isFetching: settingsFetching,\n } = useAppointmentSettings(providerId);\n const updateStatus = useUpdateAppointmentStatus();\n // The queue is only built with the provider's configured timezone; until the\n // settings load there is no day boundary and no times are shown.\n const timezone = settings?.timezone;\n // A ticking clock, so Start and No-show appear (and expired actions\n // disappear) as time passes without reloading the page.\n const [now, setNow] = useState(() => Date.now());\n useEffect(() => {\n const timer = window.setInterval(() => setNow(Date.now()), CLOCK_TICK_MS);\n return () => window.clearInterval(timer);\n }, []);\n const {\n data: appointments = [],\n isLoading: appointmentsLoading,\n isError: appointmentsFailed,\n refetch: refetchAppointments,\n isFetching: appointmentsFetching,\n } = useProviderAppointments(providerId);\n const isLoading = appointmentsLoading;\n\n const active = useMemo(\n () => appointments.filter((a) => ACTIVE_APPOINTMENT_STATUSES.includes(a.status)),\n [appointments]\n );\n\n const runAction = (appointment: ServiceAppointment, action: QueueAction) => {\n let reason: string | undefined;\n if (action.status === 'CANCELLED') {\n const answer = window.prompt(\n 'Reason for cancelling this appointment (shared with the customer):'\n );\n if (answer === null) return;\n reason = answer.trim() || undefined;\n }\n updateStatus.mutate(\n { id: appointment.id, status: action.status, reason },\n {\n onSuccess: () => onMessage(action.done, 'success'),\n onError: (error) =>\n onMessage(error.message || 'Could not update the appointment.', 'error'),\n }\n );\n };\n\n return (\n <section\n aria-labelledby=\"appointment-queue-heading\"\n className=\"rounded-lg border border-border-subtle bg-bg-surface p-4 shadow-sm\"\n >\n <div className=\"mb-3 flex items-center justify-between gap-3\">\n <h2\n id=\"appointment-queue-heading\"\n className=\"flex items-center gap-2 text-base font-semibold text-text-primary\"\n >\n <CalendarClock className=\"h-4 w-4\" />\n Service Appointments\n </h2>\n {timezone && (\n <span className=\"text-xs text-text-secondary\">\n {active.length} upcoming · times in {timezone}\n </span>\n )}\n </div>\n\n {!timezone && settingsFailed ? (\n <div className=\"flex flex-wrap items-center gap-3 py-4 text-sm text-status-error-text\">\n Could not load this cart's appointment settings, so the queue cannot be shown.\n <button\n type=\"button\"\n onClick={() => void refetchSettings()}\n disabled={settingsFetching}\n className=\"rounded-md border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed\"\n >\n Retry\n </button>\n </div>\n ) : appointmentsFailed ? (\n <div className=\"flex flex-wrap items-center gap-3 py-4 text-sm text-status-error-text\">\n Could not load your appointments.\n <button\n type=\"button\"\n onClick={() => void refetchAppointments()}\n disabled={appointmentsFetching}\n className=\"rounded-md border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed\"\n >\n Retry\n </button>\n </div>\n ) : isLoading || !timezone ? (\n <div className=\"flex items-center gap-2 py-4 text-sm text-text-secondary\">\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n Loading appointments...\n </div>\n ) : active.length === 0 ? (\n <p className=\"py-4 text-sm text-text-secondary\">\n No upcoming appointments. New service bookings appear here.\n </p>\n ) : (\n <ul className=\"divide-y divide-border-subtle\">\n {active.map((appointment) => (\n <li\n key={appointment.id}\n className=\"flex flex-col gap-3 py-3 sm:flex-row sm:items-center sm:justify-between\"\n >\n <div className=\"min-w-0\">\n <p className=\"text-sm font-medium text-text-primary\">\n {formatAppointmentTime(appointment.scheduledAt, timezone, {\n weekday: 'short',\n day: 'numeric',\n month: 'short',\n hour: 'numeric',\n minute: '2-digit',\n })}{' '}\n · {appointment.durationMinutes} min\n {appointment.timing === 'COME_NOW' && (\n <span className=\"ml-2 text-xs text-status-warning-text\">Come now</span>\n )}\n </p>\n <p className=\"truncate text-xs text-text-secondary\">\n {appointment.offering?.name ?? 'Service'}\n {appointment.contactPhone ? ` · ${appointment.contactPhone}` : ''}\n {appointment.notes ? ` · ${appointment.notes}` : ''}\n </p>\n {formatServiceAddress(appointment.serviceAddress) && (\n <p className=\"mt-0.5 flex items-start gap-1 text-xs text-text-secondary\">\n <MapPin className=\"mt-0.5 h-3 w-3 shrink-0\" />\n <span className=\"break-words\">\n {formatServiceAddress(appointment.serviceAddress)}\n </span>\n </p>\n )}\n </div>\n <div className=\"flex flex-wrap items-center gap-2\">\n <StatusBadge status={appointment.status} />\n {actionsFor(appointment, now).map((action) => (\n <button\n key={action.status}\n type=\"button\"\n disabled={updateStatus.isPending}\n onClick={() => runAction(appointment, action)}\n className={cn(\n 'rounded-md px-3 py-1.5 text-xs font-medium transition-opacity disabled:opacity-60 disabled:cursor-not-allowed',\n toneClass[action.tone]\n )}\n >\n {action.label}\n </button>\n ))}\n </div>\n </li>\n ))}\n </ul>\n )}\n </section>\n );\n}\n"],"mappings":";;;;;;;AAkCA,IAAMA,IAAuB,KAGvBC,IAAgB,KAEhBC,KAAc,GAAiC,MAA+B;CAGlF,IAAMC,IAAgBC,KAAO,IAAI,KAAKC,EAAY,MAAM,CAAC,CAAC,QAAQ;CAClE,QAAQA,EAAY,QAApB;EACE,KAAK,UAAU;GACb,IAAMC,IAAyB,CAAC;GAehC,OAdKH,KACHG,EAAQ,KAAK;IACX,QAAQ;IACR,OAAO;IACP,MAAM;IACN,MAAM;GACR,CAAC,GAEHA,EAAQ,KAAK;IACX,QAAQ;IACR,OAAO;IACP,MAAM;IACN,MAAM;GACR,CAAC,GACMA;EACT;EACA,KAAK,aAAa;GAChB,IAAMC,IAAW,IAAI,KAAKF,EAAY,WAAW,CAAC,CAAC,QAAQ,GACrDC,IAAyB,CAAC;GAwBhC,OAtBI,CAACH,KAAiBC,KAAOG,IAAWP,KACtCM,EAAQ,KAAK;IACX,QAAQ;IACR,OAAO;IACP,MAAM;IACN,MAAM;GACR,CAAC,GAECF,KAAOG,KACTD,EAAQ,KAAK;IACX,QAAQ;IACR,OAAO;IACP,MAAM;IACN,MAAM;GACR,CAAC,GAEHA,EAAQ,KAAK;IACX,QAAQ;IACR,OAAO;IACP,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