Skip to content

Commit

Permalink
refactoring: move onboarding UI from app layout to new /app/onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
flsilva committed Nov 14, 2023
1 parent 8c34a9e commit bcdca50
Show file tree
Hide file tree
Showing 8 changed files with 753 additions and 422 deletions.
2 changes: 0 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const nextConfig = {
};

const withPWA = require("@ducanh2912/next-pwa").default({
aggressiveFrontEndNavCaching: true,
cacheOnFrontEndNav: true,
dest: "public",
});

Expand Down
1,117 changes: 722 additions & 395 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app/(marketing)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async function MarketingLayout({ children }: { children: React.Re
data: { session },
} = await supabase.auth.getSession();

if (session) redirect('/app/today');
if (session) redirect('/app/onboarding');
/**/

return (
Expand Down
25 changes: 4 additions & 21 deletions src/app/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { redirect } from 'next/navigation';
import Link from 'next/link';
import { twMerge } from 'tailwind-merge';
import { buttonGreenClassName } from '@/modules/shared/controls/button/buttonClassName';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { Header } from '@/modules/app/shared/Header';
import { MainMenu } from '@/modules/app/shared/main-menu/MainMenu';
import { InstallPwaDialog } from '@/modules/shared/pwa/InstallPwaDialog';
import { getProjects } from '@/modules/app/projects/ProjectsRepository';
import { UserProvider } from '@/modules/app/users/UserProvider';
import { UpdateUserTimeZone } from '@/modules/app/users/UpdateUserTimeZone';
import { getUser, UserDto } from '@/modules/app/users/UsersRepository';
Expand All @@ -18,14 +13,16 @@ export default async function AppLayout({
children: React.ReactNode;
dialog: React.ReactNode;
}) {
/*
* Redirect to sign-in if user is not signed in.
*/
let user: UserDto;
try {
user = await getUser();
} catch {
redirect('/auth/sign-in');
}

const { data: projects, errors } = await getProjects();
/**/

return (
<UserProvider user={user}>
Expand All @@ -40,20 +37,6 @@ export default async function AppLayout({
<div className="pb-16">
{children}
{dialog}
{errors && <ErrorList errors={errors} />}
{!errors && (!projects || projects.length === 0) && (
<>
<p className="mt-4 text-sm font-medium text-gray-600">
You don&#39;t have any projects yet.
</p>
<Link
href="/app/projects/new"
className={twMerge(buttonGreenClassName, 'w-fit mt-6')}
>
Create your first!
</Link>
</>
)}
</div>
</div>
</div>
Expand Down
23 changes: 23 additions & 0 deletions src/app/app/onboarding/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'server-only';
import Link from 'next/link';
import { redirect } from 'next/navigation';
import { twMerge } from 'tailwind-merge';
import { buttonGreenClassName } from '@/modules/shared/controls/button/buttonClassName';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { getProjects } from '@/modules/app/projects/ProjectsRepository';

export default async function Onboarding() {
const { data: projects, errors } = await getProjects();
if (errors) return <ErrorList errors={errors} />;
if (projects && projects.length > 0) redirect('/app/today');

return (
<>
<h2 className="mt-4 text-2xl">Welcome!</h2>
<p className="mt-8 text-sm font-medium">You don&#39;t have any projects yet.</p>
<Link href="/app/projects/new" className={twMerge(buttonGreenClassName, 'w-fit mt-8')}>
Create your first!
</Link>
</>
);
}
2 changes: 1 addition & 1 deletion src/app/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import 'server-only';
import { redirect } from 'next/navigation';

export default function AppPage() {
redirect('/app/today');
redirect('/app/onboarding');
}
2 changes: 1 addition & 1 deletion src/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export async function GET(request: NextRequest) {
}

// URL to redirect to after sign in process completes
return NextResponse.redirect(`${requestUrl.origin}/app/today`);
return NextResponse.redirect(`${requestUrl.origin}/app/onboarding`);
}
2 changes: 1 addition & 1 deletion src/app/auth/sign-in/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default async function SignInPage() {
data: { session },
} = await supabase.auth.getSession();

if (session) redirect('/app/today');
if (session) redirect('/app/onboarding');
/**/

const baseUrl = process.env.NEXT_PUBLIC_URL;
Expand Down

0 comments on commit bcdca50

Please sign in to comment.