Skip to content

Commit 72dc654

Browse files
committed
fix: added missing functions, updated styles for every status
1 parent bb29371 commit 72dc654

File tree

5 files changed

+72
-43
lines changed

5 files changed

+72
-43
lines changed

packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
import { CurrencyTypes } from "@requestnetwork/types";
1616
import { getPaymentNetworkExtension } from "@requestnetwork/payment-detection";
1717
// Components
18+
import StatusLabel from "@requestnetwork/shared-components/status-label.svelte";
1819
import Accordion from "@requestnetwork/shared-components/accordion.svelte";
1920
import Button from "@requestnetwork/shared-components/button.svelte";
2021
import Tooltip from "@requestnetwork/shared-components/tooltip.svelte";
2122
// Icons
2223
import Check from "@requestnetwork/shared-icons/check.svelte";
2324
import Download from "@requestnetwork/shared-icons/download.svelte";
2425
// Utils
26+
import { checkStatus } from "@requestnetwork/shared-utils/checkStatus";
2527
import { formatDate } from "@requestnetwork/shared-utils/formatDate";
2628
import { calculateItemTotal } from "@requestnetwork/shared-utils/invoiceTotals";
2729
import { exportToPDF } from "@requestnetwork/shared-utils/generateInvoice";
@@ -367,9 +369,7 @@
367369
</div>
368370
<h2 class="invoice-number">
369371
Invoice #{request?.contentData?.invoiceNumber || "-"}
370-
<p class={`invoice-status ${isPaid ? "bg-green" : "bg-zinc"}`}>
371-
{isPaid ? "Paid" : "Created"}
372-
</p>
372+
<StatusLabel status={checkStatus(request)} />
373373
<Tooltip text="Download PDF">
374374
<Download
375375
onClick={async () => {
@@ -646,21 +646,6 @@
646646
height: 13px;
647647
}
648648
649-
.invoice-status {
650-
padding-left: 0.5rem;
651-
padding-right: 0.5rem;
652-
padding-top: 0.5rem;
653-
padding-bottom: 0.5rem;
654-
font-size: 14px;
655-
font-weight: 500;
656-
line-height: 1;
657-
text-align: center;
658-
border-radius: 8px;
659-
color: #ffffff;
660-
width: fit-content;
661-
margin: 0;
662-
}
663-
664649
.invoice-address {
665650
display: flex;
666651
flex-direction: column;

packages/invoice-dashboard/src/lib/view-requests.svelte

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Dropdown from "@requestnetwork/shared-components/dropdown.svelte";
1010
import Input from "@requestnetwork/shared-components/input.svelte";
1111
import PoweredBy from "@requestnetwork/shared-components/powered-by.svelte";
12+
import StatusLabel from "@requestnetwork/shared-components/status-label.svelte";
1213
import Skeleton from "@requestnetwork/shared-components/skeleton.svelte";
1314
import Toaster from "@requestnetwork/shared-components/sonner.svelte";
1415
import Tooltip from "@requestnetwork/shared-components/tooltip.svelte";
@@ -34,11 +35,12 @@
3435
import { config as defaultConfig } from "@requestnetwork/shared-utils/config";
3536
import { initializeCurrencyManager } from "@requestnetwork/shared-utils/initCurrencyManager";
3637
import { exportToPDF } from "@requestnetwork/shared-utils/generateInvoice";
38+
import { checkStatus } from "@requestnetwork/shared-utils/checkStatus";
3739
import { getCurrencyFromManager } from "@requestnetwork/shared-utils/getCurrency";
3840
import { CurrencyManager } from "@requestnetwork/currency";
3941
import { onDestroy, onMount, tick } from "svelte";
4042
import { formatUnits } from "viem";
41-
import { capitalize, debounce, formatAddress } from "../utils";
43+
import { debounce, formatAddress } from "../utils";
4244
import { Drawer, InvoiceView } from "./dashboard";
4345
import { getPaymentNetworkExtension } from "@requestnetwork/payment-detection";
4446
import { CurrencyTypes } from "@requestnetwork/types";
@@ -381,17 +383,6 @@
381383
const handleRemoveSelectedRequest = () => {
382384
activeRequest = undefined;
383385
};
384-
385-
const checkStatus = (request: any) => {
386-
switch (request?.balance?.balance > 0) {
387-
case true:
388-
return request?.balance?.balance >= request?.expectedAmount
389-
? "Paid"
390-
: "Partially Paid";
391-
default:
392-
return capitalize(request?.state);
393-
}
394-
};
395386
</script>
396387

397388
<div
@@ -653,7 +644,7 @@
653644
type={signer === request.payer?.value ? "OUT" : "IN"}
654645
/>
655646
</td>
656-
<td> {checkStatus(request)}</td>
647+
<td><StatusLabel status={checkStatus(request)} /></td>
657648
<td
658649
><Tooltip text="Download PDF">
659650
<Download

shared/components/status-label.svelte

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts">
2+
import { capitalize } from "../utils/capitalize";
3+
24
export let status: string;
35
46
let statusClass = "";
@@ -14,7 +16,7 @@
1416
case "accepted":
1517
statusClass = "status-accepted";
1618
break;
17-
case "created":
19+
case "awaiting payment":
1820
statusClass = "status-created";
1921
break;
2022
case "canceled":
@@ -30,60 +32,72 @@
3032
statusClass = "status-pending";
3133
break;
3234
default:
33-
statusClass = "";
35+
statusClass = "status-created";
3436
}
3537
}
3638
</script>
3739

