-
Notifications
You must be signed in to change notification settings - Fork 4
/
EnterCasdoorSdkConfig.js
173 lines (163 loc) · 4.31 KB
/
EnterCasdoorSdkConfig.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import React from "react";
import {StyleSheet, Text, View} from "react-native";
import {Button, Portal, TextInput} from "react-native-paper";
import {useNotifications} from "react-native-notificated";
import PropTypes from "prop-types";
import useStore from "./useStorage";
function EnterCasdoorSdkConfig({onClose, onWebviewClose, usePortal = true}) {
const {
serverUrl,
clientId,
redirectPath,
appName,
organizationName,
setServerUrl,
setClientId,
setAppName,
setOrganizationName,
} = useStore();
const {notify} = useNotifications();
const closeConfigPage = () => {
onClose();
onWebviewClose();
};
const handleSave = () => {
if (!serverUrl || !clientId || !appName || !organizationName || !redirectPath) {
notify("error", {
params: {
title: "Error",
description: "Please fill in all the fields!",
},
});
return;
}
onClose();
};
const content = (
<View style={styles.container}>
<View style={styles.content}>
<Text style={styles.title}>Casdoor Configuration</Text>
<View style={styles.formContainer}>
<TextInput
label="Endpoint"
value={serverUrl}
onChangeText={setServerUrl}
autoCapitalize="none"
style={styles.input}
mode="outlined"
/>
<TextInput
label="Client ID"
value={clientId}
onChangeText={setClientId}
autoCapitalize="none"
style={styles.input}
mode="outlined"
/>
<TextInput
label="App Name"
value={appName}
onChangeText={setAppName}
autoCapitalize="none"
style={styles.input}
mode="outlined"
/>
<TextInput
label="Organization Name"
value={organizationName}
onChangeText={setOrganizationName}
autoCapitalize="none"
style={styles.input}
mode="outlined"
/>
</View>
<View style={styles.buttonContainer}>
<Button
mode="outlined"
onPress={closeConfigPage}
style={styles.button}
labelStyle={styles.buttonLabel}
>
Cancel
</Button>
<Button
mode="contained"
onPress={handleSave}
style={styles.button}
labelStyle={styles.buttonLabel}
>
Confirm
</Button>
</View>
</View>
</View>
);
return usePortal ? <Portal>{content}</Portal> : content;
}
EnterCasdoorSdkConfig.propTypes = {
onClose: PropTypes.func.isRequired,
onWebviewClose: PropTypes.func.isRequired,
usePortal: PropTypes.bool,
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "rgba(0, 0, 0, 0.5)",
},
content: {
width: "90%",
maxWidth: 400,
borderRadius: 28,
padding: 24,
backgroundColor: "#FFFFFF",
shadowColor: "#000",
shadowOffset: {width: 0, height: 2},
shadowOpacity: 0.1,
shadowRadius: 8,
elevation: 5,
},
title: {
fontSize: 20,
fontWeight: "bold",
fontFamily: "Lato_700Bold",
color: "#212121",
textAlign: "center",
marginBottom: 16,
},
buttonContainer: {
flexDirection: "row",
justifyContent: "space-between",
},
button: {
flex: 1,
marginHorizontal: 8,
borderRadius: 100,
},
buttonLabel: {
paddingVertical: 4,
fontSize: 16,
fontWeight: "bold",
},
formContainer: {
marginBottom: 8,
},
input: {
marginBottom: 16,
},
});
export default EnterCasdoorSdkConfig;