Merge pull request 'develop' (#35) from develop into master
Reviewed-on: #35
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import type { PaginationState } from '@tanstack/react-table'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { useRouter } from 'next/navigation'
|
||||
@@ -31,6 +31,7 @@ import type { ListTableRow } from '@/components/table-column/ListTableColumn'
|
||||
import {
|
||||
createEmptyListFilter,
|
||||
ListEventHistoryBase,
|
||||
ListEventHistoryOrder,
|
||||
type LastListVisit,
|
||||
type ListDownloadMode,
|
||||
type ListDownloadPayload,
|
||||
@@ -94,6 +95,7 @@ const ListManagePage = () => {
|
||||
const [pagination, setPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 25 })
|
||||
const [restoredVisit, setRestoredVisit] = useState<LastListVisit | null>(null)
|
||||
const [restoreResolved, setRestoreResolved] = useState(false)
|
||||
const previousPrjctIdxRef = useRef(0)
|
||||
|
||||
const { get: getLastListVisit, set: setLastListVisit, remove: removeLastListVisit } = useStorage(
|
||||
StorageKeys.LastListVisit,
|
||||
@@ -141,6 +143,21 @@ const ListManagePage = () => {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [mounted, isSelectedProjectHydrated, restoreResolved])
|
||||
|
||||
useEffect(() => {
|
||||
if (!mounted || !isSelectedProjectHydrated || prjctIdx <= 0) return
|
||||
|
||||
const previousPrjctIdx = previousPrjctIdxRef.current
|
||||
previousPrjctIdxRef.current = prjctIdx
|
||||
if (previousPrjctIdx === 0 || previousPrjctIdx === prjctIdx) return
|
||||
|
||||
setSelectedRows([])
|
||||
setCurrentListFilter(createEmptyListFilter())
|
||||
setFilterSummary([])
|
||||
setSearchUiState(createEmptySearchUiState())
|
||||
setPagination({ pageIndex: 0, pageSize: 25 })
|
||||
setRestoredVisit(null)
|
||||
}, [isSelectedProjectHydrated, mounted, prjctIdx])
|
||||
|
||||
// 브라우저 뒤로가기(popstate)는 Next.js가 이 페이지를 재마운트하지 않고 재사용할 수 있어
|
||||
// refetchOnMount만으로는 최신 데이터를 보장 못한다. popstate는 브라우저 네이티브 이벤트라
|
||||
// 재마운트 여부와 무관하게 항상 발생하므로, 여기서 명시적으로 무효화한다.
|
||||
@@ -247,7 +264,7 @@ const ListManagePage = () => {
|
||||
const listFilter = buildTargetFilter(payload.target)
|
||||
|
||||
if (payload.mode === 'list') {
|
||||
const buffer = await downloadListMutation.mutateAsync(listFilter)
|
||||
const buffer = await downloadListMutation.mutateAsync({ listFilter, includeResult: payload.includeResult })
|
||||
downloadArrayBuffer(buffer, `${prjctName} list.xlsx`)
|
||||
return
|
||||
}
|
||||
@@ -265,9 +282,11 @@ const ListManagePage = () => {
|
||||
}
|
||||
|
||||
const buffer = await downloadListEventHistoryMutation.mutateAsync({
|
||||
includeResult: payload.includeResult,
|
||||
listFilter,
|
||||
resultCodeTypes: [ResultCodeType.CONTACT, ResultCodeType.INTERVIEW, ResultCodeType.SURVEY],
|
||||
searchBase: payload.contactHistoryType === 'latest' ? ListEventHistoryBase.LATEST : ListEventHistoryBase.ALL,
|
||||
historyOrder: payload.historyOrder ?? ListEventHistoryOrder.DESC,
|
||||
dateRange: toDateTimeRange(payload.contactHistoryDateFrom, payload.contactHistoryDateTo),
|
||||
})
|
||||
downloadArrayBuffer(buffer, `${prjctName} contact-history.xlsx`)
|
||||
@@ -290,6 +309,7 @@ const ListManagePage = () => {
|
||||
)}
|
||||
|
||||
<ListSearchTable
|
||||
key={prjctIdx}
|
||||
prjctIdx={prjctIdx}
|
||||
enabled={enabled}
|
||||
userRole={userRole}
|
||||
|
||||
@@ -108,7 +108,12 @@ export const POST = async (req: NextRequest, context: RouteContext) => {
|
||||
|
||||
if (action === "excel-download") {
|
||||
const body = await req.json().catch(() => null);
|
||||
const result = await contactApi.post<ArrayBuffer>(`/list/excel/download/${slug[1]}`, body, { expectBinary: true });
|
||||
const includeResult = req.nextUrl.searchParams.get("includeResult") !== "false";
|
||||
const result = await contactApi.post<ArrayBuffer>(
|
||||
`/list/excel/download/${slug[1]}?includeResult=${includeResult}`,
|
||||
body,
|
||||
{ expectBinary: true },
|
||||
);
|
||||
return new NextResponse(result, { status: 200, headers: excelHeaders });
|
||||
}
|
||||
|
||||
@@ -122,9 +127,12 @@ export const POST = async (req: NextRequest, context: RouteContext) => {
|
||||
|
||||
if (action === "event-history-download") {
|
||||
const body = await req.json().catch(() => null);
|
||||
const result = await contactApi.post<ArrayBuffer>(`/list-hist/excel/download/event/${slug[1]}`, body, {
|
||||
expectBinary: true,
|
||||
});
|
||||
const includeResult = req.nextUrl.searchParams.get("includeResult") !== "false";
|
||||
const result = await contactApi.post<ArrayBuffer>(
|
||||
`/list-hist/excel/download/event/${slug[1]}?includeResult=${includeResult}`,
|
||||
body,
|
||||
{ expectBinary: true },
|
||||
);
|
||||
return new NextResponse(result, { status: 200, headers: excelHeaders });
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,20 @@ import { useState } from 'react'
|
||||
import { Download } from 'lucide-react'
|
||||
import { KriDialog } from '@/components/common/KriDialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
|
||||
import { useDialog } from '@/hooks/useDialog'
|
||||
import type { DialogId } from '@/store/jotai/dialog'
|
||||
import ApplyFilterOption, { validateApplyFilterTarget } from './ListDialogOption/ApplyFilterOption'
|
||||
import KriDateRangePicker from '@/components/common/KriDateRangePicker'
|
||||
import type { ContactHistoryDownloadType, ListDownloadMode, ListDownloadPayload, ListFilterTarget } from '@/types/list'
|
||||
import {
|
||||
type ContactHistoryDownloadType,
|
||||
ListEventHistoryOrder,
|
||||
type ListDownloadMode,
|
||||
type ListDownloadPayload,
|
||||
type ListFilterTarget,
|
||||
} from '@/types/list'
|
||||
|
||||
export type ListDownloadDialogProps = {
|
||||
dialogId?: DialogId
|
||||
@@ -43,6 +50,8 @@ const ListDownloadDialog = ({
|
||||
const [contactHistoryDateFrom, setContactHistoryDateFrom] = useState('')
|
||||
const [contactHistoryDateTo, setContactHistoryDateTo] = useState('')
|
||||
const [contactHistoryType, setContactHistoryType] = useState<ContactHistoryDownloadType>('all')
|
||||
const [historyOrder, setHistoryOrder] = useState<ListEventHistoryOrder>(ListEventHistoryOrder.DESC)
|
||||
const [includeResult, setIncludeResult] = useState(true)
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId)
|
||||
@@ -78,9 +87,11 @@ const ListDownloadDialog = ({
|
||||
mode,
|
||||
target,
|
||||
onlyFiltered: target === 'filtered',
|
||||
includeResult,
|
||||
contactHistoryDateFrom: mode === 'contact-history' ? contactHistoryDateFrom || undefined : undefined,
|
||||
contactHistoryDateTo: mode === 'contact-history' ? contactHistoryDateTo || undefined : undefined,
|
||||
contactHistoryType: mode === 'contact-history' ? contactHistoryType : undefined,
|
||||
historyOrder: mode === 'contact-history' ? historyOrder : undefined,
|
||||
})
|
||||
handleOpenChange(false)
|
||||
} finally {
|
||||
@@ -130,6 +141,16 @@ const ListDownloadDialog = ({
|
||||
filterSummary={filterSummary}
|
||||
/>
|
||||
</div>
|
||||
{mode === 'list' || mode === 'contact-history' ? (
|
||||
<div className="flex items-center gap-2 rounded-md border p-4">
|
||||
<Checkbox
|
||||
id="download-include-result"
|
||||
checked={includeResult}
|
||||
onCheckedChange={(checked) => setIncludeResult(checked === true)}
|
||||
/>
|
||||
<Label className="text-base" htmlFor="download-include-result">결과값 포함</Label>
|
||||
</div>
|
||||
) : null}
|
||||
{mode === 'contact-history' ? (
|
||||
<div className="rounded-md border p-4 space-y-4">
|
||||
<p className="text-lg font-semibold">이력 기준</p>
|
||||
@@ -149,6 +170,25 @@ const ListDownloadDialog = ({
|
||||
</RadioGroup>
|
||||
</div>
|
||||
) : null}
|
||||
{mode === 'contact-history' && contactHistoryType === 'all' ? (
|
||||
<div className="rounded-md border p-4 space-y-4">
|
||||
<p className="text-lg font-semibold">이력 순서</p>
|
||||
<RadioGroup
|
||||
value={historyOrder}
|
||||
onValueChange={(value) => setHistoryOrder(value as ListEventHistoryOrder)}
|
||||
className="flex items-center gap-6 flex-wrap"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<RadioGroupItem value={ListEventHistoryOrder.DESC} id="download-history-order-desc" />
|
||||
<Label className="text-base" htmlFor="download-history-order-desc">최근 이력이 왼쪽부터</Label>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<RadioGroupItem value={ListEventHistoryOrder.ASC} id="download-history-order-asc" />
|
||||
<Label className="text-base" htmlFor="download-history-order-asc">오래된 이력이 왼쪽부터</Label>
|
||||
</div>
|
||||
</RadioGroup>
|
||||
</div>
|
||||
) : null}
|
||||
</KriDialog>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -275,8 +275,10 @@ export function useDeleteListEventMutation(prjctIdx: number, sid: string) {
|
||||
|
||||
export function useDownloadListMutation(prjctIdx: number) {
|
||||
return useMutation({
|
||||
mutationFn: (listFilter: ListFilter) =>
|
||||
nextApi.post<ArrayBuffer>(`/list/excel-download/${prjctIdx}`, listFilter, { expectBinary: true }),
|
||||
mutationFn: ({ listFilter, includeResult }: { listFilter: ListFilter; includeResult: boolean }) =>
|
||||
nextApi.post<ArrayBuffer>(`/list/excel-download/${prjctIdx}?includeResult=${includeResult}`, listFilter, {
|
||||
expectBinary: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -289,8 +291,10 @@ export function useDownloadListUpdateHistoryMutation(prjctIdx: number) {
|
||||
|
||||
export function useDownloadListEventHistoryMutation(prjctIdx: number) {
|
||||
return useMutation({
|
||||
mutationFn: (request: ListEventHistDownloadRequest) =>
|
||||
nextApi.post<ArrayBuffer>(`/list/event-history-download/${prjctIdx}`, request, { expectBinary: true }),
|
||||
mutationFn: ({ includeResult, ...request }: ListEventHistDownloadRequest & { includeResult: boolean }) =>
|
||||
nextApi.post<ArrayBuffer>(`/list/event-history-download/${prjctIdx}?includeResult=${includeResult}`, request, {
|
||||
expectBinary: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,11 @@ export enum ListEventHistoryBase {
|
||||
LATEST = 2,
|
||||
}
|
||||
|
||||
export enum ListEventHistoryOrder {
|
||||
ASC = 'ASC',
|
||||
DESC = 'DESC',
|
||||
}
|
||||
|
||||
export type FilterOperator = 'eq' | 'neq' | 'contains' | 'notContains' | 'empty' | 'notEmpty' | 'none';
|
||||
|
||||
export type FilterValueOption = {
|
||||
@@ -78,9 +83,11 @@ export type ListDownloadPayload = {
|
||||
mode: ListDownloadMode;
|
||||
target: ListFilterTarget;
|
||||
onlyFiltered: boolean;
|
||||
includeResult: boolean;
|
||||
contactHistoryDateFrom?: string;
|
||||
contactHistoryDateTo?: string;
|
||||
contactHistoryType?: ContactHistoryDownloadType;
|
||||
historyOrder?: ListEventHistoryOrder;
|
||||
};
|
||||
|
||||
export type ListResetScope = 'result-and-history' | 'list-only';
|
||||
@@ -355,6 +362,7 @@ export type ListEventHistDownloadRequest = {
|
||||
listFilter: ListFilter;
|
||||
resultCodeTypes: number[];
|
||||
searchBase: ListEventHistoryBase;
|
||||
historyOrder: ListEventHistoryOrder;
|
||||
dateRange?: {
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
|
||||
Reference in New Issue
Block a user