Skip to content

Commit 700d220

Browse files
committed
feat: update typing and add default for title
1 parent 1e9f2d5 commit 700d220

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

src/Shared/Services/ToastManager/ToastContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const ToastContent = ({ title, description, buttonProps }: Omit<ToastProp
66
<div className="flexbox-col dc__gap-8">
77
<div className="flexbox-col dc__gap-4">
88
<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>}
9+
<p className="fs-12 fw-4 lh-18 m-0 dc__truncate--clamp-6">{description}</p>
1010
</div>
1111
{buttonProps && (
1212
<Button
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { ReactElement, MouseEventHandler } from 'react'
1+
import { MouseEventHandler } from 'react'
22
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 ICClose } from '@Icons/ic-close.svg'
9-
import { ToastVariantType } from './types'
9+
import { ToastProps, ToastVariantType } from './types'
1010

1111
export const TOAST_BASE_CONFIG: ToastContainerProps = {
1212
autoClose: 5000,
@@ -18,34 +18,40 @@ export const TOAST_BASE_CONFIG: ToastContainerProps = {
1818
toastClassName: 'custom-toast',
1919
bodyClassName: 'custom-toast__body',
2020
closeButton: ({ closeToast }) => (
21-
<ICClose className="icon-dim-24 p-4 flex dc__no-shrink fcn-0" onClick={closeToast as MouseEventHandler} />
21+
<ICClose
22+
className="icon-dim-24 p-4 flex dc__no-shrink fcn-0 cursor"
23+
onClick={closeToast as MouseEventHandler}
24+
/>
2225
),
2326
}
2427

2528
export const TOAST_VARIANT_TO_CONFIG_MAP: Record<
2629
ToastVariantType,
27-
{
28-
icon: ReactElement
29-
} & Pick<ToastOptions, 'type'>
30+
Required<Pick<ToastProps, 'icon' | 'title'>> & Pick<ToastOptions, 'type'>
3031
> = {
3132
[ToastVariantType.info]: {
3233
icon: <ICInfoFilled />,
3334
type: 'info',
35+
title: 'Information',
3436
},
3537
[ToastVariantType.success]: {
3638
icon: <ICSuccess />,
3739
type: 'success',
40+
title: 'Success',
3841
},
3942
[ToastVariantType.error]: {
4043
icon: <ICError />,
4144
type: 'error',
45+
title: 'Error',
4246
},
4347
[ToastVariantType.warn]: {
4448
icon: <ICWarning className="warning-icon-y5-imp" />,
4549
type: 'warning',
50+
title: 'Warning',
4651
},
4752
[ToastVariantType.notAuthorized]: {
4853
icon: <ICLocked />,
4954
type: 'warning',
55+
title: 'Not authorized',
5056
},
5157
}

src/Shared/Services/ToastManager/toastManager.service.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ class ToastManager {
1919

2020
// eslint-disable-next-line class-methods-use-this
2121
showToast = (
22-
{ variant = ToastVariantType.info, icon: customIcon, ...toastProps }: ToastProps,
22+
{ variant = ToastVariantType.info, icon: customIcon, title, description, buttonProps }: ToastProps,
2323
options: Pick<ToastOptions, 'autoClose'> = {},
2424
) => {
25-
const { icon, type } = TOAST_VARIANT_TO_CONFIG_MAP[variant]
25+
const { icon, type, title: defaultTitle } = TOAST_VARIANT_TO_CONFIG_MAP[variant]
2626

27-
return toast(<ToastContent {...toastProps} />, {
28-
...options,
29-
icon: () => (
30-
<div className="dc__no-shrink flex dc__fill-available-space icon-dim-20">{customIcon ?? icon}</div>
31-
),
32-
type,
33-
})
27+
return toast(
28+
<ToastContent title={title || defaultTitle} description={description} buttonProps={buttonProps} />,
29+
{
30+
...options,
31+
icon: () => (
32+
<div className="dc__no-shrink flex dc__fill-available-space icon-dim-20">{customIcon ?? icon}</div>
33+
),
34+
type,
35+
},
36+
)
3437
}
3538
}
3639

src/Shared/Services/ToastManager/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export enum ToastVariantType {
1010
}
1111

1212
export interface ToastProps {
13-
title: string
14-
description?: string
13+
title?: string
14+
description: string
1515
icon?: ReactElement
1616
variant?: ToastVariantType
1717
buttonProps?: ButtonProps

0 commit comments

Comments
 (0)