about summary refs log tree commit diff
path: root/src/view/screens/NotFound.tsx
blob: 6ab37f11763b06ab027c72ec720f878f607b10f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from 'react'
import {StyleSheet, View} from 'react-native'
import {useNavigation, StackActions} from '@react-navigation/native'
import {ViewHeader} from '../com/util/ViewHeader'
import {Text} from '../com/util/text/Text'
import {Button} from 'view/com/util/forms/Button'
import {NavigationProp} from 'lib/routes/types'
import {usePalette} from 'lib/hooks/usePalette'
import {s} from 'lib/styles'

export const NotFoundScreen = () => {
  const pal = usePalette('default')
  const navigation = useNavigation<NavigationProp>()

  const canGoBack = navigation.canGoBack()
  const onPressHome = React.useCallback(() => {
    if (canGoBack) {
      navigation.goBack()
    } else {
      navigation.navigate('HomeTab')
      navigation.dispatch(StackActions.popToTop())
    }
  }, [navigation, canGoBack])

  return (
    <View testID="notFoundView" style={pal.view}>
      <ViewHeader title="Page not found" />
      <View style={styles.container}>
        <Text type="title-2xl" style={[pal.text, s.mb10]}>
          Page not found
        </Text>
        <Text type="md" style={[pal.text, s.mb10]}>
          We're sorry! We can't find the page you were looking for.
        </Text>
        <Button
          type="primary"
          label={canGoBack ? 'Go back' : 'Go home'}
          onPress={onPressHome}
        />
      </View>
    </View>
  )
}

const styles = StyleSheet.create({
  container: {
    paddingTop: 100,
    paddingHorizontal: 20,
    alignItems: 'center',
    height: '100%',
  },
})