Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

improvement(ui): migrate project workflow integrations settings to v3

andrewhuhh0845f80d824f
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/WorkflowIntegrationTab.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/WorkflowIntegrationTab.tsx
index 2dbb43fe64..a0c89767e9 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/WorkflowIntegrationTab.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/WorkflowIntegrationTab.tsx
@@ -1,21 +1,38 @@
-import { BsMicrosoftTeams, BsSlack } from "react-icons/bs";
-import { faGear, faPlus } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { Plus, Trash2 } from "lucide-react";
import { createNotification } from "@app/components/notifications";
-import { OrgPermissionCan } from "@app/components/permissions";
+import { ProjectPermissionCan } from "@app/components/permissions";
import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogMedia,
+ AlertDialogTitle,
Button,
- DeleteActionModal,
- EmptyState,
+ Card,
+ CardAction,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ Empty,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyTitle,
+ Skeleton,
Table,
- TableContainer,
- TBody,
- Td,
- THead,
- Tr
-} from "@app/components/v2";
-import { OrgPermissionActions, OrgPermissionSubjects, useProject } from "@app/context";
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow
+} from "@app/components/v3";
+import { ProjectPermissionActions, ProjectPermissionSub, useProject } from "@app/context";
+import { withProjectPermission } from "@app/hoc";
import { usePopUp } from "@app/hooks";
import {
useDeleteProjectWorkflowIntegration,
@@ -23,141 +40,171 @@ import {
} from "@app/hooks/api";
import { WorkflowIntegrationPlatform } from "@app/hooks/api/workflowIntegrations/types";
-import { AddWorkflowIntegrationModal } from "./components/AddWorkflowIntegrationModal";
-import { EditWorkflowIntegrationModal } from "./components/EditWorkflowIntegrationModal";
+import { AddWorkflowIntegrationSheet } from "./components/AddWorkflowIntegrationSheet";
+import { EditWorkflowIntegrationSheet } from "./components/EditWorkflowIntegrationSheet";
import { MicrosoftTeamsConfigRow } from "./components/MicrosoftTeamsConfigRow";
import { SlackConfigRow } from "./components/SlackConfigRow";
+import { WORKFLOW_INTEGRATION_PLATFORM_LABELS } from "./constants";
-export const renderProvider = (integration: WorkflowIntegrationPlatform) => {
- if (integration === WorkflowIntegrationPlatform.SLACK) {
- return <BsSlack />;
- }
+export const WorkflowIntegrationTab = withProjectPermission(
+ () => {
+ const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp([
+ "addWorkflowIntegration",
+ "removeIntegration",
+ "editIntegration"
+ ] as const);
- if (integration === WorkflowIntegrationPlatform.MICROSOFT_TEAMS) {
- return <BsMicrosoftTeams />;
- }
+ const { currentProject } = useProject();
+ const { data: slackConfig, isPending: isSlackConfigLoading } =
+ useGetWorkspaceWorkflowIntegrationConfig({
+ projectId: currentProject?.id ?? "",
+ integration: WorkflowIntegrationPlatform.SLACK
+ });
- return null;
-};
+ const { data: microsoftTeamsConfig, isPending: isMicrosoftTeamsConfigLoading } =
+ useGetWorkspaceWorkflowIntegrationConfig({
+ projectId: currentProject?.id ?? "",
+ integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS
+ });
-export const WorkflowIntegrationTab = () => {
- const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp([
- "addWorkflowIntegration",
- "removeIntegration",
- "editIntegration"
- ] as const);
+ const { mutateAsync: deleteIntegration } = useDeleteProjectWorkflowIntegration();
- const { currentProject } = useProject();
- const { data: slackConfig, isPending: isSlackConfigLoading } =
- useGetWorkspaceWorkflowIntegrationConfig({
- projectId: currentProject?.id ?? "",
- integration: WorkflowIntegrationPlatform.SLACK
- });
+ const isConfigLoading = isSlackConfigLoading || isMicrosoftTeamsConfigLoading;
+ const hasConfiguredIntegration = !!slackConfig || !!microsoftTeamsConfig;
- const { data: microsoftTeamsConfig, isPending: isMicrosoftTeamsConfigLoading } =
- useGetWorkspaceWorkflowIntegrationConfig({
- projectId: currentProject?.id ?? "",
- integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS
- });
+ const removeIntegrationData = popUp.removeIntegration.data as
+ | { integration: WorkflowIntegrationPlatform; integrationId: string }
+ | undefined;
+ const removeIntegrationLabel = removeIntegrationData
+ ? WORKFLOW_INTEGRATION_PLATFORM_LABELS[removeIntegrationData.integration]
+ : "workflow";
- const { mutateAsync: deleteIntegration } = useDeleteProjectWorkflowIntegration();
+ const handleRemoveIntegration = async () => {
+ if (!currentProject.id || !removeIntegrationData) {
+ return;
+ }
- const handleRemoveIntegration = async (
- integrationType: WorkflowIntegrationPlatform,
- integrationId: string
- ) => {
- if (!currentProject.id) {
- return;
- }
+ await deleteIntegration({
+ projectId: currentProject.id,
+ integration: removeIntegrationData.integration,
+ integrationId: removeIntegrationData.integrationId
+ });
- await deleteIntegration({
- projectId: currentProject?.id ?? "",
- integration: integrationType,
- integrationId
- });
+ handlePopUpClose("removeIntegration");
+ createNotification({
+ type: "success",
+ text: `Removed ${removeIntegrationLabel} integration from this project`
+ });
+ };
- createNotification({
- type: "success",
- text: `Successfully removed ${integrationType.replace("-", " ").replace(/\b\w/g, (char) => char.toUpperCase())} integration`
- });
- };
-
- return (
- <div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
- <div className="flex justify-between">
- <p className="text-xl font-medium text-mineshaft-100">Workflow Integrations</p>
- <OrgPermissionCan I={OrgPermissionActions.Create} an={OrgPermissionSubjects.Settings}>
- {(isAllowed) => (
- <Button
- onClick={() => {
- handlePopUpOpen("addWorkflowIntegration");
- }}
- isDisabled={!isAllowed}
- leftIcon={<FontAwesomeIcon icon={faPlus} />}
+ return (
+ <Card>
+ <CardHeader>
+ <CardTitle>Workflow Integrations</CardTitle>
+ <CardDescription>
+ Send notifications for access requests, secret approval requests, and secret sync errors
+ to Slack or Microsoft Teams.
+ </CardDescription>
+ <CardAction>
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Edit}
+ a={ProjectPermissionSub.Settings}
>
- Add
- </Button>
+ {(isAllowed) => (
+ <Button
+ variant="project"
+ size="sm"
+ onClick={() => handlePopUpOpen("addWorkflowIntegration")}
+ isDisabled={!isAllowed}
+ >
+ <Plus />
+ Add integration
+ </Button>
+ )}
+ </ProjectPermissionCan>
+ </CardAction>
+ </CardHeader>
+ <CardContent>
+ {!isConfigLoading && !hasConfiguredIntegration ? (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyTitle>No workflow integrations configured</EmptyTitle>
+ <EmptyDescription>
+ Add a workflow integration to send this project&apos;s notifications to Slack or
+ Microsoft Teams.
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ ) : (
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-1/5">Provider</TableHead>
+ <TableHead>Access request notifications</TableHead>
+ <TableHead>Secret request notifications</TableHead>
+ <TableHead>Secret sync error notifications</TableHead>
+ <TableHead className="w-px text-right" aria-label="Actions" />
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {isConfigLoading &&
+ Array.from({ length: 2 }).map((_, idx) => (
+ // eslint-disable-next-line react/no-array-index-key
+ <TableRow key={`workflow-integration-skeleton-${idx}`}>
+ <TableCell colSpan={5}>
+ <Skeleton className="h-5 w-full" />
+ </TableCell>
+ </TableRow>
+ ))}
+ {!isConfigLoading && (
+ <>
+ <SlackConfigRow handlePopUpOpen={handlePopUpOpen} slackConfig={slackConfig} />
+ <MicrosoftTeamsConfigRow
+ handlePopUpOpen={handlePopUpOpen}
+ microsoftTeamsConfig={microsoftTeamsConfig}
+ />
+ </>
+ )}
+ </TableBody>
+ </Table>
)}
- </OrgPermissionCan>
- </div>
- <p className="mb-4 text-gray-400">
- Connect Infisical to other platforms for notification and workflow integrations.
- </p>
- <TableContainer>
- {!!slackConfig || !!microsoftTeamsConfig ? (
- <Table>
- <THead>
- <Tr>
- <Td>Provider</Td>
- <Td>Access Request Notifications Destination</Td>
- <Td>Secret Request Notifications Destination</Td>
- <Td>Secret Sync Error Notifications Destination</Td>
- </Tr>
- </THead>
- <TBody>
- <SlackConfigRow
- handlePopUpOpen={handlePopUpOpen}
- isSlackConfigLoading={isSlackConfigLoading}
- slackConfig={slackConfig}
- />
- <MicrosoftTeamsConfigRow
- handlePopUpOpen={handlePopUpOpen}
- isMicrosoftTeamsConfigLoading={isMicrosoftTeamsConfigLoading}
- microsoftTeamsConfig={microsoftTeamsConfig}
- />
- </TBody>
- </Table>
- ) : (
- <div className="flex h-full w-full items-center justify-center">
- <EmptyState
- title="No project workflow integrations configured. Add a new workflow integration to get started"
- icon={faGear}
- />
- </div>
- )}
- </TableContainer>
- <AddWorkflowIntegrationModal
- isOpen={popUp.addWorkflowIntegration.isOpen}
- onToggle={(state) => handlePopUpToggle("addWorkflowIntegration", state)}
- />
- <DeleteActionModal
- isOpen={popUp.removeIntegration.isOpen}
- title="Are you sure you want to remove this integration?"
- onChange={(isOpen) => handlePopUpToggle("removeIntegration", isOpen)}
- deleteKey="confirm"
- onDeleteApproved={async () => {
- await handleRemoveIntegration(
- popUp.removeIntegration.data?.integration,
- popUp.removeIntegration.data?.integrationId
- );
- handlePopUpClose("removeIntegration");
- }}
- />
- <EditWorkflowIntegrationModal
- isOpen={popUp.editIntegration.isOpen}
- onClose={() => handlePopUpClose("editIntegration")}
- integration={popUp.editIntegration.data?.integration}
- />
- </div>
- );
-};
+ </CardContent>
+ <AddWorkflowIntegrationSheet
+ isOpen={popUp.addWorkflowIntegration.isOpen}
+ onOpenChange={(state) => handlePopUpToggle("addWorkflowIntegration", state)}
+ />
+ <EditWorkflowIntegrationSheet
+ isOpen={popUp.editIntegration.isOpen}
+ onClose={() => handlePopUpClose("editIntegration")}
+ integration={popUp.editIntegration.data?.integration}
+ />
+ <AlertDialog
+ open={popUp.removeIntegration.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("removeIntegration", isOpen)}
+ >
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogMedia>
+ <Trash2 />
+ </AlertDialogMedia>
+ <AlertDialogTitle>
+ Remove {removeIntegrationLabel} integration from this project?
+ </AlertDialogTitle>
+ <AlertDialogDescription>
+ This project will stop sending notifications to {removeIntegrationLabel}. You can
+ add the integration again later.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction variant="danger" onClick={handleRemoveIntegration}>
+ Remove
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ </Card>
+ );
+ },
+ { action: ProjectPermissionActions.Read, subject: ProjectPermissionSub.Settings }
+);
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/AddWorkflowIntegrationModal.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/AddWorkflowIntegrationModal.tsx
deleted file mode 100644
index 3ebeba7661..0000000000
--- a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/AddWorkflowIntegrationModal.tsx
+++ /dev/null
@@ -1,153 +0,0 @@
-import { useState } from "react";
-import { BsMicrosoftTeams } from "react-icons/bs";
-import { faSlack } from "@fortawesome/free-brands-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { AnimatePresence, motion } from "framer-motion";
-import { twMerge } from "tailwind-merge";
-
-import { Modal, ModalContent } from "@app/components/v2";
-import { useProject } from "@app/context";
-import { useGetWorkspaceWorkflowIntegrationConfig } from "@app/hooks/api";
-import { WorkflowIntegrationPlatform } from "@app/hooks/api/workflowIntegrations/types";
-
-import { MicrosoftTeamsIntegrationForm } from "./MicrosoftTeamsIntegrationForm";
-import { SlackIntegrationForm } from "./SlackIntegrationForm";
-
-type Props = {
- isOpen?: boolean;
- onToggle: (isOpen: boolean) => void;
-};
-
-enum WizardSteps {
- SelectPlatform = "select-platform",
- PlatformInputs = "platform-inputs"
-}
-
-const PLATFORM_LIST = [
- {
- icon: <FontAwesomeIcon icon={faSlack} size="lg" />,
- platform: WorkflowIntegrationPlatform.SLACK,
- title: "Slack"
- },
- {
- icon: <BsMicrosoftTeams className="text-lg" />,
- platform: WorkflowIntegrationPlatform.MICROSOFT_TEAMS,
- title: "Microsoft Teams"
- }
-];
-
-export const AddWorkflowIntegrationModal = ({ isOpen, onToggle }: Props) => {
- const [wizardStep, setWizardStep] = useState(WizardSteps.SelectPlatform);
- const [selectedPlatform, setSelectedPlatform] = useState<string | null>(null);
-
- const { currentProject } = useProject();
- const { data: microsoftTeamsConfig } = useGetWorkspaceWorkflowIntegrationConfig({
- projectId: currentProject?.id ?? "",
- integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS
- });
-
- const { data: slackConfig } = useGetWorkspaceWorkflowIntegrationConfig({
- projectId: currentProject?.id ?? "",
- integration: WorkflowIntegrationPlatform.SLACK
- });
-
- const microsoftTeamsConfigured = !!microsoftTeamsConfig;
- const slackConfigured = !!slackConfig;
-
- const handleFormReset = (state: boolean = false) => {
- onToggle(state);
- setWizardStep(WizardSteps.SelectPlatform);
- setSelectedPlatform(null);
- };
-
- return (
- <Modal isOpen={isOpen} onOpenChange={(state) => handleFormReset(state)}>
- <ModalContent
- title={`Add a ${selectedPlatform?.replace("-", " ").replace(/\b\w/g, (char) => char.toUpperCase()) ?? "workflow"} integration`}
- className="my-4"
- >
- <AnimatePresence mode="wait">
- {wizardStep === WizardSteps.SelectPlatform && (
- <motion.div
- key="select-type-step"
- transition={{ duration: 0.1 }}
- initial={{ opacity: 0, translateX: 30 }}
- animate={{ opacity: 1, translateX: 0 }}
- exit={{ opacity: 0, translateX: -30 }}
- >
- <div className="mb-4 text-mineshaft-300">Select a workflow integration</div>
- <div className="flex items-center space-x-4">
- {PLATFORM_LIST.map(({ icon, platform, title }) => {
- const isConfigured =
- (platform === WorkflowIntegrationPlatform.MICROSOFT_TEAMS &&
- microsoftTeamsConfigured) ||
- (platform === WorkflowIntegrationPlatform.SLACK && slackConfigured);
-
- return (
- <div className="relative" key={platform}>
- <div
- className={twMerge(
- "flex h-32 w-36 cursor-pointer flex-col items-center space-y-4 rounded-sm border border-mineshaft-500 bg-bunker-600 p-6 transition-all hover:border-primary/70 hover:bg-primary/10 hover:text-white",
- isConfigured && "border-primary/50 opacity-60"
- )}
- role="button"
- tabIndex={0}
- onClick={() => {
- setSelectedPlatform(platform);
- setWizardStep(WizardSteps.PlatformInputs);
- }}
- onKeyDown={(evt) => {
- if (evt.key === "Enter") {
- setSelectedPlatform(platform);
- setWizardStep(WizardSteps.PlatformInputs);
- }
- }}
- >
- <div>{icon}</div>
- <div className="text-center text-sm whitespace-pre-wrap">{title}</div>
- </div>
- {isConfigured && (
- <div className="absolute right-0 bottom-0 left-0 z-30 h-full">
- <div className="relative h-full">
- <div className="absolute right-0 bottom-0 w-full flex-row items-center overflow-hidden rounded-b-md bg-primary px-2 py-0.5 text-center text-xs whitespace-nowrap text-black">
- Already Configured
- </div>
- </div>
- </div>
- )}
- </div>
- );
- })}
- </div>
- </motion.div>
- )}
-
- {wizardStep === WizardSteps.PlatformInputs &&
- selectedPlatform === WorkflowIntegrationPlatform.SLACK && (
- <motion.div
- key="platform-inputs-step-slack"
- transition={{ duration: 0.1 }}
- initial={{ opacity: 0, translateX: 30 }}
- animate={{ opacity: 1, translateX: 0 }}
- exit={{ opacity: 0, translateX: -30 }}
- >
- <SlackIntegrationForm onClose={() => handleFormReset(false)} />
- </motion.div>
- )}
- {wizardStep === WizardSteps.PlatformInputs &&
- selectedPlatform === WorkflowIntegrationPlatform.MICROSOFT_TEAMS && (
- <motion.div
- key="platform-inputs-step-ms-teams"
- transition={{ duration: 0.1 }}
- initial={{ opacity: 0, translateX: 30 }}
- animate={{ opacity: 1, translateX: 0 }}
- exit={{ opacity: 0, translateX: -30 }}
- >
- <MicrosoftTeamsIntegrationForm onClose={() => handleFormReset(false)} />
- </motion.div>
- )}
- </AnimatePresence>
- </ModalContent>
- </Modal>
- );
-};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/AddWorkflowIntegrationSheet.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/AddWorkflowIntegrationSheet.tsx
new file mode 100644
index 0000000000..fb3258299e
--- /dev/null
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/AddWorkflowIntegrationSheet.tsx
@@ -0,0 +1,138 @@
+import { useRef, useState } from "react";
+import { BsMicrosoftTeams, BsSlack } from "react-icons/bs";
+
+import {
+ Badge,
+ Button,
+ Sheet,
+ SheetClose,
+ SheetContent,
+ SheetDescription,
+ SheetFooter,
+ SheetHeader,
+ SheetTitle
+} from "@app/components/v3";
+import { useProject } from "@app/context";
+import { useGetWorkspaceWorkflowIntegrationConfig } from "@app/hooks/api";
+import { WorkflowIntegrationPlatform } from "@app/hooks/api/workflowIntegrations/types";
+
+import { WORKFLOW_INTEGRATION_PLATFORM_LABELS } from "../constants";
+import { MicrosoftTeamsIntegrationForm } from "./MicrosoftTeamsIntegrationForm";
+import { SlackIntegrationForm } from "./SlackIntegrationForm";
+
+type Props = {
+ isOpen?: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+};
+
+const PLATFORM_LIST = [
+ {
+ icon: <BsSlack className="text-lg" />,
+ platform: WorkflowIntegrationPlatform.SLACK,
+ title: "Slack"
+ },
+ {
+ icon: <BsMicrosoftTeams className="text-lg" />,
+ platform: WorkflowIntegrationPlatform.MICROSOFT_TEAMS,
+ title: "Microsoft Teams"
+ }
+];
+
+export const AddWorkflowIntegrationSheet = ({ isOpen, onOpenChange }: Props) => {
+ const [selectedPlatform, setSelectedPlatform] = useState<WorkflowIntegrationPlatform | null>(
+ null
+ );
+ const containerRef = useRef<HTMLDivElement>(null);
+
+ const { currentProject } = useProject();
+ const { data: slackConfig } = useGetWorkspaceWorkflowIntegrationConfig({
+ projectId: currentProject?.id ?? "",
+ integration: WorkflowIntegrationPlatform.SLACK
+ });
+ const { data: microsoftTeamsConfig } = useGetWorkspaceWorkflowIntegrationConfig({
+ projectId: currentProject?.id ?? "",
+ integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS
+ });
+
+ const configuredPlatforms: Partial<Record<WorkflowIntegrationPlatform, boolean>> = {
+ [WorkflowIntegrationPlatform.SLACK]: !!slackConfig,
+ [WorkflowIntegrationPlatform.MICROSOFT_TEAMS]: !!microsoftTeamsConfig
+ };
+
+ const handleOpenChange = (state: boolean) => {
+ onOpenChange(state);
+ if (!state) {
+ setSelectedPlatform(null);
+ }
+ };
+
+ return (
+ <Sheet open={isOpen} onOpenChange={handleOpenChange}>
+ <SheetContent className="sm:max-w-lg">
+ <div ref={containerRef} className="flex h-full min-h-0 flex-col">
+ <SheetHeader>
+ <SheetTitle>
+ {selectedPlatform
+ ? `Configure ${WORKFLOW_INTEGRATION_PLATFORM_LABELS[selectedPlatform]} Integration`
+ : "Add Workflow Integration"}
+ </SheetTitle>
+ <SheetDescription>
+ {selectedPlatform
+ ? `Choose which events send notifications to ${WORKFLOW_INTEGRATION_PLATFORM_LABELS[selectedPlatform]}.`
+ : "Select the platform that will receive this project's notifications."}
+ </SheetDescription>
+ </SheetHeader>
+ {!selectedPlatform && (
+ <>
+ <div className="flex thin-scrollbar flex-1 flex-col gap-4 overflow-y-auto px-4">
+ <div className="flex items-center gap-4">
+ {PLATFORM_LIST.map(({ icon, platform, title }) => (
+ <button
+ type="button"
+ key={platform}
+ onClick={() => setSelectedPlatform(platform)}
+ className="relative flex h-28 w-36 flex-col items-center justify-center gap-3 overflow-hidden rounded-md border border-border bg-container transition-colors hover:border-project/70 hover:bg-project/10"
+ >
+ {icon}
+ <span className="text-sm">{title}</span>
+ {configuredPlatforms[platform] && (
+ <Badge
+ variant="project"
+ isFullWidth
+ className="absolute inset-x-0 bottom-0 justify-center rounded-none"
+ >
+ Already configured
+ </Badge>
+ )}
+ </button>
+ ))}
+ </div>
+ </div>
+ <SheetFooter className="justify-end border-t">
+ <SheetClose asChild>
+ <Button type="button" variant="ghost">
+ Cancel
+ </Button>
+ </SheetClose>
+ </SheetFooter>
+ </>
+ )}
+ {selectedPlatform === WorkflowIntegrationPlatform.SLACK && (
+ <SlackIntegrationForm
+ onClose={() => handleOpenChange(false)}
+ onBack={() => setSelectedPlatform(null)}
+ menuContainer={containerRef}
+ />
+ )}
+ {selectedPlatform === WorkflowIntegrationPlatform.MICROSOFT_TEAMS && (
+ <MicrosoftTeamsIntegrationForm
+ onClose={() => handleOpenChange(false)}
+ onBack={() => setSelectedPlatform(null)}
+ menuContainer={containerRef}
+ />
+ )}
+ </div>
+ </SheetContent>
+ </Sheet>
+ );
+};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/EditWorkflowIntegrationModal.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/EditWorkflowIntegrationModal.tsx
deleted file mode 100644
index 1cf727500b..0000000000
--- a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/EditWorkflowIntegrationModal.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-import { Modal, ModalContent } from "@app/components/v2";
-import { WorkflowIntegrationPlatform } from "@app/hooks/api/workflowIntegrations/types";
-
-import { MicrosoftTeamsIntegrationForm } from "./MicrosoftTeamsIntegrationForm";
-import { SlackIntegrationForm } from "./SlackIntegrationForm";
-
-type Props = {
- isOpen?: boolean;
- onClose: () => void;
-
- integration: WorkflowIntegrationPlatform;
-};
-
-export const EditWorkflowIntegrationModal = ({ isOpen, onClose, integration }: Props) => {
- const handleFormReset = () => {
- onClose();
- };
-
- return (
- <Modal isOpen={isOpen} onOpenChange={handleFormReset}>
- <ModalContent
- title={`Edit ${integration?.replace("-", " ").replace(/\b\w/g, (char) => char.toUpperCase()) ?? "workflow"} integration`}
- >
- {integration === WorkflowIntegrationPlatform.SLACK && (
- <SlackIntegrationForm onClose={handleFormReset} />
- )}
- {integration === WorkflowIntegrationPlatform.MICROSOFT_TEAMS && (
- <MicrosoftTeamsIntegrationForm onClose={handleFormReset} />
- )}
- </ModalContent>
- </Modal>
- );
-};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/EditWorkflowIntegrationSheet.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/EditWorkflowIntegrationSheet.tsx
new file mode 100644
index 0000000000..c481b82e0e
--- /dev/null
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/EditWorkflowIntegrationSheet.tsx
@@ -0,0 +1,48 @@
+import { useRef } from "react";
+
+import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@app/components/v3";
+import { WorkflowIntegrationPlatform } from "@app/hooks/api/workflowIntegrations/types";
+
+import { WORKFLOW_INTEGRATION_PLATFORM_LABELS } from "../constants";
+import { MicrosoftTeamsIntegrationForm } from "./MicrosoftTeamsIntegrationForm";
+import { SlackIntegrationForm } from "./SlackIntegrationForm";
+
+type Props = {
+ isOpen?: boolean;
+ onClose: () => void;
+ integration?: WorkflowIntegrationPlatform;
+};
+
+export const EditWorkflowIntegrationSheet = ({ isOpen, onClose, integration }: Props) => {
+ const containerRef = useRef<HTMLDivElement>(null);
+
+ const platformLabel = integration ? WORKFLOW_INTEGRATION_PLATFORM_LABELS[integration] : "";
+
+ return (
+ <Sheet
+ open={isOpen}
+ onOpenChange={(state) => {
+ if (!state) {
+ onClose();
+ }
+ }}
+ >
+ <SheetContent className="sm:max-w-lg">
+ <div ref={containerRef} className="flex h-full min-h-0 flex-col">
+ <SheetHeader>
+ <SheetTitle>Edit {platformLabel} Integration</SheetTitle>
+ <SheetDescription>
+ Choose which events send notifications to {platformLabel}.
+ </SheetDescription>
+ </SheetHeader>
+ {integration === WorkflowIntegrationPlatform.SLACK && (
+ <SlackIntegrationForm onClose={onClose} menuContainer={containerRef} />
+ )}
+ {integration === WorkflowIntegrationPlatform.MICROSOFT_TEAMS && (
+ <MicrosoftTeamsIntegrationForm onClose={onClose} menuContainer={containerRef} />
+ )}
+ </div>
+ </SheetContent>
+ </Sheet>
+ );
+};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/MicrosoftTeamsConfigRow.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/MicrosoftTeamsConfigRow.tsx
index da9c19a555..e6aa55863a 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/MicrosoftTeamsConfigRow.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/MicrosoftTeamsConfigRow.tsx
@@ -1,22 +1,17 @@
-/* eslint-disable no-nested-ternary */
import { BsMicrosoftTeams } from "react-icons/bs";
-import { faEllipsis } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { BanIcon } from "lucide-react";
-import { twMerge } from "tailwind-merge";
+import { MoreHorizontal, Pencil, Trash2 } from "lucide-react";
-import { OrgPermissionCan } from "@app/components/permissions";
+import { ProjectPermissionCan } from "@app/components/permissions";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
- Spinner,
- Td,
- Tr
-} from "@app/components/v2";
-import { Badge } from "@app/components/v3";
-import { OrgPermissionActions, OrgPermissionSubjects } from "@app/context";
+ IconButton,
+ TableCell,
+ TableRow
+} from "@app/components/v3";
+import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
import { useGetMicrosoftTeamsIntegrationTeams } from "@app/hooks/api";
import {
ProjectWorkflowIntegrationConfig,
@@ -24,9 +19,10 @@ import {
} from "@app/hooks/api/workflowIntegrations/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { NotificationChannelsCell } from "./NotificationChannelsCell";
+
type Props = {
microsoftTeamsConfig?: ProjectWorkflowIntegrationConfig | null;
- isMicrosoftTeamsConfigLoading: boolean;
handlePopUpOpen: (
popUpName: keyof UsePopUpState<["removeIntegration", "editIntegration"]>,
data?: {
@@ -36,11 +32,12 @@ type Props = {
) => void;
};
-export const MicrosoftTeamsConfigRow = ({
- handlePopUpOpen,
- isMicrosoftTeamsConfigLoading,
- microsoftTeamsConfig
-}: Props) => {
+const getChannelNames = (
+ channels: { channelIds: string[] } | undefined,
+ channelIdToName: Record<string, string>
+) => (channels?.channelIds ?? []).map((channelId) => channelIdToName[channelId]).filter(Boolean);
+
+export const MicrosoftTeamsConfigRow = ({ handlePopUpOpen, microsoftTeamsConfig }: Props) => {
const { data: microsoftTeamsChannels, isPending: isMicrosoftTeamsChannelsLoading } =
useGetMicrosoftTeamsIntegrationTeams(microsoftTeamsConfig?.integrationId);
const microsoftTeamsChannelIdToName = Object.fromEntries(
@@ -53,105 +50,88 @@ export const MicrosoftTeamsConfigRow = ({
return null;
}
- const isLoadingConfig = isMicrosoftTeamsChannelsLoading || isMicrosoftTeamsConfigLoading;
-
return (
- <Tr>
- <Td className="flex max-w-xs items-center overflow-hidden text-ellipsis">
+ <TableRow>
+ <TableCell>
<div className="flex items-center gap-2">
<BsMicrosoftTeams />
Microsoft Teams
</div>
- </Td>
- <Td>
- {microsoftTeamsConfig.isAccessRequestNotificationEnabled &&
- !isLoadingConfig &&
- microsoftTeamsConfig.accessRequestChannels?.channelIds?.length > 0 ? (
- <p>
- {microsoftTeamsConfig.accessRequestChannels.channelIds
- .map((channel) => microsoftTeamsChannelIdToName[channel])
- .join(", ")}
- </p>
- ) : isLoadingConfig ? (
- <Spinner size="xs" />
- ) : (
- <Badge variant="neutral">
- <BanIcon />
- Disabled
- </Badge>
+ </TableCell>
+ <NotificationChannelsCell
+ isLoading={isMicrosoftTeamsChannelsLoading}
+ isEnabled={microsoftTeamsConfig.isAccessRequestNotificationEnabled}
+ channelNames={getChannelNames(
+ microsoftTeamsConfig.accessRequestChannels,
+ microsoftTeamsChannelIdToName
)}
- </Td>
- <Td>
- {microsoftTeamsConfig.isSecretRequestNotificationEnabled &&
- !isLoadingConfig &&
- microsoftTeamsConfig.secretRequestChannels?.channelIds?.length > 0 ? (
- <p>
- {microsoftTeamsConfig.secretRequestChannels.channelIds
- .map((channel) => microsoftTeamsChannelIdToName[channel])
- .join(", ")}
- </p>
- ) : isLoadingConfig ? (
- <Spinner size="xs" />
- ) : (
- <Badge variant="neutral">
- <BanIcon />
- Disabled
- </Badge>
+ />
+ <NotificationChannelsCell
+ isLoading={isMicrosoftTeamsChannelsLoading}
+ isEnabled={microsoftTeamsConfig.isSecretRequestNotificationEnabled}
+ channelNames={getChannelNames(
+ microsoftTeamsConfig.secretRequestChannels,
+ microsoftTeamsChannelIdToName
)}
- </Td>
- <Td>
- <Badge variant="danger">Disabled</Badge>
- </Td>
- <Td>
- <DropdownMenu>
- <DropdownMenuTrigger asChild className="rounded-lg">
- <div className="flex justify-end hover:text-primary-400 data-[state=open]:text-primary-400">
- <FontAwesomeIcon size="sm" icon={faEllipsis} />
- </div>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="start" className="p-1">
- <OrgPermissionCan I={OrgPermissionActions.Edit} an={OrgPermissionSubjects.Settings}>
- {(isAllowed) => (
- <DropdownMenuItem
- disabled={!isAllowed}
- className={twMerge(
- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
- )}
- onClick={(e) => {
- e.stopPropagation();
-
- handlePopUpOpen("editIntegration", {
- integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS
- });
- }}
- >
- Edit
- </DropdownMenuItem>
- )}
- </OrgPermissionCan>
- <OrgPermissionCan I={OrgPermissionActions.Delete} an={OrgPermissionSubjects.Settings}>
- {(isAllowed) => (
- <DropdownMenuItem
- disabled={!isAllowed}
- className={twMerge(
- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
- )}
- onClick={(e) => {
- e.stopPropagation();
-
- handlePopUpOpen("removeIntegration", {
- integrationId: microsoftTeamsConfig.integrationId,
- integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS
- });
- }}
- >
- Delete
- </DropdownMenuItem>
- )}
- </OrgPermissionCan>
- </DropdownMenuContent>
- </DropdownMenu>
- </Td>
- </Tr>
+ />
+ <TableCell>
+ <span className="text-muted">Not supported</span>
+ </TableCell>
+ <TableCell>
+ <div className="flex items-center justify-end">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ variant="ghost"
+ size="xs"
+ aria-label="Actions for Microsoft Teams integration"
+ >
+ <MoreHorizontal />
+ </IconButton>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="w-44">
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Edit}
+ a={ProjectPermissionSub.Settings}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ isDisabled={!isAllowed}
+ onClick={() =>
+ handlePopUpOpen("editIntegration", {
+ integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS
+ })
+ }
+ >
+ <Pencil />
+ Edit
+ </DropdownMenuItem>
+ )}
+ </ProjectPermissionCan>
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Delete}
+ a={ProjectPermissionSub.Settings}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ variant="danger"
+ isDisabled={!isAllowed}
+ onClick={() =>
+ handlePopUpOpen("removeIntegration", {
+ integrationId: microsoftTeamsConfig.integrationId,
+ integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS
+ })
+ }
+ >
+ <Trash2 />
+ Remove
+ </DropdownMenuItem>
+ )}
+ </ProjectPermissionCan>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ </TableCell>
+ </TableRow>
);
};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/MicrosoftTeamsIntegrationForm.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/MicrosoftTeamsIntegrationForm.tsx
index 707322264c..99286ec7fc 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/MicrosoftTeamsIntegrationForm.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/MicrosoftTeamsIntegrationForm.tsx
@@ -1,54 +1,56 @@
-import { useEffect } from "react";
+import { RefObject, useEffect } from "react";
import { Controller, useForm } from "react-hook-form";
-import { faCheckCircle } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { zodResolver } from "@hookform/resolvers/zod";
+import { Link } from "@tanstack/react-router";
+import { ChevronLeft, Info } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
-import { ProjectPermissionCan } from "@app/components/permissions";
import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
Button,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
- FormControl,
- Input,
+ Field,
+ FieldContent,
+ FieldDescription,
+ FieldError,
+ FieldLabel,
+ FieldTitle,
+ FilterableSelect,
Select,
+ SelectContent,
SelectItem,
+ SelectTrigger,
+ SelectValue,
+ SheetClose,
+ SheetFooter,
Switch
-} from "@app/components/v2";
+} from "@app/components/v3";
import { useProject } from "@app/context";
-import {
- ProjectPermissionActions,
- ProjectPermissionSub
-} from "@app/context/ProjectPermissionContext";
import {
useGetMicrosoftTeamsIntegrations,
useGetMicrosoftTeamsIntegrationTeams,
useGetWorkspaceWorkflowIntegrationConfig,
useUpdateProjectWorkflowIntegrationConfig
} from "@app/hooks/api";
-import { WorkflowIntegrationPlatform } from "@app/hooks/api/workflowIntegrations/types";
+import {
+ MicrosoftTeamsIntegrationTeam,
+ WorkflowIntegrationPlatform
+} from "@app/hooks/api/workflowIntegrations/types";
+
+const channelsSchema = z.object({
+ teamId: z.string(),
+ channelIds: z.string().array()
+});
const formSchema = z
.object({
- microsoftTeamsIntegrationId: z.string(),
+ microsoftTeamsIntegrationId: z.string().min(1, "Select a Microsoft Teams integration"),
isSecretRequestNotificationEnabled: z.boolean(),
isAccessRequestNotificationEnabled: z.boolean(),
- secretRequestChannels: z
- .object({
- teamId: z.string(),
- channelIds: z.string().array()
- })
- .optional(),
- accessRequestChannels: z
- .object({
- teamId: z.string(),
- channelIds: z.string().array()
- })
- .optional()
+ secretRequestChannels: channelsSchema.optional(),
+ accessRequestChannels: channelsSchema.optional()
})
.superRefine((data, ctx) => {
if (data.isSecretRequestNotificationEnabled) {
@@ -90,23 +92,31 @@ const formSchema = z
type TMicrosoftTeamsConfigForm = z.infer<typeof formSchema>;
+type TChannelOption = {
+ channelId: string;
+ channelName: string;
+};
+
type Props = {
onClose: () => void;
+ onBack?: () => void;
+ menuContainer: RefObject<HTMLDivElement | null>;
};
-export const MicrosoftTeamsIntegrationForm = ({ onClose }: Props) => {
+export const MicrosoftTeamsIntegrationForm = ({ onClose, onBack, menuContainer }: Props) => {
const { currentProject } = useProject();
const { data: microsoftTeamsConfig } = useGetWorkspaceWorkflowIntegrationConfig({
projectId: currentProject?.id ?? "",
integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS
});
- const { data: microsoftTeamsIntegrations } = useGetMicrosoftTeamsIntegrations(
- currentProject?.orgId
- );
+ const { data: microsoftTeamsIntegrations, isPending: isMicrosoftTeamsIntegrationsLoading } =
+ useGetMicrosoftTeamsIntegrations(currentProject?.orgId);
const { mutateAsync: updateProjectMicrosoftTeamsConfig } =
useUpdateProjectWorkflowIntegrationConfig();
+ const hasMicrosoftTeamsIntegrations = !!microsoftTeamsIntegrations?.length;
+
const {
control,
watch,
@@ -116,6 +126,7 @@ export const MicrosoftTeamsIntegrationForm = ({ onClose }: Props) => {
} = useForm<TMicrosoftTeamsConfigForm>({
resolver: zodResolver(formSchema),
defaultValues: {
+ microsoftTeamsIntegrationId: "",
isAccessRequestNotificationEnabled: false,
isSecretRequestNotificationEnabled: false,
accessRequestChannels: {
@@ -150,7 +161,7 @@ export const MicrosoftTeamsIntegrationForm = ({ onClose }: Props) => {
createNotification({
type: "success",
- text: "Successfully created microsoft teams integration"
+ text: "Saved Microsoft Teams integration settings"
});
onClose();
@@ -167,34 +178,20 @@ export const MicrosoftTeamsIntegrationForm = ({ onClose }: Props) => {
const {
data: microsoftTeamsIntegrationTeams,
isPending: isLoadingMicrosoftTeamsIntegrationTeams
- } = useGetMicrosoftTeamsIntegrationTeams(selectedMicrosoftTeamsIntegrationId);
+ } = useGetMicrosoftTeamsIntegrationTeams(selectedMicrosoftTeamsIntegrationId || undefined);
- const sortedMicrosoftTeamsIntegrationTeams = microsoftTeamsIntegrationTeams?.sort((a, b) =>
- a.teamName.toLowerCase().localeCompare(b.teamName.toLowerCase())
- );
+ const sortedTeams = microsoftTeamsIntegrationTeams
+ ?.slice()
+ .sort((a, b) => a.teamName.toLowerCase().localeCompare(b.teamName.toLowerCase()));
- const selectableAccessRequestChannelIds = sortedMicrosoftTeamsIntegrationTeams
- ?.filter((team) => team.teamId === selectedAccessRequestTeamId)
- .map((team) => team.channels)
- .flat();
- const selectableSecretRequestChannelIds = sortedMicrosoftTeamsIntegrationTeams
- ?.filter((team) => team.teamId === selectedSecretRequestTeamId)
- .map((team) => team.channels)
- .flat();
-
- const channelIdToName = [
- ...(selectableAccessRequestChannelIds || []),
- ...(selectableSecretRequestChannelIds || [])
- ].reduce(
- (acc, channel) => {
- acc[channel.channelId] = channel.channelName;
- return acc;
- },
- {} as Record<string, string>
- );
+ const getTeamChannels = (teamId?: string): TChannelOption[] =>
+ sortedTeams?.find((team) => team.teamId === teamId)?.channels ?? [];
useEffect(() => {
- if (microsoftTeamsConfig) {
+ if (
+ microsoftTeamsConfig &&
+ microsoftTeamsConfig.integration === WorkflowIntegrationPlatform.MICROSOFT_TEAMS
+ ) {
setValue("microsoftTeamsIntegrationId", microsoftTeamsConfig.integrationId);
setValue(
"isSecretRequestNotificationEnabled",
@@ -205,345 +202,246 @@ export const MicrosoftTeamsIntegrationForm = ({ onClose }: Props) => {
microsoftTeamsConfig.isAccessRequestNotificationEnabled
);
- if (microsoftTeamsConfig.integration === WorkflowIntegrationPlatform.MICROSOFT_TEAMS) {
- if (microsoftTeamsConfig.secretRequestChannels) {
- if (Object.entries(microsoftTeamsConfig.accessRequestChannels).length) {
- setValue("accessRequestChannels", microsoftTeamsConfig.accessRequestChannels);
- }
- if (Object.entries(microsoftTeamsConfig.secretRequestChannels).length) {
- setValue("secretRequestChannels", microsoftTeamsConfig.secretRequestChannels);
- }
- }
+ if (
+ microsoftTeamsConfig.accessRequestChannels &&
+ Object.entries(microsoftTeamsConfig.accessRequestChannels).length
+ ) {
+ setValue("accessRequestChannels", microsoftTeamsConfig.accessRequestChannels);
+ }
+ if (
+ microsoftTeamsConfig.secretRequestChannels &&
+ Object.entries(microsoftTeamsConfig.secretRequestChannels).length
+ ) {
+ setValue("secretRequestChannels", microsoftTeamsConfig.secretRequestChannels);
}
}
}, [microsoftTeamsConfig]);
+ const renderEventChannelFields = (
+ fieldPrefix: "secretRequestChannels" | "accessRequestChannels"
+ ) => {
+ const selectedTeamId =
+ fieldPrefix === "secretRequestChannels"
+ ? selectedSecretRequestTeamId
+ : selectedAccessRequestTeamId;
+ const teamChannels = getTeamChannels(selectedTeamId);
+
+ return (
+ <>
+ <Controller
+ control={control}
+ name={`${fieldPrefix}.teamId`}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel htmlFor={`${fieldPrefix}-team`}>Microsoft Teams team</FieldLabel>
+ <FilterableSelect<MicrosoftTeamsIntegrationTeam>
+ inputId={`${fieldPrefix}-team`}
+ options={sortedTeams}
+ value={sortedTeams?.find((team) => team.teamId === value) ?? null}
+ onChange={(selected) => {
+ onChange((selected as MicrosoftTeamsIntegrationTeam | null)?.teamId ?? "");
+ // Channels belong to a team; clear stale selections when the team changes.
+ setValue(`${fieldPrefix}.channelIds`, [], { shouldDirty: true });
+ }}
+ getOptionValue={(option) => option.teamId}
+ getOptionLabel={(option) => option.teamName}
+ placeholder={
+ isLoadingMicrosoftTeamsIntegrationTeams ? "Loading..." : "Select a team..."
+ }
+ isLoading={isLoadingMicrosoftTeamsIntegrationTeams}
+ isError={Boolean(error)}
+ menuPortalTarget={menuContainer.current}
+ menuPosition="fixed"
+ menuPlacement="bottom"
+ />
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ )}
+ />
+ <Controller
+ control={control}
+ name={`${fieldPrefix}.channelIds`}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel htmlFor={`${fieldPrefix}-channels`}>Microsoft Teams channels</FieldLabel>
+ <FilterableSelect
+ isMulti
+ inputId={`${fieldPrefix}-channels`}
+ options={teamChannels}
+ value={teamChannels.filter((channel) => value?.includes(channel.channelId))}
+ onChange={(selected) =>
+ onChange(
+ (selected as readonly TChannelOption[]).map((channel) => channel.channelId)
+ )
+ }
+ getOptionValue={(option) => option.channelId}
+ getOptionLabel={(option) => option.channelName}
+ placeholder={selectedTeamId ? "Select channels..." : "Select a team first"}
+ isDisabled={!selectedTeamId}
+ isLoading={isLoadingMicrosoftTeamsIntegrationTeams}
+ isError={Boolean(error)}
+ menuPortalTarget={menuContainer.current}
+ menuPosition="fixed"
+ menuPlacement="bottom"
+ closeMenuOnSelect={false}
+ hideSelectedOptions={false}
+ />
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ )}
+ />
+ </>
+ );
+ };
+
return (
- <form onSubmit={handleSubmit(handleIntegrationSave)}>
- <div className="flex w-full flex-col justify-start">
- <ProjectPermissionCan I={ProjectPermissionActions.Edit} a={ProjectPermissionSub.Settings}>
- {(isAllowed) => (
- <Controller
- control={control}
- name="microsoftTeamsIntegrationId"
- render={({ field: { onChange, ...field }, fieldState: { error } }) => (
- <FormControl
- label="Microsoft Teams Integration"
- errorText={error?.message}
- isError={Boolean(error)}
+ <form
+ onSubmit={handleSubmit(handleIntegrationSave)}
+ className="flex min-h-0 flex-1 flex-col"
+ autoComplete="off"
+ >
+ <div className="flex thin-scrollbar flex-1 flex-col gap-4 overflow-y-auto px-4">
+ {!isMicrosoftTeamsIntegrationsLoading && !hasMicrosoftTeamsIntegrations ? (
+ <Alert>
+ <Info />
+ <AlertTitle>No Microsoft Teams integrations connected</AlertTitle>
+ <AlertDescription>
+ <p>
+ Connect a Microsoft Teams tenant to your organization before configuring project
+ notifications.
+ </p>
+ <Button asChild variant="outline" size="sm" className="mt-2">
+ <Link
+ to="/organizations/$orgId/integrations"
+ params={{ orgId: currentProject.orgId }}
+ search={{ selectedTab: "workflow-integrations" }}
>
- <Select
- {...field}
- isDisabled={!isAllowed}
- placeholder="None"
- onValueChange={(v) => {
- onChange(v);
+ Go to organization integrations
+ </Link>
+ </Button>
+ </AlertDescription>
+ </Alert>
+ ) : (
+ <Controller
+ control={control}
+ name="microsoftTeamsIntegrationId"
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel htmlFor="microsoft-teams-integration">
+ Microsoft Teams integration
+ </FieldLabel>
+ <Select
+ value={value}
+ onValueChange={(newValue) => {
+ onChange(newValue);
- setValue("isAccessRequestNotificationEnabled", false);
- setValue("isSecretRequestNotificationEnabled", false);
- setValue("accessRequestChannels", {
- teamId: "",
- channelIds: []
- });
- setValue("secretRequestChannels", {
- teamId: "",
- channelIds: []
- });
- }}
+ setValue("isAccessRequestNotificationEnabled", false);
+ setValue("isSecretRequestNotificationEnabled", false);
+ setValue("accessRequestChannels", {
+ teamId: "",
+ channelIds: []
+ });
+ setValue("secretRequestChannels", {
+ teamId: "",
+ channelIds: []
+ });
+ }}
+ >
+ <SelectTrigger
+ id="microsoft-teams-integration"
className="w-full"
- defaultValue={microsoftTeamsConfig?.integrationId}
+ aria-invalid={Boolean(error)}
>
+ <SelectValue
+ placeholder={
+ isMicrosoftTeamsIntegrationsLoading ? "Loading..." : "Select an integration"
+ }
+ />
+ </SelectTrigger>
+ <SelectContent position="popper">
{microsoftTeamsIntegrations?.map((microsoftTeamsIntegration) => (
<SelectItem
value={microsoftTeamsIntegration.id}
- key={`microsoft-teams-integration-${microsoftTeamsIntegration.id}`}
+ key={microsoftTeamsIntegration.id}
>
{microsoftTeamsIntegration.slug}
</SelectItem>
))}
- </Select>
- </FormControl>
+ </SelectContent>
+ </Select>
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ )}
+ />
+ )}
+ {!!selectedMicrosoftTeamsIntegrationId && (
+ <>
+ <Controller
+ control={control}
+ name="isSecretRequestNotificationEnabled"
+ render={({ field }) => (
+ <Field orientation="horizontal" className="items-center!">
+ <FieldContent>
+ <FieldTitle>Secret approval requests</FieldTitle>
+ <FieldDescription>
+ Send a notification when a secret approval request is opened.
+ </FieldDescription>
+ </FieldContent>
+ <Switch
+ variant="project"
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ aria-label="Secret approval request notifications"
+ />
+ </Field>
)}
/>
- )}
- </ProjectPermissionCan>
- </div>
- {selectedMicrosoftTeamsIntegrationId && (
- <>
- <h2 className="mb-2 flex-1 text-sm text-mineshaft-400">Configure Events</h2>
- <Controller
- control={control}
- name="isSecretRequestNotificationEnabled"
- render={({ field, fieldState: { error } }) => {
- return (
- <FormControl
- isError={Boolean(error)}
- errorText={error?.message}
- className="mt-3 mb-2"
- >
- <Switch
- id="secret-approval-notification"
- onCheckedChange={(value) => field.onChange(value)}
- isChecked={field.value}
- >
- <p className="w-full">Secret Approval Requests</p>
- </Switch>
- </FormControl>
- );
- }}
- />
- {secretRequestNotificationsEnabled && (
- <>
- <Controller
- control={control}
- name="secretRequestChannels.teamId"
- render={({ field: { onChange, ...field }, fieldState: { error } }) => (
- <FormControl
- label="Secret Approval Requests Notifications Team"
- isError={Boolean(error)}
- errorText={error?.message}
- >
- <Select
- {...field}
- placeholder={
- isLoadingMicrosoftTeamsIntegrationTeams ? "Loading..." : "Select a team..."
- }
- className="w-full"
- onValueChange={(value) => onChange(value)}
- isLoading={isLoadingMicrosoftTeamsIntegrationTeams}
- >
- {!isLoadingMicrosoftTeamsIntegrationTeams &&
- sortedMicrosoftTeamsIntegrationTeams?.map((team) => (
- <SelectItem
- key={`secret-requests-microsoft-teams-team-${team.teamId}`}
- value={team.teamId}
- >
- {team.teamName}
- </SelectItem>
- ))}
- </Select>
- </FormControl>
- )}
- />
- <Controller
- control={control}
- name="secretRequestChannels.channelIds"
- render={({ field: { value, onChange }, fieldState: { error } }) => (
- <FormControl
- label="Microsoft Teams channels"
- isError={Boolean(error)}
- errorText={error?.message}
- >
- <DropdownMenu>
- <DropdownMenuTrigger
- className={
- isLoadingMicrosoftTeamsIntegrationTeams || !selectedSecretRequestTeamId
- ? "opacity-50"
- : ""
- }
- asChild
- disabled={
- isLoadingMicrosoftTeamsIntegrationTeams || !selectedSecretRequestTeamId
- }
- >
- {selectedSecretRequestTeamId ? (
- <Input
- isReadOnly
- value={
- isLoadingMicrosoftTeamsIntegrationTeams
- ? "Loading..."
- : value
- ?.filter(Boolean)
- .map((entry) => channelIdToName[entry])
- .join(", ")
- }
- className="text-left"
- />
- ) : (
- <Input
- isReadOnly
- value="Select a team..."
- className="py-2 text-left text-sm"
- />
- )}
- </DropdownMenuTrigger>
- <DropdownMenuContent
- style={{
- width: "var(--radix-dropdown-menu-trigger-width)",
- maxHeight: "350px",
- overflowY: "auto"
- }}
- side="bottom"
- align="start"
- >
- {selectableSecretRequestChannelIds?.map((channel) => {
- const isChecked = value?.includes(channel.channelId);
- return (
- <DropdownMenuItem
- onClick={(evt) => {
- evt.preventDefault();
- onChange(
- isChecked
- ? value?.filter((el: string) => el !== channel.channelId)
- : [...(value || []), channel.channelId]
- );
- }}
- key={`secret-requests-microsoft-teams-channel-${channel.channelId}`}
- iconPos="right"
- icon={isChecked && <FontAwesomeIcon icon={faCheckCircle} />}
- >
- {channel.channelName}
- </DropdownMenuItem>
- );
- })}
- </DropdownMenuContent>
- </DropdownMenu>
- </FormControl>
- )}
- />
- </>
- )}
- <Controller
- control={control}
- name="isAccessRequestNotificationEnabled"
- render={({ field, fieldState: { error } }) => {
- return (
- <FormControl isError={Boolean(error)} errorText={error?.message} className="mb-2">
+ {secretRequestNotificationsEnabled && renderEventChannelFields("secretRequestChannels")}
+ <Controller
+ control={control}
+ name="isAccessRequestNotificationEnabled"
+ render={({ field }) => (
+ <Field orientation="horizontal" className="items-center!">
+ <FieldContent>
+ <FieldTitle>Access requests</FieldTitle>
+ <FieldDescription>
+ Send a notification when an access request is opened.
+ </FieldDescription>
+ </FieldContent>
<Switch
- id="access-request-notification"
- onCheckedChange={(value) => field.onChange(value)}
- isChecked={field.value}
- >
- <p className="w-full">Access Requests</p>
- </Switch>
- </FormControl>
- );
- }}
- />
- {accessRequestNotificationsEnabled && (
- <>
- <Controller
- control={control}
- name="accessRequestChannels.teamId"
- render={({ field: { onChange, ...field }, fieldState: { error } }) => (
- <FormControl
- label="Access Requests Notifications Team"
- isError={Boolean(error)}
- errorText={error?.message}
- >
- <Select
- {...field}
- placeholder={
- isLoadingMicrosoftTeamsIntegrationTeams ? "Loading..." : "Select a team..."
- }
- className="w-full"
- onValueChange={(value) => onChange(value)}
- isLoading={isLoadingMicrosoftTeamsIntegrationTeams}
- >
- {!isLoadingMicrosoftTeamsIntegrationTeams &&
- sortedMicrosoftTeamsIntegrationTeams?.map((team) => (
- <SelectItem
- key={`access-requests-microsoft-teams-team-${team.teamId}`}
- value={team.teamId}
- >
- {team.teamName}
- </SelectItem>
- ))}
- </Select>
- </FormControl>
- )}
- />
-
- <Controller
- control={control}
- name="accessRequestChannels.channelIds"
- render={({ field: { value, onChange }, fieldState: { error } }) => (
- <FormControl
- label="Microsoft Teams channels"
- isError={Boolean(error)}
- errorText={error?.message}
- >
- <DropdownMenu>
- <DropdownMenuTrigger
- className={
- isLoadingMicrosoftTeamsIntegrationTeams || !selectedAccessRequestTeamId
- ? "opacity-50"
- : ""
- }
- asChild
- disabled={
- isLoadingMicrosoftTeamsIntegrationTeams || !selectedAccessRequestTeamId
- }
- >
- {selectedAccessRequestTeamId ? (
- <Input
- isReadOnly
- value={
- isLoadingMicrosoftTeamsIntegrationTeams
- ? "Loading..."
- : value
- ?.filter(Boolean)
- .map((entry) => channelIdToName[entry])
- .join(", ")
- }
- className="text-left"
- />
- ) : (
- <Input
- isReadOnly
- value="Select a team..."
- className="py-2 text-left text-sm"
- />
- )}
- </DropdownMenuTrigger>
- <DropdownMenuContent
- style={{
- width: "var(--radix-dropdown-menu-trigger-width)",
- maxHeight: "350px",
- overflowY: "auto"
- }}
- side="bottom"
- align="start"
- >
- {selectableAccessRequestChannelIds?.map((channel) => {
- const isChecked = value?.includes(channel.channelId);
- return (
- <DropdownMenuItem
- onClick={(evt) => {
- evt.preventDefault();
- onChange(
- isChecked
- ? value?.filter((el: string) => el !== channel.channelId)
- : [...(value || []), channel.channelId]
- );
- }}
- key={`access-requests-slack-channel-${channel.channelId}`}
- iconPos="right"
- icon={isChecked && <FontAwesomeIcon icon={faCheckCircle} />}
- >
- {channel.channelName}
- </DropdownMenuItem>
- );
- })}
- </DropdownMenuContent>
- </DropdownMenu>
- </FormControl>
- )}
- />
- </>
- )}
- <Button
- colorSchema="secondary"
- className="mt-4"
- type="submit"
- disabled={!isDirty}
- isDisabled={!isDirty}
- isLoading={isSubmitting}
- >
- Save
+ variant="project"
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ aria-label="Access request notifications"
+ />
+ </Field>
+ )}
+ />
+ {accessRequestNotificationsEnabled && renderEventChannelFields("accessRequestChannels")}
+ </>
+ )}
+ </div>
+ <SheetFooter className="justify-end border-t">
+ {onBack && (
+ <Button type="button" variant="ghost" className="mr-auto" onClick={onBack}>
+ <ChevronLeft />
+ Back
+ </Button>
+ )}
+ <SheetClose asChild>
+ <Button type="button" variant="ghost">
+ Cancel
</Button>
- </>
- )}
+ </SheetClose>
+ <Button
+ type="submit"
+ variant="project"
+ isPending={isSubmitting}
+ isDisabled={!isDirty || isSubmitting || !hasMicrosoftTeamsIntegrations}
+ >
+ Save
+ </Button>
+ </SheetFooter>
</form>
);
};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/NotificationChannelsCell.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/NotificationChannelsCell.tsx
new file mode 100644
index 0000000000..1675eccb53
--- /dev/null
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/NotificationChannelsCell.tsx
@@ -0,0 +1,46 @@
+import { Ban } from "lucide-react";
+
+import { Badge, Skeleton, TableCell } from "@app/components/v3";
+
+type Props = {
+ isLoading: boolean;
+ isEnabled: boolean;
+ channelNames: string[];
+};
+
+export const NotificationChannelsCell = ({ isLoading, isEnabled, channelNames }: Props) => {
+ if (isLoading) {
+ return (
+ <TableCell>
+ <Skeleton className="h-5 w-24" />
+ </TableCell>
+ );
+ }
+
+ if (!isEnabled) {
+ return (
+ <TableCell>
+ <Badge variant="neutral">
+ <Ban />
+ Disabled
+ </Badge>
+ </TableCell>
+ );
+ }
+
+ if (!channelNames.length) {
+ return (
+ <TableCell>
+ <span className="text-muted">No channels selected</span>
+ </TableCell>
+ );
+ }
+
+ return (
+ <TableCell className="max-w-0">
+ <p className="truncate" title={channelNames.join(", ")}>
+ {channelNames.join(", ")}
+ </p>
+ </TableCell>
+ );
+};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/SlackConfigRow.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/SlackConfigRow.tsx
index afabe826cd..b089a83bbb 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/SlackConfigRow.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/SlackConfigRow.tsx
@@ -1,22 +1,17 @@
-/* eslint-disable no-nested-ternary */
import { BsSlack } from "react-icons/bs";
-import { faEllipsis } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { BanIcon } from "lucide-react";
-import { twMerge } from "tailwind-merge";
+import { MoreHorizontal, Pencil, Trash2 } from "lucide-react";
-import { OrgPermissionCan } from "@app/components/permissions";
+import { ProjectPermissionCan } from "@app/components/permissions";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
- Spinner,
- Td,
- Tr
-} from "@app/components/v2";
-import { Badge } from "@app/components/v3";
-import { OrgPermissionActions, OrgPermissionSubjects } from "@app/context";
+ IconButton,
+ TableCell,
+ TableRow
+} from "@app/components/v3";
+import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
import { useGetSlackIntegrationChannels } from "@app/hooks/api";
import {
ProjectWorkflowIntegrationConfig,
@@ -24,9 +19,10 @@ import {
} from "@app/hooks/api/workflowIntegrations/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { NotificationChannelsCell } from "./NotificationChannelsCell";
+
type Props = {
slackConfig?: ProjectWorkflowIntegrationConfig | null;
- isSlackConfigLoading: boolean;
handlePopUpOpen: (
popUpName: keyof UsePopUpState<["removeIntegration", "editIntegration"]>,
data?: {
@@ -36,7 +32,13 @@ type Props = {
) => void;
};
-export const SlackConfigRow = ({ handlePopUpOpen, isSlackConfigLoading, slackConfig }: Props) => {
+const getChannelNames = (channels: string, channelIdToName: Record<string, string>) =>
+ channels
+ .split(", ")
+ .map((channelId) => channelIdToName[channelId])
+ .filter(Boolean);
+
+export const SlackConfigRow = ({ handlePopUpOpen, slackConfig }: Props) => {
const { data: slackChannels, isPending: isSlackChannelsLoading } = useGetSlackIntegrationChannels(
slackConfig?.integrationId
);
@@ -48,123 +50,80 @@ export const SlackConfigRow = ({ handlePopUpOpen, isSlackConfigLoading, slackCon
return null;
}
- const isLoadingConfig = isSlackChannelsLoading || isSlackConfigLoading;
-
return (
- <Tr>
- <Td className="flex max-w-xs items-center overflow-hidden text-ellipsis">
+ <TableRow>
+ <TableCell>
<div className="flex items-center gap-2">
<BsSlack />
Slack
</div>
- </Td>
- <Td>
- {slackConfig.isAccessRequestNotificationEnabled &&
- !isLoadingConfig &&
- slackConfig.accessRequestChannels.length > 0 ? (
- <p>
- {slackConfig.accessRequestChannels
- .split(", ")
- .map((channel) => slackChannelIdToName[channel])
- .join(", ")}
- </p>
- ) : isLoadingConfig ? (
- <Spinner size="xs" />
- ) : (
- <Badge variant="neutral">
- <BanIcon />
- Disabled
- </Badge>
- )}
- </Td>
- <Td>
- {slackConfig.isSecretRequestNotificationEnabled &&
- !isLoadingConfig &&
- slackConfig.secretRequestChannels.length > 0 ? (
- <p>
- {slackConfig.secretRequestChannels
- .split(", ")
- .map((channel) => slackChannelIdToName[channel])
- .join(", ")}
- </p>
- ) : isLoadingConfig ? (
- <Spinner size="xs" />
- ) : (
- <Badge variant="neutral">
- <BanIcon />
- Disabled
- </Badge>
- )}
- </Td>
- <Td>
- {slackConfig.isSecretSyncErrorNotificationEnabled &&
- !isLoadingConfig &&
- slackConfig.secretSyncErrorChannels.length > 0 ? (
- <p>
- {slackConfig.secretSyncErrorChannels
- .split(", ")
- .map((channel) => slackChannelIdToName[channel])
- .join(", ")}
- </p>
- ) : isLoadingConfig ? (
- <Spinner size="xs" />
- ) : (
- <Badge variant="neutral">
- <BanIcon />
- Disabled
- </Badge>
- )}
- </Td>
- <Td>
- <DropdownMenu>
- <DropdownMenuTrigger asChild className="rounded-lg">
- <div className="flex justify-end hover:text-primary-400 data-[state=open]:text-primary-400">
- <FontAwesomeIcon size="sm" icon={faEllipsis} />
- </div>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="start" className="p-1">
- <OrgPermissionCan I={OrgPermissionActions.Edit} an={OrgPermissionSubjects.Settings}>
- {(isAllowed) => (
- <DropdownMenuItem
- disabled={!isAllowed}
- className={twMerge(
- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
- )}
- onClick={(e) => {
- e.stopPropagation();
-
- handlePopUpOpen("editIntegration", {
- integration: WorkflowIntegrationPlatform.SLACK
- });
- }}
- >
- Edit
- </DropdownMenuItem>
- )}
- </OrgPermissionCan>
- <OrgPermissionCan I={OrgPermissionActions.Delete} an={OrgPermissionSubjects.Settings}>
- {(isAllowed) => (
- <DropdownMenuItem
- disabled={!isAllowed}
- className={twMerge(
- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
- )}
- onClick={(e) => {
- e.stopPropagation();
-
- handlePopUpOpen("removeIntegration", {
- integrationId: slackConfig.integrationId,
- integration: WorkflowIntegrationPlatform.SLACK
- });
- }}
- >
- Delete
- </DropdownMenuItem>
- )}
- </OrgPermissionCan>
- </DropdownMenuContent>
- </DropdownMenu>
- </Td>
- </Tr>
+ </TableCell>
+ <NotificationChannelsCell
+ isLoading={isSlackChannelsLoading}
+ isEnabled={slackConfig.isAccessRequestNotificationEnabled}
+ channelNames={getChannelNames(slackConfig.accessRequestChannels, slackChannelIdToName)}
+ />
+ <NotificationChannelsCell
+ isLoading={isSlackChannelsLoading}
+ isEnabled={slackConfig.isSecretRequestNotificationEnabled}
+ channelNames={getChannelNames(slackConfig.secretRequestChannels, slackChannelIdToName)}
+ />
+ <NotificationChannelsCell
+ isLoading={isSlackChannelsLoading}
+ isEnabled={slackConfig.isSecretSyncErrorNotificationEnabled}
+ channelNames={getChannelNames(slackConfig.secretSyncErrorChannels, slackChannelIdToName)}
+ />
+ <TableCell>
+ <div className="flex items-center justify-end">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton variant="ghost" size="xs" aria-label="Actions for Slack integration">
+ <MoreHorizontal />
+ </IconButton>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="w-44">
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Edit}
+ a={ProjectPermissionSub.Settings}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ isDisabled={!isAllowed}
+ onClick={() =>
+ handlePopUpOpen("editIntegration", {
+ integration: WorkflowIntegrationPlatform.SLACK
+ })
+ }
+ >
+ <Pencil />
+ Edit
+ </DropdownMenuItem>
+ )}
+ </ProjectPermissionCan>
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Delete}
+ a={ProjectPermissionSub.Settings}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ variant="danger"
+ isDisabled={!isAllowed}
+ onClick={() =>
+ handlePopUpOpen("removeIntegration", {
+ integrationId: slackConfig.integrationId,
+ integration: WorkflowIntegrationPlatform.SLACK
+ })
+ }
+ >
+ <Trash2 />
+ Remove
+ </DropdownMenuItem>
+ )}
+ </ProjectPermissionCan>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ </TableCell>
+ </TableRow>
);
};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/SlackIntegrationForm.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/SlackIntegrationForm.tsx
index a473e897ea..ebe3cddefe 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/SlackIntegrationForm.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/components/SlackIntegrationForm.tsx
@@ -1,39 +1,46 @@
-import { useEffect } from "react";
+import { RefObject, useEffect } from "react";
import { Controller, useForm } from "react-hook-form";
-import { faCheckCircle } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { zodResolver } from "@hookform/resolvers/zod";
+import { Link } from "@tanstack/react-router";
+import { ChevronLeft, Info } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
-import { ProjectPermissionCan } from "@app/components/permissions";
import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
Button,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
- FormControl,
- Input,
+ Field,
+ FieldContent,
+ FieldDescription,
+ FieldError,
+ FieldLabel,
+ FieldTitle,
+ FilterableSelect,
Select,
+ SelectContent,
SelectItem,
+ SelectTrigger,
+ SelectValue,
+ SheetClose,
+ SheetFooter,
Switch
-} from "@app/components/v2";
+} from "@app/components/v3";
import { useProject } from "@app/context";
-import {
- ProjectPermissionActions,
- ProjectPermissionSub
-} from "@app/context/ProjectPermissionContext";
import {
useGetSlackIntegrationChannels,
useGetWorkflowIntegrations,
useGetWorkspaceWorkflowIntegrationConfig,
useUpdateProjectWorkflowIntegrationConfig
} from "@app/hooks/api";
-import { WorkflowIntegrationPlatform } from "@app/hooks/api/workflowIntegrations/types";
+import {
+ SlackIntegrationChannel,
+ WorkflowIntegrationPlatform
+} from "@app/hooks/api/workflowIntegrations/types";
const formSchema = z.object({
- slackIntegrationId: z.string(),
+ slackIntegrationId: z.string().min(1, "Select a Slack integration"),
isSecretRequestNotificationEnabled: z.boolean(),
secretRequestChannels: z.string().array(),
isAccessRequestNotificationEnabled: z.boolean(),
@@ -44,85 +51,70 @@ const formSchema = z.object({
type TSlackConfigForm = z.infer<typeof formSchema>;
-type TChannelSelectorProps = {
+type Props = {
+ onClose: () => void;
+ onBack?: () => void;
+ menuContainer: RefObject<HTMLDivElement | null>;
+};
+
+type TChannelsFieldProps = {
+ inputId: string;
value: string[];
onChange: (value: string[]) => void;
error?: { message?: string };
- slackChannelIdToName: Record<string, string>;
- sortedSlackChannels?: { id: string; name: string }[];
- keyPrefix: string;
+ channels?: SlackIntegrationChannel[];
+ isLoading: boolean;
+ menuContainer: RefObject<HTMLDivElement | null>;
};
-const ChannelSelector = ({
+const ChannelsField = ({
+ inputId,
value,
onChange,
error,
- slackChannelIdToName,
- sortedSlackChannels,
- keyPrefix
-}: TChannelSelectorProps) => (
- <FormControl label="Slack channels" isError={Boolean(error)} errorText={error?.message}>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Input
- isReadOnly
- value={value
- ?.filter(Boolean)
- .map((entry) => slackChannelIdToName[entry])
- .join(", ")}
- className="text-left"
- />
- </DropdownMenuTrigger>
- <DropdownMenuContent
- style={{
- width: "var(--radix-dropdown-menu-trigger-width)",
- maxHeight: "350px",
- overflowY: "auto"
- }}
- side="bottom"
- align="start"
- >
- {sortedSlackChannels?.map((slackChannel) => {
- const isChecked = value?.includes(slackChannel.id);
- return (
- <DropdownMenuItem
- onClick={(evt) => {
- evt.preventDefault();
- onChange(
- isChecked
- ? value?.filter((el: string) => el !== slackChannel.id)
- : [...(value || []), slackChannel.id]
- );
- }}
- key={`${keyPrefix}-slack-channel-${slackChannel.id}`}
- iconPos="right"
- icon={isChecked && <FontAwesomeIcon icon={faCheckCircle} />}
- >
- {slackChannel.name}
- </DropdownMenuItem>
- );
- })}
- </DropdownMenuContent>
- </DropdownMenu>
- </FormControl>
+ channels,
+ isLoading,
+ menuContainer
+}: TChannelsFieldProps) => (
+ <Field>
+ <FieldLabel htmlFor={inputId}>Slack channels</FieldLabel>
+ <FilterableSelect
+ isMulti
+ inputId={inputId}
+ options={channels}
+ value={(channels ?? []).filter((channel) => value?.includes(channel.id))}
+ onChange={(selected) =>
+ onChange((selected as readonly SlackIntegrationChannel[]).map((channel) => channel.id))
+ }
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ placeholder="Select channels..."
+ isLoading={isLoading}
+ isError={Boolean(error)}
+ menuPortalTarget={menuContainer.current}
+ menuPosition="fixed"
+ menuPlacement="bottom"
+ closeMenuOnSelect={false}
+ hideSelectedOptions={false}
+ />
+ <FieldError>{error?.message}</FieldError>
+ </Field>
);
-type Props = {
- onClose: () => void;
-};
-
-export const SlackIntegrationForm = ({ onClose }: Props) => {
+export const SlackIntegrationForm = ({ onClose, onBack, menuContainer }: Props) => {
const { currentProject } = useProject();
const { data: slackConfig } = useGetWorkspaceWorkflowIntegrationConfig({
projectId: currentProject?.id ?? "",
integration: WorkflowIntegrationPlatform.SLACK
});
- const { data: workflowIntegrations } = useGetWorkflowIntegrations(currentProject?.orgId);
+ const { data: workflowIntegrations, isPending: isWorkflowIntegrationsLoading } =
+ useGetWorkflowIntegrations(currentProject?.orgId);
const { mutateAsync: updateProjectSlackConfig } = useUpdateProjectWorkflowIntegrationConfig();
const slackIntegrations = workflowIntegrations?.filter(
(integration) => integration.integration === WorkflowIntegrationPlatform.SLACK
);
+ const hasSlackIntegrations = !!slackIntegrations?.length;
const {
control,
@@ -133,6 +125,7 @@ export const SlackIntegrationForm = ({ onClose }: Props) => {
} = useForm<TSlackConfigForm>({
resolver: zodResolver(formSchema),
defaultValues: {
+ slackIntegrationId: "",
isAccessRequestNotificationEnabled: false,
accessRequestChannels: [],
isSecretRequestNotificationEnabled: false,
@@ -159,7 +152,7 @@ export const SlackIntegrationForm = ({ onClose }: Props) => {
createNotification({
type: "success",
- text: "Successfully created slack integration"
+ text: "Saved Slack integration settings"
});
onClose();
@@ -170,13 +163,15 @@ export const SlackIntegrationForm = ({ onClose }: Props) => {
const accessRequestNotifState = watch("isAccessRequestNotificationEnabled");
const secretSyncErrorNotifState = watch("isSecretSyncErrorNotificationEnabled");
- const { data: slackChannels } = useGetSlackIntegrationChannels(selectedSlackIntegrationId);
+ const { data: slackChannels, isPending: isSlackChannelsLoading } = useGetSlackIntegrationChannels(
+ selectedSlackIntegrationId || undefined
+ );
const slackChannelIdToName = Object.fromEntries(
(slackChannels || []).map((channel) => [channel.id, channel.name])
);
- const sortedSlackChannels = slackChannels?.sort((a, b) =>
- a.name.toLowerCase().localeCompare(b.name.toLowerCase())
- );
+ const sortedSlackChannels = slackChannels
+ ?.slice()
+ .sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
useEffect(() => {
if (slackConfig && slackConfig.integration === WorkflowIntegrationPlatform.SLACK) {
@@ -218,161 +213,201 @@ export const SlackIntegrationForm = ({ onClose }: Props) => {
}, [slackConfig, slackChannels]);
return (
- <form onSubmit={handleSubmit(handleIntegrationSave)}>
- <div className="flex w-full flex-col justify-start">
- <ProjectPermissionCan I={ProjectPermissionActions.Edit} a={ProjectPermissionSub.Settings}>
- {(isAllowed) => (
- <Controller
- control={control}
- name="slackIntegrationId"
- render={({ field: { onChange, ...field }, fieldState: { error } }) => (
- <FormControl
- label="Slack Integration"
- errorText={error?.message}
- isError={Boolean(error)}
+ <form
+ onSubmit={handleSubmit(handleIntegrationSave)}
+ className="flex min-h-0 flex-1 flex-col"
+ autoComplete="off"
+ >
+ <div className="flex thin-scrollbar flex-1 flex-col gap-4 overflow-y-auto px-4">
+ {!isWorkflowIntegrationsLoading && !hasSlackIntegrations ? (
+ <Alert>
+ <Info />
+ <AlertTitle>No Slack integrations connected</AlertTitle>
+ <AlertDescription>
+ <p>
+ Connect a Slack workspace to your organization before configuring project
+ notifications.
+ </p>
+ <Button asChild variant="outline" size="sm" className="mt-2">
+ <Link
+ to="/organizations/$orgId/integrations"
+ params={{ orgId: currentProject.orgId }}
+ search={{ selectedTab: "workflow-integrations" }}
>
- <Select
- {...field}
- isDisabled={!isAllowed}
- placeholder="None"
- onValueChange={(val) => {
- onChange(val);
- }}
+ Go to organization integrations
+ </Link>
+ </Button>
+ </AlertDescription>
+ </Alert>
+ ) : (
+ <Controller
+ control={control}
+ name="slackIntegrationId"
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel htmlFor="slack-integration">Slack integration</FieldLabel>
+ <Select value={value} onValueChange={onChange}>
+ <SelectTrigger
+ id="slack-integration"
className="w-full"
- defaultValue={slackConfig?.integrationId}
+ aria-invalid={Boolean(error)}
>
+ <SelectValue
+ placeholder={
+ isWorkflowIntegrationsLoading ? "Loading..." : "Select an integration"
+ }
+ />
+ </SelectTrigger>
+ <SelectContent position="popper">
{slackIntegrations?.map((slackIntegration) => (
- <SelectItem
- value={slackIntegration.id}
- key={`slack-integration-${slackIntegration.id}`}
- >
+ <SelectItem value={slackIntegration.id} key={slackIntegration.id}>
{slackIntegration.slug}
</SelectItem>
))}
- </Select>
- </FormControl>
- )}
- />
- )}
- </ProjectPermissionCan>
- </div>
- {selectedSlackIntegrationId && (
- <>
- <h2 className="mb-2 flex-1 text-sm text-mineshaft-400">Configure Events</h2>
- <Controller
- control={control}
- name="isSecretRequestNotificationEnabled"
- render={({ field, fieldState: { error } }) => {
- return (
- <FormControl
- isError={Boolean(error)}
- errorText={error?.message}
- className="mt-3 mb-2"
- >
- <Switch
- id="secret-approval-notification"
- onCheckedChange={(value) => field.onChange(value)}
- isChecked={field.value}
- >
- <p className="w-full">Secret Approval Requests</p>
- </Switch>
- </FormControl>
- );
- }}
+ </SelectContent>
+ </Select>
+ <FieldError>{error?.message}</FieldError>
+ </Field>
+ )}
/>
- {secretRequestNotifState && (
+ )}
+ {!!selectedSlackIntegrationId && (
+ <>
<Controller
control={control}
- name="secretRequestChannels"
- render={({ field: { value, onChange }, fieldState: { error } }) => (
- <ChannelSelector
- value={value}
- onChange={onChange}
- error={error}
- slackChannelIdToName={slackChannelIdToName}
- sortedSlackChannels={sortedSlackChannels}
- keyPrefix="secret-requests"
- />
+ name="isSecretRequestNotificationEnabled"
+ render={({ field }) => (
+ <Field orientation="horizontal" className="items-center!">
+ <FieldContent>
+ <FieldTitle>Secret approval requests</FieldTitle>
+ <FieldDescription>
+ Send a notification when a secret approval request is opened.
+ </FieldDescription>
+ </FieldContent>
+ <Switch
+ variant="project"
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ aria-label="Secret approval request notifications"
+ />
+ </Field>
)}
/>
- )}
- <Controller
- control={control}
- name="isAccessRequestNotificationEnabled"
- render={({ field, fieldState: { error } }) => {
- return (
- <FormControl isError={Boolean(error)} errorText={error?.message} className="mb-2">
- <Switch
- id="access-request-notification"
- onCheckedChange={(value) => field.onChange(value)}
- isChecked={field.value}
- >
- <p className="w-full">Access Requests</p>
- </Switch>
- </FormControl>
- );
- }}
- />
- {accessRequestNotifState && (
+ {secretRequestNotifState && (
+ <Controller
+ control={control}
+ name="secretRequestChannels"
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <ChannelsField
+ inputId="secret-request-channels"
+ value={value}
+ onChange={onChange}
+ error={error}
+ channels={sortedSlackChannels}
+ isLoading={isSlackChannelsLoading}
+ menuContainer={menuContainer}
+ />
+ )}
+ />
+ )}
<Controller
control={control}
- name="accessRequestChannels"
- render={({ field: { value, onChange }, fieldState: { error } }) => (
- <ChannelSelector
- value={value}
- onChange={onChange}
- error={error}
- slackChannelIdToName={slackChannelIdToName}
- sortedSlackChannels={sortedSlackChannels}
- keyPrefix="access-requests"
- />
+ name="isAccessRequestNotificationEnabled"
+ render={({ field }) => (
+ <Field orientation="horizontal" className="items-center!">
+ <FieldContent>
+ <FieldTitle>Access requests</FieldTitle>
+ <FieldDescription>
+ Send a notification when an access request is opened.
+ </FieldDescription>
+ </FieldContent>
+ <Switch
+ variant="project"
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ aria-label="Access request notifications"
+ />
+ </Field>
)}
/>
- )}
- <Controller
- control={control}
- name="isSecretSyncErrorNotificationEnabled"
- render={({ field, fieldState: { error } }) => {
- return (
- <FormControl isError={Boolean(error)} errorText={error?.message} className="mb-2">
- <Switch
- id="secret-sync-error-notification"
- onCheckedChange={(value) => field.onChange(value)}
- isChecked={field.value}
- >
- <p className="w-full">Secret Sync Errors</p>
- </Switch>
- </FormControl>
- );
- }}
- />
- {secretSyncErrorNotifState && (
+ {accessRequestNotifState && (
+ <Controller
+ control={control}
+ name="accessRequestChannels"
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <ChannelsField
+ inputId="access-request-channels"
+ value={value}
+ onChange={onChange}
+ error={error}
+ channels={sortedSlackChannels}
+ isLoading={isSlackChannelsLoading}
+ menuContainer={menuContainer}
+ />
+ )}
+ />
+ )}
<Controller
control={control}
- name="secretSyncErrorChannels"
- render={({ field: { value, onChange }, fieldState: { error } }) => (
- <ChannelSelector
- value={value}
- onChange={onChange}
- error={error}
- slackChannelIdToName={slackChannelIdToName}
- sortedSlackChannels={sortedSlackChannels}
- keyPrefix="secret-sync-errors"
- />
+ name="isSecretSyncErrorNotificationEnabled"
+ render={({ field }) => (
+ <Field orientation="horizontal" className="items-center!">
+ <FieldContent>
+ <FieldTitle>Secret sync errors</FieldTitle>
+ <FieldDescription>
+ Send a notification when a secret sync fails.
+ </FieldDescription>
+ </FieldContent>
+ <Switch
+ variant="project"
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ aria-label="Secret sync error notifications"
+ />
+ </Field>
)}
/>
- )}
- <Button
- colorSchema="secondary"
- className="mt-4"
- type="submit"
- isDisabled={!isDirty}
- isLoading={isSubmitting}
- >
- Save
+ {secretSyncErrorNotifState && (
+ <Controller
+ control={control}
+ name="secretSyncErrorChannels"
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <ChannelsField
+ inputId="secret-sync-error-channels"
+ value={value}
+ onChange={onChange}
+ error={error}
+ channels={sortedSlackChannels}
+ isLoading={isSlackChannelsLoading}
+ menuContainer={menuContainer}
+ />
+ )}
+ />
+ )}
+ </>
+ )}
+ </div>
+ <SheetFooter className="justify-end border-t">
+ {onBack && (
+ <Button type="button" variant="ghost" className="mr-auto" onClick={onBack}>
+ <ChevronLeft />
+ Back
+ </Button>
+ )}
+ <SheetClose asChild>
+ <Button type="button" variant="ghost">
+ Cancel
</Button>
- </>
- )}
+ </SheetClose>
+ <Button
+ type="submit"
+ variant="project"
+ isPending={isSubmitting}
+ isDisabled={!isDirty || isSubmitting || !hasSlackIntegrations}
+ >
+ Save
+ </Button>
+ </SheetFooter>
</form>
);
};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/constants.ts b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/constants.ts
new file mode 100644
index 0000000000..231a2b65e2
--- /dev/null
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WorkflowIntegrationSection/constants.ts
@@ -0,0 +1,6 @@
+import { WorkflowIntegrationPlatform } from "@app/hooks/api/workflowIntegrations/types";
+
+export const WORKFLOW_INTEGRATION_PLATFORM_LABELS: Record<WorkflowIntegrationPlatform, string> = {
+ [WorkflowIntegrationPlatform.SLACK]: "Slack",
+ [WorkflowIntegrationPlatform.MICROSOFT_TEAMS]: "Microsoft Teams"
+};