Skip to content

Commit 9f8dbc4

Browse files
committed
fix: redirection handler
1 parent deee499 commit 9f8dbc4

File tree

4 files changed

+84
-18
lines changed

4 files changed

+84
-18
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/Organization/UserRegister.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/* eslint-disable */
2-
import { useApolloClient, useLazyQuery, useMutation } from '@apollo/client';
3-
import React, { useContext, useState, useEffect } from 'react';
2+
import { useLazyQuery, useMutation } from '@apollo/client';
3+
import React, { useContext, useEffect, useState } from 'react';
44
import { useForm } from 'react-hook-form';
55

6+
import jwt_decode from 'jwt-decode';
67
import { useTranslation } from 'react-i18next';
7-
import { FaGoogle, FaRegEnvelope, FaRegEye } from 'react-icons/fa';
8+
import { FaRegEnvelope, FaRegEye } from 'react-icons/fa';
89
import { FiEyeOff } from 'react-icons/fi';
910
import { MdLockOutline } from 'react-icons/md';
1011
import { Link, useLocation, useNavigate } from 'react-router-dom';
1112
import { toast } from 'react-toastify';
1213
import ButtonLoading from '../../components/ButtonLoading';
1314
import Button from '../../components/Buttons';
15+
import ControlledSelect from '../../components/ControlledSelect';
1416
import { UserContext } from '../../hook/useAuth';
1517
import useDocumentTitle from '../../hook/useDocumentTitle';
16-
import { SIGN_UP_MUTATION, GET_SIGNUP_ORGANIZATION } from './Mutations';
17-
import ControlledSelect from '../../components/ControlledSelect';
18-
import jwt_decode from 'jwt-decode';
18+
import { GET_SIGNUP_ORGANIZATION, SIGN_UP_MUTATION } from './Mutations';
1919

2020
const Signup = () => {
2121
const token: any = window.location.href.substring(

src/pages/RedirectHandler.tsx

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

0 commit comments

Comments
 (0)