251210_01_ENH : 프로젝트 수정, 에디터 구현중
This commit is contained in:
53
src/app/(pages)/(main)/ProjectTableColumn.tsx
Normal file
53
src/app/(pages)/(main)/ProjectTableColumn.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import {ProjectInfo} from "@/types/project";
|
||||
import {ColumnDef} from "@tanstack/react-table";
|
||||
import {Badge} from "@/components/ui/badge";
|
||||
import {cn, formatKst} from "@/lib/utils";
|
||||
import {PROJECT_STATUS_CLASS, PROJECT_STATUS_LABEL} from "@/const/projectConst";
|
||||
import {ItrntUserInfo} from "@/types/user";
|
||||
|
||||
export const getProjectColumns = (users:ItrntUserInfo[]): ColumnDef<ProjectInfo>[] => [
|
||||
{
|
||||
accessorKey: "prjctIdx",
|
||||
header: "No",
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: "prjctCd",
|
||||
header: "프로젝트 코드",
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: "prjctName",
|
||||
header: "프로젝트 명",
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: "prjctStatus",
|
||||
header: "진행 상태",
|
||||
cell: ({row}) => (
|
||||
<Badge className={cn("w-15 h-7 my-1.5", PROJECT_STATUS_CLASS[row.original.prjctStatus])}>
|
||||
{PROJECT_STATUS_LABEL[row.original.prjctStatus]}
|
||||
</Badge>
|
||||
) ,
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: "ownerDept",
|
||||
header: "담당 그룹",
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: "ownerFw",
|
||||
header: "담당 실사",
|
||||
enableSorting: true,
|
||||
cell: ({row}) => (
|
||||
users.find(u => u.userId === row.original.ownerFw)?.userNm ?? ""
|
||||
) ,
|
||||
},
|
||||
{
|
||||
accessorKey: "regDt",
|
||||
header: "등록일",
|
||||
cell: ({row}) => (formatKst(row.original.regDt ?? "", "date")),
|
||||
enableSorting: true,
|
||||
}
|
||||
];
|
||||
@@ -2,17 +2,17 @@ import MainLayout from "@/components/layout/MainLayout";
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import {CookieKeys} from "@/store/cookie/cookie-keys";
|
||||
import commonConst from "@/config/commonConst";
|
||||
import {FONT_SIZE} from "@/const/commonConst";
|
||||
|
||||
function parseFontSize(raw: string | undefined | null) {
|
||||
if (!raw) return commonConst.fontSizeMin;
|
||||
if (!raw) return FONT_SIZE.MIN;
|
||||
|
||||
const parsed = parseInt(raw, 10);
|
||||
if (Number.isNaN(parsed)) return commonConst.fontSizeMin;
|
||||
if (Number.isNaN(parsed)) return FONT_SIZE.MIN;
|
||||
|
||||
return Math.min(
|
||||
commonConst.fontSizeMax,
|
||||
Math.max(commonConst.fontSizeMin, parsed),
|
||||
FONT_SIZE.MAX,
|
||||
Math.max(FONT_SIZE.MIN, parsed),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
"use client";
|
||||
|
||||
import {useFontSizeValue} from "@/hooks/useFontSize";
|
||||
import {useEffect, useState} from "react";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
|
||||
import BodyTitle from "@/components/layout/BodyTitle";
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
import ProjectTitle from "@/components/layout/ProjectTitle";
|
||||
|
||||
const ListManagePage = () => {
|
||||
const fontSize = useFontSizeValue();
|
||||
const mounted = useMounted();
|
||||
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => setMounted(true), []);
|
||||
if (!mounted) return null;
|
||||
if (!mounted) return <LoadingOverlay force />;
|
||||
|
||||
return (
|
||||
<div>
|
||||
This is Manage List Page <span>{fontSize}</span>
|
||||
<div className="space-y-6 content-text-sm">
|
||||
<div>
|
||||
This is Manage List Page <span>{fontSize}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import {ColumnDef} from "@tanstack/react-table";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {Pencil, Trash2} from "lucide-react";
|
||||
import {UserTableInfo} from "@/types/user";
|
||||
import {UserInfo} from "@/types/user";
|
||||
import {formatKst} from "@/lib/utils";
|
||||
import {MultiSelectOption} from "@/components/ui/multi-select";
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +12,7 @@ export type UserColumnsActions = {
|
||||
onDelete: (userId: string) => void
|
||||
}
|
||||
|
||||
export const getUserColumns = (actions: UserColumnsActions): ColumnDef<UserTableInfo>[] => [
|
||||
export const getUserColumns = (actions: UserColumnsActions, userRoleArray:MultiSelectOption[]): ColumnDef<UserInfo>[] => [
|
||||
{
|
||||
accessorKey: "userId",
|
||||
header: "아이디",
|
||||
@@ -29,11 +31,16 @@ export const getUserColumns = (actions: UserColumnsActions): ColumnDef<UserTable
|
||||
{
|
||||
accessorKey: "userRole",
|
||||
header: "권한",
|
||||
cell: ({row}) => {
|
||||
const role = userRoleArray.filter((r) => r.value === String(row.original.userRole));
|
||||
return role.length > 0 ? role[0].label : String(row.original.userRole);
|
||||
},
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: "regDt",
|
||||
header: "등록일",
|
||||
cell: ({row}) => (formatKst(row.original.regDt ?? "", "date")),
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
'use client'
|
||||
|
||||
import {useEffect, useState} from "react";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {Input} from "@/components/ui/input";
|
||||
@@ -7,7 +8,7 @@ import { DataTable } from "@/components/data-table/DataTable";
|
||||
import { getUserColumns } from "./UserTableColumn";
|
||||
import _ from "lodash";
|
||||
import UserUpsertDialog from "@/components/dialog/UserUpsertDialog";
|
||||
import {UserInfo, UserInfoSaveRequest, UserTableInfo, UserUploadResponse} from "@/types/user";
|
||||
import {UserInfo, UserInfoSaveRequest, UserUploadResponse} from "@/types/user";
|
||||
import UserUploadDialog from "@/components/dialog/UserUploadDialog";
|
||||
import {useDialog} from "@/hooks/useDialog";
|
||||
import {downloadBase64File, downloadFile, formatKst} from "@/lib/utils";
|
||||
@@ -17,19 +18,21 @@ import {RoleInfo} from "@/types/role";
|
||||
import {DataVerification} from "@/types/common";
|
||||
import {apiError} from "@/lib/http-util";
|
||||
import {KriMultiSelect} from "@/components/common/KriAutoComplete";
|
||||
import commonConst from "@/config/commonConst";
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import {MultiSelectOption} from "@/components/ui/multi-select";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
|
||||
import {DEFAULT_COMPANY_NAME, EXTERNAL_USER_ROLE} from "@/const/userConst";
|
||||
|
||||
const UserManagePage = () => {
|
||||
const { showDialog } = useDialog();
|
||||
const mounted = useMounted();
|
||||
const { withLoadingAsync } = useLoading();
|
||||
const { auth } = useAuth();
|
||||
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [userList, setUserList] = useState<UserTableInfo[]>([]);
|
||||
const [viewList, setViewList] = useState<UserTableInfo[]>([]);
|
||||
const [selectedUserArray, setSelectedUserArray] = useState<UserTableInfo[]>([]);
|
||||
const [userList, setUserList] = useState<UserInfo[]>([]);
|
||||
const [viewList, setViewList] = useState<UserInfo[]>([]);
|
||||
const [selectedUserArray, setSelectedUserArray] = useState<UserInfo[]>([]);
|
||||
const [userCmpnArray, setUserCmpnArray] = useState<string[]>([]);
|
||||
const [userRoleArray, setUserRoleArray] = useState<MultiSelectOption[]>([]);
|
||||
|
||||
@@ -52,19 +55,7 @@ const UserManagePage = () => {
|
||||
const cmpnList = await nextApi.get<string[]>("/user/cmpn");
|
||||
setUserCmpnArray(cmpnList);
|
||||
|
||||
const userData: UserTableInfo[] = (await nextApi.get<UserInfo[]>("/user")).map((user) => {
|
||||
const role = roleList.filter((r) => r.roleCd === user.userRole);
|
||||
const roleName = role.length > 0 ? role[0].roleNm : String(user.userRole);
|
||||
return {
|
||||
userId: user.userId,
|
||||
userCmpn: user.userCmpn,
|
||||
userName: user.userName,
|
||||
userRole: roleName,
|
||||
regDt: formatKst(user.regDt ?? "", "date"),
|
||||
memo: user.memo ?? "",
|
||||
}
|
||||
});
|
||||
|
||||
const userData = await nextApi.get<UserInfo[]>("/user");
|
||||
setUserList(userData);
|
||||
|
||||
const cmpnArray = Array.from(
|
||||
@@ -159,14 +150,16 @@ const UserManagePage = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const columns = getUserColumns({
|
||||
onEdit: handleEdit,
|
||||
onDelete: handleDelete
|
||||
});
|
||||
const columns = getUserColumns(
|
||||
{
|
||||
onEdit: handleEdit,
|
||||
onDelete: handleDelete
|
||||
},
|
||||
userRoleArray
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
withLoadingAsync(setUserData);
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -183,7 +176,7 @@ const UserManagePage = () => {
|
||||
}
|
||||
|
||||
if(searchRole.length > 0){
|
||||
tempData = tempData.filter((row) => searchRole.includes(row.userRole));
|
||||
tempData = tempData.filter((row) => searchRole.includes(String(row.userRole)));
|
||||
}
|
||||
|
||||
setViewList(tempData);
|
||||
@@ -192,9 +185,11 @@ const UserManagePage = () => {
|
||||
const isInternal =
|
||||
mounted &&
|
||||
auth.user?.userRole != null &&
|
||||
auth.user.userRole < commonConst.externalUserRole
|
||||
auth.user.userRole < EXTERNAL_USER_ROLE
|
||||
|
||||
const userCmpn = auth.user?.userCmpn ?? commonConst.defaultCmpn;
|
||||
const userCmpn = auth.user?.userCmpn ?? DEFAULT_COMPANY_NAME;
|
||||
|
||||
if (!mounted) return <LoadingOverlay force />;
|
||||
|
||||
return (
|
||||
<div className="space-y-6 content-text-sm">
|
||||
@@ -223,7 +218,7 @@ const UserManagePage = () => {
|
||||
items={userRoleArray}
|
||||
value={searchRole}
|
||||
onChange={setSearchRole}
|
||||
getValue={(item) => item.label}
|
||||
getValue={(item) => item.value}
|
||||
getLabel={(item) => item.label}
|
||||
placeholder="사용자 권한"
|
||||
widthClassName="w-70"
|
||||
@@ -250,7 +245,6 @@ const UserManagePage = () => {
|
||||
data={viewList}
|
||||
isClient={true}
|
||||
selectMode='single'
|
||||
enableRowClickSelection={true}
|
||||
onRowSelectionChange={setSelectedUserArray}
|
||||
defaultPageSize={10}
|
||||
pageSizeOptions={[10, 20, 30, 50]}
|
||||
|
||||
@@ -1,8 +1,244 @@
|
||||
const MainPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
'use client'
|
||||
import {useEffect, useRef, useState} from "react";
|
||||
import BodyTitle from "@/components/layout/BodyTitle";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {DataTable} from "@/components/data-table/DataTable";
|
||||
import {getProjectColumns} from "./ProjectTableColumn";
|
||||
import {
|
||||
ProjectCreateRequest,
|
||||
ProjectInfo,
|
||||
ProjectListQuery,
|
||||
ProjectListRequest, ProjectOwnerResponse,
|
||||
} from "@/types/project";
|
||||
import {Input} from "@/components/ui/input";
|
||||
import {KriMultiSelect} from "@/components/common/KriAutoComplete";
|
||||
import {MultiSelectOption} from "@/components/ui/multi-select";
|
||||
import {PaginationState, SortingState} from "@tanstack/react-table";
|
||||
import {PageResponse} from "@/types/common";
|
||||
import ProjectCreateDialog from "@/components/dialog/ProjectCreateDialog";
|
||||
import {useDialog} from "@/hooks/useDialog";
|
||||
import {useLoading} from "@/hooks/useLoading";
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
import {SelectedProject} from "@/store/jotai/project";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
|
||||
import {FW_USER_ROLE} from "@/const/userConst";
|
||||
import {ProjectStatus} from "@/const/projectConst";
|
||||
import {useItrntUserList} from "@/hooks/useItrntUserList";
|
||||
|
||||
return (<div>Hello, Next.JS</div>)
|
||||
const MainPage = () => {
|
||||
const { users, isLoading } = useItrntUserList();
|
||||
const { showDialog } = useDialog();
|
||||
const { withLoadingAsync } = useLoading();
|
||||
const mounted = useMounted();
|
||||
const { auth } = useAuth();
|
||||
const { clearSelectedProject, setSelectedProject } = useSelectedProject();
|
||||
|
||||
const [statusArray, setStatusArray] = useState<MultiSelectOption[]>([]);
|
||||
const [deptArray, setDeptArray] = useState<string[]>([]);
|
||||
const [fwArray, setFwArray] = useState<string[]>([]);
|
||||
|
||||
const [searchText, setSearchText] = useState('');
|
||||
const [searchStatus, setSearchStatus] = useState<string[]>([]);
|
||||
const [searchDept, setSearchDept] = useState<string[]>([]);
|
||||
const [searchFw, setSearchFw] = useState<string[]>([]);
|
||||
|
||||
const [pagination, setPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 10 });
|
||||
const [sorting, setSorting] = useState<SortingState>([]);
|
||||
const [query, setQuery] = useState<ProjectListQuery>();
|
||||
|
||||
const [viewList, setViewList] = useState<ProjectInfo[]>([]);
|
||||
const [pageCount, setPageCount] = useState(0);
|
||||
const [totalCount, setTotalCount] = useState(0);
|
||||
|
||||
const columns = getProjectColumns(users);
|
||||
const userId = auth.user?.userId ?? "";
|
||||
const userRole = auth.user?.userRole ?? FW_USER_ROLE;
|
||||
|
||||
const handleSearchClick = () => {
|
||||
const searchStatusCode:ProjectStatus[] = searchStatus
|
||||
.map((value) => Number(value))
|
||||
.filter((v): v is ProjectStatus => v !== undefined);
|
||||
|
||||
setQuery({
|
||||
prjctText: searchText,
|
||||
prjctStatusList: searchStatusCode,
|
||||
ownerDeptList: searchDept,
|
||||
ownerFwList: searchFw,
|
||||
});
|
||||
|
||||
setPagination(prev => ({ ...prev, pageIndex: 0 }))
|
||||
}
|
||||
|
||||
const handleCreateClick = () => {
|
||||
showDialog('projectCreateDialog');
|
||||
}
|
||||
|
||||
const handleSubmit = async (data:ProjectCreateRequest): Promise<void> => {
|
||||
const projectInfo = await nextApi.put<ProjectInfo>("/project", data);
|
||||
setSelectedProject({
|
||||
prjctIdx: projectInfo.prjctIdx,
|
||||
prjctCd: projectInfo.prjctCd,
|
||||
prjctName: projectInfo.prjctName,
|
||||
ownerDept: projectInfo.ownerDept,
|
||||
ownerFw: projectInfo.ownerFw,
|
||||
} as SelectedProject);
|
||||
|
||||
window.location.href = `/project/info`;
|
||||
}
|
||||
|
||||
const handleClick = (projectInfo:ProjectInfo) => {
|
||||
setSelectedProject({
|
||||
prjctIdx: projectInfo.prjctIdx,
|
||||
prjctCd: projectInfo.prjctCd,
|
||||
prjctName: projectInfo.prjctName,
|
||||
ownerDept: projectInfo.ownerDept,
|
||||
ownerFw: projectInfo.ownerFw,
|
||||
} as SelectedProject);
|
||||
|
||||
window.location.href = `/list/manage`;
|
||||
}
|
||||
|
||||
// 중복 호출 방지(초기 mount에서 pagination/sorting 콜백이 각각 한번씩 날아오는 케이스 방어)
|
||||
const lastReqKeyRef = useRef<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
const reqKey = JSON.stringify({ query, pagination, sorting});
|
||||
if (lastReqKeyRef.current === reqKey) return;
|
||||
lastReqKeyRef.current = reqKey;
|
||||
|
||||
const sort = sorting?.[0];
|
||||
const searchBody: ProjectListRequest = {
|
||||
prjctText: query?.prjctText || "",
|
||||
prjctStatusList: query?.prjctStatusList || [],
|
||||
ownerDeptList: query?.ownerDeptList || [],
|
||||
ownerFwList: query?.ownerFwList || [],
|
||||
pageIndex: pagination.pageIndex,
|
||||
pageSize: pagination.pageSize,
|
||||
sortBy: sort?.id ?? "prjctIdx",
|
||||
sortDir: sort?.desc ? "desc" : "asc"
|
||||
}
|
||||
|
||||
withLoadingAsync(() =>
|
||||
nextApi.post<PageResponse<ProjectInfo>>("/project/list", searchBody)
|
||||
.then((r) => {
|
||||
setViewList(r.content);
|
||||
setTotalCount(r.totalElements);
|
||||
setPageCount(r.totalPages);
|
||||
})
|
||||
.catch(() => {
|
||||
setViewList([]);
|
||||
setTotalCount(0);
|
||||
setPageCount(0);
|
||||
})
|
||||
);
|
||||
|
||||
}, [query, pagination, sorting]);
|
||||
|
||||
useEffect(() => {
|
||||
clearSelectedProject();
|
||||
|
||||
const options: MultiSelectOption[] = Object.entries(ProjectStatus)
|
||||
.sort(([a], [b]) => Number(a) - Number(b))
|
||||
.map(([key, label]) => ({ value: key, label: String(label) }));
|
||||
|
||||
setStatusArray(options);
|
||||
|
||||
nextApi.get<ProjectOwnerResponse>("/project/owner-list")
|
||||
.then((res) => {
|
||||
setDeptArray(res.ownerDeptList);
|
||||
setFwArray(res.ownerFwList);
|
||||
});
|
||||
}, []);
|
||||
|
||||
if (!mounted || isLoading) return <LoadingOverlay force />;
|
||||
|
||||
return (
|
||||
<div className="space-y-6 content-text-sm">
|
||||
<BodyTitle titleText={"프로젝트"}/>
|
||||
|
||||
<div className="flex gap-2 items-center">
|
||||
<div className="flex flex-1 items-center gap-2">
|
||||
<Input
|
||||
placeholder="프로젝트 코드 Or 프로젝트 명"
|
||||
className="w-120 h-9 bg-white"
|
||||
value={searchText}
|
||||
onChange={(e) => setSearchText(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
handleSearchClick();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{
|
||||
userRole < FW_USER_ROLE &&
|
||||
<KriMultiSelect
|
||||
items={statusArray}
|
||||
value={searchStatus}
|
||||
onChange={setSearchStatus}
|
||||
getValue={(item) => item.value}
|
||||
getLabel={(item) => item.label}
|
||||
placeholder="진행 상태"
|
||||
widthClassName="w-60"
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
}
|
||||
<KriMultiSelect
|
||||
items={deptArray}
|
||||
value={searchDept}
|
||||
onChange={setSearchDept}
|
||||
placeholder="담당 그룹"
|
||||
widthClassName="w-60"
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
<KriMultiSelect
|
||||
items={fwArray}
|
||||
value={searchFw}
|
||||
onChange={setSearchFw}
|
||||
placeholder="담당 실사"
|
||||
widthClassName="w-60"
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
<Button
|
||||
className="content-text-lg"
|
||||
onClick={handleSearchClick}
|
||||
>
|
||||
검색
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
className="content-text-lg"
|
||||
onClick={handleCreateClick}
|
||||
>
|
||||
프로젝트 등록
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg border border-gray-200 overflow-hidden">
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={viewList}
|
||||
isClient={false}
|
||||
pageCount={pageCount}
|
||||
totalCount={totalCount}
|
||||
onPaginationChange={setPagination}
|
||||
onSortingChange={setSorting}
|
||||
selectMode='click-event'
|
||||
onRowClick={handleClick}
|
||||
pageSizeOptions={[10, 20, 30, 50]}
|
||||
getRowId={(row) => row.prjctCd} // row.id = userId
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ProjectCreateDialog
|
||||
users={users}
|
||||
ownerFw={userId}
|
||||
onSubmit={handleSubmit}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default MainPage;
|
||||
@@ -1,8 +1,480 @@
|
||||
const ProjectInfoPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
'use client'
|
||||
|
||||
return (<div>This is Project Info Page</div>)
|
||||
import {useEffect, useState} from 'react'
|
||||
import BodyTitle from '@/components/layout/BodyTitle'
|
||||
import {Button} from '@/components/ui/button'
|
||||
import {Input} from '@/components/ui/input'
|
||||
import {Label} from '@/components/ui/label'
|
||||
import {RadioGroup, RadioGroupItem} from '@/components/ui/radio-group'
|
||||
import {Checkbox} from '@/components/ui/checkbox'
|
||||
import {Tabs, TabsContent, TabsList, TabsTrigger} from '@/components/ui/tabs'
|
||||
import {KriMultiSelect, KriSingleSelect} from '@/components/common/KriAutoComplete'
|
||||
import {useDialog} from '@/hooks/useDialog'
|
||||
import ResultCodeDialog from '@/components/dialog/ResultCodeDialog'
|
||||
import {useMounted} from '@/hooks/useMounted'
|
||||
import {LoadingOverlay} from '@/components/common/LoadingOverlay'
|
||||
import {KonKiwiProjectInfo, ProjectInfo} from "@/types/project";
|
||||
import {
|
||||
PROJECT_STATUS_LABEL,
|
||||
PROJECT_STATUS_ORDER,
|
||||
ProjectStatus,
|
||||
SURVEY_TYPE_LABEL,
|
||||
SURVEY_TYPE_ORDER,
|
||||
SurveyType
|
||||
} from "@/const/projectConst";
|
||||
import {MultiSelectOption} from "@/components/ui/multi-select";
|
||||
import {FW_TEAM} from "@/const/userConst";
|
||||
import {useItrntUserList} from "@/hooks/useItrntUserList";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
import {UserInfo} from "@/types/user";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import {KriEditor} from "@/components/kri-editor";
|
||||
|
||||
|
||||
const defaultProjectInfo: Partial<ProjectInfo> = {
|
||||
prjctCd: '',
|
||||
prjctName: '',
|
||||
prjctStatus: 0,
|
||||
ownerDept: '',
|
||||
ownerFw: '',
|
||||
surveyTy: 0,
|
||||
surveyPrjctCd: '',
|
||||
surveyUrl: '',
|
||||
ff: false,
|
||||
useContactSenario: false,
|
||||
contactSenario: '',
|
||||
}
|
||||
|
||||
export default ProjectInfoPage;
|
||||
type ExternalTab = 'redirect' | 'api'
|
||||
|
||||
const ProjectInfoPage = () => {
|
||||
const mounted = useMounted();
|
||||
const { selectedProject } = useSelectedProject();
|
||||
const { isDialogOpen, showDialog, hideDialog } = useDialog();
|
||||
const { users, isLoading } = useItrntUserList();
|
||||
const { auth } = useAuth();
|
||||
|
||||
const [projectInfo, setProjectInfo] = useState<Partial<ProjectInfo>>(defaultProjectInfo);
|
||||
const [outsourceUserArray, setOutsourceUserArray] = useState<string[]>([]);
|
||||
|
||||
const [outsourceOptionArray, setOutsourceOptionArray] = useState<MultiSelectOption[]>([]);
|
||||
const [deptArray, setDeptArray] = useState<string[]>([]);
|
||||
const [fwArray, setFwArray] = useState<MultiSelectOption[]>([]);
|
||||
|
||||
const [surveyKeyword, setSurveyKeyword] = useState('');
|
||||
const debouncedKeyword = useDebouncedValue(surveyKeyword, 500);
|
||||
const [surveyProjectArray, setSurveyProjectArray] = useState<KonKiwiProjectInfo[]>([]);
|
||||
|
||||
const [externalTab, setExternalTab] = useState<ExternalTab>('redirect')
|
||||
|
||||
const internalSurvey = [SurveyType.KON, SurveyType.KIWI];
|
||||
const baseUrl = 'https://kcont.kric.com'
|
||||
const sidParam = 'sid=${$SID}'
|
||||
|
||||
const externalUrls = {
|
||||
redirect: {
|
||||
start: `${baseUrl}/redirect/start?${sidParam}`,
|
||||
complete: `${baseUrl}/redirect/complete?${sidParam}`,
|
||||
screen: `${baseUrl}/redirect/screen?${sidParam}`,
|
||||
quota: `${baseUrl}/redirect/quota?${sidParam}`,
|
||||
},
|
||||
api: {
|
||||
start: `${baseUrl}/api/external/start?${sidParam}`,
|
||||
complete: `${baseUrl}/api/external/complete?${sidParam}`,
|
||||
screen: `${baseUrl}/api/external/screen?${sidParam}`,
|
||||
quota: `${baseUrl}/api/external/quota?${sidParam}`,
|
||||
},
|
||||
} as const
|
||||
|
||||
const userTeam = auth.user?.userTeam ?? "";
|
||||
|
||||
const searchKonKiwiPrjct = async (keyword:string): Promise<void> => {
|
||||
const surveyType = projectInfo.surveyTy ?? SurveyType.NONE;
|
||||
if(internalSurvey.includes(surveyType) && userTeam){
|
||||
const isKiwi = surveyType === SurveyType.KON? 0 : 1;
|
||||
const res = await nextApi.get<KonKiwiProjectInfo[]>(
|
||||
`/kart/project-list/${projectInfo.itrntPrjctCd}/${userTeam}/${isKiwi}`,
|
||||
{ query: keyword ? { keyword } : {} }
|
||||
);
|
||||
|
||||
setSurveyProjectArray(res);
|
||||
}
|
||||
}
|
||||
|
||||
const handleChange = (field: keyof ProjectInfo, value: any) => {
|
||||
setProjectInfo((prev) => ({ ...prev, [field]: value }))
|
||||
}
|
||||
|
||||
const handleResultCodeClick = () => {
|
||||
showDialog('resultCodeDialog')
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!projectInfo.prjctName) {
|
||||
alert('프로젝트명을 입력해주세요.')
|
||||
return
|
||||
}
|
||||
// TODO: 저장 API
|
||||
}
|
||||
|
||||
const handleDeleteClick = async () => {
|
||||
if (confirm('복구 할 수 없습니다. 정말 삭제 하시겠습니까?')) {
|
||||
if(!selectedProject){
|
||||
alert("옳지 않은 요청입니다.");
|
||||
}
|
||||
else{
|
||||
await nextApi.del(`/project/${selectedProject.prjctIdx}`)
|
||||
}
|
||||
|
||||
window.location.href = `/`;
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if(selectedProject){
|
||||
nextApi.get<ProjectInfo>(`/project/info/${selectedProject.prjctIdx}`)
|
||||
.then((res) => { setProjectInfo(res)});
|
||||
|
||||
nextApi.get<UserInfo[]>(`/user/outsource`)
|
||||
.then((res) => {
|
||||
const outsourceOptions: MultiSelectOption[] = res
|
||||
.map(u => ({
|
||||
value: u.userId,
|
||||
label: `${u.userCmpn} / ${u.userName}(${u.userId})`,
|
||||
}));
|
||||
setOutsourceOptionArray(outsourceOptions)
|
||||
});
|
||||
|
||||
nextApi.get<string[]>(`/assign/prjct-outsource/${selectedProject.prjctIdx}`)
|
||||
.then((res) => setOutsourceUserArray(res));
|
||||
}
|
||||
}, [selectedProject])
|
||||
|
||||
useEffect(() => {
|
||||
if (projectInfo.surveyTy !== SurveyType.EXTERNAL) {
|
||||
setExternalTab('redirect')
|
||||
|
||||
if(projectInfo.surveyPrjctCd && internalSurvey.includes(projectInfo.surveyTy || SurveyType.NONE)){
|
||||
let surveyUrl = `/project/${projectInfo.surveyPrjctCd}/INDEX.asp?${sidParam}`;
|
||||
if(projectInfo.surveyTy === SurveyType.KON){
|
||||
surveyUrl = `https://kon.kric.com` + surveyUrl
|
||||
}
|
||||
else if(projectInfo.surveyTy === SurveyType.KIWI){
|
||||
surveyUrl = `https://kon.kiwisurvey.kr` + surveyUrl
|
||||
}
|
||||
|
||||
handleChange('surveyUrl', surveyUrl)
|
||||
}
|
||||
}
|
||||
}, [projectInfo.surveyTy, projectInfo.surveyPrjctCd])
|
||||
|
||||
useEffect(() => {
|
||||
let userTeams = Array.from(new Set(users.map(u => u.userTeam)));
|
||||
if(!userTeams.includes("T900")){ //TFT
|
||||
userTeams.push("T900");
|
||||
}
|
||||
userTeams = userTeams.sort((a, b) => a.localeCompare(b, "ko"));
|
||||
setDeptArray(userTeams);
|
||||
}, [users]);
|
||||
|
||||
useEffect(() => {
|
||||
const userOptions: MultiSelectOption[] = users
|
||||
.filter(u => u.userId == projectInfo.ownerFw || u.userTeam == FW_TEAM)
|
||||
.map(u => ({
|
||||
value: u.userId,
|
||||
label: u.userNm,
|
||||
}));
|
||||
setFwArray(userOptions);
|
||||
}, [users, projectInfo.ownerFw]);
|
||||
|
||||
useEffect(() => {
|
||||
const keyword = debouncedKeyword.trim();
|
||||
searchKonKiwiPrjct(keyword).then();
|
||||
}, [debouncedKeyword, projectInfo.surveyTy, userTeam]);
|
||||
|
||||
|
||||
if (!mounted) return <LoadingOverlay force />
|
||||
|
||||
return (
|
||||
<div className="min-h-full">
|
||||
<div className="space-y-6 pb-24 px-6">
|
||||
<div className="max-w-[900px]">
|
||||
<BodyTitle titleText="프로젝트 정보" />
|
||||
|
||||
{/* 1. 기본 정보 */}
|
||||
<div className="border rounded-lg p-6 space-y-5 bg-white mt-6">
|
||||
<h3 className="content-text-xl font-semibold">프로젝트 기본 정보</h3>
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label className="content-text-base">프로젝트 코드</Label>
|
||||
<Input value={projectInfo.prjctCd || ''} disabled className="bg-gray-100 h-9" />
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[1fr_auto] gap-3 items-end">
|
||||
<div className="space-y-2">
|
||||
<Label className="content-text-base">진행 상태</Label>
|
||||
<RadioGroup
|
||||
value={String(projectInfo.prjctStatus ?? ProjectStatus.WAITING)}
|
||||
onValueChange={(v) => handleChange('prjctStatus', Number(v) as ProjectStatus)}
|
||||
className="flex gap-4"
|
||||
>
|
||||
{PROJECT_STATUS_ORDER.map((s) => {
|
||||
const id = `status-${s}`;
|
||||
return (
|
||||
<div key={s} className="flex items-center space-x-2">
|
||||
<RadioGroupItem value={String(s)} id={id} />
|
||||
<Label htmlFor={id} className="font-normal cursor-pointer content-text-base">
|
||||
{PROJECT_STATUS_LABEL[s]}
|
||||
</Label>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</RadioGroup>
|
||||
</div>
|
||||
|
||||
<Button onClick={handleResultCodeClick} className="h-9 content-text-base whitespace-nowrap">
|
||||
결과 코드 설정
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label className="content-text-base">
|
||||
프로젝트 명<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
value={projectInfo.prjctName || ''}
|
||||
onChange={(e) => handleChange('prjctName', e.target.value)}
|
||||
placeholder="프로젝트명을 입력하세요"
|
||||
className="h-9"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label className="content-text-base">담당 그룹</Label>
|
||||
<KriSingleSelect
|
||||
items={deptArray}
|
||||
value={projectInfo.ownerDept || ''}
|
||||
onChange={(value) => handleChange('ownerDept', value)}
|
||||
placeholder="담당 그룹을 선택하세요"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label className="content-text-base">담당 실사</Label>
|
||||
<KriSingleSelect
|
||||
items={fwArray}
|
||||
value={projectInfo.ownerFw || ''}
|
||||
onChange={(value) => handleChange('ownerFw', value)}
|
||||
getValue={(item) => item.value}
|
||||
getLabel={(item) => item.label}
|
||||
placeholder="담당 실사를 선택하세요"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border rounded-lg p-6 space-y-4 bg-white mt-3">
|
||||
<h3 className="content-text-xl font-semibold">외주사</h3>
|
||||
<KriMultiSelect
|
||||
items={outsourceOptionArray}
|
||||
value={outsourceUserArray}
|
||||
onChange={(value) => console.log(value)}
|
||||
getValue={(item) => item.value}
|
||||
getLabel={(item) => item.label}
|
||||
placeholder="없음"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="border rounded-lg p-6 space-y-4 bg-white mt-3">
|
||||
<h3 className="content-text-xl font-semibold">설문 연동</h3>
|
||||
|
||||
<RadioGroup
|
||||
value={String(projectInfo.surveyTy ?? SurveyType.NONE)}
|
||||
onValueChange={(v) => handleChange('surveyTy', Number(v) as SurveyType)}
|
||||
className="flex gap-4"
|
||||
>
|
||||
{SURVEY_TYPE_ORDER.map((t) => {
|
||||
const id = `survey-${t}`; // 유니크 보장
|
||||
return (
|
||||
<div key={t} className="flex items-center space-x-2">
|
||||
<RadioGroupItem value={String(t)} id={id} />
|
||||
<Label htmlFor={id} className="font-normal cursor-pointer content-text-base">
|
||||
{SURVEY_TYPE_LABEL[t]}
|
||||
</Label>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</RadioGroup>
|
||||
|
||||
{(projectInfo.surveyTy === SurveyType.KON || projectInfo.surveyTy === SurveyType.KIWI) && (
|
||||
<div className="space-y-2">
|
||||
<Label className="content-text-base">{SURVEY_TYPE_LABEL[projectInfo.surveyTy]} 프로젝트</Label>
|
||||
<KriSingleSelect
|
||||
items={surveyProjectArray}
|
||||
value={projectInfo.surveyPrjctCd || ''}
|
||||
onChange={(value) => handleChange('surveyPrjctCd', value)}
|
||||
getValue={(item) => item.pkey}
|
||||
getLabel={(item) => `[${item.pkey}] ${item.title}`}
|
||||
searchMode={"inputOnly"}
|
||||
onSearchValueChange={setSurveyKeyword}
|
||||
placeholder="프로젝트를 선택하세요"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{projectInfo.surveyTy !== SurveyType.NONE && (
|
||||
<div className="space-y-2">
|
||||
<Label className="content-text-base">설문 URL</Label>
|
||||
<Input
|
||||
value={projectInfo.surveyUrl || ''}
|
||||
onChange={(e) => handleChange('surveyUrl', e.target.value)}
|
||||
placeholder="https://"
|
||||
className="h-9"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{projectInfo.surveyTy === SurveyType.EXTERNAL && (
|
||||
<div className="space-y-2">
|
||||
<Tabs value={externalTab} onValueChange={(v) => setExternalTab(v as ExternalTab)} className="w-full">
|
||||
<TabsList className="grid w-full grid-cols-2">
|
||||
<TabsTrigger value="redirect">리다이렉트</TabsTrigger>
|
||||
<TabsTrigger value="api">API</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="redirect" className="mt-4">
|
||||
<div className="border rounded-lg p-4 space-y-3 bg-gray-50">
|
||||
<div className="font-semibold">리다이렉트 URL</div>
|
||||
|
||||
<div className="grid gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 content-text-base">시작:</Label>
|
||||
<Input value={externalUrls.redirect.start} disabled className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 content-text-base">완료:</Label>
|
||||
<Input value={externalUrls.redirect.complete} disabled className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 content-text-base">스크린 아웃:</Label>
|
||||
<Input value={externalUrls.redirect.screen} disabled className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 content-text-base">쿼터 풀:</Label>
|
||||
<Input value={externalUrls.redirect.quota} disabled className="bg-white h-9" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="api" className="mt-4">
|
||||
<div className="border rounded-lg p-4 space-y-3 bg-gray-50">
|
||||
<div className="font-semibold">API URL</div>
|
||||
|
||||
<div className="grid gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 content-text-base">시작 API:</Label>
|
||||
<Input value={externalUrls.api.start} disabled className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 content-text-base">완료 API:</Label>
|
||||
<Input value={externalUrls.api.complete} disabled className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 content-text-base">스크린 API:</Label>
|
||||
<Input value={externalUrls.api.screen} disabled className="bg-white h-9" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="w-24 content-text-base">쿼터 API:</Label>
|
||||
<Input value={externalUrls.api.quota} disabled className="bg-white h-9" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-muted-foreground">API Method는 Post를 사용하시면 됩니다.</p>
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="border rounded-lg p-6 space-y-4 bg-white mt-3">
|
||||
<h3 className="content-text-xl font-semibold">기타 옵션</h3>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Checkbox
|
||||
id="ff"
|
||||
checked={projectInfo.ff || false}
|
||||
onCheckedChange={(checked) => handleChange('ff', checked === true)}
|
||||
/>
|
||||
<Label htmlFor="ff" className="font-normal cursor-pointer content-text-base">
|
||||
현장 면접 진행
|
||||
</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Checkbox
|
||||
id="useContactSenario"
|
||||
checked={projectInfo.useContactSenario || false}
|
||||
onCheckedChange={(checked) => handleChange('useContactSenario', checked === true)}
|
||||
/>
|
||||
<Label htmlFor="useContactSenario" className="font-normal cursor-pointer content-text-base">
|
||||
컨택 시나리오
|
||||
</Label>
|
||||
</div>
|
||||
|
||||
{projectInfo.useContactSenario && (
|
||||
<div className="ml-6 border rounded p-4 bg-gray-50 text-sm text-gray-600">
|
||||
<KriEditor
|
||||
value={projectInfo.contactSenario || ""}
|
||||
onChange={(str: string) => {handleChange('contactSenario', str); console.log(str)}}
|
||||
placeholder="컨택 시나리오를 작성해 주세요"
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="fixed left-0 right-0 bottom-0 z-[20] border-t bg-white/80 backdrop-blur shadow-sm">
|
||||
<div className="px-6 py-3">
|
||||
<div className="max-w-[836px] ml-0">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
variant="destructive"
|
||||
className="w-32 h-10 content-text-base"
|
||||
onClick={handleDeleteClick}
|
||||
>
|
||||
삭제
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} className="w-32 h-10 content-text-base">
|
||||
저장
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ResultCodeDialog
|
||||
open={isDialogOpen('resultCodeDialog')}
|
||||
onOpenChange={(open) => (open ? showDialog('resultCodeDialog') : hideDialog('resultCodeDialog'))}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ProjectInfoPage
|
||||
|
||||
@@ -5,7 +5,7 @@ import {Button} from "@/components/ui/button";
|
||||
import {Card, CardContent, CardHeader} from "@/components/ui/card";
|
||||
import {Input} from "@/components/ui/input";
|
||||
import React, {useEffect, useRef, useState} from "react";
|
||||
import {HttpError, nextApi} from "@/lib/http-client";
|
||||
import { nextApi } from "@/lib/http-client";
|
||||
import {useRouter, useSearchParams} from "next/navigation";
|
||||
import {LoginUser} from "@/types/auth";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
@@ -13,7 +13,7 @@ import { useLoading } from "@/hooks/useLoading";
|
||||
import { useStorage } from "@/hooks/useStorage"
|
||||
import { StorageKeys } from "@/store/storage/storage-keys";
|
||||
import {apiError} from "@/lib/http-util";
|
||||
import commonConst from "@/config/commonConst";
|
||||
import {NONE_HTTP_ERROR} from "@/const/commonConst";
|
||||
|
||||
const LoginPage = () => {
|
||||
const router = useRouter();
|
||||
@@ -71,7 +71,7 @@ const LoginPage = () => {
|
||||
if (err.status === 401 || err.status === 403) {
|
||||
setError("아이디 또는 비밀번호를 다시 확인해주세요.");
|
||||
}
|
||||
else if(err.code === commonConst.noneHttpError) {
|
||||
else if(err.code === NONE_HTTP_ERROR) {
|
||||
setError("알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해주세요.");
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -24,7 +24,10 @@ const LogoutPage = () => {
|
||||
logout();
|
||||
|
||||
try {
|
||||
await nextApi.post(`/logout/${userId}`);
|
||||
if(userId !== ""){
|
||||
const logoutRequestOptions = {autoLogoutOnAuthError: false};
|
||||
await nextApi.post(`/logout/${userId}`, null, logoutRequestOptions);
|
||||
}
|
||||
} catch (e) {
|
||||
const err = apiError(e);
|
||||
console.error(err.status, err.code, err.message);
|
||||
|
||||
46
src/app/api/assign/[[...slug]]/route.ts
Normal file
46
src/app/api/assign/[[...slug]]/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {DataVerification, RouteContext} from "@/types/common";
|
||||
import {createContactApi} from "@/lib/server-api";
|
||||
import {UserInfo, UserUploadResponse} from "@/types/user";
|
||||
import {errorToResponse} from "@/lib/http-util";
|
||||
|
||||
export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
try {
|
||||
const { slug = [] } = await context.params;
|
||||
const [action] = slug;
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if (action === "prjct-outsource") {
|
||||
const result = await contactApi.get<string[]>(`/assign/prjct-outsource/${slug[1]}`);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const PUT = async (req: NextRequest, context: RouteContext) => {
|
||||
try {
|
||||
const { slug = [] } = await context.params;
|
||||
const [action] = slug ?? [];
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if(!action){
|
||||
const body = await req.json().catch(() => null);
|
||||
if (!body) {
|
||||
return NextResponse.json(
|
||||
{ message: "요청 바디가 없습니다." },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
await contactApi.put(`/assign/prjct-outsource/${slug[1]}`, body);
|
||||
return new NextResponse(null, { status: 204 });
|
||||
}
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
}
|
||||
1
src/app/api/external/[[...slug]]/route.ts
vendored
Normal file
1
src/app/api/external/[[...slug]]/route.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
//외부 설문에 뎐동 되는 API
|
||||
35
src/app/api/intranet/[[...slug]]/route.ts
Normal file
35
src/app/api/intranet/[[...slug]]/route.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {RouteContext} from "@/types/common";
|
||||
import {createContactApi, createIntranetApi} from "@/lib/server-api";
|
||||
import {IntranetProjectSearchResponse, ProjectInfo, ProjectOwnerResponse} from "@/types/project";
|
||||
import {errorToResponse} from "@/lib/http-util";
|
||||
import {ItrntUserInfo} from "@/types/user";
|
||||
|
||||
export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
try {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const {slug = []} = await context.params;
|
||||
const [action] = slug;
|
||||
const itrntApi = await createIntranetApi();
|
||||
|
||||
if(action === "project"){
|
||||
const keyword = (searchParams.get("keyword") ?? "").trim();
|
||||
const result = await itrntApi.get<IntranetProjectSearchResponse[]>(
|
||||
`/project/search/top10`,
|
||||
{ query: keyword ? { keyword } : {} }
|
||||
);
|
||||
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if(action === "user-list"){
|
||||
const result = await itrntApi.get<ItrntUserInfo[]>(`/user/list`);
|
||||
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
};
|
||||
28
src/app/api/kart/[[...slug]]/route.ts
Normal file
28
src/app/api/kart/[[...slug]]/route.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {RouteContext} from "@/types/common";
|
||||
import {createKartApi} from "@/lib/server-api";
|
||||
import {KonKiwiProjectInfo} from "@/types/project";
|
||||
import {errorToResponse} from "@/lib/http-util";
|
||||
|
||||
export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
try {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const {slug = []} = await context.params;
|
||||
const [action] = slug;
|
||||
const kartApi = await createKartApi();
|
||||
|
||||
if(action === "project-list" && slug.length === 4){
|
||||
const keyword = (searchParams.get("keyword") ?? "").trim();
|
||||
const result = await kartApi.get<KonKiwiProjectInfo[]>(
|
||||
`/project/list/${slug[1]}/${slug[2]}/${slug[3]}`,
|
||||
{ query: keyword ? { keyword } : {} }
|
||||
);
|
||||
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
};
|
||||
@@ -19,7 +19,6 @@ export async function POST(
|
||||
: "/auth/logout/";
|
||||
|
||||
await contactApi.post<boolean>(url);
|
||||
|
||||
const res = NextResponse.json({ ok: true });
|
||||
|
||||
res.cookies.set("access_token", "", {
|
||||
|
||||
@@ -1,15 +1,38 @@
|
||||
import {NextRequest} from "next/server";
|
||||
import {createContactApi} from "@/lib/server-api";
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {createContactApi, createIntranetApi} from "@/lib/server-api";
|
||||
import {errorToResponse} from "@/lib/http-util";
|
||||
import {RouteContext} from "@/types/common";
|
||||
import {PageResponse, RouteContext} from "@/types/common";
|
||||
import {IntranetProjectSearchResponse, ProjectInfo, ProjectOwnerResponse} from "@/types/project";
|
||||
|
||||
export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
try {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const {slug = []} = await context.params;
|
||||
const [action] = slug;
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if(action === "owner-list"){
|
||||
const result = await contactApi.get<ProjectOwnerResponse>("/project/owner-list");
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if(action === "top"){
|
||||
const keyword = (searchParams.get("keyword") ?? "").trim();
|
||||
const result = await contactApi.get<ProjectInfo[]>(
|
||||
`/project/top/${slug[1]}`,
|
||||
{ query: keyword ? { keyword } : {} }
|
||||
);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if(action === "info"){
|
||||
const result = await contactApi.get<ProjectInfo>(
|
||||
`/project/${slug[1]}`,
|
||||
);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
@@ -21,7 +44,20 @@ export const POST = async (req: NextRequest, context: RouteContext) => {
|
||||
const [action] = slug;
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if(action === "list"){
|
||||
const body = await req.json().catch(() => null);
|
||||
if (!body) {
|
||||
return NextResponse.json(
|
||||
{ message: "요청 바디가 없습니다." },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await contactApi.post<PageResponse<ProjectInfo>>("/project/list", body);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
@@ -33,7 +69,20 @@ export const PUT = async (req: NextRequest, context: RouteContext) => {
|
||||
const [action] = slug;
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if(!action){
|
||||
const body = await req.json().catch(() => null);
|
||||
if (!body) {
|
||||
return NextResponse.json(
|
||||
{ message: "요청 바디가 없습니다." },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await contactApi.put("/project", body);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
@@ -45,7 +94,7 @@ export const PATCH = async (req: NextRequest, context: RouteContext) => {
|
||||
const [action] = slug;
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
@@ -57,7 +106,12 @@ export const DELETE = async (req: NextRequest, context: RouteContext) => {
|
||||
const [action] = slug;
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if(slug.length === 1){
|
||||
await contactApi.del<void>(`/project/${slug[0]}`);
|
||||
return new NextResponse(null, { status: 204 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if (!action) {
|
||||
const result = await contactApi.get<UserInfo[]>("/user");
|
||||
if(action === "outsource"){
|
||||
const result = await contactApi.get<UserInfo[]>("/user/outsource");
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if (!action) {
|
||||
const result = await contactApi.get<UserInfo[]>("/user");
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { Metadata } from "next";
|
||||
import {Geist, Geist_Mono} from "next/font/google";
|
||||
import { AppProvider } from "@/components/providers/AppProvider";
|
||||
import "./globals.css";
|
||||
import {Toaster} from "sonner";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
@@ -25,6 +26,7 @@ const RootLayout = ({ children }: { children: React.ReactNode}) => {
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
<AppProvider>{children}</AppProvider>
|
||||
<Toaster />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
@@ -9,6 +9,7 @@ type BaseProps<T> = {
|
||||
items: T[]
|
||||
searchable?: boolean
|
||||
searchMode?: "filter" | "inputOnly";
|
||||
defaultSearchValue?: string;
|
||||
onSearchValueChange?: (value: string) => void;
|
||||
placeholder?: string
|
||||
widthClassName?: string
|
||||
@@ -16,123 +17,164 @@ type BaseProps<T> = {
|
||||
className?: string
|
||||
getValue?: (item: T) => string
|
||||
getLabel?: (item: T) => string
|
||||
|
||||
/** ✅ 옵션: 원본 item을 option.info에 실어둘지 */
|
||||
withInfo?: boolean
|
||||
}
|
||||
|
||||
type KriMultiSelectProps<T> = BaseProps<T> & {
|
||||
type KriMultiSelectProps<T = unknown> = BaseProps<T> & {
|
||||
value: string[]
|
||||
onChange: (value: string[]) => void
|
||||
/** 최대 선택 개수 제한 (없으면 무제한) */
|
||||
maxCount?: number
|
||||
maxSelected?: number
|
||||
hideSelectAll?: boolean
|
||||
|
||||
/** ✅ withInfo=true일 때만 의미 있게 쓰면 됨 */
|
||||
onItemsChange?: (items: T[]) => void
|
||||
onOptionsChange?: (options: MultiSelectOption<T>[]) => void
|
||||
}
|
||||
|
||||
export function KriMultiSelect<T>({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = "filter",
|
||||
onSearchValueChange,
|
||||
maxCount = 1,
|
||||
maxSelected,
|
||||
hideSelectAll = false,
|
||||
placeholder = 'Select options',
|
||||
widthClassName,
|
||||
heightClassName,
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
}: KriMultiSelectProps<T>) {
|
||||
const extractValue = React.useCallback((item: T) => (getValue ? getValue(item) : String(item)), [getValue])
|
||||
const extractLabel = React.useCallback((item: T) => (getLabel ? getLabel(item) : String(item)), [getLabel])
|
||||
|
||||
const options = React.useMemo<MultiSelectOption[]>(
|
||||
() =>
|
||||
items.map((item) => ({
|
||||
value: extractValue(item),
|
||||
label: extractLabel(item),
|
||||
})),
|
||||
[items, extractValue, extractLabel]
|
||||
export function KriMultiSelect<T = unknown>({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = "filter",
|
||||
defaultSearchValue = "",
|
||||
onSearchValueChange,
|
||||
maxCount = 1,
|
||||
maxSelected,
|
||||
hideSelectAll = false,
|
||||
placeholder = 'Select options',
|
||||
widthClassName,
|
||||
heightClassName,
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
withInfo = false,
|
||||
onItemsChange,
|
||||
onOptionsChange,
|
||||
}: KriMultiSelectProps<T>) {
|
||||
const extractValue = React.useCallback(
|
||||
(item: T) => (getValue ? getValue(item) : String(item)),
|
||||
[getValue]
|
||||
)
|
||||
const extractLabel = React.useCallback(
|
||||
(item: T) => (getLabel ? getLabel(item) : String(item)),
|
||||
[getLabel]
|
||||
)
|
||||
|
||||
const options = React.useMemo<MultiSelectOption<T>[]>(() => {
|
||||
return items.map((item) => ({
|
||||
value: extractValue(item),
|
||||
label: extractLabel(item),
|
||||
...(withInfo ? { info: item } : {}), // ✅ 필요할 때만 info를 실음
|
||||
}))
|
||||
}, [items, extractValue, extractLabel, withInfo])
|
||||
|
||||
return (
|
||||
<div className={cn(widthClassName, heightClassName, "flex-none overflow-hidden")}>
|
||||
<MultiSelect
|
||||
options={options}
|
||||
defaultValue={value}
|
||||
onValueChange={onChange}
|
||||
maxSelected={maxSelected}
|
||||
placeholder={placeholder}
|
||||
className={cn("bg-white content-text-lg", className)}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
maxCount={maxCount}
|
||||
hideSelectAll={hideSelectAll}
|
||||
autoSize
|
||||
singleLine
|
||||
resetOnDefaultValueChange
|
||||
deduplicateOptions
|
||||
/>
|
||||
</div>
|
||||
<div className={cn(widthClassName, heightClassName, "flex-none overflow-hidden")}>
|
||||
<MultiSelect<T>
|
||||
options={options}
|
||||
defaultValue={value}
|
||||
onValueChange={onChange}
|
||||
onOptionChange={onOptionsChange}
|
||||
onInfoChange={onItemsChange}
|
||||
maxSelected={maxSelected}
|
||||
placeholder={placeholder}
|
||||
className={cn("bg-white content-text-lg", className)}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
defaultSearchValue={defaultSearchValue}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
maxCount={maxCount}
|
||||
hideSelectAll={hideSelectAll}
|
||||
autoSize
|
||||
singleLine
|
||||
resetOnDefaultValueChange
|
||||
deduplicateOptions
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
type KriSingleSelectProps<T> = BaseProps<T> & {
|
||||
type KriSingleSelectProps<T = unknown> = BaseProps<T> & {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
onItemChange?: (item: T | null) => void
|
||||
onOptionChange?: (option: MultiSelectOption<T> | null) => void
|
||||
preventDeselect?: boolean;
|
||||
hideOptionCheck?: boolean;
|
||||
}
|
||||
|
||||
export function KriSingleSelect<T>({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = "filter",
|
||||
onSearchValueChange,
|
||||
placeholder = 'Select an option',
|
||||
heightClassName,
|
||||
widthClassName,
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
}: KriSingleSelectProps<T>) {
|
||||
const extractValue = React.useCallback((item: T) => (getValue ? getValue(item) : String(item)), [getValue])
|
||||
const extractLabel = React.useCallback((item: T) => (getLabel ? getLabel(item) : String(item)), [getLabel])
|
||||
|
||||
const options = React.useMemo<MultiSelectOption[]>(
|
||||
() =>
|
||||
items.map((item) => ({
|
||||
value: extractValue(item),
|
||||
label: extractLabel(item),
|
||||
})),
|
||||
[items, extractValue, extractLabel]
|
||||
export function KriSingleSelect<T = unknown>({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = "filter",
|
||||
defaultSearchValue = "",
|
||||
onSearchValueChange,
|
||||
placeholder = 'Select an option',
|
||||
heightClassName,
|
||||
widthClassName,
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
withInfo = false,
|
||||
onItemChange,
|
||||
onOptionChange,
|
||||
preventDeselect = false,
|
||||
hideOptionCheck = false,
|
||||
}: KriSingleSelectProps<T>) {
|
||||
const extractValue = React.useCallback(
|
||||
(item: T) => (getValue ? getValue(item) : String(item)),
|
||||
[getValue]
|
||||
)
|
||||
const extractLabel = React.useCallback(
|
||||
(item: T) => (getLabel ? getLabel(item) : String(item)),
|
||||
[getLabel]
|
||||
)
|
||||
|
||||
const defaultValue = React.useMemo(() => (value ? [value] : []), [value]);
|
||||
const options = React.useMemo<MultiSelectOption<T>[]>(() => {
|
||||
return items.map((item) => ({
|
||||
value: extractValue(item),
|
||||
label: extractLabel(item),
|
||||
...(withInfo ? { info: item } : {}),
|
||||
}))
|
||||
}, [items, extractValue, extractLabel, withInfo])
|
||||
|
||||
const defaultValue = React.useMemo(() => (value ? [value] : []), [value])
|
||||
|
||||
return (
|
||||
<div className={cn(widthClassName, heightClassName, "flex-none overflow-hidden")}>
|
||||
<MultiSelect
|
||||
options={options}
|
||||
defaultValue={defaultValue}
|
||||
onValueChange={(next) => onChange(next.at(-1) ?? '')}
|
||||
selectionMode="single"
|
||||
maxCount={1}
|
||||
maxSelected={1}
|
||||
placeholder={placeholder}
|
||||
className={cn("bg-white content-text-lg", className)}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
hideSelectAll
|
||||
autoSize
|
||||
singleLine
|
||||
closeOnSelect
|
||||
resetOnDefaultValueChange
|
||||
deduplicateOptions
|
||||
/>
|
||||
</div>
|
||||
<div className={cn(widthClassName, heightClassName, "flex-none overflow-hidden")}>
|
||||
<MultiSelect<T>
|
||||
options={options}
|
||||
defaultValue={defaultValue}
|
||||
onValueChange={(next) => onChange(next[0] ?? '')}
|
||||
onOptionChange={(opts) => {
|
||||
const opt = opts[0] ?? null
|
||||
onOptionChange?.(opt)
|
||||
onItemChange?.((withInfo ? (opt?.info ?? null) : null))
|
||||
}}
|
||||
selectionMode="single"
|
||||
maxCount={1}
|
||||
maxSelected={1}
|
||||
placeholder={placeholder}
|
||||
className={cn("bg-white content-text-lg", className)}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
defaultSearchValue={defaultSearchValue}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
preventDeselect={preventDeselect}
|
||||
hideOptionCheck={hideOptionCheck}
|
||||
hideSelectAll
|
||||
autoSize
|
||||
singleLine
|
||||
closeOnSelect
|
||||
resetOnDefaultValueChange
|
||||
deduplicateOptions
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
import { useAtomValue } from "jotai";
|
||||
import { loadingAtom } from "@/store/jotai/loading";
|
||||
|
||||
export function LoadingOverlay() {
|
||||
export function LoadingOverlay({ force = false }: { force?: boolean }) {
|
||||
const isLoading = useAtomValue(loadingAtom);
|
||||
|
||||
if (!isLoading) return null;
|
||||
if (!force && !isLoading) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[9999] bg-black/70 flex items-center justify-center">
|
||||
|
||||
@@ -30,6 +30,7 @@ import { usePagination } from './hooks/usePagination'
|
||||
import { DataTableProps, DataTableColumn } from './DataTable.type'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
import {usePreventClickOnDrag} from "@/components/data-table/hooks/usePreventClickOnDrag";
|
||||
|
||||
export function DataTable<TData>({
|
||||
columns,
|
||||
@@ -42,8 +43,8 @@ export function DataTable<TData>({
|
||||
onPaginationChange: onServerPaginationChange,
|
||||
onSortingChange: onServerSortingChange,
|
||||
selectMode = 'none',
|
||||
onRowClick,
|
||||
onRowSelectionChange,
|
||||
enableRowClickSelection = false,
|
||||
defaultPageSize = 10,
|
||||
pageSizeOptions = [5, 10, 25, 50],
|
||||
paginationItemsToDisplay = 5
|
||||
@@ -60,6 +61,10 @@ export function DataTable<TData>({
|
||||
// Row selection state
|
||||
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
|
||||
|
||||
const drag = usePreventClickOnDrag(6);
|
||||
|
||||
const isNotSelection = !['none', 'click-event'].includes(selectMode);
|
||||
|
||||
// 서버 페이지네이션일 때 부모에게 알림
|
||||
useEffect(() => {
|
||||
if (!isClient && onServerPaginationChange) {
|
||||
@@ -76,7 +81,7 @@ export function DataTable<TData>({
|
||||
|
||||
// Row selection 변경 시 부모에게 알림
|
||||
useEffect(() => {
|
||||
if (selectMode !== 'none' && onRowSelectionChange) {
|
||||
if (isNotSelection && onRowSelectionChange) {
|
||||
const selectedRows = table
|
||||
.getSelectedRowModel()
|
||||
.rows.map(row => row.original)
|
||||
@@ -86,7 +91,7 @@ export function DataTable<TData>({
|
||||
|
||||
// selectMode에 따라 select column 추가
|
||||
const enhancedColumns: DataTableColumn<TData, any>[] = [
|
||||
...(selectMode !== 'none'
|
||||
...(isNotSelection
|
||||
? [
|
||||
{
|
||||
id: 'select',
|
||||
@@ -125,13 +130,23 @@ export function DataTable<TData>({
|
||||
|
||||
// Row 클릭 핸들러
|
||||
const handleRowClick = (row: any) => {
|
||||
if (!enableRowClickSelection || selectMode === 'none') return
|
||||
switch (selectMode) {
|
||||
case 'none':
|
||||
return
|
||||
|
||||
if (selectMode === 'single') {
|
||||
table.resetRowSelection()
|
||||
row.toggleSelected(true)
|
||||
} else {
|
||||
row.toggleSelected(!row.getIsSelected())
|
||||
case 'click-event':
|
||||
if (!onRowClick) return
|
||||
onRowClick(row.original)
|
||||
return
|
||||
|
||||
case 'single':
|
||||
table.resetRowSelection()
|
||||
row.toggleSelected(true)
|
||||
return
|
||||
|
||||
default: // 'multi' 등
|
||||
row.toggleSelected(!row.getIsSelected())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +159,7 @@ export function DataTable<TData>({
|
||||
pagination,
|
||||
rowSelection
|
||||
},
|
||||
enableRowSelection: selectMode !== 'none',
|
||||
enableRowSelection: isNotSelection,
|
||||
onRowSelectionChange: setRowSelection,
|
||||
onSortingChange: setSorting,
|
||||
onPaginationChange: setPagination,
|
||||
@@ -218,11 +233,15 @@ export function DataTable<TData>({
|
||||
<TableRow
|
||||
key={row.id}
|
||||
data-state={row.getIsSelected() && 'selected'}
|
||||
onClick={() => handleRowClick(row)}
|
||||
onPointerDown={drag.onPointerDown}
|
||||
onPointerMove={drag.onPointerMove}
|
||||
onPointerUp={drag.onPointerUp}
|
||||
onPointerCancel={drag.onPointerCancel}
|
||||
onClick={drag.wrapClick(() => handleRowClick(row))}
|
||||
className={cn(
|
||||
'content-text-base',
|
||||
'[&>td]:py-0 [&>td]:px-2',
|
||||
enableRowClickSelection && selectMode !== 'none' && 'cursor-pointer',
|
||||
selectMode !== 'none' && 'cursor-pointer',
|
||||
'data-[state=selected]:bg-slate-100 data-[state=selected]:font-semibold',
|
||||
shouldHighlight && 'bg-emerald-50',
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ColumnDef, PaginationState, SortingState } from '@tanstack/react-table'
|
||||
|
||||
export type SelectMode = 'none' | 'single' | 'multi'
|
||||
export type SelectMode = 'none' | 'click-event' | 'single' | 'multi'
|
||||
|
||||
export type DataTableColumn<TData, TValue = unknown> = ColumnDef<TData, TValue> & {
|
||||
enableSorting?: boolean // 정렬 가능 여부 (기본값: false)
|
||||
@@ -33,10 +33,10 @@ export interface DataTableProps<TData> {
|
||||
onPaginationChange?: (pagination: PaginationState) => void
|
||||
onSortingChange?: (sorting: SortingState) => void
|
||||
|
||||
// 선택 모드
|
||||
selectMode?: SelectMode // 'none' | 'single' | 'multi' (기본값: 'none')
|
||||
// 선택 모드
|
||||
selectMode?: SelectMode // 'none' | 'click-event' | 'single' | 'multi' (기본값: 'none')
|
||||
onRowClick?: (selectedRows: TData) => void
|
||||
onRowSelectionChange?: (selectedRows: TData[]) => void
|
||||
enableRowClickSelection?: boolean // row 클릭 시 select 여부 (기본값: false)
|
||||
|
||||
// 페이지네이션 설정
|
||||
defaultPageSize?: number
|
||||
|
||||
48
src/components/data-table/hooks/usePreventClickOnDrag.ts
Normal file
48
src/components/data-table/hooks/usePreventClickOnDrag.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import * as React from "react";
|
||||
|
||||
export const usePreventClickOnDrag = (thresholdPx = 6) => {
|
||||
const s = React.useRef({ x: 0, y: 0, dragging: false });
|
||||
|
||||
const onPointerDown = React.useCallback((e: React.PointerEvent) => {
|
||||
// 좌클릭만
|
||||
if (e.button !== 0) return;
|
||||
s.current.x = e.clientX;
|
||||
s.current.y = e.clientY;
|
||||
s.current.dragging = false;
|
||||
}, []);
|
||||
|
||||
const onPointerMove = React.useCallback(
|
||||
(e: React.PointerEvent) => {
|
||||
// 누르고 있을 때만
|
||||
if (e.buttons === 0) return;
|
||||
|
||||
const dx = e.clientX - s.current.x;
|
||||
const dy = e.clientY - s.current.y;
|
||||
|
||||
if (dx * dx + dy * dy >= thresholdPx * thresholdPx) {
|
||||
s.current.dragging = true;
|
||||
}
|
||||
},
|
||||
[thresholdPx]
|
||||
);
|
||||
|
||||
const onPointerUp = React.useCallback(() => {
|
||||
// click은 pointerup 다음에 발생하므로 "다음 tick"에 false로 복구
|
||||
setTimeout(() => {
|
||||
s.current.dragging = false;
|
||||
}, 0);
|
||||
}, []);
|
||||
|
||||
const wrapClick =
|
||||
(fn: () => void) =>
|
||||
(e: React.MouseEvent) => {
|
||||
if (s.current.dragging) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
fn();
|
||||
};
|
||||
|
||||
return { onPointerDown, onPointerMove, onPointerUp, onPointerCancel: onPointerUp, wrapClick };
|
||||
}
|
||||
269
src/components/dialog/ProjectCreateDialog.tsx
Normal file
269
src/components/dialog/ProjectCreateDialog.tsx
Normal file
@@ -0,0 +1,269 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect } from 'react'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from "@/components/ui/dialog";
|
||||
import {Label} from "@/components/ui/label";
|
||||
import {Input} from "@/components/ui/input";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {KriSingleSelect} from "@/components/common/KriAutoComplete";
|
||||
import {useDialog} from "@/hooks/useDialog";
|
||||
import type {DialogId} from "@/store/jotai/dialog";
|
||||
import {NONE_HTTP_ERROR, UNKNOWN_HTTP_ERROR} from "@/const/commonConst";
|
||||
import {apiError} from "@/lib/http-util";
|
||||
import {IntranetProjectSearchResponse, ProjectCreateRequest} from "@/types/project";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {PROJECT_NAME_REGEX} from "@/const/projectConst";
|
||||
import {FW_TEAM, USER_NAME_REGEX} from "@/const/userConst";
|
||||
import {MultiSelectOption} from "@/components/ui/multi-select";
|
||||
import {ItrntUserInfo} from "@/types/user";
|
||||
|
||||
export type ProjectCreateDialogProps = {
|
||||
/** Jotai로 관리할 다이얼로그 ID (기본값: 'userUpsertDialog') */
|
||||
dialogId?: DialogId
|
||||
|
||||
/** 필요하면 여전히 외부에서 open 제어도 가능하게 */
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
users:ItrntUserInfo[]
|
||||
ownerFw: string;
|
||||
onSubmit: (data: ProjectCreateRequest) => void | Promise<void>
|
||||
}
|
||||
|
||||
|
||||
|
||||
const ProjectCreateDialog = ({
|
||||
dialogId = 'projectCreateDialog',
|
||||
open,
|
||||
onOpenChange,
|
||||
users,
|
||||
ownerFw,
|
||||
onSubmit,
|
||||
}:ProjectCreateDialogProps) => {
|
||||
const defaultProjectInfo:ProjectCreateRequest = {
|
||||
prjctName: "",
|
||||
itrntPrjctCd: "",
|
||||
ownerDept: "",
|
||||
ownerFw: ownerFw,
|
||||
}
|
||||
const { isDialogOpen, showDialog, hideDialog } = useDialog();
|
||||
const [deptArray, setDeptArray] = useState<string[]>([]);
|
||||
const [fwArray, setFwArray] = useState<MultiSelectOption[]>([]);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [formData, setFormData] = useState<ProjectCreateRequest>(defaultProjectInfo);
|
||||
|
||||
const [itrntKeyword, setItrntKeyword] = useState('');
|
||||
const debouncedKeyword = useDebouncedValue(itrntKeyword, 500);
|
||||
const [itrntPrjctArray, setItrntPrjctArray] = useState<IntranetProjectSearchResponse[]>([]);
|
||||
|
||||
// 🔹 실제로 Dialog에 넘길 open 값 (외부 open 있으면 우선)
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId);
|
||||
|
||||
// 🔹 실제 onOpenChange 핸들러 (외부 콜백 + jotai 둘 다 처리)
|
||||
const handleOpenChange = (nextOpen: boolean) => {
|
||||
// 1) 외부에서 넘겨준 onOpenChange 먼저 호출
|
||||
onOpenChange?.(nextOpen);
|
||||
|
||||
// 2) jotai 전역 상태도 함께 업데이트
|
||||
if (nextOpen) {
|
||||
showDialog(dialogId);
|
||||
setItrntKeyword("");
|
||||
} else {
|
||||
hideDialog(dialogId);
|
||||
}
|
||||
}
|
||||
|
||||
const handleInputChange = (field: keyof ProjectCreateRequest, value: any) => {
|
||||
setFormData((prev) => {
|
||||
const next = { ...prev, [field]: value } as ProjectCreateRequest;
|
||||
|
||||
if (field === "itrntPrjctCd") {
|
||||
const selected = itrntPrjctArray.find((p) => p.childSn === value);
|
||||
if (selected){
|
||||
next.ownerDept = selected.researchTeam;
|
||||
next.prjctName = selected.title;
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if(!formData.itrntPrjctCd.trim()){
|
||||
alert("인트라넷 프로젝트를 선택해 주세요");
|
||||
return;
|
||||
}
|
||||
if (!formData.prjctName.trim()) {
|
||||
alert('프로젝트 명을 입력해 주세요');
|
||||
return;
|
||||
}
|
||||
if (!PROJECT_NAME_REGEX.test(formData.prjctName)) {
|
||||
alert("프로젝트명에 허용되지 않는 문자가 포함되어 있습니다");
|
||||
return;
|
||||
}
|
||||
if(!formData.ownerDept.trim()){
|
||||
alert('담당 그룹을 입력해 주세요');
|
||||
return;
|
||||
}
|
||||
if(!USER_NAME_REGEX.test(formData.ownerDept)){
|
||||
alert('담당 그룹이 올바르지 않습니다.');
|
||||
return;
|
||||
}
|
||||
if(!formData.ownerFw.trim()){
|
||||
alert('담당 SV를 입력해 주세요');
|
||||
return;
|
||||
}
|
||||
if(!USER_NAME_REGEX.test(formData.ownerDept)){
|
||||
alert('담당 SV가 올바르지 않습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
await onSubmit(formData as ProjectCreateRequest);
|
||||
handleOpenChange(false);
|
||||
} catch (e) {
|
||||
const err = apiError(e);
|
||||
if(err.code !== NONE_HTTP_ERROR && err.code !== UNKNOWN_HTTP_ERROR){
|
||||
alert(err.message);
|
||||
}
|
||||
else{
|
||||
alert('저장에 실패했습니다.');
|
||||
}
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
const searchItrntPrjct = async (keyword:string): Promise<void> => {
|
||||
const res = await nextApi.get<IntranetProjectSearchResponse[]>(
|
||||
"/intranet/project",
|
||||
{ query: keyword ? { keyword } : {} }
|
||||
);
|
||||
|
||||
setItrntPrjctArray(res);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const keyword = debouncedKeyword.trim();
|
||||
searchItrntPrjct(keyword).then();
|
||||
}, [debouncedKeyword]);
|
||||
|
||||
useEffect(() => {
|
||||
setFormData(defaultProjectInfo);
|
||||
}, [resolvedOpen])
|
||||
|
||||
useEffect(() => {
|
||||
let userTeams = Array.from(new Set(users.map(u => u.userTeam)));
|
||||
if(!userTeams.includes("T900")){ //TFT
|
||||
userTeams.push("T900");
|
||||
}
|
||||
userTeams = userTeams.sort((a, b) => a.localeCompare(b, "ko"));
|
||||
setDeptArray(userTeams);
|
||||
|
||||
const userOptions: MultiSelectOption[] = users
|
||||
.filter(u => u.userId == ownerFw || u.userTeam == FW_TEAM)
|
||||
.map(u => ({
|
||||
value: u.userId,
|
||||
label: u.userNm,
|
||||
}));
|
||||
setFwArray(userOptions);
|
||||
}, [users]);
|
||||
|
||||
return (
|
||||
<Dialog open={resolvedOpen} onOpenChange={handleOpenChange}>
|
||||
<DialogContent className="sm:max-w-[500px] content-text-sm">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="content-text-sxl">
|
||||
프로젝트 생성
|
||||
</DialogTitle>
|
||||
<DialogDescription>프로젝트 생성에 필요한 기본정보를 입력해주세요.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-6 py-4">
|
||||
<div className="grid gap-2">
|
||||
<Label>
|
||||
인트라넷 프로젝트<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<KriSingleSelect
|
||||
items={itrntPrjctArray}
|
||||
value={String(formData.itrntPrjctCd)}
|
||||
onChange={(e) => handleInputChange('itrntPrjctCd', e)}
|
||||
getLabel={(item) => `[${item.childSn}] ${item.title}`}
|
||||
getValue={(item) => item.childSn}
|
||||
searchMode={"inputOnly"}
|
||||
onSearchValueChange={setItrntKeyword}
|
||||
placeholder="인트라넷 프로젝트"
|
||||
widthClassName="w-full"
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="prjctName">
|
||||
프로젝트 명<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="prjctName"
|
||||
placeholder="프로젝트명을 입력하세요"
|
||||
value={formData.prjctName}
|
||||
onChange={(e) => handleInputChange('prjctName', e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="ownerDept">
|
||||
담당 그룹<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<KriSingleSelect
|
||||
items={deptArray}
|
||||
value={formData.ownerDept || ''}
|
||||
onChange={(value) => handleInputChange('ownerDept', value)}
|
||||
placeholder="담당 그룹을 선택하세요"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="ownerFw">
|
||||
담당 실사<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<KriSingleSelect
|
||||
items={fwArray}
|
||||
value={formData.ownerFw || ''}
|
||||
onChange={(value) => handleInputChange('ownerFw', value)}
|
||||
getValue={(item) => item.value}
|
||||
getLabel={(item) => item.label}
|
||||
placeholder="담당 실사를 선택하세요"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => handleOpenChange(false)}
|
||||
>
|
||||
취소
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
생성
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProjectCreateDialog
|
||||
325
src/components/dialog/ResultCodeDialog.tsx
Normal file
325
src/components/dialog/ResultCodeDialog.tsx
Normal file
@@ -0,0 +1,325 @@
|
||||
'use client'
|
||||
|
||||
import { useMemo, useState } from 'react'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import {Trash2, Plus, Download, Search, XIcon} from 'lucide-react'
|
||||
|
||||
export type ResultCode = {
|
||||
code: string
|
||||
label: string
|
||||
}
|
||||
|
||||
type Project = {
|
||||
prjctCd: string
|
||||
prjctName: string
|
||||
resultCodes: ResultCode[]
|
||||
}
|
||||
|
||||
type ResultCodeDialogProps = {
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
onSave?: (codes: ResultCode[]) => void
|
||||
}
|
||||
|
||||
const ResultCodeDialog = ({ open, onOpenChange, onSave }: ResultCodeDialogProps) => {
|
||||
const [importMode, setImportMode] = useState(false)
|
||||
const [selectedProject, setSelectedProject] = useState<string>('')
|
||||
|
||||
const [resultCodes, setResultCodes] = useState<ResultCode[]>([
|
||||
{ code: '0', label: '컨택 성공' },
|
||||
{ code: '1', label: '통화 예약' },
|
||||
{ code: '2', label: '비수신' },
|
||||
{ code: '3', label: '부재' },
|
||||
{ code: '4', label: '휴가' },
|
||||
{ code: '5', label: '출장' },
|
||||
{ code: '6', label: '단순 거절' },
|
||||
{ code: '7', label: '강력 거절' },
|
||||
{ code: '8', label: '그런 사람 아님' },
|
||||
{ code: '9', label: '메일 발송' },
|
||||
{ code: '10', label: '독려' },
|
||||
{ code: '11', label: '퇴사' },
|
||||
{ code: '12', label: '기타' },
|
||||
{ code: '13', label: '조사 대상 아님' },
|
||||
{ code: '14', label: '수신 거부' },
|
||||
])
|
||||
|
||||
// 샘플 프로젝트 목록 (실제로는 API에서 가져옴)
|
||||
const projects: Project[] = [
|
||||
{
|
||||
prjctCd: '250701yd',
|
||||
prjctName: '250701yd',
|
||||
resultCodes: [
|
||||
{ code: '0', label: '완료' },
|
||||
{ code: '1', label: '거절' },
|
||||
{ code: '2', label: '진행중' },
|
||||
],
|
||||
},
|
||||
{
|
||||
prjctCd: '1509013',
|
||||
prjctName: '1509013_J2307KJC_KFB_저기 1차 카카오톡 AUTOAGI_#01250Group',
|
||||
resultCodes: [
|
||||
{ code: '0', label: '성공' },
|
||||
{ code: '1', label: '실패' },
|
||||
{ code: '2', label: '보류' },
|
||||
],
|
||||
},
|
||||
{
|
||||
prjctCd: '1503013',
|
||||
prjctName: '1503013_J2307KJC_KFB_저기 1차 카카오톡 AUTOAGI_그룹01테스트0',
|
||||
resultCodes: [
|
||||
{ code: '0', label: '승인' },
|
||||
{ code: '1', label: '반려' },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const [projectSearch, setProjectSearch] = useState('')
|
||||
const filteredProjects = useMemo(() => {
|
||||
const q = projectSearch.trim().toLowerCase()
|
||||
if (!q) return projects
|
||||
return projects.filter(p =>
|
||||
`${p.prjctCd} ${p.prjctName}`.toLowerCase().includes(q)
|
||||
)
|
||||
}, [projectSearch])
|
||||
|
||||
const selectedProjectData = useMemo(
|
||||
() => projects.find(p => p.prjctCd === selectedProject),
|
||||
[selectedProject]
|
||||
)
|
||||
|
||||
const handleAddCode = () => {
|
||||
setResultCodes(prev => [...prev, { code: String(prev.length), label: '' }])
|
||||
}
|
||||
|
||||
const handleDeleteCode = (index: number) => {
|
||||
setResultCodes(prev => prev.filter((_, i) => i !== index))
|
||||
}
|
||||
|
||||
const handleCodeChange = (index: number, field: keyof ResultCode, value: string) => {
|
||||
setResultCodes(prev => {
|
||||
const next = [...prev]
|
||||
next[index] = { ...next[index], [field]: value }
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
const handleImportClick = () => {
|
||||
setImportMode(true)
|
||||
}
|
||||
|
||||
const handleImportApply = () => {
|
||||
if (selectedProjectData) {
|
||||
setResultCodes(selectedProjectData.resultCodes)
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
}
|
||||
|
||||
const handleImportCancel = () => {
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
|
||||
const handleSave = () => {
|
||||
onSave?.(resultCodes)
|
||||
onOpenChange?.(false)
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
onOpenChange?.(false)
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
{/* ✅ importMode일 때 더 넓게(그리고 애니메이션으로 부드럽게) */}
|
||||
<DialogContent
|
||||
className={[
|
||||
'p-0 overflow-hidden',
|
||||
'transition-all duration-200',
|
||||
importMode ? 'sm:max-w-6xl' : 'sm:max-w-3xl',
|
||||
'w-[calc(100vw-2rem)]',
|
||||
'max-h-[85vh]',
|
||||
'gap-2',
|
||||
].join(' ')}
|
||||
>
|
||||
<DialogHeader className="px-6 pt-6 pb-4 border-b">
|
||||
<DialogTitle className="flex items-center justify-between gap-3">
|
||||
<span>결과 코드 설정</span>
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
{/* 상단 버튼 영역 */}
|
||||
<div className="px-6 pt-1 pb-3 border-b bg-white flex justify-end">
|
||||
{!importMode ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleImportClick}
|
||||
className="h-9 px-3 gap-2"
|
||||
>
|
||||
<Download className="w-4 h-4" />
|
||||
가져오기
|
||||
</Button>
|
||||
) : (
|
||||
<div className="flex items-center gap-2 w-130">
|
||||
<div className="relative flex-1">
|
||||
<Search className="w-4 h-4 text-gray-400 absolute left-3 top-1/2 -translate-y-1/2" />
|
||||
<Input
|
||||
value={projectSearch}
|
||||
onChange={(e) => setProjectSearch(e.target.value)}
|
||||
placeholder="프로젝트 코드/이름 검색..."
|
||||
className="h-9 pl-9"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 본문 */}
|
||||
<div className={importMode ? 'grid grid-cols-1 lg:grid-cols-2' : 'block'}>
|
||||
{/* 왼쪽: 결과 코드 */}
|
||||
<div className="p-6">
|
||||
<div className="rounded-lg border bg-white overflow-hidden">
|
||||
<div className="px-4 py-3 border-b bg-gray-50 flex items-center justify-between">
|
||||
<div className="font-semibold text-sm text-gray-900">결과 코드 목록</div>
|
||||
{!importMode && (
|
||||
<Button onClick={handleAddCode} variant="outline" size="sm" className="gap-2">
|
||||
<Plus className="w-4 h-4" />
|
||||
추가
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="max-h-[420px] overflow-y-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-white border-b">
|
||||
<tr className="text-gray-600">
|
||||
<th className="px-4 py-2 text-left w-36">코드</th>
|
||||
<th className="px-4 py-2 text-left">레이블</th>
|
||||
<th className="px-2 py-2 w-12" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y">
|
||||
{resultCodes.map((code, index) => (
|
||||
<tr key={index} className="hover:bg-gray-50">
|
||||
<td className="px-4 py-2 align-middle">
|
||||
<Input
|
||||
value={code.code}
|
||||
onChange={(e) => handleCodeChange(index, 'code', e.target.value)}
|
||||
className="h-9"
|
||||
disabled={importMode}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-4 py-2 align-middle">
|
||||
<Input
|
||||
value={code.label}
|
||||
onChange={(e) => handleCodeChange(index, 'label', e.target.value)}
|
||||
className="h-9"
|
||||
disabled={importMode}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-2 py-2 align-middle">
|
||||
{!importMode && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => handleDeleteCode(index)}
|
||||
aria-label="delete"
|
||||
>
|
||||
<Trash2 className="w-4 h-4 text-red-600" />
|
||||
</Button>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{!importMode && (
|
||||
<div className="px-4 py-3 border-t bg-gray-50 text-xs text-gray-500">
|
||||
Tip: 코드 값은 중복되지 않게 유지해주세요.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 오른쪽: importMode일 때만 */}
|
||||
{importMode && (
|
||||
<div className="p-6 border-t lg:border-t-0 lg:border-l bg-white">
|
||||
{/* 미리보기 */}
|
||||
<div className="rounded-lg border bg-white overflow-hidden">
|
||||
<div className="px-4 py-3 border-b bg-gray-50 flex items-center justify-between">
|
||||
<div className="font-semibold text-sm text-gray-900">미리보기</div>
|
||||
</div>
|
||||
|
||||
<div className="max-h-[180px] overflow-y-auto">
|
||||
{selectedProjectData ? (
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-white border-b">
|
||||
<tr className="text-gray-600">
|
||||
<th className="px-4 py-2 text-left w-32">코드</th>
|
||||
<th className="px-4 py-2 text-left">레이블</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y">
|
||||
{selectedProjectData.resultCodes.map((code, idx) => (
|
||||
<tr key={idx}>
|
||||
<td className="px-4 py-2">{code.code}</td>
|
||||
<td className="px-4 py-2">{code.label}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
) : (
|
||||
<div className="p-4 text-sm text-gray-500">프로젝트를 선택하세요.</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<DialogFooter className="px-6 py-4 border-t bg-white">
|
||||
{importMode ? (
|
||||
<>
|
||||
<Button variant="outline" onClick={handleImportCancel}>
|
||||
취소
|
||||
</Button>
|
||||
<Button onClick={handleImportApply} disabled={!selectedProject} className="gap-2">
|
||||
<Download className="w-4 h-4" />
|
||||
가져오기 적용
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Button variant="outline" onClick={handleClose}>
|
||||
취소
|
||||
</Button>
|
||||
<Button onClick={handleSave}>
|
||||
저장
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default ResultCodeDialog
|
||||
@@ -18,9 +18,10 @@ import { UserInfoSaveRequest } from '@/types/user'
|
||||
import KriPassword from "@/components/common/KriPassword";
|
||||
import {KriSelect, KriSelectItem} from "@/components/common/KriSelect";
|
||||
import {DataVerification} from "@/types/common";
|
||||
import commonConst from "@/config/commonConst";
|
||||
import {apiError} from "@/lib/http-util";
|
||||
import {KriSingleSelect} from "@/components/common/KriAutoComplete";
|
||||
import {USER_NAME_REGEX} from "@/const/userConst";
|
||||
import {NONE_HTTP_ERROR, UNKNOWN_HTTP_ERROR} from "@/const/commonConst";
|
||||
|
||||
export type UserUpsertDialogProps = {
|
||||
/** Jotai로 관리할 다이얼로그 ID (기본값: 'userUpsertDialog') */
|
||||
@@ -151,19 +152,20 @@ const UserUpsertDialog = ({
|
||||
alert('이름을 입력해주세요.');
|
||||
return;
|
||||
}
|
||||
if(!commonConst.nameRegex.test(formData.userName)){
|
||||
if(!USER_NAME_REGEX.test(formData.userName)){
|
||||
alert('올바르지 않은 이름입니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true)
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
await onSubmit(formData as UserInfoSaveRequest);
|
||||
handleOpenChange(false);
|
||||
} catch (e) {
|
||||
const err = apiError(e);
|
||||
console.error(err.status, err.code, err.message);
|
||||
if(err.code !== commonConst.noneHttpError && err.code !== commonConst.unknownHttpError){
|
||||
if(err.code !== NONE_HTTP_ERROR && err.code !== UNKNOWN_HTTP_ERROR){
|
||||
alert(err.message);
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -5,7 +5,7 @@ interface BodyTitleProps {
|
||||
const BodyTitle = ({titleText}:BodyTitleProps) => {
|
||||
return (
|
||||
<div className="flex justify-between items-center">
|
||||
<h1 className="font-bold content-text-4xl">{titleText}</h1>
|
||||
<h1 className="font-bold content-text-2xl">{titleText}</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ interface HeaderProps {
|
||||
menuOpen: boolean;
|
||||
activeTopId: string;
|
||||
fontSize: number;
|
||||
handleIsProjectMenu: (isProjectMenu: boolean) => void;
|
||||
onToggleMenu: () => void;
|
||||
onNavigate: (path: string) => void;
|
||||
decreaseFontSize: () => void;
|
||||
@@ -25,12 +24,11 @@ export const Header = ({
|
||||
menuOpen,
|
||||
activeTopId,
|
||||
fontSize,
|
||||
handleIsProjectMenu,
|
||||
onToggleMenu,
|
||||
onNavigate,
|
||||
decreaseFontSize,
|
||||
increaseFontSize,
|
||||
}: HeaderProps) => {
|
||||
}: HeaderProps) => {
|
||||
const { auth } = useAuth();
|
||||
const [userInfo, setUserInfo] = useState<LoginUser|undefined>(undefined);
|
||||
|
||||
@@ -38,6 +36,9 @@ export const Header = ({
|
||||
if(auth.user){
|
||||
setUserInfo(auth.user);
|
||||
}
|
||||
else{
|
||||
onNavigate("/logout")
|
||||
}
|
||||
}, [auth])
|
||||
|
||||
return (
|
||||
@@ -79,10 +80,7 @@ export const Header = ({
|
||||
<Button
|
||||
key={m.id}
|
||||
variant={activeTopId === m.id ? "default" : "ghost"}
|
||||
onClick={() => {
|
||||
handleIsProjectMenu(m.id === "project");
|
||||
onNavigate(m.path);
|
||||
}}
|
||||
onClick={() => onNavigate(m.path)}
|
||||
>
|
||||
{m.label}
|
||||
</Button>
|
||||
|
||||
@@ -6,7 +6,10 @@ import { Header } from "@/components/layout/Header";
|
||||
import { Sidebar } from "@/components/layout/Sidebar";
|
||||
import {useFontSize} from "@/hooks/useFontSize";
|
||||
import {projectSideMenus, manageSideMenus, topMenus} from "@/config/menu.data";
|
||||
import commonConst from "@/config/commonConst";
|
||||
import ProjectTitle from "@/components/layout/ProjectTitle";
|
||||
import {cn} from "@/lib/utils";
|
||||
import {FONT_SIZE} from "@/const/commonConst";
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
|
||||
type MainLayoutProps = {
|
||||
children: ReactNode;
|
||||
@@ -17,13 +20,15 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
const [isProjectMenu, setIsProjectMenu] = useState(false);
|
||||
const { selectedProject } = useSelectedProject();
|
||||
const [menuOpen, setMenuOpen] = useState(true);
|
||||
const [fontSize, setFontSize] = useFontSize(initialFontSize, { hydrateFromCookie: false });
|
||||
|
||||
const isMain = pathname === "/";
|
||||
const isProjectMenu = !pathname.startsWith("/manage");
|
||||
const isViewProjectTitle = !isMain && isProjectMenu && !pathname.startsWith("/project/info")
|
||||
const activeTop = topMenus.find((m) => m.match?.(pathname)) ?? topMenus[0];
|
||||
const sideMenus = pathname.startsWith("/manage") ? manageSideMenus : projectSideMenus;
|
||||
const sideMenus = isProjectMenu ? projectSideMenus : manageSideMenus;
|
||||
|
||||
// 2단 메뉴 open 상태
|
||||
const [openMenus, setOpenMenus] = useState<Record<string, boolean>>(() => {
|
||||
@@ -43,10 +48,6 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
return initial;
|
||||
});
|
||||
|
||||
const handleIsProjectMenu = (isProject: boolean) => {
|
||||
setIsProjectMenu(isProject);
|
||||
}
|
||||
|
||||
const movePage = (path: string) => {
|
||||
router.push(path);
|
||||
};
|
||||
@@ -56,11 +57,11 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
};
|
||||
|
||||
const decreaseFontSize = () =>{
|
||||
setFontSize(Math.max(commonConst.fontSizeMin, fontSize - 2));
|
||||
setFontSize(Math.max(FONT_SIZE.MIN, fontSize - 2));
|
||||
}
|
||||
|
||||
const increaseFontSize = () =>{
|
||||
setFontSize(Math.min(commonConst.fontSizeMax, fontSize + 2));
|
||||
setFontSize(Math.min(FONT_SIZE.MAX, fontSize + 2));
|
||||
}
|
||||
|
||||
// CSS 변수 동기화
|
||||
@@ -72,15 +73,25 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
);
|
||||
}, [fontSize]);
|
||||
|
||||
useEffect(() => {
|
||||
if(!isMain && isProjectMenu && !selectedProject){
|
||||
alert("옳지 않은 접근입니다.");
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<div
|
||||
className={cn(
|
||||
"bg-gray-50 flex flex-col",
|
||||
isMain ? "min-h-screen" : "h-screen overflow-hidden" // ✅ 메인 제외: 바깥 스크롤 잠금
|
||||
)}
|
||||
>
|
||||
{/* 헤더 - 고정 폰트 크기 */}
|
||||
<Header
|
||||
isMain={isMain}
|
||||
menuOpen={menuOpen}
|
||||
activeTopId={activeTop.id}
|
||||
fontSize={fontSize}
|
||||
handleIsProjectMenu={handleIsProjectMenu}
|
||||
onToggleMenu={() => setMenuOpen((prev) => !prev)}
|
||||
onNavigate={movePage}
|
||||
decreaseFontSize={decreaseFontSize}
|
||||
@@ -88,7 +99,7 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
/>
|
||||
|
||||
{/* 본문 */}
|
||||
<div className="flex">
|
||||
<div className={cn("flex flex-1", !isMain && "min-h-0")}>
|
||||
{/* 사이드바 - 고정 폰트 크기 */}
|
||||
{!isMain && (
|
||||
<Sidebar
|
||||
@@ -104,11 +115,17 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
|
||||
{/* 메인 콘텐츠만 가변 폰트 크기 적용 */}
|
||||
<main
|
||||
className="flex-1 p-4"
|
||||
className={cn(
|
||||
"flex-1 p-4",
|
||||
!isMain && "min-h-0 overflow-y-auto"
|
||||
)}
|
||||
// 전역 CSS 변수(--content-font-size)를 실제 렌더에 적용
|
||||
// SSR 단계에서의 초기 폰트 값을 FOUC 없이 유지하기 위해 fallback을 함께 지정
|
||||
style={{ fontSize: `var(--content-font-size, ${initialFontSize}px)` }}
|
||||
>
|
||||
{isViewProjectTitle &&
|
||||
<ProjectTitle/>
|
||||
}
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
17
src/components/layout/ProjectTitle.tsx
Normal file
17
src/components/layout/ProjectTitle.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
|
||||
const ProjectTitle = () => {
|
||||
const mounted = useMounted();
|
||||
const { selectedProject } = useSelectedProject();
|
||||
|
||||
if(!mounted) return null;
|
||||
|
||||
return (
|
||||
<div className="flex justify-between items-center mb-2">
|
||||
<h1 className="font-bold content-text-2xl">{selectedProject?.prjctName}</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProjectTitle
|
||||
@@ -1,9 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ChevronDown } from "lucide-react";
|
||||
import { SideMenuItem } from "@/config/menu.types";
|
||||
import {KriSingleSelect} from "@/components/common/KriAutoComplete";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SidebarProjectSearch} from "@/components/layout/SidebarProjectSearch ";
|
||||
|
||||
interface SidebarProps {
|
||||
isProjectMenu: boolean;
|
||||
@@ -51,15 +53,9 @@ export const Sidebar = ({
|
||||
`}
|
||||
>
|
||||
<div className="p-4 space-y-4 overflow-y-auto h-full">
|
||||
{isProjectMenu && (
|
||||
<div className="space-y-2">
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="프로젝트 검색..."
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{isProjectMenu &&
|
||||
<SidebarProjectSearch/>
|
||||
}
|
||||
|
||||
{/* 좌측 메뉴 */}
|
||||
<nav className="space-y-1">
|
||||
|
||||
63
src/components/layout/SidebarProjectSearch .tsx
Normal file
63
src/components/layout/SidebarProjectSearch .tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {ProjectInfo} from "@/types/project";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {useEffect, useState} from "react";
|
||||
import {KriSingleSelect} from "@/components/common/KriAutoComplete";
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
import {useLoading} from "@/hooks/useLoading";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
import {PROJECT_SEARCH_COUNT} from "@/const/projectConst";
|
||||
import {SelectedProject} from "@/store/jotai/project";
|
||||
|
||||
export const SidebarProjectSearch = () =>{
|
||||
const mounted = useMounted();
|
||||
|
||||
const { selectedProject, setSelectedProject } = useSelectedProject();
|
||||
const [searchKeyword, setSearchKeyword] = useState(selectedProject?.prjctCd || "");
|
||||
const debouncedKeyword = useDebouncedValue(searchKeyword, 500);
|
||||
const [projectArray, setProjectArray] = useState<SelectedProject[]>([]);
|
||||
|
||||
const searchTopProject = async (keyword: string) => {
|
||||
const res = await nextApi.get<ProjectInfo[]>(
|
||||
`/project/top/${PROJECT_SEARCH_COUNT}`,
|
||||
{ query: { keyword } }
|
||||
);
|
||||
|
||||
setProjectArray(res);
|
||||
};
|
||||
|
||||
const handleSelectProject = (info:SelectedProject|null) => {
|
||||
if(info === null) return;
|
||||
|
||||
setSelectedProject(info);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if(selectedProject){
|
||||
const keyword = debouncedKeyword.trim();
|
||||
searchTopProject(keyword);
|
||||
}
|
||||
}, [debouncedKeyword]);
|
||||
|
||||
if (!mounted || !selectedProject) return null
|
||||
|
||||
return (
|
||||
<KriSingleSelect
|
||||
<SelectedProject>
|
||||
items={projectArray}
|
||||
value={String(selectedProject.prjctIdx)}
|
||||
onChange={() => {}}
|
||||
withInfo
|
||||
onItemChange={handleSelectProject}
|
||||
searchMode="inputOnly"
|
||||
onSearchValueChange={setSearchKeyword}
|
||||
placeholder="프로젝트 검색..."
|
||||
widthClassName="w-full"
|
||||
heightClassName="h-9"
|
||||
preventDeselect
|
||||
hideOptionCheck
|
||||
getLabel={(item) => `${item.prjctCd}_${item.prjctName}`}
|
||||
getValue={(item) => String(item.prjctIdx)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
66
src/components/ui/tabs.tsx
Normal file
66
src/components/ui/tabs.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Tabs({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
|
||||
return (
|
||||
<TabsPrimitive.Root
|
||||
data-slot="tabs"
|
||||
className={cn("flex flex-col gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsList({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.List>) {
|
||||
return (
|
||||
<TabsPrimitive.List
|
||||
data-slot="tabs-list"
|
||||
className={cn(
|
||||
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsTrigger({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
|
||||
return (
|
||||
<TabsPrimitive.Trigger
|
||||
data-slot="tabs-trigger"
|
||||
className={cn(
|
||||
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Content>) {
|
||||
return (
|
||||
<TabsPrimitive.Content
|
||||
data-slot="tabs-content"
|
||||
className={cn("flex-1 outline-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
||||
@@ -1,12 +0,0 @@
|
||||
const commonConst = {
|
||||
fontSizeDefault: 14,
|
||||
fontSizeMin: 12,
|
||||
fontSizeMax: 24,
|
||||
externalUserRole: 4000,
|
||||
unknownHttpError: 'UNKNOWN_HTTP_ERROR',
|
||||
noneHttpError: 'NONE_HTTP_ERROR',
|
||||
nameRegex: /^[가-힣A-Za-z][가-힣A-Za-z0-9_ ()]*$/,
|
||||
defaultCmpn: 'KRI',
|
||||
} as const;
|
||||
|
||||
export default commonConst;
|
||||
8
src/const/commonConst.ts
Normal file
8
src/const/commonConst.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export const FONT_SIZE = {
|
||||
DEFAULT: 14,
|
||||
MIN: 12,
|
||||
MAX: 24,
|
||||
} as const;
|
||||
|
||||
export const UNKNOWN_HTTP_ERROR = 'UNKNOWN_HTTP_ERROR';
|
||||
export const NONE_HTTP_ERROR = 'NONE_HTTP_ERROR';
|
||||
62
src/const/projectConst.ts
Normal file
62
src/const/projectConst.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
export enum SurveyType {
|
||||
NONE = 0,
|
||||
KON = 1,
|
||||
KIWI = 2,
|
||||
EXTERNAL = 99,
|
||||
}
|
||||
|
||||
export const SURVEY_TYPE_ORDER = [
|
||||
SurveyType.NONE,
|
||||
SurveyType.KON,
|
||||
SurveyType.KIWI,
|
||||
SurveyType.EXTERNAL,
|
||||
] as const;
|
||||
|
||||
// 라벨 맵 (단일 소스)
|
||||
export const SURVEY_TYPE_LABEL = {
|
||||
[SurveyType.NONE]: "없음",
|
||||
[SurveyType.KON]: "KON",
|
||||
[SurveyType.KIWI]: "KIWI",
|
||||
[SurveyType.EXTERNAL]: "외부 설문",
|
||||
} as const satisfies Record<SurveyType, string>;
|
||||
|
||||
export enum ProjectStatus {
|
||||
WAITING = 0,
|
||||
IN_PROGRESS = 1,
|
||||
COMPLETED = 10,
|
||||
}
|
||||
|
||||
export const PROJECT_STATUS_ORDER = [
|
||||
ProjectStatus.WAITING,
|
||||
ProjectStatus.IN_PROGRESS,
|
||||
ProjectStatus.COMPLETED,
|
||||
] as const;
|
||||
|
||||
export const PROJECT_STATUS_LABEL = {
|
||||
[ProjectStatus.WAITING]: "대기",
|
||||
[ProjectStatus.IN_PROGRESS]: "진행",
|
||||
[ProjectStatus.COMPLETED]: "완료",
|
||||
} as const satisfies Record<ProjectStatus, string>;
|
||||
|
||||
export const PROJECT_STATUS_CLASS = {
|
||||
[ProjectStatus.WAITING]: "bg-yellow-100 text-yellow-800",
|
||||
[ProjectStatus.IN_PROGRESS]: "bg-blue-100 text-blue-800",
|
||||
[ProjectStatus.COMPLETED]: "bg-green-100 text-green-800",
|
||||
} as const satisfies Record<ProjectStatus, string>;
|
||||
|
||||
// 옵션이 필요하면(셀렉트/라디오 등) 이것만 돌려 쓰기
|
||||
export const SURVEY_TYPE_OPTIONS = [
|
||||
{ value: SurveyType.NONE, label: SURVEY_TYPE_LABEL[SurveyType.NONE] },
|
||||
{ value: SurveyType.KON, label: SURVEY_TYPE_LABEL[SurveyType.KON] },
|
||||
{ value: SurveyType.KIWI, label: SURVEY_TYPE_LABEL[SurveyType.KIWI] },
|
||||
{ value: SurveyType.EXTERNAL, label: SURVEY_TYPE_LABEL[SurveyType.EXTERNAL] },
|
||||
] as const;
|
||||
|
||||
export const PROJECT_STATUS_OPTIONS = [
|
||||
{ value: ProjectStatus.WAITING, label: PROJECT_STATUS_LABEL[ProjectStatus.WAITING] },
|
||||
{ value: ProjectStatus.IN_PROGRESS, label: PROJECT_STATUS_LABEL[ProjectStatus.IN_PROGRESS] },
|
||||
{ value: ProjectStatus.COMPLETED, label: PROJECT_STATUS_LABEL[ProjectStatus.COMPLETED] },
|
||||
] as const;
|
||||
|
||||
export const PROJECT_NAME_REGEX= /^[^\u0000-\u001F\u007F]+$/
|
||||
export const PROJECT_SEARCH_COUNT = 20
|
||||
8
src/const/userConst.ts
Normal file
8
src/const/userConst.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export const EXTERNAL_USER_ROLE = 4000
|
||||
export const FW_USER_ROLE = 9000
|
||||
|
||||
export const USER_NAME_REGEX = /^[가-힣A-Za-z][가-힣A-Za-z0-9_ ()]*$/
|
||||
export const DEFAULT_COMPANY_NAME = 'KRI'
|
||||
|
||||
export const FW_TEAM = "S101"
|
||||
export const QC_TEAM = "S201"
|
||||
12
src/hooks/useDebouncedValue.ts
Normal file
12
src/hooks/useDebouncedValue.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useDebouncedValue<T>(value: T, delayMs = 1200) {
|
||||
const [debounced, setDebounced] = useState(value);
|
||||
|
||||
useEffect(() => {
|
||||
const t = setTimeout(() => setDebounced(value), delayMs);
|
||||
return () => clearTimeout(t);
|
||||
}, [value, delayMs]);
|
||||
|
||||
return debounced;
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { cookieStore } from "@/store/cookie/cookie";
|
||||
import { CookieKeys } from "@/store/cookie/cookie-keys";
|
||||
import commonConst from "@/config/commonConst";
|
||||
import {FONT_SIZE} from "@/const/commonConst";
|
||||
|
||||
const MIN_FONT_SIZE = 12;
|
||||
const MAX_FONT_SIZE = 24;
|
||||
@@ -48,7 +48,7 @@ type UseFontSizeOptions = {
|
||||
}
|
||||
|
||||
export const useFontSize = (
|
||||
defaultSize: number = commonConst.fontSizeDefault,
|
||||
defaultSize: number = FONT_SIZE.DEFAULT,
|
||||
options: UseFontSizeOptions = {},
|
||||
) => {
|
||||
const { hydrateFromCookie = true } = options;
|
||||
@@ -100,7 +100,7 @@ export const useFontSize = (
|
||||
export const useFontSizeValue = (
|
||||
options: UseFontSizeOptions = {},
|
||||
) => {
|
||||
const defaultSize = commonConst.fontSizeDefault;
|
||||
const defaultSize = FONT_SIZE.DEFAULT;
|
||||
const [fontSize] = useFontSize(defaultSize, options);
|
||||
return fontSize;
|
||||
}
|
||||
109
src/hooks/useItrntUserList.ts
Normal file
109
src/hooks/useItrntUserList.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { StorageKeys } from "@/store/storage/storage-keys";
|
||||
import { useStorage } from "@/hooks/useStorage";
|
||||
import { nextApi } from "@/lib/http-client";
|
||||
|
||||
export type ItrntUserInfo = {
|
||||
userId: string;
|
||||
userNm: string;
|
||||
userCmpn: string;
|
||||
userTeam: string;
|
||||
userRole: number;
|
||||
};
|
||||
|
||||
let inFlight: Promise<ItrntUserInfo[]> | null = null;
|
||||
|
||||
export const useItrntUserList = () => {
|
||||
const endpoint = "/intranet/user-list";
|
||||
const storage = useStorage(StorageKeys.ItrntUserList);
|
||||
const { get, set, remove } = storage;
|
||||
|
||||
// ✅ storage 함수 레퍼런스 고정(최신 함수는 effect로 갱신)
|
||||
const storageRef = useRef({ get, set, remove });
|
||||
useEffect(() => {
|
||||
storageRef.current = { get, set, remove };
|
||||
}, [get, set, remove]);
|
||||
|
||||
const [users, setUsers] = useState<ItrntUserInfo[]>([]);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(true);
|
||||
const [error, setError] = useState<unknown>(null);
|
||||
|
||||
const mountedRef = useRef(true);
|
||||
useEffect(() => {
|
||||
mountedRef.current = true;
|
||||
return () => {
|
||||
mountedRef.current = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const fetchUsers = useCallback(async (): Promise<ItrntUserInfo[]> => {
|
||||
return await nextApi.get<ItrntUserInfo[]>(endpoint);
|
||||
}, [endpoint]);
|
||||
|
||||
// ✅ ensure는 이제 storage 함수들에 "직접" 의존하지 않음(루프 차단)
|
||||
const ensure = useCallback(async (force = false): Promise<ItrntUserInfo[]> => {
|
||||
const { get: sGet, set: sSet } = storageRef.current;
|
||||
|
||||
if (!force) {
|
||||
const cached = sGet();
|
||||
if (Array.isArray(cached)) return cached as ItrntUserInfo[];
|
||||
}
|
||||
|
||||
if (!inFlight) {
|
||||
inFlight = fetchUsers().finally(() => {
|
||||
inFlight = null;
|
||||
});
|
||||
}
|
||||
|
||||
const list = await inFlight;
|
||||
sSet(list);
|
||||
return list;
|
||||
}, [fetchUsers]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const list = await ensure(false);
|
||||
if (!mountedRef.current) return;
|
||||
setUsers(list);
|
||||
} catch (e) {
|
||||
if (!mountedRef.current) return;
|
||||
setUsers([]);
|
||||
setError(e);
|
||||
} finally {
|
||||
if (!mountedRef.current) return;
|
||||
setIsLoading(false);
|
||||
}
|
||||
})();
|
||||
}, [ensure]);
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const list = await ensure(true);
|
||||
if (!mountedRef.current) return;
|
||||
setUsers(list);
|
||||
} catch (e) {
|
||||
if (!mountedRef.current) return;
|
||||
setUsers([]);
|
||||
setError(e);
|
||||
} finally {
|
||||
if (!mountedRef.current) return;
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [ensure]);
|
||||
|
||||
const clearCache = useCallback(() => {
|
||||
storageRef.current.remove();
|
||||
setUsers([]);
|
||||
}, []);
|
||||
|
||||
return { users, isLoading, error, refresh, clearCache } as const;
|
||||
};
|
||||
7
src/hooks/useMounted.ts
Normal file
7
src/hooks/useMounted.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export const useMounted = () => {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
useEffect(() => setMounted(true), []);
|
||||
return mounted;
|
||||
};
|
||||
@@ -7,5 +7,8 @@ const required = (name: string) => {
|
||||
export const serverEnv = {
|
||||
ENV: required("ENV"),
|
||||
API_CONTACT_SERVER: required("API_CONTACT_SERVER"),
|
||||
API_INTRANET_SERVER: required("API_INTRANET_SERVER"),
|
||||
API_KART_SERVER: required("API_KART_SERVER"),
|
||||
KART_API_KEY: required("KART_API_KEY"),
|
||||
// 다른 서버 전용 env들 추가 가능
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import {NextResponse} from "next/server";
|
||||
import {HttpError} from "@/lib/http-client";
|
||||
import {clientEnv} from "@/lib/env.client";
|
||||
import commonConst from "@/config/commonConst";
|
||||
import {NONE_HTTP_ERROR, UNKNOWN_HTTP_ERROR} from "@/const/commonConst";
|
||||
|
||||
export type ApiError = {
|
||||
status: number
|
||||
@@ -26,7 +26,7 @@ const isDev = clientEnv.ENV !== "prod"
|
||||
export const apiError = (e: unknown): ApiError => {
|
||||
if (e instanceof HttpError) {
|
||||
const d = e.data as any
|
||||
const code = typeof d?.code === "string" ? d.code : commonConst.unknownHttpError
|
||||
const code = typeof d?.code === "string" ? d.code : UNKNOWN_HTTP_ERROR
|
||||
const message =
|
||||
(typeof d?.detail === "string" && d.detail) ||
|
||||
(typeof d?.message === "string" && d.message) ||
|
||||
@@ -48,5 +48,5 @@ export const apiError = (e: unknown): ApiError => {
|
||||
}
|
||||
|
||||
if (isDev) console.error("[NON-HTTP ERROR]", e)
|
||||
return { status: 500, code: commonConst.noneHttpError, message: "저장에 실패했습니다." }
|
||||
return { status: 500, code: NONE_HTTP_ERROR, message: "저장에 실패했습니다." }
|
||||
}
|
||||
|
||||
@@ -2,15 +2,29 @@ import { cookies } from "next/headers";
|
||||
import { createHttpClient } from "@/lib/http-client";
|
||||
import { serverEnv } from "@/lib/env.server";
|
||||
|
||||
const createServerApi = async (rootUrl: string) => {
|
||||
const createServerApi = async (rootUrl: string, defaultHeaders?: Record<string, string>) => {
|
||||
const cookieStore = await cookies();
|
||||
const accessToken = cookieStore.get("access_token")?.value ?? null;
|
||||
|
||||
return createHttpClient(rootUrl, {
|
||||
getToken: () => accessToken, // 이미 위에서 읽은 값만 참조
|
||||
defaultHeaders: {
|
||||
"content-type": "application/json",
|
||||
...(defaultHeaders ?? {}),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const createContactApi = () => {
|
||||
return createServerApi(serverEnv.API_CONTACT_SERVER);
|
||||
}
|
||||
}
|
||||
|
||||
export const createIntranetApi = () => {
|
||||
return createServerApi(serverEnv.API_INTRANET_SERVER);
|
||||
}
|
||||
|
||||
export const createKartApi = () => {
|
||||
return createServerApi(serverEnv.API_KART_SERVER, {
|
||||
"X-API-Key": serverEnv.KART_API_KEY,
|
||||
});
|
||||
};
|
||||
@@ -5,6 +5,21 @@ export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
export function getKeyByValue<
|
||||
const T extends Record<PropertyKey, string>
|
||||
>(map: T, value: T[keyof T]) {
|
||||
const entry = Object.entries(map).find(([, v]) => v === value);
|
||||
return entry ? (entry[0] as keyof T) : undefined;
|
||||
}
|
||||
|
||||
export function getNumberKeyByValue(
|
||||
map: Record<number, string>,
|
||||
value: string
|
||||
): number | undefined {
|
||||
const entry = Object.entries(map).find(([, v]) => v === value);
|
||||
return entry ? Number(entry[0]) : undefined;
|
||||
}
|
||||
|
||||
export function buildUrlWithParams(
|
||||
targetPath: string,
|
||||
from: Record<string, string | string[] | undefined>,
|
||||
|
||||
@@ -3,9 +3,12 @@ import { atom } from 'jotai'
|
||||
// 사용할 수 있는 DialogId를 타입으로 고정
|
||||
// Dialog추가 할 때만다 추가하기
|
||||
export type DialogId =
|
||||
| 'userUpsertDialog'
|
||||
| 'userUploadDialog'
|
||||
| 'listUploadDialog'
|
||||
| 'userUpsertDialog'
|
||||
| 'userUploadDialog'
|
||||
| 'listUploadDialog'
|
||||
| 'projectCreateDialog'
|
||||
| 'resultCodeDialog'
|
||||
| 'resultCodeCopyDialog'
|
||||
|
||||
// 현재 열려 있는 다이얼로그 ID 리스트
|
||||
export const openDialogIdsAtom = atom<DialogId[]>([])
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
import { StorageKeys } from "@/store/storage/storage-keys";
|
||||
import {createSessionStorageAtom} from "@/store/jotai/utils";
|
||||
import {AuthState} from "@/store/jotai/auth";
|
||||
|
||||
export type SelectedProject = {
|
||||
id: string;
|
||||
name: string;
|
||||
// 필요하면 여기서 추가 (code, status 등)
|
||||
prjctIdx: number;
|
||||
prjctCd: string
|
||||
prjctName: string;
|
||||
ownerDept: string;
|
||||
ownerFw: string;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@ export const StorageKeys = {
|
||||
SeatNumber: "kri:seatNumber",
|
||||
LoginType: "kri:loginType",
|
||||
SelectedProject: "kri:selectedProject",
|
||||
ItrntUserList:"kri:itrntUserList",
|
||||
//SidebarCollapsed: "kri:sidebarCollapsed",
|
||||
// 필요하면 여기 계속 추가
|
||||
} as const;
|
||||
@@ -12,6 +13,7 @@ export const StorageType: Record<StorageKey, "local" | "session"> = {
|
||||
[StorageKeys.SeatNumber]: "local",
|
||||
[StorageKeys.LoginType]: "local",
|
||||
[StorageKeys.SelectedProject]: "session",
|
||||
[StorageKeys.ItrntUserList]: "session",
|
||||
};
|
||||
|
||||
export type StorageKey = (typeof StorageKeys)[keyof typeof StorageKeys];
|
||||
@@ -4,4 +4,16 @@ export type DataVerification = {
|
||||
errMessage: string;
|
||||
}
|
||||
|
||||
export type RouteContext = { params: Promise<{ slug?: string[] }> };
|
||||
export type RouteContext = { params: Promise<{ slug?: string[] }> };
|
||||
|
||||
export type PageResponse<T> = {
|
||||
content: T[];
|
||||
totalElements: number;
|
||||
totalPages: number;
|
||||
pageIndex: number;
|
||||
pageSize: number;
|
||||
numberOfElements: number;
|
||||
first: boolean;
|
||||
last: boolean;
|
||||
empty: boolean;
|
||||
}
|
||||
70
src/types/project.ts
Normal file
70
src/types/project.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import {ProjectStatus, SurveyType} from "@/const/projectConst";
|
||||
|
||||
export type ProjectInfo = {
|
||||
prjctIdx: number; // Long
|
||||
prjctCd: string;
|
||||
prjctStatus: ProjectStatus;
|
||||
prjctName: string;
|
||||
itrntPrjctCd: string;
|
||||
ownerDept: string;
|
||||
ownerFw: string;
|
||||
surveyTy: SurveyType;
|
||||
surveyPrjctCd?: string;
|
||||
surveyUrl?: string;
|
||||
ff: boolean;
|
||||
useContactSenario: boolean;
|
||||
contactSenario?: string;
|
||||
regUser: string;
|
||||
regDt: string;
|
||||
modUser?: string;
|
||||
modDt?: string;
|
||||
};
|
||||
|
||||
export type ProjectCreateRequest = {
|
||||
prjctName: string;
|
||||
itrntPrjctCd: string;
|
||||
ownerDept: string;
|
||||
ownerFw: string;
|
||||
}
|
||||
|
||||
export type ProjectListQuery = {
|
||||
prjctText: string;
|
||||
prjctStatusList: ProjectStatus[];
|
||||
ownerDeptList: string[];
|
||||
ownerFwList: string[];
|
||||
}
|
||||
|
||||
export type ProjectListRequest = {
|
||||
prjctText: string;
|
||||
prjctStatusList: ProjectStatus[];
|
||||
ownerDeptList: string[];
|
||||
ownerFwList: string[];
|
||||
|
||||
pageIndex: number;
|
||||
pageSize: number;
|
||||
|
||||
sortBy: string;
|
||||
sortDir: "asc" | "desc";
|
||||
}
|
||||
|
||||
export type ProjectOwnerResponse = {
|
||||
ownerDeptList:string[];
|
||||
ownerFwList:string[];
|
||||
}
|
||||
|
||||
export type IntranetProjectSearchResponse = {
|
||||
childSn: string;
|
||||
title: string;
|
||||
researchTeam: string;
|
||||
researchTeamName: string;
|
||||
}
|
||||
|
||||
export type KonKiwiProjectInfo = {
|
||||
pkey:string;
|
||||
title:string;
|
||||
surveyType:string;
|
||||
status:string;
|
||||
gkey:string;
|
||||
mkey:string;
|
||||
createDate:string;
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
export type ItrntUserInfo = {
|
||||
userId: string;
|
||||
userNm: string;
|
||||
userCmpn: string;
|
||||
userTeam: string;
|
||||
userRole: number;
|
||||
};
|
||||
|
||||
export type UserInfo = {
|
||||
/** 사용자 ID */
|
||||
userId: string
|
||||
@@ -33,15 +41,6 @@ export type UserInfoSaveRequest = {
|
||||
memo?: string
|
||||
}
|
||||
|
||||
export type UserTableInfo = {
|
||||
userId: string
|
||||
userCmpn: string
|
||||
userName: string
|
||||
userRole: string
|
||||
regDt: string
|
||||
memo: string
|
||||
}
|
||||
|
||||
export type UserUploadResponse = {
|
||||
totalCount: number;
|
||||
successCount: number;
|
||||
@@ -49,4 +48,4 @@ export type UserUploadResponse = {
|
||||
hasErrorFile: boolean;
|
||||
errorFileName: string | null;
|
||||
errorFileBase64: string | null;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user