@burdenoff/microfe-kadaikodi 2026.1126.2 → 2026.1127.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.
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/kadaikodi/components/CourierLocationSharingCard.d.ts +10 -0
- package/dist/kadaikodi/components/CourierLocationSharingCard.js +52 -0
- package/dist/kadaikodi/components/CourierLocationSharingCard.js.map +1 -0
- package/dist/kadaikodi/components/DropoffPinField.d.ts +16 -0
- package/dist/kadaikodi/components/DropoffPinField.js +67 -0
- package/dist/kadaikodi/components/DropoffPinField.js.map +1 -0
- package/dist/kadaikodi/components/LiveTrackingMap.d.ts +27 -0
- package/dist/kadaikodi/components/LiveTrackingMap.js +74 -0
- package/dist/kadaikodi/components/LiveTrackingMap.js.map +1 -0
- package/dist/kadaikodi/hooks/useCourierLocationSharing.d.ts +24 -0
- package/dist/kadaikodi/hooks/useCourierLocationSharing.js +54 -0
- package/dist/kadaikodi/hooks/useCourierLocationSharing.js.map +1 -0
- package/dist/kadaikodi/hooks/useTrackingApi.d.ts +63 -0
- package/dist/kadaikodi/hooks/useTrackingApi.js +37 -0
- package/dist/kadaikodi/hooks/useTrackingApi.js.map +1 -0
- package/dist/kadaikodi/pages/customer/CheckoutPage.js +222 -213
- package/dist/kadaikodi/pages/customer/CheckoutPage.js.map +1 -1
- package/dist/kadaikodi/pages/customer/OrderTrackingPage.d.ts +4 -0
- package/dist/kadaikodi/pages/customer/OrderTrackingPage.js +274 -249
- package/dist/kadaikodi/pages/customer/OrderTrackingPage.js.map +1 -1
- package/dist/kadaikodi/pages/customer/shared.d.ts +0 -13
- package/dist/kadaikodi/pages/customer/shared.js +16 -119
- package/dist/kadaikodi/pages/customer/shared.js.map +1 -1
- package/dist/kadaikodi/pages/worker/TaskDetailsPage.d.ts +3 -2
- package/dist/kadaikodi/pages/worker/TaskDetailsPage.js +67 -65
- package/dist/kadaikodi/pages/worker/TaskDetailsPage.js.map +1 -1
- package/dist/kadaikodi/utils/deviceGeolocation.d.ts +46 -0
- package/dist/kadaikodi/utils/deviceGeolocation.js +71 -0
- package/dist/kadaikodi/utils/deviceGeolocation.js.map +1 -0
- package/dist/kadaikodi/utils/leaflet.d.ts +8 -0
- package/dist/kadaikodi/utils/leaflet.js +11 -0
- package/dist/kadaikodi/utils/leaflet.js.map +1 -0
- package/dist/node_modules/leaflet/dist/leaflet-src.js +4535 -0
- package/dist/node_modules/leaflet/dist/leaflet-src.js.map +1 -0
- package/package.json +4 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e = null), t.exports), s = (e, i, o, s) => {
|
|
3
|
+
if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
|
|
4
|
+
get: ((e) => i[e]).bind(null, d),
|
|
5
|
+
enumerable: !(s = n(i, d)) || s.enumerable
|
|
6
|
+
});
|
|
7
|
+
return e;
|
|
8
|
+
}, c = (n, r, o) => (o = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule || !a.call(n, "default") ? t(o, "default", {
|
|
9
|
+
value: n,
|
|
10
|
+
enumerable: !0
|
|
11
|
+
}) : o, n));
|
|
12
|
+
export { o as __commonJSMin, c as __toESM };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Courier control for live location sharing on a delivery task (BOFF-3962).
|
|
3
|
+
*
|
|
4
|
+
* Explicit opt-in: the worker starts sharing once the order is out for
|
|
5
|
+
* delivery, and sharing stops when they leave the page, switch it off, or the
|
|
6
|
+
* service stops accepting fixes (order delivered or no longer assigned).
|
|
7
|
+
*/
|
|
8
|
+
export declare function CourierLocationSharingCard({ orderId }: {
|
|
9
|
+
orderId: string;
|
|
10
|
+
}): import('react').JSX.Element;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useCourierLocationSharing as e } from "../hooks/useCourierLocationSharing.js";
|
|
2
|
+
import { formatRelativeTime as t } from "../utils/formatters.js";
|
|
3
|
+
import { AlertTriangle as n, Loader2 as r, LocateFixed as i, LocateOff as a } from "lucide-react";
|
|
4
|
+
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
5
|
+
import { GlassCard as c } from "@burdenoff/fe-libs/ui";
|
|
6
|
+
// src/kadaikodi/components/CourierLocationSharingCard.tsx
|
|
7
|
+
function l({ orderId: l }) {
|
|
8
|
+
let { state: u, error: d, lastSentAt: f, start: p, stop: m } = e(l), h = u === "sharing" || u === "starting";
|
|
9
|
+
return /* @__PURE__ */ s(c, {
|
|
10
|
+
className: "p-5",
|
|
11
|
+
"aria-live": "polite",
|
|
12
|
+
children: [
|
|
13
|
+
/* @__PURE__ */ s("div", {
|
|
14
|
+
className: "flex flex-wrap items-start justify-between gap-3",
|
|
15
|
+
children: [/* @__PURE__ */ s("div", {
|
|
16
|
+
className: "min-w-0",
|
|
17
|
+
children: [/* @__PURE__ */ o("p", {
|
|
18
|
+
className: "text-sm font-semibold text-text-primary",
|
|
19
|
+
children: "Live location"
|
|
20
|
+
}), /* @__PURE__ */ o("p", {
|
|
21
|
+
className: "mt-0.5 text-xs text-text-secondary",
|
|
22
|
+
children: "Share your position with the customer while this order is out for delivery. It is only sent while this screen is open."
|
|
23
|
+
})]
|
|
24
|
+
}), /* @__PURE__ */ s("button", {
|
|
25
|
+
type: "button",
|
|
26
|
+
onClick: h ? m : p,
|
|
27
|
+
className: h ? "inline-flex items-center gap-1.5 rounded-md border border-border-default bg-bg-surface px-3 py-2 text-xs font-medium text-text-primary hover:bg-bg-sunken transition-colors" : "inline-flex items-center gap-1.5 rounded-md bg-action-primary-bg px-3 py-2 text-xs font-semibold text-action-primary-text hover:bg-action-primary-bg-hover transition-colors",
|
|
28
|
+
children: [o(h ? a : i, { className: "h-3.5 w-3.5" }), h ? "Stop sharing" : "Share live location"]
|
|
29
|
+
})]
|
|
30
|
+
}),
|
|
31
|
+
u === "starting" && /* @__PURE__ */ s("p", {
|
|
32
|
+
className: "mt-3 inline-flex items-center gap-1.5 text-xs text-text-secondary",
|
|
33
|
+
children: [/* @__PURE__ */ o(r, { className: "h-3.5 w-3.5 animate-spin" }), "Getting your location…"]
|
|
34
|
+
}),
|
|
35
|
+
u === "sharing" && f && /* @__PURE__ */ s("p", {
|
|
36
|
+
className: "mt-3 inline-flex items-center gap-1.5 text-xs text-status-success-text",
|
|
37
|
+
children: [
|
|
38
|
+
/* @__PURE__ */ o(i, { className: "h-3.5 w-3.5" }),
|
|
39
|
+
"Sharing · last sent ",
|
|
40
|
+
t(f)
|
|
41
|
+
]
|
|
42
|
+
}),
|
|
43
|
+
u === "error" && d && /* @__PURE__ */ s("p", {
|
|
44
|
+
className: "mt-3 flex items-start gap-1.5 text-xs text-status-error-text",
|
|
45
|
+
children: [/* @__PURE__ */ o(n, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }), d]
|
|
46
|
+
})
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export { l as CourierLocationSharingCard };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=CourierLocationSharingCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CourierLocationSharingCard.js","names":["CourierLocationSharingCard","useCourierLocationSharing","orderId","active","state","GlassCard","stop","start","jsx","LocateOff","LocateFixed","Loader2","lastSentAt","formatRelativeTime","error","AlertTriangle"],"sources":["../../../src/kadaikodi/components/CourierLocationSharingCard.tsx"],"sourcesContent":["/**\n * Courier control for live location sharing on a delivery task (BOFF-3962).\n *\n * Explicit opt-in: the worker starts sharing once the order is out for\n * delivery, and sharing stops when they leave the page, switch it off, or the\n * service stops accepting fixes (order delivered or no longer assigned).\n */\n\nimport { Loader2, LocateFixed, LocateOff, AlertTriangle } from 'lucide-react';\nimport { GlassCard } from '@burdenoff/fe-libs/ui';\n\nimport { useCourierLocationSharing } from '../hooks/useCourierLocationSharing';\nimport { formatRelativeTime } from '../utils/formatters';\n\nexport function CourierLocationSharingCard({ orderId }: { orderId: string }) {\n const { state, error, lastSentAt, start, stop } = useCourierLocationSharing(orderId);\n const active = state === 'sharing' || state === 'starting';\n\n return (\n <GlassCard className=\"p-5\" aria-live=\"polite\">\n <div className=\"flex flex-wrap items-start justify-between gap-3\">\n <div className=\"min-w-0\">\n <p className=\"text-sm font-semibold text-text-primary\">Live location</p>\n <p className=\"mt-0.5 text-xs text-text-secondary\">\n Share your position with the customer while this order is out for delivery. It is only\n sent while this screen is open.\n </p>\n </div>\n <button\n type=\"button\"\n onClick={active ? stop : start}\n className={\n active\n ? 'inline-flex items-center gap-1.5 rounded-md border border-border-default bg-bg-surface px-3 py-2 text-xs font-medium text-text-primary hover:bg-bg-sunken transition-colors'\n : 'inline-flex items-center gap-1.5 rounded-md bg-action-primary-bg px-3 py-2 text-xs font-semibold text-action-primary-text hover:bg-action-primary-bg-hover transition-colors'\n }\n >\n {active ? <LocateOff className=\"h-3.5 w-3.5\" /> : <LocateFixed className=\"h-3.5 w-3.5\" />}\n {active ? 'Stop sharing' : 'Share live location'}\n </button>\n </div>\n\n {state === 'starting' && (\n <p className=\"mt-3 inline-flex items-center gap-1.5 text-xs text-text-secondary\">\n <Loader2 className=\"h-3.5 w-3.5 animate-spin\" />\n Getting your location…\n </p>\n )}\n {state === 'sharing' && lastSentAt && (\n <p className=\"mt-3 inline-flex items-center gap-1.5 text-xs text-status-success-text\">\n <LocateFixed className=\"h-3.5 w-3.5\" />\n Sharing · last sent {formatRelativeTime(lastSentAt)}\n </p>\n )}\n {state === 'error' && error && (\n <p className=\"mt-3 flex items-start gap-1.5 text-xs text-status-error-text\">\n <AlertTriangle className=\"mt-0.5 h-3.5 w-3.5 shrink-0\" />\n {error}\n </p>\n )}\n </GlassCard>\n );\n}\n"],"mappings":";;;;;;AAcA,SAAgBA,EAA2B,EAAE,cAAgC;CAC3E,IAAM,EAAE,UAAO,UAAO,eAAY,UAAO,YAASC,EAA0BC,CAAO,GAC7EC,IAASC,MAAU,aAAaA,MAAU;CAEhD,OACE,kBAACC,GAAD;EAAW,WAAU;EAAM,aAAU;EAArC,UAAA;GACE,kBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,kBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACE,kBAAC,KAAD;MAAG,WAAU;MAA0C,UAAA;KAAgB,CAAA,GACvE,kBAAC,KAAD;MAAG,WAAU;MAAqC,UAAA;KAG/C,CAAA,CACA;IACL,CAAA,GAAA,kBAAC,UAAD;KACE,MAAK;KACL,SAASF,IAASG,IAAOC;KACzB,WACEJ,IACI,gLACA;KANR,UAAA,CASYK,EAATL,IAAUM,IAAwCC,GAAzC,EAAW,WAAU,cAAe,CAA0C,GACvFP,IAAS,iBAAiB,qBACrB;IACL,CAAA,CAAA;;GAEJC,MAAU,cACT,kBAAC,KAAD;IAAG,WAAU;IAAb,UAAA,CACE,kBAACO,GAAD,EAAS,WAAU,2BAA4B,CAAA,GAAC,wBAE/C;;GAEJP,MAAU,aAAaQ,KACtB,kBAAC,KAAD;IAAG,WAAU;IAAb,UAAA;KACE,kBAACF,GAAD,EAAa,WAAU,cAAe,CAAA;KAAC;KAClBG,EAAmBD,CAAU;IACjD;;GAEJR,MAAU,WAAWU,KACpB,kBAAC,KAAD;IAAG,WAAU;IAAb,UAAA,CACE,kBAACC,GAAD,EAAe,WAAU,8BAA+B,CAAA,GACvDD,CACA;;EAEI;;AAEf"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional drop-off pin for a delivery order (BOFF-3962).
|
|
3
|
+
*
|
|
4
|
+
* The customer can pin their current position at checkout; the service uses
|
|
5
|
+
* it only for the live tracking map and the distance-based ETA, and purges it
|
|
6
|
+
* with the rest of the tracking data after delivery.
|
|
7
|
+
*/
|
|
8
|
+
export interface DropoffPin {
|
|
9
|
+
latitude: number;
|
|
10
|
+
longitude: number;
|
|
11
|
+
accuracyMeters: number | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function DropoffPinField({ value, onChange, }: {
|
|
14
|
+
value: DropoffPin | null;
|
|
15
|
+
onChange: (pin: DropoffPin | null) => void;
|
|
16
|
+
}): import('react').JSX.Element;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { classifyGeolocationError as e, geolocationFailureMessage as t, getDevicePosition as n } from "../utils/deviceGeolocation.js";
|
|
2
|
+
import { useState as r } from "react";
|
|
3
|
+
import { Crosshair as i, Loader2 as a, X as o } from "lucide-react";
|
|
4
|
+
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
5
|
+
// src/kadaikodi/components/DropoffPinField.tsx
|
|
6
|
+
function l({ value: l, onChange: u }) {
|
|
7
|
+
let [d, f] = r(!1), [p, m] = r(null), h = async () => {
|
|
8
|
+
f(!0), m(null);
|
|
9
|
+
try {
|
|
10
|
+
let e = await n();
|
|
11
|
+
u({
|
|
12
|
+
latitude: e.latitude,
|
|
13
|
+
longitude: e.longitude,
|
|
14
|
+
accuracyMeters: e.accuracyMeters
|
|
15
|
+
});
|
|
16
|
+
} catch (n) {
|
|
17
|
+
m(t(e(n)));
|
|
18
|
+
} finally {
|
|
19
|
+
f(!1);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ c("div", {
|
|
23
|
+
className: "rounded-lg border border-border-subtle bg-bg-sunken p-3",
|
|
24
|
+
children: [l ? /* @__PURE__ */ c("div", {
|
|
25
|
+
className: "flex items-center justify-between gap-3",
|
|
26
|
+
children: [/* @__PURE__ */ c("p", {
|
|
27
|
+
className: "flex items-center gap-2 text-sm text-text-primary",
|
|
28
|
+
children: [
|
|
29
|
+
/* @__PURE__ */ s(i, { className: "h-4 w-4 text-status-success-text" }),
|
|
30
|
+
"Drop-off pinned to your current location",
|
|
31
|
+
l.accuracyMeters != null && /* @__PURE__ */ c("span", {
|
|
32
|
+
className: "text-xs text-text-secondary",
|
|
33
|
+
children: [
|
|
34
|
+
"(±",
|
|
35
|
+
Math.round(l.accuracyMeters),
|
|
36
|
+
" m)"
|
|
37
|
+
]
|
|
38
|
+
})
|
|
39
|
+
]
|
|
40
|
+
}), /* @__PURE__ */ s("button", {
|
|
41
|
+
type: "button",
|
|
42
|
+
onClick: () => u(null),
|
|
43
|
+
"aria-label": "Remove drop-off pin",
|
|
44
|
+
className: "rounded-md p-1.5 text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",
|
|
45
|
+
children: /* @__PURE__ */ s(o, { className: "h-4 w-4" })
|
|
46
|
+
})]
|
|
47
|
+
}) : /* @__PURE__ */ c("div", {
|
|
48
|
+
className: "flex flex-wrap items-center justify-between gap-3",
|
|
49
|
+
children: [/* @__PURE__ */ s("p", {
|
|
50
|
+
className: "text-xs text-text-secondary",
|
|
51
|
+
children: "Optional: pin where you are now so you get a live arrival time while the order is on its way."
|
|
52
|
+
}), /* @__PURE__ */ c("button", {
|
|
53
|
+
type: "button",
|
|
54
|
+
onClick: () => void h(),
|
|
55
|
+
disabled: d,
|
|
56
|
+
className: "inline-flex items-center gap-1.5 rounded-md border border-border-default bg-bg-surface px-3 py-2 text-xs font-medium text-text-primary hover:bg-bg-sunken transition-colors disabled:cursor-not-allowed disabled:opacity-60",
|
|
57
|
+
children: [d ? /* @__PURE__ */ s(a, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ s(i, { className: "h-3.5 w-3.5" }), "Pin my current location"]
|
|
58
|
+
})]
|
|
59
|
+
}), p && /* @__PURE__ */ s("p", {
|
|
60
|
+
className: "mt-2 text-xs text-status-error-text",
|
|
61
|
+
children: p
|
|
62
|
+
})]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export { l as DropoffPinField };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=DropoffPinField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DropoffPinField.js","names":["DropoffPinField","locating","setLocating","useState","error","setError","pinCurrentLocation","fix","getDevicePosition","e","geolocationFailureMessage","classifyGeolocationError","value","Crosshair","onChange","X","Loader2"],"sources":["../../../src/kadaikodi/components/DropoffPinField.tsx"],"sourcesContent":["/**\n * Optional drop-off pin for a delivery order (BOFF-3962).\n *\n * The customer can pin their current position at checkout; the service uses\n * it only for the live tracking map and the distance-based ETA, and purges it\n * with the rest of the tracking data after delivery.\n */\n\nimport { useState } from 'react';\nimport { Crosshair, Loader2, X } from 'lucide-react';\n\nimport {\n classifyGeolocationError,\n geolocationFailureMessage,\n getDevicePosition,\n} from '../utils/deviceGeolocation';\n\nexport interface DropoffPin {\n latitude: number;\n longitude: number;\n accuracyMeters: number | null;\n}\n\nexport function DropoffPinField({\n value,\n onChange,\n}: {\n value: DropoffPin | null;\n onChange: (pin: DropoffPin | null) => void;\n}) {\n const [locating, setLocating] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const pinCurrentLocation = async () => {\n setLocating(true);\n setError(null);\n try {\n const fix = await getDevicePosition();\n onChange({\n latitude: fix.latitude,\n longitude: fix.longitude,\n accuracyMeters: fix.accuracyMeters,\n });\n } catch (e) {\n setError(geolocationFailureMessage(classifyGeolocationError(e)));\n } finally {\n setLocating(false);\n }\n };\n\n return (\n <div className=\"rounded-lg border border-border-subtle bg-bg-sunken p-3\">\n {value ? (\n <div className=\"flex items-center justify-between gap-3\">\n <p className=\"flex items-center gap-2 text-sm text-text-primary\">\n <Crosshair className=\"h-4 w-4 text-status-success-text\" />\n Drop-off pinned to your current location\n {value.accuracyMeters != null && (\n <span className=\"text-xs text-text-secondary\">\n (±{Math.round(value.accuracyMeters)} m)\n </span>\n )}\n </p>\n <button\n type=\"button\"\n onClick={() => onChange(null)}\n aria-label=\"Remove drop-off pin\"\n className=\"rounded-md p-1.5 text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors\"\n >\n <X className=\"h-4 w-4\" />\n </button>\n </div>\n ) : (\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <p className=\"text-xs text-text-secondary\">\n Optional: pin where you are now so you get a live arrival time while the order is on its\n way.\n </p>\n <button\n type=\"button\"\n onClick={() => void pinCurrentLocation()}\n disabled={locating}\n className=\"inline-flex items-center gap-1.5 rounded-md border border-border-default bg-bg-surface px-3 py-2 text-xs font-medium text-text-primary hover:bg-bg-sunken transition-colors disabled:cursor-not-allowed disabled:opacity-60\"\n >\n {locating ? (\n <Loader2 className=\"h-3.5 w-3.5 animate-spin\" />\n ) : (\n <Crosshair className=\"h-3.5 w-3.5\" />\n )}\n Pin my current location\n </button>\n </div>\n )}\n {error && <p className=\"mt-2 text-xs text-status-error-text\">{error}</p>}\n </div>\n );\n}\n"],"mappings":";;;;;AAuBA,SAAgBA,EAAgB,EAC9B,UACA,eAIC;CACD,IAAM,CAACC,GAAUC,KAAeC,EAAS,EAAK,GACxC,CAACC,GAAOC,KAAYF,EAAwB,IAAI,GAEhDG,IAAqB,YAAY;EAErC,AADAJ,EAAY,EAAI,GAChBG,EAAS,IAAI;EACb,IAAI;GACF,IAAME,IAAM,MAAMC,EAAkB;GACpC,EAAS;IACP,UAAUD,EAAI;IACd,WAAWA,EAAI;IACf,gBAAgBA,EAAI;GACtB,CAAC;EACH,SAASE,GAAG;GACV,EAASC,EAA0BC,EAAyBF,CAAC,CAAC,CAAC;EACjE,UAAU;GACR,EAAY,EAAK;EACnB;CACF;CAEA,OACE,kBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACGG,IACC,kBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,kBAAC,KAAD;IAAG,WAAU;IAAb,UAAA;KACE,kBAACC,GAAD,EAAW,WAAU,mCAAoC,CAAA;KAAC;KAEzDD,EAAM,kBAAkB,QACvB,kBAAC,QAAD;MAAM,WAAU;MAAhB,UAAA;OAA8C;OACzC,KAAK,MAAMA,EAAM,cAAc;OAAE;MAChC;;IAEP;GACH,CAAA,GAAA,kBAAC,UAAD;IACE,MAAK;IACL,eAAeE,EAAS,IAAI;IAC5B,cAAW;IACX,WAAU;IAEV,UAAA,kBAACC,GAAD,EAAG,WAAU,UAAW,CAAA;GAClB,CAAA,CACL;EAEL,CAAA,IAAA,kBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,kBAAC,KAAD;IAAG,WAAU;IAA8B,UAAA;GAGxC,CAAA,GACH,kBAAC,UAAD;IACE,MAAK;IACL,eAAe,KAAKT,EAAmB;IACvC,UAAUL;IACV,WAAU;IAJZ,UAAA,CAMGA,IACC,kBAACe,GAAD,EAAS,WAAU,2BAA4B,CAAA,IAE/C,kBAACH,GAAD,EAAW,WAAU,cAAe,CAAA,GACpC,yBAEI;GACL,CAAA,CAAA;EAEN,CAAA,GAAAT,KAAS,kBAAC,KAAD;GAAG,WAAU;GAAuC,UAAAA;EAAS,CAAA,CACpE;;AAET"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LiveTrackingMap — real map for order tracking (BOFF-3962).
|
|
3
|
+
*
|
|
4
|
+
* An OpenStreetMap base (Leaflet, the map library the sibling MFEs use) with
|
|
5
|
+
* the cart (origin), the customer's drop-off pin and the courier's last-known
|
|
6
|
+
* position from `kadaikodiOrderTracking`. A dashed line joins courier → drop-off
|
|
7
|
+
* (straight line: there is no routing engine, so the line is not a road route).
|
|
8
|
+
* The map is created once and only its overlay layer is redrawn on each poll,
|
|
9
|
+
* so it does not flicker or lose the customer's pan/zoom.
|
|
10
|
+
*/
|
|
11
|
+
export interface MapPoint {
|
|
12
|
+
latitude: number;
|
|
13
|
+
longitude: number;
|
|
14
|
+
}
|
|
15
|
+
export interface LiveTrackingMapProps {
|
|
16
|
+
origin: MapPoint | null;
|
|
17
|
+
destination: MapPoint | null;
|
|
18
|
+
courier: (MapPoint & {
|
|
19
|
+
headingDegrees?: number | null;
|
|
20
|
+
stale?: boolean;
|
|
21
|
+
}) | null;
|
|
22
|
+
originLabel: string;
|
|
23
|
+
destinationLabel: string;
|
|
24
|
+
courierLabel: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function LiveTrackingMap({ origin, destination, courier, originLabel, destinationLabel, courierLabel, className, }: LiveTrackingMapProps): import('react').JSX.Element;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { __toESM as e } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { require_leaflet_src as t } from "../../node_modules/leaflet/dist/leaflet-src.js";
|
|
3
|
+
import { ensureLeafletCss as n, themeColor as r } from "../utils/leaflet.js";
|
|
4
|
+
import { cn as i } from "../utils/cn.js";
|
|
5
|
+
import { useEffect as a, useRef as o } from "react";
|
|
6
|
+
import { jsx as s } from "react/jsx-runtime";
|
|
7
|
+
// src/kadaikodi/components/LiveTrackingMap.tsx
|
|
8
|
+
var c = /* @__PURE__ */ e(t(), 1), l = [20.5937, 78.9629], u = (e) => [e.latitude, e.longitude], d = (e) => e.replace(/[&<>"']/g, (e) => `&#${e.charCodeAt(0)};`);
|
|
9
|
+
function f(e, t, n, r) {
|
|
10
|
+
let i = r == null ? "" : `<span style="position:absolute;inset:0;transform:rotate(${r}deg)"><span style="position:absolute;top:-8px;left:50%;transform:translateX(-50%);width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-bottom:7px solid ${t}"></span></span>`;
|
|
11
|
+
return c.default.divIcon({
|
|
12
|
+
className: "kk-tracking-marker",
|
|
13
|
+
html: `<div style="position:relative;width:${n}px;height:${n}px">` + i + `<div style="width:${n}px;height:${n}px;border-radius:9999px;background:${t};color:var(--color-bg-surface);border:2px solid var(--color-bg-surface);display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:600;box-shadow:var(--shadow-elevation-2)">${d(e)}</div></div>`,
|
|
14
|
+
iconSize: [n, n],
|
|
15
|
+
iconAnchor: [n / 2, n / 2]
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
var p = (e) => {
|
|
19
|
+
let t = document.createElement("span");
|
|
20
|
+
return t.textContent = e, t;
|
|
21
|
+
};
|
|
22
|
+
function m({ origin: e, destination: t, courier: d, originLabel: m, destinationLabel: h, courierLabel: g, className: _ }) {
|
|
23
|
+
let v = o(null), y = o(null), b = o(null), x = o(!1);
|
|
24
|
+
return a(() => {
|
|
25
|
+
let e = v.current;
|
|
26
|
+
if (!e) return;
|
|
27
|
+
n();
|
|
28
|
+
let t = c.default.map(e, {
|
|
29
|
+
center: l,
|
|
30
|
+
zoom: 4,
|
|
31
|
+
scrollWheelZoom: !1
|
|
32
|
+
});
|
|
33
|
+
c.default.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
|
34
|
+
attribution: "© OpenStreetMap contributors",
|
|
35
|
+
maxZoom: 19
|
|
36
|
+
}).addTo(t), c.default.control.scale({ imperial: !1 }).addTo(t), b.current = c.default.layerGroup().addTo(t), y.current = t;
|
|
37
|
+
let r = window.setTimeout(() => t.invalidateSize(), 80);
|
|
38
|
+
return () => {
|
|
39
|
+
window.clearTimeout(r), t.remove(), y.current = null, b.current = null, x.current = !1;
|
|
40
|
+
};
|
|
41
|
+
}, []), a(() => {
|
|
42
|
+
let n = y.current, i = b.current;
|
|
43
|
+
if (!n || !i) return;
|
|
44
|
+
i.clearLayers();
|
|
45
|
+
let a = [];
|
|
46
|
+
e && (a.push(u(e)), c.default.marker(u(e), { icon: f("C", "var(--color-text-secondary)", 24) }).bindPopup(p(m)).addTo(i)), t && (a.push(u(t)), c.default.marker(u(t), { icon: f("D", "var(--color-status-success-text)", 24) }).bindPopup(p(h)).addTo(i)), d && (a.push(u(d)), t && c.default.polyline([u(d), u(t)], {
|
|
47
|
+
color: r("--color-accent-primary"),
|
|
48
|
+
weight: 3,
|
|
49
|
+
opacity: .8,
|
|
50
|
+
dashArray: "6 6"
|
|
51
|
+
}).addTo(i), c.default.marker(u(d), {
|
|
52
|
+
icon: f("", d.stale ? "var(--color-text-muted)" : "var(--color-accent-primary)", 20, d.headingDegrees ?? void 0),
|
|
53
|
+
zIndexOffset: 1e3
|
|
54
|
+
}).bindPopup(p(g)).addTo(i)), !x.current && a.length > 0 ? (a.length === 1 ? n.setView(a[0], 15) : n.fitBounds(c.default.latLngBounds(a), {
|
|
55
|
+
padding: [32, 32],
|
|
56
|
+
maxZoom: 16
|
|
57
|
+
}), x.current = !0) : d && !n.getBounds().contains(u(d)) && n.panTo(u(d));
|
|
58
|
+
}, [
|
|
59
|
+
e,
|
|
60
|
+
t,
|
|
61
|
+
d,
|
|
62
|
+
m,
|
|
63
|
+
h,
|
|
64
|
+
g
|
|
65
|
+
]), /* @__PURE__ */ s("div", {
|
|
66
|
+
ref: v,
|
|
67
|
+
role: "region",
|
|
68
|
+
"aria-label": "Live delivery map",
|
|
69
|
+
className: i("relative z-0 w-full overflow-hidden rounded-lg border border-border-subtle bg-bg-sunken", _)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export { m as LiveTrackingMap };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=LiveTrackingMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveTrackingMap.js","names":["L","import_leaflet_src","require_leaflet_src","DEFAULT_CENTER","toLatLng","p","escapeHtml","text","c","dotIcon","pointer","headingDeg","background","size","label","popup","el","LiveTrackingMap","containerRef","useRef","mapRef","overlayRef","fittedRef","useEffect","map","resize","overlay","points","origin","originLabel","destination","destinationLabel","courier","themeColor","courierLabel","cn","className"],"sources":["../../../src/kadaikodi/components/LiveTrackingMap.tsx"],"sourcesContent":["/**\n * LiveTrackingMap — real map for order tracking (BOFF-3962).\n *\n * An OpenStreetMap base (Leaflet, the map library the sibling MFEs use) with\n * the cart (origin), the customer's drop-off pin and the courier's last-known\n * position from `kadaikodiOrderTracking`. A dashed line joins courier → drop-off\n * (straight line: there is no routing engine, so the line is not a road route).\n * The map is created once and only its overlay layer is redrawn on each poll,\n * so it does not flicker or lose the customer's pan/zoom.\n */\n\nimport { useEffect, useRef } from 'react';\nimport L from 'leaflet';\n\nimport { ensureLeafletCss, themeColor } from '../utils/leaflet';\nimport { cn } from '../utils/cn';\n\nexport interface MapPoint {\n latitude: number;\n longitude: number;\n}\n\nexport interface LiveTrackingMapProps {\n origin: MapPoint | null;\n destination: MapPoint | null;\n courier: (MapPoint & { headingDegrees?: number | null; stale?: boolean }) | null;\n originLabel: string;\n destinationLabel: string;\n courierLabel: string;\n className?: string;\n}\n\nconst DEFAULT_CENTER: L.LatLngExpression = [20.5937, 78.9629];\n\nconst toLatLng = (p: MapPoint): L.LatLngTuple => [p.latitude, p.longitude];\n\nconst escapeHtml = (text: string): string =>\n text.replace(/[&<>\"']/g, (c) => `&#${c.charCodeAt(0)};`);\n\n/**\n * A round marker drawn with theme tokens (inline CSS supports var()). When a\n * heading is given, a small pointer on the rim shows the direction of travel.\n */\nfunction dotIcon(label: string, background: string, size: number, headingDeg?: number): L.DivIcon {\n const pointer =\n headingDeg == null\n ? ''\n : `<span style=\"position:absolute;inset:0;transform:rotate(${headingDeg}deg)\">` +\n `<span style=\"position:absolute;top:-8px;left:50%;transform:translateX(-50%);width:0;height:0;` +\n `border-left:5px solid transparent;border-right:5px solid transparent;border-bottom:7px solid ${background}\"></span></span>`;\n return L.divIcon({\n className: 'kk-tracking-marker',\n html:\n `<div style=\"position:relative;width:${size}px;height:${size}px\">` +\n pointer +\n `<div style=\"width:${size}px;height:${size}px;border-radius:9999px;background:${background};` +\n `color:var(--color-bg-surface);border:2px solid var(--color-bg-surface);display:flex;align-items:center;` +\n `justify-content:center;font-size:11px;font-weight:600;box-shadow:var(--shadow-elevation-2)\">` +\n `${escapeHtml(label)}</div></div>`,\n iconSize: [size, size],\n iconAnchor: [size / 2, size / 2],\n });\n}\n\nconst popup = (text: string): HTMLElement => {\n const el = document.createElement('span');\n el.textContent = text;\n return el;\n};\n\nexport function LiveTrackingMap({\n origin,\n destination,\n courier,\n originLabel,\n destinationLabel,\n courierLabel,\n className,\n}: LiveTrackingMapProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const mapRef = useRef<L.Map | null>(null);\n const overlayRef = useRef<L.LayerGroup | null>(null);\n const fittedRef = useRef(false);\n\n // Create the map once.\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return undefined;\n ensureLeafletCss();\n const map = L.map(el, { center: DEFAULT_CENTER, zoom: 4, scrollWheelZoom: false });\n L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {\n attribution: '© OpenStreetMap contributors',\n maxZoom: 19,\n }).addTo(map);\n L.control.scale({ imperial: false }).addTo(map);\n overlayRef.current = L.layerGroup().addTo(map);\n mapRef.current = map;\n const resize = window.setTimeout(() => map.invalidateSize(), 80);\n return () => {\n window.clearTimeout(resize);\n map.remove();\n mapRef.current = null;\n overlayRef.current = null;\n fittedRef.current = false;\n };\n }, []);\n\n // Redraw the overlay whenever the tracking data changes.\n useEffect(() => {\n const map = mapRef.current;\n const overlay = overlayRef.current;\n if (!map || !overlay) return;\n overlay.clearLayers();\n\n const accent = 'var(--color-accent-primary)';\n const points: L.LatLngTuple[] = [];\n\n if (origin) {\n points.push(toLatLng(origin));\n L.marker(toLatLng(origin), { icon: dotIcon('C', 'var(--color-text-secondary)', 24) })\n .bindPopup(popup(originLabel))\n .addTo(overlay);\n }\n if (destination) {\n points.push(toLatLng(destination));\n L.marker(toLatLng(destination), {\n icon: dotIcon('D', 'var(--color-status-success-text)', 24),\n })\n .bindPopup(popup(destinationLabel))\n .addTo(overlay);\n }\n if (courier) {\n points.push(toLatLng(courier));\n if (destination) {\n L.polyline([toLatLng(courier), toLatLng(destination)], {\n color: themeColor('--color-accent-primary'),\n weight: 3,\n opacity: 0.8,\n dashArray: '6 6',\n }).addTo(overlay);\n }\n L.marker(toLatLng(courier), {\n icon: dotIcon(\n '',\n courier.stale ? 'var(--color-text-muted)' : accent,\n 20,\n courier.headingDegrees ?? undefined\n ),\n zIndexOffset: 1000,\n })\n .bindPopup(popup(courierLabel))\n .addTo(overlay);\n }\n\n // Frame everything once; afterwards keep the customer's own pan/zoom and\n // only follow the courier if it leaves the visible area.\n if (!fittedRef.current && points.length > 0) {\n if (points.length === 1) {\n map.setView(points[0], 15);\n } else {\n map.fitBounds(L.latLngBounds(points), { padding: [32, 32], maxZoom: 16 });\n }\n fittedRef.current = true;\n } else if (courier && !map.getBounds().contains(toLatLng(courier))) {\n map.panTo(toLatLng(courier));\n }\n }, [origin, destination, courier, originLabel, destinationLabel, courierLabel]);\n\n return (\n <div\n ref={containerRef}\n role=\"region\"\n aria-label=\"Live delivery map\"\n className={cn(\n 'relative z-0 w-full overflow-hidden rounded-lg border border-border-subtle bg-bg-sunken',\n className\n )}\n />\n );\n}\n"],"mappings":";;;;;;;A,mCAgCMG,IAAqC,CAAC,SAAS,OAAO,GAEtDC,KAAY,MAA+B,CAACC,EAAE,UAAUA,EAAE,SAAS,GAEnEC,KAAc,MAClBC,EAAK,QAAQ,aAAa,MAAM,KAAKC,EAAE,WAAW,CAAC,EAAE,EAAE;AAMzD,SAASC,EAAQ,GAAe,GAAoB,GAAc,GAAgC;CAChG,IAAMC,IACJC,KAAc,OACV,KACA,2DAA2DA,EAAW,kMAE0BC,EAAW;CACjH,OAAOZ,EAAAA,QAAE,QAAQ;EACf,WAAW;EACX,MACE,uCAAuCa,EAAK,YAAYA,EAAK,QAC7DH,IACA,qBAAqBG,EAAK,YAAYA,EAAK,qCAAqCD,EAAW,sMAGxFN,EAAWQ,CAAK,EAAE;EACvB,UAAU,CAACD,GAAMA,CAAI;EACrB,YAAY,CAACA,IAAO,GAAGA,IAAO,CAAC;CACjC,CAAC;AACH;AAEA,IAAME,KAAS,MAA8B;CAC3C,IAAMC,IAAK,SAAS,cAAc,MAAM;CAExC,OADA,EAAG,cAAcT,GACVS;AACT;AAEA,SAAgBC,EAAgB,EAC9B,WACA,gBACA,YACA,gBACA,qBACA,iBACA,gBACu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ing is explicit and foreground-only: the courier switches it on, the
|
|
5
|
+
* device position is watched while the page is open, and a fix is published at
|
|
6
|
+
* most every PUBLISH_INTERVAL_MS (the service also drops fixes that arrive too
|
|
7
|
+
* close together). Leaving the page, switching it off, or the service saying
|
|
8
|
+
* the order is no longer out for delivery stops the watch.
|
|
9
|
+
*
|
|
10
|
+
* @module kadaikodi/hooks
|
|
11
|
+
*/
|
|
12
|
+
/** Minimum gap between two published fixes. */
|
|
13
|
+
export declare const PUBLISH_INTERVAL_MS = 10000;
|
|
14
|
+
export type SharingState = 'off' | 'starting' | 'sharing' | 'error';
|
|
15
|
+
/** True when a fix taken at `now` should be published after one published at `lastSentAt`. */
|
|
16
|
+
export declare const shouldPublish: (lastSentAt: number | null, now: number) => boolean;
|
|
17
|
+
export interface CourierLocationSharing {
|
|
18
|
+
state: SharingState;
|
|
19
|
+
error: string | null;
|
|
20
|
+
lastSentAt: Date | null;
|
|
21
|
+
start: () => void;
|
|
22
|
+
stop: () => void;
|
|
23
|
+
}
|
|
24
|
+
export declare function useCourierLocationSharing(orderId: string | undefined): CourierLocationSharing;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { geolocationFailureMessage as e, watchDevicePosition as t } from "../utils/deviceGeolocation.js";
|
|
2
|
+
import { usePublishCourierLocation as n } from "./useTrackingApi.js";
|
|
3
|
+
import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
4
|
+
// src/kadaikodi/hooks/useCourierLocationSharing.ts
|
|
5
|
+
var s = 1e4, c = (e, t) => e === null || t - e >= 1e4;
|
|
6
|
+
function l(s) {
|
|
7
|
+
let l = n(), u = a(l.mutateAsync);
|
|
8
|
+
i(() => {
|
|
9
|
+
u.current = l.mutateAsync;
|
|
10
|
+
}, [l.mutateAsync]);
|
|
11
|
+
let [d, f] = o("off"), [p, m] = o(null), [h, g] = o(null), _ = a(null), v = a(null), y = a(!1), b = a(0), x = r(() => {
|
|
12
|
+
b.current += 1, _.current?.(), _.current = null, y.current = !1;
|
|
13
|
+
}, []), S = r(() => {
|
|
14
|
+
x(), f("off");
|
|
15
|
+
}, [x]), C = r((e) => {
|
|
16
|
+
x(), m(e), f("error");
|
|
17
|
+
}, [x]), w = r(() => {
|
|
18
|
+
if (!s) return;
|
|
19
|
+
x();
|
|
20
|
+
let n = b.current;
|
|
21
|
+
v.current = null, m(null), f("starting"), t((e) => {
|
|
22
|
+
if (n !== b.current || y.current) return;
|
|
23
|
+
let t = Date.now();
|
|
24
|
+
c(v.current, t) && (y.current = !0, u.current({
|
|
25
|
+
orderId: s,
|
|
26
|
+
fix: e
|
|
27
|
+
}).then(() => {
|
|
28
|
+
n === b.current && (v.current = t, g(new Date(t)), f("sharing"));
|
|
29
|
+
}).catch((e) => {
|
|
30
|
+
n === b.current && C(e instanceof Error ? e.message : "Could not share your location.");
|
|
31
|
+
}).finally(() => {
|
|
32
|
+
n === b.current && (y.current = !1);
|
|
33
|
+
}));
|
|
34
|
+
}, (t) => {
|
|
35
|
+
n === b.current && C(e(t));
|
|
36
|
+
}).then((e) => {
|
|
37
|
+
n === b.current ? _.current = e : e();
|
|
38
|
+
});
|
|
39
|
+
}, [
|
|
40
|
+
s,
|
|
41
|
+
x,
|
|
42
|
+
C
|
|
43
|
+
]);
|
|
44
|
+
return i(() => x, [s, x]), {
|
|
45
|
+
state: d,
|
|
46
|
+
error: p,
|
|
47
|
+
lastSentAt: h,
|
|
48
|
+
start: w,
|
|
49
|
+
stop: S
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export { s as PUBLISH_INTERVAL_MS, c as shouldPublish, l as useCourierLocationSharing };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=useCourierLocationSharing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCourierLocationSharing.js","names":["PUBLISH_INTERVAL_MS","shouldPublish","lastSentAt","now","useCourierLocationSharing","publish","usePublishCourierLocation","publishRef","useRef","state","setState","useState","error","setError","setLastSentAt","stopWatchRef","lastSentRef","inFlightRef","sessionRef","stopWatch","useCallback","stop","fail","message","start","orderId","session","watchDevicePosition","geolocationFailureMessage","failure","stopFn","useEffect"],"sources":["../../../src/kadaikodi/hooks/useCourierLocationSharing.ts"],"sourcesContent":["/**\n * Courier-side live location sharing for one order (BOFF-3962).\n *\n * Sharing is explicit and foreground-only: the courier switches it on, the\n * device position is watched while the page is open, and a fix is published at\n * most every PUBLISH_INTERVAL_MS (the service also drops fixes that arrive too\n * close together). Leaving the page, switching it off, or the service saying\n * the order is no longer out for delivery stops the watch.\n *\n * @module kadaikodi/hooks\n */\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport {\n type DeviceFix,\n type GeolocationFailure,\n geolocationFailureMessage,\n watchDevicePosition,\n} from '../utils/deviceGeolocation';\nimport { usePublishCourierLocation } from './useTrackingApi';\n\n/** Minimum gap between two published fixes. */\nexport const PUBLISH_INTERVAL_MS = 10_000;\n\nexport type SharingState = 'off' | 'starting' | 'sharing' | 'error';\n\n/** True when a fix taken at `now` should be published after one published at `lastSentAt`. */\nexport const shouldPublish = (lastSentAt: number | null, now: number): boolean =>\n lastSentAt === null || now - lastSentAt >= PUBLISH_INTERVAL_MS;\n\nexport interface CourierLocationSharing {\n state: SharingState;\n error: string | null;\n lastSentAt: Date | null;\n start: () => void;\n stop: () => void;\n}\n\nexport function useCourierLocationSharing(orderId: string | undefined): CourierLocationSharing {\n const publish = usePublishCourierLocation();\n const publishRef = useRef(publish.mutateAsync);\n useEffect(() => {\n publishRef.current = publish.mutateAsync;\n }, [publish.mutateAsync]);\n\n const [state, setState] = useState<SharingState>('off');\n const [error, setError] = useState<string | null>(null);\n const [lastSentAt, setLastSentAt] = useState<Date | null>(null);\n const stopWatchRef = useRef<(() => void) | null>(null);\n const lastSentRef = useRef<number | null>(null);\n const inFlightRef = useRef(false);\n const sessionRef = useRef(0);\n\n const stopWatch = useCallback(() => {\n sessionRef.current += 1;\n stopWatchRef.current?.();\n stopWatchRef.current = null;\n inFlightRef.current = false;\n }, []);\n\n const stop = useCallback(() => {\n stopWatch();\n setState('off');\n }, [stopWatch]);\n\n const fail = useCallback(\n (message: string) => {\n stopWatch();\n setError(message);\n setState('error');\n },\n [stopWatch]\n );\n\n const start = useCallback(() => {\n if (!orderId) return;\n stopWatch();\n const session = sessionRef.current;\n lastSentRef.current = null;\n setError(null);\n setState('starting');\n\n const onFix = (fix: DeviceFix) => {\n if (session !== sessionRef.current || inFlightRef.current) return;\n const now = Date.now();\n if (!shouldPublish(lastSentRef.current, now)) return;\n inFlightRef.current = true;\n publishRef\n .current({ orderId, fix })\n .then(() => {\n if (session !== sessionRef.current) return;\n lastSentRef.current = now;\n setLastSentAt(new Date(now));\n setState('sharing');\n })\n .catch((e: unknown) => {\n if (session !== sessionRef.current) return;\n // The service refuses fixes once the order is not out for delivery\n // (or the task was reassigned): stop instead of retrying forever.\n fail(e instanceof Error ? e.message : 'Could not share your location.');\n })\n .finally(() => {\n if (session === sessionRef.current) inFlightRef.current = false;\n });\n };\n const onFailure = (failure: GeolocationFailure) => {\n if (session !== sessionRef.current) return;\n fail(geolocationFailureMessage(failure));\n };\n\n void watchDevicePosition(onFix, onFailure).then((stopFn) => {\n if (session === sessionRef.current) {\n stopWatchRef.current = stopFn;\n } else {\n stopFn();\n }\n });\n }, [orderId, stopWatch, fail]);\n\n // Never keep watching after the page goes away or the order changes.\n useEffect(() => stopWatch, [orderId, stopWatch]);\n\n return { state, error, lastSentAt, start, stop };\n}\n"],"mappings":";;;;AAuBA,IAAaA,IAAsB,KAKtBC,KAAiB,GAA2B,MACvDC,MAAe,QAAQC,IAAMD,KAAA;AAU/B,SAAgBE,EAA0B,GAAqD;CAC7F,IAAMC,IAAUC,EAA0B,GACpCC,IAAaC,EAAOH,EAAQ,WAAW;CAC7C,QAAgB;EACd,EAAW,UAAUA,EAAQ;CAC/B,GAAG,CAACA,EAAQ,WAAW,CAAC;CAExB,IAAM,CAACI,GAAOC,KAAYC,EAAuB,KAAK,GAChD,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BI,EAAKM,EAA0BC,CAAO,CAAC;EACzC,CAEyC,CAAC,CAAC,MAAM,MAAW;GAC1D,AAAIH,MAAYR,EAAW,UACzB,EAAa,UAAUY,IAEvBA,EAAO;EAEX,CAAC;CACH,GAAG;EAACL;EAASN;EAAWG;CAAI,CAAC;CAK7B,OAFAS,QAAgBZ,GAAW,CAACM,GAASN,CAAS,CAAC,GAExC;EAAE;EAAO;EAAO;EAAY;EAAO;CAAK;AACjD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live delivery tracking hooks (BOFF-3962).
|
|
3
|
+
*
|
|
4
|
+
* The courier's last-known position, the drop-off pin and the ETA all come from
|
|
5
|
+
* wspace-kadaikodi-svc (`kadaikodiOrderTracking`); nothing here estimates
|
|
6
|
+
* positions on the client. The query is polled at the interval the service
|
|
7
|
+
* returns (`pollIntervalSeconds`: fast while the order is out for delivery,
|
|
8
|
+
* slow while it is being prepared, never once it is finished) — the gateway
|
|
9
|
+
* is reached over plain HTTP GraphQL, so polling is the live-update transport.
|
|
10
|
+
*
|
|
11
|
+
* @module kadaikodi/hooks
|
|
12
|
+
*/
|
|
13
|
+
export interface GeoPoint {
|
|
14
|
+
latitude: number;
|
|
15
|
+
longitude: number;
|
|
16
|
+
}
|
|
17
|
+
export interface TrackingCourier {
|
|
18
|
+
workerRefId: string;
|
|
19
|
+
name: string;
|
|
20
|
+
phone: string | null;
|
|
21
|
+
}
|
|
22
|
+
export interface CourierLocation extends GeoPoint {
|
|
23
|
+
accuracyMeters: number | null;
|
|
24
|
+
headingDegrees: number | null;
|
|
25
|
+
speedMps: number | null;
|
|
26
|
+
recordedAt: string;
|
|
27
|
+
/** True once the courier has stopped reporting for more than two minutes. */
|
|
28
|
+
stale: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface OrderTracking {
|
|
31
|
+
orderId: string;
|
|
32
|
+
status: string;
|
|
33
|
+
/** True while the order is out for delivery and the courier position is shared. */
|
|
34
|
+
active: boolean;
|
|
35
|
+
courier: TrackingCourier | null;
|
|
36
|
+
location: CourierLocation | null;
|
|
37
|
+
origin: GeoPoint | null;
|
|
38
|
+
destination: GeoPoint | null;
|
|
39
|
+
distanceMeters: number | null;
|
|
40
|
+
etaMinutes: number | null;
|
|
41
|
+
etaAt: string | null;
|
|
42
|
+
pollIntervalSeconds: number;
|
|
43
|
+
}
|
|
44
|
+
export interface CourierFixInput extends GeoPoint {
|
|
45
|
+
accuracyMeters?: number | null;
|
|
46
|
+
headingDegrees?: number | null;
|
|
47
|
+
speedMps?: number | null;
|
|
48
|
+
/** ISO-8601 device time of the fix. */
|
|
49
|
+
recordedAt?: string | null;
|
|
50
|
+
}
|
|
51
|
+
export declare const orderTrackingQueryKey: (orderId?: string) => readonly ["kadaikodi", "order-tracking", string | undefined];
|
|
52
|
+
/**
|
|
53
|
+
* Refresh interval for a tracking result: the service's suggestion, or false
|
|
54
|
+
* (stop) once it says 0 or the order is unknown.
|
|
55
|
+
*/
|
|
56
|
+
export declare const trackingRefetchInterval: (data: OrderTracking | null | undefined) => number | false;
|
|
57
|
+
/** Live tracking view for one order; null when the caller may not see it. */
|
|
58
|
+
export declare const useOrderTracking: (orderId?: string) => import('@tanstack/react-query').UseQueryResult<OrderTracking | null, Error>;
|
|
59
|
+
/** Courier side: publish one GPS fix for an order that is out for delivery. */
|
|
60
|
+
export declare const usePublishCourierLocation: () => import('@tanstack/react-query').UseMutationResult<OrderTracking, Error, {
|
|
61
|
+
orderId: string;
|
|
62
|
+
fix: CourierFixInput;
|
|
63
|
+
}, unknown>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useKadaikodi as e } from "../context/KadaikodiContext.js";
|
|
2
|
+
import "../context/index.js";
|
|
3
|
+
import { kadaikodiQuery as t } from "./useKadaikodiApi.js";
|
|
4
|
+
import { useMutation as n, useQuery as r, useQueryClient as i } from "@tanstack/react-query";
|
|
5
|
+
// src/kadaikodi/hooks/useTrackingApi.ts
|
|
6
|
+
var a = "\n orderId status active pollIntervalSeconds distanceMeters etaMinutes etaAt\n courier { workerRefId name phone }\n location { latitude longitude accuracyMeters headingDegrees speedMps recordedAt stale }\n origin { latitude longitude }\n destination { latitude longitude }\n", o = (e) => [
|
|
7
|
+
"kadaikodi",
|
|
8
|
+
"order-tracking",
|
|
9
|
+
e
|
|
10
|
+
], s = (e) => !e || e.pollIntervalSeconds <= 0 ? !1 : e.pollIntervalSeconds * 1e3, c = (n) => {
|
|
11
|
+
let { apiGatewayUrl: i } = e();
|
|
12
|
+
return r({
|
|
13
|
+
queryKey: o(n),
|
|
14
|
+
queryFn: async () => (await t(`query OrderTracking($orderId: ID!) {
|
|
15
|
+
kadaikodiOrderTracking(orderId: $orderId) { ${a} }
|
|
16
|
+
}`, { orderId: n }, i)).kadaikodiOrderTracking,
|
|
17
|
+
enabled: !!n,
|
|
18
|
+
refetchInterval: (e) => s(e.state.data),
|
|
19
|
+
refetchIntervalInBackground: !0
|
|
20
|
+
});
|
|
21
|
+
}, l = () => {
|
|
22
|
+
let { apiGatewayUrl: r } = e(), s = i();
|
|
23
|
+
return n({
|
|
24
|
+
mutationFn: async ({ orderId: e, fix: n }) => (await t(`mutation PublishCourierLocation($orderId: ID!, $input: KadaikodiCourierLocationInput!) {
|
|
25
|
+
kadaikodiPublishCourierLocation(orderId: $orderId, input: $input) { ${a} }
|
|
26
|
+
}`, {
|
|
27
|
+
orderId: e,
|
|
28
|
+
input: n
|
|
29
|
+
}, r)).kadaikodiPublishCourierLocation,
|
|
30
|
+
onSuccess: (e) => {
|
|
31
|
+
s.setQueryData(o(e.orderId), e);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export { o as orderTrackingQueryKey, s as trackingRefetchInterval, c as useOrderTracking, l as usePublishCourierLocation };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=useTrackingApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTrackingApi.js","names":["TRACKING_FIELDS","orderTrackingQueryKey","orderId","trackingRefetchInterval","data","useOrderTracking","useKadaikodi","useQuery","kadaikodiQuery","apiGatewayUrl","query","usePublishCourierLocation","queryClient","useQueryClient","useMutation","fix","tracking"],"sources":["../../../src/kadaikodi/hooks/useTrackingApi.ts"],"sourcesContent":["/**\n * Live delivery tracking hooks (BOFF-3962).\n *\n * The courier's last-known position, the drop-off pin and the ETA all come from\n * wspace-kadaikodi-svc (`kadaikodiOrderTracking`); nothing here estimates\n * positions on the client. The query is polled at the interval the service\n * returns (`pollIntervalSeconds`: fast while the order is out for delivery,\n * slow while it is being prepared, never once it is finished) — the gateway\n * is reached over plain HTTP GraphQL, so polling is the live-update transport.\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 interface GeoPoint {\n latitude: number;\n longitude: number;\n}\n\nexport interface TrackingCourier {\n workerRefId: string;\n name: string;\n phone: string | null;\n}\n\nexport interface CourierLocation extends GeoPoint {\n accuracyMeters: number | null;\n headingDegrees: number | null;\n speedMps: number | null;\n recordedAt: string;\n /** True once the courier has stopped reporting for more than two minutes. */\n stale: boolean;\n}\n\nexport interface OrderTracking {\n orderId: string;\n status: string;\n /** True while the order is out for delivery and the courier position is shared. */\n active: boolean;\n courier: TrackingCourier | null;\n location: CourierLocation | null;\n origin: GeoPoint | null;\n destination: GeoPoint | null;\n distanceMeters: number | null;\n etaMinutes: number | null;\n etaAt: string | null;\n pollIntervalSeconds: number;\n}\n\nexport interface CourierFixInput extends GeoPoint {\n accuracyMeters?: number | null;\n headingDegrees?: number | null;\n speedMps?: number | null;\n /** ISO-8601 device time of the fix. */\n recordedAt?: string | null;\n}\n\nconst TRACKING_FIELDS = `\n orderId status active pollIntervalSeconds distanceMeters etaMinutes etaAt\n courier { workerRefId name phone }\n location { latitude longitude accuracyMeters headingDegrees speedMps recordedAt stale }\n origin { latitude longitude }\n destination { latitude longitude }\n`;\n\nexport const orderTrackingQueryKey = (orderId?: string) =>\n ['kadaikodi', 'order-tracking', orderId] as const;\n\n/**\n * Refresh interval for a tracking result: the service's suggestion, or false\n * (stop) once it says 0 or the order is unknown.\n */\nexport const trackingRefetchInterval = (data: OrderTracking | null | undefined): number | false => {\n if (!data || data.pollIntervalSeconds <= 0) return false;\n return data.pollIntervalSeconds * 1000;\n};\n\n// ============================================================================\n// Hooks\n// ============================================================================\n\n/** Live tracking view for one order; null when the caller may not see it. */\nexport const useOrderTracking = (orderId?: string) => {\n const { apiGatewayUrl } = useKadaikodi();\n return useQuery({\n queryKey: orderTrackingQueryKey(orderId),\n queryFn: async () => {\n const result = await kadaikodiQuery<{ kadaikodiOrderTracking: OrderTracking | null }>(\n `query OrderTracking($orderId: ID!) {\n kadaikodiOrderTracking(orderId: $orderId) { ${TRACKING_FIELDS} }\n }`,\n { orderId },\n apiGatewayUrl\n );\n return result.kadaikodiOrderTracking;\n },\n enabled: Boolean(orderId),\n refetchInterval: (query) => trackingRefetchInterval(query.state.data),\n // Keep updating while the customer glances at another tab; the interval\n // already drops to zero once the order is finished.\n refetchIntervalInBackground: true,\n });\n};\n\n/** Courier side: publish one GPS fix for an order that is out for delivery. */\nexport const usePublishCourierLocation = () => {\n const { apiGatewayUrl } = useKadaikodi();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async ({ orderId, fix }: { orderId: string; fix: CourierFixInput }) => {\n const result = await kadaikodiQuery<{ kadaikodiPublishCourierLocation: OrderTracking }>(\n `mutation PublishCourierLocation($orderId: ID!, $input: KadaikodiCourierLocationInput!) {\n kadaikodiPublishCourierLocation(orderId: $orderId, input: $input) { ${TRACKING_FIELDS} }\n }`,\n { orderId, input: fix },\n apiGatewayUrl\n );\n return result.kadaikodiPublishCourierLocation;\n },\n onSuccess: (tracking) => {\n queryClient.setQueryData(orderTrackingQueryKey(tracking.orderId), tracking);\n },\n });\n};\n"],"mappings":";;;;;AAiEA,IAAMA,IAAkB,2RAQXC,KAAyB,MACpC;CAAC;CAAa;CAAkBC;AAAO,GAM5BC,KAA2B,MAClC,CAACC,KAAQA,EAAK,uBAAuB,IAAU,KAC5CA,EAAK,sBAAsB,KAQvBC,KAAoB,MAAqB;CACpD,IAAM,EAAE,qBAAkBC,EAAa;CACvC,OAAOC,EAAS;EACd,UAAUN,EAAsBC,CAAO;EACvC,SAAS,aAQA,MAPcM,EACnB;wDACgDR,EAAgB;YAEhE,EAAE,WAAQ,GACVS,CACF,EAAA,CACc;EAEhB,SAAS,EAAQP;EACjB,kBAAkB,MAAUC,EAAwBO,EAAM,MAAM,IAAI;EAGpE,6BAA6B;CAC/B,CAAC;AACH,GAGaC,UAAkC;CAC7C,IAAM,EAAE,qBAAkBL,EAAa,GACjCM,IAAcC,EAAe;CACnC,OAAOC,EAAY;EACjB,YAAY,OAAO,EAAE,YAAS,cAQrB,MAPcN,EACnB;gFACwER,EAAgB;YAExF;GAAE;GAAS,OAAOe;EAAI,GACtBN,CACF,EAAA,CACc;EAEhB,YAAY,MAAa;GACvB,EAAY,aAAaR,EAAsBe,EAAS,OAAO,GAAGA,CAAQ;EAC5E;CACF,CAAC;AACH"}
|