-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add Hospitals tab to Site Admin and show list * Drag-and-drop sort * Formatting
- Loading branch information
Showing
11 changed files
with
156 additions
and
2 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
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,55 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { ReactSortable } from 'react-sortablejs'; | ||
|
||
import ApiService from '../../../ApiService'; | ||
|
||
function HospitalsList() { | ||
const [records, setRecords] = useState([]); | ||
|
||
useEffect(() => { | ||
ApiService.hospitals.index().then((response) => setRecords(response.data)); | ||
}, []); | ||
|
||
async function onDrop(records) { | ||
let i = 1; | ||
for (const record of records) { | ||
record.sortSequenceNumber = i++; | ||
} | ||
setRecords(records); | ||
try { | ||
await ApiService.hospitals.sort(records.map((r) => ({ id: r.id, sortSequenceNumber: r.sortSequenceNumber }))); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
return ( | ||
<main> | ||
<div className="display-flex flex-align-center flex-justify"> | ||
<h1>Hospitals</h1> | ||
</div> | ||
<table className="usa-table usa-table--striped usa-table--borderless width-full"> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
<th className="w-35">Name</th> | ||
<th className="w-35">Organization</th> | ||
<th>State Facility Code</th> | ||
</tr> | ||
</thead> | ||
<ReactSortable tag="tbody" list={records} setList={(list) => onDrop(list)}> | ||
{records.map((r) => ( | ||
<tr key={r.id}> | ||
<td className="cursor--grab">≡</td> | ||
<td>{r.name}</td> | ||
<td>{r.organization?.name}</td> | ||
<td>{r.stateFacilityCode}</td> | ||
</tr> | ||
))} | ||
</ReactSortable> | ||
</table> | ||
</main> | ||
); | ||
} | ||
|
||
export default HospitalsList; |
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,13 @@ | ||
import { Routes, Route } from 'react-router-dom'; | ||
|
||
import HospitalsList from './HospitalsList'; | ||
|
||
function HospitalsRoutes() { | ||
return ( | ||
<Routes> | ||
<Route path="" element={<HospitalsList />} /> | ||
</Routes> | ||
); | ||
} | ||
|
||
export default HospitalsRoutes; |
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
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