Skip to content

Commit e0a6615

Browse files
committed
refactor: replace react toastify with ToastManager.showToast
1 parent fa6e06c commit e0a6615

File tree

14 files changed

+94
-116
lines changed

14 files changed

+94
-116
lines changed

.eslintrc.cjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,24 @@ module.exports = {
108108
'import/no-cycle': 'off',
109109
'import/prefer-default-export': 'off',
110110
'no-restricted-exports': 'off',
111-
'import/named': 'off'
111+
'import/named': 'off',
112112
},
113113
overrides: [
114114
{
115115
files: ['*.ts', '*.tsx'],
116116
rules: {
117117
'no-undef': 'off',
118+
'no-restricted-imports': [
119+
'error',
120+
{
121+
paths: [
122+
{
123+
name: 'react-toastify',
124+
message: 'Please use "ToastManager.showToast" instead.',
125+
}
126+
],
127+
},
128+
],
118129
},
119130
},
120131
],

src/Common/DeleteComponentModal/DeleteComponent.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import React, { useState } from 'react'
1818
import { useHistory } from 'react-router-dom'
19-
import { toast } from 'react-toastify'
2019
import info from '../../Assets/Icon/ic-info-filled.svg'
2120
import { ConfirmationDialog, DeleteDialog } from '../Dialogs'
2221
import { ServerErrors } from '../ServerError'
2322
import { DeleteComponentProps } from './types'
23+
import { ToastManager, ToastVariantType } from '@Shared/Services'
2424

