import { Input } from "@/src/components/ui/input"; import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/src/components/ui/form"; import { type UseFormReturn } from "react-hook-form"; import { type ActionDomain } from "@langfuse/shared"; import { api } from "@/src/utils/api"; import { SlackConnectionCard } from "@/src/features/slack/components/SlackConnectionCard"; import { ChannelSelector, type SlackChannel, } from "@/src/features/slack/components/ChannelSelector"; import { SlackTestMessageButton } from "@/src/features/slack/components/SlackTestMessageButton"; import { useState } from "react"; import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess"; interface SlackActionFormProps { form: UseFormReturn; disabled: boolean; projectId: string; action?: ActionDomain; } export const SlackActionForm: React.FC = ({ form, disabled, projectId, }) => { const [selectedChannel, setSelectedChannel] = useState( null, ); // Get Slack integration status const { data: integrationStatus } = api.slack.getIntegrationStatus.useQuery( { projectId }, { enabled: !!projectId }, ); // Check user permissions const hasAccess = useHasProjectAccess({ projectId, scope: "automations:CUD", }); // Handle channel selection const handleChannelSelect = (channel: SlackChannel) => { form.setValue("slack.channelId", channel.id); form.setValue("slack.channelName", channel.name); setSelectedChannel(channel); }; // Handle connection status change const handleConnectionChange = (connected: boolean) => { if (!connected) { // Clear channel selection when disconnected form.setValue("slack.channelId", ""); form.setValue("slack.channelName", ""); setSelectedChannel(null); } }; return (
{/* Slack Connection Card */} {/* Channel Selection - Only show when connected */} {integrationStatus?.isConnected && (
( Channel
Select the Slack channel where notifications will be sent.
)} /> {/* Hidden field for channel name */} } /> {/* Test Message Button - Only show when a channel is selected */} {selectedChannel && (

Test this channel to verify the bot can send messages.

)}
)}
); };