-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(js,react): Export InboxContent component (#6531)
- Loading branch information
Showing
33 changed files
with
1,231 additions
and
766 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
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
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
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,53 @@ | ||
import React from 'react'; | ||
import type { NotificationClickHandler, NotificationActionClickHandler, InboxPage } from '@novu/js/ui'; | ||
import { Mounter } from './Mounter'; | ||
import { NotificationsRenderer } from '../utils/types'; | ||
import { useRenderer } from '../context/RendererContext'; | ||
import { useNovuUI } from '../context/NovuUIContext'; | ||
import { withRenderer } from './Renderer'; | ||
|
||
export type InboxContentProps = { | ||
renderNotification?: NotificationsRenderer; | ||
onNotificationClick?: NotificationClickHandler; | ||
onPrimaryActionClick?: NotificationActionClickHandler; | ||
onSecondaryActionClick?: NotificationActionClickHandler; | ||
initialPage?: InboxPage; | ||
hideNav?: boolean; | ||
}; | ||
|
||
const _InboxContent = React.memo((props: InboxContentProps) => { | ||
const { | ||
onNotificationClick, | ||
onPrimaryActionClick, | ||
renderNotification, | ||
onSecondaryActionClick, | ||
initialPage, | ||
hideNav, | ||
} = props; | ||
const { novuUI } = useNovuUI(); | ||
const { mountElement } = useRenderer(); | ||
|
||
const mount = React.useCallback( | ||
(element: HTMLElement) => { | ||
return novuUI.mountComponent({ | ||
name: 'InboxContent', | ||
element, | ||
props: { | ||
renderNotification: renderNotification | ||
? (el, notification) => mountElement(el, renderNotification(notification)) | ||
: undefined, | ||
onNotificationClick, | ||
onPrimaryActionClick, | ||
onSecondaryActionClick, | ||
initialPage, | ||
hideNav, | ||
}, | ||
}); | ||
}, | ||
[renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick] | ||
); | ||
|
||
return <Mounter mount={mount} />; | ||
}); | ||
|
||
export const InboxContent = withRenderer(_InboxContent); |
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,43 @@ | ||
import { Novu } from '@novu/js'; | ||
import type { NovuUIOptions } from '@novu/js/ui'; | ||
import { NovuUI as NovuUIClass } from '@novu/js/ui'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { NovuUIProvider } from '../context/NovuUIContext'; | ||
import { useDataRef } from '../hooks/internal/useDataRef'; | ||
|
||
type RendererProps = React.PropsWithChildren<{ | ||
options: NovuUIOptions; | ||
novu?: Novu; | ||
}>; | ||
|
||
export const NovuUI = ({ options, novu, children }: RendererProps) => { | ||
const optionsRef = useDataRef({ ...options, novu }); | ||
const [novuUI, setNovuUI] = useState<NovuUIClass | undefined>(); | ||
|
||
useEffect(() => { | ||
const novu = new NovuUIClass(optionsRef.current); | ||
setNovuUI(novu); | ||
|
||
return () => { | ||
novu.unmount(); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!novuUI) { | ||
return; | ||
} | ||
|
||
novuUI.updateAppearance(options.appearance); | ||
novuUI.updateLocalization(options.localization); | ||
novuUI.updateTabs(options.tabs); | ||
novuUI.updateOptions(options.options); | ||
novuUI.updateRouterPush(options.routerPush); | ||
}, [options]); | ||
|
||
if (!novuUI) { | ||
return null; | ||
} | ||
|
||
return <NovuUIProvider value={{ novuUI }}>{children}</NovuUIProvider>; | ||
}; |
Oops, something went wrong.