-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
837 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,9 @@ [email protected] | |
OPENAI_API_KEY= | ||
OPENAI_BASE_URL= | ||
OPENAI_MODEL= | ||
|
||
# Subscriptions | ||
ZENOTE_SELF_HOSTED=true | ||
STRIPE_SECRET_KEY= | ||
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY= | ||
STRIPE_WEBHOOK_SECRET= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { env } from '@/env.mjs' | ||
import { getStripeServer } from '@/lib/stripe' | ||
import { db } from '@/server/db' | ||
import { users } from '@/server/db/schema' | ||
import { eq } from 'drizzle-orm' | ||
import { NextResponse } from 'next/server' | ||
import Stripe from 'stripe' | ||
|
||
export async function POST(req: Request) { | ||
if (!env.STRIPE_WEBHOOK_SECRET) | ||
return NextResponse.json( | ||
{ message: 'Stripe not configured' }, | ||
{ status: 500 } | ||
) | ||
const stripe = getStripeServer() | ||
if (!stripe) | ||
return NextResponse.json( | ||
{ message: 'Stripe not configured' }, | ||
{ status: 500 } | ||
) | ||
const body = await req.text() | ||
const sig = req.headers.get('stripe-signature') | ||
try { | ||
const event = stripe.webhooks.constructEvent( | ||
body, | ||
sig!, | ||
env.STRIPE_WEBHOOK_SECRET | ||
) | ||
if (!event) | ||
return NextResponse.json({ message: 'Invalid event' }, { status: 500 }) | ||
switch (event.type) { | ||
case 'customer.subscription.created': | ||
await db | ||
.update(users) | ||
.set({ | ||
subscriptionTier: 'standard', | ||
stripeId: String(event.data.object.customer) | ||
}) | ||
.where(eq(users.id, event.data.object.metadata.localId ?? '')) | ||
break | ||
case 'customer.subscription.deleted': | ||
await db | ||
.update(users) | ||
.set({ | ||
subscriptionTier: 'none' | ||
}) | ||
.where(eq(users.id, event.data.object.metadata.localId ?? '')) | ||
break | ||
case 'payment_intent.succeeded': | ||
await db | ||
.update(users) | ||
.set({ | ||
subscriptionTier: 'lifetime', | ||
stripeId: String(event.data.object.customer) | ||
}) | ||
.where(eq(users.id, event.data.object.metadata.localId ?? '')) | ||
break | ||
} | ||
return NextResponse.json({ ok: true }) | ||
} catch (error) { | ||
if (error instanceof Stripe.errors.StripeError) { | ||
const { message } = error | ||
return NextResponse.json({ message }, { status: error.statusCode }) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const ChannelSettingsPage = () => { | ||
return ( | ||
<div className="container flex max-w-[40rem] flex-col gap-4 py-8"> | ||
<h1>Settings</h1> | ||
</div> | ||
) | ||
} | ||
|
||
export default ChannelSettingsPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { SubscribePricing } from '@/components/subscribe/subscribe-pricing' | ||
import { api } from '@/trpc/server' | ||
|
||
const SubscribePage = async () => { | ||
const { data: priceList } = await api.subscriptions.prices.query() | ||
return ( | ||
<div className="flex flex-1 items-center justify-center"> | ||
<SubscribePricing priceList={priceList} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default SubscribePage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { ProfileForm } from "@/components/profile/profile-form" | ||
import { api } from "@/trpc/server" | ||
import { ProfileForm } from '@/components/profile/profile-form' | ||
import { api } from '@/trpc/server' | ||
|
||
const ProfilePage = async () => { | ||
const user = await api.users.me.query() | ||
if (!user) return null | ||
return ( | ||
<div className="container flex flex-col max-w-[40rem] gap-4 py-8"> | ||
<ProfileForm user={user} /> | ||
</div> | ||
) | ||
const user = await api.users.me.query() | ||
if (!user) return null | ||
return ( | ||
<div className="container flex max-w-[40rem] flex-col gap-4 py-8"> | ||
<ProfileForm user={user} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default ProfilePage | ||
export default ProfilePage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use client' | ||
|
||
import { useAppStore } from '@/store/app' | ||
import { ConfirmationDialog } from '../confirmation-dialog' | ||
import { api } from '@/trpc/react' | ||
import { useRouter } from 'next/navigation' | ||
|
||
export const ChannelDeleteDialog = () => { | ||
const router = useRouter() | ||
const { mutateAsync: deleteChannel } = api.channels.delete.useMutation() | ||
const deletingChannelId = useAppStore((state) => state.deletingChannelId) | ||
const setDeletingChannelId = useAppStore( | ||
(state) => state.setDeletingChannelId | ||
) | ||
return ( | ||
<ConfirmationDialog | ||
title="Are you absolutely sure?" | ||
description="This action will delete this channel and all its notes." | ||
onConfirm={async () => { | ||
await deleteChannel({ id: deletingChannelId ?? '' }) | ||
router.push('/channels') | ||
router.refresh() | ||
}} | ||
open={!!deletingChannelId} | ||
setOpen={(nextValue) => nextValue === false && setDeletingChannelId(null)} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use client' | ||
|
||
import { MoreVerticalIcon, Edit2Icon, TrashIcon } from 'lucide-react' | ||
import { Button } from '../ui/button' | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger | ||
} from '../ui/dropdown-menu' | ||
import { useAppStore } from '@/store/app' | ||
import { ChannelProps } from '@/lib/types' | ||
import { cn } from '@/lib/utils' | ||
import { useRouter } from 'next/navigation' | ||
|
||
export const ChannelMenu = ({ | ||
channel, | ||
hidding = true | ||
}: { | ||
channel: ChannelProps | ||
hidding?: boolean | ||
}) => { | ||
const router = useRouter() | ||
const setDeletingChannelId = useAppStore( | ||
(state) => state.setDeletingChannelId | ||
) | ||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button | ||
variant="ghost" | ||
size="sm" | ||
className={cn( | ||
'transition-opacity group-hover:opacity-100', | ||
hidding && 'opacity-0' | ||
)} | ||
> | ||
<MoreVerticalIcon size={16} /> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent side="bottom"> | ||
<DropdownMenuItem | ||
className="gap-2" | ||
onClick={() => router.push(`/channels/${channel.id}/settings`)} | ||
> | ||
<Edit2Icon size={16} /> | ||
<span>Edit</span> | ||
</DropdownMenuItem> | ||
<DropdownMenuItem | ||
className="cursor-pointer gap-2 text-red-700 dark:text-red-500" | ||
onClick={() => setDeletingChannelId(channel.id)} | ||
> | ||
<TrashIcon size={16} /> | ||
<span>Delete</span> | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
) | ||
} |
Oops, something went wrong.