fix(applications): handle cover letter copy failures (#3394)

* fix(applications): handle cover letter copy failures

* style(applications): format clipboard error toast

* refactor(applications): memoize copy draft handler
This commit is contained in:
Emanuele Tonello
2026-09-05 09:51:24 -07:00
committed by GitHub
parent 1f0844b39c
commit ef47baf243
@@ -14,7 +14,7 @@ import {
SpinnerGapIcon,
} from "@phosphor-icons/react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useState } from "react";
import { useCallback, useState } from "react";
import { toast } from "@reactive-resume/ui/components/toast";
import { generateFilename } from "@reactive-resume/utils/file";
import { cn } from "@reactive-resume/utils/style";
@@ -235,6 +235,20 @@ export function ApplicationAiCopilot({ application }: Props) {
}
};
// biome-ignore lint/correctness/useExhaustiveDependencies: keep review-requested callback dependencies explicit.
const copyDraft = useCallback(async () => {
try {
if (!navigator.clipboard?.writeText) throw new Error("Clipboard unavailable");
await navigator.clipboard.writeText(draft?.text ?? "");
toast.add({ type: "success", description: t`Copied to clipboard.` });
} catch {
toast.add({
type: "error",
description: t`Could not copy to clipboard. Please copy the text manually.`,
});
}
}, [draft?.text, toast, t]);
return (
<section className="overflow-hidden rounded-xl border border-primary/15 bg-primary/[0.04]">
<header className="flex items-center gap-2 px-3.5 pt-3">
@@ -341,10 +355,7 @@ export function ApplicationAiCopilot({ application }: Props) {
<button
type="button"
className="inline-flex items-center gap-1 text-muted-foreground text-xs hover:text-foreground"
onClick={() => {
void navigator.clipboard.writeText(draft.text);
toast.add({ type: "success", description: t`Copied to clipboard.` });
}}
onClick={() => void copyDraft()}
>
<CopyIcon className="size-3.5" /> <Trans>Copy</Trans>
</button>