mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 19:26:19 +00:00
Merge pull request #4941 from Infisical/ENG-4186
[ENG-4186] fix: secerets management project slug automatic generation
This commit is contained in:
+23
-3
@@ -1,5 +1,6 @@
|
|||||||
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 slugify from "@sindresorhus/slugify";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
@@ -31,7 +32,13 @@ type ContentProps = {
|
|||||||
const Content = ({ onComplete }: ContentProps) => {
|
const Content = ({ onComplete }: ContentProps) => {
|
||||||
const { currentProject } = useProject();
|
const { currentProject } = useProject();
|
||||||
const { mutateAsync, isPending } = useCreateWsEnvironment();
|
const { mutateAsync, isPending } = useCreateWsEnvironment();
|
||||||
const { control, handleSubmit } = useForm<FormData>({
|
const {
|
||||||
|
control,
|
||||||
|
handleSubmit,
|
||||||
|
setValue,
|
||||||
|
getValues,
|
||||||
|
formState: { dirtyFields }
|
||||||
|
} = useForm<FormData>({
|
||||||
resolver: zodResolver(schema)
|
resolver: zodResolver(schema)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -52,15 +59,28 @@ const Content = ({ onComplete }: ContentProps) => {
|
|||||||
onComplete(env);
|
onComplete(env);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleEnvironmentNameChange = () => {
|
||||||
|
if (dirtyFields.environmentSlug) return;
|
||||||
|
|
||||||
|
const value = getValues("environmentName");
|
||||||
|
setValue("environmentSlug", slugify(value, { lowercase: true }));
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit(onFormSubmit)}>
|
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
defaultValue=""
|
defaultValue=""
|
||||||
name="environmentName"
|
name="environmentName"
|
||||||
render={({ field, fieldState: { error } }) => (
|
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
||||||
<FormControl label="Environment Name" isError={Boolean(error)} errorText={error?.message}>
|
<FormControl label="Environment Name" isError={Boolean(error)} errorText={error?.message}>
|
||||||
<Input {...field} />
|
<Input
|
||||||
|
{...field}
|
||||||
|
onChange={(e) => {
|
||||||
|
onChange(e);
|
||||||
|
handleEnvironmentNameChange();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user