"use client" import { useState } from "react" import { Loader2 } from "lucide-react" import { useTranslations } from "next-intl" import { toast } from "sonner" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Switch } from "@/components/ui/switch" import { gitStashPush } from "@/lib/api" import { toErrorMessage } from "@/lib/app-error" interface StashDialogProps { open: boolean folderPath: string onClose: () => void onStashed: () => void } export function StashDialog({ open, folderPath, onClose, onStashed, }: StashDialogProps) { const t = useTranslations("Folder.branchDropdown.stashDialog") const [message, setMessage] = useState("") const [keepIndex, setKeepIndex] = useState(false) const [loading, setLoading] = useState(false) function handleClose() { if (loading) return setMessage("") setKeepIndex(false) onClose() } async function handleStash() { setLoading(true) try { await gitStashPush(folderPath, message.trim() || undefined, keepIndex) toast.success(t("success")) setMessage("") setKeepIndex(false) onStashed() onClose() } catch (err) { toast.error(t("error"), { description: toErrorMessage(err) }) } finally { setLoading(false) } } return ( !v && handleClose()}> {t("title")} {t("description")}
setMessage(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter" && !loading) { handleStash() } }} disabled={loading} autoFocus />
) }