From 0f6963afd637e45ef0428383ff154f2826b32113 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Fri, 9 Sep 2022 15:23:44 -0700 Subject: [PATCH] setting up create screen --- app/mobile/src/access/create/Create.jsx | 88 ++++++++++++------- app/mobile/src/access/create/Create.styled.js | 40 +++++++-- .../src/access/create/useCreate.hook.js | 37 ++++++-- 3 files changed, 115 insertions(+), 50 deletions(-) diff --git a/app/mobile/src/access/create/Create.jsx b/app/mobile/src/access/create/Create.jsx index a109127f..1b9de62e 100644 --- a/app/mobile/src/access/create/Create.jsx +++ b/app/mobile/src/access/create/Create.jsx @@ -1,4 +1,4 @@ -import { ActivityIndicator, Alert, Text, TextInput, View, TouchableOpacity } from 'react-native'; +import { ScrollView, ActivityIndicator, Alert, Text, TextInput, View, TouchableOpacity } from 'react-native'; import { styles } from './Create.styled'; import Ionicons from '@expo/vector-icons/AntDesign'; import { useCreate } from './useCreate.hook'; @@ -14,7 +14,7 @@ export function Create() { catch (err) { Alert.alert( "Create Failed", - "Please check your login and password.", + "Please check your username and password.", ); } } @@ -24,79 +24,99 @@ export function Create() { - + Databag Create Account - + - - - + + + + + + + { state.tokenRequired && ( + + + + + + )} + + + + + + { state.showPassword && ( - + - + )} { !state.showPassword && ( - + - + )} { state.showConfirm && ( - + - + )} { !state.showConfirm && ( - + - + )} - { state.enabled && ( - - { state.busy && ( - - )} - { !state.busy && ( - Create Account - )} + + { state.enabled && ( + + { state.busy && ( + + )} + { !state.busy && ( + Create Account + )} + + )} + { !state.enabled && ( + + Create + + )} + + Account Login - )} - { !state.enabled && ( - - Create - - )} - - Account Login - - + + ); diff --git a/app/mobile/src/access/create/Create.styled.js b/app/mobile/src/access/create/Create.styled.js index 4c101165..62489f09 100644 --- a/app/mobile/src/access/create/Create.styled.js +++ b/app/mobile/src/access/create/Create.styled.js @@ -14,6 +14,14 @@ export const styles = StyleSheet.create({ }, space: { width: 32, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }, + required: { + fontSize: 12, + color: Colors.alert, + textAlignVertical: 'center', }, container: { flexDirection: 'column', @@ -22,14 +30,13 @@ export const styles = StyleSheet.create({ width: '100%', height: '100%', display: 'flex', - paddingLeft: 16, - paddingRight: 16, - }, + }, control: { display: 'flex', flexDirection: 'row', justifyContent: 'flex-end', color: Colors.grey, + marginRight: 16, }, title: { width: '100%', @@ -46,12 +53,16 @@ export const styles = StyleSheet.create({ width: '100%', }, spacetop: { - flexGrow: 1, - flexDirection: 'column', - textAlign: 'center', - alignItems: 'center', - justifyContent: 'flex-start', width: '100%', + paddingLeft: 16, + paddingRight: 16, + }, + buttons: { + width: '100%', + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + justifyContent: 'center', }, header: { fontSize: 32, @@ -67,6 +78,17 @@ export const styles = StyleSheet.create({ marginBottom: 16, alignItems: 'center', }, + inputwrapperpad: { + display: 'flex', + flexDirection: 'row', + width: '100%', + borderRadius: 4, + borderColor: Colors.divider, + borderWidth: 1, + marginTop: 16, + marginBottom: 16, + alignItems: 'center', + }, inputfield: { flex: 1, textAlign: 'center', @@ -95,12 +117,14 @@ export const styles = StyleSheet.create({ borderRadius: 4, borderColor: Colors.divider, borderWidth: 1, + marginBottom: 16, }, nocreatetext: { color: Colors.disabled, }, create: { marginTop: 16, + marginBottom: 16, }, createtext: { fontColor: 'yellow', diff --git a/app/mobile/src/access/create/useCreate.hook.js b/app/mobile/src/access/create/useCreate.hook.js index 82d6d9bb..4a0f85f5 100644 --- a/app/mobile/src/access/create/useCreate.hook.js +++ b/app/mobile/src/access/create/useCreate.hook.js @@ -1,4 +1,4 @@ -import { useState, useEffect, useContext } from 'react'; +import { useState, useEffect, useContext, useRef } from 'react'; import { useWindowDimensions } from 'react-native'; import { useNavigate } from 'react-router-dom'; import { AppContext } from 'context/AppContext'; @@ -11,23 +11,38 @@ export function useCreate() { const [state, setState] = useState({ busy: false, enabled: false, - login: null, + server: null, + token: null, + username: null, password: null, confirm: null, showPassword: false, showConfirm: false, + serverCheck: true, + serverValid: false, + tokenRequired: false, + usernameCheck: true, + usernameValid: false, + }); + const debounceUsername = useRef(null); + const debounceServer = useRef(null); + const updateState = (value) => { setState((s) => ({ ...s, ...value })); } useEffect(() => { - if (state.password && state.login && !state.enabled) { - updateState({ enabled: true }); + if (state.password && state.username && state.server && state.confirm && state.password === state.confirm) { + if (!state.enabled) { + updateState({ enabled: true }); + } } - if ((!state.password || !state.login) && state.enabled) { - updateState({ enabled: false }); + else { + if (state.enabled) { + updateState({ enabled: false }); + } } }, [state.login, state.password]); @@ -35,8 +50,14 @@ export function useCreate() { config: () => { navigate('/admin'); }, - setLogin: (login) => { - updateState({ login }); + setServer: (server) => { + updateState({ server }); + }, + setToken: (token) => { + updateState({ token }); + }, + setUsername: (username) => { + updateState({ username }); }, setPassword: (password) => { updateState({ password });