Fix: duplicate team name no prompt (#1267)
* Fix: duplicate team name no prompt * Fix syntax error for error message
This commit is contained in:
		
							parent
							
								
									91f2c380c5
								
							
						
					
					
						commit
						c43e6783a7
					
				
					 2 changed files with 22 additions and 5 deletions
				
			
		| 
						 | 
					@ -23,7 +23,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (nameCollisions > 0) {
 | 
					    if (nameCollisions > 0) {
 | 
				
			||||||
      return res.status(409).json({ errorCode: "TeamNameCollision", message: "Team name already take." });
 | 
					      return res
 | 
				
			||||||
 | 
					        .status(409)
 | 
				
			||||||
 | 
					        .json({ errorCode: "TeamNameCollision", message: "Team username already taken." });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const createTeam = await prisma.team.create({
 | 
					    const createTeam = await prisma.team.create({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,7 @@ import Shell from "@components/Shell";
 | 
				
			||||||
import EditTeam from "@components/team/EditTeam";
 | 
					import EditTeam from "@components/team/EditTeam";
 | 
				
			||||||
import TeamList from "@components/team/TeamList";
 | 
					import TeamList from "@components/team/TeamList";
 | 
				
			||||||
import TeamListItem from "@components/team/TeamListItem";
 | 
					import TeamListItem from "@components/team/TeamListItem";
 | 
				
			||||||
 | 
					import { Alert } from "@components/ui/Alert";
 | 
				
			||||||
import Button from "@components/ui/Button";
 | 
					import Button from "@components/ui/Button";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function Teams() {
 | 
					export default function Teams() {
 | 
				
			||||||
| 
						 | 
					@ -24,6 +25,8 @@ export default function Teams() {
 | 
				
			||||||
  const [showCreateTeamModal, setShowCreateTeamModal] = useState(false);
 | 
					  const [showCreateTeamModal, setShowCreateTeamModal] = useState(false);
 | 
				
			||||||
  const [editTeamEnabled, setEditTeamEnabled] = useState(false);
 | 
					  const [editTeamEnabled, setEditTeamEnabled] = useState(false);
 | 
				
			||||||
  const [teamToEdit, setTeamToEdit] = useState<Team | null>();
 | 
					  const [teamToEdit, setTeamToEdit] = useState<Team | null>();
 | 
				
			||||||
 | 
					  const [hasErrors, setHasErrors] = useState(false);
 | 
				
			||||||
 | 
					  const [errorMessage, setErrorMessage] = useState("");
 | 
				
			||||||
  const nameRef = useRef<HTMLInputElement>() as React.MutableRefObject<HTMLInputElement>;
 | 
					  const nameRef = useRef<HTMLInputElement>() as React.MutableRefObject<HTMLInputElement>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const handleErrors = async (resp: Response) => {
 | 
					  const handleErrors = async (resp: Response) => {
 | 
				
			||||||
| 
						 | 
					@ -48,6 +51,11 @@ export default function Teams() {
 | 
				
			||||||
    loadData();
 | 
					    loadData();
 | 
				
			||||||
  }, []);
 | 
					  }, []);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  useEffect(() => {
 | 
				
			||||||
 | 
					    setHasErrors(false);
 | 
				
			||||||
 | 
					    setErrorMessage("");
 | 
				
			||||||
 | 
					  }, [showCreateTeamModal]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (loading) {
 | 
					  if (loading) {
 | 
				
			||||||
    return <Loader />;
 | 
					    return <Loader />;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -60,10 +68,16 @@ export default function Teams() {
 | 
				
			||||||
      headers: {
 | 
					      headers: {
 | 
				
			||||||
        "Content-Type": "application/json",
 | 
					        "Content-Type": "application/json",
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    }).then(() => {
 | 
					    })
 | 
				
			||||||
      loadData();
 | 
					      .then(handleErrors)
 | 
				
			||||||
      setShowCreateTeamModal(false);
 | 
					      .then(() => {
 | 
				
			||||||
    });
 | 
					        loadData();
 | 
				
			||||||
 | 
					        setShowCreateTeamModal(false);
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					      .catch((err) => {
 | 
				
			||||||
 | 
					        setHasErrors(true);
 | 
				
			||||||
 | 
					        setErrorMessage(err.message);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const editTeam = (team: Team) => {
 | 
					  const editTeam = (team: Team) => {
 | 
				
			||||||
| 
						 | 
					@ -162,6 +176,7 @@ export default function Teams() {
 | 
				
			||||||
                    <label htmlFor="name" className="block text-sm font-medium text-gray-700">
 | 
					                    <label htmlFor="name" className="block text-sm font-medium text-gray-700">
 | 
				
			||||||
                      {t("name")}
 | 
					                      {t("name")}
 | 
				
			||||||
                    </label>
 | 
					                    </label>
 | 
				
			||||||
 | 
					                    {hasErrors && <Alert className="mt-1 mb-2" severity="error" message={errorMessage} />}
 | 
				
			||||||
                    <input
 | 
					                    <input
 | 
				
			||||||
                      ref={nameRef}
 | 
					                      ref={nameRef}
 | 
				
			||||||
                      type="text"
 | 
					                      type="text"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue