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

feat(onboarding): add onboarding dialog #25

Merged
merged 19 commits into from
Jan 17, 2024
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
3 changes: 2 additions & 1 deletion apps/web/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ DATABASE_URL="postgres://postgres.[YOUR-PROJECT-ID]:[YOUR-PASSWORD]@aws-0-[REGIO

# Supabase config
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_KEY=your_supabase_service_key
26 changes: 26 additions & 0 deletions apps/web/app/[locale]/(app)/dashboard/onboarding/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { OnboardingDialog } from '@/components/onboarding/onboarding-dialog';
import { prisma } from '@/lib/server/prisma';
import { getSupabaseServerComponentClient } from '@/lib/server/supabase';
import { pick } from 'lodash';
import { NextIntlClientProvider } from 'next-intl';
import { getMessages } from 'next-intl/server';
import { redirect } from 'next/navigation';

export default async function OnboardingPage() {
const { user } = await getSupabaseServerComponentClient();
if (!user) return redirect('/login');

const result = await prisma.organization.findFirst({
where: { members: { some: { id: user.id } } },
});

if (result) return redirect(`/dashboard/${result.slug}`);

const messages = (await getMessages()) as IntlMessages;

return (
<NextIntlClientProvider messages={pick(messages, 'OnboardingDialog')}>
<OnboardingDialog />
</NextIntlClientProvider>
);
}
3 changes: 1 addition & 2 deletions apps/web/app/[locale]/(app)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ export default async function DashboardRootRedirect() {

if (result) return redirect(`/dashboard/${result.slug}`);

// TODO: Redirect to onboarding
return undefined;
return redirect('/dashboard/onboarding');
}
37 changes: 37 additions & 0 deletions apps/web/app/api/organization/create/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { prisma } from '@/lib/server/prisma';
import { getSupabaseRouteHandlerClient } from '@/lib/server/supabase';
import { NextRequest } from 'next/server';

export async function POST(request: NextRequest) {
const data = await request.json();
const { name, slug, avatar } = data as {
name: string;
slug: string;
avatar: string;
};

const { user } = await getSupabaseRouteHandlerClient();
if (!user) {
return Response.json({ error: 'Not authenticated' }, { status: 401 });
}

const createdOrg = await prisma.organization.create({
data: {
name,
slug,
logo: avatar,
members: {
connect: [{ id: user.id }],
},
},
});

if (!createdOrg) {
return Response.json(
{ error: 'Unable to create organization', created: false },
{ status: 500 }
);
}

return Response.json({ error: null, created: true }, { status: 201 });
}
34 changes: 34 additions & 0 deletions apps/web/app/api/organization/find/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { prisma } from '@/lib/server/prisma';
import { getSupabaseRouteHandlerClient } from '@/lib/server/supabase';
import { NextRequest } from 'next/server';

export async function GET(request: NextRequest) {
const slug = request.nextUrl.searchParams.get('org');

if (!slug) {
return Response.json(
{ error: 'No organization slug specified' },
{ status: 422 }
);
}

const { user } = await getSupabaseRouteHandlerClient();
if (!user) {
return Response.json({ error: 'Not authenticated' }, { status: 401 });
}

const org = await prisma.organization.findUnique({
where: {
slug: slug,
},
});

if (!org) {
return Response.json(
{ error: 'No organization found', found: false },
{ status: 404 }
);
}

return Response.json({ error: null, found: true }, { status: 200 });
}
33 changes: 33 additions & 0 deletions apps/web/app/api/profile/update/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { prisma } from '@/lib/server/prisma';
import { getSupabaseRouteHandlerClient } from '@/lib/server/supabase';
import { NextRequest } from 'next/server';

export async function PUT(request: NextRequest) {
const data = await request.json();
const { firstName, lastName } = data as {
firstName: string;
lastName: string;
};

const { user } = await getSupabaseRouteHandlerClient();
if (!user) {
return Response.json({ error: 'Not authenticated' }, { status: 401 });
}

const updatedUser = await prisma.profile.update({
where: { id: user.id },
data: {
firstName,
lastName,
},
});

if (!updatedUser) {
return Response.json(
{ error: 'Unable to update user', updated: false },
{ status: 500 }
);
}

return Response.json({ error: null, updated: true }, { status: 200 });
}
Loading