dcfa2f8c8d
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
"use client";
|
||
|
||
import { Plus } from "lucide-react";
|
||
import { createContext, use, useState } from "react";
|
||
import { Button } from "@/components/ui/button";
|
||
import {
|
||
TransactionFormDialog,
|
||
type TransactionFormMode,
|
||
} from "@/features/transactions/components/transaction-form";
|
||
import { tr } from "@/i18n/tr";
|
||
|
||
type QuickAddApi = {
|
||
/** Hızlı ekle: yeni işlem formu (varsayılan gider; sekmelerle gelir/transfer). */
|
||
openQuickAdd: (type?: "expense" | "income" | "transfer") => void;
|
||
/** Düzenle / kopyala (işlem listesi ve ayrıntısı). */
|
||
openTransactionForm: (mode: TransactionFormMode) => void;
|
||
};
|
||
|
||
const QuickAddContext = createContext<QuickAddApi | null>(null);
|
||
|
||
export function useQuickAdd() {
|
||
const ctx = use(QuickAddContext);
|
||
if (!ctx) throw new Error("useQuickAdd, QuickAddProvider içinde kullanılmalı");
|
||
return ctx;
|
||
}
|
||
|
||
/** Uygulama genelinde tek işlem formu; her ekrandan açılabilir (Bölüm 4). */
|
||
export function QuickAddProvider({ children }: { children: React.ReactNode }) {
|
||
const [mode, setMode] = useState<TransactionFormMode | null>(null);
|
||
const api: QuickAddApi = {
|
||
openQuickAdd: (type = "expense") => setMode({ kind: "create", type }),
|
||
openTransactionForm: setMode,
|
||
};
|
||
return (
|
||
<QuickAddContext value={api}>
|
||
{children}
|
||
<TransactionFormDialog mode={mode} onOpenChange={(open) => !open && setMode(null)} />
|
||
</QuickAddContext>
|
||
);
|
||
}
|
||
|
||
/** Masaüstü üst bar düğmesi. */
|
||
export function QuickAddButton({ className }: { className?: string }) {
|
||
const { openQuickAdd } = useQuickAdd();
|
||
return (
|
||
<Button onClick={() => openQuickAdd()} className={className}>
|
||
<Plus />
|
||
{tr.quickAdd.button}
|
||
</Button>
|
||
);
|
||
}
|