-
Notifications
You must be signed in to change notification settings - Fork 254
/
Copy pathGetStartedButton.tsx
92 lines (81 loc) · 2.16 KB
/
GetStartedButton.tsx
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
'use client'
import { usePostHog } from '@/hooks/posthog'
import { KeyboardArrowRight } from '@mui/icons-material'
import { Organization } from '@polar-sh/api'
import Button from '@polar-sh/ui/components/atoms/Button'
import { ComponentProps, FormEvent, useCallback, useMemo } from 'react'
import { twMerge } from 'tailwind-merge'
import { Modal } from '../Modal'
import { useModal } from '../Modal/useModal'
import { AuthModal } from './AuthModal'
interface GetStartedButtonProps extends ComponentProps<typeof Button> {
text?: string
orgSlug?: string
storefrontOrg?: Organization
}
const GetStartedButton: React.FC<GetStartedButtonProps> = ({
text: _text,
wrapperClassNames,
orgSlug: slug,
storefrontOrg,
size = 'lg',
...props
}) => {
const posthog = usePostHog()
const { isShown: isModalShown, hide: hideModal, show: showModal } = useModal()
const text = _text || 'Get Started'
const signup = useMemo(() => {
if (!storefrontOrg) return {}
return {
from_storefront: storefrontOrg.id,
}
}, [storefrontOrg])
const onClick = useCallback(() => {
posthog.capture('global:user:signup:click', signup)
showModal()
}, [signup, posthog, showModal])
// Supporting embedding the button in a form
const onSubmit = useCallback(
(e: FormEvent) => {
e.preventDefault()
e.stopPropagation()
onClick()
},
[onClick],
)
return (
<>
<Button
wrapperClassNames={twMerge(
'flex flex-row items-center gap-x-2',
wrapperClassNames,
)}
size={size}
onClick={onClick}
onSubmit={onSubmit}
{...props}
>
<div>{text}</div>
<KeyboardArrowRight
className={size === 'lg' ? 'text-lg' : 'text-md'}
fontSize="inherit"
/>
</Button>
<Modal
isShown={isModalShown}
hide={hideModal}
modalContent={
<AuthModal
returnParams={slug ? { slug, auto: 'true' } : {}}
signup={{
intent: 'creator',
...signup,
}}
/>
}
className="max-w-[480px]"
/>
</>
)
}
export default GetStartedButton