import clsx from 'clsx' import { useState } from 'react' import { Col } from '../layout/col' import { Row } from '../layout/row' import { Title } from '../title' import { User } from 'common/user' import { ManalinkCardPreview, ManalinkInfo } from 'web/components/manalink-card' import { createManalink } from 'web/lib/firebase/manalinks' import { Modal } from 'web/components/layout/modal' import Textarea from 'react-expanding-textarea' import dayjs from 'dayjs' import Button from '../button' import { getManalinkUrl } from 'web/pages/links' import { DuplicateIcon } from '@heroicons/react/outline' export function CreateLinksButton(props: { user: User highlightedSlug: string setHighlightedSlug: (slug: string) => void }) { const { user, highlightedSlug, setHighlightedSlug } = props const [open, setOpen] = useState(false) return ( <> setOpen(newOpen)}> { const slug = await createManalink({ fromId: user.id, amount: newManalink.amount, expiresTime: newManalink.expiresTime, maxUses: newManalink.maxUses, message: newManalink.message, }) setHighlightedSlug(slug || '') }} /> setOpen(true)} className={clsx('whitespace-nowrap')} > Create a Manalink > ) } function CreateManalinkForm(props: { highlightedSlug: string user: User onCreate: (m: ManalinkInfo) => Promise }) { const { user, onCreate, highlightedSlug } = props const [isCreating, setIsCreating] = useState(false) const [finishedCreating, setFinishedCreating] = useState(false) const [copyPressed, setCopyPressed] = useState(false) setTimeout(() => setCopyPressed(false), 300) const [newManalink, setNewManalink] = useState({ expiresTime: null, amount: 100, maxUses: 1, uses: 0, message: '', }) return ( <> {!finishedCreating && ( { e.preventDefault() setIsCreating(true) onCreate(newManalink).finally(() => setIsCreating(false)) setFinishedCreating(true) }} > Amount setNewManalink((m) => { return { ...m, amount: parseInt(e.target.value) } }) } > Uses setNewManalink((m) => { return { ...m, maxUses: parseInt(e.target.value) } }) } > Expires in { setNewManalink((m) => { return { ...m, expiresTime: e.target.value ? dayjs(e.target.value, 'YYYY-MM-DDTHH:mm').valueOf() : null, } }) }} > Message setNewManalink((m) => { return { ...m, message: e.target.value } }) } /> Create )} {finishedCreating && ( <> {getManalinkUrl(highlightedSlug)} { navigator.clipboard.writeText(getManalinkUrl(highlightedSlug)) setCopyPressed(true) }} className="my-auto ml-2 h-5 w-5 cursor-pointer transition hover:opacity-50" /> > )} > ) }