diff --git a/app/components/Input.tsx b/app/components/Input.tsx index 49a72d7dd4..d60acc5c86 100644 --- a/app/components/Input.tsx +++ b/app/components/Input.tsx @@ -2,7 +2,7 @@ import React from "react"; import { twMerge } from "tailwind-merge"; import { IconDefinition } from "@fortawesome/pro-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { Label } from "./Typography"; +import { Label, H6 } from "./Typography"; import { kebabCase } from "~/utilities"; import { disableHotkeyInput, @@ -11,13 +11,16 @@ import { } from "~/pages/PageEnigma/store"; interface InputProps extends React.InputHTMLAttributes { + inputClassName ?: string, label?: string; icon?: IconDefinition; + isError?: boolean; + errorMessage?: string; } -export const Input = React.forwardRef( - ( - { label, icon, className, id, ...rest }: InputProps, +export const Input = React.forwardRef(({ + label, icon, inputClassName, className, id, isError, errorMessage, ...rest + } : InputProps, ref: React.ForwardedRef, ) => { return ( @@ -33,12 +36,21 @@ export const Input = React.forwardRef( id={id ? id : label ? kebabCase(label) : undefined} className={twMerge( "h-10 w-full rounded-md bg-brand-secondary px-3 py-2.5 text-white outline-none outline-offset-0 transition-all duration-150 ease-in-out focus:outline-brand-primary", - icon ? "pl-12" : "", + icon && "pl-12", + isError && "outline-red focus:outline-red", + inputClassName )} - onFocus={() => disableHotkeyInput(DomLevels.INPUT)} - onBlur={() => enableHotkeyInput(DomLevels.INPUT)} + onFocus={(e: React.FocusEvent) => { + if (rest.onFocus) rest.onFocus(e); + disableHotkeyInput(DomLevels.INPUT) + }} + onBlur={(e: React.FocusEvent) => { + if (rest.onBlur) rest.onBlur(e); + enableHotkeyInput(DomLevels.INPUT) + }} {...rest} /> + {errorMessage &&
{errorMessage}
} ); diff --git a/app/modules/TopBar/TopBar.tsx b/app/modules/TopBar/TopBar.tsx index 800a7dcbb6..90a63979cf 100644 --- a/app/modules/TopBar/TopBar.tsx +++ b/app/modules/TopBar/TopBar.tsx @@ -1,13 +1,20 @@ +import { useState } from 'react'; import { useLocation } from "@remix-run/react"; +import { useSignals } from "@preact/signals-react/runtime"; import { faChevronLeft } from "@fortawesome/pro-solid-svg-icons"; import { ButtonLink } from "~/components"; - import { AuthButtons } from "./AuthButtons"; import { sceneTitle } from "~/store"; -import { useSignals } from "@preact/signals-react/runtime"; +import { + showErrorDialog, + errorDialogMessage, + errorDialogTitle, +} from "~/pages/PageEnigma/store"; + import { MyMoviesButton } from "~/modules/TopBar/MyMoviesButton"; +import { Input } from "~/components"; interface Props { pageName: string; @@ -16,7 +23,25 @@ interface Props { export const TopBar = ({ pageName }: Props) => { useSignals(); const currentLocation = useLocation().pathname; - + const [isValid, setIsValid] = useState(true); + const handleShowErrorDialog = ()=>{ + errorDialogTitle.value = "Error"; + errorDialogMessage.value = "Scene name can not be empty."; + showErrorDialog.value = true; + }; + const handleChangeSceneTitle = (e: React.ChangeEvent)=>{ + sceneTitle.value = e.target.value; + if (sceneTitle.value !== "") { + setIsValid(true); + } + } + const validateSceneTitle = (e: React.FocusEvent)=>{ + if (sceneTitle.value === "") { + setIsValid(false); + handleShowErrorDialog(); + e.target.focus(); + } + } return (