this repo has no description
at main 29 lines 926 B view raw
1import { getModalPageStore } from '~/stores/modalPage'; 2import { isGenericPage, type Page } from '../models'; 3import type { Logger } from '@amp/web-apps-logger/src'; 4 5/** 6 * This function handles rendering flow action pages into a modal container. 7 * NOTE: Rendering a page in a modal will not update URL or history 8 * 9 * @param page page promise 10 * @param log app logger 11 */ 12export const handleModalPresentation = ( 13 page: { promise: Promise<Page> }, 14 log: Logger<unknown[]>, 15 pageDetail?: string, 16) => { 17 page.promise 18 .then((page) => { 19 if (isGenericPage(page)) { 20 const modalStore = getModalPageStore(); 21 modalStore.setPage({ page, pageDetail }); 22 } else { 23 throw new Error('only generic page is rendered in modal'); 24 } 25 }) 26 .catch((e) => { 27 log.error('modal presentation failed', e); 28 }); 29};