Przeglądaj źródła

feat: add subscription type in user crud

Mohammad Mahdi Salimi 1 tydzień temu
rodzic
commit
2b3dd4f9db

+ 7 - 0
src/constants/users/users-constants.ts

@@ -34,3 +34,10 @@ export const activityHistoryOptions = [
   { label: 'دارم', value: true },
   { label: 'ندارم', value: false },
 ]
+
+export const planDurations: Record<number, string> = {
+  1: '1 ماهه',
+  3: '3 ماهه',
+  6: '6 ماهه',
+  12: '12 ماهه',
+}

+ 18 - 3
src/features/users/components/users-columns.tsx

@@ -11,6 +11,7 @@ import { LongText } from '@/components/long-text'
 import { type User } from '@/types/users.types'
 
 import { DataTableRowActions } from './data-table-row-actions'
+import { planDurations } from '@/constants/users/users-constants'
 
 export const usersColumns: ColumnDef<User>[] = [
   {
@@ -88,13 +89,27 @@ export const usersColumns: ColumnDef<User>[] = [
     cell: ({ row }) => <div dir='ltr'>{row.original.phone}</div>,
   },
 
+  // {
+  //   accessorKey: 'email',
+  //   header: ({ column }) => (
+  //     <DataTableColumnHeader column={column} title='ایمیل' />
+  //   ),
+  //   cell: ({ row }) => (
+  //     <div className='text-nowrap'>{row.original.email ?? '-'}</div>
+  //   ),
+  // },
+
   {
-    accessorKey: 'email',
+    accessorKey: 'subscription',
     header: ({ column }) => (
-      <DataTableColumnHeader column={column} title='ایمیل' />
+      <DataTableColumnHeader column={column} title='اشتراک' />
     ),
     cell: ({ row }) => (
-      <div className='text-nowrap'>{row.original.email ?? '-'}</div>
+      <div className='text-nowrap'>
+        {row.original.subscription?.plan
+          ? `${row.original.subscription?.plan?.type} (${planDurations[row.original.subscription?.plan?.duration]})`
+          : '-'}
+      </div>
     ),
   },
 

+ 34 - 0
src/types/users.types.ts

@@ -30,6 +30,40 @@ export interface User {
   avatar?: Avatar
   created_at: string
   updated_at: string
+  subscription: Subscription | null
+}
+
+interface Subscription {
+  id: number
+  plan: Plan
+  status: string
+  price_paid: string
+  discount_price: string
+  started_at: string
+  expires_at: string
+  cancelled_at: null
+  payment_reference: null
+}
+
+interface Plan {
+  id: number
+  name: string
+  price: number
+  discount_price: number
+  duration: number
+  type: string
+  type_label: string
+  status: string
+  description: string
+  features: Feature[]
+  created_at: string
+  updated_at: string
+}
+
+interface Feature {
+  title: string
+  type: string
+  is_special: boolean
 }
 
 export interface UsersListMeta {