Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show receipts in the settings #1822

Merged
merged 39 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4c4e754
Settings plan page UI (#1182)
tanmoyAtb Aug 18, 2021
a58a85e
billing - Add card (#1446)
tanmoyAtb Aug 20, 2021
685ba3c
Merge remote-tracking branch 'origin/dev' into epic/files-billing
FSM1 Aug 24, 2021
45ba1be
Merge branch 'dev' of github.com:ChainSafe/ui-monorepo into epic/file…
Tbaut Aug 25, 2021
925a706
wait for 10min
Tbaut Aug 25, 2021
67b9446
Current card: billing (#1463)
tanmoyAtb Aug 25, 2021
0795b57
[FILES] Subscription tab update (#1476)
FSM1 Aug 30, 2021
a440bda
Merge dev into epic/files-billing (#1491)
Tbaut Sep 6, 2021
44458cb
merge dev (#1502)
Tbaut Sep 8, 2021
0339e57
Merge dev to epic/files-billing (#1525)
Tbaut Sep 15, 2021
3f275ce
merge latest 'origin/dev' into 'epic/files-billing' (#1588)
FSM1 Sep 27, 2021
a539565
Account Restricted (#1589)
FSM1 Sep 29, 2021
e4591af
Payments add card update with setup intent (#1584)
tanmoyAtb Oct 4, 2021
8448f58
default card API added (#1623)
tanmoyAtb Oct 12, 2021
963e514
Current Product Widget (#1482)
RyRy79261 Oct 19, 2021
c6e935b
updated default card API call (#1642)
tanmoyAtb Oct 19, 2021
766facb
notifications for billing (#1656)
tanmoyAtb Nov 3, 2021
063bfc1
merge dev into billing (#1694)
tanmoyAtb Nov 4, 2021
7aaf835
[Files] - Billing history (#1492)
Tbaut Nov 4, 2021
5bb4490
Change plan widget (#1649)
RyRy79261 Nov 4, 2021
da47f1d
Place user dropdown in app nav (#1685)
tanmoyAtb Nov 5, 2021
79e4549
Merge origin/dev 2021-11-25 (#1780)
FSM1 Nov 26, 2021
f8f00f8
handle card deletion (#1800)
Tbaut Dec 3, 2021
ec2469e
Merge dev to epic/files-billing 7/12/2021 (#1810)
Tbaut Dec 7, 2021
3512dd1
signout on mobile (#1812)
Tbaut Dec 7, 2021
ecce826
Merge dev into epic/files-billing (#1816)
Tbaut Dec 8, 2021
1984d36
Remove default card (#1814)
tanmoyAtb Dec 8, 2021
72d72c7
Billing credit card flow (#1788)
tanmoyAtb Dec 8, 2021
ae68b4a
skeleton
Tbaut Dec 8, 2021
30abc35
lint
Tbaut Dec 8, 2021
a8bef28
fix conflicts
Tbaut Dec 14, 2021
0a11271
lingui extract
actions-user Dec 14, 2021
7eb71dc
fix merge issues
Tbaut Dec 14, 2021
92801c6
merge upstream
Tbaut Dec 14, 2021
7f9d8a1
lingui extract
actions-user Dec 14, 2021
48db061
use pills
Tbaut Dec 14, 2021
3626c0d
lingui extract
actions-user Dec 14, 2021
6db86cb
Update packages/files-ui/src/Components/Elements/InvoiceLines.tsx
Tbaut Dec 15, 2021
70dbd30
Merge branch 'dev' into feat/tbaut-1808
Tbaut Dec 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions packages/files-ui/src/Components/Elements/InvoiceLines.tsx
Original file line number Diff line number Diff line change
@@ -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 && (
<div className={classes.centered}>
<Loading
className={classes.loader}
type="initial"
size={32}
/>
</div>
)}
{invoicesToShow && !invoicesToShow.length && (
<div className={classes.centered}>
<Typography
className={classes.heading}
variant="h4"
component="p"
>
<Trans>No invoice found</Trans>
</Typography>
</div>
)}
{!!invoicesToShow?.length && (
invoicesToShow.map(({ paid_on, amount, currency, uuid }) =>
<section
className={classes.setOption}
key={uuid}
>
<div>
<Typography
variant="body1"
className={classes.price}
>
{amount} {currency}
</Typography>
<Typography
variant="body2"
className="receiptDate"
>
{dayjs(paid_on).format("MMM D, YYYY")}
</Typography>
<Typography>
{uuid}
</Typography>
</div>
</section>
)
)}
</>
)
}

export default InvoiceLines
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
}
})
)
Expand All @@ -29,16 +30,15 @@ const BillingHistory = () => {
<Trans>Billing history</Trans>
</Typography>
<Typography
variant="h5"
component="h5"
variant="body1"
component="p"
className={classes.link}
>
<Link
className={classes.link}
to={ROUTE_LINKS.BillingHistory}
>
<Trans>View invoices</Trans>
<Link to={ROUTE_LINKS.BillingHistory}>
<Trans>All invoices</Trans>
</Link>
</Typography>
<InvoiceLines lineNumber={3}/>
</div>
)
}
Expand Down
84 changes: 4 additions & 80 deletions packages/files-ui/src/Components/Pages/BillingHistory.tsx
Original file line number Diff line number Diff line change
@@ -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) =>
Expand All @@ -32,31 +30,6 @@ const useStyles = makeStyles(

const BillingHistory = () => {
const classes = useStyles()
const { filesApiClient } = useFilesApi()
const [invoices, setInvoices] = useState<InvoiceResponse[]>([])
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 (
<div className={classes.root}>
Expand All @@ -67,56 +40,7 @@ const BillingHistory = () => {
>
<Trans>Billing history</Trans>
</Typography>
{isLoading && (
<div className={classes.centered}>
<Loading
className={classes.loader}
type="initial"
size={32}
/>
</div>
)}
{!invoices.length && !isLoading && (
<div className={classes.centered}>
<Typography
className={classes.heading}
variant="h4"
component="p"
>
<Trans>No invoice found</Trans>
</Typography>
</div>
)}
{!!invoices.length && (
<Table
fullWidth={true}
dense={true}
>
<TableHead>
<TableRow
type="grid"
>
<TableHeadCell align="left"><Trans>Date</Trans></TableHeadCell>
<TableHeadCell align="left"><Trans>Amount</Trans></TableHeadCell>
<TableHeadCell align="left"><Trans>Method</Trans></TableHeadCell>
<TableHeadCell align="left"><Trans>Receipt</Trans></TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
{invoices.map(({ paid_on, amount, payment_method, currency, uuid }, index) =>
<TableRow
type="grid"
key={index}
>
<TableCell align="left">{dayjs(paid_on).format("ddd D MMMM h:mm a")}</TableCell>
<TableCell align="left">{amount} {currency}</TableCell>
<TableCell align="left">{payment_method}</TableCell>
<TableCell align="left">{uuid}</TableCell>
</TableRow>)}
</TableBody>
</Table>
)}

<InvoiceLines />
</div>
)
}
Expand Down
18 changes: 17 additions & 1 deletion packages/files-ui/src/Contexts/BillingContext.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -20,6 +20,7 @@ interface IBillingContext {
getAvailablePlans: () => Promise<Product[]>
deleteCard: (card: Card) => Promise<void>
updateDefaultCard: (id: PaymentMethod["id"]) => Promise<void>
invoices?: InvoiceResponse[]
cancelCurrentSubscription: () => Promise<void>
}

Expand Down Expand Up @@ -50,6 +51,20 @@ const BillingProvider = ({ children }: BillingContextProps) => {
const { refreshBuckets } = useFiles()
const [currentSubscription, setCurrentSubscription] = useState<CurrentSubscription | undefined>()
const [defaultCard, setDefaultCard] = useState<Card | undefined>(undefined)
const [invoices, setInvoices] = useState<InvoiceResponse[] | undefined>()

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) => {
Expand Down Expand Up @@ -152,6 +167,7 @@ const BillingProvider = ({ children }: BillingContextProps) => {
getAvailablePlans,
deleteCard,
updateDefaultCard,
invoices,
cancelCurrentSubscription
}}
>
Expand Down
16 changes: 2 additions & 14 deletions packages/files-ui/src/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down Expand Up @@ -262,9 +262,6 @@ msgstr ""
msgid "Data restored successfully"
msgstr ""

msgid "Date"
msgstr ""

msgid "Date Uploaded"
msgstr ""

Expand Down Expand Up @@ -502,9 +499,6 @@ msgstr ""
msgid "Manage Shared Folder"
msgstr ""

msgid "Method"
msgstr ""

msgid "Monthly billing"
msgstr ""

Expand Down Expand Up @@ -667,9 +661,6 @@ msgstr "Profileinstellungen"
msgid "Profile updated"
msgstr "Profil aktualisiert"

msgid "Receipt"
msgstr ""

msgid "Recover"
msgstr "Wiederherstellen"

Expand Down Expand Up @@ -1021,9 +1012,6 @@ msgstr ""
msgid "View folder"
msgstr "Ordner anzeigen"

msgid "View invoices"
msgstr ""

msgid "Wallet address"
msgstr ""

Expand Down
Loading