Moves barcode pattern into config.
This commit is contained in:
parent
98eac004c8
commit
77529fbb91
15
App.tsx
15
App.tsx
|
@ -15,8 +15,8 @@ import {BarCodeDisplay, PrintButton, PrintingMessage} from './components/Print';
|
||||||
import {IdNumberInput, InitialsInput, InputIdButton, ScanButton, Scanner} from './components/Scan';
|
import {IdNumberInput, InitialsInput, InputIdButton, ScanButton, Scanner} from './components/Scan';
|
||||||
import {SettingsScreen} from './components/Settings';
|
import {SettingsScreen} from './components/Settings';
|
||||||
import {styles, theme} from './components/Styles';
|
import {styles, theme} from './components/Styles';
|
||||||
import {sendDataToFirebase, SyncMessage} from './components/Sync';
|
import {SyncMessage} from './components/Sync';
|
||||||
import {firebaseConfig, defaults} from './config/default';
|
import {defaults, firebaseConfig} from './config/default';
|
||||||
import {BarcodeScannerAppState} from './models/BarcodeScannerAppState';
|
import {BarcodeScannerAppState} from './models/BarcodeScannerAppState';
|
||||||
import {CameraType, ElementProps, StateProps} from './models/ElementProps';
|
import {CameraType, ElementProps, StateProps} from './models/ElementProps';
|
||||||
import {LineCount} from './models/LineCount';
|
import {LineCount} from './models/LineCount';
|
||||||
|
@ -87,7 +87,8 @@ export default function Main() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// State event handlers
|
// State event handlers
|
||||||
const _doNothing = () => {};
|
const _doNothing = () => {
|
||||||
|
};
|
||||||
const _scan = () => {
|
const _scan = () => {
|
||||||
setErrorMessage('');
|
setErrorMessage('');
|
||||||
setAppState(BarcodeScannerAppState.SCANNING);
|
setAppState(BarcodeScannerAppState.SCANNING);
|
||||||
|
@ -107,13 +108,9 @@ export default function Main() {
|
||||||
|
|
||||||
const handleBarCodeScanned = (e: BarCodeEvent) => {
|
const handleBarCodeScanned = (e: BarCodeEvent) => {
|
||||||
// Make sure the data is the right length.
|
// Make sure the data is the right length.
|
||||||
// Scanned barcodes will be exactly 14 digits long.
|
|
||||||
// Manually-entered ID numbers will be exactly 9 digits long.
|
|
||||||
const barCodeString = e.data;
|
const barCodeString = e.data;
|
||||||
const pattern = /^[\d]{14}$|^[\d]{9}$/;
|
if (defaults.barCodeRegex.test(barCodeString)) {
|
||||||
console.log('barCodeString', barCodeString);
|
const cardId = e.data.slice(0, defaults.barCodeNumLength);
|
||||||
if (pattern.test(barCodeString)) {
|
|
||||||
const cardId = e.data.slice(0, 9);
|
|
||||||
const newSampleDate = new Date();
|
const newSampleDate = new Date();
|
||||||
setBarCodeId(cardId);
|
setBarCodeId(cardId);
|
||||||
setSampleDate(newSampleDate);
|
setSampleDate(newSampleDate);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import {ButtonProps, InputLineCountScreenProps} from '../models/ElementProps';
|
|
||||||
import React, {ReactElement, useState} from 'react';
|
import React, {ReactElement, useState} from 'react';
|
||||||
import {View} from 'react-native';
|
import {View} from 'react-native';
|
||||||
import {DefaultTheme, Subheading, Title, RadioButton, Paragraph, TextInput, HelperText, Button} from 'react-native-paper';
|
import {Button, DefaultTheme, HelperText, Subheading, TextInput, Title} from 'react-native-paper';
|
||||||
import {TextInput as NumberInput} from 'react-native';
|
import {ButtonProps, InputLineCountScreenProps} from '../models/ElementProps';
|
||||||
import {colors, styles} from './Styles';
|
import {colors, styles} from './Styles';
|
||||||
|
|
||||||
export const InputLineCountButton = (props: ButtonProps): ReactElement => {
|
export const InputLineCountButton = (props: ButtonProps): ReactElement => {
|
||||||
|
|
|
@ -2,6 +2,7 @@ import {BarCodeScanner} from 'expo-barcode-scanner';
|
||||||
import React, {ReactElement, useState} from 'react';
|
import React, {ReactElement, useState} from 'react';
|
||||||
import {Text, View} from 'react-native';
|
import {Text, View} from 'react-native';
|
||||||
import {Button, DefaultTheme, HelperText, Subheading, TextInput, Title} from 'react-native-paper';
|
import {Button, DefaultTheme, HelperText, Subheading, TextInput, Title} from 'react-native-paper';
|
||||||
|
import {defaults} from '../config/default';
|
||||||
import {ButtonProps, ElementProps, InputInitialsProps, ScannerProps} from '../models/ElementProps';
|
import {ButtonProps, ElementProps, InputInitialsProps, ScannerProps} from '../models/ElementProps';
|
||||||
import {colors, styles} from './Styles';
|
import {colors, styles} from './Styles';
|
||||||
|
|
||||||
|
@ -56,9 +57,8 @@ export const InputIdButton = (props: ButtonProps): ReactElement => {
|
||||||
|
|
||||||
export const IdNumberInput = (props: ScannerProps): ReactElement => {
|
export const IdNumberInput = (props: ScannerProps): ReactElement => {
|
||||||
const [inputStr, setInputStr] = useState<string>('');
|
const [inputStr, setInputStr] = useState<string>('');
|
||||||
const pattern = /^[\d]{9}$/;
|
|
||||||
const hasErrors = () => {
|
const hasErrors = () => {
|
||||||
return !pattern.test(inputStr);
|
return !defaults.barCodeRegex.test(inputStr);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
|
@ -81,7 +81,7 @@ export const IdNumberInput = (props: ScannerProps): ReactElement => {
|
||||||
keyboardType="numeric"
|
keyboardType="numeric"
|
||||||
/>
|
/>
|
||||||
<HelperText type="error" visible={hasErrors()}>
|
<HelperText type="error" visible={hasErrors()}>
|
||||||
ID number must be exactly 9 digits. No other characters are allowed.
|
ID number must be exactly {defaults.barCodeNumLength} digits. No other characters are allowed.
|
||||||
</HelperText>
|
</HelperText>
|
||||||
<Button
|
<Button
|
||||||
icon="check"
|
icon="check"
|
||||||
|
|
|
@ -23,4 +23,7 @@ export const defaults: AppDefaults = {
|
||||||
locationId: '0000', // Default location ID. Can be overridden by user setting.
|
locationId: '0000', // Default location ID. Can be overridden by user setting.
|
||||||
lineCountRegex: /^[\d]{4}-[\d]{12}$/, // ID format for Line Count records.
|
lineCountRegex: /^[\d]{4}-[\d]{12}$/, // ID format for Line Count records.
|
||||||
qrCodeRegex: /^[\d]{9}-[a-zA-Z]+-[\d]{12}-[\d]{4}$/, // ID format for QR Code records.
|
qrCodeRegex: /^[\d]{9}-[a-zA-Z]+-[\d]{12}-[\d]{4}$/, // ID format for QR Code records.
|
||||||
|
barCodeNumLength: 9, // Number of digits in Bar Code.
|
||||||
|
barCodeRegex: /^[\d]{14}$|^[\d]{9}$/, // Pattern for Bar Code data. Scanned barcodes will be either 9 or 14 digits long.
|
||||||
|
// Manually-entered ID numbers will be exactly 9 digits long.
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,7 @@ export const defaults: AppDefaults = {
|
||||||
locationId: '0000', // Default location ID. Can be overridden by user setting.
|
locationId: '0000', // Default location ID. Can be overridden by user setting.
|
||||||
lineCountRegex: /^[\d]{4}-[\d]{12}$/, // ID format for Line Count records.
|
lineCountRegex: /^[\d]{4}-[\d]{12}$/, // ID format for Line Count records.
|
||||||
qrCodeRegex: /^[\d]{9}-[a-zA-Z]+-[\d]{12}-[\d]{4}$/, // ID format for QR Code records.
|
qrCodeRegex: /^[\d]{9}-[a-zA-Z]+-[\d]{12}-[\d]{4}$/, // ID format for QR Code records.
|
||||||
|
barCodeNumLength: 9, // Number of digits in Bar Code.
|
||||||
|
barCodeRegex: /^[\d]{14}$|^[\d]{9}$/, // Pattern for Bar Code data. Scanned barcodes will be either 9 or 14 digits long.
|
||||||
|
// Manually-entered ID numbers will be exactly 9 digits long.
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,6 @@ export interface AppDefaults {
|
||||||
locationId: string;
|
locationId: string;
|
||||||
lineCountRegex: RegExp;
|
lineCountRegex: RegExp;
|
||||||
qrCodeRegex: RegExp;
|
qrCodeRegex: RegExp;
|
||||||
|
barCodeRegex: RegExp;
|
||||||
|
barCodeNumLength: number;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue