130 lines
3.7 KiB
TypeScript
130 lines
3.7 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { keepPreviousData, useQuery } from "@tanstack/react-query";
|
|
import { getCoreRowModel, type PaginationState } from "@tanstack/react-table";
|
|
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
|
import { Button, Input, Label } from "@common/components";
|
|
import { AttachmentApi, type AttachmentParams } from "@/entities/attachment";
|
|
import { useAlertStore, useDataTable, useMutationWrapper } from "@/shared/lib";
|
|
import { ENDPOINT } from "@/shared/config";
|
|
import { createColumns } from "../model/table-columns";
|
|
|
|
function FilePage() {
|
|
const { confirm } = useConfirm();
|
|
const alert = useAlertStore((state) => state.setMessage);
|
|
|
|
const [orgnlFileNm, setOrgnlFileNm] = useState("");
|
|
const [searchParams, setSearchParams] = useState<AttachmentParams>({
|
|
orgnlFileNm: "",
|
|
sort: "regDt,desc",
|
|
});
|
|
const [pagination, setPagination] = useState<PaginationState>({
|
|
pageIndex: 0,
|
|
pageSize: 10,
|
|
});
|
|
|
|
const query = useQuery({
|
|
queryKey: [ENDPOINT.ATTACH_SERVICE.ATTACHMENTS, searchParams, pagination],
|
|
queryFn: () =>
|
|
AttachmentApi.getAttachmentsList({
|
|
...searchParams,
|
|
page: pagination.pageIndex,
|
|
size: pagination.pageSize,
|
|
}),
|
|
placeholderData: keepPreviousData,
|
|
});
|
|
|
|
const { mutate: deleteAttachment } = useMutationWrapper({
|
|
mutationFn: (atflId: string) =>
|
|
AttachmentApi.deleteAttachmentByAtflId(atflId),
|
|
onSuccess: () => {
|
|
alert("삭제되었습니다.", query.refetch);
|
|
},
|
|
});
|
|
|
|
const handleDeleteAttachment = async (atflId: string) => {
|
|
if (await confirm("삭제하시겠습니까?")) {
|
|
deleteAttachment(atflId);
|
|
}
|
|
};
|
|
|
|
const { tableComponent } = useDataTable({
|
|
query,
|
|
tableOptions: {
|
|
columns: createColumns(handleDeleteAttachment),
|
|
state: {
|
|
pagination,
|
|
},
|
|
onPaginationChange: setPagination,
|
|
getCoreRowModel: getCoreRowModel(),
|
|
manualPagination: true,
|
|
},
|
|
dataTableOptions: {
|
|
viewPagination: true,
|
|
},
|
|
});
|
|
|
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
|
e.preventDefault();
|
|
setPagination({
|
|
...pagination,
|
|
pageIndex: 0,
|
|
});
|
|
setSearchParams({
|
|
...searchParams,
|
|
orgnlFileNm,
|
|
});
|
|
};
|
|
|
|
const handleReset = () => {
|
|
setOrgnlFileNm("");
|
|
setSearchParams({
|
|
...searchParams,
|
|
orgnlFileNm: "",
|
|
});
|
|
};
|
|
|
|
return (
|
|
<div className="card card-border !mt-6">
|
|
<div className="card card-border">
|
|
<form onSubmit={handleSubmit} className="flex gap-2 p-2">
|
|
<div className="flex space-x-6">
|
|
<div className="flex items-center gap-2">
|
|
<Label htmlFor="keyword" className="text-label">
|
|
파일명
|
|
</Label>
|
|
<Input
|
|
id="keyword"
|
|
className="h-[3.2rem] w-[24rem] rounded-sm !text-[1.3rem]"
|
|
value={orgnlFileNm}
|
|
onChange={(e) => setOrgnlFileNm(e.target.value)}
|
|
placeholder="파일명을 입력하세요"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<Button className="h-[3.2rem]" type="submit">
|
|
조회
|
|
</Button>
|
|
<Button
|
|
type="button"
|
|
color="white"
|
|
className="h-[3.2rem]"
|
|
onClick={handleReset}
|
|
>
|
|
초기화
|
|
</Button>
|
|
</form>
|
|
</div>
|
|
<div className="card card-border">
|
|
<div className="card-header">
|
|
<h3 className="text-2xl font-medium text-label">파일 목록</h3>
|
|
</div>
|
|
<div className="card !m-[1.2rem] !p-0">{tableComponent}</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export { FilePage };
|