Skip to content

Commit c368c4c

Browse files
committed
chore: make image field optional
1 parent d2d8a91 commit c368c4c

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

frontend/src/features/AddWorkspace/index.tsx

+11-16
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const AddWorkspace = () => {
7777
}
7878
};
7979

80-
const validate: _VALIDATE_PROPS = (name, value, files) => {
80+
const validate: _VALIDATE_PROPS = (name, value) => {
8181
switch (name) {
8282
case 'workspace':
8383
if (!value) {
@@ -88,11 +88,6 @@ const AddWorkspace = () => {
8888
return 'Workspace name already exist';
8989
}
9090
return '';
91-
case 'image':
92-
if (!FileList) {
93-
return 'File is required';
94-
}
95-
return '';
9691
case 'description':
9792
if (value.length > 200) {
9893
return 'Description should be less then 200 characters';
@@ -122,8 +117,8 @@ const AddWorkspace = () => {
122117
}
123118
};
124119
const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {
125-
const { name, value, files } = e.target;
126-
const error = validate(name, value, files);
120+
const { name, value } = e.target;
121+
const error = validate(name, value);
127122
setFormErrors({
128123
...formErrors,
129124
[name]: error,
@@ -132,17 +127,18 @@ const AddWorkspace = () => {
132127

133128
const handleSubmit: _FORM_SUBMIT = (event) => {
134129
event.preventDefault();
135-
const workspace_error = validate('workspace', form.workspace, null);
136-
const desc_error = validate('description', form.description, null);
137-
const image_error = form.image ? '' : 'Image is required';
130+
const workspace_error = validate('workspace', form.workspace);
131+
const desc_error = validate('description', form.description);
138132
setFormErrors({
139133
...formErrors,
140134
workspace: workspace_error,
141135
description: desc_error,
142-
image: image_error,
143136
});
144-
if (workspace_error || desc_error || image_error)
145-
toast.error('Check workspace, icon and description fields');
137+
if (workspace_error || desc_error) {
138+
if (workspace_error)
139+
toast.error('Check workspace field');
140+
if (desc_error) toast.error("Check description field")
141+
}
146142
else {
147143
if (token) {
148144
const newForm = form;
@@ -222,7 +218,7 @@ const AddWorkspace = () => {
222218
>
223219
<div className='single-form-element-container'>
224220
<p className='label'>
225-
Add Icon<span style={{ color: 'red', paddingLeft: '4px' }}>*</span>
221+
Add Icon
226222
</p>
227223
<div className='file-input-container'>
228224
<label htmlFor='icon-file' className='file-label'>
@@ -242,7 +238,6 @@ const AddWorkspace = () => {
242238
<p>Supported formats: JPEG, JPG, PNG</p>
243239
<p>Selected File: {form.image?.name}</p>
244240
</div>
245-
{formErrors.image && <p className='form-error'>{formErrors.image}</p>}
246241
</div>
247242
<div className='single-form-element-container'>
248243
<label className='label' htmlFor='workspace-name'>

frontend/src/features/AddWorkspace/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ export type _WORKSPACE_FORM_CHANGE = (
2020

2121
export type _FORM_SUBMIT = (event: FormEvent<HTMLFormElement>) => void;
2222

23-
export type _VALIDATE_PROPS = (name: string, value: string, files:FileList|null) => string;
23+
export type _VALIDATE_PROPS = (name: string, value: string) => string;

0 commit comments

Comments
 (0)