mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-09 11:01:45 +00:00
refactor: traduz dominio de payers no app
This commit is contained in:
@@ -3,8 +3,8 @@ import { fetchPendingInboxCount } from "@/features/inbox/queries";
|
||||
import { AppNavbar } from "@/shared/components/navigation/navbar/app-navbar";
|
||||
import { PrivacyProvider } from "@/shared/components/providers/privacy-provider";
|
||||
import { getUserSession } from "@/shared/lib/auth/server";
|
||||
import { fetchPagadoresWithAccess } from "@/shared/lib/payers/access";
|
||||
import { PAGADOR_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import { fetchPayersWithAccess } from "@/shared/lib/payers/access";
|
||||
import { PAYER_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import { parsePeriodParam } from "@/shared/utils/period";
|
||||
|
||||
export default async function DashboardLayout({
|
||||
@@ -15,11 +15,11 @@ export default async function DashboardLayout({
|
||||
searchParams?: Promise<Record<string, string | string[] | undefined>>;
|
||||
}>) {
|
||||
const session = await getUserSession();
|
||||
const pagadoresList = await fetchPagadoresWithAccess(session.user.id);
|
||||
const payerList = await fetchPayersWithAccess(session.user.id);
|
||||
|
||||
// Encontrar o pagador admin do usuário
|
||||
const adminPagador = pagadoresList.find(
|
||||
(p) => p.role === PAGADOR_ROLE_ADMIN && p.userId === session.user.id,
|
||||
const adminPagador = payerList.find(
|
||||
(p) => p.role === PAYER_ROLE_ADMIN && p.userId === session.user.id,
|
||||
);
|
||||
|
||||
// Buscar notificações para o período atual
|
||||
|
||||
@@ -4,41 +4,41 @@ import {
|
||||
RiWallet3Line,
|
||||
} from "@remixicon/react";
|
||||
import { notFound } from "next/navigation";
|
||||
import { PagadorCardUsageCard } from "@/features/payers/components/details/payer-card-usage-card";
|
||||
import { PagadorHeaderCard } from "@/features/payers/components/details/payer-header-card";
|
||||
import { PagadorHistoryCard } from "@/features/payers/components/details/payer-history-card";
|
||||
import { PayerCardUsageCard } from "@/features/payers/components/details/payer-card-usage-card";
|
||||
import { PayerHeaderCard } from "@/features/payers/components/details/payer-header-card";
|
||||
import { PayerHistoryCard } from "@/features/payers/components/details/payer-history-card";
|
||||
import { PagadorInfoCard } from "@/features/payers/components/details/payer-info-card";
|
||||
import { PagadorLeaveShareCard } from "@/features/payers/components/details/payer-leave-share-card";
|
||||
import { PagadorMonthlySummaryCard } from "@/features/payers/components/details/payer-monthly-summary-card";
|
||||
import { PayerLeaveShareCard } from "@/features/payers/components/details/payer-leave-share-card";
|
||||
import { PayerMonthlySummaryCard } from "@/features/payers/components/details/payer-monthly-summary-card";
|
||||
import {
|
||||
PagadorBoletoCard,
|
||||
PagadorPaymentStatusCard,
|
||||
PayerBoletoCard,
|
||||
PayerPaymentStatusCard,
|
||||
} from "@/features/payers/components/details/payer-payment-method-cards";
|
||||
import { PagadorSharingCard } from "@/features/payers/components/details/payer-sharing-card";
|
||||
import { PayerSharingCard } from "@/features/payers/components/details/payer-sharing-card";
|
||||
import {
|
||||
fetchCurrentUserShare,
|
||||
fetchPagadorLancamentos,
|
||||
fetchPagadorShares,
|
||||
fetchPayerShares,
|
||||
} from "@/features/payers/detail-queries";
|
||||
import { buildReadOnlyOptionSets } from "@/features/payers/lib/build-readonly-option-sets";
|
||||
import { fetchUserPreferences } from "@/features/settings/queries";
|
||||
import { LancamentosPage as LancamentosSection } from "@/features/transactions/components/page/transactions-page";
|
||||
import { TransactionsPage as LancamentosSection } from "@/features/transactions/components/page/transactions-page";
|
||||
import {
|
||||
buildLancamentoWhere,
|
||||
buildOptionSets,
|
||||
buildSluggedFilters,
|
||||
buildSlugMaps,
|
||||
extractLancamentoSearchFilters,
|
||||
buildTransactionWhere,
|
||||
extractTransactionSearchFilters,
|
||||
getSingleParam,
|
||||
type LancamentoSearchFilters,
|
||||
mapLancamentosData,
|
||||
mapTransactionsData,
|
||||
type ResolvedSearchParams,
|
||||
type SluggedFilters,
|
||||
type SlugMaps,
|
||||
type TransactionSearchFilters,
|
||||
} from "@/features/transactions/page-helpers";
|
||||
import {
|
||||
fetchLancamentoFilterSources,
|
||||
fetchRecentEstablishments,
|
||||
fetchTransactionFilterSources,
|
||||
} from "@/features/transactions/queries";
|
||||
import { ExpandableWidgetCard } from "@/shared/components/expandable-widget-card";
|
||||
import MonthNavigation from "@/shared/components/month-picker/month-navigation";
|
||||
@@ -49,15 +49,15 @@ import {
|
||||
TabsTrigger,
|
||||
} from "@/shared/components/ui/tabs";
|
||||
import { getUserId } from "@/shared/lib/auth/server";
|
||||
import { getPagadorAccess } from "@/shared/lib/payers/access";
|
||||
import { getPayerAccess } from "@/shared/lib/payers/access";
|
||||
import {
|
||||
fetchPagadorBoletoItems,
|
||||
fetchPagadorBoletoStats,
|
||||
fetchPagadorCardUsage,
|
||||
fetchPagadorHistory,
|
||||
fetchPagadorMonthlyBreakdown,
|
||||
fetchPagadorPaymentStatus,
|
||||
type PagadorCardUsageItem,
|
||||
fetchPayerHistory,
|
||||
fetchPayerMonthlyBreakdown,
|
||||
type PayerCardUsageItem,
|
||||
} from "@/shared/lib/payers/details";
|
||||
import { parsePeriodParam } from "@/shared/utils/period";
|
||||
|
||||
@@ -71,31 +71,31 @@ type PageProps = {
|
||||
const capitalize = (value: string) =>
|
||||
value.length ? value.charAt(0).toUpperCase().concat(value.slice(1)) : value;
|
||||
|
||||
const EMPTY_FILTERS: LancamentoSearchFilters = {
|
||||
const EMPTY_FILTERS: TransactionSearchFilters = {
|
||||
transactionFilter: null,
|
||||
conditionFilter: null,
|
||||
paymentFilter: null,
|
||||
pagadorFilter: null,
|
||||
categoriaFilter: null,
|
||||
contaCartaoFilter: null,
|
||||
payerFilter: null,
|
||||
categoryFilter: null,
|
||||
accountCardFilter: null,
|
||||
searchFilter: null,
|
||||
};
|
||||
|
||||
const createEmptySlugMaps = (): SlugMaps => ({
|
||||
pagador: new Map(),
|
||||
categoria: new Map(),
|
||||
conta: new Map(),
|
||||
cartao: new Map(),
|
||||
payer: new Map(),
|
||||
category: new Map(),
|
||||
financialAccount: new Map(),
|
||||
card: new Map(),
|
||||
});
|
||||
|
||||
type OptionSet = ReturnType<typeof buildOptionSets>;
|
||||
|
||||
export default async function Page({ params, searchParams }: PageProps) {
|
||||
const { payerId: pagadorId } = await params;
|
||||
const { payerId } = await params;
|
||||
const userId = await getUserId();
|
||||
const resolvedSearchParams = searchParams ? await searchParams : undefined;
|
||||
|
||||
const access = await getPagadorAccess(userId, pagadorId);
|
||||
const access = await getPayerAccess(userId, payerId);
|
||||
|
||||
if (!access) {
|
||||
notFound();
|
||||
@@ -112,7 +112,8 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
} = parsePeriodParam(periodoParamRaw);
|
||||
const periodLabel = `${capitalize(monthName)} de ${year}`;
|
||||
|
||||
const allSearchFilters = extractLancamentoSearchFilters(resolvedSearchParams);
|
||||
const allSearchFilters =
|
||||
extractTransactionSearchFilters(resolvedSearchParams);
|
||||
const searchFilters = canEdit
|
||||
? allSearchFilters
|
||||
: {
|
||||
@@ -121,40 +122,40 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
};
|
||||
|
||||
let filterSources: Awaited<
|
||||
ReturnType<typeof fetchLancamentoFilterSources>
|
||||
ReturnType<typeof fetchTransactionFilterSources>
|
||||
> | null = null;
|
||||
let loggedUserFilterSources: Awaited<
|
||||
ReturnType<typeof fetchLancamentoFilterSources>
|
||||
ReturnType<typeof fetchTransactionFilterSources>
|
||||
> | null = null;
|
||||
let sluggedFilters: SluggedFilters;
|
||||
let slugMaps: SlugMaps;
|
||||
|
||||
if (canEdit) {
|
||||
filterSources = await fetchLancamentoFilterSources(dataOwnerId);
|
||||
filterSources = await fetchTransactionFilterSources(dataOwnerId);
|
||||
sluggedFilters = buildSluggedFilters(filterSources);
|
||||
slugMaps = buildSlugMaps(sluggedFilters);
|
||||
} else {
|
||||
// Buscar opções do usuário logado para usar ao importar
|
||||
loggedUserFilterSources = await fetchLancamentoFilterSources(userId);
|
||||
loggedUserFilterSources = await fetchTransactionFilterSources(userId);
|
||||
sluggedFilters = {
|
||||
pagadorFiltersRaw: [],
|
||||
categoriaFiltersRaw: [],
|
||||
contaFiltersRaw: [],
|
||||
cartaoFiltersRaw: [],
|
||||
payerFiltersRaw: [],
|
||||
categoryFiltersRaw: [],
|
||||
accountFiltersRaw: [],
|
||||
cardFiltersRaw: [],
|
||||
};
|
||||
slugMaps = createEmptySlugMaps();
|
||||
}
|
||||
|
||||
const filters = buildLancamentoWhere({
|
||||
const filters = buildTransactionWhere({
|
||||
userId: dataOwnerId,
|
||||
period: selectedPeriod,
|
||||
filters: searchFilters,
|
||||
slugMaps,
|
||||
pagadorId: pagador.id,
|
||||
payerId: pagador.id,
|
||||
});
|
||||
|
||||
const sharesPromise = canEdit
|
||||
? fetchPagadorShares(pagador.id)
|
||||
? fetchPayerShares(pagador.id)
|
||||
: Promise.resolve([]);
|
||||
|
||||
const currentUserSharePromise = !canEdit
|
||||
@@ -162,7 +163,7 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
: Promise.resolve(null);
|
||||
|
||||
const [
|
||||
lancamentoRows,
|
||||
transactionRows,
|
||||
monthlyBreakdown,
|
||||
historyData,
|
||||
cardUsage,
|
||||
@@ -175,34 +176,34 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
userPreferences,
|
||||
] = await Promise.all([
|
||||
fetchPagadorLancamentos(filters),
|
||||
fetchPagadorMonthlyBreakdown({
|
||||
fetchPayerMonthlyBreakdown({
|
||||
userId: dataOwnerId,
|
||||
pagadorId: pagador.id,
|
||||
payerId: pagador.id,
|
||||
period: selectedPeriod,
|
||||
}),
|
||||
fetchPagadorHistory({
|
||||
fetchPayerHistory({
|
||||
userId: dataOwnerId,
|
||||
pagadorId: pagador.id,
|
||||
payerId: pagador.id,
|
||||
period: selectedPeriod,
|
||||
}),
|
||||
fetchPagadorCardUsage({
|
||||
userId: dataOwnerId,
|
||||
pagadorId: pagador.id,
|
||||
payerId: pagador.id,
|
||||
period: selectedPeriod,
|
||||
}),
|
||||
fetchPagadorBoletoStats({
|
||||
userId: dataOwnerId,
|
||||
pagadorId: pagador.id,
|
||||
payerId: pagador.id,
|
||||
period: selectedPeriod,
|
||||
}),
|
||||
fetchPagadorBoletoItems({
|
||||
userId: dataOwnerId,
|
||||
pagadorId: pagador.id,
|
||||
payerId: pagador.id,
|
||||
period: selectedPeriod,
|
||||
}),
|
||||
fetchPagadorPaymentStatus({
|
||||
userId: dataOwnerId,
|
||||
pagadorId: pagador.id,
|
||||
payerId: pagador.id,
|
||||
period: selectedPeriod,
|
||||
}),
|
||||
sharesPromise,
|
||||
@@ -211,12 +212,12 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
fetchUserPreferences(userId),
|
||||
]);
|
||||
|
||||
const mappedLancamentos = mapLancamentosData(lancamentoRows);
|
||||
const lancamentosData = canEdit
|
||||
? mappedLancamentos
|
||||
: mappedLancamentos.map((item) => ({ ...item, readonly: true }));
|
||||
const mappedTransactions = mapTransactionsData(transactionRows);
|
||||
const transactionData = canEdit
|
||||
? mappedTransactions
|
||||
: mappedTransactions.map((item) => ({ ...item, readonly: true }));
|
||||
|
||||
const pagadorSharesData = shareRows;
|
||||
const payerSharesData = shareRows;
|
||||
|
||||
let optionSets: OptionSet;
|
||||
let loggedUserOptionSets: OptionSet | null = null;
|
||||
@@ -225,11 +226,11 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
if (canEdit && filterSources) {
|
||||
optionSets = buildOptionSets({
|
||||
...sluggedFilters,
|
||||
pagadorRows: filterSources.pagadorRows,
|
||||
payerRows: filterSources.payerRows,
|
||||
});
|
||||
} else {
|
||||
effectiveSluggedFilters = {
|
||||
pagadorFiltersRaw: [
|
||||
payerFiltersRaw: [
|
||||
{
|
||||
id: pagador.id,
|
||||
label: pagador.name,
|
||||
@@ -238,11 +239,11 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
avatarUrl: pagador.avatarUrl,
|
||||
},
|
||||
],
|
||||
categoriaFiltersRaw: [],
|
||||
contaFiltersRaw: [],
|
||||
cartaoFiltersRaw: [],
|
||||
categoryFiltersRaw: [],
|
||||
accountFiltersRaw: [],
|
||||
cardFiltersRaw: [],
|
||||
};
|
||||
optionSets = buildReadOnlyOptionSets(lancamentosData, pagador);
|
||||
optionSets = buildReadOnlyOptionSets(transactionData, pagador);
|
||||
|
||||
// Construir opções do usuário logado para usar ao importar
|
||||
if (loggedUserFilterSources) {
|
||||
@@ -251,23 +252,23 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
);
|
||||
loggedUserOptionSets = buildOptionSets({
|
||||
...loggedUserSluggedFilters,
|
||||
pagadorRows: loggedUserFilterSources.pagadorRows,
|
||||
payerRows: loggedUserFilterSources.payerRows,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const pagadorSlug =
|
||||
effectiveSluggedFilters.pagadorFiltersRaw.find(
|
||||
const payerSlug =
|
||||
effectiveSluggedFilters.payerFiltersRaw.find(
|
||||
(item) => item.id === pagador.id,
|
||||
)?.slug ?? null;
|
||||
|
||||
const pagadorFilterOptions = pagadorSlug
|
||||
? optionSets.pagadorFilterOptions.filter(
|
||||
(option) => option.slug === pagadorSlug,
|
||||
const payerFilterOptions = payerSlug
|
||||
? optionSets.payerFilterOptions.filter(
|
||||
(option) => option.slug === payerSlug,
|
||||
)
|
||||
: optionSets.pagadorFilterOptions;
|
||||
: optionSets.payerFilterOptions;
|
||||
|
||||
const pagadorData = {
|
||||
const payerData = {
|
||||
id: pagador.id,
|
||||
name: pagador.name,
|
||||
email: pagador.email ?? null,
|
||||
@@ -288,7 +289,7 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
periodLabel,
|
||||
totalExpenses: monthlyBreakdown.totalExpenses,
|
||||
paymentSplits: monthlyBreakdown.paymentSplits,
|
||||
cardUsage: cardUsage.slice(0, 3).map((item: PagadorCardUsageItem) => ({
|
||||
cardUsage: cardUsage.slice(0, 3).map((item: PayerCardUsageItem) => ({
|
||||
name: item.name,
|
||||
amount: item.amount,
|
||||
})),
|
||||
@@ -299,7 +300,7 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
paidCount: boletoStats.paidCount,
|
||||
pendingCount: boletoStats.pendingCount,
|
||||
},
|
||||
lancamentoCount: lancamentosData.length,
|
||||
lancamentoCount: transactionData.length,
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -312,25 +313,25 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
<TabsTrigger value="painel">Painel</TabsTrigger>
|
||||
<TabsTrigger value="lancamentos">Lançamentos</TabsTrigger>
|
||||
</TabsList>
|
||||
<PagadorHeaderCard
|
||||
pagador={pagadorData}
|
||||
<PayerHeaderCard
|
||||
payer={payerData}
|
||||
selectedPeriod={selectedPeriod}
|
||||
summary={summaryPreview}
|
||||
/>
|
||||
|
||||
<TabsContent value="profile" className="space-y-4">
|
||||
<PagadorInfoCard pagador={pagadorData} />
|
||||
{canEdit && pagadorData.shareCode ? (
|
||||
<PagadorSharingCard
|
||||
pagadorId={pagador.id}
|
||||
shareCode={pagadorData.shareCode}
|
||||
shares={pagadorSharesData}
|
||||
<PagadorInfoCard payer={payerData} />
|
||||
{canEdit && payerData.shareCode ? (
|
||||
<PayerSharingCard
|
||||
payerId={pagador.id}
|
||||
shareCode={payerData.shareCode}
|
||||
shares={payerSharesData}
|
||||
/>
|
||||
) : null}
|
||||
{!canEdit && currentUserShare ? (
|
||||
<PagadorLeaveShareCard
|
||||
<PayerLeaveShareCard
|
||||
shareId={currentUserShare.id}
|
||||
pagadorName={pagadorData.name}
|
||||
pagadorName={payerData.name}
|
||||
createdAt={currentUserShare.createdAt}
|
||||
/>
|
||||
) : null}
|
||||
@@ -338,11 +339,11 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
|
||||
<TabsContent value="painel" className="space-y-4">
|
||||
<section className="grid gap-3 lg:grid-cols-2">
|
||||
<PagadorMonthlySummaryCard
|
||||
<PayerMonthlySummaryCard
|
||||
periodLabel={periodLabel}
|
||||
breakdown={monthlyBreakdown}
|
||||
/>
|
||||
<PagadorHistoryCard data={historyData} />
|
||||
<PayerHistoryCard data={historyData} />
|
||||
</section>
|
||||
|
||||
<section className="grid gap-3 lg:grid-cols-3">
|
||||
@@ -351,21 +352,21 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
subtitle="Valores por cartão neste período"
|
||||
icon={<RiBankCard2Line className="size-4" />}
|
||||
>
|
||||
<PagadorCardUsageCard items={cardUsage} />
|
||||
<PayerCardUsageCard items={cardUsage} />
|
||||
</ExpandableWidgetCard>
|
||||
<ExpandableWidgetCard
|
||||
title="Boletos"
|
||||
subtitle="Boletos registrados neste período"
|
||||
icon={<RiBarcodeLine className="size-4" />}
|
||||
>
|
||||
<PagadorBoletoCard items={boletoItems} />
|
||||
<PayerBoletoCard items={boletoItems} />
|
||||
</ExpandableWidgetCard>
|
||||
<ExpandableWidgetCard
|
||||
title="Status de Pagamento"
|
||||
subtitle="Situação das despesas no período"
|
||||
icon={<RiWallet3Line className="size-4" />}
|
||||
>
|
||||
<PagadorPaymentStatusCard data={paymentStatus} />
|
||||
<PayerPaymentStatusCard data={paymentStatus} />
|
||||
</ExpandableWidgetCard>
|
||||
</section>
|
||||
</TabsContent>
|
||||
@@ -374,29 +375,27 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
<section className="flex flex-col gap-4">
|
||||
<LancamentosSection
|
||||
currentUserId={userId}
|
||||
lancamentos={lancamentosData}
|
||||
pagadorOptions={optionSets.pagadorOptions}
|
||||
splitPagadorOptions={optionSets.splitPagadorOptions}
|
||||
defaultPagadorId={pagador.id}
|
||||
contaOptions={optionSets.contaOptions}
|
||||
cartaoOptions={optionSets.cartaoOptions}
|
||||
categoriaOptions={optionSets.categoriaOptions}
|
||||
pagadorFilterOptions={pagadorFilterOptions}
|
||||
categoriaFilterOptions={optionSets.categoriaFilterOptions}
|
||||
contaCartaoFilterOptions={optionSets.contaCartaoFilterOptions}
|
||||
transactions={transactionData}
|
||||
payerOptions={optionSets.payerOptions}
|
||||
splitPayerOptions={optionSets.splitPayerOptions}
|
||||
defaultPayerId={pagador.id}
|
||||
accountOptions={optionSets.accountOptions}
|
||||
cardOptions={optionSets.cardOptions}
|
||||
categoryOptions={optionSets.categoryOptions}
|
||||
payerFilterOptions={payerFilterOptions}
|
||||
categoryFilterOptions={optionSets.categoryFilterOptions}
|
||||
accountCardFilterOptions={optionSets.accountCardFilterOptions}
|
||||
selectedPeriod={selectedPeriod}
|
||||
estabelecimentos={estabelecimentos}
|
||||
allowCreate={canEdit}
|
||||
noteAsColumn={userPreferences?.extratoNoteAsColumn ?? false}
|
||||
columnOrder={userPreferences?.lancamentosColumnOrder ?? null}
|
||||
importPagadorOptions={loggedUserOptionSets?.pagadorOptions}
|
||||
importSplitPagadorOptions={
|
||||
loggedUserOptionSets?.splitPagadorOptions
|
||||
}
|
||||
importDefaultPagadorId={loggedUserOptionSets?.defaultPagadorId}
|
||||
importContaOptions={loggedUserOptionSets?.contaOptions}
|
||||
importCartaoOptions={loggedUserOptionSets?.cartaoOptions}
|
||||
importCategoriaOptions={loggedUserOptionSets?.categoriaOptions}
|
||||
noteAsColumn={userPreferences?.statementNoteAsColumn ?? false}
|
||||
columnOrder={userPreferences?.transactionsColumnOrder ?? null}
|
||||
importPayerOptions={loggedUserOptionSets?.payerOptions}
|
||||
importSplitPayerOptions={loggedUserOptionSets?.splitPayerOptions}
|
||||
importDefaultPayerId={loggedUserOptionSets?.defaultPayerId}
|
||||
importAccountOptions={loggedUserOptionSets?.accountOptions}
|
||||
importCardOptions={loggedUserOptionSets?.cardOptions}
|
||||
importCategoryOptions={loggedUserOptionSets?.categoryOptions}
|
||||
/>
|
||||
</section>
|
||||
</TabsContent>
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { PagadoresPage } from "@/features/payers/components/payers-page";
|
||||
import { fetchPagadoresForUser } from "@/features/payers/queries";
|
||||
import { PayersPage } from "@/features/payers/components/payers-page";
|
||||
import { fetchPayersForUser } from "@/features/payers/queries";
|
||||
import { getUserId } from "@/shared/lib/auth/server";
|
||||
|
||||
export default async function Page() {
|
||||
const userId = await getUserId();
|
||||
const { pagadores, avatarOptions } = await fetchPagadoresForUser(userId);
|
||||
const { payers, avatarOptions } = await fetchPayersForUser(userId);
|
||||
|
||||
return (
|
||||
<main className="flex flex-col items-start gap-6">
|
||||
<PagadoresPage pagadores={pagadores} avatarOptions={avatarOptions} />
|
||||
<PayersPage payers={payers} avatarOptions={avatarOptions} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { randomBytes } from "node:crypto";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { z } from "zod";
|
||||
import { compartilhamentosPagador, pagadores, user } from "@/db/schema";
|
||||
import { payerShares, payers, user } from "@/db/schema";
|
||||
import {
|
||||
handleActionError,
|
||||
revalidateForEntity,
|
||||
@@ -12,21 +12,25 @@ import {
|
||||
import { getUser } from "@/shared/lib/auth/server";
|
||||
import { db } from "@/shared/lib/db";
|
||||
import {
|
||||
DEFAULT_PAGADOR_AVATAR,
|
||||
PAGADOR_ROLE_ADMIN,
|
||||
PAGADOR_ROLE_TERCEIRO,
|
||||
PAGADOR_STATUS_OPTIONS,
|
||||
DEFAULT_PAYER_AVATAR,
|
||||
PAYER_ROLE_ADMIN,
|
||||
PAYER_ROLE_THIRD_PARTY,
|
||||
PAYER_STATUS_OPTIONS,
|
||||
} from "@/shared/lib/payers/constants";
|
||||
import { normalizeAvatarPath } from "@/shared/lib/payers/utils";
|
||||
import { noteSchema, uuidSchema } from "@/shared/lib/schemas/common";
|
||||
import type { ActionResult } from "@/shared/lib/types/actions";
|
||||
import { normalizeOptionalString } from "@/shared/utils/string";
|
||||
|
||||
const statusEnum = z.enum(PAGADOR_STATUS_OPTIONS as [string, ...string[]], {
|
||||
errorMap: () => ({
|
||||
message: "Selecione um status válido.",
|
||||
}),
|
||||
});
|
||||
const statusEnum = z
|
||||
.enum([...PAYER_STATUS_OPTIONS] as [string, ...string[]])
|
||||
.refine(
|
||||
(v) =>
|
||||
PAYER_STATUS_OPTIONS.includes(v as (typeof PAYER_STATUS_OPTIONS)[number]),
|
||||
{
|
||||
message: "Selecione um status válido.",
|
||||
},
|
||||
);
|
||||
|
||||
const baseSchema = z.object({
|
||||
name: z
|
||||
@@ -48,11 +52,11 @@ const baseSchema = z.object({
|
||||
const createSchema = baseSchema;
|
||||
|
||||
const updateSchema = baseSchema.extend({
|
||||
id: uuidSchema("Pagador"),
|
||||
id: uuidSchema("Payer"),
|
||||
});
|
||||
|
||||
const deleteSchema = z.object({
|
||||
id: uuidSchema("Pagador"),
|
||||
id: uuidSchema("Payer"),
|
||||
});
|
||||
|
||||
const shareDeleteSchema = z.object({
|
||||
@@ -67,7 +71,7 @@ const shareCodeJoinSchema = z.object({
|
||||
});
|
||||
|
||||
const shareCodeRegenerateSchema = z.object({
|
||||
pagadorId: uuidSchema("Pagador"),
|
||||
payerId: uuidSchema("Payer"),
|
||||
});
|
||||
|
||||
type CreateInput = z.infer<typeof createSchema>;
|
||||
@@ -77,7 +81,7 @@ type ShareDeleteInput = z.infer<typeof shareDeleteSchema>;
|
||||
type ShareCodeJoinInput = z.infer<typeof shareCodeJoinSchema>;
|
||||
type ShareCodeRegenerateInput = z.infer<typeof shareCodeRegenerateSchema>;
|
||||
|
||||
const revalidate = () => revalidateForEntity("pagadores");
|
||||
const revalidate = () => revalidateForEntity("payers");
|
||||
|
||||
const generateShareCode = () => {
|
||||
// base64url já retorna apenas [a-zA-Z0-9_-]
|
||||
@@ -85,56 +89,53 @@ const generateShareCode = () => {
|
||||
return randomBytes(18).toString("base64url").slice(0, 24);
|
||||
};
|
||||
|
||||
export async function createPagadorAction(
|
||||
export async function createPayerAction(
|
||||
input: CreateInput,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = createSchema.parse(input);
|
||||
|
||||
await db.insert(pagadores).values({
|
||||
await db.insert(payers).values({
|
||||
name: data.name,
|
||||
email: data.email,
|
||||
status: data.status,
|
||||
note: data.note,
|
||||
avatarUrl: normalizeAvatarPath(data.avatarUrl) ?? DEFAULT_PAGADOR_AVATAR,
|
||||
avatarUrl: normalizeAvatarPath(data.avatarUrl) ?? DEFAULT_PAYER_AVATAR,
|
||||
isAutoSend: data.isAutoSend ?? false,
|
||||
role: PAGADOR_ROLE_TERCEIRO,
|
||||
role: PAYER_ROLE_THIRD_PARTY,
|
||||
shareCode: generateShareCode(),
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
revalidate();
|
||||
|
||||
return { success: true, message: "Pagador criado com sucesso." };
|
||||
return { success: true, message: "Payer criado com sucesso." };
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updatePagadorAction(
|
||||
export async function updatePayerAction(
|
||||
input: UpdateInput,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const currentUser = await getUser();
|
||||
const data = updateSchema.parse(input);
|
||||
|
||||
const existing = await db.query.pagadores.findFirst({
|
||||
where: and(
|
||||
eq(pagadores.id, data.id),
|
||||
eq(pagadores.userId, currentUser.id),
|
||||
),
|
||||
const existing = await db.query.payers.findFirst({
|
||||
where: and(eq(payers.id, data.id), eq(payers.userId, currentUser.id)),
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
return {
|
||||
success: false,
|
||||
error: "Pagador não encontrado.",
|
||||
error: "Payer não encontrado.",
|
||||
};
|
||||
}
|
||||
|
||||
await db
|
||||
.update(pagadores)
|
||||
.update(payers)
|
||||
.set({
|
||||
name: data.name,
|
||||
email: data.email,
|
||||
@@ -143,14 +144,12 @@ export async function updatePagadorAction(
|
||||
avatarUrl:
|
||||
normalizeAvatarPath(data.avatarUrl) ?? existing.avatarUrl ?? null,
|
||||
isAutoSend: data.isAutoSend ?? false,
|
||||
role: existing.role ?? PAGADOR_ROLE_TERCEIRO,
|
||||
role: existing.role ?? PAYER_ROLE_THIRD_PARTY,
|
||||
})
|
||||
.where(
|
||||
and(eq(pagadores.id, data.id), eq(pagadores.userId, currentUser.id)),
|
||||
);
|
||||
.where(and(eq(payers.id, data.id), eq(payers.userId, currentUser.id)));
|
||||
|
||||
// Se o pagador é admin, sincronizar nome com o usuário
|
||||
if (existing.role === PAGADOR_ROLE_ADMIN) {
|
||||
if (existing.role === PAYER_ROLE_ADMIN) {
|
||||
await db
|
||||
.update(user)
|
||||
.set({ name: data.name })
|
||||
@@ -161,31 +160,31 @@ export async function updatePagadorAction(
|
||||
|
||||
revalidate();
|
||||
|
||||
return { success: true, message: "Pagador atualizado com sucesso." };
|
||||
return { success: true, message: "Payer atualizado com sucesso." };
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deletePagadorAction(
|
||||
export async function deletePayerAction(
|
||||
input: DeleteInput,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = deleteSchema.parse(input);
|
||||
|
||||
const existing = await db.query.pagadores.findFirst({
|
||||
where: and(eq(pagadores.id, data.id), eq(pagadores.userId, user.id)),
|
||||
const existing = await db.query.payers.findFirst({
|
||||
where: and(eq(payers.id, data.id), eq(payers.userId, user.id)),
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
return {
|
||||
success: false,
|
||||
error: "Pagador não encontrado.",
|
||||
error: "Payer não encontrado.",
|
||||
};
|
||||
}
|
||||
|
||||
if (existing.role === PAGADOR_ROLE_ADMIN) {
|
||||
if (existing.role === PAYER_ROLE_ADMIN) {
|
||||
return {
|
||||
success: false,
|
||||
error: "Pagadores administradores não podem ser removidos.",
|
||||
@@ -193,26 +192,26 @@ export async function deletePagadorAction(
|
||||
}
|
||||
|
||||
await db
|
||||
.delete(pagadores)
|
||||
.where(and(eq(pagadores.id, data.id), eq(pagadores.userId, user.id)));
|
||||
.delete(payers)
|
||||
.where(and(eq(payers.id, data.id), eq(payers.userId, user.id)));
|
||||
|
||||
revalidate();
|
||||
|
||||
return { success: true, message: "Pagador removido com sucesso." };
|
||||
return { success: true, message: "Payer removido com sucesso." };
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function joinPagadorByShareCodeAction(
|
||||
export async function joinPayerByShareCodeAction(
|
||||
input: ShareCodeJoinInput,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = shareCodeJoinSchema.parse(input);
|
||||
|
||||
const pagadorRow = await db.query.pagadores.findFirst({
|
||||
where: eq(pagadores.shareCode, data.code),
|
||||
const pagadorRow = await db.query.payers.findFirst({
|
||||
where: eq(payers.shareCode, data.code),
|
||||
});
|
||||
|
||||
if (!pagadorRow) {
|
||||
@@ -226,10 +225,10 @@ export async function joinPagadorByShareCodeAction(
|
||||
};
|
||||
}
|
||||
|
||||
const existingShare = await db.query.compartilhamentosPagador.findFirst({
|
||||
const existingShare = await db.query.payerShares.findFirst({
|
||||
where: and(
|
||||
eq(compartilhamentosPagador.pagadorId, pagadorRow.id),
|
||||
eq(compartilhamentosPagador.sharedWithUserId, user.id),
|
||||
eq(payerShares.payerId, pagadorRow.id),
|
||||
eq(payerShares.sharedWithUserId, user.id),
|
||||
),
|
||||
});
|
||||
|
||||
@@ -240,8 +239,8 @@ export async function joinPagadorByShareCodeAction(
|
||||
};
|
||||
}
|
||||
|
||||
await db.insert(compartilhamentosPagador).values({
|
||||
pagadorId: pagadorRow.id,
|
||||
await db.insert(payerShares).values({
|
||||
payerId: pagadorRow.id,
|
||||
sharedWithUserId: user.id,
|
||||
permission: "read",
|
||||
createdByUserId: pagadorRow.userId,
|
||||
@@ -249,28 +248,28 @@ export async function joinPagadorByShareCodeAction(
|
||||
|
||||
revalidate();
|
||||
|
||||
return { success: true, message: "Pagador adicionado à sua lista." };
|
||||
return { success: true, message: "Payer adicionado à sua lista." };
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deletePagadorShareAction(
|
||||
export async function deletePayerShareAction(
|
||||
input: ShareDeleteInput,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = shareDeleteSchema.parse(input);
|
||||
|
||||
const existing = await db.query.compartilhamentosPagador.findFirst({
|
||||
const existing = await db.query.payerShares.findFirst({
|
||||
columns: {
|
||||
id: true,
|
||||
pagadorId: true,
|
||||
payerId: true,
|
||||
sharedWithUserId: true,
|
||||
},
|
||||
where: eq(compartilhamentosPagador.id, data.shareId),
|
||||
where: eq(payerShares.id, data.shareId),
|
||||
with: {
|
||||
pagador: {
|
||||
payer: {
|
||||
columns: {
|
||||
userId: true,
|
||||
},
|
||||
@@ -279,10 +278,10 @@ export async function deletePagadorShareAction(
|
||||
});
|
||||
|
||||
// Permitir que o owner OU o próprio usuário compartilhado remova o share
|
||||
const payerOwner = existing?.payer as { userId: string } | null | undefined;
|
||||
if (
|
||||
!existing ||
|
||||
(existing.pagador.userId !== user.id &&
|
||||
existing.sharedWithUserId !== user.id)
|
||||
(payerOwner?.userId !== user.id && existing.sharedWithUserId !== user.id)
|
||||
) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -290,12 +289,10 @@ export async function deletePagadorShareAction(
|
||||
};
|
||||
}
|
||||
|
||||
await db
|
||||
.delete(compartilhamentosPagador)
|
||||
.where(eq(compartilhamentosPagador.id, data.shareId));
|
||||
await db.delete(payerShares).where(eq(payerShares.id, data.shareId));
|
||||
|
||||
revalidate();
|
||||
revalidatePath(`/payers/${existing.pagadorId}`);
|
||||
revalidatePath(`/payers/${existing.payerId}`);
|
||||
|
||||
return { success: true, message: "Compartilhamento removido." };
|
||||
} catch (error) {
|
||||
@@ -303,23 +300,20 @@ export async function deletePagadorShareAction(
|
||||
}
|
||||
}
|
||||
|
||||
export async function regeneratePagadorShareCodeAction(
|
||||
export async function regeneratePayerShareCodeAction(
|
||||
input: ShareCodeRegenerateInput,
|
||||
): Promise<{ success: true; message: string; code: string } | ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = shareCodeRegenerateSchema.parse(input);
|
||||
|
||||
const existing = await db.query.pagadores.findFirst({
|
||||
const existing = await db.query.payers.findFirst({
|
||||
columns: { id: true, userId: true },
|
||||
where: and(
|
||||
eq(pagadores.id, data.pagadorId),
|
||||
eq(pagadores.userId, user.id),
|
||||
),
|
||||
where: and(eq(payers.id, data.payerId), eq(payers.userId, user.id)),
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
return { success: false, error: "Pagador não encontrado." };
|
||||
return { success: false, error: "Payer não encontrado." };
|
||||
}
|
||||
|
||||
let attempts = 0;
|
||||
@@ -327,17 +321,12 @@ export async function regeneratePagadorShareCodeAction(
|
||||
const newCode = generateShareCode();
|
||||
try {
|
||||
await db
|
||||
.update(pagadores)
|
||||
.update(payers)
|
||||
.set({ shareCode: newCode })
|
||||
.where(
|
||||
and(
|
||||
eq(pagadores.id, data.pagadorId),
|
||||
eq(pagadores.userId, user.id),
|
||||
),
|
||||
);
|
||||
.where(and(eq(payers.id, data.payerId), eq(payers.userId, user.id)));
|
||||
|
||||
revalidate();
|
||||
revalidatePath(`/payers/${data.pagadorId}`);
|
||||
revalidatePath(`/payers/${data.payerId}`);
|
||||
return {
|
||||
success: true,
|
||||
message: "Código atualizado com sucesso.",
|
||||
@@ -347,8 +336,8 @@ export async function regeneratePagadorShareCodeAction(
|
||||
if (
|
||||
error instanceof Error &&
|
||||
"constraint" in error &&
|
||||
// @ts-expect-error constraint is present in postgres errors
|
||||
error.constraint === "pagadores_share_code_key"
|
||||
(error as { constraint?: string }).constraint ===
|
||||
"pagadores_share_code_key"
|
||||
) {
|
||||
attempts += 1;
|
||||
continue;
|
||||
|
||||
@@ -4,7 +4,7 @@ import MoneyValues from "@/shared/components/money-values";
|
||||
import { CardContent } from "@/shared/components/ui/card";
|
||||
import { WidgetEmptyState } from "@/shared/components/widget-empty-state";
|
||||
import { resolveLogoSrc } from "@/shared/lib/logo";
|
||||
import type { PagadorCardUsageItem } from "@/shared/lib/payers/details";
|
||||
import type { PayerCardUsageItem } from "@/shared/lib/payers/details";
|
||||
|
||||
const buildInitials = (value: string) => {
|
||||
const parts = value.trim().split(/\s+/).filter(Boolean);
|
||||
@@ -19,10 +19,10 @@ const buildInitials = (value: string) => {
|
||||
};
|
||||
|
||||
type PagadorCardUsageCardProps = {
|
||||
items: PagadorCardUsageItem[];
|
||||
items: PayerCardUsageItem[];
|
||||
};
|
||||
|
||||
export function PagadorCardUsageCard({ items }: PagadorCardUsageCardProps) {
|
||||
export function PayerCardUsageCard({ items }: PagadorCardUsageCardProps) {
|
||||
if (items.length === 0) {
|
||||
return (
|
||||
<CardContent className="px-0">
|
||||
|
||||
@@ -13,7 +13,7 @@ import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState, useTransition } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { sendPagadorSummaryAction } from "@/features/payers/detail-actions";
|
||||
import { sendPayerSummaryAction } from "@/features/payers/detail-actions";
|
||||
import { Badge } from "@/shared/components/ui/badge";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import {
|
||||
@@ -30,41 +30,41 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/shared/components/ui/dialog";
|
||||
import { PAGADOR_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import { PAYER_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import { getAvatarSrc } from "@/shared/lib/payers/utils";
|
||||
import { formatCurrency } from "@/shared/utils/currency";
|
||||
import { formatDateTime } from "@/shared/utils/date";
|
||||
import type { PagadorInfo, PagadorSummaryPreview } from "./types";
|
||||
import type { PayerInfo, PayerSummaryPreview } from "./types";
|
||||
|
||||
type PagadorHeaderCardProps = {
|
||||
pagador: PagadorInfo;
|
||||
type PayerHeaderCardProps = {
|
||||
payer: PayerInfo;
|
||||
selectedPeriod: string;
|
||||
summary: PagadorSummaryPreview;
|
||||
summary: PayerSummaryPreview;
|
||||
};
|
||||
|
||||
export function PagadorHeaderCard({
|
||||
pagador,
|
||||
export function PayerHeaderCard({
|
||||
payer,
|
||||
selectedPeriod,
|
||||
summary,
|
||||
}: PagadorHeaderCardProps) {
|
||||
}: PayerHeaderCardProps) {
|
||||
const router = useRouter();
|
||||
const [isSending, startTransition] = useTransition();
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
|
||||
const avatarSrc = getAvatarSrc(pagador.avatarUrl);
|
||||
const createdAtLabel = formatDate(pagador.createdAt);
|
||||
const isAdmin = pagador.role === PAGADOR_ROLE_ADMIN;
|
||||
const avatarSrc = getAvatarSrc(payer.avatarUrl);
|
||||
const createdAtLabel = formatDate(payer.createdAt);
|
||||
const isAdmin = payer.role === PAYER_ROLE_ADMIN;
|
||||
|
||||
const lastMailLabel =
|
||||
formatDateTime(pagador.lastMailAt, {
|
||||
formatDateTime(payer.lastMailAt, {
|
||||
dateStyle: "short",
|
||||
timeStyle: "short",
|
||||
}) ?? "Nunca enviado";
|
||||
|
||||
const disableSend = isSending || !pagador.email || !pagador.canEdit;
|
||||
const disableSend = isSending || !payer.email || !payer.canEdit;
|
||||
|
||||
const openConfirmDialog = () => {
|
||||
if (!pagador.email) {
|
||||
if (!payer.email) {
|
||||
toast.error("Cadastre um e-mail para este pagador antes de enviar.");
|
||||
return;
|
||||
}
|
||||
@@ -72,14 +72,14 @@ export function PagadorHeaderCard({
|
||||
};
|
||||
|
||||
const handleSendSummary = () => {
|
||||
if (!pagador.email) {
|
||||
if (!payer.email) {
|
||||
toast.error("Cadastre um e-mail para este pagador antes de enviar.");
|
||||
return;
|
||||
}
|
||||
|
||||
startTransition(async () => {
|
||||
const result = await sendPagadorSummaryAction({
|
||||
pagadorId: pagador.id,
|
||||
const result = await sendPayerSummaryAction({
|
||||
payerId: payer.id,
|
||||
period: selectedPeriod,
|
||||
});
|
||||
|
||||
@@ -109,7 +109,7 @@ export function PagadorHeaderCard({
|
||||
<div className="relative flex size-16 shrink-0 items-center justify-center overflow-hidden">
|
||||
<Image
|
||||
src={avatarSrc}
|
||||
alt={`Avatar de ${pagador.name}`}
|
||||
alt={`Avatar de ${payer.name}`}
|
||||
width={64}
|
||||
height={64}
|
||||
className="h-full w-full rounded-full object-cover"
|
||||
@@ -119,7 +119,7 @@ export function PagadorHeaderCard({
|
||||
<div className="flex flex-1 flex-col gap-2">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<CardTitle className="text-xl font-semibold text-foreground">
|
||||
{pagador.name}
|
||||
{payer.name}
|
||||
</CardTitle>
|
||||
{isAdmin ? (
|
||||
<RiVerifiedBadgeFill
|
||||
@@ -128,12 +128,12 @@ export function PagadorHeaderCard({
|
||||
/>
|
||||
) : null}
|
||||
<Badge
|
||||
variant={getStatusBadgeVariant(pagador.status)}
|
||||
variant={getStatusBadgeVariant(payer.status)}
|
||||
className="text-xs"
|
||||
>
|
||||
{pagador.status}
|
||||
{payer.status}
|
||||
</Badge>
|
||||
{pagador.isAutoSend ? (
|
||||
{payer.isAutoSend ? (
|
||||
<Badge variant="info" className="gap-1 text-xs">
|
||||
<RiMailSendLine className="size-3.5" aria-hidden />
|
||||
Envio automático
|
||||
@@ -144,14 +144,14 @@ export function PagadorHeaderCard({
|
||||
<CardDescription className="flex flex-wrap items-center gap-x-3 gap-y-1 text-sm">
|
||||
<span>Criado em {createdAtLabel}</span>
|
||||
<span className="hidden text-border/80 sm:inline">•</span>
|
||||
{pagador.email ? (
|
||||
{payer.email ? (
|
||||
<Link
|
||||
prefetch
|
||||
href={`mailto:${pagador.email}`}
|
||||
href={`mailto:${payer.email}`}
|
||||
className="inline-flex items-center gap-1.5 text-primary"
|
||||
>
|
||||
<RiMailLine className="size-4" aria-hidden />
|
||||
{pagador.email}
|
||||
{payer.email}
|
||||
</Link>
|
||||
) : (
|
||||
<span>Sem e-mail cadastrado</span>
|
||||
@@ -161,7 +161,7 @@ export function PagadorHeaderCard({
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-col items-stretch gap-2 lg:w-auto lg:items-end">
|
||||
{pagador.canEdit ? (
|
||||
{payer.canEdit ? (
|
||||
<>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -184,7 +184,7 @@ export function PagadorHeaderCard({
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
{pagador.canEdit ? (
|
||||
{payer.canEdit ? (
|
||||
<Dialog
|
||||
open={confirmOpen}
|
||||
onOpenChange={(open) => {
|
||||
@@ -202,7 +202,7 @@ export function PagadorHeaderCard({
|
||||
</span>{" "}
|
||||
para{" "}
|
||||
<span className="font-medium text-foreground">
|
||||
{pagador.email}
|
||||
{payer.email}
|
||||
</span>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
ChartTooltipContent,
|
||||
} from "@/shared/components/ui/chart";
|
||||
import { WidgetEmptyState } from "@/shared/components/widget-empty-state";
|
||||
import type { PagadorHistoryPoint } from "@/shared/lib/payers/details";
|
||||
import type { PayerHistoryPoint } from "@/shared/lib/payers/details";
|
||||
import { currencyFormatter } from "@/shared/utils/currency";
|
||||
|
||||
const chartConfig = {
|
||||
@@ -32,7 +32,7 @@ const chartConfig = {
|
||||
};
|
||||
|
||||
type PagadorHistoryCardProps = {
|
||||
data: PagadorHistoryPoint[];
|
||||
data: PayerHistoryPoint[];
|
||||
};
|
||||
|
||||
const ValueLabel = (props: LabelProps) => {
|
||||
@@ -57,7 +57,7 @@ const ValueLabel = (props: LabelProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
export function PagadorHistoryCard({ data }: PagadorHistoryCardProps) {
|
||||
export function PayerHistoryCard({ data }: PagadorHistoryCardProps) {
|
||||
const hasData = data.length > 0;
|
||||
|
||||
return (
|
||||
|
||||
@@ -8,17 +8,17 @@ import {
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/shared/components/ui/card";
|
||||
import { PAGADOR_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import { PAYER_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import { formatDateTime } from "@/shared/utils/date";
|
||||
import { cn } from "@/shared/utils/ui";
|
||||
import type { PagadorInfo } from "./types";
|
||||
import type { PayerInfo } from "./types";
|
||||
|
||||
type PagadorInfoCardProps = {
|
||||
pagador: PagadorInfo;
|
||||
type PayerInfoCardProps = {
|
||||
payer: PayerInfo;
|
||||
};
|
||||
|
||||
export function PagadorInfoCard({ pagador }: PagadorInfoCardProps) {
|
||||
const showSensitiveDetails = pagador.canEdit;
|
||||
export function PagadorInfoCard({ payer }: PayerInfoCardProps) {
|
||||
const showSensitiveDetails = payer.canEdit;
|
||||
|
||||
const getStatusBadgeVariant = (status: string): "success" | "outline" => {
|
||||
const normalizedStatus = status.toLowerCase();
|
||||
@@ -32,7 +32,7 @@ export function PagadorInfoCard({ pagador }: PagadorInfoCardProps) {
|
||||
<Card className="border gap-4">
|
||||
<CardHeader className="gap-1.5">
|
||||
<CardTitle className="text-lg font-semibold">
|
||||
Detalhes do pagador
|
||||
Detalhes do payer
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{showSensitiveDetails
|
||||
@@ -46,10 +46,10 @@ export function PagadorInfoCard({ pagador }: PagadorInfoCardProps) {
|
||||
label="Status"
|
||||
value={
|
||||
<Badge
|
||||
variant={getStatusBadgeVariant(pagador.status)}
|
||||
variant={getStatusBadgeVariant(payer.status)}
|
||||
className="text-xs"
|
||||
>
|
||||
{pagador.status}
|
||||
{payer.status}
|
||||
</Badge>
|
||||
}
|
||||
/>
|
||||
@@ -59,23 +59,23 @@ export function PagadorInfoCard({ pagador }: PagadorInfoCardProps) {
|
||||
value={
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<RiUser3Line className="size-4 text-muted-foreground" />
|
||||
{resolveRoleLabel(pagador.role)}
|
||||
{resolveRoleLabel(payer.role)}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
{showSensitiveDetails ? (
|
||||
<InfoItem
|
||||
label="Envio automático"
|
||||
value={pagador.isAutoSend ? "Ativado" : "Desativado"}
|
||||
value={payer.isAutoSend ? "Ativado" : "Desativado"}
|
||||
/>
|
||||
) : null}
|
||||
{showSensitiveDetails ? (
|
||||
<InfoItem
|
||||
label="Último envio"
|
||||
value={formatDateTime(pagador.lastMailAt) ?? "Nunca enviado"}
|
||||
value={formatDateTime(payer.lastMailAt) ?? "Nunca enviado"}
|
||||
/>
|
||||
) : null}
|
||||
{showSensitiveDetails && !pagador.email ? (
|
||||
{showSensitiveDetails && !payer.email ? (
|
||||
<InfoItem
|
||||
label="Aviso"
|
||||
value={
|
||||
@@ -90,8 +90,8 @@ export function PagadorInfoCard({ pagador }: PagadorInfoCardProps) {
|
||||
<InfoItem
|
||||
label="Observações"
|
||||
value={
|
||||
pagador.note ? (
|
||||
<span className="text-muted-foreground">{pagador.note}</span>
|
||||
payer.note ? (
|
||||
<span className="text-muted-foreground">{payer.note}</span>
|
||||
) : (
|
||||
"Sem observações"
|
||||
)
|
||||
@@ -105,8 +105,8 @@ export function PagadorInfoCard({ pagador }: PagadorInfoCardProps) {
|
||||
}
|
||||
|
||||
const resolveRoleLabel = (role: string | null) => {
|
||||
if (role === PAGADOR_ROLE_ADMIN) return "Administrador";
|
||||
return "Pagador";
|
||||
if (role === PAYER_ROLE_ADMIN) return "Administrador";
|
||||
return "Payer";
|
||||
};
|
||||
|
||||
type InfoItemProps = {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { RiLogoutBoxLine } from "@remixicon/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState, useTransition } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { deletePagadorShareAction } from "@/features/payers/actions";
|
||||
import { deletePayerShareAction } from "@/features/payers/actions";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import {
|
||||
Card,
|
||||
@@ -20,7 +20,7 @@ interface PagadorLeaveShareCardProps {
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export function PagadorLeaveShareCard({
|
||||
export function PayerLeaveShareCard({
|
||||
shareId,
|
||||
pagadorName,
|
||||
createdAt,
|
||||
@@ -31,7 +31,7 @@ export function PagadorLeaveShareCard({
|
||||
|
||||
const handleLeave = () => {
|
||||
startTransition(async () => {
|
||||
const result = await deletePagadorShareAction({ shareId });
|
||||
const result = await deletePayerShareAction({ shareId });
|
||||
|
||||
if (!result.success) {
|
||||
toast.error(result.error);
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/shared/components/ui/card";
|
||||
import type { PagadorMonthlyBreakdown } from "@/shared/lib/payers/details";
|
||||
import type { PayerMonthlyBreakdown } from "@/shared/lib/payers/details";
|
||||
import { cn } from "@/shared/utils/ui";
|
||||
|
||||
const segmentConfig = {
|
||||
@@ -26,10 +26,10 @@ const segmentConfig = {
|
||||
|
||||
type PagadorMonthlySummaryCardProps = {
|
||||
periodLabel: string;
|
||||
breakdown: PagadorMonthlyBreakdown;
|
||||
breakdown: PayerMonthlyBreakdown;
|
||||
};
|
||||
|
||||
export function PagadorMonthlySummaryCard({
|
||||
export function PayerMonthlySummaryCard({
|
||||
periodLabel,
|
||||
breakdown,
|
||||
}: PagadorMonthlySummaryCardProps) {
|
||||
|
||||
@@ -11,18 +11,18 @@ import { CardContent } from "@/shared/components/ui/card";
|
||||
import { Progress } from "@/shared/components/ui/progress";
|
||||
import { WidgetEmptyState } from "@/shared/components/widget-empty-state";
|
||||
import type {
|
||||
PagadorBoletoItem,
|
||||
PagadorPaymentStatusData,
|
||||
PayerBoletoItem,
|
||||
PayerPaymentStatusData,
|
||||
} from "@/shared/lib/payers/details";
|
||||
import { cn } from "@/shared/utils/ui";
|
||||
|
||||
// --- PagadorBoletoCard ---
|
||||
// --- PayerBoletoCard ---
|
||||
|
||||
type PagadorBoletoCardProps = {
|
||||
items: PagadorBoletoItem[];
|
||||
items: PayerBoletoItem[];
|
||||
};
|
||||
|
||||
export function PagadorBoletoCard({ items }: PagadorBoletoCardProps) {
|
||||
export function PayerBoletoCard({ items }: PagadorBoletoCardProps) {
|
||||
if (items.length === 0) {
|
||||
return (
|
||||
<CardContent className="px-0">
|
||||
@@ -72,13 +72,13 @@ export function PagadorBoletoCard({ items }: PagadorBoletoCardProps) {
|
||||
);
|
||||
}
|
||||
|
||||
// --- PagadorPaymentStatusCard ---
|
||||
// --- PayerPaymentStatusCard ---
|
||||
|
||||
type PagadorPaymentStatusCardProps = {
|
||||
data: PagadorPaymentStatusData;
|
||||
data: PayerPaymentStatusData;
|
||||
};
|
||||
|
||||
export function PagadorPaymentStatusCard({
|
||||
export function PayerPaymentStatusCard({
|
||||
data,
|
||||
}: PagadorPaymentStatusCardProps) {
|
||||
const { paidAmount, paidCount, pendingAmount, pendingCount, totalAmount } =
|
||||
|
||||
@@ -5,8 +5,8 @@ import { useRouter } from "next/navigation";
|
||||
import { useState, useTransition } from "react";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
deletePagadorShareAction,
|
||||
regeneratePagadorShareCodeAction,
|
||||
deletePayerShareAction,
|
||||
regeneratePayerShareCodeAction,
|
||||
} from "@/features/payers/actions";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import {
|
||||
@@ -25,13 +25,13 @@ type PagadorShare = {
|
||||
};
|
||||
|
||||
interface PagadorSharingCardProps {
|
||||
pagadorId: string;
|
||||
payerId: string;
|
||||
shareCode: string;
|
||||
shares: PagadorShare[];
|
||||
}
|
||||
|
||||
export function PagadorSharingCard({
|
||||
pagadorId,
|
||||
export function PayerSharingCard({
|
||||
payerId,
|
||||
shareCode,
|
||||
shares,
|
||||
}: PagadorSharingCardProps) {
|
||||
@@ -51,14 +51,14 @@ export function PagadorSharingCard({
|
||||
|
||||
const handleRegenerate = () => {
|
||||
startRegenerate(async () => {
|
||||
const result = await regeneratePagadorShareCodeAction({ pagadorId });
|
||||
const result = await regeneratePayerShareCodeAction({ payerId });
|
||||
|
||||
if (!result.success) {
|
||||
toast.error(result.error);
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentCode(result.code);
|
||||
if ("code" in result) setCurrentCode(result.code);
|
||||
toast.success("Novo código gerado com sucesso.");
|
||||
router.refresh();
|
||||
});
|
||||
@@ -67,7 +67,7 @@ export function PagadorSharingCard({
|
||||
const handleRemove = (shareId: string) => {
|
||||
setRemovePendingId(shareId);
|
||||
startRegenerate(async () => {
|
||||
const result = await deletePagadorShareAction({ shareId });
|
||||
const result = await deletePayerShareAction({ shareId });
|
||||
|
||||
if (!result.success) {
|
||||
toast.error(result.error);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export type PagadorInfo = {
|
||||
export type PayerInfo = {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string | null;
|
||||
@@ -13,7 +13,7 @@ export type PagadorInfo = {
|
||||
canEdit: boolean;
|
||||
};
|
||||
|
||||
export type PagadorSummaryPreview = {
|
||||
export type PayerSummaryPreview = {
|
||||
periodLabel: string;
|
||||
totalExpenses: number;
|
||||
paymentSplits: {
|
||||
|
||||
@@ -11,20 +11,20 @@ import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { Badge } from "@/shared/components/ui/badge";
|
||||
import { Card } from "@/shared/components/ui/card";
|
||||
import { PAGADOR_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import { PAYER_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import { getAvatarSrc } from "@/shared/lib/payers/utils";
|
||||
import type { Pagador } from "./types";
|
||||
import type { Payer } from "./types";
|
||||
|
||||
interface PagadorCardProps {
|
||||
pagador: Pagador;
|
||||
interface PayerCardProps {
|
||||
payer: Payer;
|
||||
onEdit?: () => void;
|
||||
onRemove?: () => void;
|
||||
}
|
||||
|
||||
export function PagadorCard({ pagador, onEdit, onRemove }: PagadorCardProps) {
|
||||
const avatarSrc = getAvatarSrc(pagador.avatarUrl);
|
||||
const isAdmin = pagador.role === PAGADOR_ROLE_ADMIN;
|
||||
const isReadOnly = !pagador.canEdit;
|
||||
export function PayerCard({ payer, onEdit, onRemove }: PayerCardProps) {
|
||||
const avatarSrc = getAvatarSrc(payer.avatarUrl);
|
||||
const isAdmin = payer.role === PAYER_ROLE_ADMIN;
|
||||
const isReadOnly = !payer.canEdit;
|
||||
|
||||
return (
|
||||
<Card className=" overflow-hidden px-6">
|
||||
@@ -33,7 +33,7 @@ export function PagadorCard({ pagador, onEdit, onRemove }: PagadorCardProps) {
|
||||
<div className="relative mb-3 flex size-16 items-center justify-center overflow-hidden rounded-full border-background bg-background shadow-lg">
|
||||
<Image
|
||||
src={avatarSrc}
|
||||
alt={`Avatar de ${pagador.name}`}
|
||||
alt={`Avatar de ${payer.name}`}
|
||||
width={80}
|
||||
height={80}
|
||||
className="h-full w-full object-cover"
|
||||
@@ -43,19 +43,19 @@ export function PagadorCard({ pagador, onEdit, onRemove }: PagadorCardProps) {
|
||||
{/* Nome e badges */}
|
||||
<div className="flex items-center gap-1.5">
|
||||
<h3 className="text-base font-semibold text-foreground">
|
||||
{pagador.name}
|
||||
{payer.name}
|
||||
</h3>
|
||||
{isAdmin ? (
|
||||
<RiVerifiedBadgeFill className="size-4 text-blue-500" aria-hidden />
|
||||
) : null}
|
||||
{pagador.isAutoSend ? (
|
||||
{payer.isAutoSend ? (
|
||||
<RiMailSendLine className="size-4 text-primary" aria-hidden />
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Email */}
|
||||
{pagador.email ? (
|
||||
<p className="mt-1 text-xs text-muted-foreground">{pagador.email}</p>
|
||||
{payer.email ? (
|
||||
<p className="mt-1 text-xs text-muted-foreground">{payer.email}</p>
|
||||
) : (
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
Sem email cadastrado
|
||||
@@ -65,10 +65,10 @@ export function PagadorCard({ pagador, onEdit, onRemove }: PagadorCardProps) {
|
||||
{/* Status badges */}
|
||||
<div className="mt-2 flex flex-wrap items-center justify-center gap-1.5">
|
||||
<Badge
|
||||
variant={pagador.status === "Ativo" ? "success" : "outline"}
|
||||
variant={payer.status === "Ativo" ? "success" : "outline"}
|
||||
className="text-xs"
|
||||
>
|
||||
{pagador.status}
|
||||
{payer.status}
|
||||
</Badge>
|
||||
|
||||
{isReadOnly ? (
|
||||
@@ -93,7 +93,7 @@ export function PagadorCard({ pagador, onEdit, onRemove }: PagadorCardProps) {
|
||||
) : null}
|
||||
|
||||
<Link
|
||||
href={`/payers/${pagador.id}`}
|
||||
href={`/payers/${payer.id}`}
|
||||
className={`text-primary flex items-center gap-1 font-medium transition-opacity hover:opacity-80`}
|
||||
>
|
||||
<RiFileList2Line className="size-4" aria-hidden />
|
||||
|
||||
@@ -3,8 +3,8 @@ import Image from "next/image";
|
||||
import { useEffect, useMemo, useState, useTransition } from "react";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
createPagadorAction,
|
||||
updatePagadorAction,
|
||||
createPayerAction,
|
||||
updatePayerAction,
|
||||
} from "@/features/payers/actions";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { Checkbox } from "@/shared/components/ui/checkbox";
|
||||
@@ -29,50 +29,50 @@ import {
|
||||
import { useControlledState } from "@/shared/hooks/use-controlled-state";
|
||||
import { useFormState } from "@/shared/hooks/use-form-state";
|
||||
import {
|
||||
DEFAULT_PAGADOR_AVATAR,
|
||||
PAGADOR_STATUS_OPTIONS,
|
||||
type PagadorStatus,
|
||||
DEFAULT_PAYER_AVATAR,
|
||||
PAYER_STATUS_OPTIONS,
|
||||
type PayerStatus,
|
||||
} from "@/shared/lib/payers/constants";
|
||||
import { getAvatarSrc } from "@/shared/lib/payers/utils";
|
||||
import { StatusSelectContent } from "./payer-select-items";
|
||||
import type { Pagador, PagadorFormValues } from "./types";
|
||||
import type { Payer, PayerFormValues } from "./types";
|
||||
|
||||
interface PagadorDialogProps {
|
||||
interface PayerDialogProps {
|
||||
mode: "create" | "update";
|
||||
trigger?: React.ReactNode;
|
||||
pagador?: Pagador;
|
||||
payer?: Payer;
|
||||
avatarOptions: string[];
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
}
|
||||
|
||||
const buildInitialValues = ({
|
||||
pagador,
|
||||
payer,
|
||||
avatarOptions,
|
||||
}: {
|
||||
pagador?: Pagador;
|
||||
payer?: Payer;
|
||||
avatarOptions: string[];
|
||||
}): PagadorFormValues => {
|
||||
const defaultAvatar = avatarOptions[0] ?? DEFAULT_PAGADOR_AVATAR;
|
||||
}): PayerFormValues => {
|
||||
const defaultAvatar = avatarOptions[0] ?? DEFAULT_PAYER_AVATAR;
|
||||
|
||||
return {
|
||||
name: pagador?.name ?? "",
|
||||
email: pagador?.email ?? "",
|
||||
status: (pagador?.status as PagadorStatus) ?? PAGADOR_STATUS_OPTIONS[0],
|
||||
avatarUrl: pagador?.avatarUrl ?? defaultAvatar,
|
||||
note: pagador?.note ?? "",
|
||||
isAutoSend: pagador?.isAutoSend ?? false,
|
||||
name: payer?.name ?? "",
|
||||
email: payer?.email ?? "",
|
||||
status: (payer?.status as PayerStatus) ?? PAYER_STATUS_OPTIONS[0],
|
||||
avatarUrl: payer?.avatarUrl ?? defaultAvatar,
|
||||
note: payer?.note ?? "",
|
||||
isAutoSend: payer?.isAutoSend ?? false,
|
||||
};
|
||||
};
|
||||
|
||||
export function PagadorDialog({
|
||||
export function PayerDialog({
|
||||
mode,
|
||||
trigger,
|
||||
pagador,
|
||||
payer,
|
||||
avatarOptions,
|
||||
open,
|
||||
onOpenChange,
|
||||
}: PagadorDialogProps) {
|
||||
}: PayerDialogProps) {
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
@@ -84,19 +84,19 @@ export function PagadorDialog({
|
||||
);
|
||||
|
||||
const initialState = useMemo(
|
||||
() => buildInitialValues({ pagador, avatarOptions }),
|
||||
[pagador, avatarOptions],
|
||||
() => buildInitialValues({ payer, avatarOptions }),
|
||||
[payer, avatarOptions],
|
||||
);
|
||||
|
||||
// Use form state hook for form management
|
||||
const { formState, resetForm, updateField } =
|
||||
useFormState<PagadorFormValues>(initialState);
|
||||
useFormState<PayerFormValues>(initialState);
|
||||
|
||||
const availableAvatars = useMemo(() => {
|
||||
const set = new Set<string>();
|
||||
avatarOptions.forEach((avatar) => set.add(avatar));
|
||||
set.add(initialState.avatarUrl);
|
||||
set.add(DEFAULT_PAGADOR_AVATAR);
|
||||
set.add(DEFAULT_PAYER_AVATAR);
|
||||
return Array.from(set).sort((a, b) =>
|
||||
a.localeCompare(b, "pt-BR", { sensitivity: "base" }),
|
||||
);
|
||||
@@ -110,22 +110,22 @@ export function PagadorDialog({
|
||||
}
|
||||
}, [dialogOpen, initialState, resetForm]);
|
||||
|
||||
type PagadorCreatePayload = Parameters<typeof createPagadorAction>[0];
|
||||
type PayerCreatePayload = Parameters<typeof createPayerAction>[0];
|
||||
|
||||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setErrorMessage(null);
|
||||
const pagadorId = pagador?.id;
|
||||
const payerId = payer?.id;
|
||||
|
||||
if (mode === "update" && !pagadorId) {
|
||||
const message = "Pagador inválido.";
|
||||
if (mode === "update" && !payerId) {
|
||||
const message = "Payer inválido.";
|
||||
setErrorMessage(message);
|
||||
toast.error(message);
|
||||
return;
|
||||
}
|
||||
|
||||
const emailValue = formState.email.trim();
|
||||
const payload: PagadorCreatePayload = {
|
||||
const payload: PayerCreatePayload = {
|
||||
name: formState.name.trim(),
|
||||
status: formState.status,
|
||||
avatarUrl: formState.avatarUrl,
|
||||
@@ -136,7 +136,7 @@ export function PagadorDialog({
|
||||
|
||||
startTransition(async () => {
|
||||
if (mode === "create") {
|
||||
const result = await createPagadorAction(payload);
|
||||
const result = await createPayerAction(payload);
|
||||
|
||||
if (result.success) {
|
||||
toast.success(result.message);
|
||||
@@ -150,12 +150,12 @@ export function PagadorDialog({
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pagadorId) {
|
||||
if (!payerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await updatePagadorAction({
|
||||
id: pagadorId,
|
||||
const result = await updatePayerAction({
|
||||
id: payerId,
|
||||
...payload,
|
||||
});
|
||||
|
||||
@@ -193,9 +193,9 @@ export function PagadorDialog({
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex w-full gap-2">
|
||||
<div className="flex flex-col gap-2 w-full">
|
||||
<Label htmlFor="pagador-name">Nome</Label>
|
||||
<Label htmlFor="payer-name">Nome</Label>
|
||||
<Input
|
||||
id="pagador-name"
|
||||
id="payer-name"
|
||||
value={formState.name}
|
||||
onChange={(event) =>
|
||||
updateField("name", event.target.value)
|
||||
@@ -206,9 +206,9 @@ export function PagadorDialog({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2 w-full">
|
||||
<Label htmlFor="pagador-email">E-mail</Label>
|
||||
<Label htmlFor="payer-email">E-mail</Label>
|
||||
<Input
|
||||
id="pagador-email"
|
||||
id="payer-email"
|
||||
type="email"
|
||||
value={formState.email}
|
||||
onChange={(event) =>
|
||||
@@ -220,14 +220,14 @@ export function PagadorDialog({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="pagador-status">Status</Label>
|
||||
<Label htmlFor="payer-status">Status</Label>
|
||||
<Select
|
||||
value={formState.status}
|
||||
onValueChange={(value: PagadorStatus) =>
|
||||
onValueChange={(value: PayerStatus) =>
|
||||
updateField("status", value)
|
||||
}
|
||||
>
|
||||
<SelectTrigger id="pagador-status" className="w-full">
|
||||
<SelectTrigger id="payer-status" className="w-full">
|
||||
<SelectValue placeholder="Selecione o status">
|
||||
{formState.status && (
|
||||
<StatusSelectContent label={formState.status} />
|
||||
@@ -235,7 +235,7 @@ export function PagadorDialog({
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{PAGADOR_STATUS_OPTIONS.map((status) => (
|
||||
{PAYER_STATUS_OPTIONS.map((status) => (
|
||||
<SelectItem key={status} value={status}>
|
||||
<StatusSelectContent label={status} />
|
||||
</SelectItem>
|
||||
@@ -247,7 +247,7 @@ export function PagadorDialog({
|
||||
<fieldset className="flex flex-col gap-3">
|
||||
<div className="flex items-start gap-3 rounded-lg border border-border/60 bg-muted/10 p-3">
|
||||
<Checkbox
|
||||
id="pagador-auto-send"
|
||||
id="payer-auto-send"
|
||||
checked={formState.isAutoSend}
|
||||
onCheckedChange={(checked) =>
|
||||
updateField("isAutoSend", Boolean(checked))
|
||||
@@ -256,7 +256,7 @@ export function PagadorDialog({
|
||||
/>
|
||||
<div className="space-y-1">
|
||||
<Label
|
||||
htmlFor="pagador-auto-send"
|
||||
htmlFor="payer-auto-send"
|
||||
className="text-sm font-medium text-foreground"
|
||||
>
|
||||
Enviar automaticamente
|
||||
@@ -296,9 +296,9 @@ export function PagadorDialog({
|
||||
</fieldset>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="pagador-note">Anotações</Label>
|
||||
<Label htmlFor="payer-note">Anotações</Label>
|
||||
<Input
|
||||
id="pagador-note"
|
||||
id="payer-note"
|
||||
value={formState.note}
|
||||
onChange={(event) => updateField("note", event.target.value)}
|
||||
placeholder="Observações sobre este pagador"
|
||||
|
||||
@@ -5,84 +5,81 @@ import { useRouter } from "next/navigation";
|
||||
import { useMemo, useState, useTransition } from "react";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
deletePagadorAction,
|
||||
joinPagadorByShareCodeAction,
|
||||
deletePayerAction,
|
||||
joinPayerByShareCodeAction,
|
||||
} from "@/features/payers/actions";
|
||||
import { PagadorCard } from "@/features/payers/components/payer-card";
|
||||
import { PagadorDialog } from "@/features/payers/components/payer-dialog";
|
||||
import { PayerCard } from "@/features/payers/components/payer-card";
|
||||
import { PayerDialog } from "@/features/payers/components/payer-dialog";
|
||||
import { ConfirmActionDialog } from "@/shared/components/confirm-action-dialog";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { Input } from "@/shared/components/ui/input";
|
||||
import { PAGADOR_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import type { Pagador } from "./types";
|
||||
import { PAYER_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import type { Payer } from "./types";
|
||||
|
||||
interface PagadoresPageProps {
|
||||
pagadores: Pagador[];
|
||||
interface PayersPageProps {
|
||||
payers: Payer[];
|
||||
avatarOptions: string[];
|
||||
}
|
||||
|
||||
export function PagadoresPage({
|
||||
pagadores,
|
||||
avatarOptions,
|
||||
}: PagadoresPageProps) {
|
||||
export function PayersPage({ payers, avatarOptions }: PayersPageProps) {
|
||||
const router = useRouter();
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [selectedPagador, setSelectedPagador] = useState<Pagador | null>(null);
|
||||
const [selectedPayer, setSelectedPayer] = useState<Payer | null>(null);
|
||||
const [removeOpen, setRemoveOpen] = useState(false);
|
||||
const [pagadorToRemove, setPagadorToRemove] = useState<Pagador | null>(null);
|
||||
const [payerToRemove, setPayerToRemove] = useState<Payer | null>(null);
|
||||
const [shareCodeInput, setShareCodeInput] = useState("");
|
||||
const [joinPending, startJoin] = useTransition();
|
||||
|
||||
const orderedPagadores = useMemo(
|
||||
const orderedPayers = useMemo(
|
||||
() =>
|
||||
[...pagadores].sort((a, b) => {
|
||||
[...payers].sort((a, b) => {
|
||||
// Admin sempre primeiro
|
||||
if (a.role === PAGADOR_ROLE_ADMIN && b.role !== PAGADOR_ROLE_ADMIN) {
|
||||
if (a.role === PAYER_ROLE_ADMIN && b.role !== PAYER_ROLE_ADMIN) {
|
||||
return -1;
|
||||
}
|
||||
if (a.role !== PAGADOR_ROLE_ADMIN && b.role === PAGADOR_ROLE_ADMIN) {
|
||||
if (a.role !== PAYER_ROLE_ADMIN && b.role === PAYER_ROLE_ADMIN) {
|
||||
return 1;
|
||||
}
|
||||
// Se ambos têm o mesmo tipo de role, ordena por nome
|
||||
return a.name.localeCompare(b.name, "pt-BR", { sensitivity: "base" });
|
||||
}),
|
||||
[pagadores],
|
||||
[payers],
|
||||
);
|
||||
|
||||
const handleEdit = (pagador: Pagador) => {
|
||||
setSelectedPagador(pagador);
|
||||
const handleEdit = (payer: Payer) => {
|
||||
setSelectedPayer(payer);
|
||||
setEditOpen(true);
|
||||
};
|
||||
|
||||
const handleEditOpenChange = (open: boolean) => {
|
||||
setEditOpen(open);
|
||||
if (!open) {
|
||||
setSelectedPagador(null);
|
||||
setSelectedPayer(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveRequest = (pagador: Pagador) => {
|
||||
if (pagador.role === PAGADOR_ROLE_ADMIN) {
|
||||
const handleRemoveRequest = (payer: Payer) => {
|
||||
if (payer.role === PAYER_ROLE_ADMIN) {
|
||||
toast.error("Pagadores administradores não podem ser removidos.");
|
||||
return;
|
||||
}
|
||||
setPagadorToRemove(pagador);
|
||||
setPayerToRemove(payer);
|
||||
setRemoveOpen(true);
|
||||
};
|
||||
|
||||
const handleRemoveOpenChange = (open: boolean) => {
|
||||
setRemoveOpen(open);
|
||||
if (!open) {
|
||||
setPagadorToRemove(null);
|
||||
setPayerToRemove(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveConfirm = async () => {
|
||||
if (!pagadorToRemove) {
|
||||
if (!payerToRemove) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await deletePagadorAction({ id: pagadorToRemove.id });
|
||||
const result = await deletePayerAction({ id: payerToRemove.id });
|
||||
|
||||
if (result.success) {
|
||||
toast.success(result.message);
|
||||
@@ -93,8 +90,8 @@ export function PagadoresPage({
|
||||
throw new Error(result.error);
|
||||
};
|
||||
|
||||
const removeTitle = pagadorToRemove
|
||||
? `Remover pagador "${pagadorToRemove.name}"?`
|
||||
const removeTitle = payerToRemove
|
||||
? `Remover pagador "${payerToRemove.name}"?`
|
||||
: "Remover pagador?";
|
||||
|
||||
const handleJoinByCode = (event: React.FormEvent<HTMLFormElement>) => {
|
||||
@@ -105,7 +102,7 @@ export function PagadoresPage({
|
||||
}
|
||||
|
||||
startJoin(async () => {
|
||||
const result = await joinPagadorByShareCodeAction({
|
||||
const result = await joinPayerByShareCodeAction({
|
||||
code: shareCodeInput.trim(),
|
||||
});
|
||||
|
||||
@@ -124,7 +121,7 @@ export function PagadoresPage({
|
||||
<>
|
||||
<div className="flex flex-col gap-6 w-full">
|
||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<PagadorDialog
|
||||
<PayerDialog
|
||||
mode="create"
|
||||
avatarOptions={avatarOptions}
|
||||
trigger={
|
||||
@@ -151,7 +148,7 @@ export function PagadoresPage({
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{orderedPagadores.length === 0 ? (
|
||||
{orderedPayers.length === 0 ? (
|
||||
<div className="flex min-h-[320px] items-center justify-center rounded-lg border border-dashed bg-muted/30">
|
||||
<div className="max-w-sm text-center text-sm text-muted-foreground">
|
||||
Cadastre seu primeiro pagador para organizar cobranças e
|
||||
@@ -160,14 +157,14 @@ export function PagadoresPage({
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
||||
{orderedPagadores.map((pagador) => (
|
||||
<PagadorCard
|
||||
key={pagador.id}
|
||||
pagador={pagador}
|
||||
onEdit={pagador.canEdit ? () => handleEdit(pagador) : undefined}
|
||||
{orderedPayers.map((payer) => (
|
||||
<PayerCard
|
||||
key={payer.id}
|
||||
payer={payer}
|
||||
onEdit={payer.canEdit ? () => handleEdit(payer) : undefined}
|
||||
onRemove={
|
||||
pagador.canEdit && pagador.role !== PAGADOR_ROLE_ADMIN
|
||||
? () => handleRemoveRequest(pagador)
|
||||
payer.canEdit && payer.role !== PAYER_ROLE_ADMIN
|
||||
? () => handleRemoveRequest(payer)
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
@@ -176,16 +173,16 @@ export function PagadoresPage({
|
||||
)}
|
||||
</div>
|
||||
|
||||
<PagadorDialog
|
||||
<PayerDialog
|
||||
mode="update"
|
||||
pagador={selectedPagador ?? undefined}
|
||||
payer={selectedPayer ?? undefined}
|
||||
avatarOptions={avatarOptions}
|
||||
open={editOpen && !!selectedPagador}
|
||||
open={editOpen && !!selectedPayer}
|
||||
onOpenChange={handleEditOpenChange}
|
||||
/>
|
||||
|
||||
<ConfirmActionDialog
|
||||
open={removeOpen && !!pagadorToRemove}
|
||||
open={removeOpen && !!payerToRemove}
|
||||
onOpenChange={handleRemoveOpenChange}
|
||||
title={removeTitle}
|
||||
description="Ao remover este pagador, os registros relacionados a ele deixarão de ser associados automaticamente."
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { PagadorStatus } from "@/shared/lib/payers/constants";
|
||||
import type { PayerStatus } from "@/shared/lib/payers/constants";
|
||||
|
||||
export type Pagador = {
|
||||
export type Payer = {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string | null;
|
||||
avatarUrl: string | null;
|
||||
status: PagadorStatus;
|
||||
status: PayerStatus;
|
||||
note: string | null;
|
||||
role: string | null;
|
||||
isAutoSend: boolean;
|
||||
@@ -17,10 +17,10 @@ export type Pagador = {
|
||||
shareCode?: string | null;
|
||||
};
|
||||
|
||||
export type PagadorFormValues = {
|
||||
export type PayerFormValues = {
|
||||
name: string;
|
||||
email: string;
|
||||
status: PagadorStatus;
|
||||
status: PayerStatus;
|
||||
avatarUrl: string;
|
||||
note: string;
|
||||
isAutoSend: boolean;
|
||||
|
||||
@@ -4,22 +4,22 @@ import { and, desc, eq } from "drizzle-orm";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { Resend } from "resend";
|
||||
import { z } from "zod";
|
||||
import { lancamentos, pagadores } from "@/db/schema";
|
||||
import { payers, transactions } from "@/db/schema";
|
||||
import { getUser } from "@/shared/lib/auth/server";
|
||||
import { db } from "@/shared/lib/db";
|
||||
import { getResendFromEmail } from "@/shared/lib/email/resend";
|
||||
import {
|
||||
fetchPagadorBoletoStats,
|
||||
fetchPagadorCardUsage,
|
||||
fetchPagadorHistory,
|
||||
fetchPagadorMonthlyBreakdown,
|
||||
fetchPayerHistory,
|
||||
fetchPayerMonthlyBreakdown,
|
||||
} from "@/shared/lib/payers/details";
|
||||
import { formatCurrency } from "@/shared/utils/currency";
|
||||
import { formatDateTime } from "@/shared/utils/date";
|
||||
import { displayPeriod } from "@/shared/utils/period";
|
||||
|
||||
const inputSchema = z.object({
|
||||
pagadorId: z.string().uuid("Pagador inválido."),
|
||||
payerId: z.string().uuid("Payer inválido."),
|
||||
period: z
|
||||
.string()
|
||||
.regex(/^\d{4}-\d{2}$/, "Período inválido. Informe no formato AAAA-MM."),
|
||||
@@ -78,12 +78,12 @@ type ParceladoItem = {
|
||||
type SummaryPayload = {
|
||||
pagadorName: string;
|
||||
periodLabel: string;
|
||||
monthlyBreakdown: Awaited<ReturnType<typeof fetchPagadorMonthlyBreakdown>>;
|
||||
historyData: Awaited<ReturnType<typeof fetchPagadorHistory>>;
|
||||
monthlyBreakdown: Awaited<ReturnType<typeof fetchPayerMonthlyBreakdown>>;
|
||||
historyData: Awaited<ReturnType<typeof fetchPayerHistory>>;
|
||||
cardUsage: Awaited<ReturnType<typeof fetchPagadorCardUsage>>;
|
||||
boletoStats: Awaited<ReturnType<typeof fetchPagadorBoletoStats>>;
|
||||
boletos: BoletoItem[];
|
||||
lancamentos: LancamentoRow[];
|
||||
transactions: LancamentoRow[];
|
||||
parcelados: ParceladoItem[];
|
||||
};
|
||||
|
||||
@@ -98,7 +98,7 @@ const buildSummaryHtml = ({
|
||||
cardUsage,
|
||||
boletoStats,
|
||||
boletos,
|
||||
lancamentos,
|
||||
transactions,
|
||||
parcelados,
|
||||
}: SummaryPayload) => {
|
||||
// Calcular máximo de despesas para barras de progresso
|
||||
@@ -173,9 +173,9 @@ const buildSummaryHtml = ({
|
||||
.join("")
|
||||
: `<tr><td colspan="3" style="padding:16px;text-align:center;color:#94a3b8;">Sem boletos neste período.</td></tr>`;
|
||||
|
||||
const lancamentoRows =
|
||||
lancamentos.length > 0
|
||||
? lancamentos
|
||||
const transactionRows =
|
||||
transactions.length > 0
|
||||
? transactions
|
||||
.map(
|
||||
(item) => `
|
||||
<tr>
|
||||
@@ -361,7 +361,7 @@ const buildSummaryHtml = ({
|
||||
<th style="text-align:right;padding:12px 14px;border-bottom:1px solid #e2e8f0;font-weight:600;color:#475569;">Valor</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>${lancamentoRows}</tbody>
|
||||
<tbody>${transactionRows}</tbody>
|
||||
</table>
|
||||
|
||||
<!-- Lançamentos Parcelados -->
|
||||
@@ -392,19 +392,19 @@ const buildSummaryHtml = ({
|
||||
`;
|
||||
};
|
||||
|
||||
export async function sendPagadorSummaryAction(
|
||||
export async function sendPayerSummaryAction(
|
||||
input: z.infer<typeof inputSchema>,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const { pagadorId, period } = inputSchema.parse(input);
|
||||
const { payerId, period } = inputSchema.parse(input);
|
||||
const user = await getUser();
|
||||
|
||||
const pagadorRow = await db.query.pagadores.findFirst({
|
||||
where: and(eq(pagadores.id, pagadorId), eq(pagadores.userId, user.id)),
|
||||
const pagadorRow = await db.query.payers.findFirst({
|
||||
where: and(eq(payers.id, payerId), eq(payers.userId, user.id)),
|
||||
});
|
||||
|
||||
if (!pagadorRow) {
|
||||
return { success: false, error: "Pagador não encontrado." };
|
||||
return { success: false, error: "Payer não encontrado." };
|
||||
}
|
||||
|
||||
if (!pagadorRow.email) {
|
||||
@@ -432,83 +432,83 @@ export async function sendPagadorSummaryAction(
|
||||
cardUsage,
|
||||
boletoStats,
|
||||
boletoRows,
|
||||
lancamentoRows,
|
||||
transactionRows,
|
||||
parceladoRows,
|
||||
] = await Promise.all([
|
||||
fetchPagadorMonthlyBreakdown({
|
||||
fetchPayerMonthlyBreakdown({
|
||||
userId: user.id,
|
||||
pagadorId,
|
||||
payerId,
|
||||
period,
|
||||
}),
|
||||
fetchPagadorHistory({
|
||||
fetchPayerHistory({
|
||||
userId: user.id,
|
||||
pagadorId,
|
||||
payerId,
|
||||
period,
|
||||
}),
|
||||
fetchPagadorCardUsage({
|
||||
userId: user.id,
|
||||
pagadorId,
|
||||
payerId,
|
||||
period,
|
||||
}),
|
||||
fetchPagadorBoletoStats({
|
||||
userId: user.id,
|
||||
pagadorId,
|
||||
payerId,
|
||||
period,
|
||||
}),
|
||||
db
|
||||
.select({
|
||||
name: lancamentos.name,
|
||||
amount: lancamentos.amount,
|
||||
dueDate: lancamentos.dueDate,
|
||||
name: transactions.name,
|
||||
amount: transactions.amount,
|
||||
dueDate: transactions.dueDate,
|
||||
})
|
||||
.from(lancamentos)
|
||||
.from(transactions)
|
||||
.where(
|
||||
and(
|
||||
eq(lancamentos.userId, user.id),
|
||||
eq(lancamentos.pagadorId, pagadorId),
|
||||
eq(lancamentos.period, period),
|
||||
eq(lancamentos.paymentMethod, "Boleto"),
|
||||
eq(transactions.userId, user.id),
|
||||
eq(transactions.payerId, payerId),
|
||||
eq(transactions.period, period),
|
||||
eq(transactions.paymentMethod, "Boleto"),
|
||||
),
|
||||
)
|
||||
.orderBy(desc(lancamentos.dueDate)),
|
||||
.orderBy(desc(transactions.dueDate)),
|
||||
db
|
||||
.select({
|
||||
id: lancamentos.id,
|
||||
name: lancamentos.name,
|
||||
paymentMethod: lancamentos.paymentMethod,
|
||||
condition: lancamentos.condition,
|
||||
amount: lancamentos.amount,
|
||||
transactionType: lancamentos.transactionType,
|
||||
purchaseDate: lancamentos.purchaseDate,
|
||||
id: transactions.id,
|
||||
name: transactions.name,
|
||||
paymentMethod: transactions.paymentMethod,
|
||||
condition: transactions.condition,
|
||||
amount: transactions.amount,
|
||||
transactionType: transactions.transactionType,
|
||||
purchaseDate: transactions.purchaseDate,
|
||||
})
|
||||
.from(lancamentos)
|
||||
.from(transactions)
|
||||
.where(
|
||||
and(
|
||||
eq(lancamentos.userId, user.id),
|
||||
eq(lancamentos.pagadorId, pagadorId),
|
||||
eq(lancamentos.period, period),
|
||||
eq(transactions.userId, user.id),
|
||||
eq(transactions.payerId, payerId),
|
||||
eq(transactions.period, period),
|
||||
),
|
||||
)
|
||||
.orderBy(desc(lancamentos.purchaseDate)),
|
||||
.orderBy(desc(transactions.purchaseDate)),
|
||||
db
|
||||
.select({
|
||||
name: lancamentos.name,
|
||||
amount: lancamentos.amount,
|
||||
installmentCount: lancamentos.installmentCount,
|
||||
currentInstallment: lancamentos.currentInstallment,
|
||||
purchaseDate: lancamentos.purchaseDate,
|
||||
name: transactions.name,
|
||||
amount: transactions.amount,
|
||||
installmentCount: transactions.installmentCount,
|
||||
currentInstallment: transactions.currentInstallment,
|
||||
purchaseDate: transactions.purchaseDate,
|
||||
})
|
||||
.from(lancamentos)
|
||||
.from(transactions)
|
||||
.where(
|
||||
and(
|
||||
eq(lancamentos.userId, user.id),
|
||||
eq(lancamentos.pagadorId, pagadorId),
|
||||
eq(lancamentos.period, period),
|
||||
eq(lancamentos.condition, "Parcelado"),
|
||||
eq(lancamentos.isAnticipated, false),
|
||||
eq(transactions.userId, user.id),
|
||||
eq(transactions.payerId, payerId),
|
||||
eq(transactions.period, period),
|
||||
eq(transactions.condition, "Parcelado"),
|
||||
eq(transactions.isAnticipated, false),
|
||||
),
|
||||
)
|
||||
.orderBy(desc(lancamentos.purchaseDate)),
|
||||
.orderBy(desc(transactions.purchaseDate)),
|
||||
]);
|
||||
|
||||
const normalizedBoletos: BoletoItem[] = (
|
||||
@@ -524,7 +524,7 @@ export async function sendPagadorSummaryAction(
|
||||
}));
|
||||
|
||||
const normalizedLancamentos: LancamentoRow[] = (
|
||||
lancamentoRows as Array<{
|
||||
transactionRows as Array<{
|
||||
id: string;
|
||||
name: string | null;
|
||||
paymentMethod: string | null;
|
||||
@@ -574,7 +574,7 @@ export async function sendPagadorSummaryAction(
|
||||
cardUsage,
|
||||
boletoStats,
|
||||
boletos: normalizedBoletos,
|
||||
lancamentos: normalizedLancamentos,
|
||||
transactions: normalizedLancamentos,
|
||||
parcelados: normalizedParcelados,
|
||||
});
|
||||
|
||||
@@ -588,11 +588,9 @@ export async function sendPagadorSummaryAction(
|
||||
const now = new Date();
|
||||
|
||||
await db
|
||||
.update(pagadores)
|
||||
.update(payers)
|
||||
.set({ lastMailAt: now })
|
||||
.where(
|
||||
and(eq(pagadores.id, pagadorRow.id), eq(pagadores.userId, user.id)),
|
||||
);
|
||||
.where(and(eq(payers.id, pagadorRow.id), eq(payers.userId, user.id)));
|
||||
|
||||
revalidatePath(`/payers/${pagadorRow.id}`);
|
||||
|
||||
@@ -600,7 +598,7 @@ export async function sendPagadorSummaryAction(
|
||||
} catch (error) {
|
||||
// Log estruturado em desenvolvimento
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
console.error("[sendPagadorSummaryAction]", error);
|
||||
console.error("[sendPayerSummaryAction]", error);
|
||||
}
|
||||
|
||||
// Tratar erros de validação separadamente
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { and, desc, eq, type SQL } from "drizzle-orm";
|
||||
import {
|
||||
cartoes,
|
||||
categorias,
|
||||
compartilhamentosPagador,
|
||||
contas,
|
||||
lancamentos,
|
||||
pagadores,
|
||||
cards,
|
||||
categories,
|
||||
financialAccounts,
|
||||
payerShares,
|
||||
payers,
|
||||
transactions,
|
||||
user as usersTable,
|
||||
} from "@/db/schema";
|
||||
import { db } from "@/shared/lib/db";
|
||||
@@ -18,23 +18,18 @@ export type ShareData = {
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
export async function fetchPagadorShares(
|
||||
pagadorId: string,
|
||||
): Promise<ShareData[]> {
|
||||
export async function fetchPayerShares(payerId: string): Promise<ShareData[]> {
|
||||
const shareRows = await db
|
||||
.select({
|
||||
id: compartilhamentosPagador.id,
|
||||
sharedWithUserId: compartilhamentosPagador.sharedWithUserId,
|
||||
createdAt: compartilhamentosPagador.createdAt,
|
||||
id: payerShares.id,
|
||||
sharedWithUserId: payerShares.sharedWithUserId,
|
||||
createdAt: payerShares.createdAt,
|
||||
userName: usersTable.name,
|
||||
userEmail: usersTable.email,
|
||||
})
|
||||
.from(compartilhamentosPagador)
|
||||
.innerJoin(
|
||||
usersTable,
|
||||
eq(compartilhamentosPagador.sharedWithUserId, usersTable.id),
|
||||
)
|
||||
.where(eq(compartilhamentosPagador.pagadorId, pagadorId));
|
||||
.from(payerShares)
|
||||
.innerJoin(usersTable, eq(payerShares.sharedWithUserId, usersTable.id))
|
||||
.where(eq(payerShares.payerId, payerId));
|
||||
|
||||
return shareRows.map((share) => ({
|
||||
id: share.id,
|
||||
@@ -46,17 +41,17 @@ export async function fetchPagadorShares(
|
||||
}
|
||||
|
||||
export async function fetchCurrentUserShare(
|
||||
pagadorId: string,
|
||||
payerId: string,
|
||||
userId: string,
|
||||
): Promise<{ id: string; createdAt: string } | null> {
|
||||
const shareRow = await db.query.compartilhamentosPagador.findFirst({
|
||||
const shareRow = await db.query.payerShares.findFirst({
|
||||
columns: {
|
||||
id: true,
|
||||
createdAt: true,
|
||||
},
|
||||
where: and(
|
||||
eq(compartilhamentosPagador.pagadorId, pagadorId),
|
||||
eq(compartilhamentosPagador.sharedWithUserId, userId),
|
||||
eq(payerShares.payerId, payerId),
|
||||
eq(payerShares.sharedWithUserId, userId),
|
||||
),
|
||||
});
|
||||
|
||||
@@ -71,28 +66,31 @@ export async function fetchCurrentUserShare(
|
||||
}
|
||||
|
||||
export async function fetchPagadorLancamentos(filters: SQL[]) {
|
||||
const lancamentoRows = await db
|
||||
const transactionRows = await db
|
||||
.select({
|
||||
lancamento: lancamentos,
|
||||
pagador: pagadores,
|
||||
conta: contas,
|
||||
cartao: cartoes,
|
||||
categoria: categorias,
|
||||
transaction: transactions,
|
||||
payer: payers,
|
||||
financialAccount: financialAccounts,
|
||||
card: cards,
|
||||
category: categories,
|
||||
})
|
||||
.from(lancamentos)
|
||||
.leftJoin(pagadores, eq(lancamentos.pagadorId, pagadores.id))
|
||||
.leftJoin(contas, eq(lancamentos.contaId, contas.id))
|
||||
.leftJoin(cartoes, eq(lancamentos.cartaoId, cartoes.id))
|
||||
.leftJoin(categorias, eq(lancamentos.categoriaId, categorias.id))
|
||||
.from(transactions)
|
||||
.leftJoin(payers, eq(transactions.payerId, payers.id))
|
||||
.leftJoin(
|
||||
financialAccounts,
|
||||
eq(transactions.accountId, financialAccounts.id),
|
||||
)
|
||||
.leftJoin(cards, eq(transactions.cardId, cards.id))
|
||||
.leftJoin(categories, eq(transactions.categoryId, categories.id))
|
||||
.where(and(...filters))
|
||||
.orderBy(desc(lancamentos.purchaseDate), desc(lancamentos.createdAt));
|
||||
.orderBy(desc(transactions.purchaseDate), desc(transactions.createdAt));
|
||||
|
||||
// Transformar resultado para o formato esperado
|
||||
return lancamentoRows.map((row: Record<string, unknown>) => ({
|
||||
...row.lancamento,
|
||||
pagador: row.pagador,
|
||||
conta: row.conta,
|
||||
cartao: row.cartao,
|
||||
categoria: row.categoria,
|
||||
return transactionRows.map((row) => ({
|
||||
...row.transaction,
|
||||
payer: row.payer,
|
||||
financialAccount: row.financialAccount,
|
||||
card: row.card,
|
||||
category: row.category,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { readdir } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { DEFAULT_PAGADOR_AVATAR } from "@/shared/lib/payers/constants";
|
||||
import { DEFAULT_PAYER_AVATAR } from "@/shared/lib/payers/constants";
|
||||
|
||||
const AVATAR_DIRECTORY = path.join(process.cwd(), "public", "avatars");
|
||||
const AVATAR_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".svg", ".webp"]);
|
||||
@@ -20,11 +20,11 @@ export async function loadAvatarOptions() {
|
||||
.sort((a, b) => a.localeCompare(b, "pt-BR", { sensitivity: "base" }));
|
||||
|
||||
if (items.length === 0) {
|
||||
items.push(DEFAULT_PAGADOR_AVATAR);
|
||||
items.push(DEFAULT_PAYER_AVATAR);
|
||||
}
|
||||
|
||||
return Array.from(new Set(items));
|
||||
} catch {
|
||||
return [DEFAULT_PAGADOR_AVATAR];
|
||||
return [DEFAULT_PAYER_AVATAR];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { pagadores } from "@/db/schema";
|
||||
import type { payers } from "@/db/schema";
|
||||
import type {
|
||||
ContaCartaoFilterOption,
|
||||
LancamentoFilterOption,
|
||||
LancamentoItem,
|
||||
AccountCardFilterOption,
|
||||
TransactionFilterOption,
|
||||
SelectOption,
|
||||
TransactionItem,
|
||||
} from "@/features/transactions/components/types";
|
||||
import type { buildOptionSets } from "@/features/transactions/page-helpers";
|
||||
|
||||
@@ -15,15 +15,15 @@ const normalizeOptionLabel = (
|
||||
) => (value?.trim().length ? value.trim() : fallback);
|
||||
|
||||
export function buildReadOnlyOptionSets(
|
||||
items: LancamentoItem[],
|
||||
pagador: typeof pagadores.$inferSelect,
|
||||
items: TransactionItem[],
|
||||
payer: typeof payers.$inferSelect,
|
||||
): OptionSet {
|
||||
const pagadorLabel = normalizeOptionLabel(pagador.name, "Pagador");
|
||||
const pagadorOptions: SelectOption[] = [
|
||||
const pagadorLabel = normalizeOptionLabel(payer.name, "Payer");
|
||||
const payerOptions: SelectOption[] = [
|
||||
{
|
||||
value: pagador.id,
|
||||
value: payer.id,
|
||||
label: pagadorLabel,
|
||||
slug: pagador.id,
|
||||
slug: payer.id,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -32,51 +32,54 @@ export function buildReadOnlyOptionSets(
|
||||
const categoriaOptionsMap = new Map<string, SelectOption>();
|
||||
|
||||
items.forEach((item) => {
|
||||
if (item.contaId && !contaOptionsMap.has(item.contaId)) {
|
||||
contaOptionsMap.set(item.contaId, {
|
||||
value: item.contaId,
|
||||
label: normalizeOptionLabel(item.contaName, "Conta sem nome"),
|
||||
slug: item.contaId,
|
||||
if (item.accountId && !contaOptionsMap.has(item.accountId)) {
|
||||
contaOptionsMap.set(item.accountId, {
|
||||
value: item.accountId,
|
||||
label: normalizeOptionLabel(
|
||||
item.contaName,
|
||||
"FinancialAccount sem nome",
|
||||
),
|
||||
slug: item.accountId,
|
||||
});
|
||||
}
|
||||
if (item.cartaoId && !cartaoOptionsMap.has(item.cartaoId)) {
|
||||
cartaoOptionsMap.set(item.cartaoId, {
|
||||
value: item.cartaoId,
|
||||
if (item.cardId && !cartaoOptionsMap.has(item.cardId)) {
|
||||
cartaoOptionsMap.set(item.cardId, {
|
||||
value: item.cardId,
|
||||
label: normalizeOptionLabel(item.cartaoName, "Cartão sem nome"),
|
||||
slug: item.cartaoId,
|
||||
slug: item.cardId,
|
||||
});
|
||||
}
|
||||
if (item.categoriaId && !categoriaOptionsMap.has(item.categoriaId)) {
|
||||
categoriaOptionsMap.set(item.categoriaId, {
|
||||
value: item.categoriaId,
|
||||
label: normalizeOptionLabel(item.categoriaName, "Categoria"),
|
||||
slug: item.categoriaId,
|
||||
if (item.categoryId && !categoriaOptionsMap.has(item.categoryId)) {
|
||||
categoriaOptionsMap.set(item.categoryId, {
|
||||
value: item.categoryId,
|
||||
label: normalizeOptionLabel(item.categoriaName, "Category"),
|
||||
slug: item.categoryId,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const contaOptions = Array.from(contaOptionsMap.values());
|
||||
const cartaoOptions = Array.from(cartaoOptionsMap.values());
|
||||
const categoriaOptions = Array.from(categoriaOptionsMap.values());
|
||||
const accountOptions = Array.from(contaOptionsMap.values());
|
||||
const cardOptions = Array.from(cartaoOptionsMap.values());
|
||||
const categoryOptions = Array.from(categoriaOptionsMap.values());
|
||||
|
||||
const pagadorFilterOptions: LancamentoFilterOption[] = [
|
||||
{ slug: pagador.id, label: pagadorLabel },
|
||||
const payerFilterOptions: TransactionFilterOption[] = [
|
||||
{ slug: payer.id, label: pagadorLabel },
|
||||
];
|
||||
|
||||
const categoriaFilterOptions: LancamentoFilterOption[] = categoriaOptions.map(
|
||||
const categoryFilterOptions: TransactionFilterOption[] = categoryOptions.map(
|
||||
(option) => ({
|
||||
slug: option.value,
|
||||
label: option.label,
|
||||
}),
|
||||
);
|
||||
|
||||
const contaCartaoFilterOptions: ContaCartaoFilterOption[] = [
|
||||
...contaOptions.map((option) => ({
|
||||
const accountCardFilterOptions: AccountCardFilterOption[] = [
|
||||
...accountOptions.map((option) => ({
|
||||
slug: option.value,
|
||||
label: option.label,
|
||||
kind: "conta" as const,
|
||||
})),
|
||||
...cartaoOptions.map((option) => ({
|
||||
...cardOptions.map((option) => ({
|
||||
slug: option.value,
|
||||
label: option.label,
|
||||
kind: "cartao" as const,
|
||||
@@ -84,14 +87,14 @@ export function buildReadOnlyOptionSets(
|
||||
];
|
||||
|
||||
return {
|
||||
pagadorOptions,
|
||||
splitPagadorOptions: [],
|
||||
defaultPagadorId: pagador.id,
|
||||
contaOptions,
|
||||
cartaoOptions,
|
||||
categoriaOptions,
|
||||
pagadorFilterOptions,
|
||||
categoriaFilterOptions,
|
||||
contaCartaoFilterOptions,
|
||||
payerOptions,
|
||||
splitPayerOptions: [],
|
||||
defaultPayerId: payer.id,
|
||||
accountOptions,
|
||||
cardOptions,
|
||||
categoryOptions,
|
||||
payerFilterOptions,
|
||||
categoryFilterOptions,
|
||||
accountCardFilterOptions,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,21 +2,21 @@ import { eq } from "drizzle-orm";
|
||||
import { user } from "@/db/schema";
|
||||
import { loadAvatarOptions } from "@/features/payers/lib/avatar-options";
|
||||
import { db } from "@/shared/lib/db";
|
||||
import { fetchPagadoresWithAccess } from "@/shared/lib/payers/access";
|
||||
import type { PagadorStatus } from "@/shared/lib/payers/constants";
|
||||
import { fetchPayersWithAccess } from "@/shared/lib/payers/access";
|
||||
import type { PayerStatus } from "@/shared/lib/payers/constants";
|
||||
import {
|
||||
PAGADOR_ROLE_ADMIN,
|
||||
PAGADOR_STATUS_OPTIONS,
|
||||
PAYER_ROLE_ADMIN,
|
||||
PAYER_STATUS_OPTIONS,
|
||||
} from "@/shared/lib/payers/constants";
|
||||
|
||||
export type PagadorData = {
|
||||
export type PayerData = {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string | null;
|
||||
avatarUrl: string | null;
|
||||
status: PagadorStatus;
|
||||
status: PayerStatus;
|
||||
note: string | null;
|
||||
role: string;
|
||||
role: string | null;
|
||||
isAutoSend: boolean;
|
||||
createdAt: string;
|
||||
canEdit: boolean;
|
||||
@@ -26,19 +26,19 @@ export type PagadorData = {
|
||||
shareCode: string | null;
|
||||
};
|
||||
|
||||
const resolveStatus = (status: string | null): PagadorStatus => {
|
||||
const resolveStatus = (status: string | null): PayerStatus => {
|
||||
const normalized = status?.trim() ?? "";
|
||||
const found = PAGADOR_STATUS_OPTIONS.find(
|
||||
const found = PAYER_STATUS_OPTIONS.find(
|
||||
(option) => option.toLowerCase() === normalized.toLowerCase(),
|
||||
);
|
||||
return found ?? PAGADOR_STATUS_OPTIONS[0];
|
||||
return found ?? PAYER_STATUS_OPTIONS[0];
|
||||
};
|
||||
|
||||
export async function fetchPagadoresForUser(
|
||||
export async function fetchPayersForUser(
|
||||
userId: string,
|
||||
): Promise<{ pagadores: PagadorData[]; avatarOptions: string[] }> {
|
||||
const [pagadorRows, localAvatarOptions, userData] = await Promise.all([
|
||||
fetchPagadoresWithAccess(userId),
|
||||
): Promise<{ payers: PayerData[]; avatarOptions: string[] }> {
|
||||
const [payerRows, localAvatarOptions, userData] = await Promise.all([
|
||||
fetchPayersWithAccess(userId),
|
||||
loadAvatarOptions(),
|
||||
db.query.user.findFirst({
|
||||
columns: { image: true },
|
||||
@@ -51,7 +51,7 @@ export async function fetchPagadoresForUser(
|
||||
? [userImage, ...localAvatarOptions]
|
||||
: localAvatarOptions;
|
||||
|
||||
const pagadores = pagadorRows
|
||||
const payers = payerRows
|
||||
.map((pagador) => ({
|
||||
id: pagador.id,
|
||||
name: pagador.name,
|
||||
@@ -69,12 +69,10 @@ export async function fetchPagadoresForUser(
|
||||
shareCode: pagador.canEdit ? (pagador.shareCode ?? null) : null,
|
||||
}))
|
||||
.sort((a, b) => {
|
||||
if (a.role === PAGADOR_ROLE_ADMIN && b.role !== PAGADOR_ROLE_ADMIN)
|
||||
return -1;
|
||||
if (a.role !== PAGADOR_ROLE_ADMIN && b.role === PAGADOR_ROLE_ADMIN)
|
||||
return 1;
|
||||
if (a.role === PAYER_ROLE_ADMIN && b.role !== PAYER_ROLE_ADMIN) return -1;
|
||||
if (a.role !== PAYER_ROLE_ADMIN && b.role === PAYER_ROLE_ADMIN) return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
return { pagadores, avatarOptions };
|
||||
return { payers, avatarOptions };
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ export function createSidebarNavData(
|
||||
.map((pagador) => ({
|
||||
title: pagador.name?.trim().length
|
||||
? pagador.name.trim()
|
||||
: "Pagador sem nome",
|
||||
: "Payer sem nome",
|
||||
url: `/payers/${pagador.id}`,
|
||||
key: pagador.canEdit ? pagador.id : `${pagador.id}-shared`,
|
||||
isShared: !pagador.canEdit,
|
||||
|
||||
@@ -115,7 +115,7 @@ export const auth = betterAuth({
|
||||
/**
|
||||
* Após criar novo usuário, inicializa:
|
||||
* 1. Categorias padrão (Receitas/Despesas)
|
||||
* 2. Pagador padrão (vinculado ao usuário)
|
||||
* 2. Payer padrão (vinculado ao usuário)
|
||||
*/
|
||||
after: async (user) => {
|
||||
// Se falhar aqui, o usuário já foi criado - considere usar queue para retry
|
||||
|
||||
@@ -1,42 +1,36 @@
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import {
|
||||
compartilhamentosPagador,
|
||||
pagadores,
|
||||
user as usersTable,
|
||||
} from "@/db/schema";
|
||||
import { payerShares, payers, user as usersTable } from "@/db/schema";
|
||||
import { db } from "@/shared/lib/db";
|
||||
|
||||
export type PagadorWithAccess = typeof pagadores.$inferSelect & {
|
||||
export type PayerWithAccess = Omit<typeof payers.$inferSelect, "shareCode"> & {
|
||||
shareCode: string | null;
|
||||
canEdit: boolean;
|
||||
sharedByName: string | null;
|
||||
sharedByEmail: string | null;
|
||||
shareId: string | null;
|
||||
};
|
||||
|
||||
export async function fetchPagadoresWithAccess(
|
||||
export async function fetchPayersWithAccess(
|
||||
userId: string,
|
||||
): Promise<PagadorWithAccess[]> {
|
||||
): Promise<PayerWithAccess[]> {
|
||||
const [owned, shared] = await Promise.all([
|
||||
db.query.pagadores.findMany({
|
||||
where: eq(pagadores.userId, userId),
|
||||
db.query.payers.findMany({
|
||||
where: eq(payers.userId, userId),
|
||||
}),
|
||||
db
|
||||
.select({
|
||||
shareId: compartilhamentosPagador.id,
|
||||
pagador: pagadores,
|
||||
shareId: payerShares.id,
|
||||
payer: payers,
|
||||
ownerName: usersTable.name,
|
||||
ownerEmail: usersTable.email,
|
||||
})
|
||||
.from(compartilhamentosPagador)
|
||||
.innerJoin(
|
||||
pagadores,
|
||||
eq(compartilhamentosPagador.pagadorId, pagadores.id),
|
||||
)
|
||||
.leftJoin(usersTable, eq(pagadores.userId, usersTable.id))
|
||||
.where(eq(compartilhamentosPagador.sharedWithUserId, userId)),
|
||||
.from(payerShares)
|
||||
.innerJoin(payers, eq(payerShares.payerId, payers.id))
|
||||
.leftJoin(usersTable, eq(payers.userId, usersTable.id))
|
||||
.where(eq(payerShares.sharedWithUserId, userId)),
|
||||
]);
|
||||
|
||||
const ownedMapped: PagadorWithAccess[] = owned.map((item) => ({
|
||||
const ownedMapped: PayerWithAccess[] = owned.map((item) => ({
|
||||
...item,
|
||||
canEdit: true,
|
||||
sharedByName: null,
|
||||
@@ -44,8 +38,8 @@ export async function fetchPagadoresWithAccess(
|
||||
shareId: null,
|
||||
}));
|
||||
|
||||
const sharedMapped: PagadorWithAccess[] = shared.map((item) => ({
|
||||
...item.pagador,
|
||||
const sharedMapped: PayerWithAccess[] = shared.map((item) => ({
|
||||
...(item.payer as typeof payers.$inferSelect),
|
||||
shareCode: null,
|
||||
canEdit: false,
|
||||
sharedByName: item.ownerName ?? null,
|
||||
@@ -56,9 +50,9 @@ export async function fetchPagadoresWithAccess(
|
||||
return [...ownedMapped, ...sharedMapped];
|
||||
}
|
||||
|
||||
export async function getPagadorAccess(userId: string, pagadorId: string) {
|
||||
const pagador = await db.query.pagadores.findFirst({
|
||||
where: and(eq(pagadores.id, pagadorId)),
|
||||
export async function getPayerAccess(userId: string, payerId: string) {
|
||||
const pagador = await db.query.payers.findFirst({
|
||||
where: and(eq(payers.id, payerId)),
|
||||
});
|
||||
|
||||
if (!pagador) {
|
||||
@@ -69,14 +63,14 @@ export async function getPagadorAccess(userId: string, pagadorId: string) {
|
||||
return {
|
||||
pagador,
|
||||
canEdit: true,
|
||||
share: null as typeof compartilhamentosPagador.$inferSelect | null,
|
||||
share: null as typeof payerShares.$inferSelect | null,
|
||||
};
|
||||
}
|
||||
|
||||
const share = await db.query.compartilhamentosPagador.findFirst({
|
||||
const share = await db.query.payerShares.findFirst({
|
||||
where: and(
|
||||
eq(compartilhamentosPagador.pagadorId, pagadorId),
|
||||
eq(compartilhamentosPagador.sharedWithUserId, userId),
|
||||
eq(payerShares.payerId, payerId),
|
||||
eq(payerShares.sharedWithUserId, userId),
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export const PAGADOR_STATUS_OPTIONS = ["Ativo", "Inativo"] as const;
|
||||
export const PAYER_STATUS_OPTIONS = ["Ativo", "Inativo"] as const;
|
||||
|
||||
export type PagadorStatus = (typeof PAGADOR_STATUS_OPTIONS)[number];
|
||||
export type PayerStatus = (typeof PAYER_STATUS_OPTIONS)[number];
|
||||
|
||||
export const PAGADOR_ROLE_ADMIN = "admin";
|
||||
export const PAGADOR_ROLE_TERCEIRO = "terceiro";
|
||||
export const DEFAULT_PAGADOR_AVATAR = "default_icon.png";
|
||||
export const PAYER_ROLE_ADMIN = "admin";
|
||||
export const PAYER_ROLE_THIRD_PARTY = "terceiro";
|
||||
export const DEFAULT_PAYER_AVATAR = "default_icon.png";
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { pagadores } from "@/db/schema";
|
||||
import { payers } from "@/db/schema";
|
||||
import { db } from "@/shared/lib/db";
|
||||
import {
|
||||
DEFAULT_PAGADOR_AVATAR,
|
||||
PAGADOR_ROLE_ADMIN,
|
||||
PAGADOR_STATUS_OPTIONS,
|
||||
DEFAULT_PAYER_AVATAR,
|
||||
PAYER_ROLE_ADMIN,
|
||||
PAYER_STATUS_OPTIONS,
|
||||
} from "./constants";
|
||||
import { normalizeNameFromEmail } from "./utils";
|
||||
|
||||
const DEFAULT_STATUS = PAGADOR_STATUS_OPTIONS[0];
|
||||
const DEFAULT_STATUS = PAYER_STATUS_OPTIONS[0];
|
||||
|
||||
interface SeedUserLike {
|
||||
id?: string;
|
||||
@@ -24,9 +24,9 @@ export async function ensureDefaultPagadorForUser(user: SeedUserLike) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hasAnyPagador = await db.query.pagadores.findFirst({
|
||||
const hasAnyPagador = await db.query.payers.findFirst({
|
||||
columns: { id: true, role: true },
|
||||
where: eq(pagadores.userId, userId),
|
||||
where: eq(payers.userId, userId),
|
||||
});
|
||||
|
||||
if (hasAnyPagador) {
|
||||
@@ -36,16 +36,16 @@ export async function ensureDefaultPagadorForUser(user: SeedUserLike) {
|
||||
const name =
|
||||
(user.name && user.name.trim().length > 0
|
||||
? user.name.trim()
|
||||
: normalizeNameFromEmail(user.email)) || "Pagador principal";
|
||||
: normalizeNameFromEmail(user.email)) || "Payer principal";
|
||||
|
||||
// Usa a imagem do Google se disponível, senão usa o avatar padrão
|
||||
const avatarUrl = user.image ?? DEFAULT_PAGADOR_AVATAR;
|
||||
const avatarUrl = user.image ?? DEFAULT_PAYER_AVATAR;
|
||||
|
||||
await db.insert(pagadores).values({
|
||||
await db.insert(payers).values({
|
||||
name,
|
||||
email: user.email ?? null,
|
||||
status: DEFAULT_STATUS,
|
||||
role: PAGADOR_ROLE_ADMIN,
|
||||
role: PAYER_ROLE_ADMIN,
|
||||
avatarUrl,
|
||||
note: null,
|
||||
isAutoSend: false,
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
sql,
|
||||
sum,
|
||||
} from "drizzle-orm";
|
||||
import { cartoes, lancamentos } from "@/db/schema";
|
||||
import { cards, transactions } from "@/db/schema";
|
||||
import { ACCOUNT_AUTO_INVOICE_NOTE_PREFIX } from "@/shared/lib/accounts/constants";
|
||||
import { db } from "@/shared/lib/db";
|
||||
import { toDateOnlyString } from "@/shared/utils/date";
|
||||
@@ -27,27 +27,27 @@ const DESPESA = "Despesa";
|
||||
const PAYMENT_METHOD_CARD = "Cartão de crédito";
|
||||
const PAYMENT_METHOD_BOLETO = "Boleto";
|
||||
|
||||
export type PagadorMonthlyBreakdown = {
|
||||
export type PayerMonthlyBreakdown = {
|
||||
totalExpenses: number;
|
||||
totalIncomes: number;
|
||||
paymentSplits: Record<"card" | "boleto" | "instant", number>;
|
||||
};
|
||||
|
||||
export type PagadorHistoryPoint = {
|
||||
export type PayerHistoryPoint = {
|
||||
period: string;
|
||||
label: string;
|
||||
receitas: number;
|
||||
despesas: number;
|
||||
};
|
||||
|
||||
export type PagadorCardUsageItem = {
|
||||
export type PayerCardUsageItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
logo: string | null;
|
||||
amount: number;
|
||||
};
|
||||
|
||||
export type PagadorBoletoStats = {
|
||||
export type PayerBoletoStats = {
|
||||
totalAmount: number;
|
||||
paidAmount: number;
|
||||
pendingAmount: number;
|
||||
@@ -55,7 +55,7 @@ export type PagadorBoletoStats = {
|
||||
pendingCount: number;
|
||||
};
|
||||
|
||||
export type PagadorBoletoItem = {
|
||||
export type PayerBoletoItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
amount: number;
|
||||
@@ -64,7 +64,7 @@ export type PagadorBoletoItem = {
|
||||
isSettled: boolean;
|
||||
};
|
||||
|
||||
export type PagadorPaymentStatusData = {
|
||||
export type PayerPaymentStatusData = {
|
||||
paidAmount: number;
|
||||
paidCount: number;
|
||||
pendingAmount: number;
|
||||
@@ -74,39 +74,39 @@ export type PagadorPaymentStatusData = {
|
||||
|
||||
const excludeAutoInvoiceEntries = () =>
|
||||
or(
|
||||
isNull(lancamentos.note),
|
||||
not(ilike(lancamentos.note, `${ACCOUNT_AUTO_INVOICE_NOTE_PREFIX}%`)),
|
||||
isNull(transactions.note),
|
||||
not(ilike(transactions.note, `${ACCOUNT_AUTO_INVOICE_NOTE_PREFIX}%`)),
|
||||
);
|
||||
|
||||
type BaseFilters = {
|
||||
userId: string;
|
||||
pagadorId: string;
|
||||
payerId: string;
|
||||
period: string;
|
||||
};
|
||||
|
||||
export async function fetchPagadorMonthlyBreakdown({
|
||||
export async function fetchPayerMonthlyBreakdown({
|
||||
userId,
|
||||
pagadorId,
|
||||
payerId,
|
||||
period,
|
||||
}: BaseFilters): Promise<PagadorMonthlyBreakdown> {
|
||||
}: BaseFilters): Promise<PayerMonthlyBreakdown> {
|
||||
const rows = await db
|
||||
.select({
|
||||
paymentMethod: lancamentos.paymentMethod,
|
||||
transactionType: lancamentos.transactionType,
|
||||
totalAmount: sum(lancamentos.amount).as("total"),
|
||||
paymentMethod: transactions.paymentMethod,
|
||||
transactionType: transactions.transactionType,
|
||||
totalAmount: sum(transactions.amount).as("total"),
|
||||
})
|
||||
.from(lancamentos)
|
||||
.from(transactions)
|
||||
.where(
|
||||
and(
|
||||
eq(lancamentos.userId, userId),
|
||||
eq(lancamentos.pagadorId, pagadorId),
|
||||
eq(lancamentos.period, period),
|
||||
eq(transactions.userId, userId),
|
||||
eq(transactions.payerId, payerId),
|
||||
eq(transactions.period, period),
|
||||
excludeAutoInvoiceEntries(),
|
||||
),
|
||||
)
|
||||
.groupBy(lancamentos.paymentMethod, lancamentos.transactionType);
|
||||
.groupBy(transactions.paymentMethod, transactions.transactionType);
|
||||
|
||||
const paymentSplits: PagadorMonthlyBreakdown["paymentSplits"] = {
|
||||
const paymentSplits: PayerMonthlyBreakdown["paymentSplits"] = {
|
||||
card: 0,
|
||||
boleto: 0,
|
||||
instant: 0,
|
||||
@@ -137,12 +137,12 @@ export async function fetchPagadorMonthlyBreakdown({
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchPagadorHistory({
|
||||
export async function fetchPayerHistory({
|
||||
userId,
|
||||
pagadorId,
|
||||
payerId,
|
||||
period,
|
||||
months = 6,
|
||||
}: BaseFilters & { months?: number }): Promise<PagadorHistoryPoint[]> {
|
||||
}: BaseFilters & { months?: number }): Promise<PayerHistoryPoint[]> {
|
||||
const startPeriod = addMonthsToPeriod(period, -(Math.max(months, 1) - 1));
|
||||
const windowPeriods = buildPeriodRange(startPeriod, period);
|
||||
const start = windowPeriods[0];
|
||||
@@ -150,21 +150,21 @@ export async function fetchPagadorHistory({
|
||||
|
||||
const rows = await db
|
||||
.select({
|
||||
period: lancamentos.period,
|
||||
transactionType: lancamentos.transactionType,
|
||||
totalAmount: sum(lancamentos.amount).as("total"),
|
||||
period: transactions.period,
|
||||
transactionType: transactions.transactionType,
|
||||
totalAmount: sum(transactions.amount).as("total"),
|
||||
})
|
||||
.from(lancamentos)
|
||||
.from(transactions)
|
||||
.where(
|
||||
and(
|
||||
eq(lancamentos.userId, userId),
|
||||
eq(lancamentos.pagadorId, pagadorId),
|
||||
gte(lancamentos.period, start),
|
||||
lte(lancamentos.period, end),
|
||||
eq(transactions.userId, userId),
|
||||
eq(transactions.payerId, payerId),
|
||||
gte(transactions.period, start),
|
||||
lte(transactions.period, end),
|
||||
excludeAutoInvoiceEntries(),
|
||||
),
|
||||
)
|
||||
.groupBy(lancamentos.period, lancamentos.transactionType);
|
||||
.groupBy(transactions.period, transactions.transactionType);
|
||||
|
||||
const totalsByPeriod = new Map<
|
||||
string,
|
||||
@@ -198,38 +198,38 @@ export async function fetchPagadorHistory({
|
||||
|
||||
export async function fetchPagadorCardUsage({
|
||||
userId,
|
||||
pagadorId,
|
||||
payerId,
|
||||
period,
|
||||
}: BaseFilters): Promise<PagadorCardUsageItem[]> {
|
||||
}: BaseFilters): Promise<PayerCardUsageItem[]> {
|
||||
const rows = await db
|
||||
.select({
|
||||
cartaoId: lancamentos.cartaoId,
|
||||
cardName: cartoes.name,
|
||||
cardLogo: cartoes.logo,
|
||||
totalAmount: sum(lancamentos.amount).as("total"),
|
||||
cardId: transactions.cardId,
|
||||
cardName: cards.name,
|
||||
cardLogo: cards.logo,
|
||||
totalAmount: sum(transactions.amount).as("total"),
|
||||
})
|
||||
.from(lancamentos)
|
||||
.innerJoin(cartoes, eq(lancamentos.cartaoId, cartoes.id))
|
||||
.from(transactions)
|
||||
.innerJoin(cards, eq(transactions.cardId, cards.id))
|
||||
.where(
|
||||
and(
|
||||
eq(lancamentos.userId, userId),
|
||||
eq(lancamentos.pagadorId, pagadorId),
|
||||
eq(lancamentos.period, period),
|
||||
eq(lancamentos.paymentMethod, PAYMENT_METHOD_CARD),
|
||||
eq(transactions.userId, userId),
|
||||
eq(transactions.payerId, payerId),
|
||||
eq(transactions.period, period),
|
||||
eq(transactions.paymentMethod, PAYMENT_METHOD_CARD),
|
||||
excludeAutoInvoiceEntries(),
|
||||
),
|
||||
)
|
||||
.groupBy(lancamentos.cartaoId, cartoes.name, cartoes.logo);
|
||||
.groupBy(transactions.cardId, cards.name, cards.logo);
|
||||
|
||||
const items: PagadorCardUsageItem[] = [];
|
||||
const items: PayerCardUsageItem[] = [];
|
||||
|
||||
for (const row of rows) {
|
||||
if (!row.cartaoId) {
|
||||
if (!row.cardId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
items.push({
|
||||
id: row.cartaoId,
|
||||
id: row.cardId,
|
||||
name: row.cardName ?? "Cartão",
|
||||
logo: row.cardLogo ?? null,
|
||||
amount: Math.abs(toNumber(row.totalAmount)),
|
||||
@@ -241,26 +241,26 @@ export async function fetchPagadorCardUsage({
|
||||
|
||||
export async function fetchPagadorBoletoStats({
|
||||
userId,
|
||||
pagadorId,
|
||||
payerId,
|
||||
period,
|
||||
}: BaseFilters): Promise<PagadorBoletoStats> {
|
||||
}: BaseFilters): Promise<PayerBoletoStats> {
|
||||
const rows = await db
|
||||
.select({
|
||||
isSettled: lancamentos.isSettled,
|
||||
totalAmount: sum(lancamentos.amount).as("total"),
|
||||
totalCount: sql<number>`count(${lancamentos.id})`.as("count"),
|
||||
isSettled: transactions.isSettled,
|
||||
totalAmount: sum(transactions.amount).as("total"),
|
||||
totalCount: sql<number>`count(${transactions.id})`.as("count"),
|
||||
})
|
||||
.from(lancamentos)
|
||||
.from(transactions)
|
||||
.where(
|
||||
and(
|
||||
eq(lancamentos.userId, userId),
|
||||
eq(lancamentos.pagadorId, pagadorId),
|
||||
eq(lancamentos.period, period),
|
||||
eq(lancamentos.paymentMethod, PAYMENT_METHOD_BOLETO),
|
||||
eq(transactions.userId, userId),
|
||||
eq(transactions.payerId, payerId),
|
||||
eq(transactions.period, period),
|
||||
eq(transactions.paymentMethod, PAYMENT_METHOD_BOLETO),
|
||||
excludeAutoInvoiceEntries(),
|
||||
),
|
||||
)
|
||||
.groupBy(lancamentos.isSettled);
|
||||
.groupBy(transactions.isSettled);
|
||||
|
||||
let paidAmount = 0;
|
||||
let pendingAmount = 0;
|
||||
@@ -290,31 +290,31 @@ export async function fetchPagadorBoletoStats({
|
||||
|
||||
export async function fetchPagadorBoletoItems({
|
||||
userId,
|
||||
pagadorId,
|
||||
payerId,
|
||||
period,
|
||||
}: BaseFilters): Promise<PagadorBoletoItem[]> {
|
||||
}: BaseFilters): Promise<PayerBoletoItem[]> {
|
||||
const rows = await db
|
||||
.select({
|
||||
id: lancamentos.id,
|
||||
name: lancamentos.name,
|
||||
amount: lancamentos.amount,
|
||||
dueDate: lancamentos.dueDate,
|
||||
boletoPaymentDate: lancamentos.boletoPaymentDate,
|
||||
isSettled: lancamentos.isSettled,
|
||||
id: transactions.id,
|
||||
name: transactions.name,
|
||||
amount: transactions.amount,
|
||||
dueDate: transactions.dueDate,
|
||||
boletoPaymentDate: transactions.boletoPaymentDate,
|
||||
isSettled: transactions.isSettled,
|
||||
})
|
||||
.from(lancamentos)
|
||||
.from(transactions)
|
||||
.where(
|
||||
and(
|
||||
eq(lancamentos.userId, userId),
|
||||
eq(lancamentos.pagadorId, pagadorId),
|
||||
eq(lancamentos.period, period),
|
||||
eq(lancamentos.paymentMethod, PAYMENT_METHOD_BOLETO),
|
||||
eq(transactions.userId, userId),
|
||||
eq(transactions.payerId, payerId),
|
||||
eq(transactions.period, period),
|
||||
eq(transactions.paymentMethod, PAYMENT_METHOD_BOLETO),
|
||||
excludeAutoInvoiceEntries(),
|
||||
),
|
||||
)
|
||||
.orderBy(asc(lancamentos.dueDate));
|
||||
.orderBy(asc(transactions.dueDate));
|
||||
|
||||
const items: PagadorBoletoItem[] = [];
|
||||
const items: PayerBoletoItem[] = [];
|
||||
|
||||
for (const row of rows) {
|
||||
items.push({
|
||||
@@ -332,23 +332,23 @@ export async function fetchPagadorBoletoItems({
|
||||
|
||||
export async function fetchPagadorPaymentStatus({
|
||||
userId,
|
||||
pagadorId,
|
||||
payerId,
|
||||
period,
|
||||
}: BaseFilters): Promise<PagadorPaymentStatusData> {
|
||||
}: BaseFilters): Promise<PayerPaymentStatusData> {
|
||||
const rows = await db
|
||||
.select({
|
||||
paidAmount: sql<string>`coalesce(sum(case when ${lancamentos.isSettled} = true then abs(${lancamentos.amount}) else 0 end), 0)`,
|
||||
paidCount: sql<number>`sum(case when ${lancamentos.isSettled} = true then 1 else 0 end)`,
|
||||
pendingAmount: sql<string>`coalesce(sum(case when (${lancamentos.isSettled} = false or ${lancamentos.isSettled} is null) then abs(${lancamentos.amount}) else 0 end), 0)`,
|
||||
pendingCount: sql<number>`sum(case when (${lancamentos.isSettled} = false or ${lancamentos.isSettled} is null) then 1 else 0 end)`,
|
||||
paidAmount: sql<string>`coalesce(sum(case when ${transactions.isSettled} = true then abs(${transactions.amount}) else 0 end), 0)`,
|
||||
paidCount: sql<number>`sum(case when ${transactions.isSettled} = true then 1 else 0 end)`,
|
||||
pendingAmount: sql<string>`coalesce(sum(case when (${transactions.isSettled} = false or ${transactions.isSettled} is null) then abs(${transactions.amount}) else 0 end), 0)`,
|
||||
pendingCount: sql<number>`sum(case when (${transactions.isSettled} = false or ${transactions.isSettled} is null) then 1 else 0 end)`,
|
||||
})
|
||||
.from(lancamentos)
|
||||
.from(transactions)
|
||||
.where(
|
||||
and(
|
||||
eq(lancamentos.userId, userId),
|
||||
eq(lancamentos.pagadorId, pagadorId),
|
||||
eq(lancamentos.period, period),
|
||||
eq(lancamentos.transactionType, DESPESA),
|
||||
eq(transactions.userId, userId),
|
||||
eq(transactions.payerId, payerId),
|
||||
eq(transactions.period, period),
|
||||
eq(transactions.transactionType, DESPESA),
|
||||
excludeAutoInvoiceEntries(),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { cache } from "react";
|
||||
import { pagadores } from "@/db/schema";
|
||||
import { payers } from "@/db/schema";
|
||||
import { db } from "@/shared/lib/db";
|
||||
import { PAGADOR_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
import { PAYER_ROLE_ADMIN } from "@/shared/lib/payers/constants";
|
||||
|
||||
/**
|
||||
* Returns the admin pagador ID for a user (cached per request via React.cache).
|
||||
* Eliminates the need for JOIN with pagadores in ~20 dashboard queries.
|
||||
* Eliminates the need for JOIN with payers in ~20 dashboard queries.
|
||||
*/
|
||||
export const getAdminPagadorId = cache(
|
||||
export const getAdminPayerId = cache(
|
||||
async (userId: string): Promise<string | null> => {
|
||||
const [row] = await db
|
||||
.select({ id: pagadores.id })
|
||||
.from(pagadores)
|
||||
.where(
|
||||
and(
|
||||
eq(pagadores.userId, userId),
|
||||
eq(pagadores.role, PAGADOR_ROLE_ADMIN),
|
||||
),
|
||||
)
|
||||
.select({ id: payers.id })
|
||||
.from(payers)
|
||||
.where(and(eq(payers.userId, userId), eq(payers.role, PAYER_ROLE_ADMIN)))
|
||||
.limit(1);
|
||||
return row?.id ?? null;
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { inArray } from "drizzle-orm";
|
||||
import { Resend } from "resend";
|
||||
import { pagadores } from "@/db/schema";
|
||||
import { payers } from "@/db/schema";
|
||||
import { db } from "@/shared/lib/db";
|
||||
import { getResendFromEmail } from "@/shared/lib/email/resend";
|
||||
import { formatCurrency } from "@/shared/utils/currency";
|
||||
@@ -9,7 +9,7 @@ import { formatDateTime } from "@/shared/utils/date";
|
||||
type ActionType = "created" | "deleted";
|
||||
|
||||
export type NotificationEntry = {
|
||||
pagadorId: string;
|
||||
payerId: string;
|
||||
name: string | null;
|
||||
amount: number;
|
||||
transactionType: string | null;
|
||||
@@ -20,13 +20,13 @@ export type NotificationEntry = {
|
||||
note: string | null;
|
||||
};
|
||||
|
||||
export type PagadorNotificationRequest = {
|
||||
export type PayerNotificationRequest = {
|
||||
userLabel: string;
|
||||
action: ActionType;
|
||||
entriesByPagador: Map<string, NotificationEntry[]>;
|
||||
};
|
||||
|
||||
type PagadorNotificationRecipient = {
|
||||
type PayerNotificationRecipient = {
|
||||
id: string;
|
||||
name: string | null;
|
||||
email: string | null;
|
||||
@@ -110,11 +110,11 @@ const buildHtmlBody = ({
|
||||
`;
|
||||
};
|
||||
|
||||
export async function sendPagadorAutoEmails({
|
||||
export async function sendPayerAutoEmails({
|
||||
userLabel,
|
||||
action,
|
||||
entriesByPagador,
|
||||
}: PagadorNotificationRequest) {
|
||||
}: PayerNotificationRequest) {
|
||||
"use server";
|
||||
|
||||
if (entriesByPagador.size === 0) {
|
||||
@@ -136,11 +136,11 @@ export async function sendPagadorAutoEmails({
|
||||
return;
|
||||
}
|
||||
|
||||
const pagadorRows = (await db.query.pagadores.findMany({
|
||||
where: inArray(pagadores.id, pagadorIds),
|
||||
})) as PagadorNotificationRecipient[];
|
||||
const payerRows = (await db.query.payers.findMany({
|
||||
where: inArray(payers.id, pagadorIds),
|
||||
})) as PayerNotificationRecipient[];
|
||||
|
||||
if (pagadorRows.length === 0) {
|
||||
if (payerRows.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -149,12 +149,12 @@ export async function sendPagadorAutoEmails({
|
||||
action === "created" ? "Novo lançamento" : "Lançamento removido";
|
||||
|
||||
const results = await Promise.allSettled(
|
||||
pagadorRows.map(async (pagador: PagadorNotificationRecipient) => {
|
||||
if (!pagador.email || !pagador.isAutoSend) {
|
||||
payerRows.map(async (payer: PayerNotificationRecipient) => {
|
||||
if (!payer.email || !payer.isAutoSend) {
|
||||
return;
|
||||
}
|
||||
|
||||
const entries = entriesByPagador.get(pagador.id);
|
||||
const entries = entriesByPagador.get(payer.id);
|
||||
if (!entries || entries.length === 0) {
|
||||
return;
|
||||
}
|
||||
@@ -167,8 +167,8 @@ export async function sendPagadorAutoEmails({
|
||||
|
||||
await resend.emails.send({
|
||||
from: resendFrom,
|
||||
to: pagador.email,
|
||||
subject: `${subjectPrefix} - ${pagador.name}`,
|
||||
to: payer.email,
|
||||
subject: `${subjectPrefix} - ${payer.name}`,
|
||||
html,
|
||||
});
|
||||
}),
|
||||
@@ -177,7 +177,7 @@ export async function sendPagadorAutoEmails({
|
||||
// Log any failed email sends
|
||||
results.forEach((result: PromiseSettledResult<void>, index: number) => {
|
||||
if (result.status === "rejected") {
|
||||
const pagador = pagadorRows[index];
|
||||
const pagador = payerRows[index];
|
||||
console.error(
|
||||
`Failed to send email notification to ${pagador?.name} (${pagador?.email}):`,
|
||||
result.reason,
|
||||
@@ -187,7 +187,7 @@ export async function sendPagadorAutoEmails({
|
||||
}
|
||||
|
||||
export type RawNotificationRecord = {
|
||||
pagadorId: string | null;
|
||||
payerId: string | null;
|
||||
name: string | null;
|
||||
amount: string | number | null;
|
||||
transactionType: string | null;
|
||||
@@ -198,13 +198,13 @@ export type RawNotificationRecord = {
|
||||
note: string | null;
|
||||
};
|
||||
|
||||
export const buildEntriesByPagador = (
|
||||
export const buildEntriesByPayer = (
|
||||
records: RawNotificationRecord[],
|
||||
): Map<string, NotificationEntry[]> => {
|
||||
const map = new Map<string, NotificationEntry[]>();
|
||||
|
||||
records.forEach((record) => {
|
||||
if (!record.pagadorId) {
|
||||
if (!record.payerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ export const buildEntriesByPagador = (
|
||||
: null;
|
||||
|
||||
const entry: NotificationEntry = {
|
||||
pagadorId: record.pagadorId,
|
||||
payerId: record.payerId,
|
||||
name: record.name ?? null,
|
||||
amount,
|
||||
transactionType: record.transactionType ?? null,
|
||||
@@ -231,9 +231,9 @@ export const buildEntriesByPagador = (
|
||||
note: record.note ?? null,
|
||||
};
|
||||
|
||||
const list = map.get(record.pagadorId) ?? [];
|
||||
const list = map.get(record.payerId) ?? [];
|
||||
list.push(entry);
|
||||
map.set(record.pagadorId, list);
|
||||
map.set(record.payerId, list);
|
||||
});
|
||||
|
||||
return map;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DEFAULT_PAGADOR_AVATAR } from "./constants";
|
||||
import { DEFAULT_PAYER_AVATAR } from "./constants";
|
||||
|
||||
/**
|
||||
* Normaliza o caminho do avatar extraindo apenas o nome do arquivo.
|
||||
@@ -29,7 +29,7 @@ export const normalizeAvatarPath = (
|
||||
*/
|
||||
export const getAvatarSrc = (avatar: string | null | undefined): string => {
|
||||
if (!avatar) {
|
||||
return `/avatars/${DEFAULT_PAGADOR_AVATAR}`;
|
||||
return `/avatars/${DEFAULT_PAYER_AVATAR}`;
|
||||
}
|
||||
|
||||
// Se for uma URL completa (Google, etc), retorna diretamente
|
||||
@@ -43,7 +43,7 @@ export const getAvatarSrc = (avatar: string | null | undefined): string => {
|
||||
|
||||
// Se for um caminho local, normaliza e adiciona o prefixo
|
||||
const normalized = normalizeAvatarPath(avatar);
|
||||
return `/avatars/${normalized ?? DEFAULT_PAGADOR_AVATAR}`;
|
||||
return `/avatars/${normalized ?? DEFAULT_PAYER_AVATAR}`;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user