Frontend completo (Etapas 11-18) e extensões de backend (Etapas 13 e 18)
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>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import { apiClient } from '@/lib/api/client';
|
||||
import { buildQuery, type PaginatedResult } from '@/lib/api/types';
|
||||
import type { Fatura } from '@/lib/api/faturas';
|
||||
|
||||
export type TenantStatus = 'trial' | 'ativo' | 'inadimplente' | 'suspenso' | 'cancelado';
|
||||
/** `trial` só é atribuído automaticamente na criação — nunca é um destino válido de transição manual. */
|
||||
export type TenantStatusTransition = Exclude<TenantStatus, 'trial'>;
|
||||
|
||||
interface TenantPlanoSummary {
|
||||
id: string;
|
||||
nome: string;
|
||||
valor_mensal: string;
|
||||
}
|
||||
|
||||
/** Espelha o model `tenants`, versão de listagem (`plano` selecionado, sem `faturas`/`_count`). */
|
||||
export interface TenantListItem {
|
||||
id: string;
|
||||
razao_social: string;
|
||||
nome_fantasia: string | null;
|
||||
documento: string | null;
|
||||
email_contato: string;
|
||||
telefone: string | null;
|
||||
logo_url: string | null;
|
||||
cor_primaria: string | null;
|
||||
plano_id: string;
|
||||
status: TenantStatus;
|
||||
dia_vencimento_mensalidade: number;
|
||||
trial_expira_em: string | null;
|
||||
criado_em: string;
|
||||
atualizado_em: string;
|
||||
plano: TenantPlanoSummary;
|
||||
}
|
||||
|
||||
/** `GET /master/tenants/:id` — inclui as últimas 5 faturas e contagem de uso. */
|
||||
export interface TenantDetail extends Omit<TenantListItem, 'plano'> {
|
||||
plano: TenantPlanoSummary & { limite_customers: number | null; limite_usuarios: number | null };
|
||||
faturas: Fatura[];
|
||||
_count: { usuarios: number; customers: number; vendas: number };
|
||||
}
|
||||
|
||||
export interface TenantAdminCreated {
|
||||
id: string;
|
||||
nome: string;
|
||||
email: string;
|
||||
senha_provisoria: string;
|
||||
}
|
||||
|
||||
export interface CreateTenantResult {
|
||||
tenant: TenantListItem;
|
||||
admin: TenantAdminCreated;
|
||||
}
|
||||
|
||||
/** Espelha `CreateTenantDto` (`src/modules/tenants/dto/create-tenant.dto.ts`). */
|
||||
export interface CreateTenantInput {
|
||||
razao_social: string;
|
||||
nome_fantasia?: string;
|
||||
documento?: string;
|
||||
email_contato: string;
|
||||
telefone?: string;
|
||||
plano_id: string;
|
||||
dia_vencimento_mensalidade?: number;
|
||||
admin: {
|
||||
nome: string;
|
||||
email: string;
|
||||
senha?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** Espelha `UpdateTenantDto` — mesmos campos cadastrais, sem `admin`/`status`. */
|
||||
export type UpdateTenantInput = Partial<Omit<CreateTenantInput, 'admin'>>;
|
||||
|
||||
export interface ListTenantsParams {
|
||||
status?: TenantStatus;
|
||||
busca?: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export function listTenants(params: ListTenantsParams) {
|
||||
return apiClient.get<PaginatedResult<TenantListItem>>(`/master/tenants${buildQuery(params)}`);
|
||||
}
|
||||
|
||||
export function getTenant(id: string) {
|
||||
return apiClient.get<TenantDetail>(`/master/tenants/${id}`);
|
||||
}
|
||||
|
||||
export function createTenant(input: CreateTenantInput) {
|
||||
return apiClient.post<CreateTenantResult>('/master/tenants', input);
|
||||
}
|
||||
|
||||
export function updateTenant(id: string, input: UpdateTenantInput) {
|
||||
return apiClient.put<TenantListItem>(`/master/tenants/${id}`, input);
|
||||
}
|
||||
|
||||
export function updateTenantStatus(id: string, status: TenantStatusTransition) {
|
||||
return apiClient.patch<TenantListItem>(`/master/tenants/${id}/status`, { status });
|
||||
}
|
||||
Reference in New Issue
Block a user