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:
parent
36c958a11d
commit
90ca76eeb5
5 changed files with 12 additions and 6 deletions
|
@ -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';
|
||||
|
||||
|
@ -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]);
|
||||
|
|
1
packages/schemas/src/consts/index.ts
Normal file
1
packages/schemas/src/consts/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export const signInNotificationStorageKey = 'logto:client:notification';
|
|
@ -1,3 +1,4 @@
|
|||
export * from './consts';
|
||||
export * from './foundations';
|
||||
export * from './db-entries';
|
||||
export * from './types';
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue