From 29f283efdc43b98f6520db3321a1c463ae6a5414 Mon Sep 17 00:00:00 2001 From: Karthik Ayangar Date: Sun, 19 May 2024 17:25:26 +0530 Subject: [PATCH] chore: make image field optional --- frontend/src/features/AddWorkspace/index.tsx | 31 ++++++++------------ frontend/src/features/AddWorkspace/types.ts | 2 +- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/frontend/src/features/AddWorkspace/index.tsx b/frontend/src/features/AddWorkspace/index.tsx index f333413..f5672bb 100644 --- a/frontend/src/features/AddWorkspace/index.tsx +++ b/frontend/src/features/AddWorkspace/index.tsx @@ -77,7 +77,7 @@ const AddWorkspace = () => { } }; - const validate: _VALIDATE_PROPS = (name, value, files) => { + const validate: _VALIDATE_PROPS = (name, value) => { switch (name) { case 'workspace': if (!value) { @@ -88,11 +88,6 @@ const AddWorkspace = () => { return 'Workspace name already exist'; } return ''; - case 'image': - if (!FileList) { - return 'File is required'; - } - return ''; case 'description': if (value.length > 200) { return 'Description should be less then 200 characters'; @@ -122,8 +117,8 @@ const AddWorkspace = () => { } }; const handleBlur = (e: React.FocusEvent) => { - const { name, value, files } = e.target; - const error = validate(name, value, files); + const { name, value } = e.target; + const error = validate(name, value); setFormErrors({ ...formErrors, [name]: error, @@ -132,17 +127,18 @@ const AddWorkspace = () => { const handleSubmit: _FORM_SUBMIT = (event) => { event.preventDefault(); - const workspace_error = validate('workspace', form.workspace, null); - const desc_error = validate('description', form.description, null); - const image_error = form.image ? '' : 'Image is required'; + const workspace_error = validate('workspace', form.workspace); + const desc_error = validate('description', form.description); setFormErrors({ ...formErrors, workspace: workspace_error, description: desc_error, - image: image_error, }); - if (workspace_error || desc_error || image_error) - toast.error('Check workspace, icon and description fields'); + if (workspace_error || desc_error) { + if (workspace_error) + toast.error('Check workspace field'); + if (desc_error) toast.error("Check description field") + } else { if (token) { const newForm = form; @@ -222,7 +218,7 @@ const AddWorkspace = () => { >

- Add Icon* + Add Icon

- {formErrors.image &&

{formErrors.image}

}