Files
twenty/packages/twenty-sdk/src/sdk/front-component-api/globals/frontComponentHostCommunicationApi.ts
T

50 lines
1.4 KiB
TypeScript

import {
type AppPath,
type CommandMenuPages,
type EnqueueSnackbarParams,
type NavigateOptions,
} from 'twenty-shared/types';
import { type getAppPath } from 'twenty-shared/utils';
export type NavigateFunction = <T extends AppPath>(
to: T,
params?: Parameters<typeof getAppPath<T>>[1],
queryParams?: Record<string, any>,
options?: NavigateOptions,
) => Promise<void>;
export type OpenSidePanelPageFunction = (params: {
page: CommandMenuPages;
pageTitle: string;
pageIcon?: string;
shouldResetSearchState?: boolean;
}) => Promise<void>;
export type UnmountFrontComponentFunction = () => Promise<void>;
export type EnqueueSnackbarFunction = (
params: EnqueueSnackbarParams,
) => Promise<void>;
export type CloseSidePanelFunction = () => Promise<void>;
export type RequestAccessTokenRefreshFunction = () => Promise<string>;
export type FrontComponentHostCommunicationApiStore = {
navigate?: NavigateFunction;
requestAccessTokenRefresh?: RequestAccessTokenRefreshFunction;
openSidePanelPage?: OpenSidePanelPageFunction;
unmountFrontComponent?: UnmountFrontComponentFunction;
enqueueSnackbar?: EnqueueSnackbarFunction;
closeSidePanel?: CloseSidePanelFunction;
};
declare global {
var frontComponentHostCommunicationApi: FrontComponentHostCommunicationApiStore;
}
globalThis.frontComponentHostCommunicationApi ??= {};
export const frontComponentHostCommunicationApi =
globalThis.frontComponentHostCommunicationApi;