///
import { WixPatternsContainer, FormPageState, ReportBI, TaskState } from '@wix/bex-core';
import { UseFormReturn, FieldValues } from 'react-hook-form';
import { EntityPageStateBIReporter } from './EntityPageStateBIReporter';
import { TypedEmitter } from '@wix/bex-core/events';
type OnSaveParams = {
widgetsFormData: {
[key: string]: any;
};
};
export interface EntityPageStateParams {
/**
* A function that fetches the entity data.
* @returns a promise that resolves to an object containing the entity.
*/
fetch: () => Promise<{
entity: T | undefined;
}>;
/**
* A function to handle the save action.
* @returns promise that resolves to an object that may contain a 'successToastText' string, or it may resolve to void.
*/
onSave: (params: OnSaveParams) => Promise<{
successToastText?: string;
} | void>;
/**
* An optional function to display an error toast message when a save operation fails.
* @returns an object with an optional message and a `tryAgain` flag, or it can directly return a string message.
*/
saveErrorToast?: (err: unknown) => {
message?: string;
tryAgain?: boolean;
} | string;
/**
* An object representing the form state and methods, typically returned by a useForm hook.
*/
form: UseFormReturn;
/**
* An object representing the container, possibly for dependency injection or component management.
*/
container: WixPatternsContainer;
/**
* A string representing the ID of the parent page.
*/
parentPageId: string;
}
export interface EntityPageStateInterface {
}
export interface EntityPageWidgetState {
validate: () => Promise<{
isValid: boolean;
values?: any;
}>;
isDirty: boolean;
}
export declare class EntityPageState implements EntityPageStateInterface {
readonly initTask: TaskState;
readonly submitTask: TaskState;
readonly fetch: EntityPageStateParams['fetch'];
readonly onSave: EntityPageStateParams['onSave'];
readonly saveErrorToast?: EntityPageStateParams['saveErrorToast'];
_entity: T | null;
private readonly _form;
private readonly _parentPageId;
readonly container: WixPatternsContainer;
readonly reportBI: ReportBI;
readonly bi: EntityPageStateBIReporter;
private _isSubmitSuccessful?;
private _isFormDirty?;
readonly formPage: FormPageState;
readonly events: TypedEmitter<{
save: () => void;
saveError: (err: unknown) => void;
}>;
constructor(params: EntityPageStateParams);
init(): () => void;
retryFetch(): void;
setEntity(newEntity: T | null): void;
get entity(): T | null;
get isFetching(): boolean;
get form(): UseFormReturn;
set isSubmitSuccessful(flag: boolean);
set isFormDirty(flag: boolean);
onCancel(): void;
navigateToParent(): void;
_showErrorToast(err: any, e?: React.BaseSyntheticEvent): void;
_showSuccessToast(successToastText?: string): void;
handleSubmit(e?: React.BaseSyntheticEvent): Promise;
}
export {};
//# sourceMappingURL=EntityPageState.d.ts.map