about summary refs log tree commit diff
path: root/src/components/forms/HostingProvider.tsx
blob: 80660b5804fe5b60be785e54cbe122b1b575b636 (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
import React from 'react'
import {TouchableOpacity, View} from 'react-native'

import {isAndroid} from '#/platform/detection'
import {atoms as a, useTheme} from '#/alf'
import {Globe_Stroke2_Corner0_Rounded as Globe} from '#/components/icons/Globe'
import {PencilLine_Stroke2_Corner0_Rounded as Pencil} from '#/components/icons/Pencil'
import {useDialogControl} from '../Dialog'
import {Text} from '../Typography'
import {ServerInputDialog} from '#/view/com/auth/server-input'
import {toNiceDomain} from '#/lib/strings/url-helpers'

export function HostingProvider({
  serviceUrl,
  onSelectServiceUrl,
  onOpenDialog,
}: {
  serviceUrl: string
  onSelectServiceUrl: (provider: string) => void
  onOpenDialog?: () => void
}) {
  const serverInputControl = useDialogControl()
  const t = useTheme()

  const onPressSelectService = React.useCallback(() => {
    serverInputControl.open()
    if (onOpenDialog) {
      onOpenDialog()
    }
  }, [onOpenDialog, serverInputControl])

  return (
    <>
      <ServerInputDialog
        control={serverInputControl}
        onSelect={onSelectServiceUrl}
      />
      <TouchableOpacity
        accessibilityRole="button"
        style={[
          a.w_full,
          a.flex_row,
          a.align_center,
          a.rounded_sm,
          a.px_md,
          a.gap_xs,
          {paddingVertical: isAndroid ? 14 : 9},
          t.atoms.bg_contrast_25,
        ]}
        onPress={onPressSelectService}>
        <View style={a.pr_xs}>
          <Globe size="md" fill={t.palette.contrast_500} />
        </View>
        <Text style={[a.text_md]}>{toNiceDomain(serviceUrl)}</Text>
        <View
          style={[
            a.rounded_sm,
            t.atoms.bg_contrast_100,
            {marginLeft: 'auto', left: 6, padding: 6},
          ]}>
          <Pencil size="sm" style={{color: t.palette.contrast_500}} />
        </View>
      </TouchableOpacity>
    </>
  )
}