mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem Our `<Button>` component breaks the default `button` contract by redefining the `type` prop to set its variant (`primary`, `default`, etc) instead of the button type (`submit`, `button`, etc). This is confusing and forces to write more code when using it with shadcn components that expect/inject the standard button props. ## Solution - rename the `type` prop to `variant` - rename the `htmlType` prop to `type` - propagate the changes where necessary - format code ## How to test As this is just prop renaming, if it builds it's ok --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
104 lines
3.6 KiB
TypeScript
104 lines
3.6 KiB
TypeScript
import { LW15_TWEET_TEXT, LW15_URL } from '~/lib/constants'
|
|
import { useBreakpoint } from 'common'
|
|
import dayjs from 'dayjs'
|
|
import { Check } from 'lucide-react'
|
|
import { useTheme } from 'next-themes'
|
|
import Link from 'next/link'
|
|
import { useEffect, useRef, useState } from 'react'
|
|
import { Button } from 'ui'
|
|
|
|
import useConfData from '../hooks/use-conf-data'
|
|
import supabase from '../supabase'
|
|
|
|
export default function LW15TicketShare() {
|
|
const { resolvedTheme } = useTheme()
|
|
const [state] = useConfData()
|
|
const userData = state.userTicketData
|
|
const { username, metadata } = userData
|
|
const [_imgReady, setImgReady] = useState(false)
|
|
const [_loading, setLoading] = useState(false)
|
|
const isLessThanMd = useBreakpoint()
|
|
const downloadLink = useRef<HTMLAnchorElement | undefined>(undefined)
|
|
const link = `${LW15_URL}/tickets/${username}?lw=15&t=${dayjs(new Date()).format('DHHmmss')}`
|
|
const permalink = encodeURIComponent(link)
|
|
const text = LW15_TWEET_TEXT
|
|
const encodedText = encodeURIComponent(text)
|
|
const tweetUrl = `https://twitter.com/intent/tweet?url=${permalink}&text=${encodedText}`
|
|
const linkedInUrl = `https://www.linkedin.com/sharing/share-offsite/?url=${permalink}&text=${encodedText}`
|
|
const downloadUrl = `/api-v2/ticket-og?username=${encodeURIComponent(username ?? '')}`
|
|
const TICKETS_TABLE = 'tickets'
|
|
|
|
useEffect(() => {
|
|
setImgReady(false)
|
|
|
|
const img = new Image()
|
|
|
|
img.src = downloadUrl
|
|
img.onload = () => {
|
|
setImgReady(true)
|
|
setLoading(false)
|
|
if (downloadLink.current) {
|
|
downloadLink.current.click()
|
|
downloadLink.current = undefined
|
|
}
|
|
}
|
|
}, [downloadUrl])
|
|
|
|
const handleShare = async (social: 'twitter' | 'linkedin') => {
|
|
setTimeout(async () => {
|
|
if (social === 'twitter') {
|
|
await supabase
|
|
.from(TICKETS_TABLE)
|
|
.update({
|
|
shared_on_twitter: 'now',
|
|
metadata: { ...metadata, theme: resolvedTheme },
|
|
})
|
|
.eq('launch_week', 'lw15')
|
|
.eq('username', username)
|
|
} else if (social === 'linkedin') {
|
|
await supabase
|
|
.from(TICKETS_TABLE)
|
|
.update({
|
|
shared_on_linkedin: 'now',
|
|
metadata: { ...metadata, theme: resolvedTheme },
|
|
})
|
|
.eq('launch_week', 'lw15')
|
|
.eq('username', username)
|
|
}
|
|
|
|
if (userData.shared_on_linkedin && userData.shared_on_twitter) {
|
|
await fetch(`/api-v2/ticket-og?username=${username}&platinum=true`)
|
|
}
|
|
})
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-row flex-wrap justify-stretch w-full gap-1 pointer-events-auto">
|
|
<Button
|
|
onClick={() => handleShare('twitter')}
|
|
variant={userData.shared_on_twitter ? 'secondary' : 'default'}
|
|
icon={userData.shared_on_twitter && <Check strokeWidth={2} />}
|
|
size={isLessThanMd ? 'tiny' : 'small'}
|
|
className="px-2 lg:px-3.5 h-[28px] lg:h-[34px] flex-1 w-full"
|
|
asChild
|
|
>
|
|
<Link href={tweetUrl} target="_blank">
|
|
{userData.shared_on_twitter ? 'Shared on Twitter' : 'Share on Twitter'}
|
|
</Link>
|
|
</Button>
|
|
<Button
|
|
onClick={() => handleShare('linkedin')}
|
|
variant={userData.shared_on_linkedin ? 'secondary' : 'default'}
|
|
icon={userData.shared_on_linkedin && <Check strokeWidth={2} />}
|
|
size={isLessThanMd ? 'tiny' : 'small'}
|
|
className="px-2 lg:px-3.5 h-[28px] lg:h-[34px] flex-1 w-full"
|
|
asChild
|
|
>
|
|
<Link href={linkedInUrl} target="_blank">
|
|
{userData.shared_on_linkedin ? 'Shared on Linkedin' : 'Share on Linkedin'}
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|