diff --git a/app/@newrecord/(.)new-record/page.jsx b/app/@newrecord/(.)new-record/page.jsx
deleted file mode 100644
index be9ac85..0000000
--- a/app/@newrecord/(.)new-record/page.jsx
+++ /dev/null
@@ -1,9 +0,0 @@
-import { RecordForm } from "~/RecordForm";
-import { Center } from "@chakra-ui/react";
-export default function Page() {
- return (
-
-
-
- );
-}
diff --git a/app/@newrecord/default.js b/app/@newrecord/default.js
deleted file mode 100644
index 6ddf1b7..0000000
--- a/app/@newrecord/default.js
+++ /dev/null
@@ -1,3 +0,0 @@
-export default function Default() {
- return null;
-}
diff --git a/app/api/page.jsx b/app/api/page.jsx
deleted file mode 100644
index 12b005d..0000000
--- a/app/api/page.jsx
+++ /dev/null
@@ -1,8 +0,0 @@
-import { dbConnect } from "../../serverActions/appendRecord";
-
-export default async function handler(req, res) {
- //the rest of your code here
-}
-
-await dbConnect();
-// dbConnect().catch((err) => console.error("MongoDB connection error:", err));
diff --git a/app/new-record/page.jsx b/app/new-record/page.jsx
deleted file mode 100644
index afeed47..0000000
--- a/app/new-record/page.jsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { RecordForm } from "~/RecordForm";
-
-export default function NewRecord() {
- return ;
-}
diff --git a/components/InstitutionContainer/InstitutionContainer.jsx b/components/InstitutionContainer/InstitutionContainer.jsx
index 36676f2..21e3ce1 100644
--- a/components/InstitutionContainer/InstitutionContainer.jsx
+++ b/components/InstitutionContainer/InstitutionContainer.jsx
@@ -21,6 +21,7 @@ export function InstitutionContainer({ institutionName, isInstitutionOpen }) {
handlers: formHandlers = { handleInstitutionOpen },
} = useFormContext();
+ console.log("container getValues", getValues("institutions"));
// Fast solution to allow edit name of newly created institution
// Will be replaced whith https://github.com/users/skorphil/projects/4/views/1?pane=issue&itemId=53834705
const institutionIndex = parseInt(institutionName.split(".")[1]);
diff --git a/components/InstitutionsList/InstitutionsList.jsx b/components/InstitutionsList/InstitutionsList.jsx
index 920474e..daa0492 100644
--- a/components/InstitutionsList/InstitutionsList.jsx
+++ b/components/InstitutionsList/InstitutionsList.jsx
@@ -1,22 +1,14 @@
"use client";
import { InstitutionsTabsList } from "../InstitutionsTabsList";
-import { InstitutionContainer } from "../InstitutionContainer";
-import {
- Tabs,
- Text,
- TabPanels,
- TabPanel,
- Center,
- Heading,
- VStack,
- Image,
-} from "@chakra-ui/react";
+import { Tabs } from "@chakra-ui/react";
import { useVisualViewportSize } from "../../app/hooks";
import classes from "./InstitutionsList.module.css";
import { useFormContext } from "react-hook-form";
+import { InstitutionPanel } from "./components";
function InstitutionsList({
+ institutionPanelOverlay,
simulateKeyboard = false,
isInstitutionOpen,
selectedInstitution,
@@ -38,7 +30,8 @@ function InstitutionsList({
variant="grid"
padding={isInstitutionOpen || 2}
>
-
- {selectedInstitution === null ? (
-
- ) : (
- false
- )}
- {institutions.map((institution, index) => (
-
-
-
- ))}
-
- );
-}
-
-function ContentPanelOverlay({ image, headingText, text }) {
- return (
-
-
-
-
-
-
- {headingText}
-
- {text}
-
-
-
- );
-}
diff --git a/components/InstitutionsList/components/InstitutionPanel.jsx b/components/InstitutionsList/components/InstitutionPanel.jsx
new file mode 100644
index 0000000..286314f
--- /dev/null
+++ b/components/InstitutionsList/components/InstitutionPanel.jsx
@@ -0,0 +1,52 @@
+"use client";
+import { InstitutionContainer } from "../../InstitutionContainer";
+import { TabPanels, TabPanel } from "@chakra-ui/react";
+import { useFormContext } from "react-hook-form";
+import { getInstitutionPanelOverlayState } from "../utils/getInstitutionPanelOverlayState";
+import { InstitutionPanelOverlayAllDeleted } from "./InstitutionPanelOverlayAllDeleted";
+import { InstitutionPanelOverlayInstitutionsLoaded } from "./InstitutionPanelOverlayInstitutionsLoaded";
+
+// TODO add all instituion deleted state
+export function InstitutionPanel({
+ institutions,
+ selectedInstitution,
+ isInstitutionOpen,
+}) {
+ const {
+ formState: { defaultValues },
+ getValues,
+ } = useFormContext();
+
+ const overlayState = getInstitutionPanelOverlayState(
+ defaultValues,
+ getValues
+ );
+
+ return (
+
+ {selectedInstitution !== null ? (
+ institutions.map((institution, index) => (
+
+
+
+ ))
+ ) : overlayState == "success" && selectedInstitution == null ? (
+
+ ) : overlayState == "allDeleted" && selectedInstitution == null ? (
+
+ ) : (
+ false
+ )}
+
+ );
+}
diff --git a/components/InstitutionsList/components/InstitutionPanelOverlay.jsx b/components/InstitutionsList/components/InstitutionPanelOverlay.jsx
new file mode 100644
index 0000000..565384e
--- /dev/null
+++ b/components/InstitutionsList/components/InstitutionPanelOverlay.jsx
@@ -0,0 +1,18 @@
+import { Text, Center, Heading, VStack, Image } from "@chakra-ui/react";
+
+export function InstitutionPanelOverlay({ image, headingText, text }) {
+ return (
+
+
+
+
+
+
+ {headingText}
+
+ {text}
+
+
+
+ );
+}
diff --git a/components/InstitutionsList/components/InstitutionPanelOverlayAllDeleted.jsx b/components/InstitutionsList/components/InstitutionPanelOverlayAllDeleted.jsx
new file mode 100644
index 0000000..72a1090
--- /dev/null
+++ b/components/InstitutionsList/components/InstitutionPanelOverlayAllDeleted.jsx
@@ -0,0 +1,11 @@
+import { InstitutionPanelOverlay } from "./InstitutionPanelOverlay";
+
+export function InstitutionPanelOverlayAllDeleted() {
+ return (
+
+ );
+}
diff --git a/components/InstitutionsList/components/InstitutionPanelOverlayInstitutionsLoaded.jsx b/components/InstitutionsList/components/InstitutionPanelOverlayInstitutionsLoaded.jsx
new file mode 100644
index 0000000..7a2644d
--- /dev/null
+++ b/components/InstitutionsList/components/InstitutionPanelOverlayInstitutionsLoaded.jsx
@@ -0,0 +1,11 @@
+import { InstitutionPanelOverlay } from "./InstitutionPanelOverlay";
+
+export function InstitutionPanelOverlayInstitutionsLoaded() {
+ return (
+
+ );
+}
diff --git a/components/InstitutionsList/components/index.js b/components/InstitutionsList/components/index.js
new file mode 100644
index 0000000..8380afe
--- /dev/null
+++ b/components/InstitutionsList/components/index.js
@@ -0,0 +1 @@
+export { InstitutionPanel } from "./InstitutionPanel";
diff --git a/components/InstitutionsList/index.js b/components/InstitutionsList/index.js
index 347694d..d80b8f6 100644
--- a/components/InstitutionsList/index.js
+++ b/components/InstitutionsList/index.js
@@ -1,2 +1,3 @@
export { InstitutionsList } from "./InstitutionsList";
export { institutionsListStyle } from "./InstitutionList.chakra";
+export { InstitutionPanelOverlay } from "./components/InstitutionPanelOverlay";
diff --git a/components/InstitutionsList/utils/getInstitutionPanelOverlayState.ts b/components/InstitutionsList/utils/getInstitutionPanelOverlayState.ts
new file mode 100644
index 0000000..76fc565
--- /dev/null
+++ b/components/InstitutionsList/utils/getInstitutionPanelOverlayState.ts
@@ -0,0 +1,40 @@
+import { DefaultValues, FieldValues, UseFormGetValues } from "react-hook-form";
+
+/**
+ * Function for deriving the InstitutionPanelOverlay state
+ * from useFormContext
+ */
+export function getInstitutionPanelOverlayState(defaultValues:DefaultValues, getValues:UseFormGetValues) {
+ const formValues = getValues("institutions");
+ const isAllDeleted = isAllInstitutionsDeleted(formValues);
+ const isFetchedPrevious = isFetchedPreviousRecords(defaultValues, isAllDeleted);
+// console.log("isFetchedPrevious TS", isFetchedPrevious);
+// console.log("isAllDeleted TS", isAllDeleted);
+
+if (isFetchedPrevious && !isAllDeleted) {
+ return 'success'
+ } else if (isAllDeleted) {
+ return 'allDeleted'
+ } else return false;
+}
+
+function isAllInstitutionsDeleted(formValues) {
+ const institutionsIndexes = formValues.map((institution, index) => ({
+ index,
+ isDeleted: institution.isDeleted,
+ }));
+ const availableIndexes = institutionsIndexes
+ .filter((institution) => institution.isDeleted != true)
+ .map((institution) => institution.index);
+
+ if (institutionsIndexes.length > 0 && availableIndexes.length == 0) {
+ return true;
+ } else return false;
+ }
+
+ function isFetchedPreviousRecords(defaultValues, isAllDeleted) {
+ if (defaultValues.institutions && !isAllDeleted) {
+ return true;
+ } else return false;
+ }
+
\ No newline at end of file
diff --git a/components/InstitutionsList/utils/index.js b/components/InstitutionsList/utils/index.js
new file mode 100644
index 0000000..443324a
--- /dev/null
+++ b/components/InstitutionsList/utils/index.js
@@ -0,0 +1 @@
+export { getInstitutionPanelOverlayState } from "./getInstitutionPanelOverlayState";
diff --git a/components/RecordForm/RecordForm.jsx b/components/RecordForm/RecordForm.jsx
index 523593c..430cfbc 100644
--- a/components/RecordForm/RecordForm.jsx
+++ b/components/RecordForm/RecordForm.jsx
@@ -13,7 +13,7 @@ import { useState } from "react";
import { Button, Progress, useToast } from "@chakra-ui/react";
import { InstitutionsList } from "components/InstitutionsList";
import { FormHeader } from "components/FormHeader";
-import { FormStateOverlay, FormWarning } from "./components";
+import { FormOverlay, FormAlert } from "./components";
import { appendRecord } from "serverActions/appendRecord";
import { getDefaultValues } from "./utils";
@@ -25,7 +25,7 @@ export function RecordForm() {
const [selectedInstitutionIndex, setSelectedInstitutionIndex] =
useState(null);
const [formOverlay, setFormOverlay] = useState(false);
- const [warningState, setWarningState] = useState(null);
+ const [formAlert, setFormAlert] = useState(null);
const toast = useToast({ position: "top" });
const router = useRouter();
const arrayName = "institutions";
@@ -33,7 +33,7 @@ export function RecordForm() {
defaultValues: async () =>
getDefaultValues({
setFormOverlay,
- setWarningState,
+ setFormAlert,
handleInstitutionCreate: formMethods.handlers.handleInstitutionCreate,
}),
});
@@ -106,11 +106,11 @@ export function RecordForm() {
>
}
/>
- {warningState?.isVisible && (
-
- setWarningState((current) => ({
+ setFormAlert((current) => ({
...current,
isVisible: false,
}))
@@ -123,12 +123,12 @@ export function RecordForm() {
{form.formState.isLoading ? (
) : formOverlay ? (
-
{formOverlay.children}
-
+
) : (