fix: add deleted user status filter (#5464)
This commit is contained in:
+5
-1
@@ -264,7 +264,11 @@ func SearchUsers(keyword string, group string, role *int, status *int, startIdx
|
||||
query = query.Where("role = ?", *role)
|
||||
}
|
||||
if status != nil {
|
||||
query = query.Where("status = ?", *status)
|
||||
if *status == -1 {
|
||||
query = query.Where("deleted_at IS NOT NULL")
|
||||
} else {
|
||||
query = query.Where("deleted_at IS NULL").Where("status = ?", *status)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
|
||||
@@ -31,7 +31,12 @@ import { GroupBadge } from '@/components/group-badge'
|
||||
import { LongText } from '@/components/long-text'
|
||||
import { StatusBadge } from '@/components/status-badge'
|
||||
import { TableId } from '@/components/table-id'
|
||||
import { USER_STATUSES, USER_ROLES, isUserDeleted } from '../constants'
|
||||
import {
|
||||
USER_STATUS,
|
||||
USER_STATUSES,
|
||||
USER_ROLES,
|
||||
isUserDeleted,
|
||||
} from '../constants'
|
||||
import { type User } from '../types'
|
||||
import { DataTableRowActions } from './data-table-row-actions'
|
||||
|
||||
@@ -125,7 +130,7 @@ export function useUsersColumns(): ColumnDef<User>[] {
|
||||
const requestCount = user.request_count
|
||||
|
||||
const statusConfig = isUserDeleted(user)
|
||||
? USER_STATUSES.DELETED
|
||||
? USER_STATUSES[USER_STATUS.DELETED]
|
||||
: USER_STATUSES[user.status as keyof typeof USER_STATUSES]
|
||||
|
||||
if (!statusConfig) {
|
||||
|
||||
@@ -156,6 +156,7 @@ export function UsersTable() {
|
||||
onGlobalFilterChange,
|
||||
onColumnFiltersChange,
|
||||
manualPagination: true,
|
||||
manualFiltering: true,
|
||||
totalCount: data?.total || 0,
|
||||
ensurePageInRange,
|
||||
})
|
||||
|
||||
+4
-2
@@ -34,6 +34,7 @@ export const isUserDeleted = (user: UserType): boolean => {
|
||||
export const USER_STATUS = {
|
||||
ENABLED: 1,
|
||||
DISABLED: 2,
|
||||
DELETED: -1,
|
||||
} as const
|
||||
|
||||
export const USER_STATUSES = {
|
||||
@@ -47,16 +48,17 @@ export const USER_STATUSES = {
|
||||
variant: 'neutral' as const,
|
||||
value: USER_STATUS.DISABLED,
|
||||
},
|
||||
DELETED: {
|
||||
[USER_STATUS.DELETED]: {
|
||||
labelKey: 'Deleted',
|
||||
variant: 'danger' as const,
|
||||
value: -1,
|
||||
value: USER_STATUS.DELETED,
|
||||
},
|
||||
} as const
|
||||
|
||||
export const getUserStatusOptions = (t: (key: string) => string) => [
|
||||
{ label: t('Enabled'), value: String(USER_STATUS.ENABLED) },
|
||||
{ label: t('Disabled'), value: String(USER_STATUS.DISABLED) },
|
||||
{ label: t('Deleted'), value: String(USER_STATUS.DELETED) },
|
||||
]
|
||||
|
||||
// ============================================================================
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ const usersSearchSchema = z.object({
|
||||
pageSize: z.number().optional().catch(undefined),
|
||||
filter: z.string().optional().catch(''),
|
||||
status: z
|
||||
.array(z.enum(['1', '2']))
|
||||
.array(z.enum(['-1', '1', '2']))
|
||||
.optional()
|
||||
.catch([]),
|
||||
role: z
|
||||
|
||||
Reference in New Issue
Block a user