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

Waitp 1201 basic web layout #4620

Merged
merged 23 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
27 changes: 27 additions & 0 deletions packages/tupaia-web/.storybook/ReactRouterDecorator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { useEffect } from 'react';
import { action } from '@storybook/addon-actions';
import { BrowserRouter, useLocation } from 'react-router-dom';
import { Args } from '@storybook/react';
import { DecoratorFunction } from '@storybook/csf';

const LocationChangeAction = ({ children }) => {
const location = useLocation();

useEffect(() => {
if (location.key !== 'default') action('React Router Location Change')(location);
}, [location]);

return <>{children}</>;
};

const ReactRouterDecorator: DecoratorFunction<any, Args> = (Story, context) => {
return (
<BrowserRouter>
<LocationChangeAction>
<Story {...context} />
</LocationChangeAction>
</BrowserRouter>
);
};

export default ReactRouterDecorator;
2 changes: 1 addition & 1 deletion packages/tupaia-web/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StorybookConfig } from '@storybook/react-vite';
const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
Expand Down
8 changes: 4 additions & 4 deletions packages/tupaia-web/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from 'react';
import type { Preview } from '@storybook/react';
import { AppStyleProviders } from '../src/AppStyleProviders';
import { DARK_BLUE, WHITE } from '../src/theme';

