Skip to content

Commit

Permalink
Merge branch 'dev' into pocketbase
Browse files Browse the repository at this point in the history
  • Loading branch information
tklein1801 committed Apr 10, 2024
2 parents 4909944 + 4eaf180 commit c4aefb0
Show file tree
Hide file tree
Showing 38 changed files with 781 additions and 275 deletions.
5 changes: 3 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {BrowserRouter, Navigate, Route, Routes} from 'react-router-dom';
import {FullPageLoader} from './components/Loading/FullPageLoader.component';
import {DashboardLayout, DashboardView, BudgetView, StocksView} from './routes/Dashboard';
import {FullPageLoader} from '@/components/Loading';
import {DashboardLayout, DashboardView, BudgetView, StocksView, AnalyticsView} from './routes/Dashboard';
import StockRoute from './routes/Stock.route';
import StocksRoute from './routes/Stocks.route';
import TransactionsRoute from './routes/Transactions.route';
Expand All @@ -26,6 +26,7 @@ const App = () => {
<Route index element={<DashboardView />} />
<Route path="budget" element={<BudgetView />} />
<Route path="stocks" element={<StocksView />} />
<Route path="analytics" element={<AnalyticsView navigateOnClose navigateTo="/dashboard" />} />
<Route path="*" element={<Navigate to="/dashboard" />} />
</Route>
<Route path="/stocks">
Expand Down
1 change: 0 additions & 1 deletion src/components/Base/Charts/ApexPieChart.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const ApexPieChart: React.FC<TApexPieChartProps> = ({data, ...props}) =>
},
},
labels: data.map(({label}) => label),

