mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix(site): validate group name before submitting to the backend (#16115)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -54,6 +54,7 @@ site/stats/
|
||||
|
||||
# direnv
|
||||
.envrc
|
||||
.direnv
|
||||
*.test
|
||||
|
||||
# Loadtesting
|
||||
|
@ -1,4 +1,5 @@
|
||||
import type { Meta, StoryObj } from "@storybook/react";
|
||||
import { userEvent, within } from "@storybook/test";
|
||||
import { mockApiError } from "testHelpers/entities";
|
||||
import { CreateGroupPageView } from "./CreateGroupPageView";
|
||||
|
||||
@ -21,3 +22,13 @@ export const WithError: Story = {
|
||||
initialTouched: { name: true },
|
||||
},
|
||||
};
|
||||
|
||||
export const InvalidName: Story = {
|
||||
play: async ({ canvasElement }) => {
|
||||
const user = userEvent.setup();
|
||||
const body = within(canvasElement.ownerDocument.body);
|
||||
const input = await body.findByLabelText("Name");
|
||||
await user.type(input, "$om3 !nv@lid Name");
|
||||
input.blur();
|
||||
},
|
||||
};
|
||||
|
@ -12,11 +12,15 @@ import { Stack } from "components/Stack/Stack";
|
||||
import { type FormikTouched, useFormik } from "formik";
|
||||
import type { FC } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { getFormHelpers, onChangeTrimmed } from "utils/formUtils";
|
||||
import {
|
||||
getFormHelpers,
|
||||
nameValidator,
|
||||
onChangeTrimmed,
|
||||
} from "utils/formUtils";
|
||||
import * as Yup from "yup";
|
||||
|
||||
const validationSchema = Yup.object({
|
||||
name: Yup.string().required().label("Name"),
|
||||
name: nameValidator("Name"),
|
||||
});
|
||||
|
||||
export type CreateGroupPageViewProps = {
|
||||
@ -62,6 +66,8 @@ export const CreateGroupPageView: FC<CreateGroupPageViewProps> = ({
|
||||
autoFocus
|
||||
fullWidth
|
||||
label="Name"
|
||||
onChange={onChangeTrimmed(form)}
|
||||
autoComplete="name"
|
||||
/>
|
||||
<TextField
|
||||
{...getFieldHelpers("display_name", {
|
||||
@ -69,6 +75,7 @@ export const CreateGroupPageView: FC<CreateGroupPageViewProps> = ({
|
||||
})}
|
||||
fullWidth
|
||||
label="Display Name"
|
||||
autoComplete="display_name"
|
||||
/>
|
||||
<IconField
|
||||
{...getFieldHelpers("avatar_url")}
|
||||
|
@ -30,3 +30,13 @@ export const WithError: Story = {
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export const InvalidName: Story = {
|
||||
play: async ({ canvasElement }) => {
|
||||
const user = userEvent.setup();
|
||||
const body = within(canvasElement.ownerDocument.body);
|
||||
const input = await body.findByLabelText("Name");
|
||||
await user.type(input, "$om3 !nv@lid Name");
|
||||
input.blur();
|
||||
},
|
||||
};
|
||||
|
@ -15,11 +15,15 @@ import { Spinner } from "components/Spinner/Spinner";
|
||||
import { useFormik } from "formik";
|
||||
import type { FC } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { getFormHelpers, onChangeTrimmed } from "utils/formUtils";
|
||||
import {
|
||||
getFormHelpers,
|
||||
nameValidator,
|
||||
onChangeTrimmed,
|
||||
} from "utils/formUtils";
|
||||
import * as Yup from "yup";
|
||||
|
||||
const validationSchema = Yup.object({
|
||||
name: Yup.string().required().label("Name"),
|
||||
name: nameValidator("Name"),
|
||||
});
|
||||
|
||||
export type CreateGroupPageViewProps = {
|
||||
@ -69,6 +73,8 @@ export const CreateGroupPageView: FC<CreateGroupPageViewProps> = ({
|
||||
autoFocus
|
||||
fullWidth
|
||||
label="Name"
|
||||
onChange={onChangeTrimmed(form)}
|
||||
autoComplete="name"
|
||||
/>
|
||||
<TextField
|
||||
{...getFieldHelpers("display_name", {
|
||||
@ -76,6 +82,7 @@ export const CreateGroupPageView: FC<CreateGroupPageViewProps> = ({
|
||||
})}
|
||||
fullWidth
|
||||
label="Display Name"
|
||||
autoComplete="display_name"
|
||||
/>
|
||||
<IconField
|
||||
{...getFieldHelpers("avatar_url")}
|
||||
|
Reference in New Issue
Block a user