@eka-care/abha-stg 0.1.0 → 0.1.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.
Files changed (119) hide show
  1. package/{index.html → dist/index.html} +2 -1
  2. package/dist/sdk/abha/css/abha.css +1 -0
  3. package/dist/sdk/abha/js/abha.js +63 -0
  4. package/package.json +1 -1
  5. package/.eslintignore +0 -3
  6. package/.eslintrc +0 -29
  7. package/.prettierrc +0 -7
  8. package/.turbo/daemon/da13e0828a6aedf8-turbo.log.2025-10-30 +0 -0
  9. package/package/styles/pds2/border.ts +0 -69
  10. package/package/styles/pds2/colors.ts +0 -70
  11. package/package/styles/pds2/spacing.ts +0 -1007
  12. package/package/tailwind/tailwind.config.ts +0 -124
  13. package/postcss.config.js +0 -6
  14. package/scripts/build-purged-css.cjs +0 -70
  15. package/src/App.css +0 -0
  16. package/src/App.tsx +0 -43
  17. package/src/api-queries/aorta-go/v3/get-profile-patient.ts +0 -32
  18. package/src/api-queries/aorta-go/v3/get-profiles-phr-user.ts +0 -26
  19. package/src/api-queries/aorta-go/v3/post-auth-init-v2.ts +0 -34
  20. package/src/api-queries/aorta-go/v3/post-auth-logout-v2.ts +0 -32
  21. package/src/api-queries/aorta-go/v3/post-auth-verify-v2.ts +0 -38
  22. package/src/api-queries/aorta-go/v3/post-profile-switch.ts +0 -39
  23. package/src/api-queries/ndhm/get-abdm-register-suggest.ts +0 -37
  24. package/src/api-queries/ndhm/get-pincode-details.ts +0 -28
  25. package/src/api-queries/ndhm/post-abdm-login-init.ts +0 -37
  26. package/src/api-queries/ndhm/post-abdm-login-phr.ts +0 -37
  27. package/src/api-queries/ndhm/post-abdm-login-verify.ts +0 -37
  28. package/src/api-queries/ndhm/post-abdm-profile-eka-link-phr.ts +0 -40
  29. package/src/api-queries/ndhm/post-abdm-profile-eka.ts +0 -66
  30. package/src/api-queries/ndhm/post-abdm-register-abha-number-create-phr.ts +0 -37
  31. package/src/api-queries/ndhm/post-abdm-register-mobile-create-phr.ts +0 -66
  32. package/src/api-queries/ndhm/post-abdm-register-mobile-resend-otp.ts +0 -32
  33. package/src/api-queries/ndhm/post-abdm-register-mobile-verify.ts +0 -38
  34. package/src/api-queries/ndhm/post-abdm-register-phr-check.ts +0 -34
  35. package/src/api-queries/ndhm/post-register-aadhaar-create-phr.ts +0 -37
  36. package/src/api-queries/ndhm/post-register-aadhaar-init.ts +0 -34
  37. package/src/api-queries/ndhm/post-register-aadhaar-mobile-resend-otp.ts +0 -34
  38. package/src/api-queries/ndhm/post-register-aadhaar-mobile-verify.ts +0 -37
  39. package/src/api-queries/ndhm/post-register-aadhaar-resend-otp.ts +0 -34
  40. package/src/api-queries/ndhm/post-register-aadhaar-verify.ts +0 -40
  41. package/src/api-queries/ndhm/post-register-mobile-init.ts +0 -34
  42. package/src/api-queries/use-get-profiles-patient.ts +0 -12
  43. package/src/api-queries/use-get-profiles-phr-user.ts +0 -28
  44. package/src/api-queries/use-post-abdm-login-verify-v1.ts +0 -26
  45. package/src/api-queries/use-post-auth-verify-v2.ts +0 -50
  46. package/src/api-queries/use-post-profile-switch.ts +0 -58
  47. package/src/api-queries/use-post-register-mobile-create-phr.ts +0 -39
  48. package/src/api-queries/user-post-abdm-profile-login-phr.ts +0 -26
  49. package/src/assets/Success.json +0 -1
  50. package/src/assets/react.svg +0 -1
  51. package/src/atoms/button/custom-button.tsx +0 -32
  52. package/src/atoms/button/index.tsx +0 -40
  53. package/src/atoms/button/types.d.ts +0 -31
  54. package/src/atoms/header.tsx +0 -25
  55. package/src/atoms/input-field/index.tsx +0 -63
  56. package/src/atoms/input-field/patient-input-field.tsx +0 -16
  57. package/src/atoms/input-field/types.ts +0 -24
  58. package/src/atoms/pds2-otp-input/index.tsx +0 -35
  59. package/src/atoms/pds2-otp-input/types.d.ts +0 -3
  60. package/src/atoms/single-input-chip/index.tsx +0 -32
  61. package/src/atoms/single-input-chip/types.ts +0 -6
  62. package/src/atoms/spinner.tsx +0 -33
  63. package/src/atoms/text-separator.tsx +0 -11
  64. package/src/atoms/ui/spinner.tsx +0 -75
  65. package/src/constants/constants.ts +0 -376
  66. package/src/fetch-client/index.ts +0 -164
  67. package/src/index.css +0 -152
  68. package/src/main.tsx +0 -374
  69. package/src/molecules/abha/bottom-sheet/bottom-sheet-wrapper.tsx +0 -40
  70. package/src/molecules/abha/bottom-sheet/index.tsx +0 -66
  71. package/src/molecules/abha/spaced-input-component.tsx +0 -168
  72. package/src/molecules/copyright-year.tsx +0 -16
  73. package/src/molecules/exit-popup/index.tsx +0 -101
  74. package/src/molecules/pds2-otp-component/index.tsx +0 -147
  75. package/src/organisms/abha/abha-header.tsx +0 -25
  76. package/src/organisms/abha/abha-stepper.tsx +0 -83
  77. package/src/organisms/abha/error-bottom-sheet.tsx +0 -27
  78. package/src/organisms/abha/otp-card.tsx +0 -99
  79. package/src/organisms/abha/verification-status.tsx +0 -30
  80. package/src/organisms/choose-language/choose-language.tsx +0 -53
  81. package/src/organisms/choose-language/types.ts +0 -10
  82. package/src/organisms/screen-switcher/screen-switcher.tsx +0 -80
  83. package/src/routes/abha-aadhaar-verification-status-screen.tsx +0 -246
  84. package/src/routes/abha-created-screen.tsx +0 -45
  85. package/src/routes/abha-login-otp-verify-screen.tsx +0 -519
  86. package/src/routes/abha-mobile-linking-status-screen.tsx +0 -267
  87. package/src/routes/abha-otp-and-mobile-screen.tsx +0 -435
  88. package/src/routes/abha-phone-number-verification-screen.tsx +0 -388
  89. package/src/routes/create-abha-address-screen.tsx +0 -928
  90. package/src/routes/create-abha-with-aadhaar-screen.tsx +0 -986
  91. package/src/routes/create-eka-profile-screen.tsx +0 -831
  92. package/src/routes/get-all-profiles-screen.tsx +0 -161
  93. package/src/routes/login-or-create-abha-address-screen.tsx +0 -1056
  94. package/src/routes/login-with-abha-screen.tsx +0 -454
  95. package/src/routes/select-abha-from-list-screen.tsx +0 -792
  96. package/src/routes/select-eka-profile-screen.tsx +0 -446
  97. package/src/routes/utils/trackAbhaEvent.ts +0 -41
  98. package/src/stores/auth-abha-store/index.ts +0 -152
  99. package/src/stores/auth-abha-store/types.ts +0 -217
  100. package/src/utils/mock-auth-response.ts +0 -29
  101. package/src/utils/send-event-utils.ts +0 -76
  102. package/src/utils/validations.ts +0 -89
  103. package/src/vite-env.d.ts +0 -1
  104. package/tailwind.config.ts +0 -9
  105. package/tsconfig.json +0 -25
  106. package/tsconfig.node.json +0 -10
  107. package/tsconfig.node.tsbuildinfo +0 -1
  108. package/tsconfig.tsbuildinfo +0 -1
  109. package/vite.config.d.ts +0 -2
  110. package/vite.config.js +0 -45
  111. package/vite.config.ts +0 -50
  112. /package/{public → dist}/images/adhaar.webp +0 -0
  113. /package/{public → dist}/images/at-the-rate.webp +0 -0
  114. /package/{public → dist}/images/avatar.webp +0 -0
  115. /package/{public → dist}/images/ayushman-bharat.webp +0 -0
  116. /package/{public → dist}/images/circle-checkmark.webp +0 -0
  117. /package/{public → dist}/images/link-abha.webp +0 -0
  118. /package/{public → dist}/images/national-authority.webp +0 -0
  119. /package/{public → dist}/images/three-dots.webp +0 -0
