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
@@ -10,7 +10,7 @@ import { useGetFoldersByEnv } from "@app/hooks/api";
import { Input } from "../Input"; import { Input } from "../Input";
type Props = Omit<InputHTMLAttributes<HTMLInputElement>, "size"> & { type Props = Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "onChange"> & {
value?: string | null; value?: string | null;
isImport?: boolean; isImport?: boolean;
isVisible?: boolean; isVisible?: boolean;
@@ -18,6 +18,7 @@ type Props = Omit<InputHTMLAttributes<HTMLInputElement>, "size"> & {
isDisabled?: boolean; isDisabled?: boolean;
environment?: string; environment?: string;
containerClassName?: string; containerClassName?: string;
onChange?: (arg: string) => void;
}; };
export const SecretPathInput = ({ export const SecretPathInput = ({
@@ -49,7 +50,7 @@ export const SecretPathInput = ({
if (environment) { if (environment) {
setInputValue("/"); setInputValue("/");
setSecretPath("/"); setSecretPath("/");
onChange?.({ target: { value: "/" } } as any); onChange?.("/");
} }
}, [environment]); }, [environment]);
@@ -83,7 +84,7 @@ export const SecretPathInput = ({
validPaths.pop(); validPaths.pop();
const newValue = `${validPaths.join("/")}/${suggestions[selectedIndex]}`; const newValue = `${validPaths.join("/")}/${suggestions[selectedIndex]}`;
onChange?.({ target: { value: newValue } } as any); onChange?.(newValue);
setInputValue(newValue); setInputValue(newValue);
setSecretPath(newValue); setSecretPath(newValue);
setHighlightedIndex(-1); setHighlightedIndex(-1);
@@ -107,7 +108,7 @@ export const SecretPathInput = ({
const handleInputChange = (e: any) => { const handleInputChange = (e: any) => {
// propagate event to react-hook-form onChange // propagate event to react-hook-form onChange
if (onChange) { if (onChange) {
onChange(e); onChange(e.target.value);
} }
setInputValue(e.target.value); setInputValue(e.target.value);
@@ -125,7 +125,7 @@ export default function CloudflarePagesIntegrationPage() {
<FormControl label="Infisical Secret Path" className="mt-2 px-6"> <FormControl label="Infisical Secret Path" className="mt-2 px-6">
<SecretPathInput <SecretPathInput
value={secretPath} value={secretPath}
onChange={(evt) => setSecretPath(evt.target.value)} onChange={(value) => setSecretPath(value)}
environment={selectedSourceEnvironment} environment={selectedSourceEnvironment}
placeholder="Provide a path, default is /" placeholder="Provide a path, default is /"
/> />
@@ -116,7 +116,7 @@ export default function CloudflareWorkersIntegrationPage() {
<FormControl label="Infisical Secret Path" className="mt-2 px-6"> <FormControl label="Infisical Secret Path" className="mt-2 px-6">
<SecretPathInput <SecretPathInput
value={secretPath} value={secretPath}
onChange={(evt) => setSecretPath(evt.target.value)} onChange={(value) => setSecretPath(value)}
environment={selectedSourceEnvironment} environment={selectedSourceEnvironment}
placeholder="Provide a path, default is /" placeholder="Provide a path, default is /"
/> />