-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce code duplication for QR code scan (#8004)
* Add Link/Unlink Barcode action Fixes #7920 * remove unneeded imports * remove duplication * simplify * add testing * refactor type * wait for reload to add coverage * Add warning if custom barcode is used * Add Image based assign * fix action button size * fix selection to prevent wrapping * use left section for button * Refactor to seperate Input * Add comment when not scanning * Fix punctuation * factor scan area out * fix readonly arg * make BarcodeInput more generic * make button optional * reduce code duplication by using BarcodeInput * remove unneeded abstraction
- Loading branch information
Showing
4 changed files
with
125 additions
and
211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { t } from '@lingui/macro'; | ||
import { ActionIcon, Box, Button, Divider, TextInput } from '@mantine/core'; | ||
import { IconQrcode } from '@tabler/icons-react'; | ||
import React, { useState } from 'react'; | ||
|
||
import { InputImageBarcode } from '../../pages/Index/Scan'; | ||
|
||
type BarcodeInputProps = { | ||
onScan: (decodedText: string) => void; | ||
value?: string; | ||
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void; | ||
onAction?: () => void; | ||
placeholder?: string; | ||
label?: string; | ||
actionText?: string; | ||
}; | ||
|
||
export function BarcodeInput({ | ||
onScan, | ||
value, | ||
onChange, | ||
onAction, | ||
placeholder = t`Scan barcode data here using barcode scanner`, | ||
label = t`Barcode`, | ||
actionText = t`Scan` | ||
}: Readonly<BarcodeInputProps>) { | ||
const [isScanning, setIsScanning] = useState(false); | ||
|
||
return ( | ||
<Box> | ||
{isScanning && ( | ||
<> | ||
<InputImageBarcode action={onScan} /> | ||
<Divider mt={'sm'} /> | ||
</> | ||
)} | ||
<TextInput | ||
label={label} | ||
value={value} | ||
onChange={onChange} | ||
placeholder={placeholder} | ||
leftSection={ | ||
<ActionIcon | ||
variant={isScanning ? 'filled' : 'subtle'} | ||
onClick={() => setIsScanning(!isScanning)} | ||
> | ||
<IconQrcode /> | ||
</ActionIcon> | ||
} | ||
w="100%" | ||
/> | ||
{onAction ? ( | ||
<Button color="green" onClick={onAction} mt="lg" fullWidth> | ||
{actionText} | ||
</Button> | ||
) : null} | ||
</Box> | ||
); | ||
} |
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
Oops, something went wrong.