()
| 102 | } |
| 103 | |
| 104 | export function SSO() { |
| 105 | const { data: session } = useSession() |
| 106 | const { data: orgsData } = useOrganizations() |
| 107 | const { data: subscriptionData } = useSubscriptionData() |
| 108 | |
| 109 | const activeOrganization = orgsData?.activeOrganization |
| 110 | |
| 111 | const { data: providersData, isLoading: isLoadingProviders } = useSSOProviders({ |
| 112 | organizationId: activeOrganization?.id, |
| 113 | }) |
| 114 | |
| 115 | const providers = providersData?.providers || [] |
| 116 | const existingProvider = providers[0] as SSOProvider | undefined |
| 117 | |
| 118 | const userEmail = session?.user?.email |
| 119 | const userId = session?.user?.id |
| 120 | const userRole = getUserRole(orgsData?.activeOrganization, userEmail) |
| 121 | const isOwner = userRole === 'owner' |
| 122 | const isAdmin = userRole === 'admin' |
| 123 | const canManageSSO = isOwner || isAdmin |
| 124 | const subscriptionAccess = getSubscriptionAccessState(subscriptionData?.data) |
| 125 | const hasEnterprisePlan = subscriptionAccess.hasUsableEnterpriseAccess |
| 126 | |
| 127 | const isSSOProviderOwner = |
| 128 | !isBillingEnabled && userId ? providers.some((p) => p.userId === userId) : null |
| 129 | |
| 130 | const configureSSOMutation = useConfigureSSO() |
| 131 | |
| 132 | const [showClientSecret, setShowClientSecret] = useState(false) |
| 133 | const [copied, setCopied] = useState(false) |
| 134 | const [isEditing, setIsEditing] = useState(false) |
| 135 | const [showAdvanced, setShowAdvanced] = useState(false) |
| 136 | |
| 137 | const [formData, setFormData] = useState(DEFAULT_FORM_DATA) |
| 138 | const [originalFormData, setOriginalFormData] = useState(DEFAULT_FORM_DATA) |
| 139 | const [errors, setErrors] = useState<Record<string, string[]>>(DEFAULT_ERRORS) |
| 140 | const [showErrors, setShowErrors] = useState(false) |
| 141 | |
| 142 | const hasChanges = (Object.keys(formData) as (keyof typeof formData)[]).some( |
| 143 | (k) => formData[k] !== originalFormData[k] |
| 144 | ) |
| 145 | |
| 146 | useSettingsUnsavedGuard({ isDirty: hasChanges }) |
| 147 | |
| 148 | if (isBillingEnabled) { |
| 149 | if (!activeOrganization) { |
| 150 | return ( |
| 151 | <SettingsEmptyState> |
| 152 | You must be part of an organization to configure Single Sign-On. |
| 153 | </SettingsEmptyState> |
| 154 | ) |
| 155 | } |
| 156 | |
| 157 | if (!hasEnterprisePlan) { |
| 158 | return ( |
| 159 | <SettingsEmptyState> |
| 160 | Single Sign-On is available on Enterprise plans only. |
| 161 | </SettingsEmptyState> |
nothing calls this directly
no test coverage detected