mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 08:29:55 +00:00
86 lines
3.1 KiB
TypeScript
86 lines
3.1 KiB
TypeScript
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_ROTATION_CONNECTION_MAP } from "@app/helpers/secretRotationsV2";
|
|
import { useListAvailableAppConnections } from "@app/hooks/api/appConnections";
|
|
|
|
import { TSecretRotationV2Form } from "./schemas";
|
|
|
|
type Props = {
|
|
onChange?: VoidFunction;
|
|
isUpdate: boolean;
|
|
};
|
|
|
|
export const SecretRotationV2ConnectionField = ({ onChange: callback, isUpdate }: Props) => {
|
|
const { permission } = useOrgPermission();
|
|
const { control, watch } = useFormContext<TSecretRotationV2Form>();
|
|
|
|
const rotationType = watch("type");
|
|
const app = SECRET_ROTATION_CONNECTION_MAP[rotationType];
|
|
|
|
const { data: availableConnections, isPending } = useListAvailableAppConnections(app);
|
|
|
|
const connectionName = APP_CONNECTION_MAP[app].name;
|
|
|
|
const canCreateConnection = permission.can(
|
|
OrgPermissionAppConnectionActions.Create,
|
|
OrgPermissionSubjects.AppConnections
|
|
);
|
|
|
|
const appName = APP_CONNECTION_MAP[app].name;
|
|
|
|
return (
|
|
<>
|
|
<Controller
|
|
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
|
<FormControl
|
|
tooltipText="App Connections can be created from the Organization Settings page."
|
|
isError={Boolean(error)}
|
|
errorText={error?.message}
|
|
label={`${connectionName} Connection`}
|
|
helperText={isUpdate ? "Cannot be updated" : undefined}
|
|
>
|
|
<FilterableSelect
|
|
value={value}
|
|
onChange={(newValue) => {
|
|
onChange(newValue);
|
|
if (callback) callback();
|
|
}}
|
|
isLoading={isPending}
|
|
options={availableConnections}
|
|
isDisabled={isUpdate}
|
|
placeholder="Select connection..."
|
|
getOptionLabel={(option) => option.name}
|
|
getOptionValue={(option) => option.id}
|
|
/>
|
|
</FormControl>
|
|
)}
|
|
control={control}
|
|
name="connection"
|
|
/>
|
|
{!isUpdate && availableConnections?.length === 0 && (
|
|
<p className="-mt-2.5 mb-2.5 text-xs text-yellow">
|
|
<FontAwesomeIcon className="mr-1" size="xs" icon={faInfoCircle} />
|
|
{canCreateConnection ? (
|
|
<>
|
|
You do not have access to any {appName} Connections. Create one from the{" "}
|
|
<Link to="/organization/app-connections" className="underline">
|
|
App Connections
|
|
</Link>{" "}
|
|
page.
|
|
</>
|
|
) : (
|
|
`You do not have access to any ${appName} Connections. Contact an admin to create one.`
|
|
)}
|
|
</p>
|
|
)}
|
|
</>
|
|
);
|
|
};
|