From 3cc274c33a9c1120f4e02349723201a576d393ba Mon Sep 17 00:00:00 2001 From: Philipp Rich Date: Mon, 11 Mar 2024 18:15:58 +0400 Subject: [PATCH] Implemented loading state whil fetching default values - fixed 500 error on loading app by removing window innerheight check in InstitutionsTabsList solves #73 --- app/page.jsx | 2 + .../InstitutionsTabsList.jsx | 11 ++-- components/RecordForm/RecordForm.jsx | 65 ++++++++++--------- components/RecordForm/RecordForm.module.css | 4 +- components/RecordForm/SlowLoadingToast.jsx | 12 ++++ 5 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 components/RecordForm/SlowLoadingToast.jsx diff --git a/app/page.jsx b/app/page.jsx index 264ee11..d329108 100644 --- a/app/page.jsx +++ b/app/page.jsx @@ -21,6 +21,8 @@ export default function Home() { zIndex="overlay" > 200 ? true : false); - + // const isKeyboardOpened = + // simulateKeyboard || (window.innerHeight - height > 200 ? true : false); return ( {isKeyboardOpened || Record Institutions} diff --git a/components/RecordForm/RecordForm.jsx b/components/RecordForm/RecordForm.jsx index 4294ec7..feb6e17 100644 --- a/components/RecordForm/RecordForm.jsx +++ b/components/RecordForm/RecordForm.jsx @@ -6,7 +6,7 @@ Root element of the form import { useForm, FormProvider, useFieldArray } from "react-hook-form"; import classes from "./RecordForm.module.css"; -import { Button } from "@chakra-ui/react"; +import { Button, Progress, useToast } from "@chakra-ui/react"; import { useState } from "react"; import { InstitutionsList } from "components/InstitutionsList"; @@ -22,6 +22,7 @@ export function RecordForm() { const [selectedInstitutionIndex, setSelectedInstitutionIndex] = useState(0); const router = useRouter(); const arrayName = "institutions"; + const { control, ...form } = useForm({ defaultValues: async () => getLatestRecord(), }); @@ -63,36 +64,40 @@ export function RecordForm() { return ( -
- {isInstitutionOpen || ( - - - - - } - /> - )} - + + + + } /> - + )} + {form.formState.isLoading ? ( + + ) : ( +
+ + + )} {/* */}
); diff --git a/components/RecordForm/RecordForm.module.css b/components/RecordForm/RecordForm.module.css index ce84ed4..60ede71 100644 --- a/components/RecordForm/RecordForm.module.css +++ b/components/RecordForm/RecordForm.module.css @@ -1,5 +1,7 @@ .RecordForm { display: flex; flex-direction: column; - height: 100%; + flex-shrink: 1; + flex-grow: 1; + height: 600px; } \ No newline at end of file diff --git a/components/RecordForm/SlowLoadingToast.jsx b/components/RecordForm/SlowLoadingToast.jsx new file mode 100644 index 0000000..3b041c7 --- /dev/null +++ b/components/RecordForm/SlowLoadingToast.jsx @@ -0,0 +1,12 @@ +import { useToast } from "@chakra-ui/react"; + +export function SlowLoadingToast() { + const toast = useToast(); + toast({ + title: "Account created.", + description: "We've created your account for you.", + status: "success", + duration: 5000, + isClosable: true, + }); +}