From c2d89b9831b9f5e6060a32c7df25576a3916d568 Mon Sep 17 00:00:00 2001
From: Fred Shema <51389166+fredshema@users.noreply.github.com>
Date: Mon, 7 Oct 2024 15:54:52 +0200
Subject: [PATCH] ch(#44): add redirect handler (#47)
fix: login labels
---
__tests__/components/sidebar.test.tsx | 7 +-
app/(onboarding)/index.tsx | 5 +-
app/+not-found.tsx | 44 +-
app/_layout.tsx | 16 +-
app/auth/register.tsx | 19 +-
app/dashboard/_layout.tsx | 39 +-
app/dashboard/index.tsx | 4 +-
app/redirect.tsx | 51 +
assets/Icons/auth/Icons.tsx | 1 -
assets/Icons/dashboard/Icons.tsx | 61 +-
assets/images/page_not_found.svg | 1 +
components/Login/UserLogin.tsx | 22 +-
components/sidebar.tsx | 83 +-
package-lock.json | 4482 +------------------------
package.json | 10 +-
15 files changed, 346 insertions(+), 4499 deletions(-)
create mode 100644 app/redirect.tsx
create mode 100644 assets/images/page_not_found.svg
diff --git a/__tests__/components/sidebar.test.tsx b/__tests__/components/sidebar.test.tsx
index 51fb453..812b1bf 100644
--- a/__tests__/components/sidebar.test.tsx
+++ b/__tests__/components/sidebar.test.tsx
@@ -41,7 +41,7 @@ describe('Sidebar', () => {
const attendanceItem = getByText('Attendance').parent;
expect(attendanceItem?.props.style).toEqual(
expect.objectContaining({
- backgroundColor: expect.stringContaining('indigo')
+ backgroundColor: expect.stringContaining('indigo'),
})
);
});
@@ -56,11 +56,10 @@ describe('Sidebar', () => {
it('navigates and closes sidebar when an item is pressed', async () => {
const { getByText } = render();
fireEvent.press(getByText('Attendance'));
-
+
await waitFor(() => {
expect(mockPush).toHaveBeenCalledWith('/dashboard/trainee');
expect(mockOnClose).toHaveBeenCalled();
});
});
-
-});
\ No newline at end of file
+});
diff --git a/app/(onboarding)/index.tsx b/app/(onboarding)/index.tsx
index 1e85703..91e2015 100644
--- a/app/(onboarding)/index.tsx
+++ b/app/(onboarding)/index.tsx
@@ -79,7 +79,10 @@ export default function AppOnboarding() {
- router.push('/auth/login')}>
+ router.push('/redirect?path=/auth/login&dest=app')}
+ >
Get Started
diff --git a/app/+not-found.tsx b/app/+not-found.tsx
index b1661a0..89a2f81 100644
--- a/app/+not-found.tsx
+++ b/app/+not-found.tsx
@@ -1,40 +1,30 @@
import { Link } from 'expo-router';
-import { StyleSheet } from 'react-native';
import { Text, View } from '@/components/Themed';
-import React from 'react';
+import { Image } from 'expo-image';
export default function NotFoundScreen() {
return (
<>
-
- This screen doesn't exist.
+
+
+
+
+
+ Oops! We can't find the page you're looking for.
+
-
- Go to home screen!
+
+
+ Go to home screen!
+
>
);
}
-
-const styles = StyleSheet.create({
- container: {
- flex: 1,
- alignItems: 'center',
- justifyContent: 'center',
- padding: 20,
- },
- title: {
- fontSize: 20,
- fontWeight: 'bold',
- },
- link: {
- marginTop: 15,
- paddingVertical: 15,
- },
- linkText: {
- fontSize: 14,
- color: '#2e78b7',
- },
-});
diff --git a/app/_layout.tsx b/app/_layout.tsx
index 79c5032..224cbea 100644
--- a/app/_layout.tsx
+++ b/app/_layout.tsx
@@ -57,14 +57,14 @@ function RootLayoutNav() {
return (
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
);
diff --git a/app/auth/register.tsx b/app/auth/register.tsx
index 98a55b1..5c86f94 100644
--- a/app/auth/register.tsx
+++ b/app/auth/register.tsx
@@ -16,11 +16,11 @@ import {
ActivityIndicator,
Alert,
TextInput,
- ToastAndroid,
TouchableOpacity,
useColorScheme,
} from 'react-native';
import { SvgXml } from 'react-native-svg';
+import { useToast } from 'react-native-toast-notifications';
type FormValues = {
firstName: string;
@@ -44,6 +44,7 @@ type RegisterResponse = {
export default function RegisterForm() {
const router = useRouter();
+ const toast = useToast();
const params = useLocalSearchParams();
const colorScheme = useColorScheme();
@@ -69,7 +70,9 @@ export default function RegisterForm() {
} else {
router.push('/dashboard/trainee');
}
- } catch (err) {}
+ } catch (err) {
+ toast.show('Invalid token or expired token', { type: 'danger' });
+ }
}
};
@@ -94,19 +97,19 @@ export default function RegisterForm() {
});
if (data) {
- ToastAndroid.show('Successfully registered', ToastAndroid.LONG);
+ toast.show('Successfully registered', { type: 'success' });
await AsyncStorage.setItem('org_token', data.createUser.token);
router.push('/auth/login');
}
if (errors) {
- ToastAndroid.show(errors[0].message, ToastAndroid.LONG);
+ toast.show(errors[0].message, { type: 'danger' });
}
} catch (error) {
if (error instanceof ApolloError) {
- ToastAndroid.show(`Error: ${error.message}`, ToastAndroid.LONG);
+ toast.show(`Error: ${error.message}`, { type: 'danger' });
} else {
- ToastAndroid.show(`Error: Unknown error`, ToastAndroid.LONG);
+ toast.show(`Error: Unknown error`, { type: 'danger' });
}
}
setLoading(false);
@@ -121,7 +124,9 @@ export default function RegisterForm() {
setEmail(parsedToken.email);
setOrgName(parsedToken.name);
}
- } catch (err) {}
+ } catch (err) {
+ toast.show('Invalid token or expired token', { type: 'danger' });
+ }
}, []);
return (
diff --git a/app/dashboard/_layout.tsx b/app/dashboard/_layout.tsx
index 3b9ba21..c0970e2 100644
--- a/app/dashboard/_layout.tsx
+++ b/app/dashboard/_layout.tsx
@@ -1,7 +1,21 @@
-import { lightLogoIcon, darkLogoIcon, menu, lightNotifyIcon, darkNotifyIcon } from '@/assets/Icons/dashboard/Icons';
+import {
+ lightLogoIcon,
+ darkLogoIcon,
+ menu,
+ lightNotifyIcon,
+ darkNotifyIcon,
+} from '@/assets/Icons/dashboard/Icons';
import { Slot } from 'expo-router';
import { useEffect, useState } from 'react';
-import { KeyboardAvoidingView, Platform, ScrollView, TouchableOpacity, View, useColorScheme, Image } from 'react-native';
+import {
+ KeyboardAvoidingView,
+ Platform,
+ ScrollView,
+ TouchableOpacity,
+ View,
+ useColorScheme,
+ Image,
+} from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { SvgXml } from 'react-native-svg';
import Sidebar from '@/components/sidebar';
@@ -13,7 +27,6 @@ export default function AuthLayout() {
const toggleSidebar = () => setIsSidebarOpen(!isSidebarOpen);
-
return (
-
+
-
@@ -67,9 +80,7 @@ export default function AuthLayout() {
{isSidebarOpen && (
-
+
)}
diff --git a/app/dashboard/index.tsx b/app/dashboard/index.tsx
index 2b75fa1..7e72fd6 100644
--- a/app/dashboard/index.tsx
+++ b/app/dashboard/index.tsx
@@ -6,7 +6,9 @@ const Dashboard = () => {
const colorScheme = useColorScheme();
return (
- Dashboard Coming soon
+
+ Dashboard Coming soon
+
);
};
diff --git a/app/redirect.tsx b/app/redirect.tsx
new file mode 100644
index 0000000..c1aa4cb
--- /dev/null
+++ b/app/redirect.tsx
@@ -0,0 +1,51 @@
+import { Text, View } from '@/components/Themed';
+import { Href, Link, useLocalSearchParams, useRouter } from 'expo-router';
+import { useEffect } from 'react';
+import { Linking } from 'react-native';
+import { useToast } from 'react-native-toast-notifications';
+
+type RedirectParams = {
+ path: string;
+ dest: 'app' | 'web';
+};
+
+export default function Redirect() {
+ const router = useRouter();
+ const toast = useToast();
+ const { path, dest } = useLocalSearchParams();
+
+ useEffect(() => {
+ (async () => {
+ if (!path) {
+ router.replace('/');
+ return;
+ }
+
+ if (dest === 'web') {
+ try {
+ const url = path.startsWith('http') ? path : `https://${path}`;
+ await Linking.openURL(url);
+ } catch (error) {
+ toast.show('Unable to open link', {
+ type: 'danger',
+ duration: 5000,
+ placement: 'top',
+ });
+ }
+ } else {
+ router.replace(path as Href);
+ }
+ })();
+ }, [path, dest]);
+
+ return (
+
+ Redirecting...
+
+
+ Go to home screen!
+
+
+
+ );
+}
diff --git a/assets/Icons/auth/Icons.tsx b/assets/Icons/auth/Icons.tsx
index f58f39c..f76b35d 100644
--- a/assets/Icons/auth/Icons.tsx
+++ b/assets/Icons/auth/Icons.tsx
@@ -357,4 +357,3 @@ export const DarkBottomIcon = `
`;
-
diff --git a/assets/Icons/dashboard/Icons.tsx b/assets/Icons/dashboard/Icons.tsx
index e845ba1..898b561 100644
--- a/assets/Icons/dashboard/Icons.tsx
+++ b/assets/Icons/dashboard/Icons.tsx
@@ -4,14 +4,14 @@ export const lightLogoIcon = `
-`
-export const darkLogoIcon =`