///
import { FormPageState, ReportBI, WixPatternsContainer, ActionsBarConfig, SchemaSource, Schema } from '@wix/bex-core';
import { FieldValues, UseFormReturn } from 'react-hook-form';
import { EntityPageStateBIReporter } from './EntityPageStateBIReporter';
import { TypedEmitter } from '@wix/bex-core/events';
import { WixPatternsRouterState } from '../WixPatternsRouterState';
type OnSaveParams = {
widgetsFormData: {
[key: string]: any;
};
};
interface EntityPageStateParamsBase {
/**
* 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 contains a 'updatedEntity' object.
*/
onSave: (params: OnSaveParams) => Promise<{
updatedEntity: T;
}>;
/**
* An optional object with an optional message, or it can directly get a string message.
*/
saveSuccessToast?: {
message?: string;
} | string;
/**
* An optional function to display an error toast message when a save operation fails.
* @returns An object with a `message` and an `action` object. Alternatively, it can return an object with an optional `message` and a `tryAgain` flag, or a string message.
* The previous return types are still supported but are now deprecated.
*/
saveErrorToast?: (err: unknown, params: {
retry: () => void;
}) => {
message?: string;
/**
* @deprecated use `action` instead
*/
tryAgain?: boolean;
action?: {
text: string;
onClick: () => void;
};
} | string;
/**
* An optional function to transform the updated entity data before it is passed to the collection page.
* @param entity the updated entity.
* @returns an object representing the entity in the collection page.
*/
transformEntityToCollectionItem?: (entity: T) => any;
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.
* Must be passed if not using Patterns Router
*/
parentPageId?: string;
/**
* A string representing the path of the parent page.
* Must be passed if using Patterns Router
*/
parentPath?: string;
/**
* An object representing the router state
*/
routerState?: WixPatternsRouterState | null;
/**
* An optional object to override the actions bar.
*/
actionsBarConfig?: ActionsBarConfig;
/**
* An optional schema source describing how to load the schema and access
* the entity's data. When present, the page can read fields from the source
* instead of relying only on hand-wired fetch/onSave callbacks.
*/
schemaSource?: SchemaSource;
}
export type EntityPageStateParams = EntityPageStateParamsBase;
export interface EntityPageStateInterface {
}
export interface EntityPageWidgetState {
validate: () => Promise<{
isValid: boolean;
values?: any;
}>;
isDirty: boolean;
}
export declare class EntityPageState implements EntityPageStateInterface {
readonly fetch: EntityPageStateParams['fetch'];
readonly onSave: EntityPageStateParams['onSave'];
readonly saveSuccessToast?: EntityPageStateParams['saveSuccessToast'];
readonly saveErrorToast?: EntityPageStateParams['saveErrorToast'];
readonly transformEntityToCollectionItem: (entity: T) => any;
_entity: T | null;
_schema: Schema | null;
private readonly _parentPageId?;
private readonly _parentPath?;
actionsBarConfig?: EntityPageStateParams['actionsBarConfig'];
readonly schemaSource?: SchemaSource;
readonly container: WixPatternsContainer;
readonly reportBI: ReportBI;
readonly bi: EntityPageStateBIReporter;
_routerState: WixPatternsRouterState | null;
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;
setSchema(schema: Schema | null): void;
get schema(): Schema | null;
get isFetching(): boolean;
get form(): UseFormReturn;
set isSubmitSuccessful(flag: boolean);
get isFormDirty(): boolean;
set _isFormDirty(val: boolean);
get _withinRouter(): boolean;
onCancel(): void;
navigateToParent(updatedEntity?: any): void;
_showErrorToast(err: any, e?: React.BaseSyntheticEvent): void;
_showSuccessToast(): void;
handleSubmit(e?: React.BaseSyntheticEvent): Promise;
get initTask(): import("@wix/bex-core").TaskState;
get submitTask(): import("@wix/bex-core").TaskState;
private _checkPageParams;
}
export {};
//# sourceMappingURL=EntityPageState.d.ts.map