Skip to content

Commit

Permalink
Update QR code scanner package and replace deprecated QrReader with S…
Browse files Browse the repository at this point in the history
…canner component from "@yudiel/react-qr-scanner" package.
  • Loading branch information
thedevildude committed Apr 14, 2024
1 parent 9246320 commit 2a895b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Components/ABDM/LinkABHANumberModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const ScanABHAQRSection = ({
}
setQrValue(value);
}}
parse={async (value: string) => {
parse={async (value: string | null) => {
if (!value) return;
setIsLoading(true);

Expand Down
21 changes: 11 additions & 10 deletions src/Components/Common/QRScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as Notification from "../../Utils/Notifications.js";

import CareIcon from "../../CAREUI/icons/CareIcon";
import DialogModal from "./Dialog";
import QrReader from "react-qr-reader";
import TextFormField from "../Form/FormFields/TextFormField.js";
import { useState } from "react";
import { Scanner } from "@yudiel/react-qr-scanner";

interface IQRScannerModalProps {
show: boolean;
onClose: () => void;
onScan: (scannedValue: any) => any;
onScan: (scannedValue: string | null) => void;
description?: string;
disabled?: boolean;
}
Expand All @@ -32,15 +32,16 @@ const QRScannerModal = ({
<h2 className="mb-4 self-center text-center text-lg">
{description || "Scan QR code!"}
</h2>
<QrReader
delay={300}
onScan={onScan}
onError={(e: any) =>
<Scanner
onResult={onScan}
onError={(e) =>
Notification.Error({
msg: e.message,
})
}
style={{ width: "100%" }}
options={{
delayBetweenScanAttempts: 300,
}}
/>
</div>
</DialogModal>
Expand All @@ -50,7 +51,7 @@ const QRScannerModal = ({
interface IProps {
value: string;
onChange: (value: string) => void;
parse?: (scannedValue: any) => any;
parse?: (scannedValue: string | null) => void;
className?: string;
error?: string;
label?: string;
Expand Down Expand Up @@ -92,8 +93,8 @@ const QRScanner = ({
show={showScanner}
disabled={disabled}
onClose={() => setShowScanner(false)}
onScan={async (scannedValue: any) => {
const parsedValue = (await parse?.(scannedValue)) ?? null;
onScan={async (scannedValue) => {
const parsedValue = parse?.(scannedValue) ?? null;
if (parsedValue) {
onChange(parsedValue);
setShowScanner(false);
Expand Down
13 changes: 7 additions & 6 deletions src/Components/Facility/AssetCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FieldErrorText, FieldLabel } from "../Form/FormFields/FormField";
import { LocationSelect } from "../Common/LocationSelect";
import Page from "../Common/components/Page";
import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField";
import QrReader from "react-qr-reader";
import { Scanner } from "@yudiel/react-qr-scanner";
import { SelectFormField } from "../Form/FormFields/SelectFormField";
import SwitchV2 from "../Common/components/Switch";
import TextAreaFormField from "../Form/FormFields/TextAreaFormField";
Expand Down Expand Up @@ -418,15 +418,16 @@ const AssetCreate = (props: AssetProps) => {
<CareIcon icon="l-times" className="mr-2 text-lg" />
{t("close_scanner")}
</button>
<QrReader
delay={300}
onScan={(assetId: any) => (assetId ? parseAssetId(assetId) : null)}
onError={(e: any) =>
<Scanner
onResult={(assetId) => (assetId ? parseAssetId(assetId) : null)}
onError={(e) =>
Notification.Error({
msg: e.message,
})
}
style={{ width: "100%" }}
options={{
delayBetweenScanAttempts: 300,
}}
/>
<h2 className="self-center text-center text-lg">
{t("scan_asset_qr")}
Expand Down

0 comments on commit 2a895b6

Please sign in to comment.