0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(demo-app): show notification in main flow (#1038)

* feat(demo-app): show notification in main flow

* fix: add missing file
This commit is contained in:
Gao Sun 2022-06-02 16:05:27 +08:00 committed by GitHub
parent 36c958a11d
commit 90ca76eeb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 6 deletions

View file

@ -1,4 +1,5 @@
import { LogtoProvider, useLogto } from '@logto/react'; import { LogtoProvider, useLogto } from '@logto/react';
import { signInNotificationStorageKey } from '@logto/schemas';
import { demoAppApplicationId } from '@logto/schemas/lib/seeds'; import { demoAppApplicationId } from '@logto/schemas/lib/seeds';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
@ -17,6 +18,10 @@ const Main = () => {
useEffect(() => { useEffect(() => {
if (!isAuthenticated && !isInCallback) { if (!isAuthenticated && !isInCallback) {
sessionStorage.setItem(
signInNotificationStorageKey,
'Use the admin username and password to sign in this demo.'
);
void signIn(window.location.href); void signIn(window.location.href);
} }
}, [isAuthenticated, isInCallback, signIn]); }, [isAuthenticated, isInCallback, signIn]);

View file

@ -0,0 +1 @@
export const signInNotificationStorageKey = 'logto:client:notification';

View file

@ -1,3 +1,4 @@
export * from './consts';
export * from './foundations'; export * from './foundations';
export * from './db-entries'; export * from './db-entries';
export * from './types'; export * from './types';

View file

@ -1,14 +1,13 @@
import { signInNotificationStorageKey } from '@logto/schemas';
import { render, fireEvent } from '@testing-library/react'; import { render, fireEvent } from '@testing-library/react';
import React from 'react'; import React from 'react';
import { appNotificationStorageKey } from '@/utils/session-storage';
import AppNotification from '.'; import AppNotification from '.';
describe('AppNotification', () => { describe('AppNotification', () => {
it('render properly', () => { it('render properly', () => {
const message = 'This is a notification message'; const message = 'This is a notification message';
sessionStorage.setItem(appNotificationStorageKey, message); sessionStorage.setItem(signInNotificationStorageKey, message);
const { queryByText, getByText } = render(<AppNotification />); const { queryByText, getByText } = render(<AppNotification />);
expect(queryByText(message)).not.toBeNull(); expect(queryByText(message)).not.toBeNull();

View file

@ -1,9 +1,9 @@
export const appNotificationStorageKey = 'logto:client:notification'; import { signInNotificationStorageKey } from '@logto/schemas';
export const getAppNotificationInfo = () => { export const getAppNotificationInfo = () => {
return sessionStorage.getItem(appNotificationStorageKey); return sessionStorage.getItem(signInNotificationStorageKey);
}; };
export const clearAppNotificationInfo = () => { export const clearAppNotificationInfo = () => {
sessionStorage.removeItem(appNotificationStorageKey); sessionStorage.removeItem(signInNotificationStorageKey);
}; };