From 87737dbfbe998eb484c0856589f26133cadb3198 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:17:50 +0530 Subject: [PATCH] chore: input character limit error message improvement (#4271) --- packages/ui/src/form-fields/input.tsx | 4 +- web/components/cycles/form.tsx | 5 +- .../modals/create-edit-modal/create-root.tsx | 16 ++++- .../modals/create-edit-modal/edit-root.tsx | 17 +++++- .../modals/create-edit-modal/issue-title.tsx | 7 ++- web/components/issues/issue-modal/form.tsx | 2 + web/components/modules/form.tsx | 5 +- web/components/project/form.tsx | 8 ++- web/components/views/form.tsx | 7 ++- .../workspace/create-workspace-form.tsx | 61 ++++++++++--------- 10 files changed, 84 insertions(+), 48 deletions(-) diff --git a/packages/ui/src/form-fields/input.tsx b/packages/ui/src/form-fields/input.tsx index f73467621..04182ef13 100644 --- a/packages/ui/src/form-fields/input.tsx +++ b/packages/ui/src/form-fields/input.tsx @@ -27,9 +27,7 @@ const Input = React.forwardRef((props, ref) => { : mode === "true-transparent" ? "rounded border-none bg-transparent ring-0" : "" - } ${hasError ? "border-red-500" : ""} ${hasError && mode === "primary" ? "bg-red-500/20" : ""} ${ - inputSize === "sm" ? "px-3 py-2" : inputSize === "md" ? "p-3" : "" - }`, + } ${hasError ? "border-red-500" : ""} ${inputSize === "sm" ? "px-3 py-2" : inputSize === "md" ? "p-3" : ""}`, className )} {...rest} diff --git a/web/components/cycles/form.tsx b/web/components/cycles/form.tsx index f8092f8d0..b8b34fe3b 100644 --- a/web/components/cycles/form.tsx +++ b/web/components/cycles/form.tsx @@ -77,7 +77,7 @@ export const CycleForm: React.FC = (props) => {
-
+
= (props) => { required: "Name is required", maxLength: { value: 255, - message: "Name should be less than 255 characters", + message: "Title should be less than 255 characters", }, }} render={({ field: { value, onChange } }) => ( @@ -103,6 +103,7 @@ export const CycleForm: React.FC = (props) => { /> )} /> + {errors?.name?.message}
= observer((props) setFormSubmitting(false); }; + const isTitleLengthMoreThan255Character = formData?.name ? formData.name.length > 255 : false; + if (!workspaceSlug || !projectId || !workspaceId) return <>; return (
- + = observer((props) -
diff --git a/web/components/inbox/modals/create-edit-modal/edit-root.tsx b/web/components/inbox/modals/create-edit-modal/edit-root.tsx index 774724506..6ffb6efee 100644 --- a/web/components/inbox/modals/create-edit-modal/edit-root.tsx +++ b/web/components/inbox/modals/create-edit-modal/edit-root.tsx @@ -121,10 +121,16 @@ export const InboxIssueEditRoot: FC = observer((props) => { setFormSubmitting(false); }; + const isTitleLengthMoreThan255Character = formData?.name ? formData.name.length > 255 : false; + if (!workspaceSlug || !projectId || !workspaceId || !formData) return <>; return (
- + = observer((props) => { -
diff --git a/web/components/inbox/modals/create-edit-modal/issue-title.tsx b/web/components/inbox/modals/create-edit-modal/issue-title.tsx index 27361b1f4..31a44bf76 100644 --- a/web/components/inbox/modals/create-edit-modal/issue-title.tsx +++ b/web/components/inbox/modals/create-edit-modal/issue-title.tsx @@ -6,10 +6,11 @@ import { Input } from "@plane/ui"; type TInboxIssueTitle = { data: Partial; handleData: (issueKey: keyof Partial, issueValue: Partial[keyof Partial]) => void; + isTitleLengthMoreThan255Character?: boolean; }; export const InboxIssueTitle: FC = observer((props) => { - const { data, handleData } = props; + const { data, handleData, isTitleLengthMoreThan255Character } = props; return (
@@ -21,9 +22,11 @@ export const InboxIssueTitle: FC = observer((props) => { onChange={(e) => handleData("name", e.target.value)} placeholder="Title" className="w-full resize-none text-xl" - maxLength={255} required /> + {isTitleLengthMoreThan255Character && ( + Title should be less than 255 characters + )}
); }); diff --git a/web/components/issues/issue-modal/form.tsx b/web/components/issues/issue-modal/form.tsx index 50f60bac5..2e426c9e8 100644 --- a/web/components/issues/issue-modal/form.tsx +++ b/web/components/issues/issue-modal/form.tsx @@ -391,6 +391,8 @@ export const IssueFormRoot: FC = observer((props) => { /> )} /> + {errors?.name?.message} +
{data?.description_html === undefined ? ( diff --git a/web/components/modules/form.tsx b/web/components/modules/form.tsx index 30749218d..d49a070b1 100644 --- a/web/components/modules/form.tsx +++ b/web/components/modules/form.tsx @@ -90,7 +90,7 @@ export const ModuleForm: React.FC = (props) => {
-
+
= (props) => { value={value} onChange={onChange} ref={ref} - hasError={Boolean(errors.name)} + hasError={Boolean(errors?.name)} placeholder="Module Title" className="w-full resize-none placeholder:text-sm placeholder:font-medium focus:border-blue-400" tabIndex={1} /> )} /> + {errors?.name?.message}
= (props) => { name="name" rules={{ required: "Name is required", + maxLength: { + value: 255, + message: "Project name should be less than 255 characters", + }, }} render={({ field: { value, onChange, ref } }) => ( = (props) => { /> )} /> - - <>{errors?.name?.message} - + {errors?.name?.message}

Description

diff --git a/web/components/views/form.tsx b/web/components/views/form.tsx index a8fa6b87c..cc1994eca 100644 --- a/web/components/views/form.tsx +++ b/web/components/views/form.tsx @@ -112,7 +112,7 @@ export const ProjectViewForm: React.FC = observer((props) => {

{data ? "Update" : "Create"} View

-
+
= observer((props) => { /> )} /> + {errors?.name?.message}
= observer((props) => { ? "Updating View..." : "Update View" : isSubmitting - ? "Creating View..." - : "Create View"} + ? "Creating View..." + : "Create View"}
diff --git a/web/components/workspace/create-workspace-form.tsx b/web/components/workspace/create-workspace-form.tsx index d8a443d4d..789e2ee85 100644 --- a/web/components/workspace/create-workspace-form.tsx +++ b/web/components/workspace/create-workspace-form.tsx @@ -125,35 +125,38 @@ export const CreateWorkspaceForm: FC = observer((props) => { Workspace Name * - - /^[\w\s-]*$/.test(value) || `Name can only contain (" "), ( - ), ( _ ) & alphanumeric characters.`, - maxLength: { - value: 80, - message: "Workspace name should not exceed 80 characters", - }, - }} - render={({ field: { value, ref, onChange } }) => ( - { - onChange(e.target.value); - setValue("name", e.target.value); - setValue("slug", e.target.value.toLocaleLowerCase().trim().replace(/ /g, "-")); - }} - ref={ref} - hasError={Boolean(errors.name)} - placeholder="Enter workspace name..." - className="w-full" - /> - )} - /> +
+ + /^[\w\s-]*$/.test(value) || `Name can only contain (" "), ( - ), ( _ ) & alphanumeric characters.`, + maxLength: { + value: 80, + message: "Workspace name should not exceed 80 characters", + }, + }} + render={({ field: { value, ref, onChange } }) => ( + { + onChange(e.target.value); + setValue("name", e.target.value); + setValue("slug", e.target.value.toLocaleLowerCase().trim().replace(/ /g, "-")); + }} + ref={ref} + hasError={Boolean(errors.name)} + placeholder="Enter workspace name..." + className="w-full" + /> + )} + /> + {errors?.name?.message} +