diff --git a/packages/files-ui/src/Components/Elements/InvoiceLines.tsx b/packages/files-ui/src/Components/Elements/InvoiceLines.tsx new file mode 100644 index 0000000000..ba86b290d7 --- /dev/null +++ b/packages/files-ui/src/Components/Elements/InvoiceLines.tsx @@ -0,0 +1,124 @@ +import React, { useMemo } from "react" +import { makeStyles, createStyles } from "@chainsafe/common-theme" +import { CSFTheme } from "../../Themes/types" +import { Typography, Loading } from "@chainsafe/common-components" +import { Trans } from "@lingui/macro" +import dayjs from "dayjs" +import { useBilling } from "../../Contexts/BillingContext" + +const useStyles = makeStyles( + ({ constants, breakpoints, palette, typography }: CSFTheme) => + createStyles({ + heading: { + marginBottom: constants.generalUnit * 4, + [breakpoints.down("md")]: { + marginBottom: constants.generalUnit * 2 + } + }, + loader: { + marginTop: constants.generalUnit + }, + centered: { + textAlign: "center" + }, + root: { + [breakpoints.down("md")]: { + padding: `0 ${constants.generalUnit}px` + } + }, + setOption: { + width: "100%", + backgroundColor: palette.additional["gray"][4], + color: palette.additional["gray"][9], + padding: constants.generalUnit * 1.5, + borderRadius: 16, + marginTop: constants.generalUnit * 1.5, + "& > div": { + display: "flex", + alignItems: "center", + "& > span": { + display: "block", + lineHeight: "16px", + fontWeight: typography.fontWeight.regular, + "&.receiptDate": { + marginLeft: constants.generalUnit, + marginRight: constants.generalUnit, + flex: "1 1 0" + } + } + } + }, + price: { + fontWeight: "bold !important" as "bold" + } + }) +) + +interface IInvoiceProps { + lineNumber?: number +} + +const InvoiceLines = ({ lineNumber }: IInvoiceProps) => { + const classes = useStyles() + const { invoices } = useBilling() + const invoicesToShow = useMemo(() => { + if (!invoices) return + + return lineNumber + ? invoices.slice(0, lineNumber) + : invoices + }, [invoices, lineNumber]) + + return ( + <> + {!invoicesToShow && ( +
+ +
+ )} + {invoicesToShow && !invoicesToShow.length && ( +
+ + No invoice found + +
+ )} + {!!invoicesToShow?.length && ( + invoicesToShow.map(({ paid_on, amount, currency, uuid }) => +
+
+ + {amount} {currency} + + + {dayjs(paid_on).format("MMM D, YYYY")} + + + {uuid} + +
+
+ ) + )} + + ) +} + +export default InvoiceLines \ No newline at end of file diff --git a/packages/files-ui/src/Components/Modules/Settings/SubscriptionTab/BillingHistory.tsx b/packages/files-ui/src/Components/Modules/Settings/SubscriptionTab/BillingHistory.tsx index a4a67364e6..0139dc3ba8 100644 --- a/packages/files-ui/src/Components/Modules/Settings/SubscriptionTab/BillingHistory.tsx +++ b/packages/files-ui/src/Components/Modules/Settings/SubscriptionTab/BillingHistory.tsx @@ -3,6 +3,7 @@ import { Typography, Link } from "@chainsafe/common-components" import { makeStyles, ITheme, createStyles } from "@chainsafe/common-theme" import { Trans } from "@lingui/macro" import { ROUTE_LINKS } from "../../../FilesRoutes" +import InvoiceLines from "../../../Elements/InvoiceLines" const useStyles = makeStyles(({ constants }: ITheme) => createStyles({ @@ -11,8 +12,8 @@ const useStyles = makeStyles(({ constants }: ITheme) => margin: `${constants.generalUnit * 1.5}px 0` }, link: { - display: "inline-block", - margin: `${constants.generalUnit * 2}px 0` + textAlign: "right", + marginBottom: constants.generalUnit } }) ) @@ -29,16 +30,15 @@ const BillingHistory = () => { Billing history - - View invoices + + All invoices + ) } diff --git a/packages/files-ui/src/Components/Pages/BillingHistory.tsx b/packages/files-ui/src/Components/Pages/BillingHistory.tsx index 116966c28b..16079ae2b5 100644 --- a/packages/files-ui/src/Components/Pages/BillingHistory.tsx +++ b/packages/files-ui/src/Components/Pages/BillingHistory.tsx @@ -1,11 +1,9 @@ -import React, { useEffect, useState } from "react" +import React from "react" import { makeStyles, createStyles } from "@chainsafe/common-theme" import { CSFTheme } from "../../Themes/types" -import { useFilesApi } from "../../Contexts/FilesApiContext" -import { InvoiceResponse } from "@chainsafe/files-api-client" -import { Table, TableHead, TableHeadCell, TableBody, TableRow, TableCell, Typography, Loading } from "@chainsafe/common-components" +import { Typography } from "@chainsafe/common-components" import { Trans } from "@lingui/macro" -import dayjs from "dayjs" +import InvoiceLines from "../Elements/InvoiceLines" const useStyles = makeStyles( ({ constants, breakpoints }: CSFTheme) => @@ -32,31 +30,6 @@ const useStyles = makeStyles( const BillingHistory = () => { const classes = useStyles() - const { filesApiClient } = useFilesApi() - const [invoices, setInvoices] = useState([]) - const [subscriptionId, setSubscriptionId] = useState("") - const [isLoading, setIsLoading] = useState(true) - - useEffect(() => { - filesApiClient.getCurrentSubscription() - .then((subscription) => { - setSubscriptionId(subscription.id) - }) - .catch((e) => { - console.error(e) - setIsLoading(false) - }) - }, [filesApiClient]) - - useEffect(() => { - if(!subscriptionId) return - filesApiClient.getAllInvoices(subscriptionId) - .then(({ invoices }) => { - setInvoices(invoices) - }) - .catch(console.error) - .finally(() => setIsLoading(false)) - }, [filesApiClient, subscriptionId]) return (
@@ -67,56 +40,7 @@ const BillingHistory = () => { > Billing history - {isLoading && ( -
- -
- )} - {!invoices.length && !isLoading && ( -
- - No invoice found - -
- )} - {!!invoices.length && ( - - - - Date - Amount - Method - Receipt - - - - {invoices.map(({ paid_on, amount, payment_method, currency, uuid }, index) => - - {dayjs(paid_on).format("ddd D MMMM h:mm a")} - {amount} {currency} - {payment_method} - {uuid} - )} - -
- )} - +
) } diff --git a/packages/files-ui/src/Contexts/BillingContext.tsx b/packages/files-ui/src/Contexts/BillingContext.tsx index c72c2e7f78..d3c7354536 100644 --- a/packages/files-ui/src/Contexts/BillingContext.tsx +++ b/packages/files-ui/src/Contexts/BillingContext.tsx @@ -1,7 +1,7 @@ import * as React from "react" import { useFilesApi } from "./FilesApiContext" import { ReactNode, useEffect, useState } from "react" -import { Card, CurrentSubscription, Product } from "@chainsafe/files-api-client" +import { Card, CurrentSubscription, InvoiceResponse, Product } from "@chainsafe/files-api-client" import { useCallback } from "react" import { t } from "@lingui/macro" import { PaymentMethod } from "@stripe/stripe-js" @@ -20,6 +20,7 @@ interface IBillingContext { getAvailablePlans: () => Promise deleteCard: (card: Card) => Promise updateDefaultCard: (id: PaymentMethod["id"]) => Promise + invoices?: InvoiceResponse[] cancelCurrentSubscription: () => Promise } @@ -50,6 +51,20 @@ const BillingProvider = ({ children }: BillingContextProps) => { const { refreshBuckets } = useFiles() const [currentSubscription, setCurrentSubscription] = useState() const [defaultCard, setDefaultCard] = useState(undefined) + const [invoices, setInvoices] = useState() + + useEffect(() => { + if (!currentSubscription) return + + filesApiClient.getAllInvoices(currentSubscription.id) + .then(({ invoices }) => { + setInvoices(invoices) + }) + .catch((e: any) => { + console.error(e) + setInvoices([]) + }) + }, [currentSubscription, filesApiClient]) const refreshDefaultCard = useCallback(() => { filesApiClient.getDefaultCard().then((card) => { @@ -152,6 +167,7 @@ const BillingProvider = ({ children }: BillingContextProps) => { getAvailablePlans, deleteCard, updateDefaultCard, + invoices, cancelCurrentSubscription }} > diff --git a/packages/files-ui/src/locales/de/messages.po b/packages/files-ui/src/locales/de/messages.po index 855ac4db9c..bef77212e9 100644 --- a/packages/files-ui/src/locales/de/messages.po +++ b/packages/files-ui/src/locales/de/messages.po @@ -79,10 +79,10 @@ msgstr "" msgid "Adding you to the shared folder..." msgstr "" -msgid "Allow lookup by sharing key, wallet address or username" +msgid "All invoices" msgstr "" -msgid "Amount" +msgid "Allow lookup by sharing key, wallet address or username" msgstr "" msgid "An error occurred:" @@ -262,9 +262,6 @@ msgstr "" msgid "Data restored successfully" msgstr "" -msgid "Date" -msgstr "" - msgid "Date Uploaded" msgstr "" @@ -502,9 +499,6 @@ msgstr "" msgid "Manage Shared Folder" msgstr "" -msgid "Method" -msgstr "" - msgid "Monthly billing" msgstr "" @@ -667,9 +661,6 @@ msgstr "Profileinstellungen" msgid "Profile updated" msgstr "Profil aktualisiert" -msgid "Receipt" -msgstr "" - msgid "Recover" msgstr "Wiederherstellen" @@ -1021,9 +1012,6 @@ msgstr "" msgid "View folder" msgstr "Ordner anzeigen" -msgid "View invoices" -msgstr "" - msgid "Wallet address" msgstr "" diff --git a/packages/files-ui/src/locales/en/messages.po b/packages/files-ui/src/locales/en/messages.po index 6b8836dd5d..dfd6d9ac38 100644 --- a/packages/files-ui/src/locales/en/messages.po +++ b/packages/files-ui/src/locales/en/messages.po @@ -79,12 +79,12 @@ msgstr "Add viewers and editors by username, sharing id or Ethereum address." msgid "Adding you to the shared folder..." msgstr "Adding you to the shared folder..." +msgid "All invoices" +msgstr "All invoices" + msgid "Allow lookup by sharing key, wallet address or username" msgstr "Allow lookup by sharing key, wallet address or username" -msgid "Amount" -msgstr "Amount" - msgid "An error occurred:" msgstr "An error occurred:" @@ -262,9 +262,6 @@ msgstr "Data moved to bin successfully" msgid "Data restored successfully" msgstr "Data restored successfully" -msgid "Date" -msgstr "Date" - msgid "Date Uploaded" msgstr "Date Uploaded" @@ -505,9 +502,6 @@ msgstr "Manage Access" msgid "Manage Shared Folder" msgstr "Manage Shared Folder" -msgid "Method" -msgstr "Method" - msgid "Monthly billing" msgstr "Monthly billing" @@ -670,9 +664,6 @@ msgstr "Profile settings" msgid "Profile updated" msgstr "Profile updated" -msgid "Receipt" -msgstr "Receipt" - msgid "Recover" msgstr "Recover" @@ -1024,9 +1015,6 @@ msgstr "Verifying the link..." msgid "View folder" msgstr "View folder" -msgid "View invoices" -msgstr "View invoices" - msgid "Wallet address" msgstr "Wallet address" diff --git a/packages/files-ui/src/locales/es/messages.po b/packages/files-ui/src/locales/es/messages.po index cea4c1cc1f..8dd23f4337 100644 --- a/packages/files-ui/src/locales/es/messages.po +++ b/packages/files-ui/src/locales/es/messages.po @@ -80,10 +80,10 @@ msgstr "" msgid "Adding you to the shared folder..." msgstr "" -msgid "Allow lookup by sharing key, wallet address or username" +msgid "All invoices" msgstr "" -msgid "Amount" +msgid "Allow lookup by sharing key, wallet address or username" msgstr "" msgid "An error occurred:" @@ -263,9 +263,6 @@ msgstr "" msgid "Data restored successfully" msgstr "" -msgid "Date" -msgstr "" - msgid "Date Uploaded" msgstr "" @@ -506,9 +503,6 @@ msgstr "" msgid "Manage Shared Folder" msgstr "" -msgid "Method" -msgstr "" - msgid "Monthly billing" msgstr "" @@ -671,9 +665,6 @@ msgstr "" msgid "Profile updated" msgstr "Perfil actualizado" -msgid "Receipt" -msgstr "" - msgid "Recover" msgstr "Recuperar" @@ -1025,9 +1016,6 @@ msgstr "" msgid "View folder" msgstr "Utilice un navegador guardado" -msgid "View invoices" -msgstr "" - msgid "Wallet address" msgstr "Utilice un navegador guardado" diff --git a/packages/files-ui/src/locales/fr/messages.po b/packages/files-ui/src/locales/fr/messages.po index 6b746e9373..5e68e07d65 100644 --- a/packages/files-ui/src/locales/fr/messages.po +++ b/packages/files-ui/src/locales/fr/messages.po @@ -80,12 +80,12 @@ msgstr "Ajoutez des personnes pouvant visualiser ou afficher par nom d'utilisate msgid "Adding you to the shared folder..." msgstr "Je vous ajoute au dossier partagé…" +msgid "All invoices" +msgstr "" + msgid "Allow lookup by sharing key, wallet address or username" msgstr "Permettre la recherche par clé de partage, adresse du portefeuille ou nom d'utilisateur" -msgid "Amount" -msgstr "" - msgid "An error occurred:" msgstr "Une erreur s'est produite :" @@ -263,9 +263,6 @@ msgstr "Les données ont été déplacées vers la poubelle avec succès" msgid "Data restored successfully" msgstr "Données restaurées avec succès" -msgid "Date" -msgstr "" - msgid "Date Uploaded" msgstr "" @@ -506,9 +503,6 @@ msgstr "Gérer l’accès" msgid "Manage Shared Folder" msgstr "Gérer le dossier partagé" -msgid "Method" -msgstr "" - msgid "Monthly billing" msgstr "" @@ -671,9 +665,6 @@ msgstr "Paramètres du profil" msgid "Profile updated" msgstr "Profile mis à jour" -msgid "Receipt" -msgstr "" - msgid "Recover" msgstr "Récupérer" @@ -1025,9 +1016,6 @@ msgstr "Vérification du lien…" msgid "View folder" msgstr "Voir le dossier" -msgid "View invoices" -msgstr "" - msgid "Wallet address" msgstr "Addresse du wallet" diff --git a/packages/files-ui/src/locales/no/messages.po b/packages/files-ui/src/locales/no/messages.po index 0a0c61bbe2..e65001c03f 100644 --- a/packages/files-ui/src/locales/no/messages.po +++ b/packages/files-ui/src/locales/no/messages.po @@ -79,10 +79,10 @@ msgstr "" msgid "Adding you to the shared folder..." msgstr "" -msgid "Allow lookup by sharing key, wallet address or username" +msgid "All invoices" msgstr "" -msgid "Amount" +msgid "Allow lookup by sharing key, wallet address or username" msgstr "" msgid "An error occurred:" @@ -262,9 +262,6 @@ msgstr "" msgid "Data restored successfully" msgstr "" -msgid "Date" -msgstr "" - msgid "Date Uploaded" msgstr "" @@ -502,9 +499,6 @@ msgstr "" msgid "Manage Shared Folder" msgstr "" -msgid "Method" -msgstr "" - msgid "Monthly billing" msgstr "" @@ -667,9 +661,6 @@ msgstr "Profilinnstillinger" msgid "Profile updated" msgstr "Profil oppdatert" -msgid "Receipt" -msgstr "" - msgid "Recover" msgstr "Gjenopprett" @@ -1021,9 +1012,6 @@ msgstr "" msgid "View folder" msgstr "Vis mappe" -msgid "View invoices" -msgstr "" - msgid "Wallet address" msgstr ""