adjustment: standardized slug validation

This commit is contained in:
Sheen Capadngan
2024-04-23 10:25:36 +08:00
parent 6daeed68a0
commit 738e8cfc5c
5 changed files with 67 additions and 3 deletions
@@ -166,7 +166,7 @@ export default function SecretReferenceSelect({
})}
{listReference.length !== 0 && (
<SelectPrimitive.Separator className="m-1 h-[1px] mb-2 bg-mineshaft-400" />
<SelectPrimitive.Separator className="m-1 mb-2 h-[1px] bg-mineshaft-400" />
)}
</SelectPrimitive.Group>
@@ -1,5 +1,6 @@
import { Controller, useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
import slugify from "@sindresorhus/slugify";
import * as yup from "yup";
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
@@ -16,7 +17,14 @@ type Props = {
const schema = yup.object({
environmentName: yup.string().label("Environment Name").required(),
environmentSlug: yup.string().label("Environment Slug").matches(/^[^./]*$/g, { message: "Invalid [.] or [/] not allowed"}).required()
environmentSlug: 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>;