Skip to content

Commit

Permalink
Add propTypes to Form.js
Browse files Browse the repository at this point in the history
Update prettier to 2.7.1.
Force Prettier to ignore parts of some files and allow it uglify others.
  • Loading branch information
fwextensions committed Aug 2, 2022
1 parent e408ac1 commit a844544
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.1.0",
"prettier": "2.1.1"
"prettier": "2.7.1"
}
}
32 changes: 22 additions & 10 deletions src/Components/Form.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
import React, { useMemo, useContext, createContext } from 'react';
import PropTypes from 'prop-types';

const FormContext = createContext(undefined);

const Form = ({ data, onChange, children, ...props }) => {
const context = useMemo(() => ({
data,
onChange
}), [data, onChange]);
const context = useMemo(
() => ({
data,
onChange,
}),
[data, onChange]
);

// we spread the extra props on the form so the caller can apply classes and other properties to
// the form element
return (
<FormContext.Provider value={context}>
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<form {...props}>
{children}
</form>
<form {...props}>{children}</form>
</FormContext.Provider>
);
};

Form.propTypes = {
// eslint-disable-next-line react/forbid-prop-types
data: PropTypes.object.isRequired,
onChange: PropTypes.func,
children: Promise.node,
};

Form.defaultProps = {
onChange: null,
children: null,
};

const useForm = () => {
const context = useContext(FormContext);

Expand All @@ -32,6 +46,4 @@ const useForm = () => {

export default Form;

export {
useForm,
};
export { useForm };
5 changes: 3 additions & 2 deletions src/Components/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FormInput from './FormInput';
import FormTextArea from './FormTextArea';
import { useForm } from './Form';

// prettier-ignore
export default function FormField({ metadata, ...props }) {
const { data, onChange } = useForm();
const { name: property, type, label, required } = metadata;
Expand All @@ -16,10 +17,10 @@ export default function FormField({ metadata, ...props }) {
value,
required,
onChange,
validationState: data.getValidationState(property)
validationState: data.getValidationState(property),
};

switch (type) {
switch (type) {
case 'integer':
case 'decimal': {
const { unit = metadata.unit, range = metadata.range, size = 'small' } = props;
Expand Down
6 changes: 2 additions & 4 deletions src/EMS/PatientFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ const Patient = patient.getFieldHash();

function createOptions(ids) {
return ids.map((id) => (
<option
key={id}
value={id}
>
<option key={id} value={id}>
{id}
</option>
));
}

// prettier-ignore
function PatientFields({ ringdown, onChange }) {
const [ambulanceIds, setAmbulanceIds] = useState([]);
const [dispatchCallNumbers, setDispatchCallNumbers] = useState([]);
Expand Down
3 changes: 2 additions & 1 deletion src/EMS/RingdownForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import Spinner from '../Components/Spinner';
import RingdownCard from '../Components/RingdownCard';
import Heading from '../Components/Heading';
import Alert from '../Components/Alert';
import Form from '../Components/Form';
import HospitalSelection from './HospitalSelection';
import PatientFields from './PatientFields';
import RingdownStatus from './RingdownStatus';
import Form from '../Components/Form';

function RingdownForm({ className }) {
const { ringdowns, setRingdowns } = useContext(Context);
Expand Down Expand Up @@ -94,6 +94,7 @@ function RingdownForm({ className }) {
setRingdowns([...ringdowns]);
}

// prettier-ignore
return (
<>
{ringdowns && ringdowns.length === 0 && (
Expand Down
2 changes: 1 addition & 1 deletion src/metadata/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const fields = [
{
name: 'treatmentNotes',
type: 'text',
label: 'Treatments Administered'
label: 'Treatments Administered',
},
{
name: 'etohSuspectedIndicator',
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10174,10 +10174,10 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"

prettier@2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.1.tgz#d9485dd5e499daa6cb547023b87a6cf51bee37d6"
integrity sha512-9bY+5ZWCfqj3ghYBLxApy2zf6m+NJo5GzmLTpr9FsApsfjriNnS2dahWReHMi7qNPhhHl9SYHJs2cHZLgexNIw==
prettier@2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==

pretty-bytes@^5.1.0:
version "5.3.0"
Expand Down

0 comments on commit a844544

Please sign in to comment.