Skip to content

Commit 1031ec5

Browse files
committed
ch: add redirect handler
fix: linting errors
1 parent f0d1c91 commit 1031ec5

File tree

3 files changed

+69
-12
lines changed

3 files changed

+69
-12
lines changed

src/components/InvitationTable.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ function DataTableStats({ data, columns, error, loading }: TableData) {
6363

6464
return (
6565
<div
66-
className={``}
66+
className=""
6767
>
68-
<div className="flex items-center justify-between pb-6 ">
69-
</div>
68+
<div className="flex items-center justify-between pb-6 " />
7069
<div style={{ overflowX: 'auto' }}>
7170
<table className="min-w-full leading-normal" {...getTableProps()}>
7271
<thead>

src/containers/Routes.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable */
22
import React, { Suspense } from 'react';
3-
import { Routes, Route, Outlet } from 'react-router-dom';
4-
import Home from '../pages/Home';
5-
import Header from '../components/Header';
3+
import { Outlet, Route, Routes } from 'react-router-dom';
64
import Footer from '../components/Footer';
7-
import Error from './../pages/Error';
5+
import Header from '../components/Header';
86
import Skeleton from '../components/Skeleton';
9-
import UserRegister from '../pages/Organization/UserRegister';
7+
import Home from '../pages/Home';
108
import Message from '../pages/Organization/Message';
9+
import UserRegister from '../pages/Organization/UserRegister';
10+
import Error from './../pages/Error';
1111
/* istanbul ignore next */
1212
const OrgRegister = React.lazy(() => import('../pages/OrgRegister'));
1313
/* istanbul ignore next */
@@ -32,19 +32,20 @@ const SignupOrgDocs = React.lazy(
3232
const SigninOrgDocs = React.lazy(
3333
() => import('../components/Docs/SigninOrgDocs'),
3434
);
35-
const UsersDocs = React.lazy( () => import ('../components/Docs/users'),)
35+
const UsersDocs = React.lazy(() => import('../components/Docs/users'));
3636
/* istanbul ignore next */
37+
import DashRoutes from '../containers/DashRoutes';
3738
import Noredirect from '../pages/Noredirect';
39+
import RedirectHandler from '../pages/RedirectHandler';
3840
import ProtectedRoutes from '../ProtectedRoute';
3941
import RemoveTokenPage from '../utils/RemoveTokenPage';
40-
import DashRoutes from '../containers/DashRoutes';
4142

4243
function MainRoutes() {
4344
return (
4445
<div className="min-h-screen page-layout">
4546
<Suspense fallback={<Skeleton />}>
4647
<Routes>
47-
<Route path="/*" element={<DashRoutes />} />
48+
<Route path="/*" element={<DashRoutes />} />
4849
<Route
4950
path="/"
5051
element={
@@ -91,7 +92,8 @@ function MainRoutes() {
9192
/>
9293
<Route path="/docs/org-signup" element={<SignupOrgDocs />} />
9394
<Route path="/docs/org-signin" element={<SigninOrgDocs />} />
94-
<Route path='/docs/getting-started' element={< UsersDocs />} />
95+
<Route path="/docs/getting-started" element={<UsersDocs />} />
96+
<Route path="/redirect" element={<RedirectHandler />} />
9597
<Route path="/noredirect" element={<Noredirect />} />
9698
</Route>
9799
<Route path="*" element={<Error />} />

src/pages/RedirectHandler.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, { useEffect } from 'react';
2+
3+
const APP_ID = 'com.atlp.pulseapp';
4+
5+
export default function RedirectHandler() {
6+
const buildQueryString = (params: URLSearchParams) => {
7+
let queryParams = '?';
8+
const ignoredKeys = ['path', 'dest', 'fallback'];
9+
10+
params.forEach((value, key) => {
11+
if (ignoredKeys.includes(key)) return;
12+
13+
if (!queryParams?.endsWith('?') && !queryParams?.endsWith('&'))
14+
queryParams += '&';
15+
16+
queryParams += `${key}=${value}`;
17+
});
18+
19+
return queryParams;
20+
};
21+
22+
useEffect(() => {
23+
const params = new URLSearchParams(window.location.search);
24+
const queryParams = buildQueryString(params);
25+
const path = params.get('path');
26+
const destnation = params.get('dest');
27+
const fallback = params.get('fallback');
28+
29+
if (path != null) {
30+
if (destnation === 'web') {
31+
return window.location.replace(path + queryParams);
32+
}
33+
34+
if (destnation === 'app') {
35+
setTimeout(
36+
() =>
37+
window.location.replace(`${APP_ID }://${ path }${queryParams}`),
38+
100,
39+
);
40+
}
41+
42+
window.location.replace(fallback ? fallback + queryParams : '/');
43+
} else {
44+
// eslint-disable-next-line no-console
45+
console.error('Invalid redirect data');
46+
}
47+
48+
return () => {};
49+
}, []);
50+
51+
return (
52+
<div className=" dark:bg-dark-frame-bg flex flex-col py-8 px-5 items-center justify-center grow h-full w-full">
53+
<p>Redirecting...</p>
54+
</div>
55+
);
56+
}

0 commit comments

Comments
 (0)