import ReactRouterDecorator from './ReactRouterDecorator';
const preview: Preview = {
parameters: {
backgrounds: {
default: 'Dark',
values: [
{ name: 'Dark', value: DARK_BLUE },
{ name: 'Light', value: WHITE },
{ name: 'Dark', value: '#135D8F' },
{ name: 'Light', value: '#ffffff' },
],
},
actions: { argTypesRegex: '^on[A-Z].*' },
Expand All @@ -21,6 +20,7 @@ const preview: Preview = {
},
},
decorators: [
ReactRouterDecorator,
Story => {
return (
<AppStyleProviders>
Expand Down
2 changes: 1 addition & 1 deletion packages/tupaia-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router": "6.3.0",
"react-router-dom": "6.3.0",
"react-router-dom": "6.3.0",
"styled-components": "^5.1.0",
"vite-plugin-ejs": "^1.6.4",
"vite-plugin-env-compatible": "^1.1.1"
Expand Down
12 changes: 12 additions & 0 deletions packages/tupaia-web/public/images/tupaia-logo-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions packages/tupaia-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
*/
import React from 'react';
import { AppStyleProviders } from './AppStyleProviders';
import { Router } from './Router';
import { Routes } from './Routes';
import { Layout } from './layout';
import { BrowserRouter } from 'react-router-dom';

const App = () => {
return (
<AppStyleProviders>
<Router />
<BrowserRouter>
{/** The Layout component needs to be inside BrowserRouter so that Link component from react-router-dom can be used (in menu etc.) */}
<Layout>
<Routes />
</Layout>
</BrowserRouter>
</AppStyleProviders>
);
};
Expand Down
23 changes: 2 additions & 21 deletions packages/tupaia-web/src/AppStyleProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,10 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
import React, { ReactNode } from 'react';
import {
StylesProvider,
createMuiTheme,
ThemeProvider as MuiThemeProvider,
} from '@material-ui/core/styles';
import { ThemeProvider as MuiThemeProvider, StylesProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import { ThemeProvider } from 'styled-components';

// Base theme overrides. Any extra overrides should be added here, as needed.
const theme = createMuiTheme({
palette: {
type: 'dark',
primary: {
main: '#0296c5', // Main blue (as seen on primary buttons)
},
secondary: {
main: '##ee6230', // Tupaia Orange
},
background: {
default: '#262834', // Dark blue background
},
},
});
import { theme } from './theme';

export const AppStyleProviders = ({ children }: { children: ReactNode }) => (
<StylesProvider injectFirst>
Expand Down
41 changes: 0 additions & 41 deletions packages/tupaia-web/src/Router.tsx

This file was deleted.

36 changes: 36 additions & 0 deletions packages/tupaia-web/src/Routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
tcaiger marked this conversation as resolved.
Show resolved Hide resolved
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
import React from 'react';
import { Navigate, Route, Routes as RouterRoutes } from 'react-router-dom';
import {
LandingPage,
LoginForm,
PasswordResetForm,
Project,
RegisterForm,
RequestAccessForm,
VerifyEmailForm,
} from './pages';
import { DEFAULT_URL } from './constants';

/**
* This Router is using [version 6.3]{@link https://reactrouter.com/en/v6.3.0}, as later versions are not supported by our TS setup. See [this issue here]{@link https://github.com/remix-run/react-router/discussions/8364}
* This means the newer 'createBrowserRouter' and 'RouterProvider' can't be used here.
*
* **/

export const Routes = () => (
<RouterRoutes>
<Route path="/" element={<Navigate to={`/${DEFAULT_URL}`} replace />} />
<Route path="login" element={<LoginForm />} />
<Route path="register" element={<RegisterForm />} />
<Route path="reset-password" element={<PasswordResetForm />} />
<Route path="request-access" element={<RequestAccessForm />} />
<Route path="verify-email" element={<VerifyEmailForm />} />
<Route path="/:landingPageUrlSegment" element={<LandingPage />} />
{/** Because react-router v 6.3 doesn't support optional url segments, we need to handle dashboardCode with a splat/catch-all instead */}
<Route path="/:projectCode/:entityCode/*" element={<Project />} />
</RouterRoutes>
);
61 changes: 61 additions & 0 deletions packages/tupaia-web/src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
import React, { ReactNode } from 'react';
import { Dialog, Paper as MuiPaper, useTheme, useMediaQuery } from '@material-ui/core';
import MuiCloseIcon from '@material-ui/icons/Close';
import styled from 'styled-components';
import { IconButton } from '@tupaia/ui-components';

interface ModalProps {
children?: ReactNode;
onClose: () => void;
isOpen: boolean;
}

const Wrapper = styled.div`
text-align: center;
overflow-x: hidden;
padding: 2em;
`;

const CloseIcon = styled(MuiCloseIcon)`
width: 1.2em;
height: 1.2em;
`;

const CloseButton = styled(IconButton)`
background-color: transparent;
min-width: initial;
position: absolute;
top: 0.6em;
right: 0.6em;
`;

const Paper = styled(MuiPaper)`
background-color: ${({ theme }) => theme.palette.background.default};
padding: 0;
color: rgba(255, 255, 255, 0.9);
overflow-y: auto;
max-width: 920px;
min-width: 300px;
// Prevent width from animating.
transition: transform 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
`;

export const Modal = ({ children, isOpen, onClose }: ModalProps) => {
// make the modal full screen at small screen sizes
const theme = useTheme();
const fullScreen = useMediaQuery(theme.breakpoints.down('xs'));
return (
<Dialog open={isOpen} onClose={onClose} PaperComponent={Paper} fullScreen={fullScreen}>
<Wrapper id="overlay-wrapper">
<CloseButton onClick={onClose} color="default">
<CloseIcon />
</CloseButton>
{children}
</Wrapper>
</Dialog>
);
};
1 change: 1 addition & 0 deletions packages/tupaia-web/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
export { Modal } from './Modal';
5 changes: 5 additions & 0 deletions packages/tupaia-web/src/constants/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/
export const TRANSPARENT_BLACK = 'rgba(43, 45, 56, 0.94)';
2 changes: 2 additions & 0 deletions packages/tupaia-web/src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
export const DEFAULT_PROJECT_CODE = 'explore';
export const DEFAULT_ENTITY_CODE = 'explore';
export const DEFAULT_URL = `${DEFAULT_PROJECT_CODE}/${DEFAULT_ENTITY_CODE}`;

export const TUPAIA_LIGHT_LOGO_SRC = '/images/tupaia-logo-light.svg';
1 change: 1 addition & 0 deletions packages/tupaia-web/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
export * from './colors';
export * from './constants';
Loading