mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 13:28:27 +00:00
adjustment: converted remaining salug validation to use slugify
This commit is contained in:
@@ -17,7 +17,6 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Migrate to better form management and validation. Preferable react-hook-form + yup
|
// TODO: Migrate to better form management and validation. Preferable react-hook-form + yup
|
||||||
// We should remove this?
|
|
||||||
/**
|
/**
|
||||||
* The dialog modal for when the user wants to create a new workspace
|
* The dialog modal for when the user wants to create a new workspace
|
||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
|
|||||||
+14
-3
@@ -1,5 +1,6 @@
|
|||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { yupResolver } from "@hookform/resolvers/yup";
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
|
import slugify from "@sindresorhus/slugify";
|
||||||
import * as yup from "yup";
|
import * as yup from "yup";
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
@@ -16,13 +17,19 @@ type Props = {
|
|||||||
|
|
||||||
const schema = yup.object({
|
const schema = yup.object({
|
||||||
name: yup.string().label("Environment Name").required(),
|
name: yup.string().label("Environment Name").required(),
|
||||||
slug: yup.string().label("Environment Slug").matches(/^[^./]*$/g, { message: "Invalid [.] or [/] not allowed"}).required()
|
slug: yup
|
||||||
|
.string()
|
||||||
|
.label("Environment Slug")
|
||||||
|
.test({
|
||||||
|
test: (slug) => slugify(slug as string) === slug,
|
||||||
|
message: "Slug must be a valid slug"
|
||||||
|
})
|
||||||
|
.required()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type FormData = yup.InferType<typeof schema>;
|
export type FormData = yup.InferType<typeof schema>;
|
||||||
|
|
||||||
export const UpdateEnvironmentModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Props) => {
|
export const UpdateEnvironmentModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Props) => {
|
||||||
|
|
||||||
const { currentWorkspace } = useWorkspace();
|
const { currentWorkspace } = useWorkspace();
|
||||||
const { mutateAsync, isLoading } = useUpdateWsEnvironment();
|
const { mutateAsync, isLoading } = useUpdateWsEnvironment();
|
||||||
const { control, handleSubmit, reset } = useForm<FormData>({
|
const { control, handleSubmit, reset } = useForm<FormData>({
|
||||||
@@ -108,7 +115,11 @@ export const UpdateEnvironmentModal = ({ popUp, handlePopUpClose, handlePopUpTog
|
|||||||
Update
|
Update
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button onClick={() => handlePopUpClose("updateEnv")} colorSchema="secondary" variant="plain">
|
<Button
|
||||||
|
onClick={() => handlePopUpClose("updateEnv")}
|
||||||
|
colorSchema="secondary"
|
||||||
|
variant="plain"
|
||||||
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user