Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make v3 room links backwards compatible #5107

Merged
merged 3 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions app/javascript/RootBoundary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,18 @@
// with Greenlight; if not, see <http://www.gnu.org/licenses/>.

import React from 'react';
import { isRouteErrorResponse, useRouteError } from 'react-router-dom';
import { useRouteError } from 'react-router-dom';
import DefaultErrorPage from './components/errors/DefaultErrorPage';
import NotFoundPage from './components/errors/NotFoundPage';

export default function RootBoundary() {
const error = useRouteError();
const status = error?.response?.status || error?.status;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done


if (isRouteErrorResponse(error)) {
// Route Errors
switch (error.status) {
case 404:
return <NotFoundPage />;
default:
return <DefaultErrorPage />;
}
} else {
// Non-Route Errors (hooks, promises, etc.)
switch (error.response.status) {
case 404:
return <NotFoundPage />;
default:
return <DefaultErrorPage />;
}
switch (status) {
case 404:
return <NotFoundPage />;
default:
return <DefaultErrorPage />;
}
}
2 changes: 2 additions & 0 deletions app/javascript/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import AuthenticatedOnly from './routes/AuthenticatedOnly';
import PendingRegistration from './components/users/registration/PendingRegistration';
import RootBoundary from './RootBoundary';
import Tenants from './components/admin/tenants/Tenants';
import RoomIdRouter from './routes/RoomIdRouter';

const queryClientConfig = {
defaultOptions: {
Expand Down Expand Up @@ -100,6 +101,7 @@ const router = createBrowserRouter(
</Route>

<Route path="/rooms/:friendlyId/join" element={<RoomJoin />} />
<Route path="/:roomId" element={<RoomIdRouter />} />
</Route>,
),
{ basename: process.env.RELATIVE_URL_ROOT },
Expand Down
30 changes: 30 additions & 0 deletions app/javascript/routes/RoomIdRouter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
//
// Copyright (c) 2022 BigBlueButton Inc. and by respective authors (see below).
//
// This program is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the Free Software
// Foundation; either version 3.0 of the License, or (at your option) any later
// version.
//
// Greenlight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along
// with Greenlight; if not, see <http://www.gnu.org/licenses/>.

import React from 'react';
import { Navigate, useParams } from 'react-router-dom';

export default function RoomIdRouter() {
const { roomId } = useParams();
const regex = /(\w{3}-\w{3}-\w{3})(-\w{3})?/;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catches either 123-123-123-123 or 123-123-123

const match = roomId.match(regex);

if (match) {
return <Navigate to={`/rooms/${roomId}/join`} />;
}

throw new Response('Not Found', { status: 404 });
}