Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Show feedback when special characters are entered in branch name #229

Merged
merged 8 commits into from
Feb 16, 2023
12 changes: 9 additions & 3 deletions taxonomy-editor-frontend/src/pages/startproject/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {
} from "@mui/material";

import { TAXONOMY_NAMES } from "../../constants";
import { createBaseURL } from "../../utils";
import { toSnakeCase } from "../../utils";
import { createBaseURL, toSnakeCase } from "../../utils";

const branchNameRegEx = /[^a-z0-9_]+/;

const StartProject = ({ clearNavBarLinks }) => {
const [branchName, setBranchName] = useState("");
Expand Down Expand Up @@ -64,6 +65,9 @@ const StartProject = ({ clearNavBarLinks }) => {
setErrorMessage("");
};


const isInvalidBranchName = branchNameRegEx.test(branchName);

return (
<Box>
<Grid
Expand Down Expand Up @@ -96,6 +100,8 @@ const StartProject = ({ clearNavBarLinks }) => {

<div>
<TextField
error={isInvalidBranchName}
helperText={isInvalidBranchName && "Special characters, capital letters and white spaces are not allowed"}
size="small"
sx={{ width: 265, mt: 2 }}
onChange={(event) => {
Expand Down Expand Up @@ -125,7 +131,7 @@ const StartProject = ({ clearNavBarLinks }) => {
variant="contained"
sx={{ mt: 3 }}
onClick={handleSubmit}
disabled={!branchName || !taxonomyName || loading}
disabled={!branchName || !taxonomyName || loading || isInvalidBranchName}
>
{loading ? (
<>
Expand Down