From 2327e3133f3f2716a5a96dd925d2c257c297b219 Mon Sep 17 00:00:00 2001 From: Wesley Souza | Neo Date: Fri, 8 Nov 2024 23:27:32 -0300 Subject: [PATCH] feat: :sparkles: add transaction button component --- app/_components/add-transaction-button.tsx | 252 +++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 app/_components/add-transaction-button.tsx diff --git a/app/_components/add-transaction-button.tsx b/app/_components/add-transaction-button.tsx new file mode 100644 index 0000000..2a97e53 --- /dev/null +++ b/app/_components/add-transaction-button.tsx @@ -0,0 +1,252 @@ +"use client"; + +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/app/_components/ui/dialog"; +import { Button } from "./ui/button"; +import { ArrowDownUp } from "lucide-react"; +import { DialogTrigger } from "./ui/dialog"; +import { z } from "zod"; +import { + TransactionCategory, + TransactionPaymentMethod, + TransactionType, +} from "@prisma/client"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import { + Form, + FormField, + FormItem, + FormLabel, + FormControl, + FormMessage, +} from "./ui/form"; +import { Input } from "./ui/input"; +import { MoneyInput } from "./money-input"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "./ui/select"; +import { + TRANSACTION_CATEGORY_MAP, + TRANSACTION_PAYMENT_METHOD_MAP, + transactionTypeOptions, +} from "../_constants/transaction"; +import { DatePicker } from "./ui/date-picker"; + +const formSchema = z.object({ + name: z.string().trim().min(1, { message: "O nome é obrigatório" }), + amount: z.string().trim().min(1, { message: "O valor é obrigatório" }), + type: z.nativeEnum(TransactionType, { + required_error: "O tipo é obrigatório", + }), + category: z.nativeEnum(TransactionCategory, { + required_error: "A categoria é obrigatória", + }), + paymentMethod: z.nativeEnum(TransactionPaymentMethod, { + required_error: "O método de pagamento é obrigatório", + }), + date: z.date({ + required_error: "A data é obrigatória", + }), +}); + +type FormData = z.infer; + +const AddTransactionButton = () => { + const form = useForm({ + resolver: zodResolver(formSchema), + defaultValues: { + amount: "", + category: TransactionCategory.OTHER, + name: "", + paymentMethod: TransactionPaymentMethod.CASH, + date: new Date(), + type: TransactionType.EXPENSE, + }, + }); + + const onSubmit = (data: FormData) => { + console.log({ data }); + }; + + return ( + + + + + + + Adicionar transação + + Adicione uma nova transação para começar a gerenciar suas finanças. + Insira as informações abaixo para continuar. + + +
+ + ( + + Título + + + + + + + )} + /> + + ( + + Valor da transação + + + + + + + )} + /> + + ( + + Tipo da transação + + + + + )} + /> + + ( + + Categoria + + + + + )} + /> + + ( + + Método de pagamento + + + + + )} + /> + + ( + + Data + + + + )} + /> + + + + + + + + + +
+
+ ); +}; + +export default AddTransactionButton;