forked from git.gladyson/openmonetis
Adiciona sistema completo de preferências de usuário: - Cria tabela userPreferences no schema com campos disableMagnetlines, periodMonthsBefore e periodMonthsAfter - Implementa página de Ajustes com abas (Preferências, Alterar nome, Senha, E-mail, Deletar conta) - Adiciona componente PreferencesForm para configuração de magnetlines e períodos de exibição - Propaga periodPreferences para todos os componentes de lançamentos e calendário Refatora sistema de changelog: - Remove implementação anterior baseada em JSON estático - Adiciona nova página de changelog dinâmica em app/(dashboard)/changelog - Adiciona componente changelog-list.tsx - Remove arquivos obsoletos (changelog-notification, actions, data, utils, scripts) Adiciona controle de saldo inicial em contas: - Novo campo excludeInitialBalanceFromIncome em contas - Permite excluir saldo inicial do cálculo de receitas - Atualiza queries de lançamentos para respeitar esta configuração Melhorias adicionais: - Adiciona componente ui/accordion.tsx do shadcn/ui - Refatora formatPeriodLabel para displayPeriod centralizado - Propaga estabelecimentos para componentes de lançamentos - Remove variável DB_PROVIDER obsoleta do .env.example e documentação - Adiciona 6 migrações de banco de dados (0003-0008)
137 lines
4.0 KiB
TypeScript
137 lines
4.0 KiB
TypeScript
"use client";
|
|
import { deleteAccountAction } from "@/app/(dashboard)/ajustes/actions";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "@/components/ui/dialog";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Label } from "@/components/ui/label";
|
|
import { authClient } from "@/lib/auth/client";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState, useTransition } from "react";
|
|
import { toast } from "sonner";
|
|
|
|
export function DeleteAccountForm() {
|
|
const router = useRouter();
|
|
const [isPending, startTransition] = useTransition();
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
const [confirmation, setConfirmation] = useState("");
|
|
|
|
const handleDelete = () => {
|
|
startTransition(async () => {
|
|
const result = await deleteAccountAction({
|
|
confirmation,
|
|
});
|
|
|
|
if (result.success) {
|
|
toast.success(result.message);
|
|
// Fazer logout e redirecionar para página de login
|
|
await authClient.signOut();
|
|
router.push("/");
|
|
} else {
|
|
toast.error(result.error);
|
|
}
|
|
});
|
|
};
|
|
|
|
const handleOpenModal = () => {
|
|
setConfirmation("");
|
|
setIsModalOpen(true);
|
|
};
|
|
|
|
const handleCloseModal = () => {
|
|
if (isPending) return;
|
|
setConfirmation("");
|
|
setIsModalOpen(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<div className="flex flex-col space-y-6">
|
|
<div className="space-y-4 max-w-md">
|
|
<ul className="list-disc list-inside text-sm text-destructive space-y-1">
|
|
<li>Lançamentos, orçamentos e anotações</li>
|
|
<li>Contas, cartões e categorias</li>
|
|
<li>Pagadores (incluindo o pagador padrão)</li>
|
|
<li>Preferências e configurações</li>
|
|
<li className="font-bold">
|
|
Resumindo tudo, sua conta será permanentemente removida
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div className="flex justify-end">
|
|
<Button
|
|
variant="destructive"
|
|
onClick={handleOpenModal}
|
|
disabled={isPending}
|
|
className="w-fit"
|
|
>
|
|
Deletar conta
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
<Dialog open={isModalOpen} onOpenChange={setIsModalOpen}>
|
|
<DialogContent
|
|
className="max-w-md"
|
|
onEscapeKeyDown={(e) => {
|
|
if (isPending) e.preventDefault();
|
|
}}
|
|
onPointerDownOutside={(e) => {
|
|
if (isPending) e.preventDefault();
|
|
}}
|
|
>
|
|
<DialogHeader>
|
|
<DialogTitle>Você tem certeza?</DialogTitle>
|
|
<DialogDescription>
|
|
Essa ação não pode ser desfeita. Isso irá deletar permanentemente
|
|
sua conta e remover seus dados de nossos servidores.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<div className="space-y-4 py-4">
|
|
<div className="space-y-2">
|
|
<Label htmlFor="confirmation">
|
|
Para confirmar, digite <strong>DELETAR</strong> no campo abaixo.
|
|
</Label>
|
|
<Input
|
|
id="confirmation"
|
|
value={confirmation}
|
|
onChange={(e) => setConfirmation(e.target.value)}
|
|
disabled={isPending}
|
|
placeholder="DELETAR"
|
|
autoComplete="off"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<DialogFooter className="sm:justify-end">
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
onClick={handleCloseModal}
|
|
disabled={isPending}
|
|
>
|
|
Cancelar
|
|
</Button>
|
|
<Button
|
|
type="button"
|
|
variant="destructive"
|
|
onClick={handleDelete}
|
|
disabled={isPending || confirmation !== "DELETAR"}
|
|
>
|
|
{isPending ? "Deletando..." : "Deletar"}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</>
|
|
);
|
|
}
|