-
Notifications
You must be signed in to change notification settings - Fork 3
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 #178 from Enterprise-CMCS/finsoup
Finsoup
- Loading branch information
Showing
9 changed files
with
149 additions
and
94 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as T from "@/components/RHF/types"; | ||
|
||
type GL = Record<string, any>; | ||
|
||
export const formGroupReducer = (ACC: GL, FORM: T.FormGroup) => { | ||
FORM.slots.reduce(slotReducer, ACC); | ||
return ACC; | ||
}; | ||
|
||
export const slotReducer = (ACC: GL, SLOT: T.RHFSlotProps): GL => { | ||
const optionReducer = (OPT: T.RHFOption) => { | ||
if (OPT.form) OPT.form.reduce(formGroupReducer, ACC); | ||
if (OPT.slots) OPT.slots.reduce(slotReducer, ACC); | ||
return ACC; | ||
}; | ||
|
||
const fieldReducer = (ACC1: GL, SLOT: T.RHFSlotProps): GL => { | ||
if (SLOT.rhf === "FieldArray") { | ||
return { ...ACC1, [SLOT.name]: [SLOT.fields?.reduce(fieldReducer, {})] }; | ||
} | ||
if (SLOT.rhf === "FieldGroup") { | ||
return { ...ACC1, [SLOT.name]: [SLOT.fields?.reduce(fieldReducer, {})] }; | ||
} | ||
|
||
return { ...ACC1, ...slotReducer(ACC1, SLOT) }; | ||
}; | ||
|
||
if (SLOT.rhf === "Input") ACC[SLOT.name] = ""; | ||
if (SLOT.rhf === "Textarea") ACC[SLOT.name] = ""; | ||
if (SLOT.rhf === "Switch") ACC[SLOT.name] = false; | ||
if (SLOT.rhf === "Radio") { | ||
if (SLOT.props?.options) { | ||
SLOT.props.options.forEach(optionReducer); | ||
const [first] = SLOT.props.options; | ||
ACC[SLOT.name] = first.value; | ||
} | ||
} | ||
|
||
if (SLOT.rhf === "Select") { | ||
if (SLOT.props?.options) { | ||
SLOT.props.options.forEach(optionReducer); | ||
const [first] = SLOT.props.options; | ||
ACC[SLOT.name] = first.value; | ||
} | ||
} | ||
|
||
if (SLOT.rhf === "Checkbox") { | ||
if (SLOT.props?.options) { | ||
SLOT.props.options.forEach(optionReducer); | ||
ACC[SLOT.name] = []; | ||
} | ||
} | ||
|
||
if (SLOT.rhf === "FieldArray") | ||
ACC[SLOT.name] = [SLOT.fields?.reduce(fieldReducer, {})]; | ||
if (SLOT.rhf === "FieldGroup") | ||
ACC[SLOT.name] = [SLOT.fields?.reduce(fieldReducer, {})]; | ||
|
||
return ACC; | ||
}; | ||
|
||
export const documentInitializer = (document: T.Document) => { | ||
return document.sections.reduce((ACC, SEC) => { | ||
SEC.form.reduce(formGroupReducer, ACC); | ||
return ACC; | ||
}, {} as any); | ||
}; |
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.