260427_01_ENH: 리스트 다이얼로그 및 리스트 작업 시작
This commit is contained in:
@@ -1,25 +1,392 @@
|
||||
"use client";
|
||||
'use client'
|
||||
|
||||
import {useFontSizeValue} from "@/hooks/useFontSize";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
|
||||
import BodyTitle from "@/components/layout/BodyTitle";
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
import ProjectTitle from "@/components/layout/ProjectTitle";
|
||||
import { useMemo, useState } from 'react'
|
||||
import { PaginationState, SortingState } from '@tanstack/react-table'
|
||||
import {
|
||||
Download,
|
||||
FileClock,
|
||||
Funnel,
|
||||
Mail,
|
||||
MessageSquareMore,
|
||||
PencilLine,
|
||||
RotateCcw,
|
||||
Upload,
|
||||
} from 'lucide-react'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { DataTable } from '@/components/data-table/DataTable'
|
||||
import type { DataTableColumn } from '@/components/data-table/DataTable.type'
|
||||
import { KriMultiSelect } from '@/components/common/KriAutoComplete'
|
||||
import { LoadingOverlay } from '@/components/common/LoadingOverlay'
|
||||
import { useMounted } from '@/hooks/useMounted'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useDialog } from '@/hooks/useDialog'
|
||||
import { useSelectedProject } from '@/hooks/useSelectedProject'
|
||||
import { useListHeaderQuery, useListSearchQuery } from '@/query/list'
|
||||
import { useResultCodesQuery } from '@/query/project'
|
||||
import { getListColumns, ListTableRow } from '@/components/table-column/ListTableColumn'
|
||||
import { ListSearchRequest } from '@/types/list'
|
||||
import { ResultCode, ResultCodeType } from '@/types/project'
|
||||
import { ListHeaderAssignConst } from '@/const/listConst'
|
||||
import ListResetDialog, { ListResetScope, ListResetTarget } from '@/components/dialog/ListResetDialog'
|
||||
import ListUploadDialog, { ListUploadHistory, ValidationOption } from '@/components/dialog/ListUploadDialog'
|
||||
import ListHeaderManageDialog, { ListHeaderManageRow } from '@/components/dialog/ListHeaderManageDialog'
|
||||
import ListBatchEditDialog, { BatchEditRow } from '@/components/dialog/ListBatchEditDialog'
|
||||
import ListFilterDialog, { FilterRow } from '@/components/dialog/ListFilterDialog'
|
||||
import ListDownloadDialog, { ListDownloadMode } from '@/components/dialog/ListDownloadDialog'
|
||||
import MessageSendDialog, {
|
||||
MessageSendMode,
|
||||
MessageSendPayload,
|
||||
MessageTemplateOption,
|
||||
} from '@/components/dialog/MessageSendDialog'
|
||||
import MessageHistoryDialog, { MessageHistoryRow } from '@/components/dialog/MessageHistoryDialog'
|
||||
|
||||
const uploadHistoryMock: ListUploadHistory[] = [
|
||||
{ round: 1, fileName: 'a.xlsx', userId: 'admin', uploadCount: 3500, uploadAt: '2025-10-30T11:00:00Z' },
|
||||
{ round: 2, fileName: '1.xlsx', userId: 'admin', uploadCount: 100, uploadAt: '2025-10-30T12:00:00Z' },
|
||||
{ round: 3, fileName: '2.xlsx', userId: 'admin', uploadCount: 2000, uploadAt: '2025-10-30T13:00:00Z' },
|
||||
]
|
||||
|
||||
const messageTemplateMock: MessageTemplateOption[] = [
|
||||
{
|
||||
id: 'sms-1',
|
||||
name: '[SMS] Contact Notice',
|
||||
title: 'Survey Request',
|
||||
body: 'Please participate in the survey.',
|
||||
},
|
||||
{
|
||||
id: 'email-1',
|
||||
name: '[EMAIL] Contact Notice',
|
||||
title: 'Survey Participation Guide',
|
||||
body: 'Please click the link and complete the survey.',
|
||||
},
|
||||
]
|
||||
|
||||
const messageHistoryMock: MessageHistoryRow[] = [
|
||||
{
|
||||
id: 1,
|
||||
type: 'sms',
|
||||
title: 'Survey Request',
|
||||
templateName: 'SMS Template A',
|
||||
sendInfo: '010-xxxx-xxxx',
|
||||
targetHeader: 'Phone Number',
|
||||
targetCount: 405,
|
||||
successCount: 405,
|
||||
failCount: 0,
|
||||
createdAt: '03.06 14:37',
|
||||
sendAt: '03.06 14:30 (Reserve)',
|
||||
status: 'Done',
|
||||
templatePreview: 'Please participate in the survey.',
|
||||
targetPreview: ['010-1234-5678', '010-1234-1111'],
|
||||
successPreview: ['sid 1: success', 'sid 2: success'],
|
||||
failPreview: [],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
type: 'email',
|
||||
title: 'Please answer this survey',
|
||||
templateName: 'EMAIL Template A',
|
||||
sendInfo: 'info@kric.com',
|
||||
targetHeader: 'Email',
|
||||
targetCount: 405,
|
||||
successCount: 395,
|
||||
failCount: 10,
|
||||
createdAt: '03.06 14:37',
|
||||
sendAt: '03.06 14:47 (Instant)',
|
||||
status: 'Requested',
|
||||
templatePreview: 'Please click the link and complete the survey.',
|
||||
targetPreview: ['aa@kric.com', 'bb@kric.com'],
|
||||
successPreview: ['sid 3: success', 'sid 4: success'],
|
||||
failPreview: ['sid 5: bounce', 'sid 6: invalid'],
|
||||
},
|
||||
]
|
||||
|
||||
const ListManagePage = () => {
|
||||
const fontSize = useFontSizeValue();
|
||||
const mounted = useMounted();
|
||||
const mounted = useMounted()
|
||||
const { auth } = useAuth()
|
||||
const { showDialog } = useDialog()
|
||||
const { selectedProject } = useSelectedProject()
|
||||
|
||||
if (!mounted) return <LoadingOverlay force />;
|
||||
const [searchText, setSearchText] = useState('')
|
||||
const [searchContactResult, setSearchContactResult] = useState<string[]>([])
|
||||
const [searchInterviewResult, setSearchInterviewResult] = useState<string[]>([])
|
||||
const [searchSurveyResult, setSearchSurveyResult] = useState<string[]>([])
|
||||
const [pagination, setPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 10 })
|
||||
const [sorting, setSorting] = useState<SortingState>([])
|
||||
|
||||
const [downloadMode, setDownloadMode] = useState<ListDownloadMode>('list')
|
||||
const [messageSendMode, setMessageSendMode] = useState<MessageSendMode>('email')
|
||||
const [filterRows, setFilterRows] = useState<FilterRow[]>([])
|
||||
const [batchRows, setBatchRows] = useState<BatchEditRow[]>([])
|
||||
|
||||
const userRole = auth?.user?.userRole ?? 9000
|
||||
const prjctIdx = selectedProject?.prjctIdx ?? 0
|
||||
const enabled = mounted && prjctIdx > 0
|
||||
|
||||
const resultCodesQuery = useResultCodesQuery(prjctIdx, enabled)
|
||||
const listHeaderQuery = useListHeaderQuery(prjctIdx, enabled)
|
||||
|
||||
const resultCodeArray = useMemo<ResultCode[]>(() => resultCodesQuery.data ?? [], [resultCodesQuery.data])
|
||||
|
||||
const listSearchRequest = useMemo<ListSearchRequest>(() => {
|
||||
const sort = sorting?.[0] ?? { id: 'sid', desc: true as const }
|
||||
return {
|
||||
listFilter: {
|
||||
sidSet: [],
|
||||
listUseSet: [],
|
||||
assignUserMap: {
|
||||
[ListHeaderAssignConst.OUTSOURCE]: [],
|
||||
[ListHeaderAssignConst.CONTACT_INTERVIEWER]: [],
|
||||
[ListHeaderAssignConst.FIELD_INTERVIEWER]: [],
|
||||
},
|
||||
memo: '',
|
||||
otherItems: {},
|
||||
},
|
||||
pageRequest: {
|
||||
pageIndex: pagination.pageIndex,
|
||||
pageSize: pagination.pageSize,
|
||||
sortBy: sort.id,
|
||||
sortDir: sort.desc ? 'desc' : 'asc',
|
||||
},
|
||||
}
|
||||
}, [pagination, sorting])
|
||||
|
||||
const listSearchQuery = useListSearchQuery(prjctIdx, listSearchRequest, enabled)
|
||||
|
||||
const columns = useMemo<DataTableColumn<ListTableRow, unknown>[]>(() => {
|
||||
if (!listHeaderQuery.data) return []
|
||||
return getListColumns(listHeaderQuery.data, resultCodeArray, userRole)
|
||||
}, [listHeaderQuery.data, resultCodeArray, userRole])
|
||||
|
||||
const viewList = useMemo<ListTableRow[]>(
|
||||
() => (listSearchQuery.data?.content ?? []).map((row) => ({ ...row, ...row.itemList })),
|
||||
[listSearchQuery.data],
|
||||
)
|
||||
|
||||
const totalCount = listSearchQuery.data?.totalElements ?? 0
|
||||
const pageCount = listSearchQuery.data?.totalPages ?? 0
|
||||
|
||||
const headerOptions = useMemo(
|
||||
() =>
|
||||
(listHeaderQuery.data ?? []).map((header) => ({
|
||||
id: header.listHderId,
|
||||
label: header.listHderNm,
|
||||
})),
|
||||
[listHeaderQuery.data],
|
||||
)
|
||||
|
||||
const headerManageRows = useMemo<ListHeaderManageRow[]>(
|
||||
() =>
|
||||
(listHeaderQuery.data ?? []).map((header) => ({
|
||||
id: header.listHderId,
|
||||
name: header.listHderNm,
|
||||
visible: header.useColView,
|
||||
locked: header.listHderGrad === 0,
|
||||
})),
|
||||
[listHeaderQuery.data],
|
||||
)
|
||||
|
||||
const filterHeaderOptions = useMemo(
|
||||
() => headerOptions.map((item) => ({ ...item, values: ['A', 'B', 'C'] })),
|
||||
[headerOptions],
|
||||
)
|
||||
|
||||
const messageTargetHeaders = useMemo(() => {
|
||||
const matched = headerOptions.filter((header) => /email|phone|tel/i.test(header.label))
|
||||
return matched.length > 0 ? matched : headerOptions.slice(0, 1)
|
||||
}, [headerOptions])
|
||||
|
||||
const handleSearchClick = () => {
|
||||
setPagination((prev) => ({ ...prev, pageIndex: 0 }))
|
||||
}
|
||||
|
||||
const openDownloadDialog = (mode: ListDownloadMode) => {
|
||||
setDownloadMode(mode)
|
||||
showDialog('listDownloadDialog')
|
||||
}
|
||||
|
||||
const openMessageDialog = (mode: MessageSendMode) => {
|
||||
setMessageSendMode(mode)
|
||||
showDialog('messageSendDialog')
|
||||
}
|
||||
|
||||
const handleResetConfirm = async (payload: { target: ListResetTarget; scope: ListResetScope }) => {
|
||||
void payload
|
||||
alert('List reset action callback placeholder.')
|
||||
}
|
||||
|
||||
const handleUploadConfirm = async (file: File, validation: ValidationOption) => {
|
||||
void file
|
||||
void validation
|
||||
alert('List upload action callback placeholder.')
|
||||
}
|
||||
|
||||
const handleDownloadTemplate = async () => {
|
||||
alert('Template download callback placeholder.')
|
||||
}
|
||||
|
||||
const handleHeaderManageConfirm = async (rows: ListHeaderManageRow[]) => {
|
||||
void rows
|
||||
alert('Header manage action callback placeholder.')
|
||||
}
|
||||
|
||||
const handleFilterConfirm = async (rows: FilterRow[]) => {
|
||||
setFilterRows(rows)
|
||||
alert('Filter action callback placeholder.')
|
||||
}
|
||||
|
||||
const handleBatchConfirm = async (rows: BatchEditRow[]) => {
|
||||
setBatchRows(rows)
|
||||
alert('Batch edit action callback placeholder.')
|
||||
}
|
||||
|
||||
const handleDownloadConfirm = async (payload: { mode: ListDownloadMode; onlyFiltered: boolean }) => {
|
||||
void payload
|
||||
alert('Download action callback placeholder.')
|
||||
}
|
||||
|
||||
const handleMessageSendConfirm = async (payload: MessageSendPayload) => {
|
||||
void payload
|
||||
alert('Message send action callback placeholder.')
|
||||
}
|
||||
|
||||
if (!mounted) return <LoadingOverlay force />
|
||||
|
||||
return (
|
||||
<div className="space-y-6 content-text-sm">
|
||||
<div>
|
||||
This is Manage List Page <span>{fontSize}</span>
|
||||
<div className="flex gap-2 items-center">
|
||||
<div className="flex flex-1 items-center gap-2 flex-wrap">
|
||||
<Button variant="destructive" className="content-text-base gap-2" onClick={() => showDialog('listResetDialog')}>
|
||||
<RotateCcw className="w-4 h-4" />
|
||||
리스트 초기화
|
||||
</Button>
|
||||
<Button className="content-text-base" onClick={() => showDialog('listHeaderManageDialog')}>
|
||||
헤더 관리
|
||||
</Button>
|
||||
<Button className="content-text-base gap-2" onClick={() => showDialog('listUploadDialog')}>
|
||||
<Upload className="w-4 h-4" />
|
||||
리스트 업로드
|
||||
</Button>
|
||||
<Button className="content-text-base bg-excel gap-2" onClick={() => openDownloadDialog('list')}>
|
||||
<Download className="w-4 h-4" />
|
||||
리스트
|
||||
</Button>
|
||||
<Button className="content-text-base bg-excel gap-2" onClick={() => openDownloadDialog('contact-history')}>
|
||||
<Download className="w-4 h-4" />
|
||||
컨택 이력
|
||||
</Button>
|
||||
<Button className="content-text-base bg-excel gap-2" onClick={() => openDownloadDialog('list-change-history')}>
|
||||
<Download className="w-4 h-4" />
|
||||
리스트 변경 이력
|
||||
</Button>
|
||||
<Button className="content-text-base gap-2" onClick={() => openDownloadDialog('upload-file')}>
|
||||
<Download className="w-4 h-4" />
|
||||
업로드 파일(.zip)
|
||||
</Button>
|
||||
</div>
|
||||
<Button className="content-text-base bg-blue gap-2" onClick={() => openMessageDialog('email')}>
|
||||
<Mail className="w-4 h-4" />
|
||||
이메일 발송
|
||||
</Button>
|
||||
<Button className="content-text-base bg-blue gap-2" onClick={() => openMessageDialog('sms')}>
|
||||
<MessageSquareMore className="w-4 h-4" />
|
||||
문자 발송
|
||||
</Button>
|
||||
<Button className="content-text-base gap-2" onClick={() => showDialog('messageHistoryDialog')}>
|
||||
<FileClock className="w-4 h-4" />
|
||||
발송 이력
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ListManagePage;
|
||||
<div className="flex gap-2 items-center">
|
||||
<div className="flex flex-1 items-center gap-2 flex-wrap">
|
||||
<Input
|
||||
placeholder="SID ',' '~' 사용 가능"
|
||||
className="w-100 h-9 bg-white"
|
||||
value={searchText}
|
||||
onChange={(e) => setSearchText(e.target.value)}
|
||||
/>
|
||||
<KriMultiSelect
|
||||
items={resultCodeArray.filter((item) => item.resultCdTy === ResultCodeType.CONTACT)}
|
||||
value={searchContactResult}
|
||||
onChange={setSearchContactResult}
|
||||
getValue={(item) => String(item.resultCd)}
|
||||
getLabel={(item) => item.resultCdLbl}
|
||||
placeholder="컨택 결과"
|
||||
widthClassName="w-70"
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
<KriMultiSelect
|
||||
items={resultCodeArray.filter((item) => item.resultCdTy === ResultCodeType.INTERVIEW)}
|
||||
value={searchInterviewResult}
|
||||
onChange={setSearchInterviewResult}
|
||||
getValue={(item) => String(item.resultCd)}
|
||||
getLabel={(item) => item.resultCdLbl}
|
||||
placeholder="면접 결과"
|
||||
widthClassName="w-70"
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
<KriMultiSelect
|
||||
items={resultCodeArray.filter((item) => item.resultCdTy === ResultCodeType.SURVEY)}
|
||||
value={searchSurveyResult}
|
||||
onChange={setSearchSurveyResult}
|
||||
getValue={(item) => String(item.resultCd)}
|
||||
getLabel={(item) => item.resultCdLbl}
|
||||
placeholder="설문 결과"
|
||||
widthClassName="w-70"
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
<Button className="content-text-lg" onClick={handleSearchClick}>
|
||||
검색
|
||||
</Button>
|
||||
<Button type="button" variant="outline" className="gap-2" onClick={() => showDialog('listFilterDialog')}>
|
||||
<Funnel className="w-4 h-4" />
|
||||
필터
|
||||
</Button>
|
||||
<Button type="button" variant="outline" className="gap-2" onClick={() => showDialog('listBatchEditDialog')}>
|
||||
<PencilLine className="w-4 h-4" />
|
||||
일괄 수정
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg border border-gray-200 overflow-hidden">
|
||||
<DataTable<ListTableRow>
|
||||
columns={columns}
|
||||
data={viewList}
|
||||
isClient={false}
|
||||
pageCount={pageCount}
|
||||
totalCount={totalCount}
|
||||
onPaginationChange={setPagination}
|
||||
onSortingChange={setSorting}
|
||||
selectMode="click-event"
|
||||
pageSizeOptions={[10, 20, 30, 50]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ListResetDialog onConfirm={handleResetConfirm} />
|
||||
<ListUploadDialog onUpload={handleUploadConfirm} onDownloadTemplate={handleDownloadTemplate} uploadHistory={uploadHistoryMock} />
|
||||
<ListHeaderManageDialog rows={headerManageRows} onConfirm={handleHeaderManageConfirm} />
|
||||
<ListFilterDialog headerOptions={filterHeaderOptions} initialRows={filterRows} onConfirm={handleFilterConfirm} />
|
||||
<ListBatchEditDialog
|
||||
headerOptions={headerOptions}
|
||||
appliedFilters={Object.fromEntries(filterRows.map((row) => [row.headerId, row.multiValues]))}
|
||||
initialRows={batchRows}
|
||||
onConfirm={handleBatchConfirm}
|
||||
/>
|
||||
<ListDownloadDialog mode={downloadMode} onDownload={handleDownloadConfirm} />
|
||||
<MessageSendDialog
|
||||
mode={messageSendMode}
|
||||
templateOptions={messageTemplateMock}
|
||||
targetHeaderOptions={messageTargetHeaders}
|
||||
defaultSenderEmail="info@kric.com"
|
||||
defaultSenderName="Korea Research"
|
||||
defaultSenderNumber="02-0000-0000"
|
||||
onConfirm={handleMessageSendConfirm}
|
||||
/>
|
||||
<MessageHistoryDialog rows={messageHistoryMock} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ListManagePage
|
||||
|
||||
Reference in New Issue
Block a user