mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 00:32:43 +10:00
fix: styling updates
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { HTMLAttributes } from 'react';
|
import { HTMLAttributes, useState } from 'react';
|
||||||
|
|
||||||
import { Copy, Share, Twitter } from 'lucide-react';
|
import { Copy, Share, Twitter } from 'lucide-react';
|
||||||
|
|
||||||
@ -8,11 +8,13 @@ import { generateTwitterIntent } from '@documenso/lib/universal/generate-twitter
|
|||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
Dialog,
|
||||||
DropdownMenuContent,
|
DialogContent,
|
||||||
DropdownMenuItem,
|
DialogDescription,
|
||||||
DropdownMenuTrigger,
|
DialogHeader,
|
||||||
} from '@documenso/ui/primitives/dropdown-menu';
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from '@documenso/ui/primitives/dialog';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
import { useCopyToClipboard } from '~/hooks/use-copy-to-clipboard';
|
import { useCopyToClipboard } from '~/hooks/use-copy-to-clipboard';
|
||||||
@ -26,14 +28,36 @@ export const ShareButton = ({ token, documentId }: ShareButtonProps) => {
|
|||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [, copyToClipboard] = useCopyToClipboard();
|
const [, copyToClipboard] = useCopyToClipboard();
|
||||||
|
|
||||||
const { mutateAsync: createOrGetShareLink, isLoading } =
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
trpc.shareLink.createOrGetShareLink.useMutation();
|
|
||||||
|
const {
|
||||||
|
mutateAsync: createOrGetShareLink,
|
||||||
|
data: shareLink,
|
||||||
|
isLoading,
|
||||||
|
} = trpc.shareLink.createOrGetShareLink.useMutation();
|
||||||
|
|
||||||
|
const onOpenChange = (nextOpen: boolean) => {
|
||||||
|
if (nextOpen) {
|
||||||
|
void createOrGetShareLink({
|
||||||
|
token,
|
||||||
|
documentId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsOpen(nextOpen);
|
||||||
|
};
|
||||||
|
|
||||||
const onCopyClick = async () => {
|
const onCopyClick = async () => {
|
||||||
const { slug } = await createOrGetShareLink({
|
let { slug = '' } = shareLink || {};
|
||||||
token: token,
|
|
||||||
documentId,
|
if (!slug) {
|
||||||
});
|
const result = await createOrGetShareLink({
|
||||||
|
token,
|
||||||
|
documentId,
|
||||||
|
});
|
||||||
|
|
||||||
|
slug = result.slug;
|
||||||
|
}
|
||||||
|
|
||||||
await copyToClipboard(`${window.location.origin}/share/${slug}`).catch(() => null);
|
await copyToClipboard(`${window.location.origin}/share/${slug}`).catch(() => null);
|
||||||
|
|
||||||
@ -41,26 +65,36 @@ export const ShareButton = ({ token, documentId }: ShareButtonProps) => {
|
|||||||
title: 'Copied to clipboard',
|
title: 'Copied to clipboard',
|
||||||
description: 'The sharing link has been copied to your clipboard.',
|
description: 'The sharing link has been copied to your clipboard.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setIsOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onTweetClick = async () => {
|
const onTweetClick = async () => {
|
||||||
const { slug } = await createOrGetShareLink({
|
let { slug = '' } = shareLink || {};
|
||||||
token: token,
|
|
||||||
documentId,
|
if (!slug) {
|
||||||
});
|
const result = await createOrGetShareLink({
|
||||||
|
token,
|
||||||
|
documentId,
|
||||||
|
});
|
||||||
|
|
||||||
|
slug = result.slug;
|
||||||
|
}
|
||||||
|
|
||||||
window.open(
|
window.open(
|
||||||
generateTwitterIntent(
|
generateTwitterIntent(
|
||||||
'I just signed a document with @documenso. Check it out!',
|
`I just ${token ? 'signed' : 'sent'} a document with @documenso. Check it out!`,
|
||||||
`${window.location.origin}/share/${slug}`,
|
`${window.location.origin}/share/${slug}`,
|
||||||
),
|
),
|
||||||
'_blank',
|
'_blank',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
setIsOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<Dialog open={isOpen} onOpenChange={onOpenChange}>
|
||||||
<DropdownMenuTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
disabled={!token || !documentId}
|
disabled={!token || !documentId}
|
||||||
@ -70,21 +104,43 @@ export const ShareButton = ({ token, documentId }: ShareButtonProps) => {
|
|||||||
{!isLoading && <Share className="mr-2 h-5 w-5" />}
|
{!isLoading && <Share className="mr-2 h-5 w-5" />}
|
||||||
Share
|
Share
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DialogTrigger>
|
||||||
<DropdownMenuContent>
|
|
||||||
<DropdownMenuItem className="px-10 py-3" asChild>
|
<DialogContent>
|
||||||
<div className="border-0" onClick={onCopyClick}>
|
<DialogHeader>
|
||||||
<Copy className="mr-2 h-5 w-5" />
|
<DialogTitle>Share</DialogTitle>
|
||||||
Copy Link
|
|
||||||
|
<DialogDescription className="mt-4">Share your signing experience!</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="flex w-full flex-col">
|
||||||
|
<div className="rounded-md border p-4">
|
||||||
|
I just signed a document with{' '}
|
||||||
|
<span className="font-medium text-blue-400">@documenso</span>
|
||||||
|
. Check it out!
|
||||||
|
<span className="mt-2 block" />
|
||||||
|
<span className="font-medium text-blue-400">
|
||||||
|
{window.location.origin}/share/{shareLink?.slug || '...'}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem className="px-10 py-3" asChild>
|
<Button variant="outline" className="mt-4" onClick={onTweetClick}>
|
||||||
<div onClick={onTweetClick}>
|
<Twitter className="mr-2 h-4 w-4" />
|
||||||
<Twitter className="mr-2 h-5 w-5" />
|
|
||||||
Tweet
|
Tweet
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<div className="relative flex items-center justify-center gap-x-4 py-4 text-xs uppercase">
|
||||||
|
<div className="bg-border h-px flex-1" />
|
||||||
|
<span className="text-muted-foreground bg-transparent">Or</span>
|
||||||
|
<div className="bg-border h-px flex-1" />
|
||||||
</div>
|
</div>
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
<Button variant="outline" onClick={onCopyClick}>
|
||||||
</DropdownMenu>
|
<Copy className="mr-2 h-4 w-4" />
|
||||||
|
Copy Link
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
export const generateTwitterIntent = (text: string, shareUrl: string) => {
|
export const generateTwitterIntent = (text: string, shareUrl: string) => {
|
||||||
return `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}%0A${encodeURIComponent(
|
return `https://twitter.com/intent/tweet?text=${encodeURIComponent(
|
||||||
shareUrl,
|
text,
|
||||||
)}`;
|
)}%0A%0A${encodeURIComponent(shareUrl)}`;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user