-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Partner network invite limits #2935
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
58f53a8
Misc. empty state improvements
TWilson023 0a3ea1c
DB/schema updates
TWilson023 3f87faf
Invite limits
TWilson023 a733ebc
Minor optimization
TWilson023 ac33e47
Misc. tweaks
TWilson023 7d5de96
Update network-partner-sheet.tsx
TWilson023 47ebbae
Merge branch 'main' into partner-network-invite-limit
steven-tey 8f32390
small update to lead openapi spec
steven-tey bffe343
fix getNetworkInvitesUsage
steven-tey 65b7687
fix invites usage tooltip
steven-tey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
apps/web/app/(ee)/api/network/partners/invites-usage/route.ts
This file contains hidden or 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,19 @@ | ||
| import { getNetworkInvitesUsage } from "@/lib/api/partners/get-network-invites-usage"; | ||
| import { withWorkspace } from "@/lib/auth"; | ||
| import { NextResponse } from "next/server"; | ||
|
|
||
| // GET /api/network/partners/invites-usage - get the usage and limits for partner network invitations | ||
| export const GET = withWorkspace( | ||
| async ({ workspace }) => { | ||
| const usage = await getNetworkInvitesUsage(workspace); | ||
|
|
||
| return NextResponse.json({ | ||
| usage, | ||
| limit: workspace.networkInvitesLimit, | ||
| remaining: Math.max(0, workspace.networkInvitesLimit - usage), | ||
| }); | ||
| }, | ||
| { | ||
| requiredPlan: ["enterprise"], | ||
| }, | ||
| ); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
3 changes: 2 additions & 1 deletion
3
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/network/page.tsx
This file contains hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| import { prisma } from "@dub/prisma"; | ||
| import { getBillingStartDate } from "@dub/utils"; | ||
| import { Project } from "@prisma/client"; | ||
|
|
||
| export async function getNetworkInvitesUsage( | ||
| workspace: Pick<Project, "id" | "billingCycleStart">, | ||
| ) { | ||
| const invites = await prisma.discoveredPartner.aggregate({ | ||
| _count: true, | ||
| where: { | ||
| program: { | ||
| workspaceId: workspace.id, | ||
| }, | ||
| invitedAt: { | ||
| gt: getBillingStartDate(workspace.billingCycleStart), | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| return invites._count; | ||
| } | ||
This file contains hidden or 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,34 @@ | ||
| import { fetcher } from "@dub/utils"; | ||
| import useSWR, { SWRConfiguration } from "swr"; | ||
| import useWorkspace from "./use-workspace"; | ||
|
|
||
| export default function usePartnerNetworkInvitesUsage({ | ||
| enabled, | ||
| swrOpts, | ||
| }: { | ||
| enabled?: boolean; | ||
| swrOpts?: SWRConfiguration; | ||
| } = {}) { | ||
| const { id: workspaceId } = useWorkspace(); | ||
|
|
||
| const { data, isLoading, error } = useSWR<{ | ||
| usage: number; | ||
| limit: number; | ||
| remaining: number; | ||
| }>( | ||
| workspaceId && | ||
| enabled !== false && | ||
| `/api/network/partners/invites-usage?workspaceId=${workspaceId}`, | ||
| fetcher, | ||
| { | ||
| keepPreviousData: true, | ||
| ...swrOpts, | ||
| }, | ||
| ); | ||
|
|
||
| return { | ||
| ...data, | ||
| isLoading, | ||
| error, | ||
| }; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,47 @@ | ||
| "use client"; | ||
|
|
||
| import usePartnerNetworkInvitesUsage from "@/lib/swr/use-partner-network-invites-usage"; | ||
| import { EnvelopeArrowRight, Tooltip } from "@dub/ui"; | ||
| import { cn } from "@dub/utils"; | ||
|
|
||
| export function InvitesUsage() { | ||
| const { remaining } = usePartnerNetworkInvitesUsage(); | ||
|
|
||
| return remaining === undefined ? null : ( | ||
| <Tooltip | ||
| content={ | ||
| <p className="max-w-xs p-2 text-center text-xs font-medium text-neutral-600"> | ||
| Invitation limits are reset at the start of your billing cycle. If you | ||
| need more invites,{" "} | ||
| <a | ||
| href="https://dub.co/contact/sales" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="underline" | ||
| > | ||
| contact us | ||
| </a> | ||
| . | ||
| </p> | ||
| } | ||
| align="end" | ||
| > | ||
| <div className="animate-fade-in flex cursor-default items-center gap-2"> | ||
| <EnvelopeArrowRight className="text-content-default size-4 shrink-0" /> | ||
| <span | ||
| className={cn( | ||
| "text-content-emphasis text-sm font-medium", | ||
| remaining === 0 && "text-content-subtle", | ||
| )} | ||
| > | ||
| <span | ||
| className={cn(remaining > 0 && remaining <= 5 && "text-violet-600")} | ||
| > | ||
| {remaining} <span className="hidden sm:inline">invites</span> | ||
| </span>{" "} | ||
| remaining | ||
| </span> | ||
| </div> | ||
| </Tooltip> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.