Skip to content

Commit 028fc29

Browse files
committed
fix: review comments
1 parent 6f53659 commit 028fc29

File tree

8 files changed

+49
-31
lines changed

8 files changed

+49
-31
lines changed

src/Common/Api.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ async function handleServerError(contentType, response) {
114114
throw serverError
115115
}
116116

117-
async function fetchAPI(
117+
async function fetchAPI<K = object>(
118118
url: string,
119119
type: string,
120-
data: object,
120+
data: K,
121121
signal: AbortSignal,
122122
preventAutoLogout = false,
123123
isMultipartRequest?: boolean,
@@ -185,10 +185,10 @@ async function fetchAPI(
185185
)
186186
}
187187

188-
function fetchInTime(
188+
function fetchInTime<T = object>(
189189
url: string,
190190
type: string,
191-
data: object,
191+
data: T,
192192
options?: APIOptions,
193193
isMultipartRequest?: boolean,
194194
): Promise<ResponseType> {
@@ -227,23 +227,24 @@ function fetchInTime(
227227
})
228228
}
229229

230-
export const post = <T = any>(
230+
export const post = <T = any, K = object>(
231231
url: string,
232-
data: object,
232+
data: K,
233233
options?: APIOptions,
234234
isMultipartRequest?: boolean,
235-
): Promise<ResponseType<T>> => fetchInTime(url, 'POST', data, options, isMultipartRequest)
235+
): Promise<ResponseType<T>> => fetchInTime<K>(url, 'POST', data, options, isMultipartRequest)
236236

237-
export const put = <T = any>(url: string, data: object, options?: APIOptions): Promise<ResponseType<T>> =>
238-
fetchInTime(url, 'PUT', data, options)
237+
export const put = <T = any, K = object>(url: string, data: K, options?: APIOptions): Promise<ResponseType<T>> =>
238+
fetchInTime<K>(url, 'PUT', data, options)
239239

240-
export const patch = <T = any>(url: string, data: object, options?: APIOptions): Promise<ResponseType<T>> =>
241-
fetchInTime(url, 'PATCH', data, options)
240+
export const patch = <T = any, K = object>(url: string, data: K, options?: APIOptions): Promise<ResponseType<T>> =>
241+
fetchInTime<K>(url, 'PATCH', data, options)
242242

243-
export const get = <T = any>(url: string, options?: APIOptions): Promise<ResponseType<T>> => fetchInTime(url, 'GET', null, options)
243+
export const get = <T = any>(url: string, options?: APIOptions): Promise<ResponseType<T>> =>
244+
fetchInTime(url, 'GET', null, options)
244245

245-
export const trash = <T = any>(url: string, data?: object, options?: APIOptions): Promise<ResponseType<T>> =>
246-
fetchInTime(url, 'DELETE', data, options)
246+
export const trash = <T = any, K = object>(url: string, data?: K, options?: APIOptions): Promise<ResponseType<T>> =>
247+
fetchInTime<K>(url, 'DELETE', data, options)
247248

248249
/**
249250
* Aborts the previous request before triggering next request
@@ -263,4 +264,4 @@ export const abortPreviousRequests = <T>(
263264
*/
264265
export const getIsRequestAborted = (error) =>
265266
// The 0 code is common for aborted and blocked requests
266-
error && error.code === 0 && error.message.search('abort\|aborted')
267+
error && error.code === 0 && error.message.search('abort|aborted')

src/Common/Toggle/Toggle.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ input:focus + .toggle__slider {
9393
box-shadow: 0 0 1px var(--color);
9494
}
9595

96-
.square-toggle {
96+
.dc__toggle-square-toggle {
9797
.toggle__slider {
9898
border-color: var(--color);
9999
background-color: var(--color) !important;

src/Shared/Components/EditImageFormField/EditImageFormField.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
grid-template-columns: repeat(12, 1fr);
44
grid-template-rows: repeat(12, 1fr);
55

6-
.base-image {
6+
& &--base-image {
77
grid-column: 1 / span 12;
88
grid-row: 1 / span 12;
99
}
1010

11-
.edit-image-icon {
11+
& &--edit-image-icon {
1212
grid-column: 8 / span 4;
1313
grid-row: 8 / span 4;
1414
}

src/Shared/Components/EditImageFormField/EditImageFormField.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
import { SyntheticEvent, useState } from 'react'
1+
import { KeyboardEvent, SyntheticEvent, useState } from 'react'
22
import { toast } from 'react-toastify'
33
import { showError } from '@Common/Helper'
44
import { CustomInput } from '@Common/CustomInput'
55
import { ButtonWithLoader, ImageWithFallback } from '@Shared/Components'
66
import { validateIfImageExist, validateURL } from '@Shared/validations'
77
import { ReactComponent as ICPencil } from '@Icons/ic-pencil.svg'
88
import { EditImageFormFieldProps, FallbackImageProps } from './types'
9-
import { DEFAULT_IMAGE_DIMENSIONS, DEFAULT_MAX_IMAGE_SIZE, EMPTY_PREVIEW_URL_ERROR_MESSAGE } from './constants'
9+
import {
10+
BASE_IMAGE_CLASS,
11+
DEFAULT_IMAGE_DIMENSIONS,
12+
DEFAULT_MAX_IMAGE_SIZE,
13+
EMPTY_PREVIEW_URL_ERROR_MESSAGE,
14+
} from './constants'
1015
import './EditImageFormField.scss'
1116

1217
const FallbackImage = ({ showEditIcon, defaultIcon }: FallbackImageProps) => (
1318
<div
14-
className={`flex dc__align-self-start dc__no-shrink br-4 edit-image-form-field__fallback-image p-12 ${showEditIcon ? 'base-image' : ''}`}
19+
className={`flex dc__align-self-start dc__no-shrink br-4 edit-image-form-field__fallback-image p-12 ${showEditIcon ? BASE_IMAGE_CLASS : ''}`}
1520
// Adding inline style to make sure it is configurable through constants
1621
style={{
1722
height: DEFAULT_IMAGE_DIMENSIONS.height,
@@ -62,7 +67,7 @@ const EditImageFormField = ({
6267
setLastPreviewedURL(newURL)
6368
}
6469

65-
const handleReset = (newURL?: string) => {
70+
const handleResetToInitialState = (newURL?: string) => {
6671
const targetURL = newURL ?? lastPreviewedURL
6772
handleLastPreviewedURLChange(targetURL)
6873
handleURLChange(targetURL)
@@ -73,11 +78,11 @@ const EditImageFormField = ({
7378
}
7479

7580
const handleSuccess = () => {
76-
handleReset(url)
81+
handleResetToInitialState(url)
7782
}
7883

7984
const handleCancel = () => {
80-
handleReset()
85+
handleResetToInitialState()
8186
}
8287

8388
const handleChange = (event: SyntheticEvent) => {
@@ -88,6 +93,7 @@ const EditImageFormField = ({
8893
return
8994
}
9095
setEmptyPreviewURLErrorMessage('')
96+
// TODO: Can also restrict to http/s protocol
9197
handleError(validateURL(value, false).message)
9298
}
9399

@@ -133,8 +139,9 @@ const EditImageFormField = ({
133139
}
134140
}
135141

136-
const handleKeyDown = async (event: React.KeyboardEvent<HTMLInputElement>) => {
142+
const handleKeyDown = async (event: KeyboardEvent<HTMLInputElement>) => {
137143
if (event.key === 'Enter') {
144+
event.preventDefault()
138145
await handlePreviewImage()
139146
}
140147
}
@@ -161,9 +168,9 @@ const EditImageFormField = ({
161168
aria-label={`${ariaLabelPrefix} image`}
162169
onClick={handleEnableEditing}
163170
>
164-
{renderImage(true, 'base-image')}
171+
{renderImage(true, BASE_IMAGE_CLASS)}
165172

166-
<div className="flex p-4 br-4 bcn-0 dc__border edit-image-icon dc__zi-1 bcn-0 dc__hover-n50 icon-dim-24">
173+
<div className="flex p-4 br-4 bcn-0 dc__border edit-image-form-field__figure-container--edit-image-icon dc__zi-1 bcn-0 dc__hover-n50 icon-dim-24">
167174
<ICPencil className="dc__no-shrink icon-dim-16" />
168175
</div>
169176
</button>
@@ -177,7 +184,7 @@ const EditImageFormField = ({
177184
<div className="flexbox-col dc__gap-16 flex-grow-1">
178185
<div className="flexbox-col dc__gap-6 w-100 dc__align-start">
179186
<CustomInput
180-
name={`${ariaLabelPrefix} url input`}
187+
name={`${ariaLabelPrefix}-url-input`}
181188
label="Image URL"
182189
labelClassName="m-0 fs-13 fw-4 lh-20 cn-7"
183190
placeholder="Enter image url"

src/Shared/Components/EditImageFormField/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export const DEFAULT_IMAGE_DIMENSIONS = {
44
height: 72,
55
} as const
66
export const EMPTY_PREVIEW_URL_ERROR_MESSAGE = 'Please provide image URL to preview'
7+
export const BASE_IMAGE_CLASS = 'edit-image-form-field__figure-container--base-image'

src/Shared/Components/EditImageFormField/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { ReactNode } from 'react'
1+
import { ReactElement } from 'react'
22

33
export interface EditImageFormFieldProps {
44
/**
55
* Fallback icon to be shown when image is not available
66
*/
7-
defaultIcon: ReactNode
7+
defaultIcon: ReactElement
88
/**
99
* Would be shown below input, there are two types of error messages:
1010
* External - Error message handled from state above and would propagate to parent through handleError

src/Shared/Components/SelectPicker/type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ export interface SelectPickerProps
9494
* @default 'ComponentSizeType.small'
9595
*/
9696
menuSize?: ComponentSizeType
97+
// TODO: Can make generic typing when adding multi select
9798
/**
98-
* If true, would show generic section error state as no options message
99+
* If truthy, would show generic section error state as no options message
99100
*/
100101
optionListError?: ServerErrors
101102
/**

src/Shared/validations.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ export const validateUniqueKeys = (keys: string[]) => {
254254
}
255255
}
256256

257+
/**
258+
* Rules for valid semantic version:
259+
* 1. version.length < 128 and not empty
260+
* 2. version should follow semantic versioning regex from https://semver.org/
261+
*/
257262
export const validateSemanticVersioning = (version: string): ValidationResponseType => {
258263
if (!version) {
259264
return {
@@ -285,5 +290,8 @@ export const validateSemanticVersioning = (version: string): ValidationResponseT
285290
}
286291
}
287292

293+
/**
294+
* A valid display name should be between 3 and 50 characters
295+
*/
288296
export const validateDisplayName = (name: string): ValidationResponseType =>
289297
validateStringLength(name, DISPLAY_NAME_CONSTRAINTS.MAX_LIMIT, DISPLAY_NAME_CONSTRAINTS.MIN_LIMIT)

0 commit comments

Comments
 (0)