overleaf/services/web/frontend/js/features/ui/components/bootstrap-5/notification-wrapper.tsx
ilkin-overleaf 1e7053cb8e Merge pull request #17921 from overleaf/ii-bs5-alert-continue
[web] Replace all alerts with notifications in settings page

GitOrigin-RevId: a05755c39d2e54b3f57ffa589885e3e96aee00dc
2024-04-24 08:04:35 +00:00

42 lines
1.2 KiB
TypeScript

import Notification from '@/shared/components/notification'
import { Alert, AlertProps } from 'react-bootstrap'
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
import classnames from 'classnames'
type NotificationWrapperProps = React.ComponentProps<typeof Notification> & {
bs3Props?: {
icon?: React.ReactElement
className?: string
}
}
function NotificationWrapper(props: NotificationWrapperProps) {
const { bs3Props, ...notificationProps } = props
const alertProps = {
// Map `error` to `danger`
bsStyle:
notificationProps.type === 'error' ? 'danger' : notificationProps.type,
className: classnames(notificationProps.className, bs3Props?.className),
onDismiss: notificationProps.onDismiss,
} as const satisfies AlertProps
return (
<BootstrapVersionSwitcher
bs3={
<Alert {...alertProps}>
{bs3Props?.icon}
{bs3Props?.icon && ' '}
{notificationProps.content}
</Alert>
}
bs5={
<div className="notification-list">
<Notification {...notificationProps} />
</div>
}
/>
)
}
export default NotificationWrapper