-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds SuitesReminder hook to get a consistent look across platfo…
…rms for the reminder notification (#221) Co-authored-by: jared-dickman <zenador15@gmail.com>
- Loading branch information
1 parent
c74a12e
commit 533428e
Showing
4 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.globalNavigation__suitesReminder.globalNavigation__suitesReminder-bottomLeft { | ||
left: calc(var(--nav-width) + var(--margin-xs)) !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import 'src/styles/_variables.css' | ||
import './suites-reminder.css' | ||
import { type ReactNode } from 'react' | ||
import { Button, notification, Space } from 'src/components' | ||
import { FontWeightStrong } from 'src/styles/style' | ||
|
||
export interface ISuitesReminderOptions { | ||
onClose: () => void | ||
onRemindMeLater: () => void | ||
onTakeMeThere: () => void | ||
duration?: number | ||
title?: string | ||
message?: string | ||
} | ||
|
||
type OpenNotificationFn = () => void | ||
type ContextHolder = ReactNode | ||
|
||
export type SuitesReminderHook = [OpenNotificationFn, ContextHolder] | ||
|
||
const DefaultReminderDuration = 4.5 as const // same as antd notification default duration | ||
const DefaultTitle = 'Join the new mParticle Experience!' as const | ||
const DefaultMessage = | ||
'Managing your data is easier than ever with the new mParticle experience. Try out the latest features with ease, and switch back to the classic experience anytime from the side navigation.' as const | ||
|
||
export const useSuitesReminder = (options: ISuitesReminderOptions): SuitesReminderHook => { | ||
const { | ||
onClose, | ||
onRemindMeLater, | ||
onTakeMeThere, | ||
duration = DefaultReminderDuration, | ||
title = DefaultTitle, | ||
message = DefaultMessage, | ||
} = options | ||
|
||
const [notificationApi, contextHolder] = notification.useNotification({ | ||
prefixCls: 'globalNavigation__suitesReminder', | ||
duration, | ||
placement: 'bottomLeft', | ||
}) | ||
|
||
const openNotification = (): void => { | ||
const key = `notification-${Date.now()}` | ||
const btn = ( | ||
<Space> | ||
<Button | ||
type="link" | ||
size="small" | ||
onClick={_event => { | ||
onRemindMeLater() | ||
notificationApi.destroy(key) | ||
}}> | ||
Remind me later | ||
</Button> | ||
<Button | ||
type="primary" | ||
size="small" | ||
onClick={_event => { | ||
onTakeMeThere() | ||
notificationApi.destroy(key) | ||
}}> | ||
Take me there | ||
</Button> | ||
</Space> | ||
) | ||
|
||
notificationApi.open({ | ||
message: <span style={{ fontWeight: FontWeightStrong }}>{title}</span>, | ||
description: message, | ||
btn, | ||
key, | ||
onClose, | ||
}) | ||
} | ||
|
||
return [openNotification, contextHolder] | ||
} |