generic copy link button
This commit is contained in:
parent
b60892fada
commit
45b883477d
|
@ -3,31 +3,35 @@ import { LinkIcon } from '@heroicons/react/outline'
|
||||||
import { Menu, Transition } from '@headlessui/react'
|
import { Menu, Transition } from '@headlessui/react'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
|
|
||||||
import { Contract } from 'common/contract'
|
|
||||||
import { copyToClipboard } from 'web/lib/util/copy'
|
import { copyToClipboard } from 'web/lib/util/copy'
|
||||||
import { contractPath } from 'web/lib/firebase/contracts'
|
|
||||||
import { ENV_CONFIG } from 'common/envs/constants'
|
|
||||||
import { ToastClipboard } from 'web/components/toast-clipboard'
|
import { ToastClipboard } from 'web/components/toast-clipboard'
|
||||||
import { track } from 'web/lib/service/analytics'
|
import { track } from 'web/lib/service/analytics'
|
||||||
|
import { Row } from './layout/row'
|
||||||
function copyContractUrl(contract: Contract) {
|
|
||||||
copyToClipboard(`https://${ENV_CONFIG.domain}${contractPath(contract)}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CopyLinkButton(props: {
|
export function CopyLinkButton(props: {
|
||||||
contract: Contract
|
url: string
|
||||||
|
displayUrl?: string
|
||||||
|
tracking?: string
|
||||||
buttonClassName?: string
|
buttonClassName?: string
|
||||||
toastClassName?: string
|
toastClassName?: string
|
||||||
}) {
|
}) {
|
||||||
const { contract, buttonClassName, toastClassName } = props
|
const { url, displayUrl, tracking, buttonClassName, toastClassName } = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<Row className="w-full">
|
||||||
|
<input
|
||||||
|
className="input input-bordered flex-1 rounded-r-none text-gray-500"
|
||||||
|
readOnly
|
||||||
|
type="text"
|
||||||
|
value={displayUrl ?? url}
|
||||||
|
/>
|
||||||
|
|
||||||
<Menu
|
<Menu
|
||||||
as="div"
|
as="div"
|
||||||
className="relative z-10 flex-shrink-0"
|
className="relative z-10 flex-shrink-0"
|
||||||
onMouseUp={() => {
|
onMouseUp={() => {
|
||||||
copyContractUrl(contract)
|
copyToClipboard(url)
|
||||||
track('copy share link')
|
track(tracking ?? 'copy share link')
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Menu.Button
|
<Menu.Button
|
||||||
|
@ -56,5 +60,6 @@ export function CopyLinkButton(props: {
|
||||||
</Menu.Items>
|
</Menu.Items>
|
||||||
</Transition>
|
</Transition>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
</Row>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { Contract, contractUrl } from 'web/lib/firebase/contracts'
|
|
||||||
|
import { ENV_CONFIG } from 'common/envs/constants'
|
||||||
|
|
||||||
|
import { Contract, contractPath, contractUrl } from 'web/lib/firebase/contracts'
|
||||||
import { CopyLinkButton } from './copy-link-button'
|
import { CopyLinkButton } from './copy-link-button'
|
||||||
import { Col } from './layout/col'
|
import { Col } from './layout/col'
|
||||||
import { Row } from './layout/row'
|
import { Row } from './layout/row'
|
||||||
|
@ -7,18 +10,15 @@ import { Row } from './layout/row'
|
||||||
export function ShareMarket(props: { contract: Contract; className?: string }) {
|
export function ShareMarket(props: { contract: Contract; className?: string }) {
|
||||||
const { contract, className } = props
|
const { contract, className } = props
|
||||||
|
|
||||||
|
const url = `https://${ENV_CONFIG.domain}${contractPath(contract)}`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className={clsx(className, 'gap-3')}>
|
<Col className={clsx(className, 'gap-3')}>
|
||||||
<div>Share your market</div>
|
<div>Share your market</div>
|
||||||
<Row className="mb-6 items-center">
|
<Row className="mb-6 items-center">
|
||||||
<input
|
|
||||||
className="input input-bordered flex-1 rounded-r-none text-gray-500"
|
|
||||||
readOnly
|
|
||||||
type="text"
|
|
||||||
value={contractUrl(contract)}
|
|
||||||
/>
|
|
||||||
<CopyLinkButton
|
<CopyLinkButton
|
||||||
contract={contract}
|
url={url}
|
||||||
|
displayUrl={contractUrl(contract)}
|
||||||
buttonClassName="btn-md rounded-l-none"
|
buttonClassName="btn-md rounded-l-none"
|
||||||
toastClassName={'-left-28 mt-1'}
|
toastClassName={'-left-28 mt-1'}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user