import { Controller, useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { createNotification } from "@app/components/notifications"; import { Button, FormControl, Modal, ModalClose, ModalContent, Select, SelectItem } from "@app/components/v2"; import { SECRET_SYNC_IMPORT_BEHAVIOR_MAP, SECRET_SYNC_MAP } from "@app/helpers/secretSyncs"; import { SecretSyncImportBehavior, TSecretSync, useTriggerSecretSyncImportSecrets } from "@app/hooks/api/secretSyncs"; type Props = { secretSync?: TSecretSync; isOpen: boolean; onOpenChange: (isOpen: boolean) => void; }; type ContentProps = { secretSync: TSecretSync; onComplete: () => void; }; const FormSchema = z.object({ importBehavior: z.nativeEnum(SecretSyncImportBehavior) }); type TFormData = z.infer; const Content = ({ secretSync, onComplete }: ContentProps) => { const { id: syncId, destination, projectId } = secretSync; const destinationName = SECRET_SYNC_MAP[destination].name; const { handleSubmit, control, formState: { isSubmitting, isDirty } } = useForm({ resolver: zodResolver(FormSchema) }); const triggerImportSecrets = useTriggerSecretSyncImportSecrets(); const handleTriggerImportSecrets = async ({ importBehavior }: TFormData) => { try { await triggerImportSecrets.mutateAsync({ syncId, destination, importBehavior, projectId }); createNotification({ text: `Successfully triggered secret import for ${destinationName} Sync`, type: "success" }); onComplete(); } catch (err) { console.error(err); createNotification({ text: `Failed to trigger secret import for ${destinationName} Sync`, type: "error" }); } }; return (

Are you sure you want to import secrets from this {destinationName} destination into Infiscal?

(

Specify how Infisical should resolve importing secrets from {destinationName}. The following options are available:

    {Object.values(SECRET_SYNC_IMPORT_BEHAVIOR_MAP).map((details) => { const { name, description } = details(destinationName); return (
  • {name}: {description}

  • ); })}
} errorText={error?.message} isError={Boolean(error?.message)} label="Import Behavior" >
)} />
); }; export const SecretSyncImportSecretsModal = ({ isOpen, onOpenChange, secretSync }: Props) => { if (!secretSync) return null; const destinationName = SECRET_SYNC_MAP[secretSync.destination].name; return ( onOpenChange(false)} /> ); };