@burdenoff/microfe-kadaikodi 2026.1126.1 → 2026.1126.2

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.
@@ -2,18 +2,19 @@ import { useKadaikodi as e } from "../context/KadaikodiContext.js";
2
2
  import "../context/index.js";
3
3
  import { kadaikodiQuery as t } from "./useKadaikodiApi.js";
4
4
  import { useMutation as n, useQuery as r, useQueryClient as i } from "@tanstack/react-query";
5
+ import { clearGraphqlFetchResponseCache as a } from "@burdenoff/fe-libs/shared/graphql";
5
6
  // src/kadaikodi/hooks/useAppointmentsApi.ts
6
- var a = "\n id providerId offeringId customerId orderId timing status scheduledAt endsAt durationMinutes\n serviceAddress contactPhone notes rescheduleCount cancellationReason\n offering { id name price }\n", o = "\n providerId slotIntervalMinutes capacityPerSlot bufferMinutes minLeadMinutes advanceBookingDays\n cancellationCutoffHours autoConfirm timezone blackoutDates isCustomized bookableDays\n", s = [
7
+ var o = "\n id providerId offeringId customerId orderId timing status scheduledAt endsAt durationMinutes\n serviceAddress contactPhone notes rescheduleCount cancellationReason\n offering { id name price }\n", s = "\n providerId slotIntervalMinutes capacityPerSlot bufferMinutes minLeadMinutes advanceBookingDays\n cancellationCutoffHours autoConfirm timezone blackoutDates isCustomized bookableDays\n", c = [
7
8
  "BOOKED",
8
9
  "CONFIRMED",
9
10
  "IN_PROGRESS"
10
- ], c = (e, t, n = {
11
+ ], l = (e, t, n = {
11
12
  hour: "numeric",
12
13
  minute: "2-digit"
13
14
  }) => new Date(e).toLocaleString("en-IN", {
14
15
  ...n,
15
16
  timeZone: t
16
- }), l = (e) => {
17
+ }), u = (e) => {
17
18
  if (!e) return null;
18
19
  let t = [
19
20
  "street",
@@ -23,12 +24,12 @@ var a = "\n id providerId offeringId customerId orderId timing status scheduled
23
24
  "instructions"
24
25
  ].map((t) => e[t]).filter((e) => typeof e == "string" && e.trim().length > 0).map((e) => e.trim());
25
26
  return t.length > 0 ? t.join(", ") : null;
26
- }, u = (e, t, n) => e.status !== "BOOKED" && e.status !== "CONFIRMED" ? !1 : e.timing === "COME_NOW" ? e.status === "BOOKED" && n < new Date(e.endsAt).getTime() : n <= new Date(e.scheduledAt).getTime() - t * 36e5, d = (e, t = /* @__PURE__ */ new Date()) => new Intl.DateTimeFormat("en-CA", {
27
+ }, d = (e, t, n) => e.status !== "BOOKED" && e.status !== "CONFIRMED" ? !1 : e.timing === "COME_NOW" ? e.status === "BOOKED" && n < new Date(e.endsAt).getTime() : n <= new Date(e.scheduledAt).getTime() - t * 36e5, f = (e, t = /* @__PURE__ */ new Date()) => new Intl.DateTimeFormat("en-CA", {
27
28
  timeZone: e,
28
29
  year: "numeric",
29
30
  month: "2-digit",
30
31
  day: "2-digit"
31
- }).format(t), f = 3e4, p = 3e4, m = 100, h = 20, g = (n) => {
32
+ }).format(t), p = 3e4, m = 3e4, h = 100, g = 20, _ = (n) => {
32
33
  let { apiGatewayUrl: i } = e();
33
34
  return r({
34
35
  queryKey: [
@@ -37,11 +38,11 @@ var a = "\n id providerId offeringId customerId orderId timing status scheduled
37
38
  n
38
39
  ],
39
40
  queryFn: async () => (await t(`query AppointmentSettings($providerId: ID!) {
40
- kadaikodiAppointmentSettings(providerId: $providerId) { ${o} }
41
+ kadaikodiAppointmentSettings(providerId: $providerId) { ${s} }
41
42
  }`, { providerId: n }, i)).kadaikodiAppointmentSettings,
42
43
  enabled: !!n
43
44
  });
44
- }, _ = (n, i) => {
45
+ }, v = (n, i) => {
45
46
  let { apiGatewayUrl: a } = e();
46
47
  return r({
47
48
  queryKey: [
@@ -56,7 +57,7 @@ var a = "\n id providerId offeringId customerId orderId timing status scheduled
56
57
  }, a)).kadaikodiListAvailableSlots,
57
58
  enabled: !!(n && i)
58
59
  });
