-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeviceInformationChangeViewModel.ts
47 lines (38 loc) · 1.36 KB
/
DeviceInformationChangeViewModel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Copyright © 2023 Nevis Security AG. All rights reserved.
*/
import { useState } from 'react';
import { useNavigation } from '@react-navigation/native';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import type { RootStackParamList } from './RootStackParamList';
import { ErrorHandler } from '../error/ErrorHandler';
import { OperationType } from '../model/OperationType';
import { ClientProvider } from '../utility/ClientProvider';
const useDeviceInformationChangeViewModel = () => {
const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
const [deviceName, setDeviceName] = useState('');
async function confirm() {
console.log('Change device information.');
const client = ClientProvider.getInstance().client;
await client?.operations.deviceInformationChange
.name(deviceName)
.onSuccess(() => {
console.log('Change device information succeeded.');
navigation.navigate('Result', {
operation: OperationType.deviceInformationChange,
});
})
.onError(ErrorHandler.handle.bind(null, OperationType.deviceInformationChange))
.execute()
.catch(ErrorHandler.handle.bind(null, OperationType.deviceInformationChange));
}
async function cancel() {
navigation.goBack();
}
return {
setDeviceName,
confirm,
cancel,
};
};
export default useDeviceInformationChangeViewModel;