260714_01_ENH: 테스트 서버에서 기동 후 중간 테스트를 위한 커밋
This commit is contained in:
101
src/components/assign/AssignTargetList.tsx
Normal file
101
src/components/assign/AssignTargetList.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
'use client'
|
||||
|
||||
import { useMemo } from 'react'
|
||||
import { useCmpnListQuery } from '@/query/cmpn'
|
||||
import { useFieldworkUsersQuery } from '@/query/user'
|
||||
import { useAssignedCmpnIdsQuery, useAssignedFieldworkIdsQuery } from '@/query/project'
|
||||
import { ListHeaderAssignConst } from '@/const/listConst'
|
||||
import { CONTACT_INTERVIEWER_ROLE, FIELD_INTERVIEWER_ROLE } from '@/const/userConst'
|
||||
import type { ListHeaderAssignType } from '@/types/list'
|
||||
|
||||
export type AssignTargetListProps = {
|
||||
prjctIdx: number
|
||||
enabled: boolean
|
||||
assignType: ListHeaderAssignType
|
||||
selectedId?: string
|
||||
onSelect: (id: string) => void
|
||||
}
|
||||
|
||||
export type AssignTargetRow = {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export type UseAssignTargetRowsArgs = {
|
||||
prjctIdx: number
|
||||
enabled: boolean
|
||||
assignType: ListHeaderAssignType
|
||||
}
|
||||
|
||||
export function useAssignTargetRows({ prjctIdx, enabled, assignType }: UseAssignTargetRowsArgs): AssignTargetRow[] {
|
||||
const isOutsource = assignType === ListHeaderAssignConst.OUTSOURCE
|
||||
|
||||
const assignedCmpnIdsQuery = useAssignedCmpnIdsQuery(prjctIdx, enabled && isOutsource)
|
||||
const cmpnListQuery = useCmpnListQuery()
|
||||
|
||||
const assignedFieldworkIdsQuery = useAssignedFieldworkIdsQuery(prjctIdx, enabled && !isOutsource)
|
||||
const fieldworkUsersQuery = useFieldworkUsersQuery(enabled && !isOutsource)
|
||||
|
||||
return useMemo<AssignTargetRow[]>(() => {
|
||||
if (isOutsource) {
|
||||
const assignedIds = new Set(assignedCmpnIdsQuery.data ?? [])
|
||||
return (cmpnListQuery.data ?? [])
|
||||
.filter((cmpn) => assignedIds.has(cmpn.cmpnId))
|
||||
.map((cmpn) => ({ id: cmpn.cmpnId, name: cmpn.cmpnAlias || cmpn.cmpnId }))
|
||||
}
|
||||
|
||||
const targetRole =
|
||||
assignType === ListHeaderAssignConst.CONTACT_INTERVIEWER ? CONTACT_INTERVIEWER_ROLE : FIELD_INTERVIEWER_ROLE
|
||||
const assignedIds = new Set(assignedFieldworkIdsQuery.data ?? [])
|
||||
|
||||
return (fieldworkUsersQuery.data ?? [])
|
||||
.filter((user) => assignedIds.has(user.userId) && user.userRole === targetRole)
|
||||
.map((user) => ({ id: user.userId, name: user.userName }))
|
||||
}, [
|
||||
assignType,
|
||||
isOutsource,
|
||||
assignedCmpnIdsQuery.data,
|
||||
cmpnListQuery.data,
|
||||
assignedFieldworkIdsQuery.data,
|
||||
fieldworkUsersQuery.data,
|
||||
])
|
||||
}
|
||||
|
||||
export function AssignTargetList({ prjctIdx, enabled, assignType, selectedId, onSelect }: AssignTargetListProps) {
|
||||
const rows = useAssignTargetRows({ prjctIdx, enabled, assignType })
|
||||
|
||||
return (
|
||||
<div className="border border-gray-200 rounded-lg overflow-hidden bg-white shadow-sm">
|
||||
<div className="h-[78vh] overflow-y-auto">
|
||||
<table className="w-full table-fixed">
|
||||
<colgroup>
|
||||
<col className="w-28" />
|
||||
<col />
|
||||
</colgroup>
|
||||
<thead className="bg-primary text-white sticky top-0">
|
||||
<tr>
|
||||
<th className="p-2 text-left text-base font-medium">ID</th>
|
||||
<th className="p-2 text-left text-base font-medium">이름</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((row) => (
|
||||
<tr
|
||||
key={row.id}
|
||||
className={`border-b border-gray-100 cursor-pointer hover:bg-gray-50 ${
|
||||
selectedId === row.id ? 'bg-accent' : ''
|
||||
}`}
|
||||
onClick={() => onSelect(row.id)}
|
||||
>
|
||||
<td className="p-2 text-base truncate">{row.id}</td>
|
||||
<td className="p-2 text-base truncate">{row.name}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default AssignTargetList
|
||||
Reference in New Issue
Block a user