feat: add callback for handleFormSubmit in EventType and AvailabilitySettings atoms (#22911)

* feat: Implement callback pattern in handleFormSubmit of EventTypePlatformWrapper

* feat: Implement callback pattern in handleFormSubmit of AvailabilitySettingsPlatformWrapper

* docs: add handleFormSubmit callback documentation for EventType and AvailabilitySettings atoms

* Update availability.tsx

* chore:added changelog

* update docs

---------

Co-authored-by: Rajiv Sahal <[email protected]>
This commit is contained in:
Somay ChauhanandRajiv Sahal authored and GitHub committed 2025-08-07 10:26:09 +02:00
1 parent cfda4757e4
commit d3fbc73a39
10 files changed
+129 -17

No files matched your search

+24 -1
View File
@@ -156,7 +156,16 @@ export function AvailabilityWithValidation() {
};
const handleSubmit = () => {
availabilityRef.current?.handleFormSubmit();
availabilityRef.current?.handleFormSubmit({
onSuccess: () => {
// Additional success handling logic here
console.log('Availability updated successfully');
},
onError: (error) => {
// Additional error handling logic here
console.error('Error updating availability:', error);
}
});
};
return (
@@ -184,6 +193,20 @@ export function AvailabilityWithValidation() {
| validateForm | Validates the current availability form state and returns a promise with validation results. |
| handleFormSubmit | Programmatically submits the availability form, triggering the same validation and submission flow as clicking the save button. Unlike `validateForm`, this method will check required fields and prevent submission unless all required fields are set |
### Callbacks
The `handleFormSubmit` method accepts an optional callbacks object with the following properties:
```typescript
type AvailabilitySettingsFormCallbacks = {
onSuccess?: () => void;
onError?: (error: Error) => void;
};
```
- **onSuccess**: Called when the form submission is successful. This allows you to execute additional logic after a successful update.
- **onError**: Called when an error occurs during form submission. The error parameter contains details about what went wrong, allowing you to handle specific error cases or display custom error messages.
The `validateForm` method returns an `AvailabilityFormValidationResult` object with:
- `isValid`: Boolean indicating if the form passed validation
- `errors`: Object containing any validation errors found
+24 -1
View File
@@ -218,7 +218,16 @@ export function EventTypeWithValidation(eventTypeId: number) {
};
const handleSubmit = () => {
eventTypeRef.current?.handleFormSubmit();
eventTypeRef.current?.handleFormSubmit({
onSuccess: () => {
// Additional success handling logic here
console.log('Event type updated successfully');
},
onError: (error) => {
// Additional error handling logic here
console.error('Error updating event type:', error);
}
});
};
return (
@@ -244,6 +253,20 @@ export function EventTypeWithValidation(eventTypeId: number) {
| validateForm | Validates the current event type form state and returns a promise with validation results. |
| handleFormSubmit | Programmatically submits the event type form, triggering the same validation and submission flow as clicking the save button. Unlike `validateForm`, this method will check required fields and prevent submission unless all required fields are set |
### Callbacks
The `handleFormSubmit` method accepts an optional callbacks object with the following properties:
```typescript
type EventTypeFormCallbacks = {
onSuccess?: () => void;
onError?: (error: Error) => void;
};
```
- **onSuccess**: Called when the form submission is successful. This allows you to execute additional logic after a successful update.
- **onError**: Called when an error occurs during form submission. The error parameter contains details about what went wrong, allowing you to handle specific error cases or display custom error messages.
The `validateForm` method returns an `EventTypeFormValidationResult` object with:
- `isValid`: Boolean indicating if the form passed validation
- `errors`: Object containing any validation errors found