import { t } from "@lingui/macro"; import { CaretDown, ChatTeardropText, CircleNotch, Exam, MagicWand, PenNib, } from "@phosphor-icons/react"; import { Badge, Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@reactive-resume/ui"; import { cn } from "@reactive-resume/utils"; import { useState } from "react"; import { toast } from "../hooks/use-toast"; import { changeTone } from "../services/openai/change-tone"; import { fixGrammar } from "../services/openai/fix-grammar"; import { improveWriting } from "../services/openai/improve-writing"; import { useOpenAiStore } from "../stores/openai"; type Action = "improve" | "fix" | "tone"; type Mood = "casual" | "professional" | "confident" | "friendly"; type Props = { value: string; onChange: (value: string) => void; className?: string; }; export const AiActions = ({ value, onChange, className }: Props) => { const [loading, setLoading] = useState(false); const aiEnabled = useOpenAiStore((state) => !!state.apiKey); if (!aiEnabled) return null; const onClick = async (action: Action, mood?: Mood) => { try { setLoading(action); let result = value; if (action === "improve") result = await improveWriting(value); if (action === "fix") result = await fixGrammar(value); if (action === "tone" && mood) result = await changeTone(value, mood); onChange(result); } catch (error) { toast({ variant: "error", title: t`Oops, the server returned an error.`, description: (error as Error).message, }); } finally { setLoading(false); } }; return (
{t`AI`}
onClick("tone", "casual")}> 🙂 {t`Casual`} onClick("tone", "professional")}> 💼 {t`Professional`} onClick("tone", "confident")}> 😎 {t`Confident`} onClick("tone", "friendly")}> 😊 {t`Friendly`}
); };