about summary refs log tree commit diff
path: root/src/components/dialogs/Signin.tsx
blob: d5ae98629b74114be3d76ff4817b3b75aa5c9cd9 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React from 'react'
import {View} from 'react-native'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {isNative} from '#/platform/detection'
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
import {useCloseAllActiveElements} from '#/state/util'
import {Logo} from '#/view/icons/Logo'
import {Logotype} from '#/view/icons/Logotype'
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
import {Button, ButtonText} from '#/components/Button'
import * as Dialog from '#/components/Dialog'
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
import {Text} from '#/components/Typography'

export function SigninDialog() {
  const {signinDialogControl: control} = useGlobalDialogsControlContext()
  return (
    <Dialog.Outer control={control}>
      <Dialog.Handle />
      <SigninDialogInner control={control} />
    </Dialog.Outer>
  )
}

function SigninDialogInner({}: {control: Dialog.DialogOuterProps['control']}) {
  const t = useTheme()
  const {_} = useLingui()
  const {gtMobile} = useBreakpoints()
  const {requestSwitchToAccount} = useLoggedOutViewControls()
  const closeAllActiveElements = useCloseAllActiveElements()

  const showSignIn = React.useCallback(() => {
    closeAllActiveElements()
    requestSwitchToAccount({requestedAccount: 'none'})
  }, [requestSwitchToAccount, closeAllActiveElements])

  const showCreateAccount = React.useCallback(() => {
    closeAllActiveElements()
    requestSwitchToAccount({requestedAccount: 'new'})
  }, [requestSwitchToAccount, closeAllActiveElements])

  return (
    <Dialog.ScrollableInner
      label={_(msg`Sign in to Bluesky or create a new account`)}
      style={[gtMobile ? {width: 'auto', maxWidth: 420} : a.w_full]}>
      <View style={[!isNative && a.p_2xl]}>
        <View
          style={[
            a.flex_row,
            a.align_center,
            a.justify_center,
            a.gap_sm,
            a.pb_lg,
          ]}>
          <Logo width={36} />
          <View style={{paddingTop: 6}}>
            <Logotype width={120} fill={t.atoms.text.color} />
          </View>
        </View>

        <Text
          style={[
            a.text_lg,
            a.text_center,
            t.atoms.text,
            a.pb_2xl,
            a.leading_snug,
            a.mx_auto,
            {
              maxWidth: 300,
            },
          ]}>
          <Trans>
            Sign in or create your account to join the conversation!
          </Trans>
        </Text>

        <View style={[a.flex_col, a.gap_md]}>
          <Button
            variant="solid"
            color="primary"
            size="large"
            onPress={showCreateAccount}
            label={_(msg`Create an account`)}>
            <ButtonText>
              <Trans>Create an account</Trans>
            </ButtonText>
          </Button>

          <Button
            variant="solid"
            color="secondary"
            size="large"
            onPress={showSignIn}
            label={_(msg`Sign in`)}>
            <ButtonText>
              <Trans>Sign in</Trans>
            </ButtonText>
          </Button>
        </View>

        {isNative && <View style={{height: 10}} />}
      </View>

      <Dialog.Close />
    </Dialog.ScrollableInner>
  )
}