adjustment: simplified onchange propagation

This commit is contained in:
Sheen Capadngan
2024-04-27 00:32:34 +08:00
parent 2b0670a409
commit d6a5bf9d50
3 changed files with 7 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ import { useGetFoldersByEnv } from "@app/hooks/api";
import { Input } from "../Input";
type Props = Omit<InputHTMLAttributes<HTMLInputElement>, "size"> & {
type Props = Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "onChange"> & {
value?: string | null;
isImport?: boolean;
isVisible?: boolean;
@@ -18,6 +18,7 @@ type Props = Omit<InputHTMLAttributes<HTMLInputElement>, "size"> & {
isDisabled?: boolean;
environment?: string;
containerClassName?: string;
onChange?: (arg: string) => void;
};
export const SecretPathInput = ({
@@ -49,7 +50,7 @@ export const SecretPathInput = ({
if (environment) {
setInputValue("/");
setSecretPath("/");
onChange?.({ target: { value: "/" } } as any);
onChange?.("/");
}
}, [environment]);
@@ -83,7 +84,7 @@ export const SecretPathInput = ({
validPaths.pop();
const newValue = `${validPaths.join("/")}/${suggestions[selectedIndex]}`;
onChange?.({ target: { value: newValue } } as any);
onChange?.(newValue);
setInputValue(newValue);
setSecretPath(newValue);
setHighlightedIndex(-1);
@@ -107,7 +108,7 @@ export const SecretPathInput = ({
const handleInputChange = (e: any) => {
// propagate event to react-hook-form onChange
if (onChange) {
onChange(e);
onChange(e.target.value);
}
setInputValue(e.target.value);

View File

@@ -125,7 +125,7 @@ export default function CloudflarePagesIntegrationPage() {
<FormControl label="Infisical Secret Path" className="mt-2 px-6">
<SecretPathInput
value={secretPath}
onChange={(evt) => setSecretPath(evt.target.value)}
onChange={(value) => setSecretPath(value)}
environment={selectedSourceEnvironment}
placeholder="Provide a path, default is /"
/>

View File

@@ -116,7 +116,7 @@ export default function CloudflareWorkersIntegrationPage() {
<FormControl label="Infisical Secret Path" className="mt-2 px-6">
<SecretPathInput
value={secretPath}
onChange={(evt) => setSecretPath(evt.target.value)}
onChange={(value) => setSecretPath(value)}
environment={selectedSourceEnvironment}
placeholder="Provide a path, default is /"
/>