-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proposal): Implement CashCard component for dashboard. Add title…
… and tabs to dashboard page.
- Loading branch information
1 parent
2b602ef
commit e735f2a
Showing
4 changed files
with
169 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
examples/with-nextjs-and-clerk-auth/src/components/CashCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { useCurrencies } from '@monite/sdk-react'; | ||
import { List, ListItem, ListItemText, Stack, Typography } from '@mui/material'; | ||
|
||
import { IconUniversity } from '@/icons'; | ||
|
||
import DashboardCard from './DashboardCard'; | ||
import EmptyState from './EmptyState'; | ||
|
||
interface CashItem { | ||
name: string; | ||
details: string; | ||
total: number; | ||
} | ||
|
||
const mockData = { | ||
total: 12734780, | ||
currency: 'USD', | ||
items: [ | ||
{ | ||
name: 'American Express', | ||
details: 'Business Card ( **** 8779)', | ||
total: 9734780, | ||
}, | ||
{ | ||
name: 'Mercury', | ||
details: 'Checking account (**** 2190)', | ||
total: 1000000, | ||
}, | ||
{ | ||
name: 'JP Morgan Case', | ||
details: 'Checking account (**** 5467)', | ||
total: 2000000, | ||
}, | ||
], | ||
}; | ||
|
||
const mockApi = () => Promise.resolve(mockData); | ||
|
||
export function CashCard() { | ||
const [total, setTotal] = useState(0); | ||
const [currency, setCurrency] = useState<string>(); | ||
const [items, setItems] = useState<CashItem[]>([]); | ||
|
||
const { formatCurrencyToDisplay } = useCurrencies(); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
const data = await mockApi(); | ||
|
||
setTotal(data.total); | ||
setCurrency(data.currency); | ||
setItems(data.items); | ||
}; | ||
|
||
fetchData(); | ||
}, []); | ||
|
||
const title = ( | ||
<Stack direction="row" justifyContent="space-between" alignItems="center"> | ||
<Stack> | ||
<Typography variant="subtitle1">Cash on accounts</Typography> | ||
{Boolean(items.length) && ( | ||
<Typography>{items.length} account(s)</Typography> | ||
)} | ||
</Stack> | ||
{Boolean(total) && ( | ||
<Typography variant="h3"> | ||
{formatCurrencyToDisplay(total, currency as string)} | ||
</Typography> | ||
)} | ||
</Stack> | ||
); | ||
|
||
const emptyState = ( | ||
<EmptyState renderIcon={(props) => <IconUniversity {...props} />}> | ||
No bank accounts connected | ||
</EmptyState> | ||
); | ||
|
||
const itemsList = ( | ||
<List dense> | ||
{items.map((item) => ( | ||
<ListItem key={item.name} disablePadding={true}> | ||
<ListItemText | ||
primary={item.name} | ||
primaryTypographyProps={{ variant: 'body1' }} | ||
secondary={item.details} | ||
/> | ||
<ListItemText | ||
primary={formatCurrencyToDisplay(item.total, currency as string)} | ||
primaryTypographyProps={{ | ||
variant: 'body1', | ||
sx: { fontWeight: 700, textAlign: 'right' }, | ||
}} | ||
/> | ||
</ListItem> | ||
))} | ||
</List> | ||
); | ||
|
||
return ( | ||
<DashboardCard | ||
title={title} | ||
renderIcon={(props) => <IconUniversity {...props} />} | ||
> | ||
{items.length ? itemsList : emptyState} | ||
</DashboardCard> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters