diff --git a/src/app/(dashboard)/finance/banks/components/bank-form-sheet.tsx b/src/app/(dashboard)/finance/banks/components/bank-form-sheet.tsx new file mode 100644 index 0000000..46d633e --- /dev/null +++ b/src/app/(dashboard)/finance/banks/components/bank-form-sheet.tsx @@ -0,0 +1,159 @@ +"use client"; + +import { useActionState, useEffect } from "react"; +import { Loader2, Save } from "lucide-react"; +import { toast } from "sonner"; + +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { + Sheet, + SheetContent, + SheetDescription, + SheetFooter, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet"; +import { Textarea } from "@/components/ui/textarea"; +import { + createBankAccountAction, + updateBankAccountAction, +} from "@/lib/appwrite/bank-account-actions"; +import { initialBankAccountState } from "@/lib/appwrite/bank-account-types"; + +import type { BankAccountRow } from "./types"; + +type Props = { + open: boolean; + onOpenChange: (v: boolean) => void; + account?: BankAccountRow | null; +}; + +export function BankFormSheet({ open, onOpenChange, account }: Props) { + const isEdit = Boolean(account); + const action = isEdit ? updateBankAccountAction : createBankAccountAction; + const [state, formAction, isPending] = useActionState(action, initialBankAccountState); + + useEffect(() => { + if (state.ok) { + toast.success(isEdit ? "Hesap güncellendi." : "Hesap eklendi."); + onOpenChange(false); + } else if (state.error) { + toast.error(state.error); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [state]); + + return ( + + + + {isEdit ? "Hesabı düzenle" : "Yeni banka hesabı"} + + Açılış bakiyesi sonradan değiştirilirse bütün hareketler aynı kalır, sadece toplam + kayar. + + + +
+ {isEdit && account && } + +
+
+
+ + + {state.fieldErrors?.bankName && ( +

{state.fieldErrors.bankName}

+ )} +
+
+ + + {state.fieldErrors?.accountName && ( +

{state.fieldErrors.accountName}

+ )} +
+
+ +
+ + +
+ +
+ + +

+ Bu hesabı sisteme eklediğinizdeki bakiye. Sonraki hareketler bu rakamın üstüne eklenir. +

+
+ +
+ +