WIP fix types in client
This commit is contained in:
parent
72eeb03425
commit
3ff6aa7310
@ -3,7 +3,7 @@ import rek from 'rek'
|
||||
import Head from './head.ts'
|
||||
import usePromise from '../../shared/hooks/use_promise.ts'
|
||||
|
||||
import type { Account } from '../../../shared/types.ts'
|
||||
import type { Account } from '../../../shared/types.db.ts'
|
||||
|
||||
const AccountsPage: FunctionComponent = () => {
|
||||
const accounts = usePromise<Account[]>(() => rek('/api/accounts'))
|
||||
|
||||
@ -6,7 +6,8 @@ import { formatNumber } from '../utils/format_number.ts'
|
||||
import s from './balances_page.module.scss'
|
||||
import usePromise from '../../shared/hooks/use_promise.ts'
|
||||
|
||||
import type { Balance, FinancialYear } from '../../../shared/types.ts'
|
||||
import type { FinancialYear } from '../../../shared/types.db.ts'
|
||||
import type { Balance } from '../../../shared/types.db_composite.ts'
|
||||
|
||||
const BalancesPage: FunctionComponent = () => {
|
||||
const [balances, years] = usePromise<[Balance[], number[]]>(() =>
|
||||
|
||||
@ -8,14 +8,14 @@ import rek from 'rek'
|
||||
import Head from './head.ts'
|
||||
import serializeForm from '../../shared/utils/serialize_form.ts'
|
||||
|
||||
import type { Entry, FinancialYear, Journal } from '../../../shared/types.ts'
|
||||
import type { Entry, FinancialYear, Journal } from '../../../shared/types.db.ts'
|
||||
|
||||
const dateYear = new Date().getFullYear()
|
||||
|
||||
const EntriesPage: FunctionComponent = () => {
|
||||
const [journals, setJournals] = useState<Journal[]>([])
|
||||
const [financialYears, setFinancialYears] = useState<FinancialYear[]>([])
|
||||
const [entries, setEntries] = useState<Entry[]>([])
|
||||
const [entries, setEntries] = useState<(Entry & { amount: string; journal: string })[]>([])
|
||||
|
||||
const location = useLocation()
|
||||
|
||||
@ -87,8 +87,8 @@ const EntriesPage: FunctionComponent = () => {
|
||||
{entry.journal}
|
||||
{entry.number}
|
||||
</td>
|
||||
<td>{entry.entryDate?.slice(0, 10)}</td>
|
||||
<td>{entry.transactionDate?.slice(0, 10)}</td>
|
||||
<td>{(entry.entryDate as unknown as string)?.slice(0, 10)}</td>
|
||||
<td>{(entry.transactionDate as unknown as string)?.slice(0, 10)}</td>
|
||||
<td className='tar'>{entry.amount}</td>
|
||||
<td>{entry.description}</td>
|
||||
</tr>
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
import { h, type FunctionComponent } from 'preact'
|
||||
import { useRoute } from 'preact-iso'
|
||||
import rek from 'rek'
|
||||
import { type Entry } from '../../../shared/types.ts'
|
||||
import type { Entry, Transaction } from '../../../shared/types.db.ts'
|
||||
import usePromise from '../../shared/hooks/use_promise.ts'
|
||||
import { formatNumber } from '../utils/format_number.ts'
|
||||
import Head from './head.ts'
|
||||
|
||||
const EntryPage: FunctionComponent = () => {
|
||||
const route = useRoute()
|
||||
const entry = usePromise<Entry>(() => rek(`/api/entries/${route.params.id}`))
|
||||
const entry = usePromise<Entry & { amount: number; journal: string; transactions?: Transaction[] }>(() =>
|
||||
rek(`/api/entries/${route.params.id}`),
|
||||
)
|
||||
|
||||
return (
|
||||
<section>
|
||||
@ -41,8 +43,8 @@ const EntryPage: FunctionComponent = () => {
|
||||
</td>
|
||||
<td>{entry.journal}</td>
|
||||
<td>{entry.number}</td>
|
||||
<td>{entry.entryDate?.slice(0, 10)}</td>
|
||||
<td>{entry.transactionDate?.slice(0, 10)}</td>
|
||||
<td>{(entry.entryDate as unknown as string)?.slice(0, 10)}</td>
|
||||
<td>{(entry.transactionDate as unknown as string)?.slice(0, 10)}</td>
|
||||
<td className='tar'>{entry.amount}</td>
|
||||
<td>{entry.description}</td>
|
||||
</tr>
|
||||
@ -63,8 +65,16 @@ const EntryPage: FunctionComponent = () => {
|
||||
{entry?.transactions?.map((transaction) => (
|
||||
<tr>
|
||||
<td>{transaction.accountNumber}</td>
|
||||
<td className='tar'>{transaction.amount >= 0 ? formatNumber(transaction.amount) : null}</td>
|
||||
<td className='tar'>{transaction.amount < 0 ? formatNumber(Math.abs(transaction.amount)) : null}</td>
|
||||
<td className='tar'>
|
||||
{(transaction.amount as unknown as number) >= 0
|
||||
? formatNumber(transaction.amount as unknown as number)
|
||||
: null}
|
||||
</td>
|
||||
<td className='tar'>
|
||||
{(transaction.amount as unknown as number) < 0
|
||||
? formatNumber(Math.abs(transaction.amount as unknown as number))
|
||||
: null}
|
||||
</td>
|
||||
<td>{transaction.description}</td>
|
||||
</tr>
|
||||
))}
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import { h, type FunctionalComponent } from 'preact'
|
||||
import { h, type FunctionComponent } from 'preact'
|
||||
import { useEffect, useState } from 'preact/hooks'
|
||||
import rek from 'rek'
|
||||
|
||||
import type { Transaction } from '../../../shared/types.ts'
|
||||
import type { Transaction } from '../../../shared/types.db.ts'
|
||||
|
||||
interface Props {
|
||||
interface InvoiceProps {
|
||||
year: number
|
||||
}
|
||||
|
||||
const Invoices: FunctionalComponent<Props> = ({ year }) => {
|
||||
const Invoice: FunctionComponent<InvoiceProps> = ({ year }) => {
|
||||
const [invoices, setInvoices] = useState<Transaction[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
@ -30,4 +30,4 @@ const Invoices: FunctionalComponent<Props> = ({ year }) => {
|
||||
)
|
||||
}
|
||||
|
||||
export default Invoices
|
||||
export default Invoice
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
import { h, type FunctionComponent } from 'preact'
|
||||
import { useRoute } from 'preact-iso'
|
||||
import rek from 'rek'
|
||||
import type { Invoice } from '../../../shared/types.ts'
|
||||
import type { File, Invoice, Transaction } from '../../../shared/types.db.ts'
|
||||
import usePromise from '../../shared/hooks/use_promise.ts'
|
||||
import { formatNumber } from '../utils/format_number.ts'
|
||||
import Head from './head.ts'
|
||||
|
||||
const InvoicePage: FunctionComponent = () => {
|
||||
const invoice = usePromise<Invoice>(() => rek(`/api/invoices/${route.params.id}`))
|
||||
const invoice = usePromise<Invoice & { files?: File[]; transactions?: Transaction[] }>(() =>
|
||||
rek(`/api/invoices/${route.params.id}`),
|
||||
)
|
||||
const route = useRoute()
|
||||
|
||||
return (
|
||||
@ -89,8 +91,16 @@ const InvoicePage: FunctionComponent = () => {
|
||||
<a href={`/entries/${transaction.entryId}`}>{transaction.entryId}</a>
|
||||
</td>
|
||||
<td>{transaction.accountNumber}</td>
|
||||
<td>{transaction.amount >= 0 ? formatNumber(transaction.amount) : null}</td>
|
||||
<td>{transaction.amount < 0 ? formatNumber(Math.abs(transaction.amount)) : null}</td>
|
||||
<td>
|
||||
{(transaction.amount as unknown as number) >= 0
|
||||
? formatNumber(transaction.amount as unknown as number)
|
||||
: null}
|
||||
</td>
|
||||
<td>
|
||||
{(transaction.amount as unknown as number) < 0
|
||||
? formatNumber(Math.abs(transaction.amount as unknown as number))
|
||||
: null}
|
||||
</td>
|
||||
<td>{transaction.description}</td>
|
||||
</tr>
|
||||
))}
|
||||
|
||||
@ -5,7 +5,7 @@ import { useRoute } from 'preact-iso'
|
||||
import rek from 'rek'
|
||||
import Head from './head.ts'
|
||||
import usePromise from '../../shared/hooks/use_promise.ts'
|
||||
import type { Invoice, Supplier } from '../../../shared/types.ts'
|
||||
import type { File, Invoice, Supplier } from '../../../shared/types.db.ts'
|
||||
import { formatPrice } from '../utils/format_number.ts'
|
||||
|
||||
const format = Format.bind(null, null, 'YYYY.MM.DD')
|
||||
@ -13,7 +13,7 @@ const format = Format.bind(null, null, 'YYYY.MM.DD')
|
||||
const InvoicesPage: FunctionComponent = () => {
|
||||
const route = useRoute()
|
||||
|
||||
const [supplier, invoices, totalAmount] = usePromise<[Supplier, Invoice[], number]>(() =>
|
||||
const [supplier, invoices, totalAmount] = usePromise<[Supplier, (Invoice & { files?: File[] })[], number]>(() =>
|
||||
Promise.all([
|
||||
rek(`/api/suppliers/${route.params.supplier}`),
|
||||
rek(`/api/invoices?supplier=${route.params.supplier}`),
|
||||
|
||||
@ -3,7 +3,7 @@ import rek from 'rek'
|
||||
import Head from './head.ts'
|
||||
import usePromise from '../../shared/hooks/use_promise.ts'
|
||||
|
||||
import type { Supplier } from '../../../shared/types.ts'
|
||||
import type { Supplier } from '../../../shared/types.db.ts'
|
||||
|
||||
const InvoicesPage: FunctionComponent = () => {
|
||||
const suppliers = usePromise<Supplier[]>(() => rek('/api/suppliers'))
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
import { h, type FunctionalComponent } from 'preact'
|
||||
import { h, type FunctionComponent } from 'preact'
|
||||
import type { Selectable } from 'kysely'
|
||||
import { useEffect, useState } from 'preact/hooks'
|
||||
import rek from 'rek'
|
||||
|
||||
import type { TransactionFull } from '../../../shared/types.ts'
|
||||
import type { Transaction } from '../../../shared/types.db.ts'
|
||||
|
||||
interface Props {
|
||||
interface ObjectComponentProps {
|
||||
objectId: number
|
||||
}
|
||||
|
||||
const Result: FunctionalComponent<Props> = ({ objectId }) => {
|
||||
const [transactions, setTransactions] = useState<TransactionFull[]>([])
|
||||
const ObjectComponent: FunctionComponent<ObjectComponentProps> = ({ objectId }) => {
|
||||
const [transactions, setTransactions] = useState<Selectable<Transaction>[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
rek(`/api/objects/${objectId}`).then(setTransactions)
|
||||
@ -31,7 +32,7 @@ const Result: FunctionalComponent<Props> = ({ objectId }) => {
|
||||
<td>
|
||||
<a href={`/entries/${transaction.entryId}`}>{transaction.entryId}</a>
|
||||
</td>
|
||||
<td>{transaction.transactionDate.slice(0, 10)}</td>
|
||||
<td>{(transaction.transactionDate as unknown as string)?.slice(0, 10)}</td>
|
||||
<td>{transaction.accountNumber}</td>
|
||||
<td className='tar'>{transaction.amount}</td>
|
||||
</tr>
|
||||
@ -41,4 +42,4 @@ const Result: FunctionalComponent<Props> = ({ objectId }) => {
|
||||
)
|
||||
}
|
||||
|
||||
export default Result
|
||||
export default ObjectComponent
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
import { h, type FunctionComponent } from 'preact'
|
||||
import { useState } from 'preact/hooks'
|
||||
import rek from 'rek'
|
||||
import type { Object as ObjectType } from '../../../shared/types.ts'
|
||||
import type { Selectable } from 'kysely'
|
||||
import type { Object as ObjectType } from '../../../shared/types.db.ts'
|
||||
import usePromise from '../../shared/hooks/use_promise.ts'
|
||||
import Head from './head.ts'
|
||||
import Object from './object.tsx'
|
||||
import s from './results_page.module.scss'
|
||||
|
||||
const ObjectsPage: FunctionComponent = () => {
|
||||
const objects = usePromise<ObjectType[]>(() => rek('/api/objects'))
|
||||
const [currentObject, setCurrentObject] = useState<ObjectType | null>(null)
|
||||
const objects = usePromise<(Selectable<ObjectType> & { dimensionName: string })[]>(() => rek('/api/objects'))
|
||||
const [currentObject, setCurrentObject] = useState<Selectable<ObjectType> | null>(null)
|
||||
|
||||
return (
|
||||
<section>
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { h, type FunctionComponent } from 'preact'
|
||||
import cn from 'classnames'
|
||||
import rek from 'rek'
|
||||
import type { FinancialYear, Result } from '../../../shared/types.ts'
|
||||
import type { FinancialYear } from '../../../shared/types.db.ts'
|
||||
import type { Result } from '../../../shared/types.db_composite.ts'
|
||||
import { formatNumber } from '../utils/format_number.ts'
|
||||
import usePromise from '../../shared/hooks/use_promise.ts'
|
||||
import Head from './head.ts'
|
||||
|
||||
@ -8,11 +8,11 @@ import Head from './head.ts'
|
||||
import serializeForm from '../../shared/utils/serialize_form.ts'
|
||||
import { formatNumber } from '../utils/format_number.ts'
|
||||
|
||||
import type { TransactionFull, FinancialYear } from '../../../shared/types.ts'
|
||||
import type { Transaction, FinancialYear } from '../../../shared/types.db.ts'
|
||||
|
||||
const TransactionsPage: FunctionComponent = () => {
|
||||
const [financialYears, setFinancialYears] = useState<FinancialYear[]>([])
|
||||
const [transactions, setTransactions] = useState<TransactionFull[]>([])
|
||||
const [transactions, setTransactions] = useState<(Transaction & { entryDescription: string })[]>([])
|
||||
|
||||
const location = useLocation()
|
||||
|
||||
@ -27,17 +27,13 @@ const TransactionsPage: FunctionComponent = () => {
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
rek('/api/financial-years').then((financialYears: FinancialYear[]) => {
|
||||
setFinancialYears(financialYears)
|
||||
})
|
||||
rek('/api/financial-years').then(setFinancialYears)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const search = location.url.split('?')[1] || ''
|
||||
|
||||
rek(`/api/transactions${search ? '?' + search : ''}`).then((transactions: TransactionFull[]) => {
|
||||
setTransactions(transactions)
|
||||
})
|
||||
rek(`/api/transactions${search ? '?' + search : ''}`).then(setTransactions)
|
||||
}, [location.url])
|
||||
|
||||
return (
|
||||
@ -72,10 +68,18 @@ const TransactionsPage: FunctionComponent = () => {
|
||||
<tbody>
|
||||
{transactions.map((transaction) => (
|
||||
<tr>
|
||||
<td>{transaction.transactionDate.slice(0, 10)}</td>
|
||||
<td>{(transaction.transactionDate as unknown as string)?.slice(0, 10)}</td>
|
||||
<td>{transaction.accountNumber}</td>
|
||||
<td className='tar'>{transaction.amount >= 0 ? formatNumber(transaction.amount) : null}</td>
|
||||
<td className='tar'>{transaction.amount < 0 ? formatNumber(Math.abs(transaction.amount)) : null}</td>
|
||||
<td className='tar'>
|
||||
{(transaction.amount as unknown as number) >= 0
|
||||
? formatNumber(transaction.amount as unknown as number)
|
||||
: null}
|
||||
</td>
|
||||
<td className='tar'>
|
||||
{(transaction.amount as unknown as number) < 0
|
||||
? formatNumber(Math.abs(transaction.amount as unknown as number))
|
||||
: null}
|
||||
</td>
|
||||
<td>{transaction.description}</td>
|
||||
<td>
|
||||
<a href={`/entries/${transaction.entryId}`}>{transaction.entryId}</a>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user