Skip to content

Commit

Permalink
Combined util components and added no-connectivity page
Browse files Browse the repository at this point in the history
  • Loading branch information
ystxn committed Apr 20, 2024
1 parent 2b703a8 commit 122a127
Show file tree
Hide file tree
Showing 25 changed files with 120 additions and 82 deletions.
2 changes: 1 addition & 1 deletion src/admin/admin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Routes, Route, Navigate, Link, useLocation } from 'react-router-dom';
import { useState } from 'react';
import Tab from '@mui/material/Tab';
import Tabs from '@mui/material/Tabs';
import Title from '../core/title';
import { Title } from '../core/utils';
import styled from 'styled-components';
import ManageIssuers from './manage-issuers';
import ManageUsers from './manage-users';
Expand Down
2 changes: 1 addition & 1 deletion src/admin/manage-issuers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const IssuersGrid = ({ issuers, setIssuers }) => {
setShowConfirm(false);
});

const IssuersDataGrid = () => issuers.length === 0 ?
const IssuersDataGrid = () => !issuers || issuers.length === 0 ?
<Alert severity="info" variant="outlined">No issuers added yet</Alert> :
(
<>
Expand Down
8 changes: 5 additions & 3 deletions src/core/api.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ const api = () => {

const handleError = ({ message }) => {
setLoading(false);
const msg = message.startsWith('NetworkError') || message.startsWith('Failed to fetch')
? 'Unable to establish connectivity' : message;
showStatus('error', msg);
if (message.startsWith('NetworkError') || message.startsWith('Failed to fetch')) {
navigate('no-connectivity');
} else {
showStatus('error', message);
}
};

const apiCall = (method, uri, callback, body) => {
Expand Down
7 changes: 4 additions & 3 deletions src/core/app.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffect } from 'react';
import { NoConnectivity, NotFound } from './utils';
import { Routes, Route, Navigate } from 'react-router-dom';
import { useEffect } from 'react';
import { useTheme } from '@mui/material/styles';
import Admin from '../admin/admin';
import api from './api';
import Dashboard from '../dashboard/dashboard';
import NavBar from '../nav-bar/main-menu';
import NotFound from './not-found';
import Profile from '../settings/profile';
import Settings from '../settings/settings';
import state from './state';
Expand Down Expand Up @@ -46,7 +46,7 @@ const App = () => {
}
}, []);

