Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion static/app/components/copyToClipboardButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ export function CopyToClipboardButton({
<Button
{...props}
onClick={e => {
copy(text).then(onCopy).catch(onError);
copy(text).then(result => {
if (result === undefined) {
onError?.(new Error('Failed to copy to clipboard'));
} else {
onCopy?.(result);
}
});
onClick?.(e);
}}
icon={icon ?? <IconCopy variant="muted" />}
Expand Down
5 changes: 2 additions & 3 deletions static/app/utils/useCopyToClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type CopyCallback = (
* Pass `null` to disable any toast messages.
*/
options?: {errorMessage?: React.ReactNode; successMessage?: React.ReactNode} | null
) => Promise<string>;
) => Promise<string | void>;

export function copyToClipboard(
text: string,
Expand All @@ -35,11 +35,10 @@ export function copyToClipboard(
}
return text;
})
.catch(error => {
.catch(_error => {
if (errorMessage) {
addErrorMessage(errorMessage);
}
throw error;
});

return promise;
Expand Down
Loading