# Introduction Avoid having multiple `isDefined` definition across our pacakges Also avoid importing `isDefined` from `twenty-ui` which exposes a huge barrel for a such little util function ## In a nutshell Removed own `isDefined.ts` definition from `twenty-ui` `twenty-front` and `twenty-server` to move it to `twenty-shared`. Updated imports for each packages, and added explicit dependencies to `twenty-shared` if not already in place Related PR https://github.com/twentyhq/twenty/pull/9941
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { ActionMenuEntry } from '@/action-menu/types/ActionMenuEntry';
|
|
import { isDefined } from 'twenty-shared';
|
|
|
|
export const wrapActionInCallbacks = ({
|
|
action,
|
|
onActionStartedCallback,
|
|
onActionExecutedCallback,
|
|
}: {
|
|
action: ActionMenuEntry;
|
|
onActionStartedCallback?: (action: { key: string }) => Promise<void> | void;
|
|
onActionExecutedCallback?: (action: { key: string }) => Promise<void> | void;
|
|
}) => {
|
|
const onClickWithCallbacks = isDefined(action.ConfirmationModal)
|
|
? action.onClick
|
|
: async () => {
|
|
await onActionStartedCallback?.({ key: action.key });
|
|
await action.onClick?.();
|
|
await onActionExecutedCallback?.({ key: action.key });
|
|
};
|
|
|
|
const ConfirmationModalWithCallbacks = isDefined(action.ConfirmationModal)
|
|
? {
|
|
...action.ConfirmationModal,
|
|
props: {
|
|
...action.ConfirmationModal.props,
|
|
onConfirmClick: async () => {
|
|
await onActionStartedCallback?.({ key: action.key });
|
|
await action.ConfirmationModal?.props.onConfirmClick?.();
|
|
await onActionExecutedCallback?.({ key: action.key });
|
|
},
|
|
},
|
|
}
|
|
: undefined;
|
|
|
|
return {
|
|
...action,
|
|
onClick: onClickWithCallbacks,
|
|
ConfirmationModal: ConfirmationModalWithCallbacks,
|
|
};
|
|
};
|