fix(lint): resolve Biome errors and migrate config
- migrate biome.json to schema 2.5.10 (preset instead of recommended) - apply safe fixes: formatting, import organization, unused imports/vars - use node:crypto import protocol - drop unused catch bindings - a11y: associate labels with controls via htmlFor/id (add optional id to DatePicker), hide decorative SVGs from AT, and replace the custom role="checkbox" button with a native checkbox input - remove unnecessary pageSize dependency from useMemo
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { z } from "zod";
|
||||
import { PaymentStatus, QuoteType, type Prisma } from "../../generated/prisma/client";
|
||||
import {
|
||||
PaymentStatus,
|
||||
type Prisma,
|
||||
QuoteType,
|
||||
} from "../../generated/prisma/client";
|
||||
import { cache } from "../../lib/cache";
|
||||
import { prisma } from "../../lib/prisma";
|
||||
import { roundTo } from "../../lib/utils";
|
||||
@@ -87,7 +91,10 @@ export async function getBeloSellPriceForDate(
|
||||
paymentDate.getUTCFullYear(),
|
||||
paymentDate.getUTCMonth(),
|
||||
paymentDate.getUTCDate(),
|
||||
17, 0, 0, 0,
|
||||
17,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -240,7 +247,9 @@ export async function createNonPeriodicExpense(
|
||||
const isUSDC = wallet.currency === "USDC";
|
||||
|
||||
if (isUSDC && !data.usdcConversionRate) {
|
||||
throw new Error("La tasa de conversión es obligatoria para billeteras USDC");
|
||||
throw new Error(
|
||||
"La tasa de conversión es obligatoria para billeteras USDC",
|
||||
);
|
||||
}
|
||||
|
||||
const belo = isUSDC ? null : await getBeloSellPriceForDate(dueDate);
|
||||
@@ -313,12 +322,15 @@ export async function payExpense(
|
||||
const isUSDC = wallet.currency === "USDC";
|
||||
|
||||
if (isUSDC && !data.usdcConversionRate) {
|
||||
throw new Error("La tasa de conversión es obligatoria para billeteras USDC");
|
||||
throw new Error(
|
||||
"La tasa de conversión es obligatoria para billeteras USDC",
|
||||
);
|
||||
}
|
||||
|
||||
const belo = isUSDC ? null : await getBeloSellPriceForDate(paymentDate);
|
||||
|
||||
const movementAmount = isUSDC && data.usdcConversionRate
|
||||
const movementAmount =
|
||||
isUSDC && data.usdcConversionRate
|
||||
? -roundTo(data.amountPayed / data.usdcConversionRate, 4)
|
||||
: -data.amountPayed;
|
||||
|
||||
@@ -331,7 +343,10 @@ export async function payExpense(
|
||||
|
||||
if (isUSDC && data.usdcConversionRate) {
|
||||
expenseUpdateData.beloPrice = data.usdcConversionRate;
|
||||
expenseUpdateData.usdcEquivalent = roundTo(data.amountPayed / data.usdcConversionRate, 6);
|
||||
expenseUpdateData.usdcEquivalent = roundTo(
|
||||
data.amountPayed / data.usdcConversionRate,
|
||||
6,
|
||||
);
|
||||
} else if (belo !== null) {
|
||||
expenseUpdateData.beloPrice = belo;
|
||||
expenseUpdateData.usdcEquivalent = roundTo(data.amountPayed / belo, 6);
|
||||
@@ -405,11 +420,16 @@ export async function updateExpense(
|
||||
updateData.paymentDate = new Date(data.paymentDate);
|
||||
}
|
||||
|
||||
const resolvedPaymentDate = updateData.paymentDate instanceof Date
|
||||
const resolvedPaymentDate =
|
||||
updateData.paymentDate instanceof Date
|
||||
? updateData.paymentDate
|
||||
: (existing.paymentDate ?? undefined);
|
||||
const amountPayed = updateData.amountPayed ?? existing.amountPayed;
|
||||
if (resolvedPaymentDate && amountPayed !== undefined && amountPayed !== null) {
|
||||
if (
|
||||
resolvedPaymentDate &&
|
||||
amountPayed !== undefined &&
|
||||
amountPayed !== null
|
||||
) {
|
||||
const belo = await getBeloSellPriceForDate(resolvedPaymentDate);
|
||||
if (belo !== null) {
|
||||
updateData.beloPrice = belo;
|
||||
@@ -424,7 +444,8 @@ export async function updateExpense(
|
||||
const oldPayed = existing.amountPayed
|
||||
? Number(existing.amountPayed)
|
||||
: Number(existing.amount);
|
||||
const newPayed = data.amountPayed !== undefined
|
||||
const newPayed =
|
||||
data.amountPayed !== undefined
|
||||
? Number(data.amountPayed)
|
||||
: Number(data.amount);
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Context } from "hono";
|
||||
import type { QuoteType } from "../../../generated/prisma/client";
|
||||
import { cache } from "../../../lib/cache";
|
||||
import { prisma } from "../../../lib/prisma";
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ export async function generateCodeHandler(c: Context) {
|
||||
try {
|
||||
const result = await generateCode();
|
||||
return c.json(result);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json({ error: "Failed to generate code" }, 500);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ export async function telegramStatusHandler(c: Context) {
|
||||
try {
|
||||
const status = await getTelegramStatus();
|
||||
return c.json(status);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json({ connected: false, botUsername: null }, 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import crypto from "crypto";
|
||||
import crypto from "node:crypto";
|
||||
import type { QuoteType } from "../../generated/prisma/client";
|
||||
import { logger } from "../../lib/logger";
|
||||
import { prisma } from "../../lib/prisma";
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Context } from "hono";
|
||||
import {
|
||||
adjustBalance,
|
||||
adjustBalanceSchema,
|
||||
} from "../wallets.service";
|
||||
import { adjustBalance, adjustBalanceSchema } from "../wallets.service";
|
||||
|
||||
export async function adjustBalanceHandler(c: Context) {
|
||||
const id = Number(c.req.param("id"));
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Context } from "hono";
|
||||
import {
|
||||
createWallet,
|
||||
createWalletSchema,
|
||||
} from "../wallets.service";
|
||||
import { createWallet, createWalletSchema } from "../wallets.service";
|
||||
|
||||
export async function createWalletHandler(c: Context) {
|
||||
const body = await c.req.json();
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Context } from "hono";
|
||||
import {
|
||||
depositWallet,
|
||||
depositSchema,
|
||||
} from "../wallets.service";
|
||||
import { depositSchema, depositWallet } from "../wallets.service";
|
||||
|
||||
export async function depositWalletHandler(c: Context) {
|
||||
const id = Number(c.req.param("id"));
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Context } from "hono";
|
||||
import {
|
||||
transferSchema,
|
||||
transferWallet,
|
||||
} from "../wallets.service";
|
||||
import { transferSchema, transferWallet } from "../wallets.service";
|
||||
|
||||
export async function transferWalletHandler(c: Context) {
|
||||
const body = await c.req.json();
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Context } from "hono";
|
||||
import {
|
||||
updateWallet,
|
||||
updateWalletSchema,
|
||||
} from "../wallets.service";
|
||||
import { updateWallet, updateWalletSchema } from "../wallets.service";
|
||||
|
||||
export async function updateWalletHandler(c: Context) {
|
||||
const id = Number(c.req.param("id"));
|
||||
|
||||
@@ -6,9 +6,9 @@ import { depositWalletHandler } from "./handlers/depositWallet";
|
||||
import { listAllMovementsHandler } from "./handlers/listAllMovements";
|
||||
import { listMovementsHandler } from "./handlers/listMovements";
|
||||
import { listWalletsHandler } from "./handlers/listWallets";
|
||||
import { setDefaultWalletHandler } from "./handlers/setDefaultWallet";
|
||||
import { transferWalletHandler } from "./handlers/transferWallet";
|
||||
import { updateWalletHandler } from "./handlers/updateWallet";
|
||||
import { setDefaultWalletHandler } from "./handlers/setDefaultWallet";
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { Prisma } from "../../generated/prisma/client";
|
||||
import { prisma } from "../../lib/prisma";
|
||||
import { cache } from "../../lib/cache";
|
||||
import { prisma } from "../../lib/prisma";
|
||||
|
||||
export const createWalletSchema = z.object({
|
||||
name: z.string().min(1).max(100),
|
||||
@@ -80,7 +79,9 @@ export async function updateWallet(id: number, input: UpdateWalletInput) {
|
||||
export async function deleteWallet(id: number) {
|
||||
const wallet = await prisma.wallet.findUniqueOrThrow({ where: { id } });
|
||||
if (Number(wallet.balance) !== 0) {
|
||||
throw new Error("No se puede eliminar una billetera con saldo distinto de cero");
|
||||
throw new Error(
|
||||
"No se puede eliminar una billetera con saldo distinto de cero",
|
||||
);
|
||||
}
|
||||
await prisma.walletMovement.deleteMany({ where: { walletId: id } });
|
||||
await prisma.wallet.delete({ where: { id } });
|
||||
@@ -182,7 +183,9 @@ export async function setDefaultWallet(walletId: number) {
|
||||
data: { isDefault: true },
|
||||
}),
|
||||
]);
|
||||
const wallet = await prisma.wallet.findUniqueOrThrow({ where: { id: walletId } });
|
||||
const wallet = await prisma.wallet.findUniqueOrThrow({
|
||||
where: { id: walletId },
|
||||
});
|
||||
return { ...wallet, balance: Number(wallet.balance) };
|
||||
}
|
||||
|
||||
|
||||
@@ -800,7 +800,6 @@ describe("payExpense with BELO", () => {
|
||||
amountPayed: null,
|
||||
paymentDate: null,
|
||||
};
|
||||
const paymentDate = new Date("2026-06-10T00:00:00.000Z");
|
||||
const wallet = { id: 1, balance: 100000, currency: "ARS" };
|
||||
mockPrisma.expense.findUniqueOrThrow.mockResolvedValueOnce(expense);
|
||||
mockWalletFindUnique.mockResolvedValueOnce(wallet);
|
||||
@@ -884,8 +883,7 @@ describe("createNonPeriodicExpense with BELO", () => {
|
||||
})
|
||||
.mockResolvedValueOnce(null);
|
||||
|
||||
mockPrisma.expense.create.mockImplementationOnce(
|
||||
async ({ data }) => ({
|
||||
mockPrisma.expense.create.mockImplementationOnce(async ({ data }) => ({
|
||||
id: 1,
|
||||
description: data.description,
|
||||
amount: data.amount,
|
||||
@@ -893,8 +891,7 @@ describe("createNonPeriodicExpense with BELO", () => {
|
||||
status: PaymentStatus.PAYED,
|
||||
beloPrice: data.beloPrice,
|
||||
usdcEquivalent: data.usdcEquivalent,
|
||||
}),
|
||||
);
|
||||
}));
|
||||
mockWalletUpdate.mockResolvedValueOnce({ ...wallet, balance: 70000 });
|
||||
mockMovementCreate.mockResolvedValueOnce({ id: 1 });
|
||||
|
||||
@@ -916,15 +913,13 @@ describe("createNonPeriodicExpense with BELO", () => {
|
||||
.mockResolvedValueOnce(null)
|
||||
.mockResolvedValueOnce(null);
|
||||
|
||||
mockPrisma.expense.create.mockImplementationOnce(
|
||||
async ({ data }) => ({
|
||||
mockPrisma.expense.create.mockImplementationOnce(async ({ data }) => ({
|
||||
id: 1,
|
||||
description: data.description,
|
||||
amount: data.amount,
|
||||
amountPayed: data.amountPayed,
|
||||
status: PaymentStatus.PAYED,
|
||||
}),
|
||||
);
|
||||
}));
|
||||
mockWalletUpdate.mockResolvedValueOnce({ ...wallet, balance: 97500 });
|
||||
mockMovementCreate.mockResolvedValueOnce({ id: 1 });
|
||||
|
||||
|
||||
@@ -8,16 +8,19 @@ function TelegramIcon(props: { className?: string }) {
|
||||
fill="currentColor"
|
||||
className={props.className}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
>
|
||||
<path d="M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAuth } from "@/lib/auth-context";
|
||||
import { useTelegramStatus } from "@/lib/queries";
|
||||
import { useSseStatus } from "@/lib/sse-context";
|
||||
import { useTheme } from "@/lib/theme";
|
||||
import { useTelegramStatus } from "@/lib/queries";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface HeaderProps {
|
||||
@@ -82,7 +85,11 @@ export function Header({ onMenuClick }: HeaderProps) {
|
||||
? "text-emerald-500 hover:text-emerald-400"
|
||||
: "text-muted-foreground hover:text-foreground",
|
||||
)}
|
||||
title={telegramStatus?.connected ? "Telegram conectado" : "Conectar Telegram"}
|
||||
title={
|
||||
telegramStatus?.connected
|
||||
? "Telegram conectado"
|
||||
: "Conectar Telegram"
|
||||
}
|
||||
>
|
||||
<TelegramIcon className="size-4" />
|
||||
</Link>
|
||||
|
||||
@@ -14,12 +14,14 @@ import {
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface DatePickerProps {
|
||||
id?: string;
|
||||
value: Date | undefined;
|
||||
onChange: (date: Date | undefined) => void;
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export function DatePicker({
|
||||
id,
|
||||
value,
|
||||
onChange,
|
||||
placeholder = "Seleccionar fecha",
|
||||
@@ -30,6 +32,7 @@ export function DatePicker({
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
id={id}
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"h-8 w-full justify-start gap-2 px-2.5 font-normal",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { Check } from "lucide-react";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { Controller, useForm, useWatch } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
@@ -17,7 +18,10 @@ import { useExpensesContext } from "../ExpensesProvider";
|
||||
const editSchema = z.object({
|
||||
amount: z.number().positive("El monto debe ser mayor a 0"),
|
||||
dueDate: z.date({ message: "La fecha es obligatoria" }),
|
||||
amountPayed: z.number().positive("El monto pagado debe ser mayor a 0").optional(),
|
||||
amountPayed: z
|
||||
.number()
|
||||
.positive("El monto pagado debe ser mayor a 0")
|
||||
.optional(),
|
||||
paymentDate: z.date().optional(),
|
||||
markAsPending: z.boolean(),
|
||||
});
|
||||
@@ -107,8 +111,8 @@ export function EditExpenseDialog({
|
||||
await updateExpense(expense.id, {
|
||||
amount: data.amount,
|
||||
dueDate: data.dueDate.toISOString(),
|
||||
amountPayed: data.amountPayed!,
|
||||
paymentDate: data.paymentDate!.toISOString(),
|
||||
amountPayed: data.amountPayed,
|
||||
paymentDate: data.paymentDate?.toISOString(),
|
||||
});
|
||||
} else {
|
||||
await updateExpense(expense.id, {
|
||||
@@ -193,7 +197,10 @@ export function EditExpenseDialog({
|
||||
{!markAsPending && (
|
||||
<>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label htmlFor="amountPayed" className="text-sm font-medium">
|
||||
<label
|
||||
htmlFor="amountPayed"
|
||||
className="text-sm font-medium"
|
||||
>
|
||||
Monto pagado
|
||||
</label>
|
||||
<input
|
||||
@@ -214,9 +221,7 @@ export function EditExpenseDialog({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<span className="text-sm font-medium">
|
||||
Fecha de pago
|
||||
</span>
|
||||
<span className="text-sm font-medium">Fecha de pago</span>
|
||||
<Controller
|
||||
control={control}
|
||||
name="paymentDate"
|
||||
@@ -237,40 +242,32 @@ export function EditExpenseDialog({
|
||||
</>
|
||||
)}
|
||||
|
||||
<label className="flex items-center gap-2 text-sm cursor-pointer">
|
||||
<label
|
||||
htmlFor="mark-as-pending"
|
||||
className="flex items-center gap-2 text-sm cursor-pointer"
|
||||
>
|
||||
<Controller
|
||||
control={control}
|
||||
name="markAsPending"
|
||||
render={({ field }) => (
|
||||
<button
|
||||
type="button"
|
||||
role="checkbox"
|
||||
aria-checked={field.value}
|
||||
onClick={() => field.onChange(!field.value)}
|
||||
className={
|
||||
field.value
|
||||
? "flex size-4 shrink-0 items-center justify-center rounded-[4px] bg-primary text-primary-foreground ring-offset-background transition-colors"
|
||||
: "flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input bg-background ring-offset-background transition-colors hover:border-ring"
|
||||
}
|
||||
>
|
||||
{field.value && (
|
||||
<svg
|
||||
width="10"
|
||||
height="10"
|
||||
viewBox="0 0 10 10"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M2 5.5L4 7.5L8 3"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
<>
|
||||
<input
|
||||
id="mark-as-pending"
|
||||
type="checkbox"
|
||||
checked={field.value}
|
||||
onChange={(e) => field.onChange(e.target.checked)}
|
||||
className="peer sr-only"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
<span
|
||||
className={`flex size-4 shrink-0 items-center justify-center rounded-[4px] ring-offset-background transition-colors peer-focus-visible:ring-3 peer-focus-visible:ring-ring/50 ${
|
||||
field.value
|
||||
? "bg-primary text-primary-foreground"
|
||||
: "border border-input bg-background hover:border-ring"
|
||||
}`}
|
||||
>
|
||||
{field.value && <Check className="size-3" />}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
<span>Marcar como pendiente</span>
|
||||
|
||||
@@ -18,8 +18,8 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { useExpensesContext } from "../ExpensesProvider";
|
||||
import { useQuotes, useWallets } from "@/lib/queries";
|
||||
import { useExpensesContext } from "../ExpensesProvider";
|
||||
|
||||
const newExpenseSchema = z.object({
|
||||
description: z
|
||||
@@ -175,7 +175,9 @@ export function NewExpenseDialog({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label className="text-sm font-medium">Billetera</label>
|
||||
<label htmlFor="expense-wallet" className="text-sm font-medium">
|
||||
Billetera
|
||||
</label>
|
||||
<Controller
|
||||
control={control}
|
||||
name="walletId"
|
||||
@@ -184,7 +186,7 @@ export function NewExpenseDialog({
|
||||
value={field.value ? String(field.value) : ""}
|
||||
onValueChange={(v) => field.onChange(Number(v))}
|
||||
>
|
||||
<SelectTrigger className="h-8 w-full">
|
||||
<SelectTrigger id="expense-wallet" className="h-8 w-full">
|
||||
<SelectValue placeholder="Seleccionar billetera" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
|
||||
@@ -19,8 +19,8 @@ import {
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import type { Expense } from "@/lib/api";
|
||||
import { useExpensesContext } from "../ExpensesProvider";
|
||||
import { useQuotes, useWallets } from "@/lib/queries";
|
||||
import { useExpensesContext } from "../ExpensesProvider";
|
||||
|
||||
const paySchema = z.object({
|
||||
amountPayed: z.number().positive("El monto debe ser mayor a 0"),
|
||||
@@ -194,7 +194,9 @@ export function PayExpenseDialog({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label className="text-sm font-medium">Billetera</label>
|
||||
<label htmlFor="pay-expense-wallet" className="text-sm font-medium">
|
||||
Billetera
|
||||
</label>
|
||||
<Controller
|
||||
control={control}
|
||||
name="walletId"
|
||||
@@ -203,7 +205,7 @@ export function PayExpenseDialog({
|
||||
value={field.value ? String(field.value) : ""}
|
||||
onValueChange={(v) => field.onChange(Number(v))}
|
||||
>
|
||||
<SelectTrigger className="h-8 w-full">
|
||||
<SelectTrigger id="pay-expense-wallet" className="h-8 w-full">
|
||||
<SelectValue placeholder="Seleccionar billetera" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { useSearch } from "@tanstack/react-router";
|
||||
import {
|
||||
type ColumnDef,
|
||||
flexRender,
|
||||
getCoreRowModel,
|
||||
useReactTable,
|
||||
} from "@tanstack/react-table";
|
||||
import { subMonths, startOfMonth } from "date-fns";
|
||||
import { startOfMonth, subMonths } from "date-fns";
|
||||
import {
|
||||
ChevronsLeftIcon,
|
||||
ChevronsRightIcon,
|
||||
@@ -14,7 +15,6 @@ import {
|
||||
SkipForwardIcon,
|
||||
} from "lucide-react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useSearch } from "@tanstack/react-router";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DatePicker } from "@/components/ui/date-picker";
|
||||
import {
|
||||
@@ -40,6 +40,8 @@ const amountFormatter = new Intl.NumberFormat("es-AR", {
|
||||
maximumFractionDigits: 4,
|
||||
});
|
||||
|
||||
const PAGE_SIZE = 20;
|
||||
|
||||
const dateFormatter = new Intl.DateTimeFormat("es-AR", {
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
@@ -60,8 +62,7 @@ function TypeBadge({ type }: { type: string }) {
|
||||
const styles: Record<string, string> = {
|
||||
DEPOSIT:
|
||||
"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400",
|
||||
WITHDRAWAL:
|
||||
"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",
|
||||
WITHDRAWAL: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",
|
||||
TRANSFER_IN:
|
||||
"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
|
||||
TRANSFER_OUT:
|
||||
@@ -97,7 +98,6 @@ export function WalletMovementsPage() {
|
||||
const [endDate, setEndDate] = useState<Date | undefined>(today);
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const pageSize = 20;
|
||||
|
||||
const filter: WalletMovementsFilter = useMemo(
|
||||
() => ({
|
||||
@@ -105,9 +105,9 @@ export function WalletMovementsPage() {
|
||||
startDate: startDate?.toISOString(),
|
||||
endDate: endDate?.toISOString(),
|
||||
page,
|
||||
pageSize,
|
||||
pageSize: PAGE_SIZE,
|
||||
}),
|
||||
[walletId, startDate, endDate, page, pageSize],
|
||||
[walletId, startDate, endDate, page],
|
||||
);
|
||||
|
||||
const { data: result, isLoading } = useWalletMovementsFiltered(filter);
|
||||
@@ -142,9 +142,7 @@ export function WalletMovementsPage() {
|
||||
header: "Billetera",
|
||||
id: "walletName",
|
||||
cell: ({ row }) => {
|
||||
const w = wallets?.find(
|
||||
(w) => w.id === row.original.walletId,
|
||||
);
|
||||
const w = wallets?.find((w) => w.id === row.original.walletId);
|
||||
return w ? (
|
||||
<span className="text-xs text-muted-foreground">{w.name}</span>
|
||||
) : null;
|
||||
@@ -192,13 +190,13 @@ export function WalletMovementsPage() {
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
});
|
||||
|
||||
const totalPages = Math.max(1, Math.ceil(total / pageSize));
|
||||
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
|
||||
const GROUP_SIZE = 3;
|
||||
const currentGroup = Math.floor((page - 1) / GROUP_SIZE);
|
||||
const startPage = currentGroup * GROUP_SIZE + 1;
|
||||
const endPage = Math.min(startPage + GROUP_SIZE - 1, totalPages);
|
||||
const firstItem = total === 0 ? 0 : (page - 1) * pageSize + 1;
|
||||
const lastItem = Math.min(page * pageSize, total);
|
||||
const firstItem = total === 0 ? 0 : (page - 1) * PAGE_SIZE + 1;
|
||||
const lastItem = Math.min(page * PAGE_SIZE, total);
|
||||
|
||||
const mobilePagination =
|
||||
total > 0 ? (
|
||||
@@ -233,7 +231,10 @@ export function WalletMovementsPage() {
|
||||
|
||||
<div className="flex flex-wrap items-end gap-3">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label className="text-xs font-medium text-muted-foreground">
|
||||
<label
|
||||
htmlFor="filter-wallet"
|
||||
className="text-xs font-medium text-muted-foreground"
|
||||
>
|
||||
Billetera
|
||||
</label>
|
||||
<Select
|
||||
@@ -243,13 +244,11 @@ export function WalletMovementsPage() {
|
||||
setPage(1);
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="h-8 w-44">
|
||||
<SelectTrigger id="filter-wallet" className="h-8 w-44">
|
||||
<SelectValue placeholder="Todas las billeteras" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">
|
||||
Todas las billeteras
|
||||
</SelectItem>
|
||||
<SelectItem value="all">Todas las billeteras</SelectItem>
|
||||
{wallets?.map((w: Wallet) => (
|
||||
<SelectItem key={w.id} value={String(w.id)}>
|
||||
{w.name} ({w.currency})
|
||||
@@ -260,10 +259,14 @@ export function WalletMovementsPage() {
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label className="text-xs font-medium text-muted-foreground">
|
||||
<label
|
||||
htmlFor="filter-start-date"
|
||||
className="text-xs font-medium text-muted-foreground"
|
||||
>
|
||||
Desde
|
||||
</label>
|
||||
<DatePicker
|
||||
id="filter-start-date"
|
||||
value={startDate}
|
||||
onChange={(d) => {
|
||||
setStartDate(d);
|
||||
@@ -274,10 +277,14 @@ export function WalletMovementsPage() {
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label className="text-xs font-medium text-muted-foreground">
|
||||
<label
|
||||
htmlFor="filter-end-date"
|
||||
className="text-xs font-medium text-muted-foreground"
|
||||
>
|
||||
Hasta
|
||||
</label>
|
||||
<DatePicker
|
||||
id="filter-end-date"
|
||||
value={endDate}
|
||||
onChange={(d) => {
|
||||
setEndDate(d);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState } from "react";
|
||||
import { Plus } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { useWallets } from "@/lib/queries";
|
||||
import { WalletCard } from "./components/WalletCard";
|
||||
import { CreateWalletDialog } from "./components/CreateWalletDialog";
|
||||
import { WalletCard } from "./components/WalletCard";
|
||||
|
||||
export function WalletsPage() {
|
||||
const { data: wallets, isLoading } = useWallets();
|
||||
|
||||
@@ -9,8 +9,8 @@ import {
|
||||
ResponsiveDialogHeader,
|
||||
ResponsiveDialogTitle,
|
||||
} from "@/components/ui/responsive-dialog";
|
||||
import { useAdjustBalance } from "@/lib/queries";
|
||||
import type { Wallet } from "@/lib/api";
|
||||
import { useAdjustBalance } from "@/lib/queries";
|
||||
|
||||
const adjustSchema = z.object({
|
||||
newBalance: z.number().min(0, "El saldo no puede ser negativo"),
|
||||
|
||||
@@ -9,8 +9,8 @@ import {
|
||||
ResponsiveDialogHeader,
|
||||
ResponsiveDialogTitle,
|
||||
} from "@/components/ui/responsive-dialog";
|
||||
import { useDepositWallet } from "@/lib/queries";
|
||||
import type { Wallet } from "@/lib/api";
|
||||
import { useDepositWallet } from "@/lib/queries";
|
||||
|
||||
const depositSchema = z.object({
|
||||
amount: z.number().positive("El monto debe ser mayor a 0"),
|
||||
|
||||
@@ -16,8 +16,8 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { useUpdateWallet } from "@/lib/queries";
|
||||
import type { Wallet } from "@/lib/api";
|
||||
import { useUpdateWallet } from "@/lib/queries";
|
||||
|
||||
const editWalletSchema = z.object({
|
||||
name: z.string().min(1, "El nombre es obligatorio").max(100),
|
||||
@@ -128,11 +128,7 @@ export function EditWalletDialog({
|
||||
>
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
form="edit-wallet-form"
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
<Button type="submit" form="edit-wallet-form" disabled={isSubmitting}>
|
||||
Guardar
|
||||
</Button>
|
||||
</ResponsiveDialogFooter>
|
||||
|
||||
@@ -16,8 +16,8 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { useTransferWallet, useWallets } from "@/lib/queries";
|
||||
import type { Wallet } from "@/lib/api";
|
||||
import { useTransferWallet, useWallets } from "@/lib/queries";
|
||||
|
||||
const transferSchema = z.object({
|
||||
toWalletId: z.number().positive("Seleccioná una billetera destino"),
|
||||
@@ -42,8 +42,7 @@ export function TransferDialog({
|
||||
const { data: wallets } = useWallets();
|
||||
const transfer = useTransferWallet();
|
||||
|
||||
const otherWallets =
|
||||
wallets?.filter((w) => w.id !== sourceWallet.id) ?? [];
|
||||
const otherWallets = wallets?.filter((w) => w.id !== sourceWallet.id) ?? [];
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -96,7 +95,9 @@ export function TransferDialog({
|
||||
className="flex flex-col gap-4"
|
||||
>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label className="text-sm font-medium">Billetera destino</label>
|
||||
<label htmlFor="transfer-to-wallet" className="text-sm font-medium">
|
||||
Billetera destino
|
||||
</label>
|
||||
<Controller
|
||||
control={control}
|
||||
name="toWalletId"
|
||||
@@ -105,7 +106,7 @@ export function TransferDialog({
|
||||
value={field.value ? String(field.value) : ""}
|
||||
onValueChange={(v) => field.onChange(Number(v))}
|
||||
>
|
||||
<SelectTrigger className="h-8">
|
||||
<SelectTrigger id="transfer-to-wallet" className="h-8">
|
||||
<SelectValue placeholder="Seleccionar destino" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
@@ -126,10 +127,7 @@ export function TransferDialog({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label
|
||||
htmlFor="transfer-outgoing"
|
||||
className="text-sm font-medium"
|
||||
>
|
||||
<label htmlFor="transfer-outgoing" className="text-sm font-medium">
|
||||
Monto saliente (de {sourceWallet.name})
|
||||
</label>
|
||||
<input
|
||||
@@ -149,10 +147,7 @@ export function TransferDialog({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label
|
||||
htmlFor="transfer-incoming"
|
||||
className="text-sm font-medium"
|
||||
>
|
||||
<label htmlFor="transfer-incoming" className="text-sm font-medium">
|
||||
Monto entrante (en destino)
|
||||
</label>
|
||||
<input
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import {
|
||||
ArrowDownToLine,
|
||||
ArrowLeftRight,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
PencilLine,
|
||||
Star,
|
||||
} from "lucide-react";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Tooltip,
|
||||
@@ -17,10 +17,10 @@ import {
|
||||
} from "@/components/ui/tooltip";
|
||||
import type { Wallet } from "@/lib/api";
|
||||
import { useSetDefaultWallet } from "@/lib/queries";
|
||||
import { DepositDialog } from "./DepositDialog";
|
||||
import { AdjustBalanceDialog } from "./AdjustBalanceDialog";
|
||||
import { TransferDialog } from "./TransferDialog";
|
||||
import { DepositDialog } from "./DepositDialog";
|
||||
import { EditWalletDialog } from "./EditWalletDialog";
|
||||
import { TransferDialog } from "./TransferDialog";
|
||||
|
||||
const balanceFormatter = new Intl.NumberFormat("es-AR", {
|
||||
minimumFractionDigits: 2,
|
||||
@@ -148,7 +148,10 @@ export function WalletCard({ wallet }: WalletCardProps) {
|
||||
size="icon"
|
||||
className="size-8"
|
||||
onClick={() =>
|
||||
navigate({ to: "/wallets/movements", search: { walletId: wallet.id } })
|
||||
navigate({
|
||||
to: "/wallets/movements",
|
||||
search: { walletId: wallet.id },
|
||||
})
|
||||
}
|
||||
>
|
||||
<History className="size-4" />
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useWalletMovements } from "@/lib/queries";
|
||||
import type { Wallet } from "@/lib/api";
|
||||
import {
|
||||
ResponsiveDialog,
|
||||
ResponsiveDialogContent,
|
||||
ResponsiveDialogHeader,
|
||||
ResponsiveDialogTitle,
|
||||
} from "@/components/ui/responsive-dialog";
|
||||
import type { Wallet } from "@/lib/api";
|
||||
import { useWalletMovements } from "@/lib/queries";
|
||||
|
||||
const amountFormatter = new Intl.NumberFormat("es-AR", {
|
||||
minimumFractionDigits: 2,
|
||||
@@ -62,7 +62,9 @@ export function WalletMovementsDialog({
|
||||
className="flex items-center justify-between rounded-md p-2 text-sm hover:bg-muted/50"
|
||||
>
|
||||
<div className="flex flex-col">
|
||||
<span className="font-medium">{typeLabels[m.type] ?? m.type}</span>
|
||||
<span className="font-medium">
|
||||
{typeLabels[m.type] ?? m.type}
|
||||
</span>
|
||||
{m.description && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{m.description}
|
||||
|
||||
@@ -2,6 +2,9 @@ import { createFileRoute, redirect } from "@tanstack/react-router";
|
||||
|
||||
export const Route = createFileRoute("/_authenticated/quotes/belo/analysis")({
|
||||
loader: () => {
|
||||
throw redirect({ to: "/quotes/analysis/$currency", params: { currency: "BELO" } });
|
||||
throw redirect({
|
||||
to: "/quotes/analysis/$currency",
|
||||
params: { currency: "BELO" },
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.4.16/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/2.5.10/schema.json",
|
||||
"vcs": {
|
||||
"enabled": true,
|
||||
"clientKind": "git",
|
||||
@@ -21,7 +21,7 @@
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true
|
||||
"preset": "recommended"
|
||||
}
|
||||
},
|
||||
"javascript": {
|
||||
|
||||
Reference in New Issue
Block a user