diff --git a/src/PorterooApp/Task.js b/src/PorterooApp/Task.js index 998d148..a9974e2 100644 --- a/src/PorterooApp/Task.js +++ b/src/PorterooApp/Task.js @@ -31,7 +31,7 @@ const EmphasisText = styled("p")` margin: 0; ` -function Task({ location, time, porterId, forceRefetchData }) { +function Task({ location, time, porterId, forceRefetchData, locationId }) { const [type, updateType] = useState(""); // delivery or collection const [text, updateText] = useState(""); const [postingCompleteTask, updatePostingCompleteTask] = useState(false) @@ -62,7 +62,7 @@ function Task({ location, time, porterId, forceRefetchData }) { const handleClick = async () => { updatePostingCompleteTask(true) - await fetchPost(`https://placeholder.com/porterRoute?location=${location}]?porter=${porterId}`) + await fetchPost(`http://29bbbb63.ngrok.io/checkin/${locationId}`) updatePostingCompleteTask(false) alert("Completed task - good job 👍") forceRefetchData(true) diff --git a/src/PorterooApp/index.js b/src/PorterooApp/index.js index 27310d2..03fd282 100644 --- a/src/PorterooApp/index.js +++ b/src/PorterooApp/index.js @@ -63,12 +63,6 @@ const dummyUserData = { id: 1 } -// TODO: remove routes dummy data -// - Routes -// - GET porterRoute -// - [{location: text, time: int}, ] -const data = [{ location: "Ward Green", time: 10 }, { location: "Lab", time: 10 }] - const NextTask = ({ location, time }) => { if (!location) return

No more jobs!

; return {getDeadline(time)} - {location === "Lab" ? `Delivery to ${location}` : `Collect from ${location}`} @@ -87,12 +81,22 @@ const TaskSection = ({ routes, forceRefetchData }) => { ) } +const wardNames = { + 0: "Lab", + 1: "Ward Blue", + 2: "Ward Green", + 3: "Ward Red", + 10: "Ward Teal" +} + function App() { const [refetchData, forceRefetchData] = useState(false) - const { loading } = useFetchGet( - `https://placeholder.com/porterRoute/${dummyUserData.id}`, refetchData + const { loading, data } = useFetchGet( + `http://29bbbb63.ngrok.io/porterRoute/${dummyUserData.id}`, refetchData ); + const routes = (data && data.length > 0) ? data.map(route => ({ location: wardNames[route.location] || "Ward Base", time: route.estimated_pickup, locationId: route.location })) : [] + return ( @@ -101,7 +105,7 @@ function App() {

Porter

{dummyUserData.username}

-
{loading ?

Loading Porteroo data...

: }
+
{loading ?

Loading Porteroo data...

: }
); } diff --git a/src/fetch-util.js b/src/fetch-util.js index 187a991..c47734c 100644 --- a/src/fetch-util.js +++ b/src/fetch-util.js @@ -12,7 +12,7 @@ const nextPickup = { export const fetchPost = async url => { try { const response = await fetch(url, { - method: "POST", + method: "PUT", headers: { "Content-Type": "application/json" } }); if (response.status !== 200) { @@ -33,7 +33,6 @@ export const useFetchGet = (url, rerun) => { useEffect(() => { async function fetchData() { - console.log('RUNNING ') try { const response = await fetch(url, { method: "GET", @@ -59,5 +58,5 @@ export const useFetchGet = (url, rerun) => { fetchData(); }, [url, rerun]); - return { loading, data, error }; + return { loading, data: data || [], error }; }; diff --git a/src/utils/getDeadline.js b/src/utils/getDeadline.js index d2b1c9d..88f6701 100644 --- a/src/utils/getDeadline.js +++ b/src/utils/getDeadline.js @@ -1,6 +1,4 @@ export const getDeadline = (time) => { - const currentDate = new Date(); - // TODO: Check time (int) is in minutes - const deadline = new Date(currentDate.getTime() + time * 60000) - return deadline.toTimeString().substr(0, 5) + if (!time) return "" + return time.split(" ")[1].substr(0, 5); } \ No newline at end of file