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