general-assistant
Version:
General Assistant components
49 lines (48 loc) • 2.89 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useEffect, useMemo, useState, useContext } from 'react';
import { useStore } from 'zustand';
import StoreContext from '../../../_store/StoreContext';
import { find } from 'lodash';
export default function ComposerRightAddition() {
const dataStore = useContext(StoreContext);
const { getConfig, GlobalCtxs, MyHandlers, selectedAite, setSelectedAite, confirmAite, setConfirmAite, } = useStore(dataStore, (state) => ({
getConfig: state.getConfig,
GlobalCtxs: state.GlobalCtxs,
MyHandlers: state.MyHandlers,
selectedAite: state.selectedAite,
setSelectedAite: state.setSelectedAite,
confirmAite: state.confirmAite,
setConfirmAite: state.setConfirmAite,
}));
const { inputProps, inputOrderCaution } = getConfig();
const { currentKey, ContentRender, list } = inputOrderCaution || {};
const { RightAdditionContainer } = inputProps;
const { onRightAdditionClose } = MyHandlers;
useEffect(() => {
setConfirmAite(find(list, (item) => item.key === currentKey));
}, [list, currentKey]);
useEffect(() => {
dealCautionRender(confirmAite);
}, [confirmAite]);
const [renderHandle, setRenderHandle] = useState();
const isOpen = useMemo(() => {
return !!confirmAite || typeof RightAdditionContainer === 'function';
}, [confirmAite, RightAdditionContainer]);
function dealCautionRender(opt) {
if (!!opt) {
if (typeof ContentRender !== 'function') {
setRenderHandle(_jsxs("div", { className: 'DS-GA-pl-3 DS-GA-flex DS-GA-justify-start DS-GA-items-center DS-GA-gap-1', children: ["@", _jsx("div", { className: 'DS-GA-min-h-7 DS-GA-min-w-7 DS-GA-rounded-full DS-GA-text-lg DS-GA-flex DS-GA-justify-center DS-GA-items-center', children: opt.ItemIcon }), _jsx("div", { className: 'DS-GA-text-sm', children: opt.ItemName }), _jsx("div", { className: 'DS-GA-text-xs DS-GA-text-gray-500', children: opt.ItemDesc })] }));
}
else {
setRenderHandle(ContentRender(opt));
}
return true;
}
return false;
}
return _jsx(_Fragment, { children: isOpen && GlobalCtxs && (RightAdditionContainer || renderHandle) &&
_jsxs("div", { className: 'DS-GA-w-full DS-GA-flex DS-GA-justify-between DS-GA-items-center', children: [renderHandle ? renderHandle : _jsx(RightAdditionContainer, { ctx: GlobalCtxs }), _jsx("i", { className: 'DS-GA-inline-block iconfont-assistant icon-del DS-GA-text-xs DS-GA-m-4 DS-GA-text-gray-500 DS-GA-cursor-pointer', onClick: () => {
setConfirmAite(undefined);
typeof onRightAdditionClose === 'function' && onRightAdditionClose(GlobalCtxs);
} })] }) });
}