2525
const DeleteComponent = ({
2626
setDeleting,
@@ -43,7 +43,10 @@ const DeleteComponent = ({
4343
setDeleting(true)
4444
try {
4545
await deleteComponent(payload)
46-
toast.success('Successfully deleted')
46+
ToastManager.showToast({
47+
variant: ToastVariantType.success,
48+
description: 'Successfully deleted',
49+
})
4750
toggleConfirmation(false)
4851
if (redirectTo) {
4952
push(url)

src/Common/GenericDescription/GenericDescription.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { useState, useRef, useEffect } from 'react'
1818
import Tippy from '@tippyjs/react'
1919
import ReactMde from 'react-mde'
2020
import 'react-mde/lib/styles/css/react-mde-all.css'
21-
import { toast } from 'react-toastify'
2221
import moment from 'moment'
2322
import Markdown from '../Markdown/MarkDown'
2423
import { DATE_TIME_FORMATS, deepEqual, showError } from '..'
@@ -31,7 +30,7 @@ import {
3130
MARKDOWN_EDITOR_COMMAND_TITLE,
3231
MARKDOWN_EDITOR_COMMAND_ICON_TIPPY_CONTENT,
3332
} from '../Markdown/constant'
34-
import { ButtonWithLoader } from '../../Shared'
33+
import { ButtonWithLoader, ToastManager, ToastVariantType } from '../../Shared'
3534
import { ReactComponent as HeaderIcon } from '../../Assets/Icon/ic-header.svg'
3635
import { ReactComponent as BoldIcon } from '../../Assets/Icon/ic-bold.svg'
3736
import { ReactComponent as ItalicIcon } from '../../Assets/Icon/ic-italic.svg'
@@ -73,7 +72,10 @@ const GenericDescription = ({
7372
const validateDescriptionText = (description: string): boolean => {
7473
let isValid = true
7574
if (description.length === 0) {
76-
toast.error(DESCRIPTION_EMPTY_ERROR_MSG)
75+
ToastManager.showToast({
76+
variant: ToastVariantType.error,
77+
description: DESCRIPTION_EMPTY_ERROR_MSG,
78+
})
7779
isValid = false
7880
}
7981
return isValid

src/Common/Helper.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ import { components } from 'react-select'
2121
import * as Sentry from '@sentry/browser'
2222
import moment from 'moment'
2323
import { useLocation } from 'react-router-dom'
24-
import { toast } from 'react-toastify'
2524
import YAML from 'yaml'
26-
import { ERROR_EMPTY_SCREEN, SortingOrder, EXCLUDED_FALSY_VALUES, DISCORD_LINK, ZERO_TIME_STRING } from './Constants'
25+
import { ERROR_EMPTY_SCREEN, SortingOrder, EXCLUDED_FALSY_VALUES, DISCORD_LINK, ZERO_TIME_STRING, TOAST_ACCESS_DENIED } from './Constants'
2726
import { ServerErrors } from './ServerError'
28-
import { toastAccessDenied } from './ToastBody'
2927
import { AsyncOptions, AsyncState, UseSearchString } from './Types'
30-
import { scrollableInterface, DATE_TIME_FORMAT_STRING } from '../Shared'
28+
import { scrollableInterface, DATE_TIME_FORMAT_STRING, ToastManager, ToastVariantType } from '../Shared'
3129
import { ReactComponent as ArrowDown } from '../Assets/Icon/ic-chevron-down.svg'
3230

3331
export function showError(serverError, showToastOnUnknownError = true, hideAccessError = false) {
@@ -38,10 +36,16 @@ export function showError(serverError, showToastOnUnknownError = true, hideAcces
3836
(userMessage === ERROR_EMPTY_SCREEN.UNAUTHORIZED || userMessage === ERROR_EMPTY_SCREEN.FORBIDDEN)
3937
) {
4038
if (!hideAccessError) {
41-
toastAccessDenied()
39+
ToastManager.showToast({
40+
variant: ToastVariantType.notAuthorized,
41+
description: TOAST_ACCESS_DENIED.SUBTITLE,
42+
})
4243
}
4344
} else {
44-
toast.error(userMessage || internalMessage)
45+
ToastManager.showToast({
46+
variant: ToastVariantType.error,
47+
description: userMessage || internalMessage,
48+
})
4549
}
4650
})
4751
} else {
@@ -51,9 +55,15 @@ export function showError(serverError, showToastOnUnknownError = true, hideAcces
5155

5256
if (showToastOnUnknownError) {
5357
if (serverError.message) {
54-
toast.error(serverError.message)
58+
ToastManager.showToast({
59+
variant: ToastVariantType.error,
60+
description: serverError.message,
61+
})
5562
} else {
56-
toast.error('Some Error Occurred')
63+
ToastManager.showToast({
64+
variant: ToastVariantType.error,
65+
description: 'Some Error Occurred',
66+
})
5767
}
5868
}
5969
}
@@ -454,7 +464,10 @@ export function copyToClipboard(str, callback = noop) {
454464
callback()
455465
})
456466
.catch(() => {
457-
toast.error('Failed to copy to clipboard')
467+
ToastManager.showToast({
468+
variant: ToastVariantType.error,
469+
description: 'Failed to copy to clipboard',
470+
})
458471
})
459472
} else {
460473
unsecureCopyToClipboard(str, callback)

src/Common/ImageTags.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import { useEffect, useRef, useState } from 'react'
18-
import { toast } from 'react-toastify'
1918
import Tippy from '@tippyjs/react'
2019
import { ReactComponent as Add } from '../Assets/Icon/ic-add.svg'
2120
import { ReactComponent as Close } from '../Assets/Icon/ic-cross.svg'
@@ -30,7 +29,7 @@ import { ImageButtonType, ImageTaggingContainerType, ReleaseTag } from './ImageT
3029
import { showError, stopPropagation } from './Helper'
3130
import { setImageTags } from './Common.service'
3231
import { Progressing } from './Progressing'
33-
import { InfoIconTippy } from '../Shared'
32+
import { InfoIconTippy, ToastManager, ToastVariantType } from '../Shared'
3433

3534
export const ImageTagsContainer = ({
3635
// Setting it to zero in case of external pipeline
@@ -257,7 +256,10 @@ export const ImageTagsContainer = ({
257256
.catch((err) => {
258257
// Fix toast message
259258
if (err.errors?.[0]?.userMessage?.appReleaseTags?.length) {
260-
toast.error(err.errors?.[0]?.internalMessage)
259+
ToastManager.showToast({
260+
variant: ToastVariantType.error,
261+
description: err.errors?.[0]?.internalMessage,
262+
})
261263
errorStateHandling(err.errors)
262264
} else {
263265
showError(err)

src/Common/ToastBody.tsx

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/Common/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export * from './Constants'
1818
export * from './ServerError'
1919
export * from './Types'
2020
export * from './Api'
21-
export * from './ToastBody'
2221
export { default as Reload } from './Reload'
2322
export { default as ErrorScreenManager } from './ErrorScreenManager'
2423
export { default as ErrorScreenNotAuthorized } from './ErrorScreenNotAuthorized'

src/Pages/GlobalConfigurations/BuildInfra/utils.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import { FormEvent, useEffect, useState } from 'react'
18-
import { toast } from 'react-toastify'
1918
import { showError, useAsync } from '../../../Common'
2019
import { getBuildInfraProfileByName, createBuildInfraProfile, updateBuildInfraProfile } from './services'
2120
import {
@@ -43,6 +42,8 @@ import {
4342
validateRequiredPositiveNumber,
4443
getCommonSelectStyle,
4544
validateRequiredPositiveInteger,
45+
ToastVariantType,
46+
ToastManager,
4647
} from '../../../Shared'
4748

4849
export const validateRequestLimit = ({
@@ -419,7 +420,10 @@ export const useBuildInfraForm = ({
419420
).length > 0
420421

421422
if (hasErrors) {
422-
toast.error(BUILD_INFRA_TEXT.INVALID_FORM_MESSAGE)
423+
ToastManager.showToast({
424+
variant: ToastVariantType.error,
425+
description: BUILD_INFRA_TEXT.INVALID_FORM_MESSAGE,
426+
})
423427
return
424428
}
425429

@@ -431,7 +435,10 @@ export const useBuildInfraForm = ({
431435
await createBuildInfraProfile({ profileInput })
432436
}
433437
setLoadingActionRequest(false)
434-
toast.success(BUILD_INFRA_TEXT.getSubmitSuccessMessage(profileInput.name, editProfile))
438+
ToastManager.showToast({
439+
variant: ToastVariantType.success,
440+
description: BUILD_INFRA_TEXT.getSubmitSuccessMessage(profileInput.name, editProfile),
441+
})
435442

436443
if (handleSuccessRedirection) {
437444
handleSuccessRedirection()

src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { createContext, useContext, useMemo, useState } from 'react'
18-
import { toast } from 'react-toastify'
18+
import { ToastManager, ToastVariantType } from '@Shared/Services'
1919
import {
2020
BULK_SELECTION_CONTEXT_ERROR,
2121
CLEAR_SELECTIONS_WARNING,
@@ -92,7 +92,10 @@ export const BulkSelectionProvider = <T,>({
9292
break
9393

9494
case BulkSelectionEvents.CLEAR_IDENTIFIERS_AFTER_ACROSS_SELECTION: {
95-
toast.info(CLEAR_SELECTIONS_WARNING)
95+
ToastManager.showToast({
96+
variant: ToastVariantType.info,
97+
description: CLEAR_SELECTIONS_WARNING,
98+
})
9699
setIdentifiersAfterClear(identifiers, selectedIds)
97100
break
98101
}
@@ -128,7 +131,10 @@ export const BulkSelectionProvider = <T,>({
128131

129132
case BulkSelectionEvents.SELECT_ALL_ON_PAGE: {
130133
if (selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]) {
131-
toast.info(CLEAR_SELECTIONS_WARNING)
134+
ToastManager.showToast({
135+
variant: ToastVariantType.info,
136+
description: CLEAR_SELECTIONS_WARNING,
137+
})
132138
}
133139

134140
setIdentifiersAfterPageSelection(identifiers)

src/Shared/Components/CICDHistory/TriggerOutput.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import { Redirect, Route, Switch, useLocation, useParams, useRouteMatch, Link, NavLink } from 'react-router-dom'
1818
import React, { useEffect, useMemo, useState } from 'react'
1919
import moment from 'moment'
20-
import { toast } from 'react-toastify'
2120
import { ShowMoreText } from '@Shared/Components/ShowMoreText'
2221
import { getHandleOpenURL } from '@Shared/Helpers'
2322
import { ImageChipCell } from '@Shared/Components/ImageChipCell'
@@ -26,6 +25,7 @@ import { ReactComponent as ICLines } from '@Icons/ic-lines.svg'
2625
import { ReactComponent as ICPulsateStatus } from '@Icons/ic-pulsate-status.svg'
2726
import { ReactComponent as ICArrowRight } from '@Icons/ic-arrow-right.svg'
2827
import { getDeploymentStageTitle } from '@Pages/App'
28+
import { ToastManager, ToastVariantType } from '@Shared/Services'
2929
import {
3030
ConfirmationDialog,
3131
DATE_TIME_FORMATS,
@@ -164,7 +164,10 @@ const ProgressingStatus = React.memo(({ status, stage, type }: ProgressingStatus
164164
setAborting(true)
165165
try {
166166
await abort(abortError.status)
167-
toast.success('Build Aborted')
167+
ToastManager.showToast({
168+
variant: ToastVariantType.success,
169+
description: 'Build Aborted',
170+
})
168171
setAbortConfirmation(false)
169172
setAbortError({
170173
status: false,

src/Shared/Components/EditImageFormField/EditImageFormField.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { KeyboardEvent, SyntheticEvent, useState } from 'react'
2-
import { toast } from 'react-toastify'
32
import { showError } from '@Common/Helper'
43
import { CustomInput } from '@Common/CustomInput'
54
import { ButtonWithLoader, ImageWithFallback } from '@Shared/Components'
65
import { validateIfImageExist, validateURL } from '@Shared/validations'
6+
import { ToastManager, ToastVariantType } from '@Shared/Services'
77
import { ReactComponent as ICPencil } from '@Icons/ic-pencil.svg'
88
import { EditImageFormFieldProps, FallbackImageProps } from './types'
99
import {
@@ -101,12 +101,18 @@ const EditImageFormField = ({
101101
if (!url) {
102102
// Not setting the error since can save without image
103103
setEmptyPreviewURLErrorMessage(EMPTY_PREVIEW_URL_ERROR_MESSAGE)
104-
toast.error(EMPTY_PREVIEW_URL_ERROR_MESSAGE)
104+
ToastManager.showToast({
105+
variant: ToastVariantType.error,
106+
description: EMPTY_PREVIEW_URL_ERROR_MESSAGE,
107+
})
105108
return
106109
}
107110

108111
if (errorMessage) {
109-
toast.error(errorMessage)
112+
ToastManager.showToast({
113+
variant: ToastVariantType.error,
114+
description: errorMessage,
115+
})
110116
return
111117
}
112118

0 commit comments

Comments
 (0)