Merge remote-tracking branch 'origin/iipbs/as/dev' into iipbs/as/dev
This commit is contained in:
@@ -18,7 +18,6 @@ export interface ElaprAplnListParams extends PageableParams {
|
||||
}
|
||||
|
||||
export interface ElaprAplnSaveRequest {
|
||||
aplnId: string;
|
||||
elaprTmpltId: string;
|
||||
aprvrUuid?: string;
|
||||
atrzSeComCd?: string;
|
||||
|
||||
@@ -20,7 +20,6 @@ export interface ElaprTmpltSearchParams extends PageableParams {
|
||||
}
|
||||
|
||||
export interface ElaprTmpltSaveRequest {
|
||||
elaprTmpltId: string;
|
||||
elaprTmpltNm: string;
|
||||
elaprTmpltExpln?: string;
|
||||
docSeComCd?: string;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { useEffect } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { generateClientId } from "@/shared/lib";
|
||||
import { CodeSelect } from "@/entities/code";
|
||||
import type { ElaprTmplt } from "@/entities/elapr";
|
||||
import {
|
||||
@@ -19,7 +18,7 @@ import {
|
||||
} from "@common/components";
|
||||
|
||||
export interface ElaprTmpltFormValues {
|
||||
elaprTmpltId: string;
|
||||
elaprTmpltId?: string;
|
||||
elaprTmpltNm: string;
|
||||
docSeComCd: string;
|
||||
elaprTmpltExpln: string;
|
||||
@@ -44,7 +43,6 @@ function ElaprTmpltFormDialog({
|
||||
}: ElaprTmpltFormDialogProps) {
|
||||
const { register, handleSubmit, reset, setValue, watch } = useForm<ElaprTmpltFormValues>({
|
||||
defaultValues: {
|
||||
elaprTmpltId: "",
|
||||
elaprTmpltNm: "",
|
||||
docSeComCd: "",
|
||||
elaprTmpltExpln: "",
|
||||
@@ -67,8 +65,6 @@ function ElaprTmpltFormDialog({
|
||||
}
|
||||
|
||||
reset({
|
||||
// TBD: elaprTmpltId 발급 정책 — 현재 클라이언트 임시 ID
|
||||
elaprTmpltId: generateClientId("TMPL"),
|
||||
elaprTmpltNm: "",
|
||||
docSeComCd: "",
|
||||
elaprTmpltExpln: "",
|
||||
@@ -82,10 +78,12 @@ function ElaprTmpltFormDialog({
|
||||
<DialogTitle>{mode === "create" ? "결재서식 등록" : "결재서식 수정"}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<form className="space-y-4" onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="elaprTmpltId">전자결재서식아이디</Label>
|
||||
<Input id="elaprTmpltId" disabled {...register("elaprTmpltId", { required: true })} />
|
||||
</div>
|
||||
{mode === "edit" ? (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="elaprTmpltId">전자결재서식아이디</Label>
|
||||
<Input id="elaprTmpltId" disabled {...register("elaprTmpltId")} />
|
||||
</div>
|
||||
) : null}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="elaprTmpltNm">결재서식명</Label>
|
||||
<Input id="elaprTmpltNm" {...register("elaprTmpltNm", { required: true })} />
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
/** TBD: elaprTmpltId / aplnId 서버 발급 정책 확정 후 클라이언트 생성 규칙 교체 */
|
||||
export function generateClientId(prefix: string): string {
|
||||
const suffix = crypto.randomUUID().replace(/-/g, "").slice(0, 8).toUpperCase();
|
||||
return `${prefix}-${suffix}`;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
export { getCookie, removeCookie, setCookie } from "./cookie";
|
||||
export { dayjs } from "./dayjs";
|
||||
export { generateClientId } from "./generate-client-id";
|
||||
export { matchQueryStatus } from "./match-query-status";
|
||||
export { queryClient } from "./query-client";
|
||||
export { useAlertStore } from "./use-alert-store";
|
||||
|
||||
@@ -4,13 +4,12 @@ import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import { arrayMove } from "@dnd-kit/sortable";
|
||||
|
||||
import { generateClientId } from "@/shared/lib";
|
||||
import type { ElaprApln } from "@/entities/elapr";
|
||||
|
||||
import type { ElaprAplnRow } from "../model/types";
|
||||
|
||||
function toRow(item: ElaprApln): ElaprAplnRow {
|
||||
return { ...item, isNew: false, isDirty: false };
|
||||
return { ...item, rowKey: item.aplnId, isNew: false, isDirty: false };
|
||||
}
|
||||
|
||||
interface UseAplnRowsOptions {
|
||||
@@ -18,32 +17,36 @@ interface UseAplnRowsOptions {
|
||||
serverRows: ElaprApln[] | undefined;
|
||||
}
|
||||
|
||||
export function createDraftRowKey(): string {
|
||||
return `draft-${Date.now()}`;
|
||||
}
|
||||
|
||||
export function useAplnRows({ elaprTmpltId, serverRows }: UseAplnRowsOptions) {
|
||||
const [rows, setRows] = useState<ElaprAplnRow[]>([]);
|
||||
const [editingRowId, setEditingRowId] = useState<string | null>(null);
|
||||
const [editingRowKey, setEditingRowKey] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!elaprTmpltId) {
|
||||
setRows([]);
|
||||
setEditingRowId(null);
|
||||
setEditingRowKey(null);
|
||||
return;
|
||||
}
|
||||
setRows((serverRows ?? []).map(toRow));
|
||||
setEditingRowId(null);
|
||||
setEditingRowKey(null);
|
||||
}, [elaprTmpltId, serverRows]);
|
||||
|
||||
const isEditingLocked = editingRowId != null;
|
||||
const isEditingLocked = editingRowKey != null;
|
||||
|
||||
const addRow = useCallback(() => {
|
||||
if (!elaprTmpltId || isEditingLocked) return;
|
||||
|
||||
const tempId = generateClientId("APLN");
|
||||
const rowKey = createDraftRowKey();
|
||||
const nextSeq = rows.length + 1;
|
||||
|
||||
setRows((prev) => [
|
||||
...prev,
|
||||
{
|
||||
aplnId: tempId,
|
||||
rowKey,
|
||||
elaprTmpltId,
|
||||
atrzSeqNo: nextSeq,
|
||||
atrzSeComCd: "",
|
||||
@@ -53,40 +56,40 @@ export function useAplnRows({ elaprTmpltId, serverRows }: UseAplnRowsOptions) {
|
||||
isDirty: true,
|
||||
},
|
||||
]);
|
||||
setEditingRowId(tempId);
|
||||
setEditingRowKey(rowKey);
|
||||
}, [elaprTmpltId, isEditingLocked, rows.length]);
|
||||
|
||||
const startEdit = useCallback(
|
||||
(aplnId: string) => {
|
||||
(rowKey: string) => {
|
||||
if (isEditingLocked) return;
|
||||
setEditingRowId(aplnId);
|
||||
setEditingRowKey(rowKey);
|
||||
setRows((prev) =>
|
||||
prev.map((row) => (row.aplnId === aplnId ? { ...row, snapshot: { ...row } } : row)),
|
||||
prev.map((row) => (row.rowKey === rowKey ? { ...row, snapshot: { ...row } } : row)),
|
||||
);
|
||||
},
|
||||
[isEditingLocked],
|
||||
);
|
||||
|
||||
const updateRow = useCallback(
|
||||
(aplnId: string, patch: Partial<ElaprAplnRow>) => {
|
||||
if (editingRowId !== aplnId) return;
|
||||
(rowKey: string, patch: Partial<ElaprAplnRow>) => {
|
||||
if (editingRowKey !== rowKey) return;
|
||||
setRows((prev) =>
|
||||
prev.map((row) => (row.aplnId === aplnId ? { ...row, ...patch, isDirty: true } : row)),
|
||||
prev.map((row) => (row.rowKey === rowKey ? { ...row, ...patch, isDirty: true } : row)),
|
||||
);
|
||||
},
|
||||
[editingRowId],
|
||||
[editingRowKey],
|
||||
);
|
||||
|
||||
const cancelEdit = useCallback(() => {
|
||||
if (!editingRowId) return;
|
||||
if (!editingRowKey) return;
|
||||
|
||||
setRows((prev) => {
|
||||
const target = prev.find((r) => r.aplnId === editingRowId);
|
||||
const target = prev.find((r) => r.rowKey === editingRowKey);
|
||||
if (target?.isNew) {
|
||||
return prev.filter((r) => r.aplnId !== editingRowId);
|
||||
return prev.filter((r) => r.rowKey !== editingRowKey);
|
||||
}
|
||||
return prev.map((row) => {
|
||||
if (row.aplnId !== editingRowId) return row;
|
||||
if (row.rowKey !== editingRowKey) return row;
|
||||
if (row.snapshot) {
|
||||
const { snapshot: _s, isNew: _n, isDirty: _d, ...restored } = row.snapshot;
|
||||
return { ...restored, isNew: false, isDirty: false };
|
||||
@@ -94,27 +97,27 @@ export function useAplnRows({ elaprTmpltId, serverRows }: UseAplnRowsOptions) {
|
||||
return { ...row, isDirty: false };
|
||||
});
|
||||
});
|
||||
setEditingRowId(null);
|
||||
}, [editingRowId]);
|
||||
setEditingRowKey(null);
|
||||
}, [editingRowKey]);
|
||||
|
||||
const clearEditing = useCallback(() => {
|
||||
setEditingRowId(null);
|
||||
setEditingRowKey(null);
|
||||
}, []);
|
||||
|
||||
const removeRowLocal = useCallback((aplnId: string) => {
|
||||
setRows((prev) => prev.filter((r) => r.aplnId !== aplnId));
|
||||
setEditingRowId((id) => (id === aplnId ? null : id));
|
||||
const removeRowLocal = useCallback((rowKey: string) => {
|
||||
setRows((prev) => prev.filter((r) => r.rowKey !== rowKey));
|
||||
setEditingRowKey((key) => (key === rowKey ? null : key));
|
||||
}, []);
|
||||
|
||||
const reorderRows = useCallback(
|
||||
(activeId: string, overId: string): ElaprAplnRow[] => {
|
||||
(activeKey: string, overKey: string): ElaprAplnRow[] => {
|
||||
if (isEditingLocked) return [];
|
||||
|
||||
let newRows: ElaprAplnRow[] = [];
|
||||
|
||||
setRows((prev) => {
|
||||
const oldIndex = prev.findIndex((r) => r.aplnId === activeId);
|
||||
const newIndex = prev.findIndex((r) => r.aplnId === overId);
|
||||
const oldIndex = prev.findIndex((r) => r.rowKey === activeKey);
|
||||
const newIndex = prev.findIndex((r) => r.rowKey === overKey);
|
||||
if (oldIndex < 0 || newIndex < 0) return prev;
|
||||
|
||||
const moved = arrayMove(prev, oldIndex, newIndex).map((row, idx) => ({
|
||||
@@ -134,7 +137,7 @@ export function useAplnRows({ elaprTmpltId, serverRows }: UseAplnRowsOptions) {
|
||||
return {
|
||||
rows,
|
||||
setRows,
|
||||
editingRowId,
|
||||
editingRowKey,
|
||||
isEditingLocked,
|
||||
addRow,
|
||||
startEdit,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import type { ElaprApln } from "@/entities/elapr";
|
||||
|
||||
/** 그리드 로컬 행 — API 응답 + UI 보조 필드 */
|
||||
export interface ElaprAplnRow extends ElaprApln {
|
||||
export interface ElaprAplnRow extends Omit<ElaprApln, "aplnId"> {
|
||||
/** React key · DnD · 편집 잠금용 — 서버 aplnId와 분리 */
|
||||
rowKey: string;
|
||||
aplnId?: string;
|
||||
/** 결재자 표시명 — 응답 DTO에 없음, 선택 시 로컬 유지 */
|
||||
aprvrNm?: string;
|
||||
isNew?: boolean;
|
||||
|
||||
@@ -36,7 +36,7 @@ interface ElaprAplnGridProps {
|
||||
|
||||
function ElaprAplnGrid({ elaprTmpltId }: ElaprAplnGridProps) {
|
||||
const [pickerOpen, setPickerOpen] = useState(false);
|
||||
const [pickingRowId, setPickingRowId] = useState<string | null>(null);
|
||||
const [pickingRowKey, setPickingRowKey] = useState<string | null>(null);
|
||||
|
||||
const alert = useAlertStore((state) => state.setMessage);
|
||||
|
||||
@@ -53,7 +53,7 @@ function ElaprAplnGrid({ elaprTmpltId }: ElaprAplnGridProps) {
|
||||
|
||||
const {
|
||||
rows,
|
||||
editingRowId,
|
||||
editingRowKey,
|
||||
isEditingLocked,
|
||||
addRow,
|
||||
startEdit,
|
||||
@@ -73,7 +73,7 @@ function ElaprAplnGrid({ elaprTmpltId }: ElaprAplnGridProps) {
|
||||
const handleDragEnd = (event: DragEndEvent) => {
|
||||
const { active, over } = event;
|
||||
if (!over || active.id === over.id) return;
|
||||
const payloadRows = reorderRows(String(active.id), String(over.id));
|
||||
reorderRows(String(active.id), String(over.id));
|
||||
};
|
||||
|
||||
const handleRowSave = async (row: ElaprAplnRow) => {
|
||||
@@ -82,7 +82,7 @@ function ElaprAplnGrid({ elaprTmpltId }: ElaprAplnGridProps) {
|
||||
alert(fieldError);
|
||||
return;
|
||||
}
|
||||
const dupError = validateUniqueSeqNo(rows.map((r) => (r.aplnId === row.aplnId ? row : r)));
|
||||
const dupError = validateUniqueSeqNo(rows.map((r) => (r.rowKey === row.rowKey ? row : r)));
|
||||
if (dupError) {
|
||||
alert(dupError);
|
||||
return;
|
||||
@@ -92,13 +92,12 @@ function ElaprAplnGrid({ elaprTmpltId }: ElaprAplnGridProps) {
|
||||
|
||||
if (row.isNew) {
|
||||
await createMutation.mutateAsync({
|
||||
aplnId: row.aplnId,
|
||||
elaprTmpltId,
|
||||
aprvrUuid: row.aprvrUuid,
|
||||
atrzSeComCd: row.atrzSeComCd,
|
||||
atrzSeqNo: row.atrzSeqNo,
|
||||
});
|
||||
} else {
|
||||
} else if (row.aplnId) {
|
||||
await updateMutation.mutateAsync({
|
||||
aplnId: row.aplnId,
|
||||
body: {
|
||||
@@ -118,11 +117,11 @@ function ElaprAplnGrid({ elaprTmpltId }: ElaprAplnGridProps) {
|
||||
if (!window.confirm("선택한 결재선을 삭제하시겠습니까?")) return;
|
||||
|
||||
if (row.isNew) {
|
||||
removeRowLocal(row.aplnId);
|
||||
removeRowLocal(row.rowKey);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!elaprTmpltId) return;
|
||||
if (!elaprTmpltId || !row.aplnId) return;
|
||||
|
||||
await deleteMutation.mutateAsync({ aplnId: row.aplnId, elaprTmpltId });
|
||||
await aplnQuery.refetch();
|
||||
@@ -148,13 +147,12 @@ function ElaprAplnGrid({ elaprTmpltId }: ElaprAplnGridProps) {
|
||||
|
||||
if (row.isNew) {
|
||||
await createMutation.mutateAsync({
|
||||
aplnId: row.aplnId,
|
||||
elaprTmpltId,
|
||||
aprvrUuid: row.aprvrUuid,
|
||||
atrzSeComCd: row.atrzSeComCd,
|
||||
atrzSeqNo: row.atrzSeqNo,
|
||||
});
|
||||
} else {
|
||||
} else if (row.aplnId) {
|
||||
await updateMutation.mutateAsync({
|
||||
aplnId: row.aplnId,
|
||||
body: {
|
||||
@@ -172,12 +170,12 @@ function ElaprAplnGrid({ elaprTmpltId }: ElaprAplnGridProps) {
|
||||
};
|
||||
|
||||
const handleReviewerSelect = (reviewer: ReviewerOption) => {
|
||||
if (!pickingRowId) return;
|
||||
updateRow(pickingRowId, {
|
||||
if (!pickingRowKey) return;
|
||||
updateRow(pickingRowKey, {
|
||||
aprvrUuid: reviewer.uuid,
|
||||
aprvrNm: reviewer.name,
|
||||
});
|
||||
setPickingRowId(null);
|
||||
setPickingRowKey(null);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -229,23 +227,23 @@ function ElaprAplnGrid({ elaprTmpltId }: ElaprAplnGridProps) {
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<SortableContext
|
||||
items={rows.map((r) => r.aplnId)}
|
||||
items={rows.map((r) => r.rowKey)}
|
||||
strategy={verticalListSortingStrategy}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<SortableAplnRow
|
||||
key={row.aplnId}
|
||||
key={row.rowKey}
|
||||
row={row}
|
||||
isEditing={editingRowId === row.aplnId}
|
||||
isEditing={editingRowKey === row.rowKey}
|
||||
isLocked={isEditingLocked}
|
||||
dragDisabled={isEditingLocked}
|
||||
onStartEdit={() => startEdit(row.aplnId)}
|
||||
onStartEdit={() => startEdit(row.rowKey)}
|
||||
onSave={() => handleRowSave(row)}
|
||||
onCancel={cancelEdit}
|
||||
onDelete={() => handleRowDelete(row)}
|
||||
onChange={(patch) => updateRow(row.aplnId, patch)}
|
||||
onChange={(patch) => updateRow(row.rowKey, patch)}
|
||||
onPickAprvr={() => {
|
||||
setPickingRowId(row.aplnId);
|
||||
setPickingRowKey(row.rowKey);
|
||||
setPickerOpen(true);
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -37,7 +37,7 @@ function SortableAplnRow({
|
||||
const { data: atrzSeCodes } = useCodeList("ATRZSECD");
|
||||
|
||||
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
||||
id: row.aplnId,
|
||||
id: row.rowKey,
|
||||
disabled: dragDisabled,
|
||||
});
|
||||
|
||||
@@ -65,7 +65,7 @@ function SortableAplnRow({
|
||||
<Equal className="!size-6" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
<TableCell align="center">{row.aplnId}</TableCell>
|
||||
<TableCell align="center">{row.isNew ? "-" : (row.aplnId ?? "-")}</TableCell>
|
||||
<TableCell align="center">
|
||||
{isEditing ? (
|
||||
<Input
|
||||
|
||||
@@ -86,12 +86,13 @@ function ElaprTmpltList({ selectedTmpltId, onSelectTmplt }: ElaprTmpltListProps)
|
||||
|
||||
const handleFormSubmit = async (values: ElaprTmpltFormValues) => {
|
||||
if (dialogMode === "create") {
|
||||
await createMutation.mutateAsync({
|
||||
elaprTmpltId: values.elaprTmpltId,
|
||||
const created = await createMutation.mutateAsync({
|
||||
elaprTmpltNm: values.elaprTmpltNm,
|
||||
docSeComCd: values.docSeComCd || undefined,
|
||||
elaprTmpltExpln: values.elaprTmpltExpln || undefined,
|
||||
});
|
||||
onSelectTmplt(created);
|
||||
setRowSelection({ [created.elaprTmpltId]: true });
|
||||
} else if (dialogMode === "edit" && editingTmplt) {
|
||||
await updateMutation.mutateAsync({
|
||||
elaprTmpltId: editingTmplt.elaprTmpltId,
|
||||
|
||||
Reference in New Issue
Block a user