Skip to content

Commit

Permalink
coloring balance
Browse files Browse the repository at this point in the history
  • Loading branch information
paolini committed Dec 3, 2024
1 parent 279dc15 commit 85f7ce6
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
11 changes: 7 additions & 4 deletions app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Provider from '../components/Provider'
import Balance from '../components/Balance'
import Loading from '../components/Loading'
import Error from '../components/Error'
import Amount from '../components/Amount'
import { myDate, myTime } from '../utils'

export default function Admin({}) {
Expand Down Expand Up @@ -114,11 +115,13 @@ function TransactionRow({transaction, edit}:{
? originalEmail
: <input type="email" placeholder="email" value={newEmail} onChange={e => setEmail(e.target.value)} />}
</td>
<td>{transaction && !editing ? originalCount
:<input type="number" placeholder="count" value={newCount || ''} size={4} onChange={e => setCount(parseInt(e.target.value) || 0)} />}
<td align="right">{transaction && !editing
? (originalCount || '')
: <input type="number" placeholder="count" value={newCount || ''} size={4} onChange={e => setCount(parseInt(e.target.value) || 0)} />}
</td>
<td>{transaction && !editing ?(`${(originalAmount/100).toFixed(2)}€`)
:<input type="number" placeholder="cents" value={newAmount || ''} onChange={e => setAmount(parseInt(e.target.value))} />}
<td align="right">{transaction && !editing
? <Amount cents={originalAmount}/>
: <input type="number" placeholder="cents" value={newAmount || ''} onChange={e => setAmount(parseInt(e.target.value))} />}
</td>
<td>{transaction && !editing ?originalDescription
:<input type="text" placeholder="description" value={newDescription} onChange={e => setDescription(e.target.value)} />}
Expand Down
5 changes: 3 additions & 2 deletions app/admin/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useState } from 'react'
import Provider from '../../components/Provider'
import Loading from '../../components/Loading'
import Error from '../../components/Error'
import Amount from '../../components/Amount'
import {myDate, myTime} from '../../utils'

export default function UsersPage({}) {
Expand Down Expand Up @@ -41,8 +42,8 @@ function Users() {
{data.users.map((user: any, i: number) =>
<tr key={i}>
<td>{user.email}</td>
<td align="right">{user.count}</td>
<td align="right">{(user.creditCents/100).toFixed(2)}</td>
<td align="right">{user.count||""}</td>
<td align="right"><Amount cents={user.creditCents}/></td>
<td align="right">{myDate(user.timestamp)}</td>
</tr>
)}
Expand Down
6 changes: 6 additions & 0 deletions app/components/Amount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function Amount({cents,prefix}:{
cents:number,
prefix?:string
}) {
return <b className={cents<0?"text-red-500":"text-blue-500"}>{prefix} {(cents/100).toFixed(2)}</b>
}
3 changes: 2 additions & 1 deletion app/components/Balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useQuery, gql } from '@apollo/client'

import Loading from './Loading'
import Error from './Error'
import Amount from './Amount'

const GET_BALANCE = gql`
query GetBalance {
Expand All @@ -18,7 +19,7 @@ export default function Balance() {
if (loading) return <Loading />
if (error) return <Error error={error}/>
return <div>
<p>Bilancio complessivo: {(data.balance.cents / 100).toFixed(2)} per {data.balance.count} caffé</p>
<p>Bilancio complessivo: <Amount prefix="€" cents={data.balance.cents}/> per <b>{data.balance.count}</b> caffé</p>
</div>
}

3 changes: 2 additions & 1 deletion app/components/Credit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useQuery, gql } from '@apollo/client'

import Loading from './Loading'
import Error from './Error'
import Amount from './Amount'

const GET_CREDIT = gql`
query GetCredit {
Expand All @@ -16,7 +17,7 @@ export default function Credit() {
if (loading) return <Loading />
if (error) return <Error error={error}/>
return <div>
<p>Il tuo credito: {(data.credit.cents / 100).toFixed(2)}, caffé: {data.credit.count}</p>
<p>Il tuo credito: <Amount prefix="€" cents={data.credit.cents}/>, caffé: {data.credit.count}</p>
</div>
}

Expand Down
3 changes: 2 additions & 1 deletion app/components/Transactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { gql, useQuery } from '@apollo/client'

import Loading from './Loading'
import Error from './Error'
import Amount from './Amount'
import { myDate, myTime } from '../utils'

const GET_MY_TRANSACTIONS = gql`
Expand Down Expand Up @@ -36,7 +37,7 @@ export default function Transactions() {
<td className="text-sm">{myDate(transaction.timestamp)}</td>
<td className="text-sm">{myTime(transaction.timestamp)}</td>
<td align="right">{transaction.count || ""}</td>
<td align="right"><b>{(transaction.amountCents/100).toFixed(2)}</b></td>
<td align="right"><Amount cents={transaction.amountCents}/></td>
<td><i>{transaction.description}</i></td>
<td className="text-sm">{transaction.code||''}</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dm-coffee",
"version": "1.1.0",
"version": "1.1.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down

0 comments on commit 85f7ce6

Please sign in to comment.