import { useMemo } from "react"; import { Controller, useFormContext } from "react-hook-form"; import { faInfoCircle } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Link } from "@tanstack/react-router"; import { FilterableSelect, FormControl } from "@app/components/v2"; import { OrgPermissionSubjects, useOrgPermission } from "@app/context"; import { OrgPermissionAppConnectionActions } from "@app/context/OrgPermissionContext/types"; import { APP_CONNECTION_MAP } from "@app/helpers/appConnections"; import { SECRET_SYNC_CONNECTION_MAP } from "@app/helpers/secretSyncs"; import { TAvailableAppConnection, useListAvailableAppConnections } from "@app/hooks/api/appConnections"; import { TSecretSyncForm } from "./schemas"; type Props = { onChange?: VoidFunction; }; export const SecretSyncConnectionField = ({ onChange: callback, filterConnections }: Props) => { const { permission } = useOrgPermission(); const { control, watch } = useFormContext(); const destination = watch("destination"); const app = SECRET_SYNC_CONNECTION_MAP[destination]; const { data: availableConnections, isLoading } = useListAvailableAppConnections(app); const connectionName = APP_CONNECTION_MAP[app].name; const canCreateConnection = permission.can( OrgPermissionAppConnectionActions.Create, OrgPermissionSubjects.AppConnections ); const appName = APP_CONNECTION_MAP[SECRET_SYNC_CONNECTION_MAP[destination]].name; return ( <>

Specify the {appName} Connection to use to connect to {connectionName} and configure destination parameters.

( { onChange(newValue); if (callback) callback(); }} isLoading={isLoading} options={availableConnections} placeholder="Select connection..." getOptionLabel={(option) => option.name} getOptionValue={(option) => option.id} /> )} control={control} name="connection" /> {availableConnections?.length === 0 && (

{canCreateConnection ? ( <> You do not have access to any {appName} Connections. Create one from the{" "} Organization Settings {" "} page. ) : ( `You do not have access to any ${appName} Connections. Contact an admin to create one.` )}

)} ); };