-
Notifications
You must be signed in to change notification settings - Fork 0
test exercise code #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
test exercise code #145
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
48586f4
exercise page split #132
DAC098 47ab37c
PR requests / additional fixes #132
DAC098 6336232
fix ts error #132
DAC098 cd52d6f
resolved stash conflict
DAC098 a1a297b
id check and err check #132
DAC098 a05ba72
Merge branch 't132_split_exercise_table_form' into t138_test_exercise…
DAC098 787f289
app form #138
DAC098 586ac69
tanstack form devtools #138
DAC098 596b3c7
test exercise and form rewrite #138
DAC098 d14b48d
Merge branch 'main' into t138_test_exercise_code
DAC098 c36d875
Merge branch 'main' into t138_test_exercise_code
DAC098 f6da752
error handling and checks #138
DAC098 1e53df5
silence ts errors #138
DAC098 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| import { createFormHook } from "@tanstack/react-form"; | ||
|
|
||
| import { | ||
| fieldContext, | ||
| formContext, | ||
| useFieldContext, | ||
| useFormContext | ||
| } from "./form/context"; | ||
| import { | ||
| SubmitButton, | ||
| ConfirmReset, | ||
| ConfirmDelete, | ||
| ConfirmAway | ||
| } from "./form/button"; | ||
|
|
||
| const { useAppForm } = createFormHook({ | ||
| fieldContext, | ||
| formContext, | ||
| fieldComponents: {}, | ||
| formComponents: { | ||
| SubmitButton, | ||
| ConfirmReset, | ||
| ConfirmDelete, | ||
| ConfirmAway, | ||
| }, | ||
| }); | ||
|
|
||
| export { useAppForm, useFieldContext, useFormContext }; |
This file contains hidden or 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,203 @@ | ||
| import { ArrowLeftIcon, TrashIcon, ArrowPathIcon } from "@heroicons/react/24/solid"; | ||
| import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from "flowbite-react"; | ||
| import { useState } from "react"; | ||
|
|
||
| import { useFormContext } from "./context"; | ||
|
|
||
| interface SubmitButtonProps {} | ||
|
|
||
| export function SubmitButton({}) { | ||
| const form = useFormContext(); | ||
|
|
||
| return <form.Subscribe selector={state => ({ | ||
| submitting: state.isSubmitting, | ||
| dirty: state.isDirty, | ||
| can_submit: state.canSubmit, | ||
| })}> | ||
| {({submitting, dirty, can_submit}) => ( | ||
| <Button type="submit" disabled={submitting || !dirty || !can_submit}> | ||
| Save | ||
| </Button> | ||
| )} | ||
| </form.Subscribe> | ||
| } | ||
|
|
||
| interface ConfirmResetProps { | ||
| /** | ||
| * will be called when the user requests the reset | ||
| */ | ||
| on_reset: () => void, | ||
| /** | ||
| * will be called when the user requests to cancel the reset | ||
| */ | ||
| on_cancel?: () => void, | ||
| } | ||
|
|
||
| /** | ||
| * a simple reset confirmation modal that will trigger the `on_reset` when the | ||
| * user confirms the reset action. requires a form context as it will enable | ||
| * and disable based on if the form is `submitting` or is `dirty`. | ||
| */ | ||
| export function ConfirmReset({ | ||
| on_reset, | ||
| on_cancel = () => {}, | ||
| }: ConfirmResetProps) { | ||
| const form = useFormContext(); | ||
|
|
||
| const [open, set_open] = useState(false); | ||
|
|
||
| const cancel_cb = () => { | ||
| set_open(false); | ||
| on_cancel(); | ||
| }; | ||
|
|
||
| const reset_cb = () => { | ||
| set_open(false); | ||
| on_reset(); | ||
| }; | ||
|
|
||
| return <form.Subscribe selector={state => ({ | ||
| submitting: state.isSubmitting, | ||
| dirty: state.isDirty, | ||
| })}> | ||
| {({submitting, dirty}) => <> | ||
| <Button type="button" color="dark" disabled={submitting || !dirty} onClick={() => set_open(true)}> | ||
| <ArrowPathIcon className="mr-2 w-4 h-4"/> Reset | ||
| </Button> | ||
| <Modal dismissible show={open} onClose={cancel_cb}> | ||
| <ModalHeader>Reset Data</ModalHeader> | ||
| <ModalBody> | ||
| <p>This will reset any changes you made to its original state. Are you sure?</p> | ||
| </ModalBody> | ||
| <ModalFooter> | ||
| <Button type="button" onClick={reset_cb}>Reset</Button> | ||
| <Button type="button" color="dark" onClick={cancel_cb}>Cancel</Button> | ||
| </ModalFooter> | ||
| </Modal> | ||
| </>} | ||
| </form.Subscribe> | ||
| } | ||
|
|
||
| interface ConfirmDeleteProps { | ||
| /** | ||
| * will be called when the user requests the delete | ||
| */ | ||
| on_delete: () => void, | ||
| /** | ||
| * will be called when the user reqests to cancel the delete | ||
| */ | ||
| on_cancel?: () => void, | ||
| } | ||
|
|
||
| /** | ||
| * a simple delete confirmation modal that will trigger the `on_delete` when the | ||
| * user confirms the delete action. requires a form context as it will enable | ||
| * and disable based on if the form is `submitting` | ||
| */ | ||
| export function ConfirmDelete({ | ||
| on_delete, | ||
| on_cancel = () => {}, | ||
| }: ConfirmDeleteProps) { | ||
| const form = useFormContext(); | ||
|
|
||
| const [open, set_open] = useState(false); | ||
|
|
||
| const cancel_cb = () => { | ||
| set_open(false); | ||
| on_cancel(); | ||
| }; | ||
|
|
||
| const delete_cb = () => { | ||
| set_open(false); | ||
| on_delete(); | ||
| }; | ||
|
|
||
| return <form.Subscribe selector={state => ({ | ||
| submitting: state.isSubmitting, | ||
| })}> | ||
| {({submitting}) => <> | ||
| <Button type="button" color="red" disabled={submitting} onClick={() => set_open(true)}> | ||
| <TrashIcon className="mr-2 w-4 h-4"/> Delete | ||
| </Button> | ||
| <Modal dismissible show={open} onClose={cancel_cb}> | ||
| <ModalHeader>Delete Data</ModalHeader> | ||
| <ModalBody> | ||
| <p>This will delete the current data from the server. Are you sure?</p> | ||
| </ModalBody> | ||
| <ModalFooter> | ||
| <Button type="button" color="red" onClick={delete_cb}>Delete</Button> | ||
| <Button type="button" color="dark" onClick={cancel_cb}>Cancel</Button> | ||
| </ModalFooter> | ||
| </Modal> | ||
| </>} | ||
| </form.Subscribe> | ||
| } | ||
|
|
||
| interface ConfirmAwayProps { | ||
| /** | ||
| * will be called when the user reqests to away | ||
| */ | ||
| on_away: () => void, | ||
| /** | ||
| * will be called when the user requests to cancel the away | ||
| */ | ||
| on_cancel?: () => void, | ||
| } | ||
|
|
||
| /** | ||
| * a simple away confirmation modal that will trigger the `on_away` when the | ||
| * user confirms the awayt action. requires a form context as it will enable | ||
| * and disable based on if the form is `submitting`. the modal will only appear | ||
| * if the form is marked as dirty otherwise it will not prompt the user to | ||
| * confirm the away request. | ||
| */ | ||
| export function ConfirmAway({ | ||
| on_away, | ||
| on_cancel = () => {}, | ||
| }: ConfirmAwayProps) { | ||
| const form = useFormContext(); | ||
|
|
||
| const [open, set_open] = useState(false); | ||
|
|
||
| const away_cb = () => { | ||
| set_open(false); | ||
| on_away(); | ||
| }; | ||
|
|
||
| const cancel_cb = () => { | ||
| set_open(false); | ||
| on_cancel(); | ||
| }; | ||
|
|
||
| return <form.Subscribe selector={state => ({ | ||
| submitting: state.isSubmitting, | ||
| dirty: state.isDirty, | ||
| })}> | ||
| {({submitting, dirty}) => <> | ||
| <Button | ||
| type="button" | ||
| color="light" | ||
| disabled={submitting} | ||
| onClick={() => { | ||
| if (dirty) { | ||
| set_open(true); | ||
| } else { | ||
| on_away(); | ||
| } | ||
| }} | ||
| > | ||
| <ArrowLeftIcon className="w-6 h-6"/> | ||
| </Button> | ||
| <Modal dismissible show={open} onClose={cancel_cb}> | ||
| <ModalHeader>Cancel Changes</ModalHeader> | ||
| <ModalBody> | ||
| <p>You have made changes to the data and did not save. Are you sure?</p> | ||
| </ModalBody> | ||
| <ModalFooter> | ||
| <Button type="button" color="light" onClick={away_cb}>Leave</Button> | ||
| <Button type="button" color="dark" onClick={cancel_cb}>Cancel</Button> | ||
| </ModalFooter> | ||
| </Modal> | ||
| </>} | ||
| </form.Subscribe> | ||
| } |
This file contains hidden or 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,6 @@ | ||
| import { createFormHookContexts, createFormHook } from "@tanstack/react-form"; | ||
|
|
||
| const { fieldContext, formContext, useFieldContext, useFormContext } = createFormHookContexts(); | ||
|
|
||
| export { fieldContext, formContext, useFieldContext, useFormContext }; | ||
|
|
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.