From 9010f0d5943fccb7cec51aecbd4c1ee33703f26e Mon Sep 17 00:00:00 2001 From: Alan Alickovic Date: Wed, 30 Oct 2024 23:00:34 +0100 Subject: [PATCH] Improvements (#220) --- apps/nextjs-app/e2e/tests/auth.setup.ts | 2 +- apps/nextjs-app/src/app/auth/layout.tsx | 18 +++- apps/nextjs-app/src/app/auth/login/page.tsx | 5 +- .../nextjs-app/src/app/auth/register/page.tsx | 5 +- apps/nextjs-app/src/app/not-found.tsx | 3 +- apps/nextjs-app/src/app/page.tsx | 9 +- .../src/components/layouts/auth-layout.tsx | 65 +++++++------- .../components/layouts/dashboard-layout.tsx | 11 +-- apps/nextjs-app/src/config/paths.ts | 42 +++++++++ .../features/auth/components/login-form.tsx | 3 +- .../auth/components/register-form.tsx | 3 +- .../components/discussion-view.tsx | 3 +- .../components/discussions-list.tsx | 3 +- apps/nextjs-app/src/lib/auth.tsx | 9 +- apps/nextjs-app/src/lib/authorization.tsx | 3 +- .../nextjs-pages/src/app/pages/auth/login.tsx | 5 +- .../src/app/pages/auth/register.tsx | 5 +- .../src/components/layouts/auth-layout.tsx | 8 +- .../components/layouts/dashboard-layout.tsx | 11 +-- apps/nextjs-pages/src/config/paths.ts | 42 +++++++++ .../features/auth/components/login-form.tsx | 3 +- .../auth/components/register-form.tsx | 3 +- .../components/discussion-view.tsx | 3 +- .../components/discussions-list.tsx | 3 +- apps/nextjs-pages/src/lib/api-client.ts | 10 +-- apps/nextjs-pages/src/lib/auth.tsx | 5 +- apps/nextjs-pages/src/pages/404.tsx | 3 +- apps/nextjs-pages/src/pages/index.tsx | 5 +- apps/react-vite/src/app/router.tsx | 87 ++++++++++--------- apps/react-vite/src/app/routes/app/root.tsx | 25 ++---- apps/react-vite/src/app/routes/auth/login.tsx | 14 +-- .../src/app/routes/auth/register.tsx | 14 +-- apps/react-vite/src/app/routes/landing.tsx | 5 +- apps/react-vite/src/app/routes/not-found.tsx | 3 +- .../src/components/layouts/auth-layout.tsx | 14 ++- .../components/layouts/dashboard-layout.tsx | 11 +-- apps/react-vite/src/config/paths.ts | 46 ++++++++++ .../features/auth/components/login-form.tsx | 3 +- .../auth/components/register-form.tsx | 3 +- .../components/discussions-list.tsx | 3 +- apps/react-vite/src/lib/api-client.ts | 6 +- apps/react-vite/src/lib/auth.tsx | 10 ++- 42 files changed, 359 insertions(+), 175 deletions(-) create mode 100644 apps/nextjs-app/src/config/paths.ts create mode 100644 apps/nextjs-pages/src/config/paths.ts create mode 100644 apps/react-vite/src/config/paths.ts diff --git a/apps/nextjs-app/e2e/tests/auth.setup.ts b/apps/nextjs-app/e2e/tests/auth.setup.ts index 1117cc38..187d10c9 100644 --- a/apps/nextjs-app/e2e/tests/auth.setup.ts +++ b/apps/nextjs-app/e2e/tests/auth.setup.ts @@ -28,7 +28,7 @@ setup('authenticate', async ({ page }) => { // log out: await page.getByRole('button', { name: 'Open user menu' }).click(); await page.getByRole('menuitem', { name: 'Sign Out' }).click(); - await page.waitForURL('/auth/login?redirectTo=%2Fapp'); + await page.waitForURL('/auth/login?redirectTo=%252Fapp'); // log in: await page.getByLabel('Email Address').click(); diff --git a/apps/nextjs-app/src/app/auth/layout.tsx b/apps/nextjs-app/src/app/auth/layout.tsx index 28a5c00f..6ee7609b 100644 --- a/apps/nextjs-app/src/app/auth/layout.tsx +++ b/apps/nextjs-app/src/app/auth/layout.tsx @@ -1,6 +1,8 @@ -import { ReactNode } from 'react'; +import { ReactNode, Suspense } from 'react'; +import { ErrorBoundary } from 'react-error-boundary'; import { AuthLayout as AuthLayoutComponent } from '@/components/layouts/auth-layout'; +import { Spinner } from '@/components/ui/spinner'; export const metadata = { title: 'Bulletproof React', @@ -8,7 +10,19 @@ export const metadata = { }; const AuthLayout = ({ children }: { children: ReactNode }) => { - return {children}; + return ( + + + + } + > + Something went wrong!}> + {children} + + + ); }; export default AuthLayout; diff --git a/apps/nextjs-app/src/app/auth/login/page.tsx b/apps/nextjs-app/src/app/auth/login/page.tsx index b779aef0..fcdfff01 100644 --- a/apps/nextjs-app/src/app/auth/login/page.tsx +++ b/apps/nextjs-app/src/app/auth/login/page.tsx @@ -2,6 +2,7 @@ import { useRouter, useSearchParams } from 'next/navigation'; +import { paths } from '@/config/paths'; import { LoginForm } from '@/features/auth/components/login-form'; // export const metadata = { @@ -17,7 +18,9 @@ const LoginPage = () => { return ( - router.replace(`${redirectTo ? `${redirectTo}` : '/app'}`) + router.replace( + `${redirectTo ? `${decodeURIComponent(redirectTo)}` : paths.app.dashboard.getHref()}`, + ) } /> ); diff --git a/apps/nextjs-app/src/app/auth/register/page.tsx b/apps/nextjs-app/src/app/auth/register/page.tsx index 87ca70fd..aed4c1cb 100644 --- a/apps/nextjs-app/src/app/auth/register/page.tsx +++ b/apps/nextjs-app/src/app/auth/register/page.tsx @@ -3,6 +3,7 @@ import { useRouter, useSearchParams } from 'next/navigation'; import { useState } from 'react'; +import { paths } from '@/config/paths'; import { RegisterForm } from '@/features/auth/components/register-form'; import { useTeams } from '@/features/teams/api/get-teams'; @@ -28,7 +29,9 @@ const RegisterPage = () => { return ( - router.replace(`${redirectTo ? `${redirectTo}` : '/app'}`) + router.replace( + `${redirectTo ? `${decodeURIComponent(redirectTo)}` : paths.app.dashboard.getHref()}`, + ) } chooseTeam={chooseTeam} setChooseTeam={() => setChooseTeam(!chooseTeam)} diff --git a/apps/nextjs-app/src/app/not-found.tsx b/apps/nextjs-app/src/app/not-found.tsx index 2aa724ad..6f3ae4e6 100644 --- a/apps/nextjs-app/src/app/not-found.tsx +++ b/apps/nextjs-app/src/app/not-found.tsx @@ -1,11 +1,12 @@ import { Link } from '@/components/ui/link'; +import { paths } from '@/config/paths'; const NotFoundPage = () => { return (

404 - Not Found

Sorry, the page you are looking for does not exist.

- + Go to Home
diff --git a/apps/nextjs-app/src/app/page.tsx b/apps/nextjs-app/src/app/page.tsx index 3276a41b..2d7d0051 100644 --- a/apps/nextjs-app/src/app/page.tsx +++ b/apps/nextjs-app/src/app/page.tsx @@ -1,5 +1,6 @@ import { Button } from '@/components/ui/button'; import { Link } from '@/components/ui/link'; +import { paths } from '@/config/paths'; import { checkLoggedIn } from '@/utils/auth'; const HomePage = () => { @@ -15,7 +16,13 @@ const HomePage = () => {

Showcasing Best Practices For Building React Applications

- +