From f05000d4c7d69725822cf15675a9d16f8e05985e Mon Sep 17 00:00:00 2001 From: Hayata Suenaga Date: Fri, 6 Oct 2023 15:59:50 +0900 Subject: [PATCH 1/5] feat: add new comp for iframe --- src/components/IFrame.js | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/components/IFrame.js diff --git a/src/components/IFrame.js b/src/components/IFrame.js new file mode 100644 index 000000000000..04a6c8d43075 --- /dev/null +++ b/src/components/IFrame.js @@ -0,0 +1,62 @@ +import React, {useEffect} from 'react'; + +function getNewDotURL(url) { + const urlObj = new URL(url); + const paramString = urlObj.searchParams.get('param') ?? ''; + const pathname = urlObj.pathname.slice(1); + + let params; + try { + params = JSON.parse(paramString); + } catch { + params = {}; + } + + if (pathname === 'inbox') { + return 'home'; + } + + if (pathname === 'expenses') { + return `${params.viewMode === 'charts' ? 'insights' : 'expenses'}/${paramString}`; + } + + if (pathname === 'admin_policies') { + const {section} = params; + return section === 'individual' ? 'individual_workspaces' : 'group_workspaces'; + } + + if (pathname === 'policy') { + const workspaceID = params.policyID || ''; + const section = urlObj.hash.slice(1) || 'overview'; + + return `workspace/${workspaceID}/${section}`; + } + + if (pathname === 'settings') { + const {section} = params; + return `settings/${section}`; + } + + if (pathname.includes('domain')) { + return pathname; + } + + return pathname; +} + +export default function ReportScreen() { + useEffect(() => { + window.addEventListener('message', (event) => { + const url = event.data; + const newDotURL = getNewDotURL(url); + }); + }, []); + + return ( +