mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-09 23:28:31 +00:00
feat: parse full env secrets (key,value) when pasted from clipboard
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { ClipboardEvent } from 'react';
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
@@ -38,6 +39,7 @@ export const CreateSecretForm = ({
|
|||||||
handleSubmit,
|
handleSubmit,
|
||||||
control,
|
control,
|
||||||
reset,
|
reset,
|
||||||
|
setValue,
|
||||||
formState: { errors, isSubmitting }
|
formState: { errors, isSubmitting }
|
||||||
} = useForm<TFormSchema>({ resolver: zodResolver(typeSchema) });
|
} = useForm<TFormSchema>({ resolver: zodResolver(typeSchema) });
|
||||||
const { isOpen } = usePopUpState(PopUpNames.CreateSecretForm);
|
const { isOpen } = usePopUpState(PopUpNames.CreateSecretForm);
|
||||||
@@ -73,6 +75,20 @@ export const CreateSecretForm = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePaste = (e: ClipboardEvent<HTMLInputElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const pastedContent = e.clipboardData.getData('text');
|
||||||
|
const splitIndex = pastedContent.indexOf("=");
|
||||||
|
|
||||||
|
if (splitIndex == -1) return
|
||||||
|
|
||||||
|
const key = pastedContent.slice(0, splitIndex)
|
||||||
|
const value = pastedContent.slice(splitIndex + 1);
|
||||||
|
|
||||||
|
setValue('key', key);
|
||||||
|
setValue('value', value);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
@@ -87,6 +103,7 @@ export const CreateSecretForm = ({
|
|||||||
<Input
|
<Input
|
||||||
{...register("key")}
|
{...register("key")}
|
||||||
placeholder="Type your secret name"
|
placeholder="Type your secret name"
|
||||||
|
onPaste={handlePaste}
|
||||||
autoCapitalization={autoCapitalize}
|
autoCapitalization={autoCapitalize}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|||||||
+18
@@ -1,3 +1,4 @@
|
|||||||
|
import { ClipboardEvent } from 'react';
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { faWarning } from "@fortawesome/free-solid-svg-icons";
|
import { faWarning } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
@@ -54,6 +55,7 @@ export const CreateSecretForm = ({
|
|||||||
control,
|
control,
|
||||||
reset,
|
reset,
|
||||||
watch,
|
watch,
|
||||||
|
setValue,
|
||||||
formState: { isSubmitting, errors }
|
formState: { isSubmitting, errors }
|
||||||
} = useForm<TFormSchema>({ resolver: zodResolver(typeSchema) });
|
} = useForm<TFormSchema>({ resolver: zodResolver(typeSchema) });
|
||||||
const newSecretKey = watch("key");
|
const newSecretKey = watch("key");
|
||||||
@@ -133,6 +135,21 @@ export const CreateSecretForm = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePaste = (e: ClipboardEvent<HTMLInputElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const pastedContent = e.clipboardData.getData('text');
|
||||||
|
const splitIndex = pastedContent.indexOf("=");
|
||||||
|
|
||||||
|
if (splitIndex == -1) return
|
||||||
|
|
||||||
|
const key = pastedContent.slice(0, splitIndex)
|
||||||
|
const value = pastedContent.slice(splitIndex + 1);
|
||||||
|
|
||||||
|
setValue('key', key);
|
||||||
|
setValue('value', value);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={isOpen} onOpenChange={onTogglePopUp}>
|
<Modal isOpen={isOpen} onOpenChange={onTogglePopUp}>
|
||||||
<ModalContent
|
<ModalContent
|
||||||
@@ -145,6 +162,7 @@ export const CreateSecretForm = ({
|
|||||||
<Input
|
<Input
|
||||||
{...register("key")}
|
{...register("key")}
|
||||||
placeholder="Type your secret name"
|
placeholder="Type your secret name"
|
||||||
|
onPaste={handlePaste}
|
||||||
autoCapitalization={currentWorkspace?.autoCapitalization}
|
autoCapitalization={currentWorkspace?.autoCapitalization}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|||||||
Reference in New Issue
Block a user