2025-12-26 14:37:23 +05:30
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import type { FC } from "react";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import type { Action, ActionsConfig } from "./schema";
|
|
|
|
|
|
|
|
|
|
interface ActionButtonsProps {
|
2025-12-26 17:49:56 +05:30
|
|
|
actions?: Action[] | ActionsConfig;
|
|
|
|
|
onAction?: (actionId: string) => void;
|
|
|
|
|
disabled?: boolean;
|
2025-12-26 14:37:23 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const ActionButtons: FC<ActionButtonsProps> = ({ actions, onAction, disabled }) => {
|
2025-12-26 17:49:56 +05:30
|
|
|
if (!actions) return null;
|
2025-12-26 14:37:23 +05:30
|
|
|
|
2025-12-26 17:49:56 +05:30
|
|
|
// Normalize actions to array format
|
|
|
|
|
const actionArray: Action[] = Array.isArray(actions)
|
|
|
|
|
? actions
|
|
|
|
|
: ([
|
|
|
|
|
actions.confirm && { ...actions.confirm, id: "confirm" },
|
|
|
|
|
actions.cancel && { ...actions.cancel, id: "cancel" },
|
|
|
|
|
].filter(Boolean) as Action[]);
|
2025-12-26 14:37:23 +05:30
|
|
|
|
2025-12-26 17:49:56 +05:30
|
|
|
if (actionArray.length === 0) return null;
|
2025-12-26 14:37:23 +05:30
|
|
|
|
2025-12-26 17:49:56 +05:30
|
|
|
return (
|
|
|
|
|
<div className="flex flex-wrap gap-2 pt-3">
|
|
|
|
|
{actionArray.map((action) => (
|
|
|
|
|
<Button
|
|
|
|
|
key={action.id}
|
|
|
|
|
variant={action.variant || "default"}
|
|
|
|
|
size="sm"
|
|
|
|
|
disabled={disabled || action.disabled}
|
|
|
|
|
onClick={() => onAction?.(action.id)}
|
|
|
|
|
>
|
|
|
|
|
{action.label}
|
|
|
|
|
</Button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-12-26 14:37:23 +05:30
|
|
|
};
|