Skip to content

Commit

Permalink
feat: catch unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Jan 25, 2024
1 parent bccc00c commit cf85542
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
7 changes: 4 additions & 3 deletions public/assets/i18n/en/period.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"invoices": "Invoices have been or have to be invoices for a period from <strong>{{from}}</strong> to <strong>{{to}}</strong>.",
"text": "If a part of this period is over and related invoices have been billed, you can close the timeframe.",
"text-more": "This function can be useful for example when you want to close an accounting year.",
"invoices": "Invoices have been or need to be issued for the period from <strong>{{from}}</strong> to <strong>{{to}}</strong>.",
"no_invoices": "Invoices are issued or need to be issued for an unspecified period.",
"text": "If a portion of this period has elapsed and the related invoices have been issued, you may close the timeframe.",
"text-more": "This function can be useful, for instance, when you need to close an accounting year.",
"close": "Close selected period",
"alert": {
"warning": "WARNING",
Expand Down
28 changes: 19 additions & 9 deletions src/pages/period/Period.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ const Period: React.FC = () => {
await initPeriod();
};

const renderPeriod = () => {
if (period?.from === undefined && period?.to === undefined) {
return <p className={`${styles.text} ion-padding-top`}>{t('period:no_invoices')}</p>;
}

return (
<p
className={`${styles.text} ion-padding-top`}
dangerouslySetInnerHTML={{
__html: t('period:invoices', {
from: format(period?.from) ?? t('period:unknown'),
to: format(period?.to) ?? t('period:unknown'),
}),
}}
></p>
);
};

return (
<IonPage>
<IonContent>
Expand All @@ -106,15 +124,7 @@ const Period: React.FC = () => {
</IonHeader>

<LocalizationProvider dateAdapter={AdapterDateFns}>
<p
className={`${styles.text} ion-padding-top`}
dangerouslySetInnerHTML={{
__html: t('period:invoices', {
from: format(period?.from) ?? t('period:unknown'),
to: format(period?.to) ?? t('period:unknown'),
}),
}}
></p>
{renderPeriod()}

<p>{t('period:text')}</p>

Expand Down

0 comments on commit cf85542

Please sign in to comment.