2022-10-14 06:20:51 +00:00
|
|
|
import { TextInput, Alert, Switch, TouchableOpacity, View, Text, Modal, FlatList, KeyboardAvoidingView } from 'react-native';
|
2022-10-13 07:03:10 +00:00
|
|
|
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
|
|
|
|
import Ionicons from '@expo/vector-icons/AntDesign';
|
|
|
|
import { styles } from './Dashboard.styled';
|
|
|
|
import { useLocation } from 'react-router-dom';
|
|
|
|
import { useDashboard } from './useDashboard.hook';
|
|
|
|
import { Logo } from 'utils/Logo';
|
|
|
|
|
|
|
|
export function Dashboard(props) {
|
|
|
|
|
|
|
|
const location = useLocation();
|
|
|
|
const { config, server, token } = location.state;
|
|
|
|
const { state, actions } = useDashboard(config, server, token);
|
|
|
|
|
2022-10-14 06:20:51 +00:00
|
|
|
const saveConfig = async () => {
|
|
|
|
try {
|
|
|
|
await actions.saveConfig();
|
|
|
|
actions.hideEditConfig();
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
Alert.alert(
|
|
|
|
'Failed to Save Settings',
|
|
|
|
'Please try again.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-13 07:03:10 +00:00
|
|
|
return (
|
|
|
|
<SafeAreaView style={styles.container}>
|
|
|
|
<View style={styles.header}>
|
|
|
|
<Text style={styles.headerLabel}>Accounts</Text>
|
2022-10-13 22:21:40 +00:00
|
|
|
<TouchableOpacity onPress={actions.refresh}>
|
|
|
|
<Ionicons style={styles.icon} name={'reload1'} size={20} />
|
|
|
|
</TouchableOpacity>
|
|
|
|
<TouchableOpacity onPress={actions.showEditConfig}>
|
|
|
|
<Ionicons style={styles.icon} name={'setting'} size={20} />
|
|
|
|
</TouchableOpacity>
|
2022-10-13 07:03:10 +00:00
|
|
|
<TouchableOpacity onPress={actions.logout}>
|
2022-10-13 18:22:14 +00:00
|
|
|
<Ionicons style={styles.icon} name={'logout'} size={20} />
|
2022-10-13 07:03:10 +00:00
|
|
|
</TouchableOpacity>
|
2022-10-13 22:21:40 +00:00
|
|
|
<View style={styles.end}>
|
|
|
|
<TouchableOpacity onPress={actions.showAddUser}>
|
|
|
|
<Ionicons style={styles.icon} name={'adduser'} size={24} />
|
|
|
|
</TouchableOpacity>
|
2022-10-13 07:03:10 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
<View style={styles.accounts}>
|
|
|
|
<FlatList style={styles.lit}
|
|
|
|
data={state.accounts}
|
|
|
|
keyExtractor={item => item.accountId}
|
|
|
|
renderItem={({ item }) => (
|
|
|
|
<View style={styles.account}>
|
2022-10-13 18:22:14 +00:00
|
|
|
<Logo src={item.logo} width={32} height={32} radius={4} />
|
2022-10-13 07:03:10 +00:00
|
|
|
<View style={styles.details}>
|
|
|
|
<Text style={styles.name}>{ item.name }</Text>
|
|
|
|
<Text style={styles.handle}>{ item.handle }</Text>
|
|
|
|
</View>
|
|
|
|
<View style={styles.control}>
|
2022-10-13 22:21:40 +00:00
|
|
|
<TouchableOpacity activeOpacity={1} onPress={() => actions.showAccessUser(item.accountId)}>
|
|
|
|
<Ionicons style={styles.icon} name={'unlock'} size={20} />
|
|
|
|
</TouchableOpacity>
|
2022-10-13 07:03:10 +00:00
|
|
|
<Ionicons style={styles.disable} name={'closecircleo'} size={20} />
|
|
|
|
<Ionicons style={styles.delete} name={'deleteuser'} size={20} />
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</View>
|
2022-10-13 22:21:40 +00:00
|
|
|
|
|
|
|
<Modal
|
|
|
|
animationType="fade"
|
|
|
|
transparent={true}
|
|
|
|
visible={state.editConfig}
|
|
|
|
supportedOrientations={['portrait', 'landscape']}
|
|
|
|
onRequestClose={actions.hideEditConfig}
|
|
|
|
>
|
|
|
|
<KeyboardAvoidingView behavior="height" style={styles.modalBackground}>
|
|
|
|
<View style={styles.modalContainer}>
|
|
|
|
<View style={styles.modalHeader}>
|
|
|
|
<Text style={styles.modalHeaderText}>Settings:</Text>
|
|
|
|
</View>
|
|
|
|
<View style={styles.modalBody}>
|
2022-10-14 06:20:51 +00:00
|
|
|
<TextInput style={styles.input} value={state.domain} onChangeText={actions.setDomain}
|
2022-10-13 22:21:40 +00:00
|
|
|
autoCorrect={false} autoCapitalize="none" placeholder="Federated Host" />
|
2022-10-14 06:20:51 +00:00
|
|
|
<TextInput style={styles.input} value={state.storage}
|
|
|
|
onChangeText={actions.setStorage}
|
2022-10-13 22:21:40 +00:00
|
|
|
keyboardType='numeric' placeholder="Storage Limit (GB) / Account" />
|
2022-10-14 06:20:51 +00:00
|
|
|
<Text style={styles.modalLabel}>Account Key Type:</Text>
|
|
|
|
<View style={styles.keyType}>
|
|
|
|
<TouchableOpacity style={styles.optionLeft} activeOpacity={1}
|
|
|
|
onPress={() => actions.setKeyType('RSA2048')}>
|
|
|
|
{ state.keyType === 'RSA2048' && (
|
|
|
|
<View style={styles.selected} />
|
|
|
|
)}
|
|
|
|
{ state.keyType === 'RSA4096' && (
|
|
|
|
<View style={styles.radio} />
|
|
|
|
)}
|
|
|
|
<Text style={styles.option}>RSA 2048</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
<TouchableOpacity style={styles.optionRight} activeOpacity={1}
|
|
|
|
onPress={() => actions.setKeyType('RSA4096')}>
|
|
|
|
{ state.keyType === 'RSA2048' && (
|
|
|
|
<View style={styles.radio} />
|
|
|
|
)}
|
|
|
|
{ state.keyType === 'RSA4096' && (
|
|
|
|
<View style={styles.selected} />
|
|
|
|
)}
|
|
|
|
<Text style={styles.option}>RSA 4096</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
<TouchableOpacity style={styles.media} activeOpacity={1}
|
|
|
|
onPress={() => actions.setEnableImage(!state.enableImage)}>
|
|
|
|
<Text style={styles.modalLabel}>Enable Image Queue: </Text>
|
|
|
|
<Switch style={styles.switch} value={state.enableImage}
|
|
|
|
onValueChange={actions.setEnableImage} trackColor={styles.track}/>
|
|
|
|
</TouchableOpacity>
|
|
|
|
<TouchableOpacity style={styles.media} activeOpacity={1}
|
|
|
|
onPress={() => actions.setEnableAudio(!state.enableAudio)}>
|
|
|
|
<Text style={styles.modalLabel}>Enable Audio Queue: </Text>
|
|
|
|
<Switch style={styles.switch} value={state.enableAudio}
|
|
|
|
onValueChange={actions.setEnableAudio} trackColor={styles.track}/>
|
|
|
|
</TouchableOpacity>
|
|
|
|
<TouchableOpacity style={styles.media} activeOpacity={1}
|
|
|
|
onPress={() => actions.setEnableVideo(!state.enableVideo)}>
|
|
|
|
<Text style={styles.modalLabel}>Enable Video Queue: </Text>
|
|
|
|
<Switch style={styles.switch} value={state.enableVideo}
|
|
|
|
onValueChange={actions.setEnableVideo} trackColor={styles.track}/>
|
|
|
|
</TouchableOpacity>
|
2022-10-13 22:21:40 +00:00
|
|
|
</View>
|
|
|
|
<View style={styles.modalControls}>
|
|
|
|
<TouchableOpacity style={styles.cancel} onPress={actions.hideEditConfig}>
|
|
|
|
<Text>Cancel</Text>
|
|
|
|
</TouchableOpacity>
|
2022-10-14 06:20:51 +00:00
|
|
|
<TouchableOpacity style={styles.save} onPress={saveConfig}>
|
2022-10-13 22:21:40 +00:00
|
|
|
<Text style={styles.saveText}>Save</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</KeyboardAvoidingView>
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
<Modal
|
|
|
|
animationType="fade"
|
|
|
|
transparent={true}
|
|
|
|
visible={state.addUser}
|
|
|
|
supportedOrientations={['portrait', 'landscape']}
|
|
|
|
onRequestClose={actions.hideAddUser}
|
|
|
|
>
|
|
|
|
<KeyboardAvoidingView behavior="height" style={styles.modalBackground}>
|
|
|
|
<View style={styles.modalContainer}>
|
|
|
|
<Text style={styles.modalHeader}>Add User:</Text>
|
|
|
|
<View style={styles.modalControls}>
|
|
|
|
<TouchableOpacity style={styles.cancel} onPress={actions.hideAddUser}>
|
|
|
|
<Text>Done</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</KeyboardAvoidingView>
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
<Modal
|
|
|
|
animationType="fade"
|
|
|
|
transparent={true}
|
|
|
|
visible={state.accessUser}
|
|
|
|
supportedOrientations={['portrait', 'landscape']}
|
|
|
|
onRequestClose={actions.hideAccessUser}
|
|
|
|
>
|
|
|
|
<KeyboardAvoidingView behavior="height" style={styles.modalBackground}>
|
|
|
|
<View style={styles.modalContainer}>
|
|
|
|
<Text style={styles.modalHeader}>Access User:</Text>
|
|
|
|
<View style={styles.modalControls}>
|
|
|
|
<TouchableOpacity style={styles.cancel} onPress={actions.hideAccessUser}>
|
|
|
|
<Text>Done</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</KeyboardAvoidingView>
|
|
|
|
</Modal>
|
|
|
|
|
2022-10-13 07:03:10 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
)
|
2022-09-13 22:15:49 +00:00
|
|
|
}
|
2022-10-12 19:24:29 +00:00
|
|
|
|