Skip to content

Commit

Permalink
refactor: unfinished consumptions are redundant on person account detail
Browse files Browse the repository at this point in the history
  • Loading branch information
czabaj committed Sep 7, 2024
1 parent be6036a commit ef32303
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 48 deletions.
7 changes: 0 additions & 7 deletions src/components/TableConsumptions/TableConsumptions.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
--cell-inline-padding: var(--padding-inline, 8px);
}

.table caption {
font-size: 1.17rem;
font-weight: var(--font-weight-semibold);
margin-block: 0.25rem;
grid-column: 1 / -1;
}

.table :where(tbody, thead) {
display: contents;
}
Expand Down
5 changes: 0 additions & 5 deletions src/components/TableConsumptions/TableConsumptions.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ type classesType = {
@react.component
let make = (
~ariaLabelledby=?,
~captionSlot=?,
~formatConsumption,
~onDeleteConsumption,
~unfinishedConsumptions: array<Db.userConsumption>,
) => {
<table ?ariaLabelledby className={`${classes.table} ${Styles.table.inDialog}`}>
{switch captionSlot {
| Some(slot) => <caption> {slot} </caption>
| None => React.null
}}
<thead>
<tr className={Styles.utility.srOnly}>
<th scope="col"> {React.string("Pivo")} </th>
Expand Down
42 changes: 16 additions & 26 deletions src/pages/PlacePersonsSetting/PersonDetail.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ let byCreatedDesc = (

@react.component
let make = (
~formatConsumption,
~hasNext,
~hasPrevious,
~onDeleteConsumption,
~onDeletePerson,
~onDismiss,
~onNextPerson,
Expand Down Expand Up @@ -112,30 +110,22 @@ let make = (
}}
</p>
}}
{unfinishedConsumptions->Array.length === 0
? <p>
{React.string(`${person.name} nemá nezaúčtovaná piva.`)}
{switch (pendingTransactions, maybePersonDoc) {
| ([], Some({transactions: []})) =>
<>
{React.string(` Dokonce nemá ani účetní záznam. Pokud jste tuto osobu přidali omylem, můžete jí nyní `)}
<button
className={Styles.link.base}
onClick={_ => setDialog(_ => ConfirmDeletePerson)}
type_="button">
{React.string("zcela odebrat z aplikace")}
</button>
{React.string(". S účetním záznamem to později již není možné ☝️")}
</>
| _ => React.null
}}
</p>
: <TableConsumptions
captionSlot={React.string("Nezaúčtované konzumace")}
formatConsumption
onDeleteConsumption
unfinishedConsumptions
/>}
{switch (unfinishedConsumptions, pendingTransactions, maybePersonDoc) {
| ([], [], Some({transactions: []})) =>
<p>
{React.string(
`${person.name} nemá nezaúčtovaná piva. Dokonce nemá ani účetní záznam. Pokud jste tuto osobu přidali omylem, můžete jí nyní `,
)}
<button
className={Styles.link.base}
onClick={_ => setDialog(_ => ConfirmDeletePerson)}
type_="button">
{React.string("zcela odebrat z aplikace")}
</button>
{React.string(". S účetním záznamem to později již není možné ☝️")}
</p>
| _ => React.null
}}
<section ariaLabelledby="financial_transactions">
<header>
<h3 id="financial_transactions"> {React.string("Účetní záznamy")} </h3>
Expand Down
10 changes: 0 additions & 10 deletions src/pages/PlacePersonsSetting/PlacePersonsSetting.res
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ let make = (~placeId) => {
if !isUserAuthorized(UserRoles.Admin) {
Exn.raiseError(`Insufficient permissions to view this page`)
}
let formatConsumption = BackendUtils.getFormatConsumption(place.consumptionSymbols)
<FormattedCurrency.Provider value={place.currency}>
<div className=Styles.page.narrow>
<PlaceHeader
Expand Down Expand Up @@ -167,17 +166,8 @@ let make = (~placeId) => {
let unfinishedConsumptions =
unfinishedConsumptionsByUser->Map.get(personId)->Option.getOr([])
<PersonDetail
formatConsumption
hasNext
hasPrevious
onDeleteConsumption={consumption => {
Db.Keg.deleteConsumption(
firestore,
~placeId,
~kegId=consumption.kegId,
~consumptionId=consumption.consumptionId,
)->ignore
}}
onDeletePerson={_ => {
Db.Person.delete(firestore, ~placeId, ~personId)->ignore
}}
Expand Down

0 comments on commit ef32303

Please sign in to comment.