31 lines
803 B
TypeScript
31 lines
803 B
TypeScript
import type { Elements } from '../config/map/actions';
|
|
import { useProcessContext } from '@/process/hooks/common';
|
|
import { useStatus } from '@/stores/calculation/statuses/hooks';
|
|
import { observer } from 'mobx-react-lite';
|
|
import type { ComponentType } from 'react';
|
|
|
|
type BuilderProps = {
|
|
elementName: Elements;
|
|
valueName: string;
|
|
};
|
|
|
|
export default function buildAction<T>(
|
|
Component: ComponentType<T>,
|
|
{ elementName, valueName: processName }: BuilderProps
|
|
) {
|
|
return observer((props: T) => {
|
|
const status = useStatus(elementName);
|
|
|
|
const context = useProcessContext();
|
|
|
|
return (
|
|
<Component
|
|
action={() =>
|
|
import(`process/${processName}/action`).then((module) => module.action(context))}
|
|
status={status}
|
|
{...props}
|
|
/>
|
|
);
|
|
});
|
|
}
|