Refactor Supabase type imports for improved clarity
Replaced specific object paths with generic type helpers across several files to enhance readability and maintainability. This change standardizes the import patterns and type definitions for database tables and enums.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { BadgeCheck } from 'lucide-react';
|
||||
|
||||
import { BillingConfig, getProductPlanPairByVariantId } from '@kit/billing';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
@@ -14,8 +14,8 @@ import { Trans } from '@kit/ui/trans';
|
||||
import { CurrentPlanBadge } from './current-plan-badge';
|
||||
import { LineItemDetails } from './line-item-details';
|
||||
|
||||
type Order = Database['public']['Tables']['orders']['Row'];
|
||||
type LineItem = Database['public']['Tables']['order_items']['Row'];
|
||||
type Order = Tables<'orders'>
|
||||
type LineItem = Tables<'order_items'>;
|
||||
|
||||
interface Props {
|
||||
order: Order & {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Enums } from '@kit/supabase/database';
|
||||
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
export function CurrentPlanAlert(
|
||||
props: React.PropsWithoutRef<{
|
||||
status: Database['public']['Enums']['subscription_status'];
|
||||
status: Enums<'subscription_status'>
|
||||
}>,
|
||||
) {
|
||||
let variant: 'success' | 'warning' | 'destructive';
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Enums } from '@kit/supabase/database';
|
||||
import { Badge } from '@kit/ui/badge';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
type Status =
|
||||
| Database['public']['Enums']['subscription_status']
|
||||
| Database['public']['Enums']['payment_status'];
|
||||
type Status = Enums<'subscription_status'> | Enums<'payment_status'>;
|
||||
|
||||
export function CurrentPlanBadge(
|
||||
props: React.PropsWithoutRef<{
|
||||
|
||||
@@ -2,7 +2,7 @@ import { formatDate } from 'date-fns';
|
||||
import { BadgeCheck } from 'lucide-react';
|
||||
|
||||
import { BillingConfig, getProductPlanPairByVariantId } from '@kit/billing';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
||||
import {
|
||||
Card,
|
||||
@@ -18,8 +18,8 @@ import { CurrentPlanAlert } from './current-plan-alert';
|
||||
import { CurrentPlanBadge } from './current-plan-badge';
|
||||
import { LineItemDetails } from './line-item-details';
|
||||
|
||||
type Subscription = Database['public']['Tables']['subscriptions']['Row'];
|
||||
type LineItem = Database['public']['Tables']['subscription_items']['Row'];
|
||||
type Subscription = Tables<'subscriptions'>;
|
||||
type LineItem = Tables<'subscription_items'>;
|
||||
|
||||
interface Props {
|
||||
subscription: Subscription & {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Suspense, forwardRef, lazy, memo, useMemo } from 'react';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Enums } from '@kit/supabase/database';
|
||||
import { LoadingOverlay } from '@kit/ui/loading-overlay';
|
||||
|
||||
type BillingProvider = Database['public']['Enums']['billing_provider'];
|
||||
type BillingProvider = Enums<'billing_provider'>;
|
||||
|
||||
const Fallback = <LoadingOverlay fullPage={false} />;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'server-only';
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { BillingConfig } from '@kit/billing';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Database, Enums } from '@kit/supabase/database';
|
||||
|
||||
import { BillingEventHandlerFactoryService } from './billing-event-handler-factory.service';
|
||||
import { createBillingEventHandlerService } from './billing-event-handler.service';
|
||||
@@ -12,7 +12,7 @@ import { createBillingEventHandlerService } from './billing-event-handler.servic
|
||||
type ClientProvider = () => SupabaseClient<Database>;
|
||||
|
||||
// the billing provider from the database
|
||||
type BillingProvider = Database['public']['Enums']['billing_provider'];
|
||||
type BillingProvider = Enums<'billing_provider'>;
|
||||
|
||||
/**
|
||||
* @name getBillingEventHandlerService
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import 'server-only';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
|
||||
import { createBillingGatewayService } from '../billing-gateway/billing-gateway.service';
|
||||
|
||||
type Subscription = Database['public']['Tables']['subscriptions']['Row'];
|
||||
type Subscription = Tables<'subscriptions'>
|
||||
|
||||
export function createBillingWebhooksService() {
|
||||
return new BillingWebhooksService();
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
|
||||
import { BillingConfig, BillingWebhookHandlerService } from '@kit/billing';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Database, Enums } from '@kit/supabase/database';
|
||||
|
||||
import { getLemonSqueezyEnv } from '../schema/lemon-squeezy-server-env.schema';
|
||||
import { OrderWebhook } from '../types/order-webhook';
|
||||
@@ -24,6 +24,8 @@ type UpsertSubscriptionParams =
|
||||
type UpsertOrderParams =
|
||||
Database['public']['Functions']['upsert_order']['Args'];
|
||||
|
||||
type BillingProvider = Enums<'billing_provider'>;
|
||||
|
||||
interface LineItem {
|
||||
id: string;
|
||||
quantity: number;
|
||||
@@ -42,8 +44,7 @@ type OrderStatus = 'pending' | 'failed' | 'paid' | 'refunded';
|
||||
export class LemonSqueezyWebhookHandlerService
|
||||
implements BillingWebhookHandlerService
|
||||
{
|
||||
private readonly provider: Database['public']['Enums']['billing_provider'] =
|
||||
'lemon-squeezy';
|
||||
private readonly provider: BillingProvider = 'lemon-squeezy';
|
||||
|
||||
private readonly namespace = 'billing.lemon-squeezy';
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import Stripe from 'stripe';
|
||||
|
||||
import { BillingConfig, BillingWebhookHandlerService } from '@kit/billing';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Database, Enums } from '@kit/supabase/database';
|
||||
|
||||
import { StripeServerEnvSchema } from '../schema/stripe-server-env.schema';
|
||||
import { createStripeClient } from './stripe-sdk';
|
||||
@@ -29,6 +29,8 @@ interface LineItem {
|
||||
type UpsertOrderParams =
|
||||
Database['public']['Functions']['upsert_order']['Args'];
|
||||
|
||||
type BillingProvider = Enums<'billing_provider'>;
|
||||
|
||||
export class StripeWebhookHandlerService
|
||||
implements BillingWebhookHandlerService
|
||||
{
|
||||
@@ -36,7 +38,7 @@ export class StripeWebhookHandlerService
|
||||
|
||||
constructor(private readonly config: BillingConfig) {}
|
||||
|
||||
private readonly provider: Database['public']['Enums']['billing_provider'] =
|
||||
private readonly provider: BillingProvider =
|
||||
'stripe';
|
||||
|
||||
private readonly namespace = 'billing.stripe';
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
VenetianMask,
|
||||
} from 'lucide-react';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
||||
import { AppBreadcrumbs } from '@kit/ui/app-breadcrumbs';
|
||||
@@ -32,9 +32,8 @@ import { AdminMembersTable } from './admin-members-table';
|
||||
import { AdminMembershipsTable } from './admin-memberships-table';
|
||||
import { AdminReactivateUserDialog } from './admin-reactivate-user-dialog';
|
||||
|
||||
type Db = Database['public']['Tables'];
|
||||
type Account = Db['accounts']['Row'];
|
||||
type Membership = Db['accounts_memberships']['Row'];
|
||||
type Account = Tables<'accounts'>;
|
||||
type Membership = Tables<'accounts_memberships'>;
|
||||
|
||||
export function AdminAccountPage(props: {
|
||||
account: Account & { memberships: Membership[] };
|
||||
|
||||
@@ -4,16 +4,15 @@ import Link from 'next/link';
|
||||
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
import { DataTable } from '@kit/ui/enhanced-data-table';
|
||||
|
||||
type Membership =
|
||||
Database['public']['Tables']['accounts_memberships']['Row'] & {
|
||||
type Membership = Tables<'accounts_memberships'> & {
|
||||
account: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export function AdminMembershipsTable(props: { memberships: Membership[] }) {
|
||||
return <DataTable data={props.memberships} columns={getColumns()} />;
|
||||
|
||||
Reference in New Issue
Block a user