forked from openmrs/openmrs-esm-patient-management
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hie otp verification to use values and replaced CR id with SHA nu…
…mber on HealthID (#55) * Added hie Patient OTP verification to use patient data and replace CR id with SHA number * Updated transalations
- Loading branch information
1 parent
fe870ad
commit 6037eca
Showing
6 changed files
with
333 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...app/src/client-registry/hie-client-registry/modal/hie-otp-verification-form.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Button, Column, Row, Stack, Tag, TextInput, InlineLoading } from '@carbon/react'; | ||
import { showSnackbar } from '@openmrs/esm-framework'; | ||
import React from 'react'; | ||
import { Controller, useFormContext } from 'react-hook-form'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { type authorizationFormSchema, generateOTP, persistOTP, sendOtp } from '../hie-resource'; | ||
import styles from './confirm-hie.scss'; | ||
import { type z } from 'zod'; | ||
|
||
type HIEOTPVerficationFormProps = { | ||
name: string; | ||
patientId: string; | ||
status?: 'loadingOtp' | 'otpSendSuccessfull' | 'otpFetchError'; | ||
setStatus: React.Dispatch<React.SetStateAction<'loadingOtp' | 'otpSendSuccessfull' | 'otpFetchError'>>; | ||
}; | ||
|
||
const HIEOTPVerficationForm: React.FC<HIEOTPVerficationFormProps> = ({ name, patientId, setStatus, status }) => { | ||
const form = useFormContext<z.infer<typeof authorizationFormSchema>>(); | ||
const { t } = useTranslation(); | ||
|
||
const handleGetOTP = async () => { | ||
try { | ||
setStatus('loadingOtp'); | ||
const otp = generateOTP(5); | ||
await sendOtp({ otp, receiver: form.watch('receiver') }, name); | ||
setStatus('otpSendSuccessfull'); | ||
persistOTP(otp, patientId); | ||
} catch (error) { | ||
setStatus('otpFetchError'); | ||
showSnackbar({ title: t('error', 'Error'), kind: 'error', subtitle: error?.message }); | ||
} | ||
}; | ||
|
||
return ( | ||
<Stack gap={4} className={styles.grid}> | ||
<Column> | ||
<Controller | ||
control={form.control} | ||
name="receiver" | ||
render={({ field }) => ( | ||
<TextInput | ||
invalid={form.formState.errors[field.name]?.message} | ||
invalidText={form.formState.errors[field.name]?.message} | ||
{...field} | ||
placeholder={t('patientPhoneNUmber', 'Patient Phone number')} | ||
labelText={t('patientPhoneNUmber', 'Patient Phone number')} | ||
helperText={t('phoneNumberHelper', 'Patient will receive OTP on this number')} | ||
/> | ||
)} | ||
/> | ||
</Column> | ||
|
||
<Column> | ||
<Controller | ||
control={form.control} | ||
name="otp" | ||
render={({ field }) => ( | ||
<Row className={styles.otpInputRow}> | ||
<TextInput | ||
invalid={form.formState.errors[field.name]?.message} | ||
invalidText={form.formState.errors[field.name]?.message} | ||
{...field} | ||
placeholder={t('otpCode', 'OTP Authorization code')} | ||
labelText={t('otpCode', 'OTP Authorization code')} | ||
/> | ||
<Button | ||
onClick={handleGetOTP} | ||
role="button" | ||
type="blue" | ||
kind="tertiary" | ||
disabled={['loadingOtp', 'otpSendSuccessfull'].includes(status)}> | ||
{status === 'loadingOtp' ? ( | ||
<InlineLoading status="active" iconDescription="Loading" description="Loading data..." /> | ||
) : status === 'otpFetchError' ? ( | ||
t('retry', 'Retry') | ||
) : ( | ||
t('verifyOTP', 'Verify with OTP') | ||
)} | ||
</Button> | ||
</Row> | ||
)} | ||
/> | ||
</Column> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default HIEOTPVerficationForm; |
Oops, something went wrong.