From a7455130921df529fbf1a8911c2b566e7d05af28 Mon Sep 17 00:00:00 2001 From: balzack Date: Sat, 10 Sep 2022 23:40:11 -0700 Subject: [PATCH] added account reset screen --- app/mobile/App.js | 1 + app/mobile/src/access/Access.jsx | 7 ++ app/mobile/src/access/create/Create.jsx | 2 +- app/mobile/src/access/login/Login.jsx | 5 + app/mobile/src/access/login/Login.styled.js | 8 +- app/mobile/src/access/login/useLogin.hook.js | 3 + app/mobile/src/access/reset/Reset.jsx | 69 +++++++++++ app/mobile/src/access/reset/Reset.styled.js | 113 +++++++++++++++++++ app/mobile/src/access/reset/useReset.hook.js | 63 +++++++++++ 9 files changed, 269 insertions(+), 2 deletions(-) create mode 100644 app/mobile/src/access/reset/Reset.jsx create mode 100644 app/mobile/src/access/reset/Reset.styled.js create mode 100644 app/mobile/src/access/reset/useReset.hook.js diff --git a/app/mobile/App.js b/app/mobile/App.js index 255464fc..2641151d 100644 --- a/app/mobile/App.js +++ b/app/mobile/App.js @@ -16,6 +16,7 @@ export default function App() { } /> } /> } /> + } /> } /> } /> diff --git a/app/mobile/src/access/Access.jsx b/app/mobile/src/access/Access.jsx index 4d854d3a..c59921f1 100644 --- a/app/mobile/src/access/Access.jsx +++ b/app/mobile/src/access/Access.jsx @@ -3,6 +3,7 @@ import { Wrapper, Container, PaddedPane, Pane, Splash } from './Access.styled'; import { useAccess } from './useAccess.hook'; import { Login } from './login/Login'; import { Create } from './create/Create'; +import { Reset } from './reset/Reset'; import logo from 'images/login.png'; export function Access({ mode }) { @@ -24,6 +25,9 @@ export function Access({ mode }) { { mode === 'create' && ( )} + { mode === 'reset' && ( + + )} )} @@ -35,6 +39,9 @@ export function Access({ mode }) { { mode === 'create' && ( )} + { mode === 'reset' && ( + + )} )} diff --git a/app/mobile/src/access/create/Create.jsx b/app/mobile/src/access/create/Create.jsx index 897b8db7..6d658333 100644 --- a/app/mobile/src/access/create/Create.jsx +++ b/app/mobile/src/access/create/Create.jsx @@ -28,7 +28,7 @@ export function Create() { - + Databag diff --git a/app/mobile/src/access/login/Login.jsx b/app/mobile/src/access/login/Login.jsx index 111913d2..58623476 100644 --- a/app/mobile/src/access/login/Login.jsx +++ b/app/mobile/src/access/login/Login.jsx @@ -76,6 +76,11 @@ export function Login() { Create Account + + + Forgot Password + + diff --git a/app/mobile/src/access/login/Login.styled.js b/app/mobile/src/access/login/Login.styled.js index 89be9d95..25795aa4 100644 --- a/app/mobile/src/access/login/Login.styled.js +++ b/app/mobile/src/access/login/Login.styled.js @@ -108,6 +108,12 @@ export const styles = StyleSheet.create({ nocreatetext: { color: Colors.disabled, }, - + bottom: { + display: 'flex', + flexGrow: 1, + alignItems: 'flex-end', + justifyContent: 'flex-end', + paddingBottom: 16, + }, }) diff --git a/app/mobile/src/access/login/useLogin.hook.js b/app/mobile/src/access/login/useLogin.hook.js index bb2dc8f6..5ec5fb8a 100644 --- a/app/mobile/src/access/login/useLogin.hook.js +++ b/app/mobile/src/access/login/useLogin.hook.js @@ -42,6 +42,9 @@ export function useLogin() { create: () => { navigate('/create'); }, + reset: () => { + navigate('/reset'); + }, showPassword: () => { updateState({ showPassword: true }); }, diff --git a/app/mobile/src/access/reset/Reset.jsx b/app/mobile/src/access/reset/Reset.jsx new file mode 100644 index 00000000..9e844147 --- /dev/null +++ b/app/mobile/src/access/reset/Reset.jsx @@ -0,0 +1,69 @@ +import { ActivityIndicator, Alert, Text, TextInput, View, TouchableOpacity } from 'react-native'; +import { styles } from './Reset.styled'; +import Ionicons from '@expo/vector-icons/AntDesign'; +import { useReset } from './useReset.hook'; + +export function Reset() { + + const { state, actions } = useReset(); + + const reset = async () => { + try { + await actions.reset(); + } + catch (err) { + Alert.alert( + "Reset Failed", + "Please check your server and token.", + ); + } + } + + return ( + + + + + + + + Databag + + Access Account + + + + + + + + + + + + + { state.enabled && ( + + { state.busy && ( + + )} + { !state.busy && ( + Access + )} + + )} + { !state.enabled && ( + + Access + + )} + + Account Login + + + + + ); +} diff --git a/app/mobile/src/access/reset/Reset.styled.js b/app/mobile/src/access/reset/Reset.styled.js new file mode 100644 index 00000000..e426ce3e --- /dev/null +++ b/app/mobile/src/access/reset/Reset.styled.js @@ -0,0 +1,113 @@ +import { StyleSheet } from 'react-native'; +import { Colors } from 'constants/Colors'; + +export const styles = StyleSheet.create({ + wrapper: { + width: '100%', + height: '100%', + }, + config: { + paddingTop: 8, + }, + icon: { + padding: 8, + }, + space: { + width: 32, + }, + container: { + flexDirection: 'column', + backgroundColor: Colors.formBackground, + borderRadius: 4, + width: '100%', + height: '100%', + display: 'flex', + paddingLeft: 16, + paddingRight: 16, + }, + control: { + display: 'flex', + flexDirection: 'row', + justifyContent: 'flex-end', + color: Colors.grey, + }, + title: { + width: '100%', + textAlign: 'center', + fontSize: 24, + color: Colors.grey, + }, + spacemid: { + flexGrow: 1, + flexDirection: 'column', + textAlign: 'center', + alignItems: 'center', + justifyContent: 'center', + width: '100%', + }, + spacetop: { + flexGrow: 1, + flexDirection: 'column', + textAlign: 'center', + alignItems: 'center', + justifyContent: 'flex-start', + width: '100%', + }, + header: { + fontSize: 32, + color: Colors.text, + }, + inputwrapper: { + display: 'flex', + flexDirection: 'row', + width: '100%', + borderRadius: 4, + borderColor: Colors.divider, + borderWidth: 1, + marginBottom: 16, + alignItems: 'center', + }, + inputfield: { + flex: 1, + textAlign: 'center', + padding: 8, + }, + reset: { + marginTop: 16, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + width: 128, + height: 28, + backgroundColor: Colors.primary, + borderRadius: 4, + }, + resettext: { + color: Colors.formFocus, + }, + noreset: { + marginTop: 16, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + width: 128, + height: 28, + borderRadius: 4, + borderColor: Colors.divider, + borderWidth: 1, + }, + noresettext: { + color: Colors.disabled, + }, + login: { + marginTop: 16, + }, + logintext: { + fontColor: 'yellow', + }, + nologintext: { + color: Colors.disabled, + }, + +}) + diff --git a/app/mobile/src/access/reset/useReset.hook.js b/app/mobile/src/access/reset/useReset.hook.js new file mode 100644 index 00000000..5b36a256 --- /dev/null +++ b/app/mobile/src/access/reset/useReset.hook.js @@ -0,0 +1,63 @@ +import { useState, useEffect, useContext } from 'react'; +import { useWindowDimensions } from 'react-native'; +import { useNavigate } from 'react-router-dom'; +import { AppContext } from 'context/AppContext'; + +export function useReset() { + + const navigate = useNavigate(); + const app = useContext(AppContext); + + const [state, setState] = useState({ + busy: false, + enabled: false, + server: null, + token: null, + }); + + const updateState = (value) => { + setState((s) => ({ ...s, ...value })); + } + + useEffect(() => { + if (state.token && state.server && !state.enabled) { + updateState({ enabled: true }); + } + if ((!state.token || !state.server) && state.enabled) { + updateState({ enabled: false }); + } + }, [state.server, state.token]); + + const actions = { + config: () => { + navigate('/admin'); + }, + setServer: (server) => { + updateState({ server }); + }, + setToken: (token) => { + updateState({ token }); + }, + login: () => { + navigate('/login'); + }, + access: async () => { + if (!state.busy) { + updateState({ busy: true }); + try { + await app.actions.login(state.login, state.password); + navigate('/'); + } + catch (err) { + console.log(err); + updateState({ busy: false, showAlert: true }); + throw new Error('login failed'); + } + updateState({ busy: false }); + } + } + }; + + return { state, actions }; +} +