mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
feat: add dropdown to tweet or copy signing link
This commit is contained in:
@ -2,10 +2,16 @@
|
||||
|
||||
import { HTMLAttributes } from 'react';
|
||||
|
||||
import { Share } from 'lucide-react';
|
||||
import { Copy, Share, Twitter } from 'lucide-react';
|
||||
|
||||
import { trpc } from '@documenso/trpc/react';
|
||||
import { Button } from '@documenso/ui/primitives/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@documenso/ui/primitives/dropdown-menu';
|
||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||
|
||||
import { useCopyToClipboard } from '~/hooks/use-copy-to-clipboard';
|
||||
@ -15,6 +21,12 @@ export type ShareButtonProps = HTMLAttributes<HTMLButtonElement> & {
|
||||
documentId: number;
|
||||
};
|
||||
|
||||
const generateTwitterIntent = (text: string, shareUrl: string) => {
|
||||
return `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}%0A${encodeURIComponent(
|
||||
shareUrl,
|
||||
)}`;
|
||||
};
|
||||
|
||||
export const ShareButton = ({ token, documentId }: ShareButtonProps) => {
|
||||
const { toast } = useToast();
|
||||
const [, copyToClipboard] = useCopyToClipboard();
|
||||
@ -22,7 +34,7 @@ export const ShareButton = ({ token, documentId }: ShareButtonProps) => {
|
||||
const { mutateAsync: createOrGetShareLink, isLoading } =
|
||||
trpc.shareLink.createOrGetShareLink.useMutation();
|
||||
|
||||
const onShareClick = async () => {
|
||||
const onCopyClick = async () => {
|
||||
const { slug } = await createOrGetShareLink({
|
||||
token: token,
|
||||
documentId,
|
||||
@ -36,16 +48,48 @@ export const ShareButton = ({ token, documentId }: ShareButtonProps) => {
|
||||
});
|
||||
};
|
||||
|
||||
const onTweetClick = async () => {
|
||||
const { slug } = await createOrGetShareLink({
|
||||
token: token,
|
||||
documentId,
|
||||
});
|
||||
|
||||
window.open(
|
||||
generateTwitterIntent(
|
||||
'I just signed a document with @documenso. Check it out!',
|
||||
`${window.location.origin}/share/${slug}`,
|
||||
),
|
||||
'_blank',
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outline"
|
||||
className="flex-1"
|
||||
disabled={!token || !documentId}
|
||||
loading={isLoading}
|
||||
onClick={onShareClick}
|
||||
>
|
||||
{!isLoading && <Share className="mr-2 h-5 w-5" />}
|
||||
Share
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={!token || !documentId}
|
||||
className="flex-1"
|
||||
loading={isLoading}
|
||||
>
|
||||
{!isLoading && <Share className="mr-2 h-5 w-5" />}
|
||||
Share
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem className="px-10 py-3" asChild>
|
||||
<div className="border-0" onClick={onCopyClick}>
|
||||
<Copy className="mr-2 h-5 w-5" />
|
||||
Copy Link
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="px-10 py-3" asChild>
|
||||
<div onClick={onTweetClick}>
|
||||
<Twitter className="mr-2 h-5 w-5" />
|
||||
Tweet
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
};
|
||||
|
||||
11
package-lock.json
generated
11
package-lock.json
generated
@ -19809,6 +19809,7 @@
|
||||
"@aws-sdk/signature-v4-crt": "^3.410.0",
|
||||
"@documenso/email": "*",
|
||||
"@documenso/prisma": "*",
|
||||
"@documenso/signing": "*",
|
||||
"@next-auth/prisma-adapter": "1.0.7",
|
||||
"@pdf-lib/fontkit": "^1.1.1",
|
||||
"@scure/base": "^1.1.3",
|
||||
@ -19862,17 +19863,23 @@
|
||||
"packages/signing": {
|
||||
"name": "@documenso/signing",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"license": "AGPLv3",
|
||||
"dependencies": {
|
||||
"@documenso/tsconfig": "*",
|
||||
"node-forge": "^1.3.1",
|
||||
"node-signpdf": "^2.0.0",
|
||||
"pdf-lib": "^1.17.1"
|
||||
"pdf-lib": "^1.17.1",
|
||||
"ts-pattern": "^5.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node-forge": "^1.3.4"
|
||||
}
|
||||
},
|
||||
"packages/signing/node_modules/ts-pattern": {
|
||||
"version": "5.0.5",
|
||||
"resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-5.0.5.tgz",
|
||||
"integrity": "sha512-tL0w8U/pgaacOmkb9fRlYzWEUDCfVjjv9dD4wHTgZ61MjhuMt46VNWTG747NqW6vRzoWIKABVhFSOJ82FvXrfA=="
|
||||
},
|
||||
"packages/tailwind-config": {
|
||||
"name": "@documenso/tailwind-config",
|
||||
"version": "0.0.0",
|
||||
|
||||
Reference in New Issue
Block a user