feat: expose form validation methods from EventTypePlatformWrapper (#22655)
* feat: expose form validation methods from EventTypePlatformWrapper - Add validateForm and handleFormSubmit methods to onFormStateChange prop - Update useEventTypeForm hook to return validateForm method - Add proper TypeScript types for form validation result - Enable external form validation and submission capabilities Co-Authored-By: [email protected] <[email protected]> * fix: correct forwardRef syntax to resolve parsing errors - Fix forwardRef parameter destructuring syntax - Use proper props parameter pattern for forwardRef components - Ensure prettier can parse the file correctly Co-Authored-By: [email protected] <[email protected]> * feat: add form validation and submission handlers to event types platform wrapper * refactor: move form validation and submit handlers from hook to wrapper component * fix: add ref to the save button for proper form validation * feat: extend ref-based validation API to AvailabilitySettingsPlatformWrapper - Add AvailabilityFormValidationResult and AvailabilitySettingsPlatformWrapperRef types - Implement forwardRef pattern in AvailabilitySettings component with save button ref - Add validateForm and handleFormSubmit methods using useImperativeHandle - Update AvailabilitySettingsPlatformWrapper to support ref forwarding - Add comprehensive documentation for ref-based validation API in both event-type.mdx and availability-settings.mdx - Follow same patterns established in EventTypePlatformWrapper for consistency Co-Authored-By: [email protected] <[email protected]> * refactor: rename AvailabilitySettingsPlatformWrapperRef to AvailabilitySettingsFormRef * feat: add ref-based validation pattern to availability example page - Mirror the ref-based validation implementation from event-types.tsx - Add useRef, handleValidate, and handleSubmit functions - Demonstrate validateForm() and handleFormSubmit() methods - Add validation and submit buttons to showcase the new API - Use AvailabilitySettingsFormRef type for proper typing Co-Authored-By: [email protected] <[email protected]> * refactor: remove unused state variables * docs: clarify form validation behavior for availability and event type atoms * chore: remove console.logs --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Somay Chauhan <[email protected]>
This commit is contained in:
15 files changed
+755
-455
No files matched your search
@@ -64,6 +64,7 @@ export type EventTypeComponentProps = EventTypeSetupProps & {
|
||||
tabName: (typeof tabs)[number];
|
||||
tabsNavigation: VerticalTabItemProps[];
|
||||
allowDelete?: boolean;
|
||||
saveButtonRef?: React.RefObject<HTMLButtonElement>;
|
||||
};
|
||||
|
||||
export const EventType = ({
|
||||
@@ -82,6 +83,7 @@ export const EventType = ({
|
||||
handleSubmit,
|
||||
children,
|
||||
allowDelete = true,
|
||||
saveButtonRef,
|
||||
}: EventTypeComponentProps) => {
|
||||
const [animationParentRef] = useAutoAnimate<HTMLDivElement>();
|
||||
|
||||
@@ -101,7 +103,8 @@ export const EventType = ({
|
||||
isDeleting={isDeleting}
|
||||
isPlatform={isPlatform}
|
||||
allowDelete={allowDelete}
|
||||
tabsNavigation={tabsNavigation}>
|
||||
tabsNavigation={tabsNavigation}
|
||||
saveButtonRef={saveButtonRef}>
|
||||
<Form form={formMethods} id="event-type-form" handleSubmit={handleSubmit}>
|
||||
<div ref={animationParentRef}>{tabMap[tabName]}</div>
|
||||
</Form>
|
||||
|
||||
@@ -47,6 +47,7 @@ type Props = {
|
||||
isPlatform?: boolean;
|
||||
tabsNavigation: VerticalTabItemProps[];
|
||||
allowDelete?: boolean;
|
||||
saveButtonRef?: React.RefObject<HTMLButtonElement>;
|
||||
};
|
||||
|
||||
function EventTypeSingleLayout({
|
||||
@@ -64,6 +65,7 @@ function EventTypeSingleLayout({
|
||||
isPlatform,
|
||||
tabsNavigation,
|
||||
allowDelete = true,
|
||||
saveButtonRef,
|
||||
}: Props) {
|
||||
const { t } = useLocale();
|
||||
const eventTypesLockedByOrg = eventType.team?.parent?.organizationSettings?.lockEventTypeCreationForUsers;
|
||||
@@ -262,6 +264,7 @@ function EventTypeSingleLayout({
|
||||
</Dropdown>
|
||||
<div className="border-default border-l-2" />
|
||||
<Button
|
||||
ref={saveButtonRef}
|
||||
className="ml-4 lg:ml-0"
|
||||
type="submit"
|
||||
loading={isUpdateMutationLoading}
|
||||
|
||||
@@ -220,3 +220,13 @@ export type SelectClassNames = {
|
||||
label?: string;
|
||||
container?: string;
|
||||
};
|
||||
|
||||
export type FormValidationResult = {
|
||||
isValid: boolean;
|
||||
errors: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export interface EventTypePlatformWrapperRef {
|
||||
validateForm: () => Promise<FormValidationResult>;
|
||||
handleFormSubmit: () => void;
|
||||
}
|
||||
Reference in new issue
Block a user