-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat(form): actions (submit & base button) in form (#5) #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { LoadingButton } from '@mui/lab'; | ||
import { FC } from 'react'; | ||
import { ActionBaseProps } from './actionBase.types'; | ||
|
||
const ActionBase: FC<ActionBaseProps> = ({ children, ...actionBaseProps }) => { | ||
return <LoadingButton {...actionBaseProps}>{children}</LoadingButton>; | ||
}; | ||
|
||
export default ActionBase; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { LoadingButtonProps } from '@mui/lab'; | ||
import { ReactNode } from 'react'; | ||
|
||
export type ActionBaseProps = LoadingButtonProps & { | ||
children: ReactNode; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Button } from '@mui/material'; | ||
import { FC } from 'react'; | ||
import { ActionSubmitFieldProps } from './submit.types'; | ||
import useForms from '../../../hooks/useForms/useForms'; | ||
import { FieldValues } from 'react-hook-form'; | ||
|
||
const ActionSubmit: FC<ActionSubmitFieldProps> = ({ | ||
formId, | ||
children, | ||
...submitFieldProps | ||
}) => { | ||
const forms = useForms((state) => state.forms); | ||
const { handleSubmit } = forms[formId]; | ||
const onSubmit = (values: FieldValues) => { | ||
console.log(values); | ||
}; | ||
|
||
return ( | ||
<Button {...submitFieldProps} onClick={handleSubmit(onSubmit)}> | ||
{children} | ||
</Button> | ||
); | ||
Comment on lines
+7
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Consider enhancing the |
||
}; | ||
|
||
export default ActionSubmit; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { FormId } from '../../../types/public.types'; | ||
import { ActionBaseProps } from '../base/actionBase.types'; | ||
|
||
export type ActionSubmitFieldProps = ActionBaseProps & FormId; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { FIELD_TYPE, FieldProps } from '../../types/public.types'; | ||
import { FormTypes, FieldProps } from '../../types/public.types'; | ||
|
||
export interface BuilderProps { | ||
fieldType: FIELD_TYPE; | ||
fieldType: FormTypes; | ||
fieldProps: FieldProps; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { TextFieldProps } from "@mui/material"; | ||
import { FormId, Id } from "../../types/public.types"; | ||
import { FormId, Id } from "../../../types/public.types"; | ||
|
||
export type TextProps = TextFieldProps & Id & FormId; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { TextProps } from "../components/text/text.types"; | ||
import { ActionSubmitFieldProps } from "../components/actions/submit/submit.types"; | ||
import { TextProps } from "../components/fields/text/text.types"; | ||
|
||
export type FormId = { formId: string }; | ||
|
||
export type Id = { | ||
id: string; | ||
}; | ||
|
||
export enum FIELD_TYPE { | ||
TEXT = 'text', | ||
} | ||
export type FormTypes = 'field-text' | "action-submit"; | ||
|
||
export type FieldProps = TextProps; | ||
export type FieldProps = TextProps | ActionSubmitFieldProps; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate
id
value for the entry withid: '4'
. Each entry in thegroupList
should have a uniqueid
to avoid potential rendering issues or unintended behavior.