Skip to content

Commit

Permalink
✨ Meterings migrated to React
Browse files Browse the repository at this point in the history
  • Loading branch information
vokimon committed Mar 11, 2024
1 parent 4c4011a commit d6714bc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
4 changes: 3 additions & 1 deletion tomatic/ui/src/mithril/components/callinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ CallInfo.selectedPartner = subscriptable(function () {


CallInfo.contractDetails = subscriptable(function() {
const contract = CallInfo.selectedContract()
return {
atr_cases: CallInfo.selectedContract()?.atr_cases ?? null,
atr_cases: contract?.atr_cases ?? null,
lectures_comptadors: contract?.lectures_comptadors ?? null,
}
})

Expand Down
2 changes: 1 addition & 1 deletion tomatic/ui/src/pages/CallinfoPage/AtrCases.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function AtrCases() {
<tr key={i}>
<td>
{
// Not the time
// Date not time
atr_case.date.slice(0, 10)
}
</td>
Expand Down
3 changes: 2 additions & 1 deletion tomatic/ui/src/pages/CallinfoPage/DetailsInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CircularProgress from '@mui/material/CircularProgress'
import m from '../../services/hyperscript'
import TabbedCard from './TabbedCard'
import AtrCases from './AtrCases'
import Meterings from './Meterings'
import CallInfo from '../../mithril/components/callinfo'
import { useSubscriptable } from '../../services/subscriptable'

Expand All @@ -30,7 +31,7 @@ export default function DetailsInfo() {
<Box className="contract-info-box">
{activeView === 0 && <AtrCases />}
{/* activeView === 1 && <Invoices invoices={contract.invoices} /> */}
{/* activeView === 2 && <Meterings meterings={contract.lectures_comptadors} /> */}
{ activeView === 2 && <Meterings /> }
</Box>
</TabbedCard>
</Box>
Expand Down
57 changes: 57 additions & 0 deletions tomatic/ui/src/pages/CallinfoPage/Meterings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react'
import Box from '@mui/material/Box'
import CircularProgress from '@mui/material/CircularProgress'
import CallInfo from '../../mithril/components/callinfo'
import { useSubscriptable } from '../../services/subscriptable'

export default function Meterings() {
const contract = useSubscriptable(CallInfo.selectedContract)
const readings = useSubscriptable(CallInfo.contractDetails).lectures_comptadors
if (readings === null) {
return (
<Box className="meter-readings">
<Box className="loading layout vertical center">
{'Carregant lectures...'}
<CircularProgress />
</Box>
</Box>
)
}
if (readings.length === 0) {
return (
<Box className="meter-readings">
<Box className="loading layout vertical center">
{'No hi ha lectures disponibles.'}
</Box>
</Box>
)
}
return (
<Box className="meter-readings">
<table>
<thead>
<tr>
<th>{'Comptador'}</th>
<th>{'Data'}</th>
<th>{'Lectura'}</th>
<th>{'Origen'}</th>
<th>{'Període'}</th>
</tr>
</thead>
<tbody>
{readings.map(function (reading, i) {
return (
<tr key={i}>
<td>{reading.comptador}</td>
<td>{reading.data}</td>
<td>{reading.lectura}</td>
<td>{reading.origen}</td>
<td>{reading.periode}</td>
</tr>
)
})}
</tbody>
</table>
</Box>
)
}

0 comments on commit d6714bc

Please sign in to comment.