return issuers && accounts && (
return (
<Root>
<NavBar />
<Content isMobile={isMobile}>
Expand All @@ -56,6 +56,7 @@ const App = () => {
<Route path="admin/*" element={<Admin /> } />
<Route path="settings/*" element={<Settings /> } />
<Route path="profile" element={<Profile /> } />
<Route path="no-connectivity" element={<NoConnectivity />} />
<Route path="/" element={<Navigate to="/dash" />} />
<Route path="register" element={<Navigate to="/dash" /> } />
<Route path="login" element={<Navigate to="/dash" /> } />
Expand Down
29 changes: 0 additions & 29 deletions src/core/loader.jsx

This file was deleted.

6 changes: 0 additions & 6 deletions src/core/not-found.jsx

This file was deleted.

8 changes: 0 additions & 8 deletions src/core/sub-title.jsx

This file was deleted.

8 changes: 0 additions & 8 deletions src/core/title.jsx

This file was deleted.

73 changes: 73 additions & 0 deletions src/core/utils.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Divider, Typography } from '@mui/material';
import { grey } from '@mui/material/colors';
import Box from '@mui/material/Box';
import CircularProgress from '@mui/material/CircularProgress';
import Skeleton from '@mui/material/Skeleton';
import styled from 'styled-components';

const Root = styled.div`
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
`;

const Card = styled.div`
background: ${grey[900]};
border-radius: .5rem;
`;

const CircularLoader = () => (
<Root>
<CircularProgress size="5rem" thickness={2} />
</Root>
);

const HorizontalLoader = () => (
<Box width="100%" height="100%">
<Skeleton animation="wave" />
<Skeleton animation="wave" />
<Skeleton animation="wave" />
<Skeleton animation="wave" />
</Box>
);

const Title = ({ mb, children }) => (
<Typography variant="h5" m={0} mb={mb}>
{children}
</Typography>
);

const SubTitle = ({ children }) => (
<Typography variant="h6" mb={1}>
{children}
</Typography>
);

const Error = ({ title, message }) => (
<Root>
<Card>
<Typography m={3} variant="h4">
{title}
</Typography>
<Divider />
<Typography m={3}>
{message}
</Typography>
</Card>
</Root>
);

const NotFound = () => <Error title="Not Found" message="This page does not exist" />;

const NoConnectivity = () => <Error title="No Connectivity" message="Sledger is unavailable at the moment" />;

export {
CircularLoader,
HorizontalLoader,
Title,
SubTitle,
NotFound,
NoConnectivity,
};
4 changes: 2 additions & 2 deletions src/dashboard/balance-history.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BarChart } from '@mui/x-charts';
import { HorizontalLoader } from '../core/loader';
import { HorizontalLoader } from '../core/utils';
import { useEffect, useState } from 'react';
import api from '../core/api';
import dayjs from 'dayjs';
import Title from '../core/title';
import { Title } from '../core/utils';

const BalanceHistory = ({ setRoute }) => {
const [ balanceHistory, setBalanceHistory ] = useState();
Expand Down
4 changes: 2 additions & 2 deletions src/dashboard/credit-card-bills.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataGrid } from '@mui/x-data-grid';
import { formatDecimal, formatNumber, formatMonth } from '../util/formatters';
import { HorizontalLoader } from '../core/loader';
import { HorizontalLoader } from '../core/utils';
import { useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { useTheme } from '@mui/material/styles';
Expand All @@ -9,7 +9,7 @@ import api from '../core/api';
import dayjs from 'dayjs';
import state from '../core/state';
import styled from 'styled-components';
import Title from '../core/title';
import { Title } from '../core/utils';
import useMediaQuery from '@mui/material/useMediaQuery';

const Root = styled.div`
Expand Down
4 changes: 2 additions & 2 deletions src/dashboard/insights.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BarChart } from '@mui/x-charts';
import { DataGrid } from '@mui/x-data-grid';
import { formatDecimal, formatNumber } from '../util/formatters';
import { HorizontalLoader } from '../core/loader';
import { HorizontalLoader } from '../core/utils';
import { pink, lightGreen } from '@mui/material/colors';
import { Routes, Route, Navigate, Link, useLocation, useNavigate } from 'react-router-dom';
import { useEffect, useState } from 'react';
Expand All @@ -17,7 +17,7 @@ import styled from 'styled-components';
import Switch from '@mui/material/Switch';
import Tab from '@mui/material/Tab';
import Tabs from '@mui/material/Tabs';
import Title from '../core/title';
import { Title } from '../core/utils';
import useMediaQuery from '@mui/material/useMediaQuery';

const Root = styled.div`
Expand Down
10 changes: 7 additions & 3 deletions src/dashboard/summary.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { formatDecimal } from '../util/formatters';
import { HorizontalLoader } from '../core/loader';
import { HorizontalLoader } from '../core/utils';
import { useEffect, useState, Fragment } from 'react';
import { useNavigate } from 'react-router-dom';
import { useTheme } from '@mui/material/styles';
import Alert from '@mui/material/Alert';
import Chip from '@mui/material/Chip';
import state from '../core/state';
import styled from 'styled-components';
import SubTitle from '../core/sub-title';
import Title from '../core/title';
import { SubTitle } from '../core/utils';
import { Title } from '../core/utils';

const Wrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -247,6 +247,10 @@ const Summary = ({ setRoute }) => {
</Alert>
);

if (!accounts) {
return <HorizontalLoader />;
}

return !accounts.find((a) => a.visible) ? <Empty /> : (
<Root theme={theme}>
<Title>Summary</Title>
Expand Down
2 changes: 1 addition & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CssBaseline from '@mui/material/CssBaseline';
import { BrowserRouter } from 'react-router-dom';
import { CircularLoader } from './core/loader';
import { CircularLoader } from './core/utils';
import { createRoot } from 'react-dom/client';
import { RecoilRoot } from 'recoil';
import { registerSW } from 'virtual:pwa-register';
Expand Down
2 changes: 1 addition & 1 deletion src/nav-bar/main-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const NavBar = () => {
];
const props = { pages, currentPath: location.pathname };

return (
return location.pathname !== '/no-connectivity' && (
<AppBar theme={theme}>
<Group>
<MobileMenu {...props} />
Expand Down
2 changes: 1 addition & 1 deletion src/public/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import LoginIcon from '@mui/icons-material/Login';
import Stack from '@mui/material/Stack';
import state from '../core/state';
import TextField from '@mui/material/TextField';
import Title from '../core/title';
import { Title } from '../core/utils';

const Login = () => {
let navigate = useNavigate();
Expand Down
3 changes: 2 additions & 1 deletion src/public/public.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NoConnectivity, NotFound } from '../core/utils';
import { Routes, Route, Navigate } from 'react-router-dom';
import Box from '@mui/material/Box';
import Container from '@mui/material/Container';
import Login from './login';
import NotFound from '../core/not-found';
import Register from './register';
import styled from 'styled-components';

Expand All @@ -19,6 +19,7 @@ const Public = () => (
<Routes>
<Route path="register" element={<Register /> } />
<Route path="login" element={<Login /> } />
<Route path="no-connectivity" element={<NoConnectivity />} />
<Route path="/" element={<Navigate to="/login" />} />
<Route path="*" element={<NotFound />} />
</Routes>
Expand Down
2 changes: 1 addition & 1 deletion src/public/register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import LoadingButton from '@mui/lab/LoadingButton';
import Stack from '@mui/material/Stack';
import state from '../core/state';
import TextField from '@mui/material/TextField';
import Title from '../core/title';
import { Title } from '../core/utils';

const Register = () => {
let navigate = useNavigate();
Expand Down
5 changes: 5 additions & 0 deletions src/settings/accounts-grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Chip from '@mui/material/Chip';
import styled from 'styled-components';
import Switch from '@mui/material/Switch';
import VisibilityIcon from '@mui/icons-material/Visibility';
import { HorizontalLoader } from '../core/utils';

const GridBox = styled.div`
display: flex;
Expand Down Expand Up @@ -161,6 +162,10 @@ const AccountsGrid = ({
setSelectedAccount(selection);
};

if (!accounts) {
return <HorizontalLoader />;
}

return accounts.length === 0 ? <Empty /> : (
<GridBox isMobile={isMobile}>
{ accounts.filter(a => a.visible).length === 0 && <NoVisible /> }
Expand Down
2 changes: 1 addition & 1 deletion src/settings/accounts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
import AccountsGrid from './accounts-grid';
import Stack from '@mui/material/Stack';
import state from '../core/state';
import Title from '../core/title';
import { Title } from '../core/utils';
import AccountsActionButtons from './accounts-action-buttons';

const Accounts = ({ isMobile, setRoute }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/settings/profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import LoadingButton from '@mui/lab/LoadingButton';
import Stack from '@mui/material/Stack';
import state from '../core/state';
import TextField from '@mui/material/TextField';
import Title from '../core/title';
import { Title } from '../core/utils';
import Tooltip from '@mui/material/Tooltip';

const Profile = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/settings/templates.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createFilterOptions } from '@mui/material/Autocomplete';
import { DataGrid, useGridApiRef, useGridApiContext, gridPageCountSelector } from '@mui/x-data-grid';
import { HorizontalLoader } from '../core/loader';
import { HorizontalLoader } from '../core/utils';
import { useState, useEffect, useLayoutEffect, useRef } from 'react';
import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline';
import api from '../core/api';
Expand All @@ -13,7 +13,7 @@ import Stack from '@mui/material/Stack';
import state from '../core/state';
import styled from 'styled-components';
import TextField from '@mui/material/TextField';
import Title from '../core/title';
import { Title } from '../core/utils';

const GridBox = styled.div`
flex: 1 1 1px;
Expand Down
2 changes: 1 addition & 1 deletion src/transactions/transactions-grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../util/formatters';
import { cpfCodes } from '../util/cpf-codes';
import { GridPagination } from '@mui/x-data-grid';
import { HorizontalLoader } from '../core/loader';
import { HorizontalLoader } from '../core/utils';
import { pink, lightGreen } from '@mui/material/colors';
import { useEffect, useState } from 'react';
import { useTheme } from '@mui/material/styles';
Expand Down
2 changes: 1 addition & 1 deletion src/transactions/transactions-import.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CircularLoader } from '../core/loader';
import { CircularLoader } from '../core/utils';
import { useGridApiRef } from '@mui/x-data-grid';
import { useState } from 'react';
import api from '../core/api';
Expand Down
Loading

0 comments on commit 122a127

Please sign in to comment.