@eka-care/abdm-dashboard-stg 0.0.1 → 0.0.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/package.json +1 -1
- package/src/config/runtime-config.ts +3 -0
- package/src/features/api/baseApi.ts +2 -1
- package/src/main.tsx +78 -21
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/features/api/baseApi.ts
|
|
2
2
|
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
|
3
|
+
import { runtimeConfig } from "../../config/runtime-config";
|
|
3
4
|
|
|
4
5
|
export const baseApi = createApi({
|
|
5
6
|
reducerPath: "baseApi",
|
|
@@ -13,7 +14,7 @@ export const baseApi = createApi({
|
|
|
13
14
|
credentials: "include",
|
|
14
15
|
|
|
15
16
|
prepareHeaders: (headers) => {
|
|
16
|
-
headers.set("client-id",
|
|
17
|
+
headers.set("client-id", runtimeConfig.clientId);
|
|
17
18
|
|
|
18
19
|
return headers;
|
|
19
20
|
},
|
package/src/main.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createRoot, type Root } from "react-dom/client";
|
|
2
2
|
import "./index.css";
|
|
3
3
|
import AbdmDashboard from "./abdm-dashboard.tsx";
|
|
4
|
+
import { runtimeConfig } from "./config/runtime-config.ts";
|
|
4
5
|
|
|
5
6
|
declare global {
|
|
6
7
|
interface Window {
|
|
7
|
-
Bridge: new () => any;
|
|
8
|
+
Bridge: new () => any;
|
|
8
9
|
initAbhaApp?: (params: {
|
|
9
10
|
clientId: string;
|
|
10
11
|
containerId: string;
|
|
@@ -21,8 +22,12 @@ declare global {
|
|
|
21
22
|
const roots: Map<string, Root> = new Map();
|
|
22
23
|
|
|
23
24
|
interface MountOptions {
|
|
24
|
-
clinicId
|
|
25
|
-
clientId
|
|
25
|
+
clinicId: string;
|
|
26
|
+
clientId: string;
|
|
27
|
+
|
|
28
|
+
onAbdmDashboardSuccess?: (params: { clinicId: string; clientId: string }) => void;
|
|
29
|
+
onAbdmDashboardError?: (params: { clinicId: string; clientId: string }) => void;
|
|
30
|
+
onAbdmDashboardClose?: (params: { clinicId: string; clientId: string }) => void;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
interface MountResult {
|
|
@@ -42,36 +47,75 @@ function ensureContainer(id: string): HTMLElement {
|
|
|
42
47
|
|
|
43
48
|
export function mountABDMDashboard(
|
|
44
49
|
elementId = "abdm-dashboard-root",
|
|
45
|
-
options: MountOptions
|
|
50
|
+
options: MountOptions
|
|
46
51
|
): MountResult {
|
|
47
52
|
const id = elementId;
|
|
53
|
+
|
|
48
54
|
const {
|
|
49
|
-
clinicId
|
|
50
|
-
clientId
|
|
55
|
+
clinicId,
|
|
56
|
+
clientId,
|
|
57
|
+
onAbdmDashboardSuccess,
|
|
58
|
+
onAbdmDashboardError,
|
|
59
|
+
onAbdmDashboardClose,
|
|
51
60
|
} = options;
|
|
52
61
|
|
|
53
|
-
|
|
62
|
+
try {
|
|
63
|
+
const container = ensureContainer(id);
|
|
64
|
+
|
|
65
|
+
if (roots.has(id)) {
|
|
66
|
+
return {
|
|
67
|
+
id,
|
|
68
|
+
unmount: () =>
|
|
69
|
+
unmountABDMDashboard(id, {
|
|
70
|
+
clinicId,
|
|
71
|
+
clientId,
|
|
72
|
+
onAbdmDashboardError,
|
|
73
|
+
onAbdmDashboardClose,
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const root = createRoot(container);
|
|
79
|
+
roots.set(id, root);
|
|
80
|
+
|
|
81
|
+
// store clientId for api headers
|
|
82
|
+
runtimeConfig.clientId = clientId;
|
|
83
|
+
|
|
84
|
+
root.render(
|
|
85
|
+
<AbdmDashboard clinicId={clinicId} clientId={clientId} />
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// successful mount
|
|
89
|
+
onAbdmDashboardSuccess?.({ clinicId, clientId });
|
|
54
90
|
|
|
55
|
-
if (roots.has(id)) {
|
|
56
91
|
return {
|
|
57
92
|
id,
|
|
58
|
-
unmount: () =>
|
|
93
|
+
unmount: () =>
|
|
94
|
+
unmountABDMDashboard(id, {
|
|
95
|
+
clinicId,
|
|
96
|
+
clientId,
|
|
97
|
+
onAbdmDashboardError,
|
|
98
|
+
onAbdmDashboardClose,
|
|
99
|
+
}),
|
|
59
100
|
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const root = createRoot(container);
|
|
63
|
-
roots.set(id, root);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error("abdmDashboard: mount failed", e);
|
|
64
103
|
|
|
65
|
-
|
|
104
|
+
// mount failure
|
|
105
|
+
onAbdmDashboardError?.({ clinicId, clientId });
|
|
66
106
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
unmount: () => unmountABDMDashboard(id),
|
|
70
|
-
};
|
|
107
|
+
throw e;
|
|
108
|
+
}
|
|
71
109
|
}
|
|
72
110
|
|
|
73
111
|
export function unmountABDMDashboard(
|
|
74
|
-
elementId = "abdm-dashboard-root"
|
|
112
|
+
elementId = "abdm-dashboard-root",
|
|
113
|
+
params?: {
|
|
114
|
+
clinicId?: string;
|
|
115
|
+
clientId?: string;
|
|
116
|
+
onAbdmDashboardError?: (params: { clinicId: string; clientId: string }) => void;
|
|
117
|
+
onAbdmDashboardClose?: (params: { clinicId: string; clientId: string }) => void;
|
|
118
|
+
}
|
|
75
119
|
): boolean {
|
|
76
120
|
const id = elementId;
|
|
77
121
|
const root = roots.get(id);
|
|
@@ -81,14 +125,27 @@ export function unmountABDMDashboard(
|
|
|
81
125
|
try {
|
|
82
126
|
root.unmount();
|
|
83
127
|
roots.delete(id);
|
|
128
|
+
|
|
129
|
+
// successful unmount
|
|
130
|
+
params?.onAbdmDashboardClose?.({
|
|
131
|
+
clinicId: params?.clinicId ?? "default-clinic",
|
|
132
|
+
clientId: params?.clientId ?? "default-client",
|
|
133
|
+
});
|
|
134
|
+
|
|
84
135
|
return true;
|
|
85
136
|
} catch (e) {
|
|
86
137
|
console.error("abdmDashboard: unmount failed", e);
|
|
138
|
+
|
|
139
|
+
// unmount failure
|
|
140
|
+
params?.onAbdmDashboardError?.({
|
|
141
|
+
clinicId: params?.clinicId ?? "default-clinic",
|
|
142
|
+
clientId: params?.clientId ?? "default-client",
|
|
143
|
+
});
|
|
144
|
+
|
|
87
145
|
return false;
|
|
88
146
|
}
|
|
89
147
|
}
|
|
90
148
|
|
|
91
|
-
|
|
92
149
|
export const __attachToWindow = (() => {
|
|
93
150
|
try {
|
|
94
151
|
const w = window as any;
|
|
@@ -101,7 +158,7 @@ export const __attachToWindow = (() => {
|
|
|
101
158
|
|
|
102
159
|
export default function abdmDashboard(
|
|
103
160
|
name: string,
|
|
104
|
-
options
|
|
161
|
+
options: MountOptions
|
|
105
162
|
): MountResult {
|
|
106
163
|
return mountABDMDashboard(name, options);
|
|
107
164
|
}
|