@@ -1,928 +0,0 @@
1
- import { ArrowLeftRegularIcon } from '@eka-care/icons';
2
- import {
3
- ABHA_AUTH_FLOW_METHOD,
4
- GET_EXTRA_HEADERS,
5
- LOADING_STATE,
6
- REGISTRATION_TYPE,
7
- TProfileRecord,
8
- } from '../constants/constants';
9
- import { useQueryClient } from '@tanstack/react-query';
10
- import { useEffect, useState } from 'react';
11
- import usePostAuthVerifyV2, { TVerifyToken } from '../api-queries/use-post-auth-verify-v2';
12
- import usePostProfileSwitch from '../api-queries/use-post-profile-switch';
13
- import usePostRegisterMobileCreatePhr from '../api-queries/use-post-register-mobile-create-phr';
14
- import Pds2Button from '../atoms/button';
15
- import Pds2Header from '../atoms/header';
16
- import ExitPopup from '../molecules/exit-popup';
17
- import AbhaErrorBottomSheet from '../organisms/abha/error-bottom-sheet';
18
- import useAuthAbhaStore from '../stores/auth-abha-store';
19
- import { CustomCardLayout } from './abha-otp-and-mobile-screen';
20
-
21
- import { onAbhaSuccess, unMount } from '../main';
22
- import { getMockAuthVerifyResponse } from '../utils/mock-auth-response';
23
- import { CircleInfoSolidIcon } from '@eka-care/icons';
24
- import AbhaStepper from '../organisms/abha/abha-stepper';
25
- import handleSendEvent from '../utils/send-event-utils';
26
- import getAbdmRegisterSuggest from '../api-queries/ndhm/get-abdm-register-suggest';
27
- import postRegisterAadhaarCreatePhr from '../api-queries/ndhm/post-register-aadhaar-create-phr';
28
- import postAbdmProfileEkaLinkPhr from '../api-queries/ndhm/post-abdm-profile-eka-link-phr';
29
- import postAbdmProfileEka from '../api-queries/ndhm/post-abdm-profile-eka';
30
- import postAbdmRegisterPhrCheck from '../api-queries/ndhm/post-abdm-register-phr-check';
31
- import postAbdmRegisterAbhaNumberCreatePhr from '../api-queries/ndhm/post-abdm-register-abha-number-create-phr';
32
-
33
- type TAbhaAddressCardProps = {
34
- address: string;
35
- setAddress: (val: string) => void;
36
- suggestions?: Array<string>;
37
- };
38
-
39
- const isProd = import.meta.env.VITE_APP_ENV === 'PROD';
40
-
41
- const AbhaAddressCard = ({ address, setAddress, suggestions }: TAbhaAddressCardProps) => {
42
- return (
43
- <CustomCardLayout className="pds2-space-y-24">
44
- <div className="pds2-space-y-12">
45
- <img
46
- src="https://cdn.eka.care/vagus/cmgkgn6m500010td37a5wbbl3.webp"
47
- alt="at-the-rate"
48
- className="pds2-w-48"
49
- />
50
- <div className="pds2-space-y-4">
51
- <div className="pds2-text-text-01 Body1Regular">Choose your ABHA Address</div>
52
- <div className="pds2-text-text-secondary BodyFootnote">
53
- This ABHA Address will be used as your identity for ABHA Services.
54
- </div>
55
- </div>
56
- </div>
57
- <div className="pds2-space-y-2 pds2-flex pds2-flex-col">
58
- <label htmlFor="abha-address" className="pds2-text-text-brand BodyInputLabel">
59
- ABHA Address
60
- <sup className="pds2-text-text-error Body3Semibold"> *</sup>
61
- </label>
62
- <div className="pds2-relative pds2-text-text-01 Body1Semibold">
63
- <input
64
- value={address}
65
- className="pds2-py-4 pds2-bg-transparent pds2-border-b-1 pds2-border-b-text-brand pds2-w-full pds2-pr-16 pds2-outline-none"
66
- id="abha-address"
67
- onChange={(e) => {
68
- const value = e.target.value.replace(/[^a-zA-Z0-9]/g, '');
69
- if (value.length <= 18) {
70
- setAddress(value);
71
- }
72
- }}
73
- autoCapitalize="off"
74
- autoCorrect="off"
75
- />
76
- <span className="pds2-absolute pds2-right-0 pds2-top-1/2 pds2-transform pds2--translate-y-1/2 pds2-pointer-events-none">
77
- {isProd ? '@abdm' : '@sbx'}
78
- </span>
79
- </div>
80
- <div className="pds2-py-6 pds2-text-text-secondary BodyInputLabel">
81
- 8-18 characters alphabets and numbers only
82
- </div>
83
- </div>
84
- {suggestions && suggestions.length > 0 ? (
85
- <div className="pds2-space-y-8">
86
- <div className="pds2-text-text-04 Body1Semibold">Suggestions:</div>
87
- <div className="pds2-flex pds2-overflow-x-auto pds2-gap-6 pds2-py-4 pds2-px-4 -pds2-ml-4">
88
- {suggestions.map((suggestion) => (
89
- <label
90
- key={suggestion}
91
- className={`
92
- pds2-flex pds2-items-center pds2-cursor-pointer pds2-px-12 pds2-py-8
93
- pds2-border-1 pds2-rounded-12 pds2-bg-bg-01
94
- ${
95
- address === suggestion
96
- ? 'pds2-border-border-brand-01 pds2-text-text-brand Body2Semibold focus-within:pds2-ring-2 focus-within:pds2-ring-border-brand-01 focus-within:pds2-ring-offset-2'
97
- : 'pds2-border-border-03 pds2-text-text-secondary Body3Medium'
98
- }
99
- active:pds2-bg-bg-brand-02 hover:pds2-bg-bg-hover-01
100
- pds2-transition-colors pds2-duration-200
101
- `}
102
- >
103
- <input
104
- type="radio"
105
- name="abha-suggestion"
106
- value={suggestion}
107
- checked={address === suggestion}
108
- onClick={() => setAddress(address === suggestion ? '' : suggestion)}
109
- className="focus:pds2-outline-none pds2-appearance-none"
110
- />
111
- <span>
112
- {suggestion}
113
- {isProd ? '@abdm' : '@sbx'}
114
- </span>
115
- </label>
116
- ))}
117
- </div>
118
- </div>
119
- ) : null}
120
- </CustomCardLayout>
121
- );
122
- };
123
-
124
- const CreateAbhaAddressScreen = () => {
125
- const [abhaAddress, setAbhaAddress] = useState<string>('');
126
- const txnId = useAuthAbhaStore((state) => state.txnId);
127
- const setSelectedAbhaAddress = useAuthAbhaStore((state) => state.setSelectedAbhaAddress);
128
- const goBackLoginScreen = useAuthAbhaStore((state) => state.goBackLoginScreen);
129
- const abhaAuthFlowMethod = useAuthAbhaStore((state) => state.abhaAuthFlowMethod);
130
- const [loadingStatus, setLoadingState] = useState<string | null>(null);
131
- const authTxnId = useAuthAbhaStore((state) => state.authTxnId);
132
- const [error, setError] = useState<string | null>(null);
133
- const { mutateAsync: postAuthVerifyV2Mutate } = usePostAuthVerifyV2();
134
- const setBottomsheetErrorInfo = useAuthAbhaStore((state) => state.setBottomsheetErrorInfo);
135
- const clearAbhaAuthStore = useAuthAbhaStore((state) => state.clearAbhaAuthStore);
136
- const [abhaSuggestions, setAbhaSuggestions] = useState<Array<string>>([]);
137
- const [isExitPopupOpen, setIsExitPopupOpen] = useState<boolean>(false);
138
- const { mutateAsync: postAbdmRegisterMobileCreatePhrMutate } = usePostRegisterMobileCreatePhr();
139
- const ekaProfileInfo = useAuthAbhaStore((state) => state.ekaProfileInfo);
140
- const registrationType = useAuthAbhaStore((state) => state.registrationType);
141
- const { mutateAsync: postProfileSwitchMutate } = usePostProfileSwitch();
142
- const extraHeaders = GET_EXTRA_HEADERS();
143
- const isEkaAppLogin = useAuthAbhaStore((state) => state.isEkaAppLogin);
144
- const clientId = useAuthAbhaStore((state) => state.clientId);
145
- const validGenders = ['M', 'F', 'O', 'U'] as const;
146
- const isNewLoginOrCreateFlow = useAuthAbhaStore((state) => state.isNewLoginOrCreateFlow);
147
- const selectedMethod = useAuthAbhaStore(
148
- (state) => state.abhaAuthFlowMethod || ABHA_AUTH_FLOW_METHOD.MOBILE
149
- );
150
-
151
- // Unified analytics event tracker that sends event data to both handle SendEvent and Mixpanel (if available)
152
- const trackAbhaEvent = ({ name, data = {} }: { name: string; data?: Record<string, any> }) => {
153
- const baseProps = {
154
- login_platform: clientId,
155
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
156
- is_new_login_or_create_flow: isNewLoginOrCreateFlow ? 'true' : 'false',
157
- txn_id: txnId || 'missing txnId',
158
- oid: extraHeaders?.['X-User-ID'] ? 'true' : 'false',
159
- access_token: extraHeaders?.['auth'] ? 'true' : 'false',
160
- flow: selectedMethod?.toString()
161
- };
162
-
163
- const eventData = {
164
- ...baseProps,
165
- ...data,
166
- };
167
-
168
- handleSendEvent({
169
- eventName: name,
170
- eventData,
171
- });
172
-
173
- window.curio?.pushToMixpanel?.(name, eventData);
174
- };
175
-
176
- useEffect(() => {
177
- // Track page view on component mount or when `clientId` changes
178
- trackAbhaEvent({
179
- name: 'page_view',
180
- data: {
181
- page_view: 'choose_abha_address_screen',
182
- platform: clientId,
183
- },
184
- });
185
- }, [clientId]);
186
-
187
- useEffect(() => {
188
- // On mount, fetch ABHA address suggestions based on transaction ID and profile info
189
- async function fetchRegisterAbhaSuggestions() {
190
- if (!txnId) return;
191
- try {
192
- const { suggestions, error: registerSuggestError } = await getAbdmRegisterSuggest({
193
- txn_id: txnId,
194
- fn: ekaProfileInfo?.firstname,
195
- ln: ekaProfileInfo?.lastname,
196
- dob: ekaProfileInfo?.date_of_birth,
197
- });
198
- // Handle error from API
199
- if (registerSuggestError) {
200
- setError(registerSuggestError || 'Something went wrong. Please try again.');
201
- return;
202
- }
203
- // If suggestions are received, set state and pre-fill address with first suggestion
204
- if (suggestions) {
205
- setAbhaSuggestions(suggestions);
206
- // Prefill abhaAddress with the first suggestion if available
207
- if (suggestions.length > 0) {
208
- setAbhaAddress(suggestions[0]);
209
- }
210
- }
211
- } catch (err) {}
212
- }
213
-
214
- fetchRegisterAbhaSuggestions();
215
- }, []);
216
-
217
- // Called when user clicks "Create ABHA Address"
218
- const handleCreateAbhaAddressClick = async () => {
219
- // If no address selected, track and exit early
220
- if (!abhaAddress) {
221
- // Track attempt to create ABHA address without selecting any address
222
- trackAbhaEvent({
223
- name: 'create_abha_address_click_no_selection',
224
- data: {
225
- platform: clientId,
226
- type: 'create',
227
- reason: 'no_abha_address_selected',
228
- abha_address_selected: false,
229
- },
230
- });
231
- return;
232
- }
233
-
234
- // Track the click event when user tries to create ABHA address
235
- trackAbhaEvent({
236
- name: 'create_abha_address_clicks',
237
- data: {
238
- platform: clientId,
239
- type: 'create',
240
- },
241
- });
242
-
243
- setLoadingState(LOADING_STATE.LOADING);
244
-
245
- if (registrationType === REGISTRATION_TYPE.CREATE) {
246
- if (!txnId || !ekaProfileInfo) return;
247
- /**
248
- * Create phr address regardless, if it is mobile, then call mobile create phr , else call aadhaar create phr
249
- * check if oid is present
250
- * if no, call profile/eka
251
- * if yes, call link-phr
252
- * call switch with the oid
253
- */
254
-
255
- // Extract date of birth parts safely
256
- const [year, month, day] = ekaProfileInfo.date_of_birth
257
- ? ekaProfileInfo?.date_of_birth?.split('-')
258
- : ['', '', ''];
259
-
260
- // --- MOBILE FLOW ---
261
-
262
- if (abhaAuthFlowMethod === ABHA_AUTH_FLOW_METHOD.MOBILE) {
263
- // Prepare payload for mobile create PHR
264
- const mobileCreatePhrData = {
265
- abha_address: abhaAddress,
266
- day_of_birth: parseInt(day),
267
- first_name: ekaProfileInfo.firstname,
268
- gender: ekaProfileInfo.gender,
269
- last_name: ekaProfileInfo.lastname,
270
- month_of_birth: parseInt(month),
271
- pincode: ekaProfileInfo.pincode,
272
- year_of_birth: parseInt(year),
273
- txn_id: txnId,
274
- };
275
-
276
- trackAbhaEvent({
277
- name: 'create_abha_process_started',
278
- data: {
279
- method: 'mobile',
280
- abha_address: abhaAddress,
281
- platform: clientId,
282
- pincode_sent: mobileCreatePhrData?.pincode,
283
- date_of_birth: ekaProfileInfo?.date_of_birth || 'missing date of birth',
284
- day_of_birth: mobileCreatePhrData?.day_of_birth || 'missing day of birth',
285
- month_of_birth: mobileCreatePhrData?.month_of_birth || 'missing month of birth',
286
- year_of_birth: mobileCreatePhrData?.year_of_birth || 'missing year of birth',
287
- },
288
- });
289
-
290
- // Call API to create PHR via mobile method
291
- const {
292
- error: registerError,
293
- eka,
294
- profile,
295
- action: errorAction,
296
- } = await postAbdmRegisterMobileCreatePhrMutate(mobileCreatePhrData);
297
-
298
- // Handle possible errors from API
299
- if (errorAction) {
300
- trackAbhaEvent({
301
- name: 'create_abha_process_error_action',
302
- data: {
303
- method: 'mobile',
304
- platform: clientId,
305
- error_message: errorAction?.cta?.title || 'unknown_error_message',
306
- error_message_exists: !!errorAction?.cta?.title,
307
- },
308
- });
309
- setBottomsheetErrorInfo(errorAction);
310
- return;
311
- }
312
-
313
- if (registerError || !eka) {
314
- trackAbhaEvent({
315
- name: 'create_abha_process_failed',
316
- data: {
317
- method: 'mobile',
318
- platform: clientId,
319
- error_message: registerError || 'unknown_error',
320
- error_message_exists: !!registerError,
321
- pincode_received: profile?.pincode || 'missing_pincode_received',
322
- pincode_received_exists: !!profile?.pincode,
323
- pincode_sent: ekaProfileInfo?.pincode || 'missing_pincode_sent',
324
- pincode_sent_exists: !!ekaProfileInfo?.pincode,
325
- },
326
- });
327
- setLoadingState(LOADING_STATE.REJECTED);
328
- setError(registerError || 'Something went wrong. Please try again.');
329
- return;
330
- }
331
-
332
- // Track successful address creation
333
- trackAbhaEvent({
334
- name: 'abha_address_created',
335
- data: {
336
- type: 'create_abha',
337
- platform: clientId,
338
- },
339
- });
340
-
341
- // If eka OID is available and login via Eka app, proceed with auth success
342
- if (eka.oid && isEkaAppLogin) {
343
- setLoadingState(LOADING_STATE.RESOLVED);
344
- trackAbhaEvent({
345
- name: 'abha_create_process_started',
346
- data: {
347
- method: abhaAuthFlowMethod.toLowerCase(),
348
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
349
- platform: clientId,
350
- },
351
- });
352
-
353
- // Validate gender field in profile
354
- const gender = validGenders.includes(profile?.gender as any)
355
- ? (profile?.gender as 'M' | 'F' | 'O' | 'U')
356
- : undefined;
357
-
358
- // Prepare auth profile object for mock verification response
359
- const authProfile: TProfileRecord = {
360
- oid: eka?.oid || '',
361
- fln: profile?.first_name + ' ' + profile?.last_name,
362
- dob: `${profile?.year_of_birth}-${String(profile?.month_of_birth).padStart(2, '0')}-${String(profile?.day_of_birth).padStart(2, '0')}`,
363
- gen: gender,
364
- mobile: profile?.mobile,
365
- at: '',
366
- fn: profile?.first_name || '',
367
- mn: profile?.middle_name || '',
368
- ln: profile?.last_name || '',
369
- 'health-ids': profile?.abha_address ? [profile.abha_address] : undefined,
370
- abha_number: profile?.abha_number || '',
371
- };
372
-
373
- // Generate auth success response
374
- const authResponse = getMockAuthVerifyResponse(authProfile);
375
-
376
- trackAbhaEvent({
377
- name: 'abha_create_process_success',
378
- data: {
379
- method: abhaAuthFlowMethod.toLowerCase(),
380
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
381
- platform: clientId,
382
- },
383
- });
384
- if (window.EkaAbha && window.EkaAbha.onAbhaSuccess) {
385
- window.EkaAbha?.onAbhaSuccess(JSON.stringify({ response: authResponse }));
386
- return;
387
- }
388
- // @ts-ignore
389
- onAbhaSuccess({ response: authResponse });
390
- unMount();
391
- return;
392
- }
393
- } else {
394
- // --- AADHAAR FLOW ---
395
-
396
- trackAbhaEvent({
397
- name: 'create_abha_process_started',
398
- data: {
399
- method: abhaAuthFlowMethod?.toLowerCase(),
400
- platform: clientId,
401
- },
402
- });
403
-
404
- // Call API to create PHR via aadhaar method
405
- const {
406
- error: registerError,
407
- eka,
408
- profile,
409
- action: errorAction,
410
- } = await postRegisterAadhaarCreatePhr({
411
- abha_address: abhaAddress,
412
- txn_id: txnId,
413
- });
414
-
415
- // Handle possible errors from API
416
- if (errorAction) {
417
- trackAbhaEvent({
418
- name: 'create_abha_process_error_action',
419
- data: {
420
- method: abhaAuthFlowMethod?.toLowerCase() || 'unknown_method',
421
- platform: clientId,
422
- error_message: errorAction?.cta?.title || 'unknown_error_message',
423
- error_message_exists: !!errorAction?.cta?.title,
424
- },
425
- });
426
- setBottomsheetErrorInfo(errorAction);
427
- return;
428
- }
429
-
430
- if (registerError || !eka) {
431
- trackAbhaEvent({
432
- name: 'create_abha_process_failed',
433
- data: {
434
- method: abhaAuthFlowMethod?.toLowerCase() || 'unknown_method',
435
- platform: clientId,
436
- error_message: registerError || 'unknown_error',
437
- error_message_exists: !!registerError,
438
- pincode_received: profile?.pincode || 'missing_pincode_received',
439
- pincode_received_exists: !!profile?.pincode,
440
- pincode_sent: ekaProfileInfo?.pincode || 'missing_pincode_sent',
441
- pincode_sent_exists: !!ekaProfileInfo?.pincode,
442
- },
443
- });
444
- setLoadingState(LOADING_STATE.REJECTED);
445
- setError(registerError || 'Something went wrong. Please try again.');
446
- return;
447
- }
448
- // Track successful address creation
449
- trackAbhaEvent({
450
- name: 'abha_address_created',
451
- data: {
452
- type: 'create_abha',
453
- platform: clientId,
454
- },
455
- });
456
-
457
- // If eka OID is available and login via Eka app, proceed with auth success
458
- if (eka.oid && isEkaAppLogin) {
459
- setLoadingState(LOADING_STATE.RESOLVED);
460
-
461
- trackAbhaEvent({
462
- name: 'abha_create_process_started',
463
- data: {
464
- method: abhaAuthFlowMethod?.toLowerCase(),
465
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
466
- platform: clientId,
467
- page_view: 'choose_abha_address',
468
- },
469
- });
470
-
471
- // Validate gender field in profile
472
- const gender = validGenders.includes(profile?.gender as any)
473
- ? (profile?.gender as 'M' | 'F' | 'O' | 'U')
474
- : undefined;
475
-
476
- // Prepare auth profile object for mock verification response
477
- const authProfile: TProfileRecord = {
478
- oid: eka?.oid || '',
479
- fln: profile?.first_name + ' ' + profile?.last_name,
480
- dob: `${profile?.year_of_birth}-${String(profile?.month_of_birth).padStart(2, '0')}-${String(profile?.day_of_birth).padStart(2, '0')}`,
481
- gen: gender,
482
- mobile: profile?.mobile,
483
- at: '',
484
- fn: profile?.first_name || '',
485
- mn: profile?.middle_name || '',
486
- ln: profile?.last_name || '',
487
- 'health-ids': profile?.abha_address ? [profile.abha_address] : undefined,
488
- abha_number: profile?.abha_number || '',
489
- };
490
-
491
- // Generate auth success response
492
- const authResponse = getMockAuthVerifyResponse(authProfile);
493
- trackAbhaEvent({
494
- name: 'abha_create_process_success',
495
- data: {
496
- method: abhaAuthFlowMethod?.toLowerCase(),
497
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
498
- platform: clientId,
499
- },
500
- });
501
-
502
- if (window.EkaAbha && window.EkaAbha.onAbhaSuccess) {
503
- window.EkaAbha?.onAbhaSuccess(JSON.stringify({ response: authResponse }));
504
- return;
505
- }
506
- // @ts-ignore
507
- onAbhaSuccess({ response: authResponse });
508
- unMount();
509
- return;
510
- }
511
- }
512
-
513
- // Determine the oid to be used later for profile switch
514
- let oidForSwitch = ekaProfileInfo.oid;
515
-
516
- if (ekaProfileInfo.oid) {
517
- // Track start of PHR linking process (existing profile found)
518
- trackAbhaEvent({
519
- name: 'abha_create_process_link_phr_started',
520
- data: {
521
- method: abhaAuthFlowMethod?.toLowerCase(),
522
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
523
- platform: clientId,
524
- page_view: 'choose_abha_address',
525
- },
526
- });
527
- // Attempt to link the PHR profile using existing OID
528
- const {
529
- error: linkPhrError,
530
- action: errorAction,
531
- eka,
532
- } = await postAbdmProfileEkaLinkPhr({
533
- abha_address: abhaAddress,
534
- oid: ekaProfileInfo.oid,
535
- // token: authVerifyV2Response?.sess,
536
- });
537
-
538
- // Handle case: linking failed due to actionable server response
539
- if (errorAction) {
540
- trackAbhaEvent({
541
- name: 'abha_create_process_link_phr_failed',
542
- data: {
543
- method: abhaAuthFlowMethod?.toLowerCase() || 'unknown_method',
544
- platform: clientId,
545
- error_message: errorAction?.cta?.title || 'unknown_error_message',
546
- error_message_exists: !!errorAction?.cta?.title,
547
- },
548
- });
549
- setBottomsheetErrorInfo(errorAction);
550
- return;
551
- }
552
-
553
- // Handle case: linking failed due to unknown error or missing response
554
- if (linkPhrError || !eka || !eka.oid) {
555
- trackAbhaEvent({
556
- name: 'abha_create_process_link_phr_failed',
557
- data: {
558
- method: abhaAuthFlowMethod?.toLowerCase() || 'unknown_method',
559
- platform: clientId,
560
- error_message: linkPhrError || 'unknown_error',
561
- error_message_exists: !!linkPhrError,
562
- eka: eka || 'missing_eka',
563
- eka_oid: eka?.oid || 'missing_oid',
564
- eka_oid_exists: !!eka?.oid,
565
- },
566
- });
567
- setLoadingState(LOADING_STATE.REJECTED);
568
- setError(linkPhrError || 'Something went wrong. Please try again.');
569
- return;
570
- }
571
-
572
- // Linking successful
573
- trackAbhaEvent({
574
- name: 'abha_create_process_link_phr_success',
575
- data: {
576
- method: abhaAuthFlowMethod?.toLowerCase(),
577
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
578
- platform: clientId,
579
- page_view: 'choose_abha_address',
580
- },
581
- });
582
- } else {
583
- // Track start of new PHR profile creation (no existing OID)
584
- trackAbhaEvent({
585
- name: 'abha_create_process_eka_started',
586
- data: {
587
- method: abhaAuthFlowMethod?.toLowerCase(),
588
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
589
- platform: clientId,
590
- },
591
- });
592
-
593
- // Construct payload for profile creation
594
- const profileEkaData = {
595
- abha_address: abhaAddress,
596
- day_of_birth: parseInt(day),
597
- first_name: ekaProfileInfo.firstname,
598
- gender: ekaProfileInfo.gender,
599
- last_name: ekaProfileInfo.lastname || '',
600
- month_of_birth: parseInt(month),
601
- pincode: ekaProfileInfo.pincode,
602
- year_of_birth: parseInt(year),
603
- };
604
-
605
- // Attempt to create new profile
606
- const {
607
- error: phrError,
608
- eka,
609
- action: errorAction,
610
- } = await postAbdmProfileEka({ ...profileEkaData });
611
-
612
- // Handle case: creation failed due to actionable server response
613
- if (errorAction) {
614
- trackAbhaEvent({
615
- name: 'abha_create_process_eka_failed',
616
- data: {
617
- method: abhaAuthFlowMethod?.toLowerCase() || 'unknown_method',
618
- platform: clientId,
619
- error_message: errorAction?.cta?.title || 'unknown_error_message',
620
- error_message_exists: !!errorAction?.cta?.title,
621
- },
622
- });
623
- setBottomsheetErrorInfo(errorAction);
624
- return;
625
- }
626
-
627
- // Handle case: creation failed due to unknown error or missing response
628
- if (phrError || !eka || !eka.oid) {
629
- trackAbhaEvent({
630
- name: 'abha_create_process_eka_failed',
631
- data: {
632
- method: abhaAuthFlowMethod?.toLowerCase() || 'unknown_method',
633
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
634
- platform: clientId,
635
- error_message: phrError || 'unknown_error',
636
- error_message_exists: !!phrError,
637
- eka_exists: !!eka,
638
- eka_oid: eka?.oid || 'missing_oid',
639
- eka_oid_exists: !!eka?.oid,
640
- flow: selectedMethod ?? ""
641
- },
642
- });
643
- setLoadingState(LOADING_STATE.REJECTED);
644
- setError(phrError || 'Something went wrong. Please try again.');
645
- return;
646
- }
647
-
648
- // Creation successful; store returned OID
649
- oidForSwitch = eka.oid;
650
- trackAbhaEvent({
651
- name: 'abha_create_process_eka_success',
652
- data: {
653
- method: abhaAuthFlowMethod?.toLowerCase(),
654
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
655
- platform: clientId,
656
- oid: eka?.oid,
657
- },
658
- });
659
- }
660
-
661
- // Fallback safety: ensure OID exists before switching profile
662
- if (!oidForSwitch) {
663
- trackAbhaEvent({
664
- name: 'abha_create_process_oid_switch_failed',
665
- data: {
666
- method: abhaAuthFlowMethod?.toLowerCase() || 'unknown_method',
667
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
668
- platform: clientId,
669
- oid: oidForSwitch || 'missing_oid',
670
- oid_exists: !!oidForSwitch,
671
- },
672
- });
673
- return;
674
- }
675
-
676
- // Begin profile switch process
677
- trackAbhaEvent({
678
- name: 'abha_create_process_switch_started',
679
- data: {
680
- method: abhaAuthFlowMethod?.toLowerCase(),
681
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
682
- platform: clientId,
683
- oid: oidForSwitch,
684
- },
685
- });
686
-
687
- // Attempt to switch active profile
688
- const profileSwitchResponse = await postProfileSwitchMutate({
689
- oid: oidForSwitch,
690
- });
691
-
692
- // Handle case: switching profile failed
693
- if (profileSwitchResponse.error) {
694
- trackAbhaEvent({
695
- name: 'abha_create_process_switch_failed',
696
- data: {
697
- method: abhaAuthFlowMethod?.toLowerCase() || 'unknown_method',
698
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
699
- platform: clientId,
700
- oid: oidForSwitch || 'missing_oid',
701
- oid_exists: !!oidForSwitch,
702
- error_message: profileSwitchResponse.error?.message || 'unknown_error',
703
- error_message_exists: !!profileSwitchResponse.error?.message,
704
- },
705
- });
706
- setLoadingState(LOADING_STATE.REJECTED);
707
- setError(profileSwitchResponse.error?.message || 'Something went wrong, please try again');
708
- return;
709
- }
710
-
711
- // Switching successful; ABHA account fully created and activated
712
- trackAbhaEvent({
713
- name: 'abha_create_process_switch_success',
714
- data: {
715
- method: abhaAuthFlowMethod?.toLowerCase(),
716
- is_eka_app_login: isEkaAppLogin ? 'true' : 'false',
717
- platform: clientId,
718
- oid: oidForSwitch,
719
- },
720
- });
721
-
722
- // Finalize state
723
- setLoadingState(LOADING_STATE.RESOLVED);
724
- return;
725
- }
726
- setSelectedAbhaAddress(`${abhaAddress}${isProd ? '@abdm' : '@sbx'}`);
727
- const {
728
- exists: isPhrAlreadyExist,
729
- error: phrCheckError,
730
- action: errorAction,
731
- } = await postAbdmRegisterPhrCheck({
732
- abha_address: abhaAddress,
733
- });
734
-
735
- if (phrCheckError) {
736
- setLoadingState(LOADING_STATE.REJECTED);
737
- setError(phrCheckError || 'Something went wrong. Please try again.');
738
- return;
739
- }
740
-
741
- if (isPhrAlreadyExist) {
742
- setLoadingState(LOADING_STATE.REJECTED);
743
- setError('This abha address is already taken.');
744
- return;
745
- }
746
-
747
- // this has to deprecated , but we do not have abha number flow yet.
748
- if (abhaAuthFlowMethod === ABHA_AUTH_FLOW_METHOD.ABHA_NUMBER) {
749
- if (!txnId) return;
750
- const {
751
- error: registerAbhaError,
752
- eka,
753
- action: errorAction,
754
- } = await postAbdmRegisterAbhaNumberCreatePhr({ abha_address: abhaAddress, txn_id: txnId });
755
-
756
- if (errorAction) {
757
- setBottomsheetErrorInfo(errorAction);
758
- return;
759
- }
760
-
761
- if (registerAbhaError || !eka) {
762
- setLoadingState(LOADING_STATE.REJECTED);
763
- setError(registerAbhaError || 'Something went wrong. Please try again.');
764
- return;
765
- }
766
-
767
- // if the auth is present in the headers, then do not trigger auth verify api
768
- if (extraHeaders && extraHeaders['auth'] && isEkaAppLogin) {
769
- setLoadingState(LOADING_STATE.RESOLVED);
770
- // @ts-ignore
771
- onAbhaSuccess({ response: '' }); // not in use, no change required, because abha number is not yet used.
772
- unMount();
773
- return;
774
- }
775
-
776
- if (!eka.min_token || !authTxnId) {
777
- setLoadingState(LOADING_STATE.REJECTED);
778
- setError(registerAbhaError || 'Something went wrong. Please try again.');
779
- }
780
-
781
- const authVerifyResponse = await postAuthVerifyV2Mutate({
782
- txn_id: authTxnId || '',
783
- token: eka.min_token,
784
- ...(eka.oid ? { oid: eka.oid } : null),
785
- });
786
-
787
- if (!authVerifyResponse.data) {
788
- setLoadingState(LOADING_STATE.REJECTED);
789
- setError(authVerifyResponse.error?.message || 'Something went wrong, please try again');
790
- return;
791
- }
792
- setLoadingState(LOADING_STATE.RESOLVED);
793
- return;
794
- }
795
-
796
- // if (abhaAuthFlowMethod === ABHA_AUTH_FLOW_METHOD.MOBILE) {
797
- // // setScreen(SCREEN_NAMES.CREATE_EKA_PROFILE);
798
- // if (!txnId || !ekaProfileInfo) return;
799
-
800
- // const [year, month, day] = ekaProfileInfo.date_of_birth
801
- // ? ekaProfileInfo?.date_of_birth?.split('-')
802
- // : ['', '', ''];
803
-
804
- // const mobileCreatePhrData = {
805
- // abha_address: abhaAddress,
806
- // day_of_birth: parseInt(day),
807
- // first_name: ekaProfileInfo.firstname,
808
- // gender: ekaProfileInfo.gender,
809
- // last_name: ekaProfileInfo.lastname,
810
- // month_of_birth: parseInt(month),
811
- // pincode: ekaProfileInfo.pincode,
812
- // year_of_birth: parseInt(year),
813
- // txn_id: txnId,
814
- // };
815
- // const {
816
- // error: registerError,
817
- // eka,
818
- // action: errorAction,
819
- // } = await postAbdmRegisterMobileCreatePhrMutate(mobileCreatePhrData);
820
-
821
- // if (errorAction) {
822
- // setBottomsheetErrorInfo(errorAction);
823
- // return;
824
- // }
825
-
826
- // if (registerError || !eka) {
827
- // setLoadingState(LOADING_STATE.REJECTED);
828
- // setError(registerError || 'Something went wrong. Please try again.');
829
- // return;
830
- // }
831
-
832
- // let txn_Id = ''
833
- // // only check for this min token and auth txnid not found error,
834
- // // when the token is not present in the extra headers
835
- // if (!extraHeaders || ) {
836
- // if (!eka.min_token || !authTxnId) {
837
- // setLoadingState(LOADING_STATE.REJECTED);
838
- // setError(registerError || 'Something went wrong. Please try again.');
839
- // return;
840
- // }
841
- // txn_Id = authTxnId
842
- // } else {
843
- // setLoadingState(LOADING_STATE.RESOLVED);
844
- // return;
845
- // }
846
-
847
- // const authVerifyResponse = await postAuthVerifyV2Mutate({
848
- // txn_id: txn_Id,
849
- // token: eka.min_token,
850
- // ...(eka.oid ? { oid: eka.oid } : null),
851
- // });
852
-
853
- // if (!authVerifyResponse.data) {
854
- // setLoadingState(LOADING_STATE.REJECTED);
855
- // setError(authVerifyResponse.error?.message || 'Something went wrong, please try again');
856
- // return;
857
- // }
858
- // setLoadingState(LOADING_STATE.RESOLVED);
859
- // return;
860
- // }
861
- };
862
-
863
- const handleErrorBottomsheetButtonClick = () => {
864
- goBackLoginScreen();
865
- const isAppLogin = useAuthAbhaStore.getState().isEkaAppLogin;
866
- clearAbhaAuthStore();
867
- useAuthAbhaStore.setState({ isEkaAppLogin: isAppLogin });
868
- };
869
-
870
- return (
871
- <div className="pds2-w-full pds2-h-full pds2-flex pds2-flex-col pds2-bg-bg-01">
872
- <Pds2Header
873
- title="Create ABHA Address"
874
- prefixIcon={
875
- <button
876
- className="pds2-w-24 pds2-h-24 pds2-rounded-full pds2-flex pds2-items-center pds2-justify-center ripple"
877
- onClick={() => setIsExitPopupOpen(true)}
878
- >
879
- <ArrowLeftRegularIcon />
880
- </button>
881
- }
882
- className="pds2-border-b pds2-border-bg-seperator-dark pds2-bg-bg-white pds2-flex-shrink-0"
883
- />
884
- <AbhaStepper/>
885
- {/* {isNewLoginOrCreateFlow && ( */}
886
- {/* <div
887
- className="pds2-mx-16 pds2-mt-16 pds2-border-1 pds2-rounded-16 pds2-flex pds2-items-stretch pds2-overflow-hidden pds2-flex-shrink-0"
888
- style={{ borderColor: '#F0B429', marginTop: '16px' }}
889
- >
890
- <div className="pds2-bg-bg-warning-03 pds2-p-12 pds2-flex-1 pds2-flex pds2-items-center">
891
- <p className="pds2-text-14 pds2-text-text-03 pds2-font-medium">
892
- {selectedMethod === ABHA_AUTH_FLOW_METHOD.MOBILE
893
- ? 'We will create a new ABHA address based on this mobile number'
894
- : 'We will create a new ABHA number and address based on this Aadhaar number.'}
895
- </p>
896
- </div>
897
- <div className="pds2-bg-bg-warning-03 pds2-flex-shrink-0 pds2-flex pds2-items-center pds2-px-16">
898
- <div className="pds2-w-24 pds2-h-24 pds2-rounded-full pds2-flex pds2-items-center pds2-justify-center">
899
- <CircleInfoSolidIcon className="pds2-w-14 pds2-h-14" style={{ color: '#F0B429' }} />
900
- </div>
901
- </div>
902
- </div> */}
903
- {/* )} */}
904
-
905
- <div className="pds2-p-16 pds2-flex-1 pds2-overflow-y-auto pds2-bg-bg-01">
906
- <AbhaAddressCard
907
- address={abhaAddress}
908
- setAddress={setAbhaAddress}
909
- suggestions={abhaSuggestions}
910
- />
911
- </div>
912
- {error && <div className="pds2-p-16 pds2-text-text-error pds2-text-center">{error}</div>}
913
- <div className="pds2-p-16 pds2-shadow-elevation-only-top pds2-sticky pds2-bottom-0">
914
- <Pds2Button
915
- title="Create"
916
- state={(abhaAddress.length < 8 && abhaAddress.length > 18 || loadingStatus === LOADING_STATE.LOADING) ? 'disabled' : 'enabled'}
917
- onClick={handleCreateAbhaAddressClick}
918
- isLoading={loadingStatus === LOADING_STATE.LOADING}
919
- className="pds2-w-full"
920
- />
921
- </div>
922
- <AbhaErrorBottomSheet onSubmitClick={handleErrorBottomsheetButtonClick} />
923
- <ExitPopup open={isExitPopupOpen} setOpen={setIsExitPopupOpen} />
924
- </div>
925
- );
926
- };
927
-
928
- export default CreateAbhaAddressScreen;