@eka-care/abha 0.0.1 → 0.0.3
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/.eslintignore +3 -0
- package/.eslintrc +29 -0
- package/.prettierrc +7 -0
- package/dev-abha-ios-android.zip +0 -0
- package/{dist/index.html → index.html} +1 -2
- package/package.json +5 -32
- package/postcss.config.js +6 -0
- package/prod-abha-mixpanel.zip +0 -0
- package/scripts/build-purged-css.cjs +70 -0
- package/src/App.css +0 -0
- package/src/App.tsx +32 -0
- package/src/api-queries/use-get-profiles-patient.ts +12 -0
- package/src/api-queries/use-get-profiles-phr-user.ts +27 -0
- package/src/api-queries/use-post-abdm-login-verify-v1.ts +25 -0
- package/src/api-queries/use-post-auth-verify-v2.ts +74 -0
- package/src/api-queries/use-post-profile-switch.ts +57 -0
- package/src/api-queries/use-post-register-mobile-create-phr.ts +39 -0
- package/src/api-queries/user-post-abdm-profile-login-phr.ts +25 -0
- package/src/assets/react.svg +1 -0
- package/src/atoms/button/custom-button.tsx +32 -0
- package/src/atoms/button/index.tsx +40 -0
- package/src/atoms/button/types.d.ts +31 -0
- package/src/atoms/header.tsx +25 -0
- package/src/atoms/input-field/index.tsx +62 -0
- package/src/atoms/input-field/patient-input-field.tsx +16 -0
- package/src/atoms/input-field/types.ts +24 -0
- package/src/atoms/pds2-otp-input/index.tsx +35 -0
- package/src/atoms/pds2-otp-input/types.d.ts +3 -0
- package/src/atoms/single-input-chip/index.tsx +32 -0
- package/src/atoms/single-input-chip/types.ts +6 -0
- package/src/atoms/spinner.tsx +33 -0
- package/src/atoms/text-separator.tsx +11 -0
- package/src/index.css +118 -0
- package/src/main.tsx +313 -0
- package/src/molecules/abha/bottom-sheet/bottom-sheet-wrapper.tsx +40 -0
- package/src/molecules/abha/bottom-sheet/index.tsx +66 -0
- package/src/molecules/abha/spaced-input-component.tsx +150 -0
- package/src/molecules/copyright-year.tsx +16 -0
- package/src/molecules/exit-popup/index.tsx +99 -0
- package/src/molecules/pds2-otp-component/index.tsx +148 -0
- package/src/organisms/abha/abha-header.tsx +25 -0
- package/src/organisms/abha/error-bottom-sheet.tsx +27 -0
- package/src/organisms/abha/otp-card.tsx +99 -0
- package/src/organisms/abha/verification-status.tsx +40 -0
- package/src/organisms/choose-language/choose-language.tsx +53 -0
- package/src/organisms/choose-language/types.ts +10 -0
- package/src/organisms/screen-switcher/screen-switcher.tsx +80 -0
- package/src/routes/abha-aadhaar-verification-status-screen.tsx +209 -0
- package/src/routes/abha-created-screen.tsx +45 -0
- package/src/routes/abha-login-otp-verify-screen.tsx +523 -0
- package/src/routes/abha-mobile-linking-status-screen.tsx +267 -0
- package/src/routes/abha-otp-and-mobile-screen.tsx +429 -0
- package/src/routes/abha-phone-number-verification-screen.tsx +373 -0
- package/src/routes/create-abha-address-screen.tsx +928 -0
- package/src/routes/create-abha-with-aadhaar-screen.tsx +984 -0
- package/src/routes/create-eka-profile-screen.tsx +777 -0
- package/src/routes/get-all-profiles-screen.tsx +161 -0
- package/src/routes/login-or-create-abha-address-screen.tsx +953 -0
- package/src/routes/login-with-abha-screen.tsx +448 -0
- package/src/routes/select-abha-from-list-screen.tsx +718 -0
- package/src/routes/select-eka-profile-screen.tsx +444 -0
- package/src/routes/utils/trackAbhaEvent.ts +41 -0
- package/src/stores/auth-abha-store/index.ts +138 -0
- package/src/stores/auth-abha-store/types.ts +204 -0
- package/src/utils/mock-auth-response.ts +31 -0
- package/src/vite-env.d.ts +1 -0
- package/tailwind.config.ts +9 -0
- package/tsconfig.app.json +26 -0
- package/tsconfig.json +25 -0
- package/tsconfig.node.json +10 -0
- package/tsconfig.node.tsbuildinfo +1 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vite.config.d.ts +2 -0
- package/vite.config.js +30 -0
- package/vite.config.ts +35 -0
- package/dist/README.md +0 -114
- package/dist/package.json +0 -7
- package/dist/sdk/abha/css/abha.css +0 -1
- package/dist/sdk/abha/js/abha.js +0 -137
- /package/{dist → public}/images/adhaar.webp +0 -0
- /package/{dist → public}/images/at-the-rate.webp +0 -0
- /package/{dist → public}/images/avatar.webp +0 -0
- /package/{dist → public}/images/ayushman-bharat.webp +0 -0
- /package/{dist → public}/images/circle-checkmark.webp +0 -0
- /package/{dist → public}/images/link-abha.webp +0 -0
- /package/{dist → public}/images/national-authority.webp +0 -0
- /package/{dist → public}/images/three-dots.webp +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { InputFieldProps } from './types';
|
|
2
|
+
|
|
3
|
+
const Pds2InputField = ({
|
|
4
|
+
PrefixComponent,
|
|
5
|
+
placeholder,
|
|
6
|
+
value,
|
|
7
|
+
onChange,
|
|
8
|
+
borderStyle = '',
|
|
9
|
+
borderRadius = 'pds2-rounded-16',
|
|
10
|
+
padding = 'pds2-px-24 pds2-py-16',
|
|
11
|
+
textColor = 'pds2-text-text-black',
|
|
12
|
+
textStyle = '',
|
|
13
|
+
onKeyDown = () => {},
|
|
14
|
+
type = 'text',
|
|
15
|
+
label,
|
|
16
|
+
isMandatory,
|
|
17
|
+
maxDate,
|
|
18
|
+
error,
|
|
19
|
+
autoCapitalize = 'off',
|
|
20
|
+
autoCorrect = 'off',
|
|
21
|
+
disabled,
|
|
22
|
+
inputMode,
|
|
23
|
+
autoFocus,
|
|
24
|
+
pattern,
|
|
25
|
+
maxLength,
|
|
26
|
+
}: InputFieldProps) => {
|
|
27
|
+
return (
|
|
28
|
+
<div className="pds2-flex pds2-flex-col pds2-space-y-8 pds2-w-full">
|
|
29
|
+
{label ? (
|
|
30
|
+
<div className="Body3Medium pds2-text-text-04">
|
|
31
|
+
{label}
|
|
32
|
+
{isMandatory ? <sup className="pds2-text-text-error Body3Semibold">*</sup> : null}
|
|
33
|
+
</div>
|
|
34
|
+
) : null}
|
|
35
|
+
<label
|
|
36
|
+
className={`${padding} ${borderRadius} ${borderStyle} pds2-border ${
|
|
37
|
+
error ? 'pds2-border-text-error pds2-border-2' : 'pds2-border-border-03'
|
|
38
|
+
} pds2-flex pds2-flex-row pds2-items-center pds2-gap-x-8 pds2-w-full pds2-bg-bg-white pds2-text-text-invert`}
|
|
39
|
+
>
|
|
40
|
+
{PrefixComponent ? PrefixComponent : null}
|
|
41
|
+
<input
|
|
42
|
+
className={`${textColor} ${textStyle} pds2-outline-none pds2-w-full pds2-bg-transparent disabled:pds2-text-text-04`}
|
|
43
|
+
placeholder={placeholder || 'Enter Value'}
|
|
44
|
+
value={value}
|
|
45
|
+
onChange={onChange}
|
|
46
|
+
type={type}
|
|
47
|
+
max={type === 'date' && maxDate ? maxDate : undefined}
|
|
48
|
+
onKeyDown={onKeyDown}
|
|
49
|
+
autoCapitalize={autoCapitalize}
|
|
50
|
+
autoCorrect={autoCorrect}
|
|
51
|
+
disabled={disabled}
|
|
52
|
+
inputMode={inputMode}
|
|
53
|
+
autoFocus={autoFocus}
|
|
54
|
+
pattern={pattern}
|
|
55
|
+
maxLength={maxLength}
|
|
56
|
+
/>
|
|
57
|
+
</label>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default Pds2InputField;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Pds2InputField from '.';
|
|
2
|
+
import { InputFieldProps } from './types';
|
|
3
|
+
|
|
4
|
+
type TPatientPds2InputFieldProps = InputFieldProps;
|
|
5
|
+
|
|
6
|
+
const PatientPds2InputField = (props: TPatientPds2InputFieldProps) => {
|
|
7
|
+
return (
|
|
8
|
+
<Pds2InputField
|
|
9
|
+
{...props}
|
|
10
|
+
textStyle="Body1Medium"
|
|
11
|
+
borderStyle="focus-within:pds2-ring-2 focus-within:pds2-ring-border-brand-01 focus-within:pds2-ring-offset-2"
|
|
12
|
+
/>
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default PatientPds2InputField;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type InputFieldProps = {
|
|
2
|
+
borderRadius?: string;
|
|
3
|
+
borderStyle?: string;
|
|
4
|
+
padding?: string;
|
|
5
|
+
textColor?: string;
|
|
6
|
+
textStyle?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
PrefixComponent?: React.ReactNode;
|
|
9
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
10
|
+
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
|
|
11
|
+
value: string;
|
|
12
|
+
type?: React.HTMLInputTypeAttribute;
|
|
13
|
+
label?: string;
|
|
14
|
+
isMandatory?: boolean;
|
|
15
|
+
maxDate?: string;
|
|
16
|
+
error?: string;
|
|
17
|
+
autoCapitalize?: string;
|
|
18
|
+
autoCorrect?: string;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
inputMode?: 'email' | 'search' | 'tel' | 'text' | 'url' | 'none' | 'numeric' | 'decimal';
|
|
21
|
+
autoFocus?: boolean;
|
|
22
|
+
pattern?: string;
|
|
23
|
+
maxLength?: number;
|
|
24
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { InputHTMLAttributes, useState } from 'react';
|
|
2
|
+
import { TOtpInputProps } from './types';
|
|
3
|
+
|
|
4
|
+
const Pds2OtpInput = ({
|
|
5
|
+
value,
|
|
6
|
+
isError,
|
|
7
|
+
...restProps
|
|
8
|
+
}: InputHTMLAttributes<HTMLInputElement> & TOtpInputProps) => {
|
|
9
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<input
|
|
13
|
+
{...restProps}
|
|
14
|
+
value={value}
|
|
15
|
+
placeholder="."
|
|
16
|
+
onFocus={(e) => {
|
|
17
|
+
setIsFocused(true);
|
|
18
|
+
restProps.onFocus?.(e);
|
|
19
|
+
}}
|
|
20
|
+
onBlur={(e) => {
|
|
21
|
+
setIsFocused(false);
|
|
22
|
+
restProps.onBlur?.(e);
|
|
23
|
+
}}
|
|
24
|
+
className={`pds2-rounded-16 pds2-border-1 pds2-p-16 ${
|
|
25
|
+
isError
|
|
26
|
+
? 'pds2-border-border-error'
|
|
27
|
+
: isFocused
|
|
28
|
+
? 'pds2-border-border-doc'
|
|
29
|
+
: 'pds2-border-border-03'
|
|
30
|
+
} pds2-w-48 pds2-bg-bg-white pds2-text-text-primary pds2-text-center placeholder:pds2-text-text-04 Body1Regular pds2-outline-none`}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default Pds2OtpInput;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { TSingleInputChipProps } from './types';
|
|
3
|
+
|
|
4
|
+
export default function Pds2SingleInputChip({
|
|
5
|
+
title,
|
|
6
|
+
isDisabled,
|
|
7
|
+
isSelected,
|
|
8
|
+
onSelect,
|
|
9
|
+
}: TSingleInputChipProps) {
|
|
10
|
+
const divRef = useRef<HTMLInputElement>(null);
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
onClick={!isDisabled ? onSelect : undefined}
|
|
14
|
+
className={`pds2-flex pds2-items-center pds2-cursor-pointer pds2-py-12 pds2-px-16 pds2-border-1 pds2-rounded-12 pds2-bg-bg-white
|
|
15
|
+
${isSelected ? 'pds2-border-border-brand-01' : 'pds2-border-border-03'}
|
|
16
|
+
focus-within:pds2-ring-2 focus-within:pds2-ring-border-brand-01 focus-within:pds2-ring-offset-2
|
|
17
|
+
active:pds2-bg-bg-brand-02 hover:pds2-bg-bg-hover-01
|
|
18
|
+
pds2-transition-colors pds2-duration-200
|
|
19
|
+
`}
|
|
20
|
+
tabIndex={-1}
|
|
21
|
+
ref={divRef}
|
|
22
|
+
>
|
|
23
|
+
<p
|
|
24
|
+
className={`${
|
|
25
|
+
isSelected ? 'pds2-text-text-brand Body2Semibold' : 'pds2-text-text-01 Body2Medium'
|
|
26
|
+
}`}
|
|
27
|
+
>
|
|
28
|
+
{title}
|
|
29
|
+
</p>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
type TSpinner = {
|
|
2
|
+
className?: string;
|
|
3
|
+
size?: number;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const Pds2Spinner = ({ className = '', size = 40 }: TSpinner): JSX.Element => {
|
|
7
|
+
return (
|
|
8
|
+
<div className={`pds2-w-fit pds2-flex pds2-justify-center pds2-items-center ${className}`}>
|
|
9
|
+
<svg
|
|
10
|
+
className="pds2-animate-spin"
|
|
11
|
+
id="svg-spinner"
|
|
12
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
13
|
+
width={size}
|
|
14
|
+
height={size}
|
|
15
|
+
viewBox="0 0 48 48"
|
|
16
|
+
fill="currentColor"
|
|
17
|
+
>
|
|
18
|
+
<circle cx="24" cy="4" r="2.5" className="fill-current opacity-100" />
|
|
19
|
+
<circle cx="12.19" cy="7.86" r="2.5" className="fill-current opacity-90" />
|
|
20
|
+
<circle cx="5.02" cy="17.68" r="2.5" className="fill-current opacity-80" />
|
|
21
|
+
<circle cx="5.02" cy="30.32" r="2.5" className="fill-current opacity-70" />
|
|
22
|
+
<circle cx="12.19" cy="40.14" r="2.5" className="fill-current opacity-60" />
|
|
23
|
+
<circle cx="24" cy="44" r="2.5" className="fill-current opacity-50" />
|
|
24
|
+
<circle cx="35.81" cy="40.14" r="2.5" className="fill-current opacity-40" />
|
|
25
|
+
<circle cx="42.98" cy="30.32" r="2.5" className="fill-current opacity-30" />
|
|
26
|
+
<circle cx="42.98" cy="17.68" r="2.5" className="fill-current opacity-20" />
|
|
27
|
+
<circle cx="35.81" cy="7.86" r="2.5" className="fill-current opacity-10" />
|
|
28
|
+
</svg>
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default Pds2Spinner;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const TextSeparator = ({ title }: { title: string }) => {
|
|
2
|
+
return (
|
|
3
|
+
<div className="pds2-relative pds2-flex pds2-flex-row pds2-items-center pds2-gap-16">
|
|
4
|
+
<div className="pds2-w-full pds2-h-1 pds2-bg-border-03"></div>
|
|
5
|
+
<div className="pds2-text-text-04 Body2Regular pds2-text-center pds2-min-w-max">{title}</div>
|
|
6
|
+
<div className="pds2-w-full pds2-h-1 pds2-bg-border-03"></div>
|
|
7
|
+
</div>
|
|
8
|
+
);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default TextSeparator;
|
package/src/index.css
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
body {
|
|
6
|
+
@apply pds2-font-lato;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@layer base {
|
|
10
|
+
.TitlesSubheadline {
|
|
11
|
+
@apply pds2-font-700 pds2-text-16 pds2-leading-20;
|
|
12
|
+
}
|
|
13
|
+
.BodyBody {
|
|
14
|
+
@apply pds2-font-400 pds2-text-16 pds2-leading-22;
|
|
15
|
+
}
|
|
16
|
+
.DisplayRegular {
|
|
17
|
+
@apply pds2-font-400 pds2-text-34 pds2-leading-44;
|
|
18
|
+
}
|
|
19
|
+
.DisplayMedium {
|
|
20
|
+
@apply pds2-font-500 pds2-text-32 pds2-leading-40;
|
|
21
|
+
}
|
|
22
|
+
.DisplaySemibold {
|
|
23
|
+
@apply pds2-font-600 pds2-text-32 pds2-leading-40;
|
|
24
|
+
}
|
|
25
|
+
.Heading2Medium {
|
|
26
|
+
@apply pds2-font-500 pds2-text-24 pds2-leading-32;
|
|
27
|
+
}
|
|
28
|
+
.Heading2Semibold {
|
|
29
|
+
@apply pds2-font-600 pds2-text-24 pds2-leading-32;
|
|
30
|
+
}
|
|
31
|
+
.Heading3Semibold {
|
|
32
|
+
@apply pds2-font-600 pds2-text-20 pds2-leading-28;
|
|
33
|
+
}
|
|
34
|
+
.Heading4Semibold {
|
|
35
|
+
@apply pds2-font-600 pds2-text-18 pds2-leading-24;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.Body1Semibold {
|
|
39
|
+
@apply pds2-font-600 pds2-text-16 pds2-leading-24;
|
|
40
|
+
}
|
|
41
|
+
.Body2Semibold {
|
|
42
|
+
@apply pds2-font-600 pds2-text-14 pds2-leading-20;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.Body1Regular {
|
|
46
|
+
@apply pds2-font-400 pds2-text-16 pds2-leading-24;
|
|
47
|
+
}
|
|
48
|
+
.Body2Regular {
|
|
49
|
+
@apply pds2-font-400 pds2-text-14 pds2-leading-20;
|
|
50
|
+
}
|
|
51
|
+
.Body2Medium {
|
|
52
|
+
@apply pds2-font-500 pds2-text-14 pds2-leading-20;
|
|
53
|
+
}
|
|
54
|
+
.Body3Regular {
|
|
55
|
+
@apply pds2-font-400 pds2-text-12 pds2-leading-16;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.Body3Medium {
|
|
59
|
+
@apply pds2-font-500 pds2-text-12 pds2-leading-16;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.Body3Semibold {
|
|
63
|
+
@apply pds2-font-600 pds2-text-12 pds2-leading-16;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.Body3CapsRegular {
|
|
67
|
+
@apply pds2-font-400 pds2-text-12 pds2-leading-16 pds2-uppercase pds2-tracking-[0.96px];
|
|
68
|
+
}
|
|
69
|
+
.Body3CapsSemibold {
|
|
70
|
+
@apply pds2-font-600 pds2-text-12 pds2-leading-16 pds2-uppercase pds2-tracking-[0.96px];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.BodyFootnote {
|
|
74
|
+
@apply pds2-font-400 pds2-text-13 pds2-leading-18;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.BodyInputLabel {
|
|
78
|
+
@apply pds2-font-400 pds2-text-12 pds2-leading-12;
|
|
79
|
+
}
|
|
80
|
+
.Label1Semibold {
|
|
81
|
+
@apply pds2-font-600 pds2-text-10 pds2-leading-14;
|
|
82
|
+
}
|
|
83
|
+
.SubheadlineRegular {
|
|
84
|
+
@apply pds2-font-400 pds2-text-14 pds2-leading-20;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@layer utilities {
|
|
89
|
+
@variants responsive {
|
|
90
|
+
.ripple {
|
|
91
|
+
@apply pds2-relative pds2-overflow-hidden pds2-transform;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.ripple::after {
|
|
95
|
+
@apply pds2-absolute pds2-inset-0 pds2-block pds2-bg-center pds2-bg-no-repeat pds2-opacity-0 pds2-pointer-events-none;
|
|
96
|
+
content: '';
|
|
97
|
+
background-image: radial-gradient(circle, #000 10%, transparent 10.01%);
|
|
98
|
+
transform: scale(10, 10);
|
|
99
|
+
transition:
|
|
100
|
+
transform 0.3s,
|
|
101
|
+
opacity 1s;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.ripple:active::after {
|
|
105
|
+
transform: scale(0, 0);
|
|
106
|
+
opacity: 0.3;
|
|
107
|
+
transition: 0s;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
input[type="date"]::-webkit-calendar-picker-indicator {
|
|
113
|
+
display: inline !important;
|
|
114
|
+
-webkit-appearance: auto !important;
|
|
115
|
+
width: 16px;
|
|
116
|
+
padding: 0px;
|
|
117
|
+
margin: 0px;
|
|
118
|
+
}
|
package/src/main.tsx
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { ABHA_AUTH_FLOW_METHOD } from '@elixir/types';
|
|
2
|
+
import { setEnv } from 'apis';
|
|
3
|
+
import { TAuthVerifyV2Response } from 'apis/src/types/aorta-go';
|
|
4
|
+
import { createRoot, Root } from 'react-dom/client';
|
|
5
|
+
import 'ui/styles.css';
|
|
6
|
+
import App, { queryClient } from './App';
|
|
7
|
+
import './index.css';
|
|
8
|
+
import useAuthAbhaStore from './stores/auth-abha-store';
|
|
9
|
+
import { SCREEN_NAMES } from './stores/auth-abha-store/types';
|
|
10
|
+
import { handleSendEvent } from '@elixir/utils';
|
|
11
|
+
|
|
12
|
+
const trackAbhaEvent = ({ name, data = {} }: { name: string; data?: Record<string, any> }) => {
|
|
13
|
+
|
|
14
|
+
const eventData = {
|
|
15
|
+
...data,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
handleSendEvent({
|
|
19
|
+
eventName: name,
|
|
20
|
+
eventData,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
window.curio?.pushToMixpanel?.(name, eventData);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type TMethod = 'login_with_abha' | 'create_abha_with_mobile' | 'login_or_create_abha';
|
|
27
|
+
|
|
28
|
+
const getScreenName = ({ method = 'login_with_abha' }: { method?: TMethod }): SCREEN_NAMES => {
|
|
29
|
+
switch (method) {
|
|
30
|
+
case 'login_with_abha':
|
|
31
|
+
return SCREEN_NAMES.LOGIN_WITH_ABHA;
|
|
32
|
+
case 'create_abha_with_mobile':
|
|
33
|
+
return SCREEN_NAMES.CREATE_ABHA_WITH_AADHAAR;
|
|
34
|
+
case 'login_or_create_abha':
|
|
35
|
+
return SCREEN_NAMES.LOGIN_OR_CREATE_ABHA;
|
|
36
|
+
default:
|
|
37
|
+
return SCREEN_NAMES.LOGIN_WITH_ABHA;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
type TInitAbhaAppParams = {
|
|
42
|
+
clientId: string;
|
|
43
|
+
containerId: string;
|
|
44
|
+
urlParams?: {
|
|
45
|
+
nextUrl: string;
|
|
46
|
+
};
|
|
47
|
+
method?: TMethod;
|
|
48
|
+
data?: {
|
|
49
|
+
mobile?: string;
|
|
50
|
+
accessToken?: string;
|
|
51
|
+
oid?: string;
|
|
52
|
+
};
|
|
53
|
+
appVersion?: string;
|
|
54
|
+
onSuccess: (params: TOnAbhaSuccessParams) => void;
|
|
55
|
+
onError: (params: TOnAbhaFailureParams) => void;
|
|
56
|
+
onAbhaClose: () => void;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
declare global {
|
|
60
|
+
interface Window {
|
|
61
|
+
initAbhaApp: (params: TInitAbhaAppParams) => void;
|
|
62
|
+
closeAbhaApp: () => void;
|
|
63
|
+
EkaAbha?: {
|
|
64
|
+
mobileNumber?: string;
|
|
65
|
+
onAbhaSuccess: (params: string) => void;
|
|
66
|
+
onAbhaError: (params: string) => void;
|
|
67
|
+
onAbhaClose: () => void;
|
|
68
|
+
changeStatusBarColor?: (params: string) => void;
|
|
69
|
+
};
|
|
70
|
+
curio?: {
|
|
71
|
+
pushToMixpanel?: (eventName: string, eventProps: Record<string, any>) => void;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// TODO: Move all the rendering functions to a separate file
|
|
77
|
+
|
|
78
|
+
let PopupReactNode: Root | null = null;
|
|
79
|
+
|
|
80
|
+
export let unMount: () => void;
|
|
81
|
+
|
|
82
|
+
type TOnAbhaSuccessParams = {
|
|
83
|
+
response: TAuthVerifyV2Response;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export let onAbhaSuccess: (params: TOnAbhaSuccessParams) => void;
|
|
87
|
+
|
|
88
|
+
type TOnAbhaFailureParams = { error?: string; response?: TAuthVerifyV2Response };
|
|
89
|
+
|
|
90
|
+
export let onAbhaFailure: (params: TOnAbhaFailureParams) => void;
|
|
91
|
+
|
|
92
|
+
function initAbhaApp(params: TInitAbhaAppParams) {
|
|
93
|
+
// clear abha auth store at the very start
|
|
94
|
+
console.log('clear the abha auth store for every sdk invocation', params);
|
|
95
|
+
useAuthAbhaStore.getState().clearAbhaAuthStore();
|
|
96
|
+
|
|
97
|
+
const {
|
|
98
|
+
clientId,
|
|
99
|
+
containerId,
|
|
100
|
+
urlParams,
|
|
101
|
+
method,
|
|
102
|
+
data: abhaData,
|
|
103
|
+
appVersion,
|
|
104
|
+
onSuccess,
|
|
105
|
+
onError,
|
|
106
|
+
onAbhaClose,
|
|
107
|
+
} = params;
|
|
108
|
+
const { mobile, accessToken, oid } = abhaData || {};
|
|
109
|
+
const headers: Record<string, string> = {};
|
|
110
|
+
|
|
111
|
+
if (accessToken) {
|
|
112
|
+
headers.auth = accessToken;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (oid) {
|
|
116
|
+
headers['X-User-ID'] = oid;
|
|
117
|
+
}
|
|
118
|
+
console.log('set headers in headers');
|
|
119
|
+
|
|
120
|
+
console.log('invoked initAbhaApp', headers);
|
|
121
|
+
|
|
122
|
+
// adding a check of oid in headers, in stetho, only oid is passed, auth is not passed.
|
|
123
|
+
|
|
124
|
+
const isEkaAppLogin = headers !== null && ('auth' in headers || 'X-User-ID' in headers);
|
|
125
|
+
useAuthAbhaStore.getState().setIsEkaAppLogin(isEkaAppLogin);
|
|
126
|
+
|
|
127
|
+
// set true to isEkaAppLogin if clientId is doc-web
|
|
128
|
+
if (clientId === 'doc-web') {
|
|
129
|
+
useAuthAbhaStore.getState().setIsEkaAppLogin(true);
|
|
130
|
+
}
|
|
131
|
+
console.log('clientId ', clientId);
|
|
132
|
+
console.log('isEkaAppLogin', useAuthAbhaStore.getState().isEkaAppLogin);
|
|
133
|
+
|
|
134
|
+
if (
|
|
135
|
+
clientId === 'androiddoc' ||
|
|
136
|
+
clientId === 'doctor-app-ios' ||
|
|
137
|
+
clientId === 'doctor-ipad-ios' ||
|
|
138
|
+
clientId === 'doc-web'
|
|
139
|
+
) {
|
|
140
|
+
useAuthAbhaStore.getState().setClientId('doctor');
|
|
141
|
+
} else if (clientId === 'androidp' || clientId === 'patient-app-ios') {
|
|
142
|
+
useAuthAbhaStore.getState().setClientId('phr');
|
|
143
|
+
} else if (clientId === 'www-eka') {
|
|
144
|
+
useAuthAbhaStore.getState().setClientId('eka-web');
|
|
145
|
+
} else {
|
|
146
|
+
console.log('here');
|
|
147
|
+
useAuthAbhaStore.getState().setClientId('phr');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let isDocAppRequest = false;
|
|
151
|
+
|
|
152
|
+
// publish an mix panel event
|
|
153
|
+
handleSendEvent({
|
|
154
|
+
eventName: 'init_abha_app',
|
|
155
|
+
eventData: {
|
|
156
|
+
platform: clientId,
|
|
157
|
+
method: method || '',
|
|
158
|
+
mobile: mobile || '',
|
|
159
|
+
accessToken: accessToken || '',
|
|
160
|
+
oid: oid || '',
|
|
161
|
+
appVersion: appVersion || '',
|
|
162
|
+
isEkaAppLogin: isEkaAppLogin.toString(),
|
|
163
|
+
container_id: containerId,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// use onTrack
|
|
168
|
+
onTrack('init_abha_app', {
|
|
169
|
+
platform: clientId,
|
|
170
|
+
method: method || '',
|
|
171
|
+
mobile: mobile || '',
|
|
172
|
+
accessToken: headers.auth || '',
|
|
173
|
+
oid: headers['X-User-ID'] || '',
|
|
174
|
+
appVersion: appVersion || '',
|
|
175
|
+
isEkaAppLogin: isEkaAppLogin.toString(),
|
|
176
|
+
container_id: containerId,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (
|
|
180
|
+
clientId === 'androiddoc' ||
|
|
181
|
+
clientId === 'doctor-app-ios' ||
|
|
182
|
+
clientId === 'doctor-ipad-ios' ||
|
|
183
|
+
clientId === 'doc-web'
|
|
184
|
+
) {
|
|
185
|
+
isDocAppRequest = true;
|
|
186
|
+
useAuthAbhaStore.getState().setIsDocAppRequest(isDocAppRequest);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
useAuthAbhaStore
|
|
190
|
+
.getState()
|
|
191
|
+
.setInitAbhaAppMethod(
|
|
192
|
+
method === 'create_abha_with_mobile' ? 'create_abha_with_mobile' : 'login_with_abha'
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
setEnv({
|
|
196
|
+
// TODO: Change this to the actual client id
|
|
197
|
+
clientId,
|
|
198
|
+
env: import.meta.env.VITE_APP_ENV === 'PROD' ? 'PROD' : 'DEV',
|
|
199
|
+
...(headers && { extraHeaders: headers }),
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const screenName = SCREEN_NAMES.LOGIN_OR_CREATE_ABHA;
|
|
203
|
+
|
|
204
|
+
useAuthAbhaStore.getState().setInitState({
|
|
205
|
+
screen: [screenName],
|
|
206
|
+
urlParams,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
useAuthAbhaStore.getState().setAbhaAuthFlowMethod(ABHA_AUTH_FLOW_METHOD.MOBILE);
|
|
210
|
+
const regex = /[^0-9]/g;
|
|
211
|
+
const mobileNumber = mobile || window.EkaAbha?.mobileNumber;
|
|
212
|
+
const regexMobileNumber = mobileNumber?.replace(regex, '');
|
|
213
|
+
const validMobile = regexMobileNumber?.slice(-10);
|
|
214
|
+
|
|
215
|
+
if (validMobile && validMobile.length === 10) {
|
|
216
|
+
// if it valid mobile number then set it in the store
|
|
217
|
+
useAuthAbhaStore.getState().setInitAbhaAppMobileNumber(validMobile);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const closeAbhaApp = () => {
|
|
221
|
+
|
|
222
|
+
trackAbhaEvent({
|
|
223
|
+
name: 'connectivity-debug-onclose',
|
|
224
|
+
data: {
|
|
225
|
+
platform: clientId,
|
|
226
|
+
line: 226,
|
|
227
|
+
function: "closeAbhaApp",
|
|
228
|
+
page: "main.tsx.tsx",
|
|
229
|
+
flow: "debug",
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
useAuthAbhaStore.getState().clearAbhaAuthStore();
|
|
233
|
+
queryClient.removeQueries();
|
|
234
|
+
PopupReactNode?.unmount();
|
|
235
|
+
onAbhaClose();
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const rootElement = document.getElementById(containerId);
|
|
239
|
+
if (!rootElement) {
|
|
240
|
+
const errorMessage = `Element with id ${containerId} not found`;
|
|
241
|
+
console.error(errorMessage);
|
|
242
|
+
onError({ error: errorMessage });
|
|
243
|
+
closeAbhaApp();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
onAbhaSuccess = onSuccess;
|
|
248
|
+
onAbhaFailure = onError;
|
|
249
|
+
|
|
250
|
+
PopupReactNode = createRoot(rootElement);
|
|
251
|
+
PopupReactNode.render(<App />);
|
|
252
|
+
|
|
253
|
+
unMount = closeAbhaApp;
|
|
254
|
+
window.closeAbhaApp = closeAbhaApp;
|
|
255
|
+
|
|
256
|
+
return closeAbhaApp;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
window.initAbhaApp = initAbhaApp;
|
|
260
|
+
|
|
261
|
+
let eventQueue: Array<{ eventName: string; eventProps: Record<string, any> }> = [];
|
|
262
|
+
|
|
263
|
+
function onTrack(eventName: string, eventProperties: Record<string, any> = {}) {
|
|
264
|
+
const platform = useAuthAbhaStore.getState().clientId || 'unknown-platform';
|
|
265
|
+
|
|
266
|
+
const finalEventProps = {
|
|
267
|
+
...eventProperties,
|
|
268
|
+
platform,
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
console.log('Tracking Event:', eventName, finalEventProps);
|
|
272
|
+
|
|
273
|
+
if (window.curio?.pushToMixpanel) {
|
|
274
|
+
console.log('Pushing to Mixpanel:', eventName, finalEventProps);
|
|
275
|
+
window.curio.pushToMixpanel(eventName, finalEventProps);
|
|
276
|
+
} else {
|
|
277
|
+
console.log('Curio not available. Queuing event:', eventName, finalEventProps);
|
|
278
|
+
console.error('Curio not available. Could not push event to Mixpanel.');
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (import.meta.env.VITE_APP_MODE === 'DEBUG') {
|
|
283
|
+
initAbhaApp({
|
|
284
|
+
clientId: 'www-eka',
|
|
285
|
+
containerId: 'lofe_root',
|
|
286
|
+
method: 'login_or_create_abha',
|
|
287
|
+
data: {
|
|
288
|
+
// mobile: '8709459003',
|
|
289
|
+
// accessToken:
|
|
290
|
+
// 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhbmRyb2lkZG9jIiwiYi1pZCI6Ijc3MjM3NjM3NzYzODE3IiwiY2MiOnt9LCJkb2IiOiIxOTk4LTAyLTEwIiwiZXhwIjoxNzQxODY3NDMyLCJmbiI6IlN0YWdlIiwiZ2VuIjoiTSIsImlhdCI6MTc0MTg2NjgzMiwiaXNzIjoiZW1yLmVrYS5jYXJlIiwibG4iOiJHb2QiLCJvaWQiOiIxNzQxMTY3MTMwMjk3NjgiLCJwcyI6IkQiLCJ1dWlkIjoiZGRjMGVmNDUtNDZmOS00ZGE5LTlhNTgtNjcwZjc1N2YyYzc3In0.ZHpMNQuolWQ-MqzbYAHnZGVz1CqFTofm7sV-7ARlfug',
|
|
291
|
+
// oid: '17418668693032712',
|
|
292
|
+
},
|
|
293
|
+
// urlParams: { from: 'dr', next: 'https://www.google.com' },
|
|
294
|
+
// workspaceName: 'hell',
|
|
295
|
+
onSuccess: (params) => {
|
|
296
|
+
handleSendEvent({
|
|
297
|
+
eventName: 'abha_on_success',
|
|
298
|
+
eventData: {
|
|
299
|
+
params: JSON.stringify(params),
|
|
300
|
+
oid: params?.response?.data?.profile?.oid ?? '',
|
|
301
|
+
uuid: params?.response?.data?.profile?.uuid ?? '',
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
console.log('%c Line:117 🍕 onSuccessParams', 'color:#465975', params);
|
|
305
|
+
},
|
|
306
|
+
onError: (params) => {
|
|
307
|
+
console.log('%c Line:121 🥟 onErrorParams', 'color:#6ec1c2', params);
|
|
308
|
+
},
|
|
309
|
+
onAbhaClose: () => {
|
|
310
|
+
console.log('%c Line:121 🥟 onAbhaClose', 'color:#6ec1c2');
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
}
|