diff --git a/src/app/(dashboard)/finance/cards/components/card-form-sheet.tsx b/src/app/(dashboard)/finance/cards/components/card-form-sheet.tsx new file mode 100644 index 0000000..7b52839 --- /dev/null +++ b/src/app/(dashboard)/finance/cards/components/card-form-sheet.tsx @@ -0,0 +1,225 @@ +"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 { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { + Sheet, + SheetContent, + SheetDescription, + SheetFooter, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet"; +import { Textarea } from "@/components/ui/textarea"; +import { + createCreditCardAction, + updateCreditCardAction, +} from "@/lib/appwrite/credit-card-actions"; +import { initialCreditCardState } from "@/lib/appwrite/credit-card-types"; + +import type { BankAccountOption, CreditCardRow } from "./types"; + +const NONE = "__none__"; + +export function CardFormSheet({ + open, + onOpenChange, + card, + bankAccounts, +}: { + open: boolean; + onOpenChange: (v: boolean) => void; + card?: CreditCardRow | null; + bankAccounts: BankAccountOption[]; +}) { + const isEdit = Boolean(card); + const action = isEdit ? updateCreditCardAction : createCreditCardAction; + const [state, formAction, isPending] = useActionState(action, initialCreditCardState); + + useEffect(() => { + if (state.ok) { + toast.success(isEdit ? "Kart güncellendi." : "Kart eklendi."); + onOpenChange(false); + } else if (state.error) { + toast.error(state.error); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [state]); + + return ( + + + + {isEdit ? "Kartı düzenle" : "Yeni kredi kartı"} + + Hesap kesim ve son ödeme günleri her ay otomatik kullanılır. Ekstreler kart başına manuel girilir. + + + +
{ + if (fd.get("bankAccountId") === NONE) fd.set("bankAccountId", ""); + formAction(fd); + }} + className="flex flex-1 flex-col" + > + {isEdit && card && } + +
+
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +

+ Ekstre ödemeleri seçilen hesaba expense olarak yazılır. +

+
+ +
+ +