Skip to content

Commit 17fc5a4

Browse files
committed
refactor: upgrade react toastify to v9
1 parent 353e7b7 commit 17fc5a4

File tree

6 files changed

+49
-47
lines changed

6 files changed

+49
-47
lines changed

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"prettier": "^3.1.1",
6565
"react-ga4": "^1.4.1",
6666
"react-mde": "^11.5.0",
67-
"react-toastify": "^8.2.0",
67+
"react-toastify": "9.1.3",
6868
"typescript": "5.5.4",
6969
"vite": "5.4.2",
7070
"vite-plugin-dts": "4.0.3",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Button, ButtonStyleType, ButtonVariantType } from '@Shared/Components'
2+
import { ComponentSizeType } from '@Shared/constants'
3+
import { ToastProps } from './types'
4+
5+
export const ToastContent = ({ title, description, buttonProps }: Omit<ToastProps, 'variant'>) => (
6+
<div className="flexbox-col dc__gap-8">
7+
<div className="flexbox-col dc__gap-4">
8+
<h3 className="m-0 fs-13 fw-6 lh-20 cn-0 dc__truncate">{title}</h3>
9+
{description && <p className="fs-12 fw-4 lh-18 m-0 dc__truncate--clamp-6">{description}</p>}
10+
</div>
11+
{buttonProps && (
12+
<Button
13+
{...buttonProps}
14+
variant={ButtonVariantType.text}
15+
size={ComponentSizeType.small}
16+
style={ButtonStyleType.neutral}
17+
/>
18+
)}
19+
</div>
20+
)

src/Shared/Services/ToastManager/constants.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1-
import { ReactElement } from 'react'
2-
import { ToastOptions } from 'react-toastify'
1+
import { ReactElement, MouseEventHandler } from 'react'
2+
import { ToastOptions, ToastContainerProps } from 'react-toastify'
33
import { ReactComponent as ICInfoFilled } from '@Icons/ic-info-filled.svg'
44
import { ReactComponent as ICSuccess } from '@Icons/ic-success.svg'
55
import { ReactComponent as ICError } from '@Icons/ic-error.svg'
66
import { ReactComponent as ICWarning } from '@Icons/ic-warning.svg'
77
import { ReactComponent as ICLocked } from '@Icons/ic-locked.svg'
88
import { ReactComponent as ICSparkles } from '@Icons/ic-sparkles.svg'
9+
import { ReactComponent as ICClose } from '@Icons/ic-close.svg'
910
import { ToastVariantType } from './types'
1011

12+
export const TOAST_BASE_CONFIG: ToastContainerProps = {
13+
autoClose: 5000,
14+
hideProgressBar: false,
15+
pauseOnHover: true,
16+
pauseOnFocusLoss: true,
17+
closeOnClick: false,
18+
newestOnTop: true,
19+
toastClassName: 'custom-toast',
20+
bodyClassName: 'custom-toast__body',
21+
closeButton: ({ closeToast }) => (
22+
<ICClose className="icon-dim-24 p-4 flex dc__no-shrink fcn-0" onClick={closeToast as MouseEventHandler} />
23+
),
24+
}
25+
1126
export const TOAST_VARIANT_TO_CONFIG_MAP: Record<
1227
ToastVariantType,
1328
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { default as ToastManager } from './toastManager.service'
1+
export { default as ToastManager, ToastManagerContainer } from './toastManager.service'
22
export { ToastVariantType } from './types'
33
export type { ToastProps } from './types'
Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,14 @@
1-
import { toast, ToastOptions } from 'react-toastify'
1+
import { toast, ToastContainer, ToastOptions } from 'react-toastify'
22
import 'react-toastify/dist/ReactToastify.css'
3-
4-
import { ReactComponent as ICClose } from '@Icons/ic-close.svg'
5-
import { Button, ButtonStyleType, ButtonVariantType } from '@Shared/Components'
6-
import { ComponentSizeType } from '@Shared/constants'
73
import { ToastProps, ToastVariantType } from './types'
4+
import { TOAST_BASE_CONFIG, TOAST_VARIANT_TO_CONFIG_MAP } from './constants'
5+
import { ToastContent } from './ToastContent'
86
import './toastManager.scss'
9-
import { TOAST_VARIANT_TO_CONFIG_MAP } from './constants'
10-
11-
export const ToastContent = ({ title, description, buttonProps }: Omit<ToastProps, 'variant'>) => (
12-
<div className="flexbox-col dc__gap-8">
13-
<div className="flexbox-col dc__gap-4">
14-
<h3 className="m-0 fs-13 fw-6 lh-20 cn-0 dc__truncate">{title}</h3>
15-
{description && <p className="fs-12 fw-4 lh-18 m-0 dc__truncate--clamp-6">{description}</p>}
16-
</div>
17-
{buttonProps && (
18-
<Button
19-
{...buttonProps}
20-
variant={ButtonVariantType.text}
21-
size={ComponentSizeType.small}
22-
style={ButtonStyleType.neutral}
23-
/>
24-
)}
25-
</div>
26-
)
277

288
class ToastManager {
299
// eslint-disable-next-line no-use-before-define
3010
static #instance: ToastManager
3111

32-
constructor() {
33-
toast.configure({
34-
autoClose: 5000,
35-
hideProgressBar: false,
36-
pauseOnHover: true,
37-
pauseOnFocusLoss: true,
38-
closeOnClick: false,
39-
newestOnTop: true,
40-
toastClassName: 'custom-toast',
41-
bodyClassName: 'custom-toast__body',
42-
closeButton: ({ closeToast }) => (
43-
<ICClose className="icon-dim-24 p-4 flex dc__no-shrink fcn-0" onClick={closeToast} />
44-
),
45-
})
46-
}
47-
4812
public static get instance(): ToastManager {
4913
if (!ToastManager.#instance) {
5014
ToastManager.#instance = new ToastManager()
@@ -68,4 +32,6 @@ class ToastManager {
6832
}
6933
}
7034

35+
export const ToastManagerContainer = () => <ToastContainer {...TOAST_BASE_CONFIG} />
36+
7137
export default ToastManager.instance

0 commit comments

Comments
 (0)