Skip to content

Commit

Permalink
fix: update transactions data table to use currentLedger.id from new …
Browse files Browse the repository at this point in the history
…format
  • Loading branch information
gabrielcastr0 committed Feb 25, 2025
1 parent c24907f commit 349cd24
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 40 deletions.
3 changes: 1 addition & 2 deletions locales/extracted/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"common.table.accounts": "{number, plural, =0 {No accounts} one {# account} other {# accounts}}",
"common.table.metadata": "{number, plural, =0 {-} one {# record} other {# records}}",
"common.tooltipCopyText": "Click to copy",
"common.transactions": "Transactions",
"common.type": "Type",
"common.typePlaceholder": "Type...",
"common.user": "User",
Expand Down Expand Up @@ -363,7 +364,6 @@
"sideBar.ledger.overview": "Overview",
"sideBar.ledger.segments": "Segments",
"sideBar.ledger.title": "Ledger",
"sideBar.ledger.transactions": "Transactions",
"sideBar.ledgers": "Ledgers",
"signIn.buttonSignIn": "Continue",
"signIn.descriptionLogin": "Enter your email and password to continue.",
Expand Down Expand Up @@ -423,7 +423,6 @@
"transactions.tab.data": "Transaction Data",
"transactions.tab.operations": "Operations & Metadata",
"transactions.tab.summary": "Summary",
"transactions.title": "Transactions",
"transactions.toast.update.error": "An error occurred while updating the transaction",
"transactions.toast.update.success": "Transaction updated successfully"
}
9 changes: 7 additions & 2 deletions locales/extracted/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@
"transactions.ledgers.subtitle": "Selecione um ledger para carregar as transações.",
"transactions.section.description": "Este é o espaço das {transactions}. As movimentações que acontecem em todas as suas ledgers ficam organizadas aqui.",
"transactions.subtitle": "Visualize, edite e gerencie as transações de um Ledgers específico.",
"transactions.title": "Transações",
"language.english": "Inglês",
"language.portuguese": "Português",
"settings.system.language": "Idioma",
Expand Down Expand Up @@ -425,5 +424,11 @@
"sideBar.ledger.overview": "Visão Geral",
"sideBar.ledger.segments": "Segmentos",
"sideBar.ledger.title": "Ledger",
"sideBar.ledger.transactions": "Transações"
"assets.helperTrigger.answer": "Livro com o registro de todas as transações e operações da Organização.",
"assets.helperTrigger.question": "O que é um ativo?",
"assets.listingTemplate.addButton": "Novo Ativo",
"assets.subtitle": "Visualize, edite e gerencie os ativos do livro razão atual.",
"common.assets": "Ativos",
"common.read.docs": "Leia a documentação.",
"common.transactions": "Transações"
}
52 changes: 34 additions & 18 deletions src/app/(routes)/transactions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,61 @@ import { TransactionsSkeleton } from './transactions-skeleton'
import { useQueryParams } from '@/hooks/use-query-params'
import { PageHeader } from '@/components/page-header'
import { useIntl } from 'react-intl'
import { getBreadcrumbPaths } from '@/components/breadcrumb/get-breadcrumb-paths'
import { Breadcrumb } from '@/components/breadcrumb'

