mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 09:12:02 +10:00
refactor: restructure logic
This commit is contained in:
@ -20,7 +20,7 @@ export type DataTableActionButtonProps = {
|
||||
export const DataTableActionButton = ({ row }: DataTableActionButtonProps) => {
|
||||
const { data: session } = useSession();
|
||||
|
||||
const { copyShareLink, isCopyingShareLink } = useCopyShareLink();
|
||||
const { createAndCopyShareLink, isCopyingShareLink } = useCopyShareLink();
|
||||
|
||||
if (!session) {
|
||||
return null;
|
||||
@ -63,12 +63,12 @@ export const DataTableActionButton = ({ row }: DataTableActionButtonProps) => {
|
||||
<Button
|
||||
className="w-24"
|
||||
loading={isCopyingShareLink}
|
||||
onClick={() => {
|
||||
void copyShareLink({
|
||||
onClick={async () =>
|
||||
createAndCopyShareLink({
|
||||
token: recipient?.token,
|
||||
documentId: row.id,
|
||||
});
|
||||
}}
|
||||
})
|
||||
}
|
||||
>
|
||||
{!isCopyingShareLink && <Share className="-ml-1 mr-2 h-4 w-4" />}
|
||||
Share
|
||||
|
||||
@ -39,7 +39,7 @@ export type DataTableActionDropdownProps = {
|
||||
export const DataTableActionDropdown = ({ row }: DataTableActionDropdownProps) => {
|
||||
const { data: session } = useSession();
|
||||
|
||||
const { copyShareLink, isCopyingShareLink } = useCopyShareLink();
|
||||
const { createAndCopyShareLink, isCopyingShareLink } = useCopyShareLink();
|
||||
|
||||
if (!session) {
|
||||
return null;
|
||||
@ -140,12 +140,12 @@ export const DataTableActionDropdown = ({ row }: DataTableActionDropdownProps) =
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
void copyShareLink({
|
||||
onClick={async () =>
|
||||
createAndCopyShareLink({
|
||||
token: recipient?.token,
|
||||
documentId: row.id,
|
||||
});
|
||||
}}
|
||||
})
|
||||
}
|
||||
>
|
||||
{isCopyingShareLink ? (
|
||||
<Loader className="mr-2 h-4 w-4" />
|
||||
|
||||
@ -24,7 +24,7 @@ export type ShareButtonProps = HTMLAttributes<HTMLButtonElement> & {
|
||||
};
|
||||
|
||||
export const ShareButton = ({ token, documentId }: ShareButtonProps) => {
|
||||
const { copyShareLink, isCopyingShareLink } = useCopyShareLink();
|
||||
const { copyShareLink, createAndCopyShareLink, isCopyingShareLink } = useCopyShareLink();
|
||||
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
@ -46,14 +46,14 @@ export const ShareButton = ({ token, documentId }: ShareButtonProps) => {
|
||||
};
|
||||
|
||||
const onCopyClick = async () => {
|
||||
const copyToClipboardValue = shareLink
|
||||
? `${window.location.origin}/share/${shareLink.slug}`
|
||||
: {
|
||||
token,
|
||||
documentId,
|
||||
};
|
||||
|
||||
await copyShareLink(copyToClipboardValue);
|
||||
if (shareLink) {
|
||||
await copyShareLink(`${window.location.origin}/share/${shareLink.slug}`);
|
||||
} else {
|
||||
await createAndCopyShareLink({
|
||||
token,
|
||||
documentId,
|
||||
});
|
||||
}
|
||||
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user