3840
<div class={`status-indicator ${statusClass}`}>
39-
{status}
41+
{capitalize(status)}
4042
</div>
4143

4244
<style>
4345
.status-indicator {
4446
text-align: center;
4547
padding: 6px 12px;
4648
text-align: center;
47-
min-width: 84px;
49+
width: fit-content;
4850
border-radius: 8px;
51+
font-weight: 500;
4952
}
5053
5154
.status-paid {
5255
color: #328965;
53-
background-color: #58e1a5;
56+
background-color: rgba(88, 225, 165, 0.15);
5457
}
5558
5659
.status-partially-paid {
57-
background: linear-gradient(135deg, green 50%, white 50%);
60+
color: #328965;
61+
background: linear-gradient(
62+
135deg,
63+
rgba(88, 225, 165, 0.2) 25%,
64+
white 25%,
65+
white 50%,
66+
rgba(88, 225, 165, 0.2) 50%,
67+
rgba(88, 225, 165, 0.2) 75%,
68+
white 75%,
69+
white 100%
70+
);
71+
background-size: 20px 20px;
5872
}
5973
6074
.status-accepted {
6175
color: #006ebe;
62-
background-color: #5abaff;
76+
background-color: rgba(90, 186, 255, 0.15);
6377
}
6478
6579
.status-created {
6680
color: #c99101;
67-
background-color: #ffc531;
81+
background-color: rgba(255, 197, 49, 0.15);
6882
}
6983
7084
.status-canceled {
7185
color: #212121;
72-
background-color: #252525;
86+
background-color: rgba(37, 37, 37, 0.15);
7387
}
7488
7589
.status-rejected {
7690
color: #d9601c;
77-
background-color: #ff8743;
91+
background-color: rgba(255, 135, 67, 0.15);
7892
}
7993
8094
.status-overdue {
8195
color: #d91c1c;
82-
background-color: #ff3131;
96+
background-color: rgba(255, 49, 49, 0.15);
8397
}
8498
8599
.status-pending {
86100
color: #7b7b7b;
87-
background-color: #e0e0e0;
101+
background-color: rgba(224, 224, 224, 0.15);
88102
}
89103
</style>

shared/utils/capitalize.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const capitalize = (str: string) =>
2+
(str && str[0].toUpperCase() + str.slice(1)) || "";

shared/utils/checkStatus.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { capitalize } from "./capitalize";
2+
import { Types } from "@requestnetwork/request-client.js";
3+
4+
export const checkStatus = (request: Types.IRequestDataWithEvents | null) => {
5+
const balance = BigInt(request?.balance?.balance ?? 0);
6+
const expectedAmount = BigInt(request?.expectedAmount ?? 0);
7+
const today = new Date();
8+
const dueDate = new Date(request?.contentData?.paymentTerms?.dueDate);
9+
const isPaid = balance >= expectedAmount ? "Paid" : "Partially Paid";
10+
11+
const eventStatus = {
12+
reject: "Rejected",
13+
cancel: "Canceled",
14+
};
15+
16+
for (const [event, status] of Object.entries(eventStatus)) {
17+
if (
18+
request?.events?.some(
19+
(e: { name?: string }) => e?.name?.toLowerCase() === event.toLowerCase()
20+
)
21+
) {
22+
return capitalize(status);
23+
}
24+
}
25+
26+
if (dueDate < today) {
27+
if (balance === BigInt(0)) {
28+
return "Overdue";
29+
}
30+
return isPaid;
31+
} else {
32+
if (balance === BigInt(0)) {
33+
return "Awaiting Payment";
34+
}
35+
return isPaid;
36+
}
37+
};

0 commit comments

Comments
 (0)