refactor: reorganize credit transaction types and update imports

- Moved CREDIT_TRANSACTION_TYPE from constants to a new types.ts file for better modularity.
- Updated import paths in credit-related components to reflect the new structure.
- Removed the old CREDIT_TRANSACTION_TYPE definition from constants.ts to streamline the codebase.
This commit is contained in:
javayhu 2025-07-06 23:25:38 +08:00
parent 04c2b2d7ee
commit 0af0aa3b09
5 changed files with 14 additions and 11 deletions

View File

@ -54,7 +54,7 @@ import { useState } from 'react';
import { toast } from 'sonner';
import { Badge } from '../../ui/badge';
import { Label } from '../../ui/label';
import { CREDIT_TRANSACTION_TYPE } from '@/lib/constants';
import { CREDIT_TRANSACTION_TYPE } from '@/credits/types';
// Define the credit transaction interface
interface CreditTransaction {

View File

@ -5,10 +5,10 @@ import { addDays, isAfter } from 'date-fns';
import { and, asc, eq, or } from 'drizzle-orm';
import {
CREDIT_EXPIRE_DAYS,
CREDIT_TRANSACTION_TYPE,
FREE_MONTHLY_CREDITS,
REGISTER_GIFT_CREDITS,
} from '../lib/constants';
import { CREDIT_TRANSACTION_TYPE } from './types';
/**
* Get user's current credit balance

10
src/credits/types.ts Normal file
View File

@ -0,0 +1,10 @@
/**
* Credit transaction type enum
*/
export enum CREDIT_TRANSACTION_TYPE {
MONTHLY_REFRESH = 'MONTHLY_REFRESH', // credits earned by monthly refresh
REGISTER_GIFT = 'REGISTER_GIFT', // credits earned by register gift
PURCHASE = 'PURCHASE', // credits earned by purchase
USAGE = 'USAGE', // credits spent by usage
EXPIRE = 'EXPIRE', // credits expired
}

View File

@ -42,11 +42,4 @@ export const REGISTER_GIFT_CREDITS = 100;
// default credit expiration days
export const CREDIT_EXPIRE_DAYS = 30;
// credit transaction type
export const CREDIT_TRANSACTION_TYPE = {
MONTHLY_REFRESH: 'MONTHLY_REFRESH', // credits earned by monthly refresh
REGISTER_GIFT: 'REGISTER_GIFT', // credits earned by register gift
PURCHASE: 'PURCHASE', // credits earned by purchase
USAGE: 'USAGE', // credits spent by usage
EXPIRE: 'EXPIRE', // credits expired
};

View File

@ -8,7 +8,7 @@ import {
} from '@/lib/price-plan';
import { sendNotification } from '@/notification/notification';
import { addCredits } from '@/credits/credits';
import { CREDIT_TRANSACTION_TYPE } from '@/lib/constants';
import { CREDIT_TRANSACTION_TYPE } from '@/credits/types';
import { desc, eq } from 'drizzle-orm';
import { Stripe } from 'stripe';
import {