Files
openmonetis/components/ajustes/update-name-form.tsx
Felipe Coutinho a7f63fb77a refactor: migrate from ESLint to Biome and extract SQL queries to data.ts
- Replace ESLint with Biome for linting and formatting
- Configure Biome with tabs, double quotes, and organized imports
- Move all SQL/Drizzle queries from page.tsx files to data.ts files
- Create new data.ts files for: ajustes, dashboard, relatorios/categorias
- Update existing data.ts files: extrato, fatura (add lancamentos queries)
- Remove all drizzle-orm imports from page.tsx files
- Update README.md with new tooling info

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 13:15:37 +00:00

76 lines
1.9 KiB
TypeScript

"use client";
import { useState, useTransition } from "react";
import { toast } from "sonner";
import { updateNameAction } from "@/app/(dashboard)/ajustes/actions";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
type UpdateNameFormProps = {
currentName: string;
};
export function UpdateNameForm({ currentName }: UpdateNameFormProps) {
const [isPending, startTransition] = useTransition();
// Dividir o nome atual em primeiro nome e sobrenome
const nameParts = currentName.split(" ");
const initialFirstName = nameParts[0] || "";
const initialLastName = nameParts.slice(1).join(" ") || "";
const [firstName, setFirstName] = useState(initialFirstName);
const [lastName, setLastName] = useState(initialLastName);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
startTransition(async () => {
const result = await updateNameAction({
firstName,
lastName,
});
if (result.success) {
toast.success(result.message);
} else {
toast.error(result.error);
}
});
};
return (
<form onSubmit={handleSubmit} className="flex flex-col space-y-6">
<div className="space-y-4 max-w-md">
<div className="space-y-2">
<Label htmlFor="firstName">Primeiro nome</Label>
<Input
id="firstName"
value={firstName}
onChange={(e) => setFirstName(e.target.value)}
disabled={isPending}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="lastName">Sobrenome</Label>
<Input
id="lastName"
value={lastName}
onChange={(e) => setLastName(e.target.value)}
disabled={isPending}
required
/>
</div>
</div>
<div className="flex justify-end">
<Button type="submit" disabled={isPending} className="w-fit">
{isPending ? "Atualizando..." : "Atualizar nome"}
</Button>
</div>
</form>
);
}