export default function TransactionsPage() {
const intl = useIntl()
const { currentOrganization, currentLedgerId } = useOrganization()
const { currentOrganization, currentLedger } = useOrganization()
const [total, setTotal] = React.useState(0)

const { form, searchValues, pagination } = useQueryParams({ total })

const { data: transactions, isLoading: isLoadingTransactions } =
useListTransactions({
organizationId: currentOrganization?.id!,
ledgerId: currentLedgerId,
ledgerId: currentLedger.id,
...(searchValues as any)
})

React.useEffect(() => {
setTotal(transactions?.items?.length || 0)
}, [transactions?.items])

const hasLedgerLoaded = Boolean(currentLedgerId)
const hasLedgerLoaded = Boolean(currentLedger.id)

const transactionsTableProps = {
transactions,
form,
total,
pagination,
currentLedger
}

const breadcrumbPaths = getBreadcrumbPaths([
{
name: currentOrganization.legalName
},
{
name: currentLedger.name
},
{
name: intl.formatMessage({
id: `common.transactions`,
defaultMessage: 'Transactions'
})
}
])

return (
<React.Fragment>
<Breadcrumb paths={breadcrumbPaths} />

<PageHeader.Root>
<PageHeader.Wrapper>
<PageHeader.InfoTitle
title={intl.formatMessage({
id: 'transactions.title',
id: 'common.transactions',
defaultMessage: 'Transactions'
})}
subtitle={intl.formatMessage({
Expand Down Expand Up @@ -75,20 +102,9 @@ export default function TransactionsPage() {
</PageHeader.Root>

<div className="mt-10">
{isLoadingTransactions ? (
<TransactionsSkeleton />
) : (
hasLedgerLoaded && (
<TransactionsDataTable
transactionsState={{
transactions,
form,
total,
pagination,
currentLedgerId
}}
/>
)
{isLoadingTransactions && <TransactionsSkeleton />}
{!isLoadingTransactions && hasLedgerLoaded && (
<TransactionsDataTable {...transactionsTableProps} />
)}
</div>
</React.Fragment>
Expand Down
34 changes: 17 additions & 17 deletions src/app/(routes)/transactions/transactions-data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,19 @@ import { FormProvider, UseFormReturn } from 'react-hook-form'
import { PaginationDto } from '@/core/application/dto/pagination-dto'
import { ITransactionType } from '@/types/transactions-type'
import { IdTableCell } from '@/components/id-table-cell'
import { ILedgerType } from '@/types/ledgers-type'

type TransactionsDataTableProps = {
transactionsState: {
transactions: PaginationDto<ITransactionType> | undefined
form: UseFormReturn<any>
total: number
pagination: PaginationProps
currentLedgerId: string | null
}
transactions: PaginationDto<ITransactionType> | undefined
form: UseFormReturn<any>
total: number
pagination: PaginationProps
currentLedger: ILedgerType
}

type TransactionsRowProps = {
transaction: Row<ITransactionType>
currentLedgerId: string | null
currentLedger: ILedgerType
}

const multipleItemsMessages = defineMessages({
Expand Down Expand Up @@ -92,7 +91,7 @@ const statusMessages = defineMessages({

const TransactionRow: React.FC<TransactionsRowProps> = ({
transaction,
currentLedgerId
currentLedger
}) => {
const intl = useIntl()
const {
Expand Down Expand Up @@ -181,7 +180,7 @@ const TransactionRow: React.FC<TransactionsRowProps> = ({
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<Link
href={`/ledgers/${currentLedgerId}/transactions/${transaction.original.id}`}
href={`/ledgers/${currentLedger.id}/transactions/${transaction.original.id}`}
>
<DropdownMenuItem>
{intl.formatMessage({
Expand All @@ -199,15 +198,16 @@ const TransactionRow: React.FC<TransactionsRowProps> = ({
}

export const TransactionsDataTable = ({
transactionsState
transactions,
form,
total,
pagination,
currentLedger
}: TransactionsDataTableProps) => {
const intl = useIntl()
const router = useRouter()
const [columnFilters, setColumnFilters] = React.useState<any>([])

const { transactions, form, total, pagination, currentLedgerId } =
transactionsState

const table = useReactTable({
data: transactions?.items || [],
columns: [
Expand All @@ -226,8 +226,8 @@ export const TransactionsDataTable = ({
})

const handleCreateTransaction = React.useCallback(() => {
router.push(`/ledgers/${currentLedgerId}/transactions/create`)
}, [currentLedgerId, router])
router.push(`/ledgers/${currentLedger.id}/transactions/create`)
}, [currentLedger, router])

return (
<FormProvider {...form}>
Expand Down Expand Up @@ -320,7 +320,7 @@ export const TransactionsDataTable = ({
<TransactionRow
key={transaction.id}
transaction={transaction}
currentLedgerId={currentLedgerId}
currentLedger={currentLedger}
/>
))}
</TableBody>
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const Sidebar = () => {

<SidebarItem
title={intl.formatMessage({
id: 'sideBar.ledger.transactions',
id: 'common.transactions',
defaultMessage: 'Transactions'
})}
icon={<ArrowLeftRight />}
Expand Down

0 comments on commit 349cd24

Please sign in to comment.