react-native-scanner/Pages/Settings/index.js

77 lines
2.0 KiB
JavaScript

import {Text, View} from 'react-native';
import {Button} from 'react-native-paper';
import EncryptedStorage from 'react-native-encrypted-storage';
export default function Settings({setScannerSession}) {
const onSignOut = async () => {
try {
const scannerHost = await EncryptedStorage.getItem('scanner_host');
const scannerSession = await EncryptedStorage.getItem('scanner_session');
await EncryptedStorage.removeItem('scanner_host');
console.log('after await ', scannerHost, scannerSession);
setScannerSession();
const response = await fetch(scannerHost, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'X-Authorization': scannerSession,
},
});
const result = await response.text();
console.log('result', result);
} catch (error) {
console.error(error);
}
/*EncryptedStorage.getItem('scanner_host')
.then(scannerHost => {
console.log('scanner host', scannerHost);
fetch(scannerHost, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'X-Authorization': userSession,
},
})
.then(res => {
if (res.status === 200) {
setSnackbarMessage('Sent to dashboard');
return res.text();
}
setSnackbarMessage('Failed to send');
return Promise.reject(res.status);
})
.then(data => {
console.log('data', data);
})
.catch(err => {
console.error(err);
});
})
.catch(err => console.error(err));*/
};
return (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<Text style={{color: '#fff'}}>Settings</Text>
<Button mode="contained" onPress={() => onSignOut()}>
Sign out
</Button>
</View>
);
}