From 69d2e11f37968da612592fd9b83f27bae65742f8 Mon Sep 17 00:00:00 2001 From: Jared Drueco Date: Mon, 24 Jul 2023 09:48:16 -0600 Subject: [PATCH 1/2] Added error modal when dish not found --- app/src/features/api.tsx | 6 +++++ app/src/routes/borrow.tsx | 51 ++++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/app/src/features/api.tsx b/app/src/features/api.tsx index c310ef3e..aa454a50 100644 --- a/app/src/features/api.tsx +++ b/app/src/features/api.tsx @@ -51,6 +51,8 @@ const DishAPI = { addDishBorrow: async function (qr: string, user: string | null) { console.log(FirebaseDatabase, QRCollectionName, qr) + try { + const qrRef = doc(FirebaseDatabase, QRCollectionName, qr); const out = await runTransaction(FirebaseDatabase, async (transaction) => { @@ -73,6 +75,10 @@ const DishAPI = { return docRef.id; }); return out; + } catch (e) { + console.error('Error occurred:',e); + return null; + } }, updateDishReturn: async function (qr: string) { diff --git a/app/src/routes/borrow.tsx b/app/src/routes/borrow.tsx index 71f28632..d2f72d8b 100644 --- a/app/src/routes/borrow.tsx +++ b/app/src/routes/borrow.tsx @@ -3,7 +3,7 @@ import { useNavigate } from "react-router-dom"; import Scanner from "../widgets/scanner"; import Modal from "react-bootstrap/Modal"; import Button from "react-bootstrap/Button"; -import { faCoffee } from "@fortawesome/free-solid-svg-icons"; +import { faCoffee, faCircleExclamation } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import DishAPI from "../features/api"; import { FirebaseContext } from "../firebase"; @@ -21,8 +21,8 @@ const Confirm = ({ show, onSubmit, onCancel, id }) => { > -

ID : {id}

+

ID: {id}