forked from impress-org/givewp
-
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.
Feature: classic template (impress-org#40)
* feature: scaffold start of classic template overrides * refactor: remove additional conditional * refactor: adjust structure of base form elements including abiliy to override html tags * refactor: update base form to include submit inside a section * feature: first pass classic template structure and amount field * feature: add setFocus to custom amount * feature: use classNames package for className conditionals * feature: add support for field level error styling * refactor: get formState from useFormState hoook * fix: search for updated node names * feature: add name prop to NodeWrapper for parent div styling * feature: improve form styles with updated gateway field styles * feature: add submit button hover * refactor: start isolating FormSections into seperate component for resolving nested rerenders and validation focus issue * feature: add border radius to bottom * feature: update input labels * refactor: convert amount field to BEM structure * refactor: update component to use types * chore: cleanup unused and add comments * fix: scss typo * chore: update type import locations * refactor: move utility functions into seperate files * feature: create SectionNode component and wrap template functions in useMemo * refactor: get rid of unnecessary loopy components and move sections back into form now * feature: take a step further and seperate node types * chore: format file, c'mon phpstorm * chore: y u no format Co-authored-by: Jon Waldstein <jonwaldstein@jons-air.mynetworksettings.com>
- Loading branch information
1 parent
f94d115
commit 94ab1db
Showing
41 changed files
with
866 additions
and
300 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
10 changes: 10 additions & 0 deletions
10
src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/ElementNode.tsx
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,10 @@ | ||
import {Element} from '@givewp/forms/types'; | ||
import {getElementTemplate} from '../templates'; | ||
import {useMemo} from "react"; | ||
|
||
export default function ElementNode({node}: { node: Element }) { | ||
const Element = useMemo(() => getElementTemplate(node.type), [node.type]); | ||
|
||
return <Element key={node.name} {...node} />; | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/FieldNode.tsx
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 buildRegisterValidationOptions from "../utilities/buildRegisterValidationOptions"; | ||
import {Field} from '@givewp/forms/types'; | ||
import {getFieldTemplate} from '../templates'; | ||
import getErrorByFieldName from "../utilities/getErrorByFieldName"; | ||
import {useFormContext, useFormState} from "react-hook-form"; | ||
import {useMemo} from "react"; | ||
|
||
export default function FieldNode({node}: { node: Field }) { | ||
const {register} = useFormContext(); | ||
const {errors} = useFormState(); | ||
const Field = useMemo(() => getFieldTemplate(node.type), [node.type]); | ||
const inputProps = register(node.name, buildRegisterValidationOptions(node.validationRules)); | ||
|
||
return <Field key={node.name} inputProps={inputProps} | ||
fieldError={getErrorByFieldName(errors, node.name)} | ||
{...node} />; | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/GroupNode.tsx
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,24 @@ | ||
import buildRegisterValidationOptions from "../utilities/buildRegisterValidationOptions"; | ||
import {Group} from '@givewp/forms/types'; | ||
import {getGroupTemplate} from '../templates'; | ||
import {useFormContext} from "react-hook-form"; | ||
import {useMemo} from "react"; | ||
import getGroupFields from "../utilities/getGroupFields"; | ||
|
||
export default function GroupNode({node}: { node: Group }) { | ||
const {register} = useFormContext(); | ||
const Group = useMemo(() => getGroupTemplate(node.type), [node.type]); | ||
const fields = node.nodes.reduce(getGroupFields, []); | ||
|
||
const inputProps = fields.reduce((inputProps, field) => { | ||
inputProps[field.name] = register( | ||
field.name, | ||
buildRegisterValidationOptions(field.validationRules) | ||
); | ||
|
||
return inputProps; | ||
}, {}); | ||
|
||
return <Group key={node.name} inputProps={inputProps} {...node} />; | ||
} | ||
|
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
22 changes: 22 additions & 0 deletions
22
src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/SectionNode.tsx
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,22 @@ | ||
import {isElement, isField, isGroup, Node} from '@givewp/forms/types'; | ||
import FieldNode from "./FieldNode"; | ||
import ElementNode from "./ElementNode"; | ||
import GroupNode from "./GroupNode"; | ||
|
||
/** | ||
* Determine which node template to render | ||
* | ||
* @unreleased | ||
*/ | ||
export default function SectionNode({node}: { node: Node }) { | ||
if (isField(node)) { | ||
return <FieldNode node={node}/> | ||
} else if (isElement(node)) { | ||
return <ElementNode node={node}/> | ||
} else if (isGroup(node)) { | ||
return <GroupNode node={node}/> | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
73 changes: 0 additions & 73 deletions
73
src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/SectionNodes.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.