@premieroctet/next-admin
Version:
Next-Admin provides a customizable and turnkey admin dashboard for applications built with Next.js and powered by the Prisma ORM. It aims to simplify the development process by providing a turnkey admin system that can be easily integrated into your proje
50 lines (49 loc) • 2.46 kB
JavaScript
import { jsx, jsxs } from "react/jsx-runtime";
import external_clsx_default from "clsx";
import { twMerge } from "tailwind-merge";
import { useClientActionDialog } from "../context/ClientActionDialogContext.mjs";
import { useI18n } from "../context/I18nContext.mjs";
import { useAction } from "../hooks/useAction.mjs";
import { DropdownItem } from "./radix/Dropdown.mjs";
import { SimpleTooltip } from "./radix/Tooltip.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__heroicons_react_24_outline_ca17940a__ from "@heroicons/react/24/outline";
const ActionDropdownItem = ({ action, resource, resourceIds })=>{
const { t } = useI18n();
const { runAction } = useAction(resource, resourceIds);
const { open: openActionDialog } = useClientActionDialog();
const isClientAction = "component" in action && "type" in action && "dialog" === action.type;
const Icon = action.icon && __WEBPACK_EXTERNAL_MODULE__heroicons_react_24_outline_ca17940a__[action.icon];
const enabledAction = void 0 === action.allowedIds || action.allowedIds.length > 0 && resourceIds.every((id)=>action.allowedIds?.includes(id));
if (!enabledAction && 1 === resourceIds.length) return null;
const component = /*#__PURE__*/ jsxs(DropdownItem, {
disabled: !enabledAction,
className: twMerge(external_clsx_default("flex cursor-pointer items-center gap-2 rounded-md px-2 py-1", {
"text-red-700 dark:text-red-400": "destructive" === action.style,
"hover:bg-red-50": "destructive" === action.style,
"text-nextadmin-content-emphasis/50 dark:text-dark-nextadmin-content-emphasis/50 cursor-not-allowed": !enabledAction
})),
onClick: (evt)=>{
if (!enabledAction) return;
evt.stopPropagation();
if (isClientAction) openActionDialog({
action: action,
resource,
resourceIds
});
else runAction(action);
},
children: [
Icon && /*#__PURE__*/ jsx(Icon, {
className: "h-5 w-5"
}),
t(action.title)
]
}, action.title);
if (!enabledAction && resourceIds.length > 1) return /*#__PURE__*/ jsx(SimpleTooltip, {
text: t("actions.some_failed_condition"),
children: component
});
return component;
};
const components_ActionDropdownItem = ActionDropdownItem;
export { components_ActionDropdownItem as default };