From 8d021389a08d691b212ece0861ab519f4557912a Mon Sep 17 00:00:00 2001 From: Lakhan Baheti <94619783+1akhanBaheti@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:18:48 +0530 Subject: [PATCH] fix: create workspace form validation (#2958) * fix: create workspace form validation * fix: textfield placeholder typo * fix: name field onchange --- .../account/sign-in-forms/unique-code.tsx | 2 +- web/components/onboarding/join-workspaces.tsx | 2 +- web/components/onboarding/workspace.tsx | 29 +++++++------------ 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/web/components/account/sign-in-forms/unique-code.tsx b/web/components/account/sign-in-forms/unique-code.tsx index 71ed93f0c..0091819f8 100644 --- a/web/components/account/sign-in-forms/unique-code.tsx +++ b/web/components/account/sign-in-forms/unique-code.tsx @@ -196,7 +196,7 @@ export const UniqueCodeForm: React.FC = (props) => { value={value} onChange={onChange} hasError={Boolean(errors.token)} - placeholder="gets-sets-fays" + placeholder="gets-sets-flys" className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12" /> )} diff --git a/web/components/onboarding/join-workspaces.tsx b/web/components/onboarding/join-workspaces.tsx index 214f3b709..66f88fb49 100644 --- a/web/components/onboarding/join-workspaces.tsx +++ b/web/components/onboarding/join-workspaces.tsx @@ -24,7 +24,7 @@ export const JoinWorkspaces: React.FC = ({ stepChange, setTryDiffAccount } = useForm({ defaultValues: { name: "", - slug: `${window.location.host}/`, + slug: "", }, mode: "onChange", }); diff --git a/web/components/onboarding/workspace.tsx b/web/components/onboarding/workspace.tsx index cb126adfd..e14356e5a 100644 --- a/web/components/onboarding/workspace.tsx +++ b/web/components/onboarding/workspace.tsx @@ -40,8 +40,6 @@ export const Workspace: React.FC = (props) => { const handleCreateWorkspace = async (formData: IWorkspace) => { if (isSubmitting) return; - const slug = formData.slug.split("/"); - formData.slug = slug[slug.length - 1]; await workspaceService .workspaceSlugCheck(formData.slug) @@ -118,11 +116,7 @@ export const Workspace: React.FC = (props) => { onChange={(event) => { onChange(event.target.value); setValue("name", event.target.value); - if (window && window.location.host) { - const host = window.location.host; - const slug = event.currentTarget.value.split("/"); - setValue("slug", `${host}/${slug[slug.length - 1].toLocaleLowerCase().trim().replace(/ /g, "-")}`); - } + setValue("slug", event.target.value.toLocaleLowerCase().trim().replace(/ /g, "-")); }} placeholder="Enter workspace name..." ref={ref} @@ -137,26 +131,25 @@ export const Workspace: React.FC = (props) => { ( -
+ render={({ field: { value, ref, onChange } }) => ( +
+ {window && window.location.host}/ { - const host = window.location.host; - const slug = e.currentTarget.value.split("/"); - if (slug.length > 1) { - /^[a-zA-Z0-9_-]+$/.test(slug[slug.length - 1]) ? setInvalidSlug(false) : setInvalidSlug(true); - setValue("slug", `${host}/${slug[slug.length - 1].toLocaleLowerCase().trim().replace(/ /g, "-")}`); - } else { - setValue("slug", `${host}/`); - } + /^[a-zA-Z0-9_-]+$/.test(e.target.value) ? setInvalidSlug(false) : setInvalidSlug(true); + onChange(e.target.value.toLowerCase()); }} ref={ref} hasError={Boolean(errors.slug)} - className="w-full h-[46px] border-onboarding-border-100" + className="w-full h-[46px] !px-0 border-none" />
)}