Skip to content

Commit

Permalink
➰ Yet even more TypeScript conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNerd committed Sep 25, 2020
1 parent a6f86ab commit 2e9c1f0
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 32 deletions.
24 changes: 21 additions & 3 deletions src/components/ListGroups/MedicineListGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TooltipButton from "../Buttons/TooltipButton";
import PropTypes from 'prop-types';
import {drawBarcode} from "../../utility/drawBarcode";
import Button from "react-bootstrap/Button";
import logButtonColor from "../../utility/logButtonColor";

/**
* MedicineListGroup
Expand Down Expand Up @@ -42,6 +43,23 @@ const MedicineListGroup = (props) => {
}
}, [barCode, canvasId, canvasUpdated]);

/**
* Determine the tooltip text given the number of hours the drug was last taken
*
* @param {number | null | boolean} lastTaken
* @returns {string|null}
*/
const tooltipText = (lastTaken) => {
if (lastTaken === null || lastTaken === false) return null;
if (lastTaken <= 1) {
return activeDrug.Drug + " taken in the last hour";
}
if (lastTaken <=4) {
return activeDrug.Drug + " recently taken";
}
return null;
}

return (
<ListGroup>
<ListGroup.Item active>
Expand All @@ -54,18 +72,18 @@ const MedicineListGroup = (props) => {

<ListGroup.Item>
<TooltipButton
tooltip={lastTaken <= 1 && lastTaken !== null ? activeDrug.Drug + " taken in the last hour" : null}
tooltip={tooltipText(lastTaken)}
placement="top"
className="mr-2"
variant={lastTaken === 0 ? "warning" : "primary"}
variant={logButtonColor(lastTaken)}
onClick={(e) => addDrugLog(e)}
>
+ Log Drug
</TooltipButton>

<Button
disabled={lastTaken === 0}
variant="outline-primary"
variant={"outline-" + logButtonColor(lastTaken)}
onClick={(e) => {
e.preventDefault();
logDrug(1);
Expand Down
2 changes: 1 addition & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'reactn';
import {ResidentRecord} from "./utility/InitialState";
import {ResidentRecord} from "./types/RecordTypes";

declare module 'reactn/default' {

Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ReactDOM from 'react-dom';
import React, {setGlobal} from "reactn";
import App from './App';
import {initialState} from "./utility/InitialState";
import {initialState} from "./utility/initialState";

setGlobal(initialState)
.then((initialState) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/LoginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Row from 'react-bootstrap/Row';
import TabContent from '../styles/tab_content.css';
import ResidentProvider from '../providers/ResidentProvider';
import MedicineProvider from '../providers/MedicineProvider';
import {initialState} from "../utility/InitialState";
import {initialState} from "../utility/initialState";
import MedHistoryProvider from "../providers/MedHistoryProvider";
import Frak from "../providers/Frak";
import RefreshOtcList from "../providers/helpers/RefreshOtcList";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ManageDrugPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import RefreshMedicineList from "../providers/RefreshMedicineList";
import DeleteMedicine from "../providers/helpers/DeleteMedicine";
import TooltipButton from "../components/Buttons/TooltipButton";
import PropTypes from 'prop-types';
import {handleMedicineEditModalClose} from "../utility/helpers";
import {handleMedicineEditModalClose} from "../utility/handleMedicineEditModalClose";

/**
* ManageDrugPage
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ManageOtcPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DeleteMedicine from "../providers/helpers/DeleteMedicine";
import TooltipButton from "../components/Buttons/TooltipButton";
import RefreshOtcList from "../providers/helpers/RefreshOtcList";
import PropTypes from 'prop-types';
import {handleMedicineEditModalClose} from "../utility/helpers";
import {handleMedicineEditModalClose} from "../utility/handleMedicineEditModalClose";

/**
* ManageOtcPage
Expand Down
7 changes: 4 additions & 3 deletions src/pages/MedicinePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import RefreshMedicineLog from "../providers/RefreshMedicineLog";
import MedicineListGroup from "../components/ListGroups/MedicineListGroup";
import TooltipButton from "../components/Buttons/TooltipButton";
import {calculateLastTaken} from "../utility/common";
import {newDrugInfo} from "../utility/InitialState";
import {newDrugInfo} from "../types/RecordTypes";
import PropTypes from 'prop-types';
import LastTakenButton from "../components/Buttons/LastTakenButton";
import searchDrugs from "../utility/searchDrugs";
import isSearchValid from "../utility/isSearchValid";
import logButtonColor from "../utility/logButtonColor";

/**
* MedicinePage
Expand Down Expand Up @@ -273,7 +274,7 @@ const MedicinePage = (props) => {
<span style={{textAlign: "center"}}> <h2>{activeDrug.Drug} History</h2> </span>
<Button
disabled={lastTaken === 0}
variant="outline-primary"
variant={"outline-" + logButtonColor(lastTaken)}
className="mr-2"
onClick={(e) => {
e.preventDefault();
Expand All @@ -286,7 +287,7 @@ const MedicinePage = (props) => {
<Button
disabled={lastTaken === 0}
className="mr-3"
variant="outline-primary"
variant={"outline-" + logButtonColor(lastTaken)}
onClick={(e) => {
e.preventDefault();
handleLogDrugAmount(2);
Expand Down
7 changes: 4 additions & 3 deletions src/pages/OtcPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import RefreshMedicineLog from "../providers/RefreshMedicineLog";
import MedicineListGroup from "../components/ListGroups/MedicineListGroup";
import RefreshOtcList from "../providers/helpers/RefreshOtcList";
import {calculateLastTaken} from "../utility/common";
import {newDrugInfo} from "../utility/InitialState";
import {newDrugInfo} from "../types/RecordTypes";
import PropTypes from 'prop-types';
import LastTakenButton from "../components/Buttons/LastTakenButton";
import searchDrugs from "../utility/searchDrugs";
import isSearchValid from "../utility/isSearchValid";
import logButtonColor from "../utility/logButtonColor";

/**
* OtcPage
Expand Down Expand Up @@ -280,7 +281,7 @@ const OtcPage = (props) => {
<span style={{textAlign: "center"}}> <h2>OTC Drug History</h2> </span>
<Button
disabled={lastTaken === 0}
variant="outline-primary"
variant={"outline-" + logButtonColor(lastTaken)}
className="mr-2"
onClick={(e) => {
e.preventDefault();
Expand All @@ -293,7 +294,7 @@ const OtcPage = (props) => {
<Button
disabled={lastTaken === 0}
className="mr-3"
variant="outline-primary"
variant={"outline-" + logButtonColor(lastTaken)}
onClick={(e) => {
e.preventDefault();
handleLogDrugAmount(2);
Expand Down
16 changes: 0 additions & 16 deletions src/utility/InitialState.tsx → src/types/RecordTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ export type DrugLogRecord = {
Updated: Date
}

export const initialState = {
development: process.env.REACT_APP_DEVELOPMENT === 'true',
activeResident: null,
residentList: null,
medicineList: null,
otcList: null,
drugLogList: null,
apiKey: null,
baseUrl: process.env.REACT_APP_BASEURL,
providers: {
residentProvider: null,
medicineProvider: null,
medHistoryProvider: null
}
};

export const newDrugInfo = {
Id: null,
Barcode: "",
Expand Down
2 changes: 1 addition & 1 deletion src/utility/common.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {DrugLogRecord, ResidentRecord} from "./InitialState";
import {DrugLogRecord, ResidentRecord} from "../types/RecordTypes";

/**
* Given a ResidentRecord return the resident's DOB as a string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
* @param {Promise} refreshList
* @param {function} setDrugList
* @param {function} onError
* @returns {void}
*/
export const handleMedicineEditModalClose = (
drugInfo: {Id: number | null, Notes: string | null},
medicineProvider: {post: Function},
refreshList: Function,
setDrugList: Function,
onError: Function
) => {
): void => {
if (drugInfo) {
const drugData = {...drugInfo};

Expand Down
15 changes: 15 additions & 0 deletions src/utility/initialState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const initialState = {
development: process.env.REACT_APP_DEVELOPMENT === 'true',
activeResident: null,
residentList: null,
medicineList: null,
otcList: null,
drugLogList: null,
apiKey: null,
baseUrl: process.env.REACT_APP_BASEURL,
providers: {
residentProvider: null,
medicineProvider: null,
medHistoryProvider: null
}
};
20 changes: 20 additions & 0 deletions src/utility/logButtonColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Given the last time a drug was taken in hours determine the button color for logging drugs
* @param {number} lastTaken
* @returns {string}
*/
const logButtonColor = (lastTaken) => {
if (lastTaken === null || lastTaken === false) {
return 'primary'
}
if (lastTaken <= 1) {
return 'danger'
}
if (lastTaken <= 4) {
return 'info'
}
return 'primary';
}

export default logButtonColor;

0 comments on commit 2e9c1f0

Please sign in to comment.