BREAKING CHANGE: Remove feature de seleção de período das preferências do usuário
Alterações principais:
- Adiciona sistema completo de relatórios por categoria
- Cria página /relatorios/categorias com filtros e visualizações
- Implementa tabela e gráfico de evolução mensal
- Adiciona funcionalidade de exportação de dados
- Cria skeleton otimizado para melhor UX de loading
- Remove feature de seleção de período das preferências
- Deleta lib/user-preferences/period.ts
- Remove colunas periodMonthsBefore e periodMonthsAfter do schema
- Remove todas as referências em 16+ arquivos
- Atualiza database schema via Drizzle
- Substitui Select de período por MonthPicker visual
- Implementa componente PeriodPicker reutilizável
- Integra shadcn MonthPicker customizado (português, Remix icons)
- Substitui createMonthOptions em todos os formulários
- Mantém formato "YYYY-MM" no banco de dados
- Melhora design da tabela de relatórios
- Mescla colunas Categoria e Tipo em uma única coluna
- Substitui badge de tipo por dot colorido discreto
- Reduz largura da tabela em ~120px
- Atualiza skeleton para refletir nova estrutura
- Melhorias gerais de UI
- Reduz espaçamento entre títulos da sidebar (p-2 → px-2 py-1)
- Adiciona MonthNavigation para navegação entre períodos
- Otimiza loading states com skeletons detalhados
79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
"use client";
|
|
|
|
import { updatePreferencesAction } from "@/app/(dashboard)/ajustes/actions";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Label } from "@/components/ui/label";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState, useTransition } from "react";
|
|
import { toast } from "sonner";
|
|
|
|
interface PreferencesFormProps {
|
|
disableMagnetlines: boolean;
|
|
}
|
|
|
|
export function PreferencesForm({
|
|
disableMagnetlines,
|
|
}: PreferencesFormProps) {
|
|
const router = useRouter();
|
|
const [isPending, startTransition] = useTransition();
|
|
const [magnetlinesDisabled, setMagnetlinesDisabled] =
|
|
useState(disableMagnetlines);
|
|
|
|
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
|
event.preventDefault();
|
|
|
|
startTransition(async () => {
|
|
const result = await updatePreferencesAction({
|
|
disableMagnetlines: magnetlinesDisabled,
|
|
});
|
|
|
|
if (result.success) {
|
|
toast.success(result.message);
|
|
// Recarregar a página para aplicar as mudanças nos componentes
|
|
router.refresh();
|
|
// Forçar reload completo para garantir que os hooks re-executem
|
|
setTimeout(() => {
|
|
window.location.reload();
|
|
}, 500);
|
|
} 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="flex items-center justify-between rounded-lg border border-dashed p-4">
|
|
<div className="space-y-0.5">
|
|
<Label htmlFor="magnetlines" className="text-base">
|
|
Desabilitar Magnetlines
|
|
</Label>
|
|
<p className="text-sm text-muted-foreground">
|
|
Remove o recurso de linhas magnéticas do sistema. Essa mudança
|
|
afeta a interface e interações visuais.
|
|
</p>
|
|
</div>
|
|
<Switch
|
|
id="magnetlines"
|
|
checked={magnetlinesDisabled}
|
|
onCheckedChange={setMagnetlinesDisabled}
|
|
disabled={isPending}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex justify-end">
|
|
<Button type="submit" disabled={isPending} className="w-fit">
|
|
{isPending ? "Salvando..." : "Salvar preferências"}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|