2020-09-06 03:16:46 +00:00
|
|
|
import React, {ReactElement, useState} from 'react';
|
|
|
|
import {View} from 'react-native';
|
|
|
|
import {DefaultTheme, Subheading, Title, RadioButton, Paragraph, TextInput, HelperText, Button} from 'react-native-paper';
|
|
|
|
import {CameraType, SettingsScreenProps} from '../models/ElementProps';
|
|
|
|
import {colors, styles} from './Styles';
|
|
|
|
|
2020-09-10 22:23:55 +00:00
|
|
|
const _stringToInt = (inputStr: string): number => {
|
|
|
|
const num = parseInt(inputStr || '0', 10);
|
|
|
|
if (!isNaN(num)) {
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-06 03:16:46 +00:00
|
|
|
export const SettingsScreen = (props: SettingsScreenProps): ReactElement => {
|
|
|
|
const [newCameraType, setNewCameraType] = useState<CameraType>(props.cameraType);
|
2020-09-10 22:23:55 +00:00
|
|
|
const [newNumCopies, setNewNumCopies] = useState<number>(props.numCopies);
|
2020-09-06 03:16:46 +00:00
|
|
|
const [newLocationStr, setNewLocationStr] = useState<string>(props.locationStr);
|
|
|
|
|
2020-09-10 22:23:55 +00:00
|
|
|
const _numCopiesHasErrors = () => {
|
|
|
|
return newNumCopies <= 0 || newNumCopies > 10;
|
|
|
|
};
|
|
|
|
|
|
|
|
const locPattern = /^[\d]{4}$/;
|
|
|
|
const _locHasErrors = () => {
|
|
|
|
return !locPattern.test(newLocationStr);
|
2020-09-06 03:16:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return <View style={styles.settings}>
|
|
|
|
<Title style={{color: DefaultTheme.colors.text}}>Settings</Title>
|
|
|
|
<View style={{marginBottom: 40}}>
|
|
|
|
<Subheading style={{color: DefaultTheme.colors.text}}>Camera to Use</Subheading>
|
|
|
|
<RadioButton.Group
|
|
|
|
onValueChange={value => setNewCameraType(value as CameraType)}
|
|
|
|
value={newCameraType as string}
|
|
|
|
>
|
|
|
|
<RadioButton.Item
|
|
|
|
value="front"
|
|
|
|
label="Front"
|
|
|
|
theme={DefaultTheme}
|
|
|
|
/>
|
|
|
|
<RadioButton.Item
|
|
|
|
value="back"
|
|
|
|
label="Back"
|
|
|
|
theme={DefaultTheme}
|
|
|
|
/>
|
|
|
|
</RadioButton.Group>
|
|
|
|
</View>
|
|
|
|
|
2020-09-10 22:23:55 +00:00
|
|
|
<View style={{marginBottom: 40}}>
|
|
|
|
<Subheading style={{color: DefaultTheme.colors.text}}>Copies of labels</Subheading>
|
|
|
|
<Paragraph style={{color: DefaultTheme.colors.text}}>
|
|
|
|
Input the number of sets of labels to print for each patient
|
|
|
|
</Paragraph>
|
|
|
|
<TextInput
|
|
|
|
label="# of copies"
|
|
|
|
value={newNumCopies.toString()}
|
|
|
|
onChangeText={inputStr => setNewNumCopies(_stringToInt(inputStr))}
|
|
|
|
mode="outlined"
|
|
|
|
theme={DefaultTheme}
|
|
|
|
keyboardType="numeric"
|
|
|
|
/>
|
|
|
|
<HelperText type="error" visible={_numCopiesHasErrors()}>
|
|
|
|
Please enter a number from 1 to 10.
|
|
|
|
</HelperText>
|
|
|
|
</View>
|
|
|
|
|
2020-09-06 03:16:46 +00:00
|
|
|
<View style={{marginBottom: 10}}>
|
|
|
|
<Subheading style={{color: DefaultTheme.colors.text}}>Location Code</Subheading>
|
|
|
|
<Paragraph style={{color: DefaultTheme.colors.text}}>
|
|
|
|
Please do NOT change this unless you know what you are doing. Entering an incorrect location number may
|
|
|
|
prevent patients from getting accurate info about their test results.
|
|
|
|
</Paragraph>
|
|
|
|
<TextInput
|
|
|
|
label="Location #"
|
|
|
|
value={newLocationStr}
|
|
|
|
onChangeText={inputStr => setNewLocationStr(inputStr)}
|
|
|
|
mode="outlined"
|
|
|
|
theme={DefaultTheme}
|
2020-09-10 22:23:55 +00:00
|
|
|
keyboardType="numeric"
|
2020-09-06 03:16:46 +00:00
|
|
|
/>
|
2020-09-10 22:23:55 +00:00
|
|
|
<HelperText type="error" visible={_locHasErrors()}>
|
2020-09-06 03:16:46 +00:00
|
|
|
Location number must be exactly 4 digits. No other characters are allowed.
|
|
|
|
</HelperText>
|
|
|
|
<Button
|
|
|
|
icon="content-save"
|
|
|
|
mode="contained"
|
|
|
|
color={colors.primary}
|
|
|
|
style={{marginBottom: 10}}
|
2020-09-10 22:23:55 +00:00
|
|
|
disabled={_locHasErrors() || _numCopiesHasErrors()}
|
|
|
|
onPress={() => props.onSave(newCameraType, newNumCopies, newLocationStr)}
|
2020-09-06 03:16:46 +00:00
|
|
|
>Save</Button>
|
|
|
|
<Button
|
|
|
|
icon="cancel"
|
|
|
|
mode="outlined"
|
|
|
|
color={colors.primary}
|
|
|
|
onPress={props.onCancel}
|
|
|
|
>Cancel</Button>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
}
|