Front: Navigation: Add key to routes + logout button on profile error
This commit is contained in:
+10
-2
@@ -18,6 +18,9 @@ import { LoadingView } from './components/Loading';
|
|||||||
import ProfileView from './views/ProfileView';
|
import ProfileView from './views/ProfileView';
|
||||||
import useColorScheme from './hooks/colorScheme';
|
import useColorScheme from './hooks/colorScheme';
|
||||||
import { Button, Center, VStack } from 'native-base';
|
import { Button, Center, VStack } from 'native-base';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { unsetAccessToken } from './state/UserSlice';
|
||||||
|
import TextButton from './components/TextButton';
|
||||||
|
|
||||||
|
|
||||||
const protectedRoutes = () => ({
|
const protectedRoutes = () => ({
|
||||||
@@ -59,8 +62,9 @@ const RouteToScreen = <T extends {}, >(component: Route<T>['component']) => (pro
|
|||||||
</>
|
</>
|
||||||
|
|
||||||
const routesToScreens = (routes: Partial<Record<keyof AppRouteParams, Route>>) => Object.entries(routes)
|
const routesToScreens = (routes: Partial<Record<keyof AppRouteParams, Route>>) => Object.entries(routes)
|
||||||
.map(([name, route]) => (
|
.map(([name, route], routeIndex) => (
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
|
key={'route-' + routeIndex}
|
||||||
name={name as keyof AppRouteParams}
|
name={name as keyof AppRouteParams}
|
||||||
options={route.options}
|
options={route.options}
|
||||||
component={RouteToScreen(route.component)}
|
component={RouteToScreen(route.component)}
|
||||||
@@ -68,11 +72,15 @@ const routesToScreens = (routes: Partial<Record<keyof AppRouteParams, Route>>) =
|
|||||||
))
|
))
|
||||||
|
|
||||||
const ProfileErrorView = (props: { onTryAgain: () => any }) => {
|
const ProfileErrorView = (props: { onTryAgain: () => any }) => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
return <Center style={{ flexGrow: 1 }}>
|
return <Center style={{ flexGrow: 1 }}>
|
||||||
<VStack space={3}>
|
<VStack space={3}>
|
||||||
<Translate translationKey='userProfileFetchError'/>
|
<Translate translationKey='userProfileFetchError'/>
|
||||||
<Button onPress={props.onTryAgain}><Translate translationKey='tryAgain'/></Button>
|
<Button onPress={props.onTryAgain}><Translate translationKey='tryAgain'/></Button>
|
||||||
|
<TextButton onPress={() => dispatch(unsetAccessToken())}
|
||||||
|
colorScheme="error" variant='outline'
|
||||||
|
translate={{ translationKey: 'signOutBtn' }}
|
||||||
|
/>
|
||||||
</VStack>
|
</VStack>
|
||||||
</Center>
|
</Center>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user