mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 07:26:45 +00:00
fix: requested changes
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { ClipboardEvent } from "react";
|
import { ClipboardEvent, useRef } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
|
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
@@ -60,7 +60,7 @@ export const CreateSecretForm = ({
|
|||||||
canReadTags ? workspaceId : ""
|
canReadTags ? workspaceId : ""
|
||||||
);
|
);
|
||||||
|
|
||||||
const secretValue = watch("value");
|
const secretKeyInputRef = useRef<HTMLInputElement>(null);
|
||||||
const secretKey = watch("key");
|
const secretKey = watch("key");
|
||||||
|
|
||||||
const slugSchema = z.string().trim().toLowerCase().min(1);
|
const slugSchema = z.string().trim().toLowerCase().min(1);
|
||||||
@@ -116,13 +116,15 @@ export const CreateSecretForm = ({
|
|||||||
const pastedContent = e.clipboardData.getData("text");
|
const pastedContent = e.clipboardData.getData("text");
|
||||||
const { key, value } = getKeyValue(pastedContent, delimitters);
|
const { key, value } = getKeyValue(pastedContent, delimitters);
|
||||||
|
|
||||||
if (!secretKey) {
|
const isWholeKeyHighlighted =
|
||||||
|
secretKeyInputRef.current &&
|
||||||
|
secretKeyInputRef.current.selectionStart === 0 &&
|
||||||
|
secretKeyInputRef.current.selectionEnd === secretKeyInputRef.current.value.length;
|
||||||
|
|
||||||
|
if (!secretKey || isWholeKeyHighlighted) {
|
||||||
setValue("key", key);
|
setValue("key", key);
|
||||||
}
|
|
||||||
if (!secretValue) {
|
|
||||||
setValue("value", value);
|
setValue("value", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!secretKey) {
|
if (!secretKey) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
@@ -138,6 +140,7 @@ export const CreateSecretForm = ({
|
|||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
{...register("key")}
|
{...register("key")}
|
||||||
|
ref={secretKeyInputRef}
|
||||||
placeholder="Type your secret name"
|
placeholder="Type your secret name"
|
||||||
onPaste={handlePaste}
|
onPaste={handlePaste}
|
||||||
autoCapitalization={autoCapitalize}
|
autoCapitalization={autoCapitalize}
|
||||||
|
|||||||
+9
-6
@@ -1,4 +1,4 @@
|
|||||||
import { ClipboardEvent } from "react";
|
import { ClipboardEvent, useRef } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { subject } from "@casl/ability";
|
import { subject } from "@casl/ability";
|
||||||
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
|
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
|
||||||
@@ -62,7 +62,7 @@ export const CreateSecretForm = ({ secretPath = "/", onClose }: Props) => {
|
|||||||
canReadTags ? workspaceId : ""
|
canReadTags ? workspaceId : ""
|
||||||
);
|
);
|
||||||
|
|
||||||
const secretValue = watch("value");
|
const secretKeyInputRef = useRef<HTMLInputElement>(null);
|
||||||
const secretKey = watch("key");
|
const secretKey = watch("key");
|
||||||
|
|
||||||
const handleFormSubmit = async ({ key, value, environments: selectedEnv, tags }: TFormSchema) => {
|
const handleFormSubmit = async ({ key, value, environments: selectedEnv, tags }: TFormSchema) => {
|
||||||
@@ -160,13 +160,15 @@ export const CreateSecretForm = ({ secretPath = "/", onClose }: Props) => {
|
|||||||
const pastedContent = e.clipboardData.getData("text");
|
const pastedContent = e.clipboardData.getData("text");
|
||||||
const { key, value } = getKeyValue(pastedContent, delimitters);
|
const { key, value } = getKeyValue(pastedContent, delimitters);
|
||||||
|
|
||||||
if (!secretKey) {
|
const isWholeKeyHighlighted =
|
||||||
|
secretKeyInputRef.current &&
|
||||||
|
secretKeyInputRef.current.selectionStart === 0 &&
|
||||||
|
secretKeyInputRef.current.selectionEnd === secretKeyInputRef.current.value.length;
|
||||||
|
|
||||||
|
if (!secretKey || isWholeKeyHighlighted) {
|
||||||
setValue("key", key);
|
setValue("key", key);
|
||||||
}
|
|
||||||
if (!secretValue) {
|
|
||||||
setValue("value", value);
|
setValue("value", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!secretKey) {
|
if (!secretKey) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
@@ -201,6 +203,7 @@ export const CreateSecretForm = ({ secretPath = "/", onClose }: Props) => {
|
|||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
{...register("key")}
|
{...register("key")}
|
||||||
|
ref={secretKeyInputRef}
|
||||||
placeholder="Type your secret name"
|
placeholder="Type your secret name"
|
||||||
onPaste={handlePaste}
|
onPaste={handlePaste}
|
||||||
autoCapitalization={currentWorkspace?.autoCapitalization}
|
autoCapitalization={currentWorkspace?.autoCapitalization}
|
||||||
|
|||||||
Reference in New Issue
Block a user