Skip to content

Commit

Permalink
feat(demo-app): show notification in main flow (#1038)
Browse files Browse the repository at this point in the history
* feat(demo-app): show notification in main flow

* fix: add missing file
  • Loading branch information
gao-sun authored Jun 2, 2022
1 parent 36c958a commit 90ca76e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/demo-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LogtoProvider, useLogto } from '@logto/react';
import { signInNotificationStorageKey } from '@logto/schemas';
import { demoAppApplicationId } from '@logto/schemas/lib/seeds';
import React, { useEffect } from 'react';

Expand All @@ -17,6 +18,10 @@ const Main = () => {

useEffect(() => {
if (!isAuthenticated && !isInCallback) {
sessionStorage.setItem(
signInNotificationStorageKey,
'Use the admin username and password to sign in this demo.'
);
void signIn(window.location.href);
}
}, [isAuthenticated, isInCallback, signIn]);
Expand Down
1 change: 1 addition & 0 deletions packages/schemas/src/consts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const signInNotificationStorageKey = 'logto:client:notification';
1 change: 1 addition & 0 deletions packages/schemas/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './consts';
export * from './foundations';
export * from './db-entries';
export * from './types';
Expand Down
5 changes: 2 additions & 3 deletions packages/ui/src/containers/AppNotification/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { signInNotificationStorageKey } from '@logto/schemas';
import { render, fireEvent } from '@testing-library/react';
import React from 'react';

import { appNotificationStorageKey } from '@/utils/session-storage';

import AppNotification from '.';

describe('AppNotification', () => {
it('render properly', () => {
const message = 'This is a notification message';
sessionStorage.setItem(appNotificationStorageKey, message);
sessionStorage.setItem(signInNotificationStorageKey, message);
const { queryByText, getByText } = render(<AppNotification />);

expect(queryByText(message)).not.toBeNull();
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/utils/session-storage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const appNotificationStorageKey = 'logto:client:notification';
import { signInNotificationStorageKey } from '@logto/schemas';

export const getAppNotificationInfo = () => {
return sessionStorage.getItem(appNotificationStorageKey);
return sessionStorage.getItem(signInNotificationStorageKey);
};

export const clearAppNotificationInfo = () => {
sessionStorage.removeItem(appNotificationStorageKey);
sessionStorage.removeItem(signInNotificationStorageKey);
};

0 comments on commit 90ca76e

Please sign in to comment.