Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
import { Controller, useFormContext, useWatch } from "react-hook-form";
import { Info } from "lucide-react";
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
import {
Combobox,
Field,
FieldContent,
FieldError,
FieldGroup,
FieldLabel,
Tooltip,
TooltipContent,
TooltipTrigger
} from "@app/components/v3";
import {
useNorthflankConnectionListProjects,
useNorthflankConnectionListSecretGroups
} from "@app/hooks/api/appConnections/northflank";
import { SecretSync } from "@app/hooks/api/secretSyncs";
import { TSecretSyncForm } from "../schemas";
export const NorthflankSyncFields = () => {
const { control, setValue } = useFormContext<
TSecretSyncForm & { destination: SecretSync.Northflank }
>();
const connectionId = useWatch({ name: "connection.id", control });
const projectId = useWatch({ name: "destinationConfig.projectId", control });
const { data: projects = [], isPending: isProjectsLoading } = useNorthflankConnectionListProjects(
connectionId,
{
enabled: Boolean(connectionId)
}
);
const { data: secretGroups = [], isPending: isSecretGroupsLoading } =
useNorthflankConnectionListSecretGroups(connectionId, projectId, {
enabled: Boolean(connectionId) && Boolean(projectId)
});
return (
<FieldGroup>
<SecretSyncConnectionField
onChange={() => {
setValue("destinationConfig.projectId", "");
setValue("destinationConfig.projectName", "");
setValue("destinationConfig.secretGroupId", "");
setValue("destinationConfig.secretGroupName", "");
}}
/>
<Controller
name="destinationConfig.projectId"
control={control}
render={({ field: { value, onChange }, fieldState: { error } }) => (
<Field>
<FieldLabel
id="secret-sync-northflank-project-id-label"
htmlFor="secret-sync-northflank-project-id"
>
Project
<Tooltip>
<TooltipTrigger asChild>
<Info />
</TooltipTrigger>
<TooltipContent className="max-w-md">
Ensure the project exists in the connection's Northflank team and the
connection has access to it.
</TooltipContent>
</Tooltip>
</FieldLabel>
<FieldContent>
<Combobox
aria-labelledby="secret-sync-northflank-project-id-label"
aria-describedby={error ? "secret-sync-northflank-project-id-error" : undefined}
id="secret-sync-northflank-project-id"
isError={Boolean(error)}
isLoading={isProjectsLoading && Boolean(connectionId)}
isDisabled={!connectionId}
value={projects.find((p) => p.id === value) ?? null}
onValueChange={(option) => {
const v = option;
onChange(v?.id ?? null);
setValue("destinationConfig.projectName", v?.name ?? "");
setValue("destinationConfig.secretGroupId", "");
setValue("destinationConfig.secretGroupName", "");
}}
options={projects}
placeholder="Select a project..."
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}
getOptionKeywords={(option) => [option.id]}
modal
/>
<FieldError id="secret-sync-northflank-project-id-error" errors={[error]} />
</FieldContent>
</Field>
)}
/>
<Controller
name="destinationConfig.secretGroupId"
control={control}
render={({ field: { value, onChange }, fieldState: { error } }) => (
<Field>
<FieldLabel
id="secret-sync-northflank-secret-group-id-label"
htmlFor="secret-sync-northflank-secret-group-id"
>
Secret Group
<Tooltip>
<TooltipTrigger asChild>
<Info />
</TooltipTrigger>
<TooltipContent className="max-w-md">
Ensure the secret group exists in the connection's Northflank project and the
connection has access to it.
</TooltipContent>
</Tooltip>
</FieldLabel>
<FieldContent>
<Combobox
aria-labelledby="secret-sync-northflank-secret-group-id-label"
aria-describedby={
error ? "secret-sync-northflank-secret-group-id-error" : undefined
}
id="secret-sync-northflank-secret-group-id"
isError={Boolean(error)}
isLoading={isSecretGroupsLoading && Boolean(projectId)}
isDisabled={!projectId}
value={secretGroups.find((sg) => sg.id === value) ?? null}
onValueChange={(option) => {
const v = option;
onChange(v?.id ?? null);
setValue("destinationConfig.secretGroupName", v?.name ?? "");
}}
options={secretGroups}
placeholder="Select a secret group..."
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}
getOptionKeywords={(option) => [option.id]}
modal
/>
<FieldError id="secret-sync-northflank-secret-group-id-error" errors={[error]} />
</FieldContent>
</Field>
)}
/>
</FieldGroup>
);
};