dataLabels: {
// @ts-ignore
formatter(val, opts) {
Expand Down
50 changes: 50 additions & 0 deletions src/components/Base/FullScreenDialog.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import {AppBar, Box, type BoxProps, Dialog, type DialogProps, IconButton, Toolbar, Typography} from '@mui/material';
import {CloseRounded} from '@mui/icons-material';
import {Transition} from '@/components/DeleteDialog.component.tsx';

export type TFullScreenDialogProps = DialogProps & {
title: string;
onClose: () => void;
appBarActions?: React.ReactNode;
boxProps?: BoxProps;
};

export const FullScreenDialog: React.FC<TFullScreenDialogProps> = ({
title,
onClose,
appBarActions,
boxProps,
...dialogProps
}) => {
return (
<Dialog fullScreen TransitionComponent={Transition} PaperProps={{elevation: 0}} {...dialogProps}>
<AppBar
elevation={0}
sx={{position: 'relative', border: 0, borderBottom: theme => `1px solid ${theme.palette.divider}`}}>
<Toolbar sx={{border: 'none'}}>
<Typography
sx={{
flex: 1,
fontWeight: 700,
color: 'inherit',
textDecoration: 'none',
}}
variant="h5"
component="div">
{title}
</Typography>

{appBarActions}
<IconButton edge="start" color="inherit" onClick={onClose} aria-label="close">
<CloseRounded />
</IconButton>
</Toolbar>
</AppBar>

<Box {...boxProps} sx={{p: 2, ...boxProps?.sx}}>
{dialogProps.children}
</Box>
</Dialog>
);
};
74 changes: 0 additions & 74 deletions src/components/Base/Input/FileUploadPreview.component.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Base/Input/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export * from './ReceiverAutocomplete.component';
export * from './DateRange.component';
export * from './PasswordInput.component';
export * from './FileUpload.component';
export * from './FileUploadPreview.component';
1 change: 1 addition & 0 deletions src/components/Base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './Charts';
export * from './SparklineWidget.component';
export * from './LabelBadge.component';
export * from './TabPanel.component';
export * from './FullScreenDialog.component.tsx';
2 changes: 1 addition & 1 deletion src/components/Category/Chart/IncomeChart.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const CategoryIncomeChart: React.FC<TCategoryIncomeChartProps> = () => {
<NoResults
sx={{m: 2}}
text={
chart === 'MONTH' ? 'There are no information about this month!' : 'There are no information in general!'
chart === 'MONTH' ? 'There are no transactions for this month!' : "You haven't receive any income yet!"
}
/>
)}
Expand Down
26 changes: 22 additions & 4 deletions src/components/Category/Chip.component.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import {Chip, type ChipProps} from '@mui/material';
import {useFilterStore} from '../Filter';
import {Chip, Tooltip, type ChipProps} from '@mui/material';
import {useFilterStore} from '@/components/Filter';
import {type TCategory} from '@budgetbuddyde/types';
import {useTransactionStore} from '@/components/Transaction';

export type TCategoryChipProps = ChipProps & {category: TCategory};
export type TCategoryChipProps = ChipProps & {category: TCategory; showUsage?: boolean};

export const CategoryChip: React.FC<TCategoryChipProps> = ({category, ...otherProps}) => {
export const CategoryChip: React.FC<TCategoryChipProps> = ({category, showUsage = false, ...otherProps}) => {
const {filters, setFilters} = useFilterStore();
const {categoryUsage} = useTransactionStore();

const handleChipClick = () => {
if (!filters.categories) {
Expand All @@ -30,6 +32,22 @@ export const CategoryChip: React.FC<TCategoryChipProps> = ({category, ...otherPr
});
};

if (showUsage) {
return (
<Tooltip
title={`Used ${categoryUsage.has(category.id) ? categoryUsage.get(category.id) : 0} times`}
placement="top"
arrow>
<Chip
onClick={handleChipClick}
onDelete={filters.categories && filters.categories.includes(category.id) ? handleChipDelete : undefined}
label={category.name}
variant="outlined"
{...otherProps}
/>
</Tooltip>
);
}
return (
<Chip
onClick={handleChipClick}
Expand Down
48 changes: 48 additions & 0 deletions src/components/Download/DownloadButton.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import {Button, Tooltip, type ButtonProps} from '@mui/material';
import {useSnackbarContext} from '@/components/Snackbar';

export type TDownloadButtonProps = ButtonProps & {
exportFormat: /*'CSV' |*/ 'JSON';
exportFileName: string;
data: object;
withTooltip?: boolean;
};

export const DownloadButton: React.FC<TDownloadButtonProps> = ({
exportFormat,
exportFileName,
data,
...buttonProps
}) => {
const {showSnackbar} = useSnackbarContext();
const downloadBtnRef = React.useRef<HTMLAnchorElement | null>(null);

const downloadContent = () => {
if (!downloadBtnRef.current)
return showSnackbar({
message: 'Download button not found',
action: <Button onClick={downloadContent}>Retry</Button>,
});
downloadBtnRef.current.setAttribute(
'href',
`data:text/json;charset=utf-8,${encodeURIComponent(JSON.stringify(data, null, 2))}`,
);
downloadBtnRef.current?.setAttribute('download', `${exportFileName}.${exportFormat.toLowerCase()}`);
downloadBtnRef.current.click();
showSnackbar({message: 'Download started'});
};

return (
<React.Fragment>
{buttonProps.withTooltip ? (
<Tooltip title={`Download as ${exportFormat}`}>
<Button {...buttonProps} onClick={downloadContent} />
</Tooltip>
) : (
<Button {...buttonProps} onClick={downloadContent} />
)}
<a aria-hidden ref={downloadBtnRef} />
</React.Fragment>
);
};
1 change: 1 addition & 0 deletions src/components/Download/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './DownloadButton.component';
24 changes: 21 additions & 3 deletions src/components/Drawer/FormDrawer/FormDrawer.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {Box, Drawer, Typography, type DrawerProps, Button, IconButton, Alert, Ci
import React from 'react';
import {ActionPaper} from '@/components/Base';
import {CloseRounded, DoneRounded, ErrorRounded} from '@mui/icons-material';
import {type TFormDrawerState} from './FormDrawer.reducer';
import {type TFormDrawerState} from '@/components/Drawer';
import {useKeyPress} from '@/hooks/useKeyPress.hook.ts';

export type TFormDrawerProps = {
state?: TFormDrawerState;
Expand All @@ -24,14 +25,29 @@ export const FormDrawer: React.FC<React.PropsWithChildren<TFormDrawerProps>> = (
heading = 'Drawer',
children,
}) => {
const drawerRef = React.useRef<HTMLDivElement | null>(null);
const saveBtnRef = React.useRef<HTMLButtonElement | null>(null);
const screenSize = useScreenSize();

useKeyPress(
['s'],
e => {
if (saveBtnRef.current) {
e.preventDefault();
saveBtnRef.current.click();
}
},
drawerRef.current,
true,
);

const DrawerAnchor: DrawerProps['anchor'] = React.useMemo(() => {
return screenSize === 'small' ? 'bottom' : 'right';
}, [screenSize]);

return (
<Drawer
ref={drawerRef}
anchor={DrawerAnchor}
open={open}
onClose={(_event, reason) => {
Expand Down Expand Up @@ -85,13 +101,14 @@ export const FormDrawer: React.FC<React.PropsWithChildren<TFormDrawerProps>> = (
p: 2,
pt: 0,
}}>
<Button onClick={onClose} sx={{mr: 2}}>
<Button onClick={onClose} sx={{mr: 2}} tabIndex={2}>
Cancel
</Button>

<Button
type="submit"
variant="contained"
ref={saveBtnRef}
{...(state !== undefined
? {
startIcon: state.loading ? (
Expand All @@ -103,7 +120,8 @@ export const FormDrawer: React.FC<React.PropsWithChildren<TFormDrawerProps>> = (
) : null,
disabled: state.loading,
}
: {})}>
: {})}
tabIndex={1}>
Save
</Button>
</Box>
Expand Down
Loading

0 comments on commit c4aefb0

Please sign in to comment.