-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from skorphil/86-all-institutions-were-deleted
implemented allLoaded state
- Loading branch information
Showing
29 changed files
with
237 additions
and
171 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
52 changes: 52 additions & 0 deletions
52
components/InstitutionsList/components/InstitutionPanel.jsx
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,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 ( | ||
<TabPanels | ||
bg="gray.800" | ||
borderRadius={isInstitutionOpen || "lg"} | ||
h="100%" | ||
minHeight="260px" | ||
flexGrow={1} | ||
flexShrink={1} | ||
> | ||
{selectedInstitution !== null ? ( | ||
institutions.map((institution, index) => ( | ||
<TabPanel p={0} key={institution.id} h="100%" overflow="auto"> | ||
<InstitutionContainer | ||
institutionName={`institutions.${index}`} | ||
isInstitutionOpen={isInstitutionOpen} | ||
/> | ||
</TabPanel> | ||
)) | ||
) : overlayState == "success" && selectedInstitution == null ? ( | ||
<InstitutionPanelOverlayInstitutionsLoaded /> | ||
) : overlayState == "allDeleted" && selectedInstitution == null ? ( | ||
<InstitutionPanelOverlayAllDeleted /> | ||
) : ( | ||
false | ||
)} | ||
</TabPanels> | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
components/InstitutionsList/components/InstitutionPanelOverlay.jsx
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,18 @@ | ||
import { Text, Center, Heading, VStack, Image } from "@chakra-ui/react"; | ||
|
||
export function InstitutionPanelOverlay({ image, headingText, text }) { | ||
return ( | ||
<Center h="100%" p={2}> | ||
<VStack gap={12}> | ||
<Image src={image} alt="Illustration" boxSize="240px" /> | ||
|
||
<VStack> | ||
<Heading textAlign="center" size="md"> | ||
{headingText} | ||
</Heading> | ||
<Text>{text}</Text> | ||
</VStack> | ||
</VStack> | ||
</Center> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
components/InstitutionsList/components/InstitutionPanelOverlayAllDeleted.jsx
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,11 @@ | ||
import { InstitutionPanelOverlay } from "./InstitutionPanelOverlay"; | ||
|
||
export function InstitutionPanelOverlayAllDeleted() { | ||
return ( | ||
<InstitutionPanelOverlay | ||
image="/empty.svg" | ||
headingText="No institutions left in the record" | ||
text="Add or restore institutions" | ||
/> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
components/InstitutionsList/components/InstitutionPanelOverlayInstitutionsLoaded.jsx
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,11 @@ | ||
import { InstitutionPanelOverlay } from "./InstitutionPanelOverlay"; | ||
|
||
export function InstitutionPanelOverlayInstitutionsLoaded() { | ||
return ( | ||
<InstitutionPanelOverlay | ||
image="/institutions-loaded.svg" | ||
headingText="Institutions loaded from latest record" | ||
text="Edit institutions to reflect asset updates" | ||
/> | ||
); | ||
} |
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 @@ | ||
export { InstitutionPanel } from "./InstitutionPanel"; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { InstitutionsList } from "./InstitutionsList"; | ||
export { institutionsListStyle } from "./InstitutionList.chakra"; | ||
export { InstitutionPanelOverlay } from "./components/InstitutionPanelOverlay"; |
40 changes: 40 additions & 0 deletions
40
components/InstitutionsList/utils/getInstitutionPanelOverlayState.ts
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,40 @@ | ||
import { DefaultValues, FieldValues, UseFormGetValues } from "react-hook-form"; | ||
|
||
/** | ||
* Function for deriving the InstitutionPanelOverlay state | ||
* from useFormContext | ||
*/ | ||
export function getInstitutionPanelOverlayState(defaultValues:DefaultValues<FieldValues>, getValues:UseFormGetValues<FieldValues>) { | ||
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; | ||
} | ||
|
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 @@ | ||
export { getInstitutionPanelOverlayState } from "./getInstitutionPanelOverlayState"; |
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,43 @@ | ||
import { | ||
Button, | ||
Accordion, | ||
AccordionButton, | ||
AccordionItem, | ||
AccordionIcon, | ||
Box, | ||
AccordionPanel, | ||
Text, | ||
} from "@chakra-ui/react"; | ||
|
||
/** | ||
* Alert, appended to the top of RecordForm. Used for non-blocking warnings or information. | ||
* Can be expanded and explicitly closed until reload of the form. | ||
* @param {string} heading - heading text (always visible) | ||
* @param {string} message - collapsed text | ||
* @param {function} [onHide] - handler for hideWarning button | ||
* @returns | ||
*/ | ||
export function FormAlert({ heading, message, onHide }) { | ||
return ( | ||
<Box bg="yellow.900" m={2} borderRadius="md"> | ||
<Accordion w="100%" allowToggle> | ||
<AccordionItem borderStyle="none"> | ||
<AccordionButton> | ||
<Box as="span" flex="1" textAlign="left"> | ||
{heading} | ||
</Box> | ||
<AccordionIcon /> | ||
</AccordionButton> | ||
<AccordionPanel maxH="180px" overflow="auto" pb={4}> | ||
<Text>{message}</Text> | ||
{onHide && ( | ||
<Button mt={2} variant="link" onClick={onHide}> | ||
Hide warning | ||
</Button> | ||
)} | ||
</AccordionPanel> | ||
</AccordionItem> | ||
</Accordion> | ||
</Box> | ||
); | ||
} |
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
Oops, something went wrong.