[as] feat: 결재선 검증 로직 수정
This commit is contained in:
@@ -16,7 +16,7 @@ export function validateAtrzOrder(rows: AtrzOrderValidateRow[]): string | null {
|
||||
const visibleRows = rows.filter((row) => !row.isDeleted);
|
||||
|
||||
const finalCount = visibleRows.filter((row) => row.atrzSeComCd === ATRZ_FINAL_CD).length;
|
||||
if (finalCount === 0) {
|
||||
if (visibleRows.length > 0 && finalCount === 0) {
|
||||
return "최종승인자는 반드시 등록해야 합니다.";
|
||||
}
|
||||
if (finalCount > 1) {
|
||||
@@ -52,7 +52,8 @@ export function validateAllRowsForSave(
|
||||
}
|
||||
|
||||
const visibleRows = getVisibleRows(rows);
|
||||
if (visibleRows.length === 0) {
|
||||
const hasDeletedDirtyRows = rows.some((row) => row.isDeleted && row.isDirty);
|
||||
if (visibleRows.length === 0 && !hasDeletedDirtyRows) {
|
||||
return "저장할 결재선이 없습니다.";
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
import { useMemo, useState } from "react";
|
||||
|
||||
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { getCoreRowModel, type RowSelectionState } from "@tanstack/react-table";
|
||||
|
||||
import { useDataTable } from "@/shared/lib";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
import { useDataTable, useMutationWrapper } from "@/shared/lib";
|
||||
import {
|
||||
type ElaprTmplt,
|
||||
elaprTmpltService,
|
||||
useCreateElaprTmplt,
|
||||
useDeleteElaprTmplt,
|
||||
useElaprTmpltPage,
|
||||
useUpdateElaprTmplt,
|
||||
} from "@/entities/elapr";
|
||||
@@ -26,6 +28,7 @@ interface ElaprTmpltListProps {
|
||||
|
||||
function ElaprTmpltList({ selectedTmpltId, onSelectTmplt }: ElaprTmpltListProps) {
|
||||
const { confirm } = useConfirm();
|
||||
const queryClient = useQueryClient();
|
||||
const [dialogMode, setDialogMode] = useState<"create" | "edit" | null>(null);
|
||||
const [editingTmplt, setEditingTmplt] = useState<ElaprTmplt | null>(null);
|
||||
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
||||
@@ -38,7 +41,14 @@ function ElaprTmpltList({ selectedTmpltId, onSelectTmplt }: ElaprTmpltListProps)
|
||||
|
||||
const createMutation = useCreateElaprTmplt();
|
||||
const updateMutation = useUpdateElaprTmplt();
|
||||
const deleteMutation = useDeleteElaprTmplt();
|
||||
const { mutateAsync: deleteTmplt } = useMutationWrapper({
|
||||
mutationFn: (elaprTmpltId: string) => elaprTmpltService.remove(elaprTmpltId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [ENDPOINT.AS_ELAPR_SERVICE.ELAPR_TMPLT],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const columns = useMemo(
|
||||
() =>
|
||||
@@ -49,13 +59,13 @@ function ElaprTmpltList({ selectedTmpltId, onSelectTmplt }: ElaprTmpltListProps)
|
||||
},
|
||||
onDelete: async (row) => {
|
||||
if (!(await confirm("선택한 결재서식을 삭제하시겠습니까?"))) return;
|
||||
await deleteMutation.mutateAsync(row.elaprTmpltId);
|
||||
await deleteTmplt(row.elaprTmpltId);
|
||||
if (selectedTmpltId === row.elaprTmpltId) {
|
||||
onSelectTmplt(null);
|
||||
}
|
||||
},
|
||||
}),
|
||||
[confirm, deleteMutation, onSelectTmplt, selectedTmpltId],
|
||||
[confirm, deleteTmplt, onSelectTmplt, selectedTmpltId],
|
||||
);
|
||||
|
||||
const { tableComponent } = useDataTable({
|
||||
|
||||
@@ -5,5 +5,6 @@ export { queryClient } from "./query-client";
|
||||
export { useAlertStore } from "./use-alert-store";
|
||||
export { useDataTable } from "./use-data-table";
|
||||
export { useMenuStore } from "./use-menu-store";
|
||||
export { useMutationWrapper } from "./use-mutation-wrapper";
|
||||
export { getDefaultFileKey, useTus } from "./use-tus";
|
||||
export { useUserStore } from "./use-user-store";
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useMutation, type UseMutationOptions } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
import { useAlertStore } from "./use-alert-store";
|
||||
|
||||
export const useMutationWrapper = <
|
||||
TData = unknown,
|
||||
TError = unknown,
|
||||
TVariables = void,
|
||||
TContext = unknown,
|
||||
>(
|
||||
mutationOptions: UseMutationOptions<TData, TError, TVariables, TContext>,
|
||||
) => {
|
||||
const alert = useAlertStore((state) => state.setMessage);
|
||||
return useMutation({
|
||||
...mutationOptions,
|
||||
onError: (error) => {
|
||||
let errorMessage = "";
|
||||
|
||||
if (error instanceof AxiosError) {
|
||||
if (error.response?.data?.message) errorMessage += `${error.response.data.message}\n`;
|
||||
if (error.response?.data?.errors[0]?.message)
|
||||
errorMessage += `${error.response.data.errors[0].message}\n`;
|
||||
}
|
||||
|
||||
alert(`${errorMessage}`);
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user