adjustment: converted remaining salug validation to use slugify

This commit is contained in:
Sheen Capadngan
2024-04-23 21:14:33 +08:00
parent 80b0dc6895
commit 872f8bdad8
2 changed files with 14 additions and 4 deletions
@@ -17,7 +17,6 @@ type Props = {
};
// 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
* @param {*} param0
@@ -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 { createNotification } from "@app/components/notifications";
@@ -16,13 +17,19 @@ type Props = {
const schema = yup.object({
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 const UpdateEnvironmentModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Props) => {
const { currentWorkspace } = useWorkspace();
const { mutateAsync, isLoading } = useUpdateWsEnvironment();
const { control, handleSubmit, reset } = useForm<FormData>({
@@ -108,7 +115,11 @@ export const UpdateEnvironmentModal = ({ popUp, handlePopUpClose, handlePopUpTog
Update
</Button>
<Button onClick={() => handlePopUpClose("updateEnv")} colorSchema="secondary" variant="plain">
<Button
onClick={() => handlePopUpClose("updateEnv")}
colorSchema="secondary"
variant="plain"
>
Cancel
</Button>
</div>