Skip to content

Commit

Permalink
BAH-3459 | Add. create default abha address
Browse files Browse the repository at this point in the history
  • Loading branch information
SanoferSameera committed Jan 12, 2024
1 parent f89ca45 commit d171e9a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
59 changes: 39 additions & 20 deletions src/components/creation/CreateABHAAddress.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useState} from "react";
import './creation.scss';
import Spinner from "../spinner/spinner";
import {checkIfABHAAddressExists, createABHAAddress} from "../../api/hipServiceApi";
import {checkIfABHAAddressExists, createABHAAddress, createDefaultHealthId} from "../../api/hipServiceApi";
import Footer from "./Footer";
import {cmSuffixProperty} from "../../api/constants";

Expand Down Expand Up @@ -35,6 +35,7 @@ const CreateABHAAddress = (props) => {
if (response.data === undefined) {
processingError(response);
} else {
setNewAbhaAddress(newAbhaAddress.concat(cmSuffix));
props.setABHAAddressCreated(true);
}
}
Expand All @@ -51,6 +52,20 @@ const CreateABHAAddress = (props) => {
}
}

async function createDefault() {
setLoader(true);
setError('');
const response = await createDefaultHealthId();
if (response.data !== undefined) {
props.setABHAAddressCreated(true);
setNewAbhaAddress(response.data.healthId);
}
else {
setError(response.details[0].message || response.message)
}
setLoader(false);
}

function processingError(response){
if (response.details !== undefined && response.details.length > 0)
setError(response.details[0].message)
Expand All @@ -64,28 +79,32 @@ const CreateABHAAddress = (props) => {

return (
<div>
<div>
<div className="abha-address" >
<label htmlFor="abhaAdddress">Enter new ABHA ADDRESS </label>
<div className="abha-adddress-input" >
<div className="new-abha-address-input">
<input type="text" id="abhaAdddress" name="abhaAdddress" value={newAbhaAddress} onChange={OnChangeHandler} />
<span className="abha-address-suffix">{cmSuffix}</span>
</div>
<div className="abha-address" >
<label htmlFor="abhaAdddress">Enter new ABHA ADDRESS </label>
<div className="abha-adddress-input" >
<div className="new-abha-address-input">
<input type="text" id="abhaAdddress" name="abhaAdddress" value={newAbhaAddress} onChange={OnChangeHandler} />
<span className="abha-address-suffix">{cmSuffix}</span>
</div>
</div>
<div className="center" >
<input type="checkbox" id="preferred" checked={isPreferred} className="checkbox" onChange={OnClick}/>
<span className="preferred"> Preferred </span>
</div>
<p className="message">Click on the check box to make the above abha-address as a default</p>
{error !== '' && <h6 className="error">{error}</h6>}
{loader && <Spinner />}
<div className="center">
<button type="button" className="proceed" onClick={onCreate}>Create</button>
</div>
<Footer setBack={props.setBack} />
</div>
<div className="center" >
<input type="checkbox" id="preferred" checked={isPreferred} className="checkbox" onChange={OnClick}/>
<span className="preferred"> Preferred </span>
</div>
<p className="message">Click on the check box to make the above abha-address as a default</p>
<div className="center">
<button type="button" className="proceed" onClick={onCreate}>Create</button>
</div>
<div className="alternative-text">
OR
</div>
<div className="create-default-healthId">
<button name="default-healthId-btn" type="button" onClick={createDefault}>Create Default ABHA Address</button>
</div>
{loader && <Spinner />}
{error !== '' && <h6 className="error">{error}</h6>}
<Footer setBack={props.setBack} />
</div>
);
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/creation/LinkABHAAddress.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './creation.scss';
import PatientDetails from "../patient-details/patientDetails";
import VerifyMobileEmail from "./VerifyMobileEmail";
import CreateABHAAddress from "./CreateABHAAddress";
import {cmSuffixProperty, enableLinkABHAAddress} from "../../api/constants";
import {enableLinkABHAAddress} from "../../api/constants";
import CheckIdentifierExists from "../Common/CheckIdentifierExists";
import {fetchGlobalProperty} from "../../api/hipServiceApi";

Expand All @@ -22,8 +22,6 @@ const LinkABHAAddress = (props) => {
const [healthNumberAlreadyLinked, setHealthNumberAlreadyLinked] = useState(false);
let isLinkingEnabled;
const refEls = useRef({});

const cmSuffix = localStorage.getItem(cmSuffixProperty)

function onProceed() {
mapPatient();
Expand Down Expand Up @@ -65,7 +63,7 @@ const LinkABHAAddress = (props) => {


function mapPatient(){
props.mappedPatient.id = abhaAddressCreated ? newAbhaAddress.concat(cmSuffix) : abhaAddress;
props.mappedPatient.id = abhaAddressCreated ? newAbhaAddress : abhaAddress;
}

function gotoLink(){
Expand Down
5 changes: 5 additions & 0 deletions src/components/creation/creation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
color: red;
margin-top: 0px;
}

.create-default-healthId {
margin-left: 40%;
margin-top: 5%
}
}

button {
Expand Down

0 comments on commit d171e9a

Please sign in to comment.