Skip to content

Commit

Permalink
Big bang
Browse files Browse the repository at this point in the history
Big bang bang
  • Loading branch information
TuukkaP authored and Tuukka Peuraniemi committed Feb 21, 2020
1 parent 85a8459 commit e680211
Show file tree
Hide file tree
Showing 22 changed files with 16,619 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# fsopen-frontend
Base for the version for students to clone
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm build`

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
16,017 changes: 16,017 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "diagnosis-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.19.0",
"formik": "^2.0.6",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-router-dom": "^5.1.2",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.88.1"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/jest": "24.0.19",
"@types/node": "12.11.7",
"@types/react": "^16.9.11",
"@types/react-dom": "16.9.3",
"@types/react-router-dom": "^5.1.2",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"eslint-config-prettier": "^6.7.0",
"eslint-config-react": "^1.1.7",
"eslint-plugin-prettier": "^3.1.2",
"prettier": "^1.19.1",
"react-scripts": "3.3.0",
"typescript": "^3.7.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint './src/**/*.{ts,tsx}'",
"lint:fix": "eslint './src/**/*.{ts,tsx}' --fix"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added public/favicon.ico
Binary file not shown.
42 changes: 42 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Diagnosis app</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
8 changes: 8 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
83 changes: 83 additions & 0 deletions src/AddPatientModal/AddPatientForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react';
import { Grid, Button } from 'semantic-ui-react';
import { Formik, Form } from 'formik';

import { TextField, SelectField, Option } from './FormField';
import { Gender, Patient } from '../types';

/*
* use type Patient, but omit id and entries,
* because those are irrelevant for new patient object.
*/
export type FormValues = Omit<Patient, 'id' | 'entries'>;

interface Props {
onSubmit: (values: FormValues) => void;
onCancel: () => void;
}

const genderOptions: Option<Gender>[] = [
{ value: Gender.Male, label: 'Male' },
{ value: Gender.Female, label: 'Female' },
{ value: Gender.Other, label: 'Other' },
];

export const AddPatientForm: React.FC<Props> = ({ onSubmit, onCancel }) => {
return (
<Formik
initialValues={{
name: '',
ssn: '',
dateOfBirth: '',
occupation: '',
gender: Gender.Other,
}}
onSubmit={values => {
onSubmit(values);
}}
>
{() => (
<Form className="form ui">
<TextField label="Name" name="name" placeholder="Name" />
<TextField
label="Social Security Number"
name="ssn"
placeholder="SSN"
component={TextField}
/>
<TextField
label="Date Of Birth"
name="dateOfBirth"
placeholder="YYYY-MM-DD"
component={TextField}
/>
<TextField
label="Occupation"
name="occupation"
placeholder="Occupation"
/>
<SelectField<string>
label="Gender"
name="gender"
defaultValue=""
options={genderOptions}
/>
<Grid>
<Grid.Column floated="left" width={5}>
<Button type="button" onClick={onCancel} color="red">
Cancel
</Button>
</Grid.Column>
<Grid.Column floated="right" width={5}>
<Button type="submit" floated="right" color="green">
Add
</Button>
</Grid.Column>
</Grid>
</Form>
)}
</Formik>
);
};

export default AddPatientForm;
55 changes: 55 additions & 0 deletions src/AddPatientModal/FormField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { Field, FieldProps } from 'formik';
import { Input, InputProps, Form } from 'semantic-ui-react';

// Describe what types of options are allowed
type OptionValue = string | number;

// structure of a single option (generic - type of value is inferred from T)
export type Option<T extends OptionValue> = {
value: T;
label?: string;
};

// props for select field component
interface SelectFieldProps<T extends OptionValue> {
name: string;
label?: string;
options: Option<T>[]; // array of option generic type
defaultValue?: T;
}

export const SelectField = <T extends OptionValue>({
name,
label,
options,
defaultValue,
}: SelectFieldProps<T>) => (
<Form.Field>
{label && <label>{label}</label>}
<Field as="select" name={name} className="ui dropdown">
{!defaultValue && <option value={defaultValue}>{defaultValue}</option>}
{options.map(option => (
<option key={option.value} value={option.value}>
{option.label || option.value}
</option>
))}
</Field>
</Form.Field>
);

const TextInput: React.FC<FieldProps & InputProps> = ({
placeholder,
field,
}) => <Input placeholder={placeholder} {...field} />;

export const TextField: React.FC<InputProps & { label?: string }> = ({
name,
label,
placeholder,
}) => (
<Form.Field>
{label && <label>{label}</label>}
<Field name={name} placeholder={placeholder} component={TextInput} />
</Form.Field>
);
22 changes: 22 additions & 0 deletions src/AddPatientModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { Modal, Segment } from 'semantic-ui-react';
import AddPatientForm, { FormValues } from './AddPatientForm';

interface Props {
modalOpen: boolean;
onClose: () => void;
onSubmit: (values: FormValues) => void;
error?: string;
}

const AddPatientModal = ({ modalOpen, onClose, onSubmit, error }: Props) => (
<Modal open={modalOpen} onClose={onClose} centered={false} closeIcon>
<Modal.Header>Add a new patient</Modal.Header>
<Modal.Content>
{error && <Segment inverted color="red">{`Error: ${error}`}</Segment>}
<AddPatientForm onSubmit={onSubmit} onCancel={onClose} />
</Modal.Content>
</Modal>
);

export default AddPatientModal;
27 changes: 27 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
import { Button, Divider, Header, Container } from "semantic-ui-react";

import PatientListPage from "./PatientListPage";
import { reducer, StateProvider } from "./state";

const App: React.FC = () => {
return (
<StateProvider reducer={reducer}>
<div className="App">
<Router>
<Container>
<Header as="h1">Poor mans online electronic medical record</Header>
<Button as={Link} to="/" primary>
Home
</Button>
<Divider hidden />
<Route exact path="/" render={() => <PatientListPage />} />
</Container>
</Router>
</div>
</StateProvider>
);
};

export default App;
Loading

0 comments on commit e680211

Please sign in to comment.