-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zeke/dev/typescript conversion (#64)
## Problem On the web side, the app uses React but is implemented using Javascript. It is recommended to use Typescript instead. ## Solution * Convert web app to Typescript. * Modify web project files to use Typescript, added TS configs, and removed old and conflicting project files. * Renamed `.js` files to `.ts` or `.tsx` as needed. * Refactored Javascript code to Typescript/JSX compliant. * Created interfaces as necessary. * Factored out some code in large components and pages ## Ticket URL https://mediform.atlassian.net/browse/MEDI-17 ## Documentation N/A ## Tests Run * Tested locally. Rebuilt `web` image and container from scratch * Manually tested web application - Login - Create a new patient encounter form - Search PE forms - View existing PE - Update existing PEs - Delete PEs
- Loading branch information
Showing
54 changed files
with
1,061 additions
and
5,579 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as React from 'react'; | ||
import Typography, { TypographyProps } from '@mui/material/Typography'; | ||
|
||
|
||
/** | ||
* This component is used to display the copy right information in the footer | ||
* | ||
* @param props The properties of the component | ||
* | ||
* @returns The JSX element for the component | ||
*/ | ||
export function Copyright(props: TypographyProps) { | ||
return ( | ||
<Typography variant="body2" color="text.secondary" align="center" {...props}> | ||
{'Copyright © '} | ||
{new Date().getFullYear()} | ||
{'.'} | ||
</Typography> | ||
); | ||
} |
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,126 @@ | ||
import React, { useState } from "react"; | ||
import Link from "next/link"; | ||
import AppBar from "@mui/material/AppBar"; | ||
import Box from "@mui/material/Box"; | ||
import Divider from "@mui/material/Divider"; | ||
import Drawer from "@mui/material/Drawer"; | ||
import IconButton from "@mui/material/IconButton"; | ||
import List from "@mui/material/List"; | ||
import ListItem from "@mui/material/ListItem"; | ||
import ListItemButton from "@mui/material/ListItemButton"; | ||
import ListItemText from "@mui/material/ListItemText"; | ||
import MenuIcon from "@mui/icons-material/Menu"; | ||
import Toolbar from "@mui/material/Toolbar"; | ||
import Typography from "@mui/material/Typography"; | ||
import Button from "@mui/material/Button"; | ||
|
||
/** | ||
* Renders a navbar for the protected routes. | ||
* | ||
* @returns JSX element representing the navbar. | ||
*/ | ||
const ProtectedNavbar: React.FC = () => { | ||
const [mobileOpen, setMobileOpen] = useState(false); | ||
|
||
const drawerWidth = 240; | ||
|
||
const handleDrawerToggle = () => { | ||
setMobileOpen(!mobileOpen); | ||
}; | ||
|
||
const logout = () => { | ||
window.localStorage.removeItem("auth-token"); | ||
window.location.pathname = "/"; | ||
}; | ||
|
||
const drawer = ( | ||
<Box onClick={handleDrawerToggle} sx={{ textAlign: "center" }}> | ||
<Typography variant="h6" sx={{ my: 2 }}> | ||
MUI | ||
</Typography> | ||
<Divider /> | ||
<List> | ||
<ListItem key="New Entry" disablePadding> | ||
<ListItemButton href="/forms/form" sx={{ textAlign: "center" }}> | ||
<ListItemText primary="New Entry" /> | ||
</ListItemButton> | ||
</ListItem> | ||
<ListItemButton onClick={logout} sx={{ textAlign: "center" }}> | ||
<ListItemText primary="Logout" /> | ||
</ListItemButton> | ||
</List> | ||
</Box> | ||
); | ||
|
||
return ( | ||
<> | ||
<Box sx={{ display: "flex", pb: "60px" }}> | ||
<AppBar component="nav"> | ||
<Toolbar> | ||
<IconButton | ||
color="inherit" | ||
aria-label="open drawer" | ||
edge="start" | ||
onClick={handleDrawerToggle} | ||
sx={{ mr: 2, display: { sm: "none" } }} | ||
> | ||
<MenuIcon /> | ||
</IconButton> | ||
<Typography | ||
variant="h6" | ||
component="div" | ||
sx={{ | ||
flexGrow: 1, | ||
display: { xs: "none", sm: "block", fontWeight: "bold" }, | ||
}} | ||
> | ||
<Link href="/home">Home</Link> | ||
</Typography> | ||
<Box sx={{ display: { xs: "none", sm: "block" } }}> | ||
<Button | ||
href="/search/encounters" | ||
sx={{ color: "#fff", fontWeight: "bold" }} | ||
> | ||
List Entries | ||
</Button> | ||
<Button | ||
href="/forms/form" | ||
sx={{ color: "#fff", fontWeight: "bold" }} | ||
> | ||
New Entry | ||
</Button> | ||
<Button | ||
key="logout" | ||
sx={{ color: "#fff", fontWeight: "bold" }} | ||
onClick={logout} | ||
> | ||
Logout | ||
</Button> | ||
</Box> | ||
</Toolbar> | ||
</AppBar> | ||
<Box component="nav"> | ||
<Drawer | ||
variant="temporary" | ||
open={mobileOpen} | ||
onClose={handleDrawerToggle} | ||
ModalProps={{ | ||
keepMounted: true, // Better open performance on mobile. | ||
}} | ||
sx={{ | ||
display: { xs: "block", sm: "none" }, | ||
"& .MuiDrawer-paper": { | ||
boxSizing: "border-box", | ||
width: drawerWidth, | ||
}, | ||
}} | ||
> | ||
{drawer} | ||
</Drawer> | ||
</Box> | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
export default ProtectedNavbar; |
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,25 @@ | ||
import React from "react"; | ||
import { Alert } from "@mui/material"; | ||
import { FieldErrors, FieldError } from "react-hook-form"; | ||
|
||
export function RenderErrorAlerts(errors: FieldErrors<any>) { | ||
return ( | ||
<> | ||
{Object.entries(errors).map(([fieldName, error], index) => { | ||
if (error && (error as FieldError).message) { | ||
return ( | ||
<Alert | ||
severity="error" | ||
key={index} | ||
sx={{ mt: 1 }} | ||
variant="filled" | ||
> | ||
{error.message as React.ReactNode} | ||
</Alert> | ||
); | ||
} | ||
return null; | ||
})} | ||
</> | ||
); | ||
} |
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,25 @@ | ||
import React from "react"; | ||
import { Alert } from "@mui/material"; | ||
import { AlertObject } from "../interfaces/AlertObject"; | ||
|
||
/** | ||
* Renders a submit alert based on the provided alert object. | ||
* | ||
* @param alert - Alert object containing the type and message of the alert. | ||
* | ||
* @returns JSX element representing the submit alert, or null if no alert is provided. | ||
*/ | ||
|
||
export function RenderSubmitAlert( | ||
alert: AlertObject | null | ||
): JSX.Element | null { | ||
|
||
if (alert) { | ||
return ( | ||
<Alert severity={alert.type} sx={{ mt: 2 }} variant="filled"> | ||
{alert.message} | ||
</Alert> | ||
); | ||
} | ||
return null; | ||
} |
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,9 @@ | ||
import React from "react"; | ||
import Slide from "@mui/material/Slide"; | ||
|
||
export const SlideTransition = React.forwardRef(function Transition( | ||
props: any, | ||
ref: React.Ref<unknown> | ||
) { | ||
return <Slide direction="up" ref={ref} {...props} />; | ||
}); |
9 changes: 5 additions & 4 deletions
9
...nents/patient_encounter_form/age_field.js → ...nents/patient_encounter_form/AgeField.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
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
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
Oops, something went wrong.