import React, { useState } from "react"; import { useDeleteSsoProviderMutation, useGetSsoProviders, } from "@/ee/security/queries/security-query.ts"; import { ActionIcon, Badge, Card, Group, Menu, Table, Text, ThemeIcon, } from "@mantine/core"; import { IconCheck, IconDots, IconLock, IconPencil, IconTrash, IconX, } from "@tabler/icons-react"; import { useDisclosure } from "@mantine/hooks"; import { modals } from "@mantine/modals"; import { IAuthProvider } from "@/ee/security/types/security.types.ts"; import { useTranslation } from "react-i18next"; import SsoProviderModal from "@/ee/security/components/sso-provider-modal.tsx"; import { SSO_PROVIDER } from "@/ee/security/contants.ts"; import { GoogleIcon } from "@/components/icons/google-icon.tsx"; import { CustomAvatar } from "@/components/ui/custom-avatar.tsx"; import RoleSelectMenu from "@/components/ui/role-select-menu.tsx"; import { getUserRoleLabel } from "@/features/workspace/types/user-role-data.ts"; export default function SsoProviderList() { const { t } = useTranslation(); const { data, isLoading } = useGetSsoProviders(); const [opened, { open, close }] = useDisclosure(false); const deleteSsoProviderMutation = useDeleteSsoProviderMutation(); const [editProvider, setEditProvider] = useState(null); if (isLoading || !data) { return null; } if (data?.items.length === 0) { return {t("No SSO providers found.")}; } const handleEdit = (provider: IAuthProvider) => { setEditProvider(provider); open(); }; const openDeleteModal = (providerId: string) => modals.openConfirmModal({ title: t("Delete SSO provider"), centered: true, children: ( {t("Are you sure you want to delete this SSO provider?")} ), labels: { confirm: t("Delete"), cancel: t("Don't") }, confirmProps: { color: "red" }, onConfirm: () => deleteSsoProviderMutation.mutateAsync(providerId), }); return ( <> {t("Name")} {t("Type")} {t("Status")} {t("Allow signup")} {t("Action")} {data?.items .sort((a, b) => { const enabledDiff = Number(b.isEnabled) - Number(a.isEnabled); if (enabledDiff !== 0) return enabledDiff; return a.name.localeCompare(b.name); }) .map((provider: IAuthProvider, index) => ( {provider.type === SSO_PROVIDER.GOOGLE ? ( ) : ( )}
{provider.name}
{provider.type.toUpperCase()} {provider.isEnabled ? "Active" : "InActive"} {provider.allowSignup ? ( ) : ( )} handleEdit(provider)} > handleEdit(provider)} leftSection={} > {t("Edit")} openDeleteModal(provider.id)} leftSection={} color="red" disabled={provider.type === SSO_PROVIDER.GOOGLE} > {t("Delete")}
))}
); }