Skip to content

feat(ui): add NotificationProvider #7967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/site/components/Common/CodeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import { CodeBracketIcon } from '@heroicons/react/24/outline';
import BaseCodeBox from '@node-core/ui-components/Common/BaseCodeBox';
import styles from '@node-core/ui-components/Common/BaseCodeBox/index.module.css';
import { useNotification } from '@node-core/ui-components/Providers/NotificationProvider';
import { useTranslations } from 'next-intl';
import type { FC, PropsWithChildren } from 'react';

import Link from '#site/components/Link';
import { useCopyToClipboard, useNotification } from '#site/hooks';
import { useCopyToClipboard } from '#site/hooks';

type CodeBoxProps = {
language: string;
Expand Down
54 changes: 0 additions & 54 deletions apps/site/hooks/react-client/__tests__/useNotification.test.jsx

This file was deleted.

1 change: 0 additions & 1 deletion apps/site/hooks/react-client/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export { default as useCopyToClipboard } from './useCopyToClipboard';
export { default as useDetectOS } from './useDetectOS';
export { default as useMediaQuery } from './useMediaQuery';
export { default as useNotification } from './useNotification';
export { default as useClientContext } from './useClientContext';
export { default as useNavigationState } from './useNavigationState';
9 changes: 0 additions & 9 deletions apps/site/hooks/react-client/useNotification.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/site/hooks/react-server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { default as useCopyToClipboard } from './useCopyToClipboard';
export { default as useDetectOS } from './useDetectOS';
export { default as useMediaQuery } from './useMediaQuery';
export { default as useNotification } from './useNotification';
export { default as useClientContext } from './useClientContext';
5 changes: 0 additions & 5 deletions apps/site/hooks/react-server/useNotification.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/site/layouts/Base.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use client';

import { NotificationProvider } from '@node-core/ui-components/Providers/NotificationProvider';
import type { FC, PropsWithChildren } from 'react';

import { NavigationStateProvider } from '#site/providers/navigationStateProvider';
import { NotificationProvider } from '#site/providers/notificationProvider';

import styles from './layouts.module.css';

Expand Down
1 change: 0 additions & 1 deletion apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@oramacloud/client": "^2.1.4",
"@radix-ui/react-slot": "^1.2.3",
"@radix-ui/react-tabs": "^1.1.12",
"@radix-ui/react-toast": "^1.2.14",
"@radix-ui/react-tooltip": "^1.2.7",
"@tailwindcss/postcss": "~4.1.11",
"@types/node": "catalog:",
Expand Down
43 changes: 0 additions & 43 deletions apps/site/providers/__tests__/notificationProvider.test.jsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Notification from '@node-core/ui-components/Common/Notification';
import * as Toast from '@radix-ui/react-toast';
import { createContext, useContext, useEffect, useState } from 'react';
import type {
Dispatch,
FC,
PropsWithChildren,
ReactNode,
SetStateAction,
} from 'react';
import { createContext, useEffect, useState } from 'react';

import Notification from '#ui/Common/Notification';

type NotificationContextType = {
message: string | ReactNode;
Expand All @@ -22,6 +23,8 @@ export const NotificationDispatch = createContext<
Dispatch<SetStateAction<NotificationContextType>>
>(() => {});

export const useNotification = () => useContext(NotificationDispatch);

export const NotificationProvider: FC<PropsWithChildren<NotificationProps>> = ({
viewportClassName,
children,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { render } from '@testing-library/react';

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';

import { NotificationProvider, useNotification } from '../NotificationProvider';

describe('useNotification', () => {
it('should return the notification dispatch function', () => {
// Arrange
const TestComponent = () => {
const notificationDispatch = useNotification();
return (
<div>
{notificationDispatch ? 'Dispatch available' : 'Dispatch unavailable'}
</div>
);
};

// Act
const { getByText } = render(
<NotificationProvider>
<TestComponent />
</NotificationProvider>
);

// Assert
const result = getByText('Dispatch available');
assert.ok(result.ownerDocument);
});

it('should return null outside NotificationProvider', () => {
// Arrange
const TestComponent = () => {
const notificationDispatch = useNotification();
return (
<div>
{notificationDispatch ? 'Dispatch available' : 'Dispatch unavailable'}
</div>
);
};

// Act
const { queryByText } = render(<TestComponent />);

// Assert
const result = queryByText((content, element) => {
return element.textContent === 'Dispatch unavailable';
});

assert.equal(result, null);
});
});
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading