diff --git a/packages/cyberstorm/src/components/Button/Button.tsx b/packages/cyberstorm/src/components/Button/Button.tsx index d372564c3..f96ddaa52 100644 --- a/packages/cyberstorm/src/components/Button/Button.tsx +++ b/packages/cyberstorm/src/components/Button/Button.tsx @@ -50,6 +50,7 @@ export interface ButtonProps { style?: { [key: string]: string }; type?: "button" | "submit" | "reset"; tooltipText?: string; + disabled?: boolean; } const TooltipWrapper = (props: TooltipWrapperProps) => @@ -82,6 +83,7 @@ const Button = React.forwardRef< paddingSize = "medium", iconAlignment = "default", tooltipText, + disabled = false, ...forwardedProps } = props; @@ -90,6 +92,7 @@ const Button = React.forwardRef< if (plain) { const fRef = forwardedRef as React.ForwardedRef; const ref = fRef || fallbackRef; + // TODO: Add disabled mode return (
{children} diff --git a/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.tsx b/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.tsx index 912716280..bb90685f1 100644 --- a/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.tsx +++ b/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.tsx @@ -9,17 +9,22 @@ import styles from "./CreateTeamForm.module.css"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { isErrorResponse } from "../../../utils/type_guards"; +import { useEffect } from "react"; export function CreateTeamForm() { const toast = useToast(); + // "Required field" error is different from value being too little + // Check that the value is "> 0" const schema = z.object({ - teamName: z.string({ required_error: "Team name is required" }), + teamName: z + .string({ required_error: "Team name is required" }) + .min(1, { message: "Team name is required" }), }); const { control, - formState: { isSubmitting }, + formState: { isSubmitting, errors }, } = useForm>({ mode: "onSubmit", resolver: zodResolver(schema), @@ -30,6 +35,20 @@ export function CreateTeamForm() { name: "teamName", }); + // We have to do this because the RHF Form component is in beta and it + // doesn't have a callback prop like "onValidation" that could take in + // the generalized addToast error informing block. + useEffect(() => { + if (errors.teamName) { + console.log(errors); + toast.addToast({ + variant: "danger", + message: errors.teamName.message, + duration: 30000, + }); + } + }, [errors]); + return (
- + {isSubmitting ? (