import { Entity, EntityStatus, EntityValues, ResolvedEntitySchema } from "./entities"; import { FireCMSContext } from "./firecms_context"; /** * This interface defines all the callbacks that can be used when an entity * is being created, updated or deleted. * Useful for adding your own logic or blocking the execution of the operation. * @category Models */ export interface EntityCallbacks { /** * Callback used when save is successful * @param entitySaveProps */ onSaveSuccess?(entitySaveProps: EntityOnSaveProps): Promise | void; /** * Callback used when saving fails * @param entitySaveProps */ onSaveFailure?(entitySaveProps: EntityOnSaveProps): Promise | void; /** * Callback used before saving, you need to return the values that will get * saved. If you throw an error in this method the process stops, and an * error snackbar gets displayed. * @param entitySaveProps */ onPreSave?(entitySaveProps: EntityOnSaveProps): Promise>> | Partial>; /** * Callback used after the entity is deleted. * If you throw an error in this method the process stops, and an * error snackbar gets displayed. * * @param entityDeleteProps */ onPreDelete?(entityDeleteProps: EntityOnDeleteProps): void; /** * Callback used after the entity is deleted. * * @param entityDeleteProps */ onDelete?(entityDeleteProps: EntityOnDeleteProps): void; } /** * Parameters passed to hooks when an entity is saved * @category Models */ export interface EntityOnSaveProps { /** * Resolved schema of the entity */ schema: ResolvedEntitySchema; /** * Full path where this entity is being saved */ path: string; /** * Id of the entity or undefined if new */ entityId?: string; /** * Values being saved */ values: Partial>; /** * Previous values */ previousValues?: Partial>; /** * New or existing entity */ status: EntityStatus; /** * Context of the app status */ context: FireCMSContext; } /** * Parameters passed to hooks when an entity is deleted * @category Models */ export interface EntityOnDeleteProps { /** * Schema of the entity being deleted */ schema: ResolvedEntitySchema; /** * Path of the parent collection */ path: string; /** * Deleted entity id */ entityId: string; /** * Deleted entity */ entity: Entity; /** * Context of the app status */ context: FireCMSContext; }