59
- }, v = (n) => {
60
+ }, y = (n) => {
60
61
  let { apiGatewayUrl: i } = e();
61
62
  return r({
62
63
  queryKey: [
@@ -65,15 +66,15 @@ var a = "\n id providerId offeringId customerId orderId timing status scheduled
65
66
  n
66
67
  ],
67
68
  queryFn: async () => (await t(`query OrderAppointment($id: ID!) {
68
- kadaikodiOrder(id: $id) { id appointment { ${a} } }
69
+ kadaikodiOrder(id: $id) { id appointment { ${o} } }
69
70
  }`, { id: n }, i)).kadaikodiOrder?.appointment ?? null,
70
71
  enabled: !!n,
71
72
  refetchInterval: (e) => {
72
73
  let t = e.state.data;
73
- return t && s.includes(t.status) ? p : !1;
74
+ return t && c.includes(t.status) ? m : !1;
74
75
  }
75
76
  });
76
- }, y = (n) => {
77
+ }, b = (n) => {
77
78
  let { apiGatewayUrl: i } = e();
78
79
  return r({
79
80
  queryKey: [
@@ -83,34 +84,35 @@ var a = "\n id providerId offeringId customerId orderId timing status scheduled
83
84
  ],
84
85
  queryFn: async () => {
85
86
  let e = [];
86
- for (let r of s) for (let o = 0; o < h; o++) {
87
+ for (let r of c) for (let a = 0; a < g; a++) {
87
88
  let s = (await t(`query ProviderAppointments($providerId: ID!, $status: KadaikodiAppointmentStatus, $pagination: KadaikodiPaginationInput) {
88
89
  kadaikodiProviderAppointments(providerId: $providerId, status: $status, pagination: $pagination) {
89
- ${a}
90
+ ${o}
90
91
  }
91
92
  }`, {
92
93
  providerId: n,
93
94
  status: r,
94
95
  pagination: {
95
- limit: m,
96
- offset: o * m
96
+ limit: h,
97
+ offset: a * h
97
98
  }
98
99
  }, i)).kadaikodiProviderAppointments;
99
- if (e.push(...s), s.length < m) break;
100
+ if (e.push(...s), s.length < h) break;
100
101
  }
101
- let r = (e) => s.indexOf(e), o = /* @__PURE__ */ new Map();
102
+ let r = (e) => c.indexOf(e), a = /* @__PURE__ */ new Map();
102
103
  for (let t of e) {
103
- let e = o.get(t.id);
104
- (!e || r(t.status) > r(e.status)) && o.set(t.id, t);
104
+ let e = a.get(t.id);
105
+ (!e || r(t.status) > r(e.status)) && a.set(t.id, t);
105
106
  }
106
- return [...o.values()].sort((e, t) => new Date(e.scheduledAt).getTime() - new Date(t.scheduledAt).getTime());
107
+ return [...a.values()].sort((e, t) => new Date(e.scheduledAt).getTime() - new Date(t.scheduledAt).getTime());
107
108
  },
108
109
  enabled: !!n,
109
- refetchInterval: f
110
+ refetchInterval: p
110
111
  });
111
- }, b = () => {
112
+ }, x = () => {
112
113
  let e = i();
113
114
  return () => {
115
+ a();
114
116
  for (let t of [
115
117
  "appointment-slots",
116
118
  "order-appointment",
@@ -119,41 +121,41 @@ var a = "\n id providerId offeringId customerId orderId timing status scheduled
119
121
  "order"
120
122
  ]) e.invalidateQueries({ queryKey: ["kadaikodi", t] });
121
123
  };
122
- }, x = () => {
123
- let { apiGatewayUrl: r } = e(), i = b();
124
+ }, S = () => {
125
+ let { apiGatewayUrl: r } = e(), i = x();
124
126
  return n({
125
127
  mutationFn: async (e) => (await t(`mutation BookAppointment($input: KadaikodiBookAppointmentInput!) {
126
- kadaikodiBookAppointment(input: $input) { ${a} }
128
+ kadaikodiBookAppointment(input: $input) { ${o} }
127
129
  }`, { input: e }, r)).kadaikodiBookAppointment,
128
130
  onSuccess: i
129
131
  });
130
- }, S = () => {
131
- let { apiGatewayUrl: r } = e(), i = b();
132
+ }, C = () => {
133
+ let { apiGatewayUrl: r } = e(), i = x();
132
134
  return n({
133
135
  mutationFn: async ({ id: e, scheduledAt: n }) => (await t(`mutation RescheduleAppointment($id: ID!, $scheduledAt: DateTime!) {
134
- kadaikodiRescheduleAppointment(id: $id, scheduledAt: $scheduledAt) { ${a} }
136
+ kadaikodiRescheduleAppointment(id: $id, scheduledAt: $scheduledAt) { ${o} }
135
137
  }`, {
136
138
  id: e,
137
139
  scheduledAt: n
138
140
  }, r)).kadaikodiRescheduleAppointment,
139
141
  onSuccess: i
140
142
  });
141
- }, C = () => {
142
- let { apiGatewayUrl: r } = e(), i = b();
143
+ }, w = () => {
144
+ let { apiGatewayUrl: r } = e(), i = x();
143
145
  return n({
144
146
  mutationFn: async ({ id: e, reason: n }) => (await t(`mutation CancelAppointment($id: ID!, $reason: String) {
145
- kadaikodiCancelAppointment(id: $id, reason: $reason) { ${a} }
147
+ kadaikodiCancelAppointment(id: $id, reason: $reason) { ${o} }
146
148
  }`, {
147
149
  id: e,
148
150
  reason: n
149
151
  }, r)).kadaikodiCancelAppointment,
150
152
  onSuccess: i
151
153
  });
152
- }, w = () => {
153
- let { apiGatewayUrl: r } = e(), i = b();
154
+ }, T = () => {
155
+ let { apiGatewayUrl: r } = e(), i = x();
154
156
  return n({
155
157
  mutationFn: async ({ id: e, status: n, reason: i }) => (await t(`mutation UpdateAppointmentStatus($id: ID!, $status: KadaikodiAppointmentProviderStatus!, $reason: String) {
156
- kadaikodiUpdateAppointmentStatus(id: $id, status: $status, reason: $reason) { ${a} }
158
+ kadaikodiUpdateAppointmentStatus(id: $id, status: $status, reason: $reason) { ${o} }
157
159
  }`, {
158
160
  id: e,
159
161
  status: n,
@@ -161,17 +163,17 @@ var a = "\n id providerId offeringId customerId orderId timing status scheduled
161
163
  }, r)).kadaikodiUpdateAppointmentStatus,
162
164
  onSuccess: i
163
165
  });
164
- }, T = () => {
165
- let r = i(), { apiGatewayUrl: a } = e();
166
+ }, E = () => {
167
+ let r = i(), { apiGatewayUrl: o } = e();
166
168
  return n({
167
169
  mutationFn: async ({ providerId: e, input: n }) => (await t(`mutation UpsertAppointmentSettings($providerId: ID!, $input: KadaikodiAppointmentSettingsInput!) {
168
- kadaikodiUpsertAppointmentSettings(providerId: $providerId, input: $input) { ${o} }
170
+ kadaikodiUpsertAppointmentSettings(providerId: $providerId, input: $input) { ${s} }
169
171
  }`, {
170
172
  providerId: e,
171
173
  input: n
172
- }, a)).kadaikodiUpsertAppointmentSettings,
174
+ }, o)).kadaikodiUpsertAppointmentSettings,
173
175
  onSuccess: (e) => {
174
- r.setQueryData([
176
+ a(), r.setQueryData([
175
177
  "kadaikodi",
176
178
  "appointment-settings",
177
179
  e.providerId
@@ -179,6 +181,6 @@ var a = "\n id providerId offeringId customerId orderId timing status scheduled
179
181
  }
180
182
  });
181
183
  };
182
- export { s as ACTIVE_APPOINTMENT_STATUSES, d as calendarDateIn, u as customerCanChangeAppointment, c as formatAppointmentTime, l as formatServiceAddress, g as useAppointmentSettings, _ as useAvailableSlots, x as useBookAppointment, C as useCancelAppointment, v as useOrderAppointment, y as useProviderAppointments, S as useRescheduleAppointment, w as useUpdateAppointmentStatus, T as useUpsertAppointmentSettings };
184
+ export { c as ACTIVE_APPOINTMENT_STATUSES, f as calendarDateIn, d as customerCanChangeAppointment, l as formatAppointmentTime, u as formatServiceAddress, _ as useAppointmentSettings, v as useAvailableSlots, S as useBookAppointment, w as useCancelAppointment, y as useOrderAppointment, b as useProviderAppointments, C as useRescheduleAppointment, T as useUpdateAppointmentStatus, E as useUpsertAppointmentSettings };
183
185
 
184
186
  //# sourceMappingURL=useAppointmentsApi.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAppointmentsApi.js","names":["APPOINTMENT_FIELDS","SETTINGS_FIELDS","ACTIVE_APPOINTMENT_STATUSES","formatAppointmentTime","iso","options","timezone","formatServiceAddress","address","parts","key","value","customerCanChangeAppointment","appointment","now","cancellationCutoffHours","calendarDateIn","instant","PROVIDER_QUEUE_POLL_MS","ACTIVE_APPOINTMENT_POLL_MS","PROVIDER_QUEUE_PAGE_SIZE","PROVIDER_QUEUE_MAX_PAGES","useAppointmentSettings","useKadaikodi","useQuery","providerId","kadaikodiQuery","apiGatewayUrl","useAvailableSlots","offeringId","date","useOrderAppointment","orderId","query","useProviderAppointments","appointments","status","page","rows","rank","byId","seen","a","b","useInvalidateAppointments","queryClient","useQueryClient","useBookAppointment","invalidate","useMutation","useRescheduleAppointment","useCancelAppointment","useUpdateAppointmentStatus","useUpsertAppointmentSettings","settings"],"sources":["../../../src/kadaikodi/hooks/useAppointmentsApi.ts"],"sourcesContent":["/**\n * Service appointment hooks (BOFF-3965).\n *\n * Slot availability, booking, reschedule/cancel and the provider appointment\n * queue all come from wspace-kadaikodi-svc; nothing here computes slots on the\n * client. Every appointment is paired with an order, so mutations also\n * invalidate the order caches the existing pages read.\n *\n * @module kadaikodi/hooks\n */\n\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\n\nimport { useKadaikodi } from '../context';\nimport { kadaikodiQuery } from './useKadaikodiApi';\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport type AppointmentStatus =\n 'BOOKED' | 'CONFIRMED' | 'IN_PROGRESS' | 'COMPLETED' | 'CANCELLED' | 'NO_SHOW';\n\n/** Statuses a provider can move an appointment to. */\nexport type ProviderAppointmentStatus = Exclude<AppointmentStatus, 'BOOKED'>;\n\nexport type AppointmentTiming = 'SCHEDULED' | 'COME_NOW';\n\nexport interface ServiceAppointment {\n id: string;\n providerId: string;\n offeringId: string;\n customerId: string;\n orderId: string | null;\n timing: AppointmentTiming;\n status: AppointmentStatus;\n scheduledAt: string;\n endsAt: string;\n durationMinutes: number;\n serviceAddress: Record<string, unknown> | null;\n contactPhone: string | null;\n notes: string | null;\n rescheduleCount: number;\n cancellationReason: string | null;\n offering: { id: string; name: string; price: number } | null;\n}\n\nexport interface AppointmentSlot {\n startsAt: string;\n endsAt: string;\n available: boolean;\n remainingCapacity: number;\n}\n\nexport interface AvailableSlots {\n date: string;\n timezone: string;\n durationMinutes: number;\n slots: AppointmentSlot[];\n nextAvailableAt: string | null;\n}\n\nexport interface AppointmentSettings {\n providerId: string;\n slotIntervalMinutes: number;\n capacityPerSlot: number;\n bufferMinutes: number;\n minLeadMinutes: number;\n advanceBookingDays: number;\n cancellationCutoffHours: number;\n autoConfirm: boolean;\n timezone: string;\n blackoutDates: string[];\n isCustomized: boolean;\n bookableDays: string[];\n}\n\nexport type AppointmentSettingsInput = Partial<\n Omit<AppointmentSettings, 'providerId' | 'isCustomized' | 'bookableDays'>\n>;\n\nexport interface BookAppointmentInput {\n offeringId: string;\n timing: AppointmentTiming;\n scheduledAt?: string;\n serviceAddress?: Record<string, unknown>;\n contactPhone?: string;\n notes?: string;\n paymentMethod?: string;\n}\n\nconst APPOINTMENT_FIELDS = `\n id providerId offeringId customerId orderId timing status scheduledAt endsAt durationMinutes\n serviceAddress contactPhone notes rescheduleCount cancellationReason\n offering { id name price }\n`;\n\nconst SETTINGS_FIELDS = `\n providerId slotIntervalMinutes capacityPerSlot bufferMinutes minLeadMinutes advanceBookingDays\n cancellationCutoffHours autoConfirm timezone blackoutDates isCustomized bookableDays\n`;\n\n/** Statuses that still occupy the provider's calendar. */\nexport const ACTIVE_APPOINTMENT_STATUSES: readonly AppointmentStatus[] = [\n 'BOOKED',\n 'CONFIRMED',\n 'IN_PROGRESS',\n];\n\n/**\n * Format an instant in the provider's timezone so customers and providers see\n * the same wall-clock time regardless of the device timezone.\n */\nexport const formatAppointmentTime = (\n iso: string,\n timezone: string,\n options: Intl.DateTimeFormatOptions = { hour: 'numeric', minute: '2-digit' }\n): string => new Date(iso).toLocaleString('en-IN', { ...options, timeZone: timezone });\n\n/**\n * One-line service address for display (street, landmark, instructions as\n * sent by DirectServiceBookingPage, plus area/city when present), or null.\n */\nexport const formatServiceAddress = (address: Record<string, unknown> | null): string | null => {\n if (!address) return null;\n const parts = ['street', 'area', 'city', 'landmark', 'instructions']\n .map((key) => address[key])\n .filter((value): value is string => typeof value === 'string' && value.trim().length > 0)\n .map((value) => value.trim());\n return parts.length > 0 ? parts.join(', ') : null;\n};\n\n/**\n * Whether the customer may still cancel or reschedule, mirroring the service\n * rule: a scheduled booking (BOOKED or CONFIRMED) until `cancellationCutoffHours`\n * before its start; a come-now request only while it is unconfirmed and its\n * window has not ended.\n */\nexport const customerCanChangeAppointment = (\n appointment: Pick<ServiceAppointment, 'status' | 'timing' | 'scheduledAt' | 'endsAt'>,\n cancellationCutoffHours: number,\n now: number\n): boolean => {\n if (appointment.status !== 'BOOKED' && appointment.status !== 'CONFIRMED') return false;\n if (appointment.timing === 'COME_NOW') {\n return appointment.status === 'BOOKED' && now < new Date(appointment.endsAt).getTime();\n }\n const cutoff = new Date(appointment.scheduledAt).getTime() - cancellationCutoffHours * 3_600_000;\n return now <= cutoff;\n};\n\n/** Calendar date (`YYYY-MM-DD`) of `instant` in `timezone`. */\nexport const calendarDateIn = (timezone: string, instant: Date = new Date()): string =>\n // en-CA formats dates as YYYY-MM-DD.\n new Intl.DateTimeFormat('en-CA', {\n timeZone: timezone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n }).format(instant);\n\n/** How often the provider queue polls for new bookings while it is open. */\nconst PROVIDER_QUEUE_POLL_MS = 30_000;\n/** How often a customer's active appointment is refreshed while it is on screen. */\nconst ACTIVE_APPOINTMENT_POLL_MS = 30_000;\n/** Page size for the provider queue (the service's maximum page size). */\nconst PROVIDER_QUEUE_PAGE_SIZE = 100;\n/** Upper bound on pages fetched per status and refresh (2,000 active appointments). */\nconst PROVIDER_QUEUE_MAX_PAGES = 20;\n\n// ============================================================================\n// Queries\n// ============================================================================\n\nexport const useAppointmentSettings = (providerId?: string) => {\n const { apiGatewayUrl } = useKadaikodi();\n return useQuery({\n queryKey: ['kadaikodi', 'appointment-settings', providerId],\n queryFn: async () => {\n const result = await kadaikodiQuery<{ kadaikodiAppointmentSettings: AppointmentSettings }>(\n `query AppointmentSettings($providerId: ID!) {\n kadaikodiAppointmentSettings(providerId: $providerId) { ${SETTINGS_FIELDS} }\n }`,\n { providerId },\n apiGatewayUrl\n );\n return result.kadaikodiAppointmentSettings;\n },\n enabled: Boolean(providerId),\n });\n};\n\nexport const useAvailableSlots = (offeringId?: string, date?: string) => {\n const { apiGatewayUrl } = useKadaikodi();\n return useQuery({\n queryKey: ['kadaikodi', 'appointment-slots', offeringId, date],\n queryFn: async () => {\n const result = await kadaikodiQuery<{ kadaikodiListAvailableSlots: AvailableSlots }>(\n `query AvailableSlots($offeringId: ID!, $date: String!) {\n kadaikodiListAvailableSlots(offeringId: $offeringId, date: $date) {\n date timezone durationMinutes nextAvailableAt\n slots { startsAt endsAt available remainingCapacity }\n }\n }`,\n { offeringId, date },\n apiGatewayUrl\n );\n return result.kadaikodiListAvailableSlots;\n },\n enabled: Boolean(offeringId && date),\n });\n};\n\n/** The appointment booked with an order, or null when the order is not a service booking. */\nexport const useOrderAppointment = (orderId?: string) => {\n const { apiGatewayUrl } = useKadaikodi();\n return useQuery({\n queryKey: ['kadaikodi', 'order-appointment', orderId],\n queryFn: async () => {\n const result = await kadaikodiQuery<{\n kadaikodiOrder: { id: string; appointment: ServiceAppointment | null } | null;\n }>(\n `query OrderAppointment($id: ID!) {\n kadaikodiOrder(id: $id) { id appointment { ${APPOINTMENT_FIELDS} } }\n }`,\n { id: orderId },\n apiGatewayUrl\n );\n return result.kadaikodiOrder?.appointment ?? null;\n },\n enabled: Boolean(orderId),\n // While the appointment is still active the provider may confirm, start,\n // cancel or complete it from another session: poll so the status and the\n // customer's actions stay current. Finished or non-appointment orders stop.\n refetchInterval: (query) => {\n const appointment = query.state.data;\n return appointment && ACTIVE_APPOINTMENT_STATUSES.includes(appointment.status)\n ? ACTIVE_APPOINTMENT_POLL_MS\n : false;\n },\n });\n};\n\n/**\n * Every active (BOOKED, CONFIRMED, IN_PROGRESS) appointment of a provider,\n * soonest first. Queried per status with no date bound, so overdue bookings\n * from earlier days (e.g. a service that ran past midnight) stay manageable.\n */\nexport const useProviderAppointments = (providerId?: string) => {\n const { apiGatewayUrl } = useKadaikodi();\n return useQuery({\n queryKey: ['kadaikodi', 'provider-appointments', providerId],\n queryFn: async () => {\n const appointments: ServiceAppointment[] = [];\n for (const status of ACTIVE_APPOINTMENT_STATUSES) {\n // Walk every page (the service caps a page at 100 rows).\n for (let page = 0; page < PROVIDER_QUEUE_MAX_PAGES; page++) {\n const result = await kadaikodiQuery<{\n kadaikodiProviderAppointments: ServiceAppointment[];\n }>(\n `query ProviderAppointments($providerId: ID!, $status: KadaikodiAppointmentStatus, $pagination: KadaikodiPaginationInput) {\n kadaikodiProviderAppointments(providerId: $providerId, status: $status, pagination: $pagination) {\n ${APPOINTMENT_FIELDS}\n }\n }`,\n {\n providerId,\n status,\n pagination: {\n limit: PROVIDER_QUEUE_PAGE_SIZE,\n offset: page * PROVIDER_QUEUE_PAGE_SIZE,\n },\n },\n apiGatewayUrl\n );\n const rows = result.kadaikodiProviderAppointments;\n appointments.push(...rows);\n if (rows.length < PROVIDER_QUEUE_PAGE_SIZE) break;\n }\n }\n // An appointment can advance (e.g. BOOKED -> CONFIRMED) between the\n // per-status requests and appear twice; keep the most advanced record.\n const rank = (status: AppointmentStatus): number =>\n ACTIVE_APPOINTMENT_STATUSES.indexOf(status);\n const byId = new Map<string, ServiceAppointment>();\n for (const appointment of appointments) {\n const seen = byId.get(appointment.id);\n if (!seen || rank(appointment.status) > rank(seen.status)) {\n byId.set(appointment.id, appointment);\n }\n }\n return [...byId.values()].sort(\n (a, b) => new Date(a.scheduledAt).getTime() - new Date(b.scheduledAt).getTime()\n );\n },\n enabled: Boolean(providerId),\n // Poll so incoming bookings appear without a reload.\n refetchInterval: PROVIDER_QUEUE_POLL_MS,\n });\n};\n\n// ============================================================================\n// Mutations\n// ============================================================================\n\nconst useInvalidateAppointments = () => {\n const queryClient = useQueryClient();\n return () => {\n for (const key of [\n 'appointment-slots',\n 'order-appointment',\n 'provider-appointments',\n 'orders',\n 'order',\n ]) {\n void queryClient.invalidateQueries({ queryKey: ['kadaikodi', key] });\n }\n };\n};\n\nexport const useBookAppointment = () => {\n const { apiGatewayUrl } = useKadaikodi();\n const invalidate = useInvalidateAppointments();\n return useMutation({\n mutationFn: async (input: BookAppointmentInput) => {\n const result = await kadaikodiQuery<{ kadaikodiBookAppointment: ServiceAppointment }>(\n `mutation BookAppointment($input: KadaikodiBookAppointmentInput!) {\n kadaikodiBookAppointment(input: $input) { ${APPOINTMENT_FIELDS} }\n }`,\n { input },\n apiGatewayUrl\n );\n return result.kadaikodiBookAppointment;\n },\n onSuccess: invalidate,\n });\n};\n\nexport const useRescheduleAppointment = () => {\n const { apiGatewayUrl } = useKadaikodi();\n const invalidate = useInvalidateAppointments();\n return useMutation({\n mutationFn: async ({ id, scheduledAt }: { id: string; scheduledAt: string }) => {\n const result = await kadaikodiQuery<{ kadaikodiRescheduleAppointment: ServiceAppointment }>(\n `mutation RescheduleAppointment($id: ID!, $scheduledAt: DateTime!) {\n kadaikodiRescheduleAppointment(id: $id, scheduledAt: $scheduledAt) { ${APPOINTMENT_FIELDS} }\n }`,\n { id, scheduledAt },\n apiGatewayUrl\n );\n return result.kadaikodiRescheduleAppointment;\n },\n onSuccess: invalidate,\n });\n};\n\nexport const useCancelAppointment = () => {\n const { apiGatewayUrl } = useKadaikodi();\n const invalidate = useInvalidateAppointments();\n return useMutation({\n mutationFn: async ({ id, reason }: { id: string; reason?: string }) => {\n const result = await kadaikodiQuery<{ kadaikodiCancelAppointment: ServiceAppointment }>(\n `mutation CancelAppointment($id: ID!, $reason: String) {\n kadaikodiCancelAppointment(id: $id, reason: $reason) { ${APPOINTMENT_FIELDS} }\n }`,\n { id, reason },\n apiGatewayUrl\n );\n return result.kadaikodiCancelAppointment;\n },\n onSuccess: invalidate,\n });\n};\n\nexport const useUpdateAppointmentStatus = () => {\n const { apiGatewayUrl } = useKadaikodi();\n const invalidate = useInvalidateAppointments();\n return useMutation({\n mutationFn: async ({\n id,\n status,\n reason,\n }: {\n id: string;\n status: ProviderAppointmentStatus;\n reason?: string;\n }) => {\n const result = await kadaikodiQuery<{ kadaikodiUpdateAppointmentStatus: ServiceAppointment }>(\n `mutation UpdateAppointmentStatus($id: ID!, $status: KadaikodiAppointmentProviderStatus!, $reason: String) {\n kadaikodiUpdateAppointmentStatus(id: $id, status: $status, reason: $reason) { ${APPOINTMENT_FIELDS} }\n }`,\n { id, status, reason },\n apiGatewayUrl\n );\n return result.kadaikodiUpdateAppointmentStatus;\n },\n onSuccess: invalidate,\n });\n};\n\nexport const useUpsertAppointmentSettings = () => {\n const queryClient = useQueryClient();\n const { apiGatewayUrl } = useKadaikodi();\n return useMutation({\n mutationFn: async ({\n providerId,\n input,\n }: {\n providerId: string;\n input: AppointmentSettingsInput;\n }) => {\n const result = await kadaikodiQuery<{\n kadaikodiUpsertAppointmentSettings: AppointmentSettings;\n }>(\n `mutation UpsertAppointmentSettings($providerId: ID!, $input: KadaikodiAppointmentSettingsInput!) {\n kadaikodiUpsertAppointmentSettings(providerId: $providerId, input: $input) { ${SETTINGS_FIELDS} }\n }`,\n { providerId, input },\n apiGatewayUrl\n );\n return result.kadaikodiUpsertAppointmentSettings;\n },\n onSuccess: (settings) => {\n queryClient.setQueryData(\n ['kadaikodi', 'appointment-settings', settings.providerId],\n settings\n );\n void queryClient.invalidateQueries({ queryKey: ['kadaikodi', 'appointment-slots'] });\n },\n });\n};\n"],"mappings":";;;;;AA2FA,IAAMA,IAAqB,4MAMrBC,IAAkB,gMAMXC,IAA4D;CACvE;CACA;CACA;AACF,GAMaC,KACX,GACA,GACA,IAAsC;CAAE,MAAM;CAAW,QAAQ;AAAU,MAChE,IAAI,KAAKC,CAAG,CAAC,CAAC,eAAe,SAAS;CAAE,GAAGC;CAAS,UAAUC;AAAS,CAAC,GAMxEC,KAAwB,MAA2D;CAC9F,IAAI,CAACC,GAAS,OAAO;CACrB,IAAMC,IAAQ;EAAC;EAAU;EAAQ;EAAQ;EAAY;CAAc,CAAC,CACjE,KAAK,MAAQD,EAAQE,EAAI,CAAC,CAC1B,QAAQ,MAA2B,OAAOC,KAAU,YAAYA,EAAM,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,CACxF,KAAK,MAAUA,EAAM,KAAK,CAAC;CAC9B,OAAOF,EAAM,SAAS,IAAIA,EAAM,KAAK,IAAI,IAAI;AAC/C,GAQaG,KACX,GACA,GACA,MAEIC,EAAY,WAAW,YAAYA,EAAY,WAAW,cAAoB,KAC9EA,EAAY,WAAW,aAClBA,EAAY,WAAW,YAAYC,IAAM,IAAI,KAAKD,EAAY,MAAM,CAAC,CAAC,QAAQ,IAGhFC,KADQ,IAAI,KAAKD,EAAY,WAAW,CAAC,CAAC,QAAQ,IAAIE,IAA0B,MAK5EC,KAAkB,GAAkB,oBAAgB,IAAI,KAAK,MAExE,IAAI,KAAK,eAAe,SAAS;CAC/B,U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,GACjCyB,IAAaJ,EAA0B;CAC7C,OAAOK,EAAY;EACjB,YAAY,OAAO,EAAE,OAAI,sBAQhB,MAPcvB,EACnB;iFACyE1B,EAAmB;YAE5F;GAAE;GAAI;EAAY,GAClB2B,CACF,EAAA,CACc;EAEhB,WAAWqB;CACb,CAAC;AACH,GAEaG,UAA6B;CACxC,IAAM,EAAE,qBAAkB5B,EAAa,GACjCyB,IAAaJ,EAA0B;CAC7C,OAAOK,EAAY;EACjB,YAAY,OAAO,EAAE,OAAI,iBAQhB,MAPcvB,EACnB;mEAC2D1B,EAAmB;YAE9E;GAAE;GAAI;EAAO,GACb2B,CACF,EAAA,CACc;EAEhB,WAAWqB;CACb,CAAC;AACH,GAEaI,UAAmC;CAC9C,IAAM,EAAE,qBAAkB7B,EAAa,GACjCyB,IAAaJ,EAA0B;CAC7C,OAAOK,EAAY;EACjB,YAAY,OAAO,EACjB,OACA,WACA,iBAaO,MAPcvB,EACnB;0FACkF1B,EAAmB;YAErG;GAAE;GAAI;GAAQ;EAAO,GACrB2B,CACF,EAAA,CACc;EAEhB,WAAWqB;CACb,CAAC;AACH,GAEaK,UAAqC;CAChD,IAAMR,IAAcC,EAAe,GAC7B,EAAE,qBAAkBvB,EAAa;CACvC,OAAO0B,EAAY;EACjB,YAAY,OAAO,EACjB,eACA,gBAcO,MATcvB,EAGnB;yFACiFzB,EAAgB;YAEjG;GAAE;GAAY;EAAM,GACpB0B,CACF,EAAA,CACc;EAEhB,YAAY,MAAa;GAKvB,AAJAkB,EAAY,aACV;IAAC;IAAa;IAAwBS,EAAS;GAAU,GACzDA,CACF,GACAT,EAAiB,kBAAkB,EAAE,UAAU,CAAC,aAAa,mBAAmB,EAAE,CAAC;EACrF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"useAppointmentsApi.js","names":["APPOINTMENT_FIELDS","SETTINGS_FIELDS","ACTIVE_APPOINTMENT_STATUSES","formatAppointmentTime","iso","options","timezone","formatServiceAddress","address","parts","key","value","customerCanChangeAppointment","appointment","now","cancellationCutoffHours","calendarDateIn","instant","PROVIDER_QUEUE_POLL_MS","ACTIVE_APPOINTMENT_POLL_MS","PROVIDER_QUEUE_PAGE_SIZE","PROVIDER_QUEUE_MAX_PAGES","useAppointmentSettings","useKadaikodi","useQuery","providerId","kadaikodiQuery","apiGatewayUrl","useAvailableSlots","offeringId","date","useOrderAppointment","orderId","query","useProviderAppointments","appointments","status","page","rows","rank","byId","seen","a","b","useInvalidateAppointments","queryClient","useQueryClient","useBookAppointment","invalidate","useMutation","useRescheduleAppointment","useCancelAppointment","useUpdateAppointmentStatus","useUpsertAppointmentSettings","clearGraphqlFetchResponseCache","settings"],"sources":["../../../src/kadaikodi/hooks/useAppointmentsApi.ts"],"sourcesContent":["/**\n * Service appointment hooks (BOFF-3965).\n *\n * Slot availability, booking, reschedule/cancel and the provider appointment\n * queue all come from wspace-kadaikodi-svc; nothing here computes slots on the\n * client. Every appointment is paired with an order, so mutations also\n * invalidate the order caches the existing pages read.\n *\n * @module kadaikodi/hooks\n */\n\nimport { clearGraphqlFetchResponseCache } from '@burdenoff/fe-libs/shared/graphql';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\n\nimport { useKadaikodi } from '../context';\nimport { kadaikodiQuery } from './useKadaikodiApi';\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport type AppointmentStatus =\n 'BOOKED' | 'CONFIRMED' | 'IN_PROGRESS' | 'COMPLETED' | 'CANCELLED' | 'NO_SHOW';\n\n/** Statuses a provider can move an appointment to. */\nexport type ProviderAppointmentStatus = Exclude<AppointmentStatus, 'BOOKED'>;\n\nexport type AppointmentTiming = 'SCHEDULED' | 'COME_NOW';\n\nexport interface ServiceAppointment {\n id: string;\n providerId: string;\n offeringId: string;\n customerId: string;\n orderId: string | null;\n timing: AppointmentTiming;\n status: AppointmentStatus;\n scheduledAt: string;\n endsAt: string;\n durationMinutes: number;\n serviceAddress: Record<string, unknown> | null;\n contactPhone: string | null;\n notes: string | null;\n rescheduleCount: number;\n cancellationReason: string | null;\n offering: { id: string; name: string; price: number } | null;\n}\n\nexport interface AppointmentSlot {\n startsAt: string;\n endsAt: string;\n available: boolean;\n remainingCapacity: number;\n}\n\nexport interface AvailableSlots {\n date: string;\n timezone: string;\n durationMinutes: number;\n slots: AppointmentSlot[];\n nextAvailableAt: string | null;\n}\n\nexport interface AppointmentSettings {\n providerId: string;\n slotIntervalMinutes: number;\n capacityPerSlot: number;\n bufferMinutes: number;\n minLeadMinutes: number;\n advanceBookingDays: number;\n cancellationCutoffHours: number;\n autoConfirm: boolean;\n timezone: string;\n blackoutDates: string[];\n isCustomized: boolean;\n bookableDays: string[];\n}\n\nexport type AppointmentSettingsInput = Partial<\n Omit<AppointmentSettings, 'providerId' | 'isCustomized' | 'bookableDays'>\n>;\n\nexport interface BookAppointmentInput {\n offeringId: string;\n timing: AppointmentTiming;\n scheduledAt?: string;\n serviceAddress?: Record<string, unknown>;\n contactPhone?: string;\n notes?: string;\n paymentMethod?: string;\n}\n\nconst APPOINTMENT_FIELDS = `\n id providerId offeringId customerId orderId timing status scheduledAt endsAt durationMinutes\n serviceAddress contactPhone notes rescheduleCount cancellationReason\n offering { id name price }\n`;\n\nconst SETTINGS_FIELDS = `\n providerId slotIntervalMinutes capacityPerSlot bufferMinutes minLeadMinutes advanceBookingDays\n cancellationCutoffHours autoConfirm timezone blackoutDates isCustomized bookableDays\n`;\n\n/** Statuses that still occupy the provider's calendar. */\nexport const ACTIVE_APPOINTMENT_STATUSES: readonly AppointmentStatus[] = [\n 'BOOKED',\n 'CONFIRMED',\n 'IN_PROGRESS',\n];\n\n/**\n * Format an instant in the provider's timezone so customers and providers see\n * the same wall-clock time regardless of the device timezone.\n */\nexport const formatAppointmentTime = (\n iso: string,\n timezone: string,\n options: Intl.DateTimeFormatOptions = { hour: 'numeric', minute: '2-digit' }\n): string => new Date(iso).toLocaleString('en-IN', { ...options, timeZone: timezone });\n\n/**\n * One-line service address for display (street, landmark, instructions as\n * sent by DirectServiceBookingPage, plus area/city when present), or null.\n */\nexport const formatServiceAddress = (address: Record<string, unknown> | null): string | null => {\n if (!address) return null;\n const parts = ['street', 'area', 'city', 'landmark', 'instructions']\n .map((key) => address[key])\n .filter((value): value is string => typeof value === 'string' && value.trim().length > 0)\n .map((value) => value.trim());\n return parts.length > 0 ? parts.join(', ') : null;\n};\n\n/**\n * Whether the customer may still cancel or reschedule, mirroring the service\n * rule: a scheduled booking (BOOKED or CONFIRMED) until `cancellationCutoffHours`\n * before its start; a come-now request only while it is unconfirmed and its\n * window has not ended.\n */\nexport const customerCanChangeAppointment = (\n appointment: Pick<ServiceAppointment, 'status' | 'timing' | 'scheduledAt' | 'endsAt'>,\n cancellationCutoffHours: number,\n now: number\n): boolean => {\n if (appointment.status !== 'BOOKED' && appointment.status !== 'CONFIRMED') return false;\n if (appointment.timing === 'COME_NOW') {\n return appointment.status === 'BOOKED' && now < new Date(appointment.endsAt).getTime();\n }\n const cutoff = new Date(appointment.scheduledAt).getTime() - cancellationCutoffHours * 3_600_000;\n return now <= cutoff;\n};\n\n/** Calendar date (`YYYY-MM-DD`) of `instant` in `timezone`. */\nexport const calendarDateIn = (timezone: string, instant: Date = new Date()): string =>\n // en-CA formats dates as YYYY-MM-DD.\n new Intl.DateTimeFormat('en-CA', {\n timeZone: timezone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n }).format(instant);\n\n/** How often the provider queue polls for new bookings while it is open. */\nconst PROVIDER_QUEUE_POLL_MS = 30_000;\n/** How often a customer's active appointment is refreshed while it is on screen. */\nconst ACTIVE_APPOINTMENT_POLL_MS = 30_000;\n/** Page size for the provider queue (the service's maximum page size). */\nconst PROVIDER_QUEUE_PAGE_SIZE = 100;\n/** Upper bound on pages fetched per status and refresh (2,000 active appointments). */\nconst PROVIDER_QUEUE_MAX_PAGES = 20;\n\n// ============================================================================\n// Queries\n// ============================================================================\n\nexport const useAppointmentSettings = (providerId?: string) => {\n const { apiGatewayUrl } = useKadaikodi();\n return useQuery({\n queryKey: ['kadaikodi', 'appointment-settings', providerId],\n queryFn: async () => {\n const result = await kadaikodiQuery<{ kadaikodiAppointmentSettings: AppointmentSettings }>(\n `query AppointmentSettings($providerId: ID!) {\n kadaikodiAppointmentSettings(providerId: $providerId) { ${SETTINGS_FIELDS} }\n }`,\n { providerId },\n apiGatewayUrl\n );\n return result.kadaikodiAppointmentSettings;\n },\n enabled: Boolean(providerId),\n });\n};\n\nexport const useAvailableSlots = (offeringId?: string, date?: string) => {\n const { apiGatewayUrl } = useKadaikodi();\n return useQuery({\n queryKey: ['kadaikodi', 'appointment-slots', offeringId, date],\n queryFn: async () => {\n const result = await kadaikodiQuery<{ kadaikodiListAvailableSlots: AvailableSlots }>(\n `query AvailableSlots($offeringId: ID!, $date: String!) {\n kadaikodiListAvailableSlots(offeringId: $offeringId, date: $date) {\n date timezone durationMinutes nextAvailableAt\n slots { startsAt endsAt available remainingCapacity }\n }\n }`,\n { offeringId, date },\n apiGatewayUrl\n );\n return result.kadaikodiListAvailableSlots;\n },\n enabled: Boolean(offeringId && date),\n });\n};\n\n/** The appointment booked with an order, or null when the order is not a service booking. */\nexport const useOrderAppointment = (orderId?: string) => {\n const { apiGatewayUrl } = useKadaikodi();\n return useQuery({\n queryKey: ['kadaikodi', 'order-appointment', orderId],\n queryFn: async () => {\n const result = await kadaikodiQuery<{\n kadaikodiOrder: { id: string; appointment: ServiceAppointment | null } | null;\n }>(\n `query OrderAppointment($id: ID!) {\n kadaikodiOrder(id: $id) { id appointment { ${APPOINTMENT_FIELDS} } }\n }`,\n { id: orderId },\n apiGatewayUrl\n );\n return result.kadaikodiOrder?.appointment ?? null;\n },\n enabled: Boolean(orderId),\n // While the appointment is still active the provider may confirm, start,\n // cancel or complete it from another session: poll so the status and the\n // customer's actions stay current. Finished or non-appointment orders stop.\n refetchInterval: (query) => {\n const appointment = query.state.data;\n return appointment && ACTIVE_APPOINTMENT_STATUSES.includes(appointment.status)\n ? ACTIVE_APPOINTMENT_POLL_MS\n : false;\n },\n });\n};\n\n/**\n * Every active (BOOKED, CONFIRMED, IN_PROGRESS) appointment of a provider,\n * soonest first. Queried per status with no date bound, so overdue bookings\n * from earlier days (e.g. a service that ran past midnight) stay manageable.\n */\nexport const useProviderAppointments = (providerId?: string) => {\n const { apiGatewayUrl } = useKadaikodi();\n return useQuery({\n queryKey: ['kadaikodi', 'provider-appointments', providerId],\n queryFn: async () => {\n const appointments: ServiceAppointment[] = [];\n for (const status of ACTIVE_APPOINTMENT_STATUSES) {\n // Walk every page (the service caps a page at 100 rows).\n for (let page = 0; page < PROVIDER_QUEUE_MAX_PAGES; page++) {\n const result = await kadaikodiQuery<{\n kadaikodiProviderAppointments: ServiceAppointment[];\n }>(\n `query ProviderAppointments($providerId: ID!, $status: KadaikodiAppointmentStatus, $pagination: KadaikodiPaginationInput) {\n kadaikodiProviderAppointments(providerId: $providerId, status: $status, pagination: $pagination) {\n ${APPOINTMENT_FIELDS}\n }\n }`,\n {\n providerId,\n status,\n pagination: {\n limit: PROVIDER_QUEUE_PAGE_SIZE,\n offset: page * PROVIDER_QUEUE_PAGE_SIZE,\n },\n },\n apiGatewayUrl\n );\n const rows = result.kadaikodiProviderAppointments;\n appointments.push(...rows);\n if (rows.length < PROVIDER_QUEUE_PAGE_SIZE) break;\n }\n }\n // An appointment can advance (e.g. BOOKED -> CONFIRMED) between the\n // per-status requests and appear twice; keep the most advanced record.\n const rank = (status: AppointmentStatus): number =>\n ACTIVE_APPOINTMENT_STATUSES.indexOf(status);\n const byId = new Map<string, ServiceAppointment>();\n for (const appointment of appointments) {\n const seen = byId.get(appointment.id);\n if (!seen || rank(appointment.status) > rank(seen.status)) {\n byId.set(appointment.id, appointment);\n }\n }\n return [...byId.values()].sort(\n (a, b) => new Date(a.scheduledAt).getTime() - new Date(b.scheduledAt).getTime()\n );\n },\n enabled: Boolean(providerId),\n // Poll so incoming bookings appear without a reload.\n refetchInterval: PROVIDER_QUEUE_POLL_MS,\n });\n};\n\n// ============================================================================\n// Mutations\n// ============================================================================\n\n/**\n * After an appointment write, drop graphqlFetch's short-lived read cache before\n * invalidating: otherwise the refetches replay the pre-write responses (for up\n * to the cache TTL) and the page keeps showing the old status or slot.\n */\nconst useInvalidateAppointments = () => {\n const queryClient = useQueryClient();\n return () => {\n clearGraphqlFetchResponseCache();\n for (const key of [\n 'appointment-slots',\n 'order-appointment',\n 'provider-appointments',\n 'orders',\n 'order',\n ]) {\n void queryClient.invalidateQueries({ queryKey: ['kadaikodi', key] });\n }\n };\n};\n\nexport const useBookAppointment = () => {\n const { apiGatewayUrl } = useKadaikodi();\n const invalidate = useInvalidateAppointments();\n return useMutation({\n mutationFn: async (input: BookAppointmentInput) => {\n const result = await kadaikodiQuery<{ kadaikodiBookAppointment: ServiceAppointment }>(\n `mutation BookAppointment($input: KadaikodiBookAppointmentInput!) {\n kadaikodiBookAppointment(input: $input) { ${APPOINTMENT_FIELDS} }\n }`,\n { input },\n apiGatewayUrl\n );\n return result.kadaikodiBookAppointment;\n },\n onSuccess: invalidate,\n });\n};\n\nexport const useRescheduleAppointment = () => {\n const { apiGatewayUrl } = useKadaikodi();\n const invalidate = useInvalidateAppointments();\n return useMutation({\n mutationFn: async ({ id, scheduledAt }: { id: string; scheduledAt: string }) => {\n const result = await kadaikodiQuery<{ kadaikodiRescheduleAppointment: ServiceAppointment }>(\n `mutation RescheduleAppointment($id: ID!, $scheduledAt: DateTime!) {\n kadaikodiRescheduleAppointment(id: $id, scheduledAt: $scheduledAt) { ${APPOINTMENT_FIELDS} }\n }`,\n { id, scheduledAt },\n apiGatewayUrl\n );\n return result.kadaikodiRescheduleAppointment;\n },\n onSuccess: invalidate,\n });\n};\n\nexport const useCancelAppointment = () => {\n const { apiGatewayUrl } = useKadaikodi();\n const invalidate = useInvalidateAppointments();\n return useMutation({\n mutationFn: async ({ id, reason }: { id: string; reason?: string }) => {\n const result = await kadaikodiQuery<{ kadaikodiCancelAppointment: ServiceAppointment }>(\n `mutation CancelAppointment($id: ID!, $reason: String) {\n kadaikodiCancelAppointment(id: $id, reason: $reason) { ${APPOINTMENT_FIELDS} }\n }`,\n { id, reason },\n apiGatewayUrl\n );\n return result.kadaikodiCancelAppointment;\n },\n onSuccess: invalidate,\n });\n};\n\nexport const useUpdateAppointmentStatus = () => {\n const { apiGatewayUrl } = useKadaikodi();\n const invalidate = useInvalidateAppointments();\n return useMutation({\n mutationFn: async ({\n id,\n status,\n reason,\n }: {\n id: string;\n status: ProviderAppointmentStatus;\n reason?: string;\n }) => {\n const result = await kadaikodiQuery<{ kadaikodiUpdateAppointmentStatus: ServiceAppointment }>(\n `mutation UpdateAppointmentStatus($id: ID!, $status: KadaikodiAppointmentProviderStatus!, $reason: String) {\n kadaikodiUpdateAppointmentStatus(id: $id, status: $status, reason: $reason) { ${APPOINTMENT_FIELDS} }\n }`,\n { id, status, reason },\n apiGatewayUrl\n );\n return result.kadaikodiUpdateAppointmentStatus;\n },\n onSuccess: invalidate,\n });\n};\n\nexport const useUpsertAppointmentSettings = () => {\n const queryClient = useQueryClient();\n const { apiGatewayUrl } = useKadaikodi();\n return useMutation({\n mutationFn: async ({\n providerId,\n input,\n }: {\n providerId: string;\n input: AppointmentSettingsInput;\n }) => {\n const result = await kadaikodiQuery<{\n kadaikodiUpsertAppointmentSettings: AppointmentSettings;\n }>(\n `mutation UpsertAppointmentSettings($providerId: ID!, $input: KadaikodiAppointmentSettingsInput!) {\n kadaikodiUpsertAppointmentSettings(providerId: $providerId, input: $input) { ${SETTINGS_FIELDS} }\n }`,\n { providerId, input },\n apiGatewayUrl\n );\n return result.kadaikodiUpsertAppointmentSettings;\n },\n onSuccess: (settings) => {\n // New settings change the free slots: never replay a cached slot read.\n clearGraphqlFetchResponseCache();\n queryClient.setQueryData(\n ['kadaikodi', 'appointment-settings', settings.providerId],\n settings\n );\n void queryClient.invalidateQueries({ queryKey: ['kadaikodi', 'appointment-slots'] });\n },\n });\n};\n"],"mappings":";;;;;;AA4FA,IAAMA,IAAqB,4MAMrBC,IAAkB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GAAE;GAAI;EAAO,GACb2B,CACF,EAAA,CACc;EAEhB,WAAWqB;CACb,CAAC;AACH,GAEaI,UAAmC;CAC9C,IAAM,EAAE,qBAAkB7B,EAAa,GACjCyB,IAAaJ,EAA0B;CAC7C,OAAOK,EAAY;EACjB,YAAY,OAAO,EACjB,OACA,WACA,iBAaO,MAPcvB,EACnB;0FACkF1B,EAAmB;YAErG;GAAE;GAAI;GAAQ;EAAO,GACrB2B,CACF,EAAA,CACc;EAEhB,WAAWqB;CACb,CAAC;AACH,GAEaK,UAAqC;CAChD,IAAMR,IAAcC,EAAe,GAC7B,EAAE,qBAAkBvB,EAAa;CACvC,OAAO0B,EAAY;EACjB,YAAY,OAAO,EACjB,eACA,gBAcO,MATcvB,EAGnB;yFACiFzB,EAAgB;YAEjG;GAAE;GAAY;EAAM,GACpB0B,CACF,EAAA,CACc;EAEhB,YAAY,MAAa;GAOvB,AALA2B,EAA+B,GAC/BT,EAAY,aACV;IAAC;IAAa;IAAwBU,EAAS;GAAU,GACzDA,CACF,GACAV,EAAiB,kBAAkB,EAAE,UAAU,CAAC,aAAa,mBAAmB,EAAE,CAAC;EACrF;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-kadaikodi",
3
- "version": "2026.1126.1",
3
+ "version": "2026.1126.2",
4
4
  "description": "Burdenoff Kadaikodi Microfrontend - Mobile services marketplace platform for connecting service providers with customers",
5
5
  "type": "module",
6
6
  "files": [