Skip to content

Commit

Permalink
add enterprise bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
psiddharthdesign committed Aug 20, 2024
1 parent 130be4a commit 767802d
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ async function OrganizationSubscriptionSidebarCard({
const isOrganizationAdmin = userRole === 'admin' || userRole === 'owner'

switch (normalizedSubscription.type) {
case 'bypassed_enterprise_organization':
return null;
case 'trialing':
return <FreeTrialComponent
organizationId={organizationId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,25 @@ export async function OrganizationSubscripionDetails({
const isOrganizationAdmin =
organizationRole === 'admin' || organizationRole === 'owner';



const subscriptionDetails = formatNormalizedSubscription(
normalizedSubscription,
);

if (normalizedSubscription.type === 'bypassed_enterprise_organization') {
return <Card>
<CardHeader>
<CardTitle>
Subscription
</CardTitle>
<CardDescription>
This organization is using the enterprise (demo) plan. Contact application administrator to modify subscription details.
</CardDescription>
</CardHeader>
</Card>;
}

if (
!subscriptionDetails.title ||
normalizedSubscription.type === 'no-subscription'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import {
getLoggedInUserOrganizationRole,
getNormalizedOrganizationSubscription,
getSlimOrganizationById,
getSlimOrganizationById
} from '@/data/user/organizations';
import { getSlimProjectById } from '@/data/user/projects';
import { getLoggedInUserTeamRole, getSlimTeamById } from '@/data/user/teams';
Expand All @@ -19,7 +18,6 @@ async function fetchData(projectId: string) {
projectByIdData.team_id
? getLoggedInUserTeamRole(projectByIdData.team_id)
: null,
getNormalizedOrganizationSubscription(projectByIdData.organization_id),
]);

return {
Expand Down
62 changes: 0 additions & 62 deletions src/components/SubscriptionCardSmall/SubscriptionCardSmall.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/SubscriptionCardSmall/index.ts

This file was deleted.

34 changes: 29 additions & 5 deletions src/data/user/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,34 @@ export const getNormalizedOrganizationSubscription = async (
organizationId: string,
): Promise<NormalizedSubscription> => {
const supabase = createSupabaseUserServerComponentClient();
const { data: subscriptions, error } = await supabase
.from('subscriptions')
.select('*, prices(*, products(*))')
.eq('organization_id', organizationId)
.in('status', ['trialing', 'active']);
const [organizationSubscriptionsResponse, byOrganizationsResponse] =
await Promise.all([
supabase
.from('subscriptions')
.select('*, prices(*, products(*))')
.eq('organization_id', organizationId)
.in('status', ['trialing', 'active']),
supabase
.from('billing_bypass_organizations')
.select('*')
.eq('id', organizationId)
.single(),
]);

const { data: bypassOrganizations, error: bypassOrganizationsError } =
byOrganizationsResponse;

if (bypassOrganizationsError) {
// ignore this is the likely case.
}

if (bypassOrganizations) {
return {
type: 'bypassed_enterprise_organization',
};
}

const { data: subscriptions, error } = organizationSubscriptionsResponse;

if (error) {
throw error;
Expand Down Expand Up @@ -385,6 +408,7 @@ export const getActiveProductsWithPrices = async () => {
.select('*, prices(*)')
.eq('active', true)
.eq('prices.active', true)
.eq('is_visible_in_ui', true)
.order('unit_amount', { foreignTable: 'prices' });

if (error) {
Expand Down
26 changes: 26 additions & 0 deletions src/lib/database.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@ export type Database = {
},
]
}
billing_bypass_organizations: {
Row: {
created_at: string
id: string
}
Insert: {
created_at?: string
id: string
}
Update: {
created_at?: string
id?: string
}
Relationships: [
{
foreignKeyName: "billing_bypass_organizations_id_fkey"
columns: ["id"]
isOneToOne: true
referencedRelation: "organizations"
referencedColumns: ["id"]
},
]
}
chats: {
Row: {
created_at: string
Expand Down Expand Up @@ -1193,6 +1216,7 @@ export type Database = {
description: string | null
id: string
image: string | null
is_visible_in_ui: boolean
metadata: Json | null
name: string | null
}
Expand All @@ -1201,6 +1225,7 @@ export type Database = {
description?: string | null
id: string
image?: string | null
is_visible_in_ui?: boolean
metadata?: Json | null
name?: string | null
}
Expand All @@ -1209,6 +1234,7 @@ export type Database = {
description?: string | null
id?: string
image?: string | null
is_visible_in_ui?: boolean
metadata?: Json | null
name?: string | null
}
Expand Down
Loading

0 comments on commit 767802d

Please sign in to comment.