[as] feat: 결재선 관리 페이지 구현
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { client } from "@/shared/api/client";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
|
||||
import type { Code, CodeService } from "../model/code-interface";
|
||||
|
||||
async function getList(upCd: string): Promise<Code[]> {
|
||||
const response = await client.get<Code[]>(`${ENDPOINT.CMS_SERVICE.CODE}/${upCd}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function getListByUseYn(upCd: string, useYn: string): Promise<Code[]> {
|
||||
const response = await client.get<Code[]>(
|
||||
`${ENDPOINT.CMS_SERVICE.CODE}/${upCd}/${useYn}`,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function getCodeName(upCd: string, lwpoCd: string): Promise<string> {
|
||||
const response = await client.get<string>(
|
||||
`${ENDPOINT.CMS_SERVICE.CODE}/${upCd}/lwpoCd/${lwpoCd}`,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export const codeService = {
|
||||
getList,
|
||||
getListByUseYn,
|
||||
getCodeName,
|
||||
} satisfies CodeService;
|
||||
@@ -0,0 +1,36 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
|
||||
import { codeService } from "./code-service";
|
||||
|
||||
const codeBaseKey = [ENDPOINT.CMS_SERVICE.CODE] as const;
|
||||
|
||||
const CODE_STALE_TIME = 1000 * 60 * 10;
|
||||
|
||||
export function useCodeList(upCd: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: [...codeBaseKey, upCd],
|
||||
queryFn: () => codeService.getList(upCd!),
|
||||
enabled: Boolean(upCd),
|
||||
staleTime: CODE_STALE_TIME,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCodeListByUseYn(upCd: string | undefined, useYn: string) {
|
||||
return useQuery({
|
||||
queryKey: [...codeBaseKey, upCd, useYn],
|
||||
queryFn: () => codeService.getListByUseYn(upCd!, useYn),
|
||||
enabled: Boolean(upCd && useYn),
|
||||
staleTime: CODE_STALE_TIME,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCodeName(upCd: string | undefined, lwpoCd: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: [...codeBaseKey, upCd, "name", lwpoCd],
|
||||
queryFn: () => codeService.getCodeName(upCd!, lwpoCd!),
|
||||
enabled: Boolean(upCd && lwpoCd),
|
||||
staleTime: CODE_STALE_TIME,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export { codeService } from "./api/code-service";
|
||||
export { useCodeList, useCodeListByUseYn, useCodeName } from "./api/queries";
|
||||
export { findCodeLabel } from "./lib/find-code-label";
|
||||
export { UP_CD } from "./lib/up-cd-constants";
|
||||
export { CodeSelect } from "./ui/code-select";
|
||||
export type { Code, CodeService } from "./model/code-interface";
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { Code } from "../model/code-interface";
|
||||
|
||||
export function findCodeLabel(codes: Code[] | undefined, lwpoCd?: string): string {
|
||||
if (!lwpoCd) return "";
|
||||
if (!codes?.length) return lwpoCd;
|
||||
return codes.find((c) => c.lwpoCd === lwpoCd)?.lwpoCdNm ?? lwpoCd;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/** 결재선 관리 SPEC 상위코드 */
|
||||
export const UP_CD = {
|
||||
DOC_SE: "ASDOCSECD",
|
||||
ATRZ_SE: "ATRZSECD",
|
||||
} as const;
|
||||
@@ -0,0 +1,14 @@
|
||||
/** cms-service CodeResponseDto */
|
||||
export interface Code {
|
||||
lwpoCd: string;
|
||||
upCd: string;
|
||||
lwpoCdNm: string;
|
||||
unit?: string;
|
||||
prntLwpoCd?: string;
|
||||
}
|
||||
|
||||
export interface CodeService {
|
||||
getList(upCd: string): Promise<Code[]>;
|
||||
getListByUseYn(upCd: string, useYn: string): Promise<Code[]>;
|
||||
getCodeName(upCd: string, lwpoCd: string): Promise<string>;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
cn,
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@common/components";
|
||||
|
||||
import { useCodeList, useCodeListByUseYn } from "../api/queries";
|
||||
|
||||
interface CodeSelectProps extends React.ComponentPropsWithoutRef<typeof Select> {
|
||||
upCd: string;
|
||||
useYn?: string;
|
||||
placeholder?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
function CodeSelect({
|
||||
upCd,
|
||||
useYn,
|
||||
placeholder = "선택",
|
||||
className,
|
||||
...props
|
||||
}: CodeSelectProps) {
|
||||
const listQuery = useCodeList(useYn ? undefined : upCd);
|
||||
const listByUseYnQuery = useCodeListByUseYn(useYn ? upCd : undefined, useYn ?? "");
|
||||
|
||||
const codes = useYn ? listByUseYnQuery.data : listQuery.data;
|
||||
const isLoading = useYn ? listByUseYnQuery.isPending : listQuery.isPending;
|
||||
|
||||
return (
|
||||
<Select {...props} disabled={props.disabled || isLoading}>
|
||||
<SelectTrigger className={cn("w-[12rem]", className)}>
|
||||
<SelectValue placeholder={isLoading ? "로딩 중…" : placeholder} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{codes?.map((item) => (
|
||||
<SelectItem key={item.lwpoCd} value={item.lwpoCd}>
|
||||
{item.lwpoCdNm}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
|
||||
export { CodeSelect };
|
||||
Reference in New Issue
Block a user