-
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 #91 from skorphil/refactoring-recordform
refactored RecordForm
- Loading branch information
Showing
13 changed files
with
167 additions
and
93 deletions.
There are no files selected for viewing
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
File renamed without changes.
File renamed without changes.
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,2 @@ | ||
export { FormStateOverlay } from "./FormStateOverlay"; | ||
export { FormWarning } from "./FormWarning"; |
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,28 @@ | ||
/* | ||
Root element of the form | ||
*/ | ||
"use client"; | ||
import { Button, Heading, Text } from "@chakra-ui/react"; | ||
|
||
export function handleEmptyState({ setFormOverlay, handleInstitutionCreate }) { | ||
setFormOverlay({ | ||
children: ( | ||
<> | ||
<Heading as="h1" size="md"> | ||
No institutions were added yet | ||
</Heading> | ||
<Text>Create your first institution</Text> | ||
<Button | ||
mt={2} | ||
onClick={() => { | ||
handleInstitutionCreate(); | ||
setFormOverlay(null); | ||
}} | ||
> | ||
Add institution | ||
</Button> | ||
</> | ||
), | ||
image: "/empty.svg", | ||
}); | ||
} |
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,32 @@ | ||
/* | ||
Root element of the form | ||
*/ | ||
"use client"; | ||
import { Heading, Text } from "@chakra-ui/react"; | ||
|
||
interface handleFetchErrorProps { | ||
error: Error | ||
setFormOverlay: React.Dispatch<React.SetStateAction<OverlayProps>> | ||
} | ||
|
||
interface OverlayProps { | ||
children: React.ReactNode; | ||
errorMessage?: string; | ||
image?: string; | ||
} | ||
|
||
export function handleFetchError({ error, setFormOverlay }: handleFetchErrorProps): void { | ||
|
||
setFormOverlay({ | ||
children: ( | ||
<> | ||
<Heading as="h1" size="md"> | ||
Cannot check previos record | ||
</Heading> | ||
<Text>Try to reload the page</Text> | ||
</> | ||
), | ||
errorMessage: error.stack, | ||
image: "/server-down.svg", | ||
}); | ||
} |
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 @@ | ||
/* | ||
Root element of the form | ||
*/ | ||
"use client"; | ||
export function handleRecordExist({ existingRecordDate, setWarningState }) { | ||
setWarningState({ | ||
heading: `Record from ${new Date(existingRecordDate).toLocaleDateString( | ||
"en-US", | ||
{ | ||
day: "numeric", | ||
month: "long", | ||
} | ||
)} will be replaced`, | ||
message: `There is a saved record for this month already. | ||
Saving current record will override that.`, | ||
isVisible: true, | ||
}); | ||
} |
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,12 @@ | ||
/* | ||
Root element of the form | ||
*/ | ||
"use client"; | ||
export function handleSavingError({ toast, error }) { | ||
toast({ | ||
title: "Error saving record", | ||
description: error.message, | ||
status: "error", | ||
isClosable: true, | ||
}); | ||
} |
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 @@ | ||
/* | ||
Root element of the form | ||
*/ | ||
"use client"; | ||
export function handleSavingSuccess({ toast }) { | ||
toast({ | ||
title: "Record saved", | ||
status: "success", | ||
duration: 3000, | ||
}); | ||
} |
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,5 @@ | ||
export { handleEmptyState } from "./handleEmptyState"; | ||
export { handleFetchError } from "./handleFetchError"; | ||
export { handleRecordExist } from "./handleRecordExist"; | ||
export { handleSavingError } from "./handleSavingError"; | ||
export { handleSavingSuccess } from "./handleSavingSuccess"; |
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,2 @@ | ||
export { getDefaultValues } from "./getDefaultValues"; | ||
export { isInCurrentMonth } from "./isDateInCurrentMonth"; |
This file was deleted.
Oops, something went wrong.