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