Adiciona o frontend Next.js em frontend/ (setup, design system, autenticação/tema, layout/navegação, área master, área tenant completa: clientes, produtos, vendas, recebimentos, whatsapp, e-mail, alertas, equipe e perfil). Estende o backend de forma aditiva e autorizada: cookie httpOnly para refresh token (Etapa 13) e CRUD de equipe + edição de perfil do tenant (Etapa 18, módulo src/modules/equipe/ novo e PUT /tenant/perfil). Detalhes completos em Etapas/V2/*. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
'use client';
|
|
|
|
import { useRouter } from 'next/navigation';
|
|
import { useMutation } from '@tanstack/react-query';
|
|
|
|
import { createSale, type SaleInput } from '@/lib/api/sales';
|
|
import type { SaleFormValues } from '@/lib/validators/sales';
|
|
import { ApiError } from '@/lib/api/client';
|
|
import { toast } from '@/lib/toast';
|
|
import { VendaForm } from '@/components/domain/venda-form';
|
|
|
|
function todayIso(): string {
|
|
return new Date().toISOString().slice(0, 10);
|
|
}
|
|
|
|
const DEFAULT_VALUES: SaleFormValues = {
|
|
customer_id: '',
|
|
data_venda: todayIso(),
|
|
desconto: 0,
|
|
observacoes: '',
|
|
itens: [],
|
|
modoParcelas: 'automatico',
|
|
numeroParcelas: 1,
|
|
parcelasManuais: [],
|
|
};
|
|
|
|
export default function NovaVendaPage() {
|
|
const router = useRouter();
|
|
|
|
const draftMutation = useMutation({
|
|
mutationFn: (input: SaleInput) => createSale({ ...input, status: 'orcamento' }),
|
|
onSuccess: (sale) => {
|
|
toast.success('Orçamento salvo.');
|
|
router.push(`/app/vendas/${sale.id}`);
|
|
},
|
|
onError: (err) => {
|
|
toast.error(err instanceof ApiError ? err.message : 'Não foi possível salvar o orçamento.');
|
|
},
|
|
});
|
|
|
|
const confirmMutation = useMutation({
|
|
mutationFn: (input: SaleInput) => createSale({ ...input, status: 'confirmada' }),
|
|
onSuccess: (sale) => {
|
|
toast.success('Venda confirmada.');
|
|
router.push(`/app/vendas/${sale.id}`);
|
|
},
|
|
onError: (err) => {
|
|
toast.error(err instanceof ApiError ? err.message : 'Não foi possível confirmar a venda.');
|
|
},
|
|
});
|
|
|
|
return (
|
|
<div className="flex flex-col gap-6">
|
|
<div>
|
|
<h1 className="text-xl font-semibold text-foreground">Nova venda</h1>
|
|
<p className="text-sm text-muted-foreground">Registre uma venda com itens e parcelas</p>
|
|
</div>
|
|
|
|
<VendaForm
|
|
mode="create"
|
|
defaultValues={DEFAULT_VALUES}
|
|
submittingDraft={draftMutation.isPending}
|
|
submittingConfirmOrSave={confirmMutation.isPending}
|
|
onSaveDraft={(input) => draftMutation.mutate(input)}
|
|
onConfirmOrSave={(input) => confirmMutation.mutate(input)}
|
|
onCancel={() => router.push('/app/vendas')}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|