feat: fix new user null bug and text input bug (#31)

This commit is contained in:
IZUMI-Zu 2024-10-27 10:39:19 +08:00 committed by GitHub
parent 4fef2a2e30
commit ea4f542b0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 125 additions and 92 deletions

47
App.js
View File

@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import * as React from "react"; import React from "react";
import {Lato_700Bold, useFonts} from "@expo-google-fonts/lato";
import {Roboto_500Medium} from "@expo-google-fonts/roboto";
import {NavigationContainer} from "@react-navigation/native"; import {NavigationContainer} from "@react-navigation/native";
import {PaperProvider} from "react-native-paper"; import {PaperProvider} from "react-native-paper";
import {SafeAreaView, Text} from "react-native"; import {SafeAreaView, Text} from "react-native";
@ -29,6 +31,11 @@ import migrations from "./drizzle/migrations";
const App = () => { const App = () => {
const {success, error} = useMigrations(db, migrations); const {success, error} = useMigrations(db, migrations);
const [fontsLoaded] = useFonts({
Lato_700Bold,
Roboto_500Medium,
});
const {NotificationsProvider} = createNotifications({ const {NotificationsProvider} = createNotifications({
duration: 800, duration: 800,
notificationPosition: "top", notificationPosition: "top",
@ -53,25 +60,27 @@ const App = () => {
); );
} }
if (!success) { if (!success || !fontsLoaded) {
return ( return (
<ContentLoader <SafeAreaView style={{flex: 1, justifyContent: "center", alignItems: "center"}}>
speed={2} <ContentLoader
width={400} speed={2}
height={150} width={300}
viewBox="0 0 400 150" height={150}
backgroundColor="#f3f3f3" viewBox="0 0 300 150"
foregroundColor="#ecebeb" backgroundColor="#f3f3f3"
> foregroundColor="#ecebeb"
<Circle cx="10" cy="20" r="8" /> >
<Rect x="25" y="15" rx="5" ry="5" width="220" height="10" /> <Circle cx="10" cy="20" r="8" />
<Circle cx="10" cy="50" r="8" /> <Rect x="25" y="15" rx="5" ry="5" width="220" height="10" />
<Rect x="25" y="45" rx="5" ry="5" width="220" height="10" /> <Circle cx="10" cy="50" r="8" />
<Circle cx="10" cy="80" r="8" /> <Rect x="25" y="45" rx="5" ry="5" width="220" height="10" />
<Rect x="25" y="75" rx="5" ry="5" width="220" height="10" /> <Circle cx="10" cy="80" r="8" />
<Circle cx="10" cy="110" r="8" /> <Rect x="25" y="75" rx="5" ry="5" width="220" height="10" />
<Rect x="25" y="105" rx="5" ry="5" width="220" height="10" /> <Circle cx="10" cy="110" r="8" />
</ContentLoader> <Rect x="25" y="105" rx="5" ry="5" width="220" height="10" />
</ContentLoader>
</SafeAreaView>
); );
} }

View File

@ -127,6 +127,7 @@ function CasdoorLoginPage({onWebviewClose, initialMethod}) {
<EnterCasdoorSdkConfig <EnterCasdoorSdkConfig
onClose={() => handleLogin(initialMethod)} onClose={() => handleLogin(initialMethod)}
onWebviewClose={onWebviewClose} onWebviewClose={onWebviewClose}
usePortal={false}
/> />
), ),
scanner: ( scanner: (

View File

@ -19,7 +19,7 @@ import {useNotifications} from "react-native-notificated";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import useStore from "./useStorage"; import useStore from "./useStorage";
function EnterCasdoorSdkConfig({onClose, onWebviewClose}) { function EnterCasdoorSdkConfig({onClose, onWebviewClose, usePortal = true}) {
const { const {
serverUrl, serverUrl,
clientId, clientId,
@ -52,72 +52,73 @@ function EnterCasdoorSdkConfig({onClose, onWebviewClose}) {
onClose(); onClose();
}; };
return ( const content = (
<Portal> <View style={styles.container}>
<View style={styles.container}> <View style={styles.content}>
<View style={styles.content}> <Text style={styles.title}>Casdoor Configuration</Text>
<Text style={styles.title}>Casdoor Configuration</Text> <View style={styles.formContainer}>
<View style={styles.formContainer}> <TextInput
<TextInput label="Endpoint"
label="Endpoint" value={serverUrl}
value={serverUrl} onChangeText={setServerUrl}
onChangeText={setServerUrl} autoCapitalize="none"
autoCapitalize="none" style={styles.input}
style={styles.input} mode="outlined"
mode="outlined" />
/> <TextInput
<TextInput label="Client ID"
label="Client ID" value={clientId}
value={clientId} onChangeText={setClientId}
onChangeText={setClientId} autoCapitalize="none"
autoCapitalize="none" style={styles.input}
style={styles.input} mode="outlined"
mode="outlined" />
/> <TextInput
<TextInput label="App Name"
label="App Name" value={appName}
value={appName} onChangeText={setAppName}
onChangeText={setAppName} autoCapitalize="none"
autoCapitalize="none" style={styles.input}
style={styles.input} mode="outlined"
mode="outlined" />
/> <TextInput
<TextInput label="Organization Name"
label="Organization Name" value={organizationName}
value={organizationName} onChangeText={setOrganizationName}
onChangeText={setOrganizationName} autoCapitalize="none"
autoCapitalize="none" style={styles.input}
style={styles.input} mode="outlined"
mode="outlined" />
/> </View>
</View> <View style={styles.buttonContainer}>
<View style={styles.buttonContainer}> <Button
<Button mode="outlined"
mode="outlined" onPress={closeConfigPage}
onPress={closeConfigPage} style={styles.button}
style={styles.button} labelStyle={styles.buttonLabel}
labelStyle={styles.buttonLabel} >
> Cancel
Cancel </Button>
</Button> <Button
<Button mode="contained"
mode="contained" onPress={handleSave}
onPress={handleSave} style={styles.button}
style={styles.button} labelStyle={styles.buttonLabel}
labelStyle={styles.buttonLabel} >
> Confirm
Confirm </Button>
</Button>
</View>
</View> </View>
</View> </View>
</Portal> </View>
); );
return usePortal ? <Portal>{content}</Portal> : content;
} }
EnterCasdoorSdkConfig.propTypes = { EnterCasdoorSdkConfig.propTypes = {
onClose: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired,
onWebviewClose: PropTypes.func.isRequired, onWebviewClose: PropTypes.func.isRequired,
usePortal: PropTypes.bool,
}; };
const styles = StyleSheet.create({ const styles = StyleSheet.create({
@ -142,7 +143,7 @@ const styles = StyleSheet.create({
title: { title: {
fontSize: 20, fontSize: 20,
fontWeight: "bold", fontWeight: "bold",
fontFamily: "Lato-Bold", fontFamily: "Lato_700Bold",
color: "#212121", color: "#212121",
textAlign: "center", textAlign: "center",
marginBottom: 16, marginBottom: 16,

View File

@ -159,7 +159,7 @@ const styles = StyleSheet.create({
fontSize: Math.max(24, width * 0.05), fontSize: Math.max(24, width * 0.05),
fontWeight: "bold", fontWeight: "bold",
color: "#212121", color: "#212121",
fontFamily: "Lato-Bold", fontFamily: "Lato_700Bold",
}, },
buttonContainer: { buttonContainer: {
borderRadius: 24, borderRadius: 24,
@ -179,7 +179,7 @@ const styles = StyleSheet.create({
fontWeight: "600", fontWeight: "600",
marginLeft: 8, marginLeft: 8,
color: "#424242", color: "#424242",
fontFamily: "Roboto-Medium", fontFamily: "Roboto_500Medium",
}, },
menuContent: { menuContent: {
backgroundColor: "#FAFAFA", backgroundColor: "#FAFAFA",

5
api.js
View File

@ -38,7 +38,10 @@ export const getMfaAccounts = async(serverUrl, owner, name, token, timeoutMs = T
throw new Error(res.msg); throw new Error(res.msg);
} }
return {updatedTime: res.data.updatedTime, mfaAccounts: res.data.mfaAccounts}; return {
updatedTime: res.data.updatedTime,
mfaAccounts: res.data.mfaAccounts || [],
};
} catch (error) { } catch (error) {
if (error.name === "AbortError") { if (error.name === "AbortError") {
throw new Error("Request timed out"); throw new Error("Request timed out");

View File

@ -50,7 +50,8 @@
"photosPermission": "The app accesses your photos to add Totp account." "photosPermission": "The app accesses your photos to add Totp account."
} }
], ],
"expo-asset" "expo-asset",
"expo-font"
], ],
"owner": "casdoor" "owner": "casdoor"
} }

31
package-lock.json generated
View File

@ -8,6 +8,8 @@
"name": "casdoor-app", "name": "casdoor-app",
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "dependencies": {
"@expo-google-fonts/lato": "^0.2.3",
"@expo-google-fonts/roboto": "^0.2.3",
"@expo/react-native-action-sheet": "^4.1.0", "@expo/react-native-action-sheet": "^4.1.0",
"@react-native-async-storage/async-storage": "1.23.1", "@react-native-async-storage/async-storage": "1.23.1",
"@react-native-community/masked-view": "^0.1.11", "@react-native-community/masked-view": "^0.1.11",
@ -19,13 +21,14 @@
"casdoor-react-native-sdk": "1.1.0", "casdoor-react-native-sdk": "1.1.0",
"drizzle-orm": "^0.33.0", "drizzle-orm": "^0.33.0",
"eslint-plugin-import": "^2.28.1", "eslint-plugin-import": "^2.28.1",
"expo": "~51.0.37", "expo": "~51.0.38",
"expo-asset": "~10.0.10", "expo-asset": "~10.0.10",
"expo-camera": "~15.0.16", "expo-camera": "~15.0.16",
"expo-crypto": "~13.0.2", "expo-crypto": "~13.0.2",
"expo-dev-client": "~4.0.28", "expo-dev-client": "~4.0.28",
"expo-document-picker": "~12.0.2", "expo-document-picker": "~12.0.2",
"expo-drizzle-studio-plugin": "^0.0.2", "expo-drizzle-studio-plugin": "^0.0.2",
"expo-font": "~12.0.10",
"expo-image": "~1.13.0", "expo-image": "~1.13.0",
"expo-image-picker": "~15.0.7", "expo-image-picker": "~15.0.7",
"expo-sqlite": "^14.0.6", "expo-sqlite": "^14.0.6",
@ -3112,6 +3115,18 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/@expo-google-fonts/lato": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.com/@expo-google-fonts/lato/-/lato-0.2.3.tgz",
"integrity": "sha512-X56FEZn2GNYtI2/UqyOps7TShuDwi/k9JKa7VzM0x2ywBOnhTtXGq2IsZyNPzT9KnQA/ID84F9yiMS8e3obu0g==",
"license": "MIT"
},
"node_modules/@expo-google-fonts/roboto": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.com/@expo-google-fonts/roboto/-/roboto-0.2.3.tgz",
"integrity": "sha512-PF6S//ZYWeXfpYTwvY2oEe0d5RnqwR5KMsGjuTgg6y9p/CPK/IkWL+wsbkzjfd+Jck1Q1pRlWOoe5uz42sQFRg==",
"license": "MIT"
},
"node_modules/@expo/bunyan": { "node_modules/@expo/bunyan": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://registry.npmjs.com/@expo/bunyan/-/bunyan-4.0.1.tgz", "resolved": "https://registry.npmjs.com/@expo/bunyan/-/bunyan-4.0.1.tgz",
@ -11260,9 +11275,9 @@
} }
}, },
"node_modules/expo": { "node_modules/expo": {
"version": "51.0.37", "version": "51.0.38",
"resolved": "https://registry.npmjs.com/expo/-/expo-51.0.37.tgz", "resolved": "https://registry.npmjs.com/expo/-/expo-51.0.38.tgz",
"integrity": "sha512-zMdfTiGNgNWG0HOOFA3zRreS94iQ7fDxxgEIR6wdQCbncTpbeYj+5mscTAlHE9JJ+oBkcNyJXrLSjE/YVbFERg==", "integrity": "sha512-/B9npFkOPmv6WMIhdjQXEY0Z9k/67UZIVkodW8JxGIXwKUZAGHL+z1R5hTtWimpIrvVhyHUFU3f8uhfEKYhHNQ==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.20.0", "@babel/runtime": "^7.20.0",
@ -11277,7 +11292,7 @@
"expo-font": "~12.0.10", "expo-font": "~12.0.10",
"expo-keep-awake": "~13.0.2", "expo-keep-awake": "~13.0.2",
"expo-modules-autolinking": "1.11.3", "expo-modules-autolinking": "1.11.3",
"expo-modules-core": "1.12.25", "expo-modules-core": "1.12.26",
"fbemitter": "^3.0.0", "fbemitter": "^3.0.0",
"whatwg-url-without-unicode": "8.0.0-3" "whatwg-url-without-unicode": "8.0.0-3"
}, },
@ -11667,9 +11682,9 @@
} }
}, },
"node_modules/expo-modules-core": { "node_modules/expo-modules-core": {
"version": "1.12.25", "version": "1.12.26",
"resolved": "https://registry.npmjs.com/expo-modules-core/-/expo-modules-core-1.12.25.tgz", "resolved": "https://registry.npmjs.com/expo-modules-core/-/expo-modules-core-1.12.26.tgz",
"integrity": "sha512-HB2LS2LEM41Xq1bG+Jtzqm6XgPaa+mM9BAvCdX1lDGMQ9Ay9vMTL/GVEs2gpsINPofICopjBRwD+wftyCbVrzg==", "integrity": "sha512-y8yDWjOi+rQRdO+HY+LnUlz8qzHerUaw/LUjKPU/mX8PRXP4UUPEEp5fjAwBU44xjNmYSHWZDwet4IBBE+yQUA==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"invariant": "^2.2.4" "invariant": "^2.2.4"

View File

@ -10,6 +10,8 @@
"release": "npx -p semantic-release-expo -p semantic-release -p @semantic-release/git -p @semantic-release/changelog -p @semantic-release/exec semantic-release" "release": "npx -p semantic-release-expo -p semantic-release -p @semantic-release/git -p @semantic-release/changelog -p @semantic-release/exec semantic-release"
}, },
"dependencies": { "dependencies": {
"@expo-google-fonts/lato": "^0.2.3",
"@expo-google-fonts/roboto": "^0.2.3",
"@expo/react-native-action-sheet": "^4.1.0", "@expo/react-native-action-sheet": "^4.1.0",
"@react-native-async-storage/async-storage": "1.23.1", "@react-native-async-storage/async-storage": "1.23.1",
"@react-native-community/masked-view": "^0.1.11", "@react-native-community/masked-view": "^0.1.11",
@ -21,13 +23,14 @@
"casdoor-react-native-sdk": "1.1.0", "casdoor-react-native-sdk": "1.1.0",
"drizzle-orm": "^0.33.0", "drizzle-orm": "^0.33.0",
"eslint-plugin-import": "^2.28.1", "eslint-plugin-import": "^2.28.1",
"expo": "~51.0.37", "expo": "~51.0.38",
"expo-asset": "~10.0.10", "expo-asset": "~10.0.10",
"expo-camera": "~15.0.16", "expo-camera": "~15.0.16",
"expo-crypto": "~13.0.2", "expo-crypto": "~13.0.2",
"expo-dev-client": "~4.0.28", "expo-dev-client": "~4.0.28",
"expo-document-picker": "~12.0.2", "expo-document-picker": "~12.0.2",
"expo-drizzle-studio-plugin": "^0.0.2", "expo-drizzle-studio-plugin": "^0.0.2",
"expo-font": "~12.0.10",
"expo-image": "~1.13.0", "expo-image": "~1.13.0",
"expo-image-picker": "~15.0.7", "expo-image-picker": "~15.0.7",
"expo-sqlite": "^14.0.6", "expo-sqlite": "^14.0.6",