251216_01_ENH : 프로젝트에 FW User 배정 구현 및 테스트 완료
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
const ProjectAssignPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is Project Assign Page</div>)
|
||||
}
|
||||
|
||||
export default ProjectAssignPage;
|
||||
@@ -57,11 +57,6 @@ const UserManagePage = () => {
|
||||
|
||||
const userData = await nextApi.get<UserInfo[]>("/user");
|
||||
setUserList(userData);
|
||||
|
||||
const cmpnArray = Array.from(
|
||||
new Set(userData.map(u => u.userCmpn).filter(Boolean))
|
||||
).sort((a, b) => a.localeCompare(b, "ko"));
|
||||
setUserCmpnArray(cmpnArray);
|
||||
}
|
||||
|
||||
// 등록 버튼 클릭
|
||||
|
||||
498
src/app/(pages)/(main)/project/assign/page.tsx
Normal file
498
src/app/(pages)/(main)/project/assign/page.tsx
Normal file
@@ -0,0 +1,498 @@
|
||||
'use client'
|
||||
|
||||
import {useCallback, useEffect, useMemo, useState} from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { ChevronLeft, ChevronRight } from 'lucide-react'
|
||||
import { KriSingleSelect } from '@/components/common/KriAutoComplete'
|
||||
import {ProjectInfo} from "@/types/project";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {PROJECT_SEARCH_COUNT} from "@/const/projectConst";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
import {UserInfo} from "@/types/user";
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
import {KriSelect, KriSelectItem} from "@/components/common/KriSelect";
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import {RoleInfo} from "@/types/role";
|
||||
import {CONTACT_USER_ROLE, FW_USER_ROLE} from "@/const/userConst";
|
||||
import {useLoading} from "@/hooks/useLoading";
|
||||
import _ from "lodash";
|
||||
|
||||
const ProjectAssignPage = () => {
|
||||
const mounted = useMounted();
|
||||
const { withLoadingAsync } = useLoading();
|
||||
const { auth } = useAuth();
|
||||
const { selectedProject } = useSelectedProject();
|
||||
|
||||
const [projectArray, setProjectArray] = useState<ProjectInfo[]>([]);
|
||||
const [searchKeyword, setSearchKeyword] = useState("");
|
||||
const debouncedKeyword = useDebouncedValue(searchKeyword, 500);
|
||||
const [sourceProject, setSourceProject] = useState<ProjectInfo>();
|
||||
|
||||
const [companyArray, setCompanyArray] = useState<string[]>([]);
|
||||
const [companyFilter, setCompanyFilter] = useState<string>('');
|
||||
const [roleArray, setRoleArray] = useState<KriSelectItem[]>([]);
|
||||
const [roleFilter, setRoleFilter] = useState<KriSelectItem>();
|
||||
const [fwUserArray, setFwUserArray] = useState<UserInfo[]>([]);
|
||||
|
||||
const [originAssign, setOriginAssign] = useState<UserInfo[]>([]);
|
||||
const [assignUserArray, setAssignUserArray] = useState<UserInfo[]>([]);
|
||||
const [selectedAssignUser, setSelectedAssignUser] = useState<string[]>([]);
|
||||
const [searchAssign, setSearchAssign] = useState('');
|
||||
const debouncedAssign = useDebouncedValue(searchAssign, 500);
|
||||
|
||||
const [assignInfoString, setAssignInfoString] = useState<string>('');
|
||||
|
||||
const [ableUserArray, setAbleUserArray] = useState<UserInfo[]>([]);
|
||||
const [selectedAbleUser, setSelectedAbleUser] = useState<string[]>([]);
|
||||
const [searchAble, setSearchAble] = useState('');
|
||||
const debouncedAble = useDebouncedValue(searchAble, 500);
|
||||
|
||||
const searchTopProject = async (keyword: string) => {
|
||||
const res = await nextApi.get<ProjectInfo[]>(
|
||||
`/project/top/${PROJECT_SEARCH_COUNT}`,
|
||||
{ query: { keyword } }
|
||||
);
|
||||
|
||||
setProjectArray(res);
|
||||
};
|
||||
|
||||
const handleSelectProject = (info:ProjectInfo|null) => {
|
||||
if(info === null){
|
||||
setSourceProject(undefined)
|
||||
}
|
||||
else{
|
||||
setSourceProject(info);
|
||||
}
|
||||
}
|
||||
|
||||
const handleSelectAllLeft = (checked: boolean) => {
|
||||
if (checked) {
|
||||
setSelectedAssignUser(assignUserArray.map(u => u.userId))
|
||||
} else {
|
||||
setSelectedAssignUser([])
|
||||
}
|
||||
}
|
||||
|
||||
const handleSelectAllRight = (checked: boolean) => {
|
||||
if (checked) {
|
||||
setSelectedAbleUser(ableUserArray.map(u => u.userId))
|
||||
} else {
|
||||
setSelectedAbleUser([])
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggleUnassign = (id: string) => {
|
||||
setSelectedAssignUser(prev =>
|
||||
prev.includes(id)
|
||||
? prev.filter(x => x !== id)
|
||||
: [...prev, id]
|
||||
)
|
||||
}
|
||||
|
||||
const handleToggleAssign = (id: string) => {
|
||||
setSelectedAbleUser(prev =>
|
||||
prev.includes(id)
|
||||
? prev.filter(x => x !== id)
|
||||
: [...prev, id]
|
||||
)
|
||||
}
|
||||
|
||||
const appendUserInfo = (
|
||||
userIdArray:string[],
|
||||
sourceArray:UserInfo[]
|
||||
) => {
|
||||
return sourceArray.filter(user => userIdArray.includes(user.userId));
|
||||
}
|
||||
|
||||
const resetSelect = () => {
|
||||
setSelectedAssignUser([]);
|
||||
setSelectedAbleUser([]);
|
||||
|
||||
//검색도 초기화
|
||||
setSearchAssign('');
|
||||
setSearchAble('');
|
||||
}
|
||||
|
||||
const resetSelectAndAssign = () => {
|
||||
resetSelect();
|
||||
setAssignUserArray(_.cloneDeep(originAssign));
|
||||
};
|
||||
|
||||
const handleCompanyChange = (v: string) => {
|
||||
resetSelectAndAssign();
|
||||
setCompanyFilter(v);
|
||||
// 필요하면 데이터도 같이 재조회/재계산 트리거
|
||||
};
|
||||
|
||||
const handleRoleChange = (item: KriSelectItem) => {
|
||||
resetSelectAndAssign();
|
||||
setRoleFilter(item);
|
||||
};
|
||||
|
||||
const handleAssign = () => {
|
||||
const toAssign = ableUserArray.filter(u => selectedAbleUser.includes(u.userId));
|
||||
setAssignUserArray(prev => [...prev, ...toAssign]);
|
||||
|
||||
setSelectedAbleUser([]);
|
||||
}
|
||||
|
||||
const handleRemove = () => {
|
||||
const toRemove = assignUserArray.filter(u => selectedAssignUser.includes(u.userId));
|
||||
setAssignUserArray(prev => prev.filter(u => !selectedAssignUser.includes(u.userId)));
|
||||
|
||||
setSelectedAssignUser([]);
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
if(selectedProject){
|
||||
await nextApi.put(
|
||||
`/assign/prjct-fieldwork/${selectedProject.prjctIdx}`,
|
||||
assignUserArray.map(u => u.userId)
|
||||
)
|
||||
|
||||
setOriginAssign(_.cloneDeep(assignUserArray));
|
||||
|
||||
alert("저장되었습니다.");
|
||||
}
|
||||
else{
|
||||
alert("옳지 않은 요청입니다.");
|
||||
}
|
||||
}
|
||||
|
||||
const baseFiltered = useCallback((users: UserInfo[]) => {
|
||||
return users.filter(
|
||||
(u) =>
|
||||
String(u.userRole) === roleFilter?.value &&
|
||||
u.userCmpn === companyFilter
|
||||
);
|
||||
}, [roleFilter, companyFilter]);
|
||||
|
||||
const withKeyword = useCallback((users: UserInfo[], keyword: string) => {
|
||||
const k = keyword.trim();
|
||||
if (!k) return users;
|
||||
|
||||
return users.filter(
|
||||
(u) => u.userId.includes(k) || u.userName.includes(k)
|
||||
);
|
||||
}, []);
|
||||
|
||||
const assignBase = useMemo(
|
||||
() => baseFiltered(assignUserArray),
|
||||
[assignUserArray, baseFiltered]
|
||||
);
|
||||
|
||||
const assignView = useMemo(
|
||||
() => withKeyword(assignBase, debouncedAssign),
|
||||
[assignBase, debouncedAssign, withKeyword]
|
||||
);
|
||||
|
||||
const assignedIdSet = useMemo(
|
||||
() => new Set(assignUserArray.map(u => u.userId)),
|
||||
[assignUserArray]
|
||||
);
|
||||
|
||||
const ableBase = useMemo(
|
||||
() => baseFiltered(ableUserArray)
|
||||
.filter((user) => !assignedIdSet.has(user.userId)),
|
||||
[ableUserArray, baseFiltered, assignedIdSet]
|
||||
);
|
||||
|
||||
const ableView = useMemo(
|
||||
() => withKeyword(ableBase, debouncedAble)
|
||||
.filter((user) => !assignedIdSet.has(user.userId)),
|
||||
[ableBase, debouncedAble, withKeyword, assignedIdSet]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if(selectedProject){
|
||||
const keyword = debouncedKeyword.trim();
|
||||
searchTopProject(keyword);
|
||||
}
|
||||
}, [debouncedKeyword]);
|
||||
|
||||
useEffect(() => {
|
||||
withLoadingAsync(async () => {
|
||||
nextApi.get<UserInfo[]>("/user/fieldwork")
|
||||
.then(res => setFwUserArray(res));
|
||||
|
||||
nextApi.get<string[]>("/user/cmpn")
|
||||
.then((res) => setCompanyArray(res));
|
||||
|
||||
const roleList = await nextApi.get<RoleInfo[]>("/role")
|
||||
const roleOptionArray = roleList
|
||||
.filter(role => role.roleCd >= FW_USER_ROLE)
|
||||
.map((role) => ({
|
||||
value: String(role.roleCd),
|
||||
label: role.roleNm,
|
||||
}))
|
||||
setRoleArray(roleOptionArray);
|
||||
const contactRole = roleOptionArray.find((role) => role.value === CONTACT_USER_ROLE.toString());
|
||||
if(contactRole){
|
||||
setRoleFilter(contactRole);
|
||||
}
|
||||
})
|
||||
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if(auth.user){
|
||||
setCompanyFilter(auth.user.userCmpn || "")
|
||||
}
|
||||
}, [auth.user]);
|
||||
|
||||
useEffect(() => {
|
||||
withLoadingAsync(async () => {
|
||||
if(selectedProject){
|
||||
const res = await nextApi.get<string[]>(`/assign/prjct-fieldwork/${selectedProject.prjctIdx}`);
|
||||
const assignUserInfoArray = appendUserInfo(res, fwUserArray);
|
||||
|
||||
setAssignUserArray(assignUserInfoArray);
|
||||
setOriginAssign(assignUserInfoArray);
|
||||
}else{
|
||||
setAssignUserArray([]);
|
||||
setOriginAssign([]);
|
||||
}
|
||||
resetSelect();
|
||||
});
|
||||
}, [fwUserArray, selectedProject, roleArray]);
|
||||
|
||||
useEffect(() => {
|
||||
const assignString = roleArray.map((role) => {
|
||||
const assignCount = originAssign.filter(user => user.userRole.toString() === role.value).length
|
||||
return `${role.label} : ${assignCount}`;
|
||||
}).join(' / ');
|
||||
|
||||
setAssignInfoString(assignString);
|
||||
}, [originAssign]);
|
||||
|
||||
useEffect(() => {
|
||||
withLoadingAsync(async () => {
|
||||
let ableUserList :UserInfo[] = [];
|
||||
|
||||
if(sourceProject){
|
||||
const res = await nextApi.get<string[]>(`/assign/prjct-fieldwork/${sourceProject.prjctIdx}`);
|
||||
ableUserList = appendUserInfo(res, fwUserArray);
|
||||
}
|
||||
else{
|
||||
ableUserList = _.cloneDeep(fwUserArray);
|
||||
}
|
||||
|
||||
setAbleUserArray(ableUserList);
|
||||
});
|
||||
}, [fwUserArray, sourceProject]);
|
||||
|
||||
if (!mounted || !selectedProject) return null
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50 p-1">
|
||||
<div className="max-w-7xl mx-auto">
|
||||
{/* 공용 필터 바 (회사 / 대상) */}
|
||||
<div className="mb-6 rounded-lg border border-gray-200 bg-white p-4 shadow-sm">
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-end">
|
||||
<div className="w-full sm:w-auto flex items-center gap-3">
|
||||
<div className="w-14 content-text-lg font-medium text-gray-700 whitespace-nowrap text-right">
|
||||
회사
|
||||
</div>
|
||||
<KriSelect
|
||||
items={companyArray}
|
||||
value={companyFilter}
|
||||
onChange={handleCompanyChange}
|
||||
placeholder="회사 선택"
|
||||
className="w-56 h-9"
|
||||
useAll={false}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="w-full sm:w-auto flex items-center gap-3">
|
||||
<div className="w-14 content-text-lg font-medium text-gray-700 whitespace-nowrap text-right">
|
||||
대상
|
||||
</div>
|
||||
<KriSelect
|
||||
items={roleArray}
|
||||
value={roleFilter?.value || ""}
|
||||
onChangeOption={handleRoleChange}
|
||||
placeholder="대상 선택"
|
||||
className="w-56 h-9"
|
||||
useAll={false}
|
||||
getValue={(x) => x.value}
|
||||
getLabel={(x) => x.label}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 메인 배정 영역 */}
|
||||
<div className="grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] gap-6 mb-6">
|
||||
{/* 왼쪽: 배정된 면접원 */}
|
||||
<div className="min-w-0">
|
||||
<div className="p-3 bg-black text-white rounded-lg content-text-lg mb-2 h-15 flex items-center">
|
||||
<span className="truncate w-full">
|
||||
{assignInfoString}
|
||||
</span>
|
||||
</div>
|
||||
<div className="border border-gray-200 rounded-lg overflow-hidden bg-white shadow-sm">
|
||||
<div className="bg-gray-50 p-3 border-b border-gray-200">
|
||||
<Input
|
||||
placeholder="면접원 ID Or 면접원 이름"
|
||||
value={searchAssign}
|
||||
onChange={(e) => setSearchAssign(e.target.value)}
|
||||
className="bg-white border-gray-300"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="h-[600px] overflow-y-auto">
|
||||
<table className="w-full">
|
||||
<thead className="bg-black text-white sticky top-0">
|
||||
<tr>
|
||||
<th className="p-3 text-left w-12">
|
||||
<Checkbox
|
||||
checked={selectedAssignUser.length === assignView.length && assignView.length > 0}
|
||||
onCheckedChange={handleSelectAllLeft}
|
||||
className="border-white"
|
||||
/>
|
||||
</th>
|
||||
<th className="p-3 text-left content-text-base font-medium">배정된 {roleFilter?.label} ( {assignBase.length}명 )</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{assignView
|
||||
.map((userInfo) => (
|
||||
<tr
|
||||
key={userInfo.userId}
|
||||
className={`border-b border-gray-100 cursor-pointer hover:bg-gray-50 ${
|
||||
selectedAssignUser.includes(userInfo.userId) ? 'bg-blue-50' : ''
|
||||
}`}
|
||||
onClick={() => handleToggleUnassign(userInfo.userId)}
|
||||
>
|
||||
<td className="p-3">
|
||||
<Checkbox
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
checked={selectedAssignUser.includes(userInfo.userId)}
|
||||
onCheckedChange={() => handleToggleUnassign(userInfo.userId)}
|
||||
/>
|
||||
</td>
|
||||
<td className="p-3 content-text-base">
|
||||
{userInfo.userName} ({userInfo.userId})
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 가운데: 배정/제외 버튼 */}
|
||||
<div className="flex flex-col justify-center gap-4">
|
||||
<Button
|
||||
onClick={handleAssign}
|
||||
disabled={selectedAbleUser.length === 0}
|
||||
className="bg-black hover:bg-gray-800 w-36 h-12 flex items-center justify-center content-text-base disabled:bg-gray-300"
|
||||
>
|
||||
<ChevronLeft className="w-5 h-5" />
|
||||
<span className="ml-2">배정 {selectedAbleUser.length}명</span>
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleRemove}
|
||||
disabled={selectedAssignUser.length === 0}
|
||||
className="bg-red-600 hover:bg-red-700 w-36 h-12 flex items-center justify-center content-text-base disabled:bg-gray-300"
|
||||
>
|
||||
<ChevronRight className="w-5 h-5" />
|
||||
<span className="ml-2">제외 {selectedAssignUser.length}명</span>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 오른쪽: 전체 면접원 풀 */}
|
||||
<div className="min-w-0">
|
||||
<div className="p-3 bg-black text-white rounded-lg content-text-lg mb-2 h-15">
|
||||
<KriSingleSelect
|
||||
<ProjectInfo>
|
||||
items={projectArray}
|
||||
value={String(sourceProject?.prjctIdx ?? "")}
|
||||
onChange={() => {}}
|
||||
withInfo
|
||||
onItemChange={handleSelectProject}
|
||||
searchMode="inputOnly"
|
||||
onSearchValueChange={setSearchKeyword}
|
||||
placeholder="프로젝트 검색..."
|
||||
widthClassName="w-full"
|
||||
heightClassName="h-9"
|
||||
preventDeselect
|
||||
hideOptionCheck
|
||||
useClear
|
||||
getLabel={(item) => `${item.prjctCd}_${item.prjctName}`}
|
||||
getValue={(item) => String(item.prjctIdx)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="border border-gray-200 rounded-lg overflow-hidden bg-white shadow-sm">
|
||||
<div className="bg-gray-50 p-3 border-b border-gray-200">
|
||||
<Input
|
||||
placeholder="면접원 ID Or 면접원 이름"
|
||||
value={searchAble}
|
||||
onChange={(e) => setSearchAble(e.target.value)}
|
||||
className="bg-white border-gray-300"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="h-[600px] overflow-y-auto">
|
||||
<table className="w-full">
|
||||
<thead className="bg-black text-white sticky top-0">
|
||||
<tr>
|
||||
<th className="p-3 text-left w-12">
|
||||
<Checkbox
|
||||
checked={selectedAbleUser.length === ableView.length && ableView.length > 0}
|
||||
onCheckedChange={handleSelectAllRight}
|
||||
className="border-white"
|
||||
/>
|
||||
</th>
|
||||
<th className="p-3 text-left content-text-base font-medium">배정 가능 {roleFilter?.label} ({ableBase.length}명 )</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{ableView
|
||||
.map((user) => (
|
||||
<tr
|
||||
key={user.userId}
|
||||
className={`border-b border-gray-100 cursor-pointer hover:bg-gray-50 ${
|
||||
selectedAbleUser.includes(user.userId) ? 'bg-blue-50' : ''
|
||||
}`}
|
||||
onClick={() => handleToggleAssign(user.userId)}
|
||||
>
|
||||
<td className="p-3">
|
||||
<Checkbox
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
checked={selectedAbleUser.includes(user.userId)}
|
||||
onCheckedChange={() => handleToggleAssign(user.userId)}
|
||||
/>
|
||||
</td>
|
||||
<td className="p-3 content-text-base">
|
||||
{user.userName} ({user.userId})
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 하단 저장 버튼 */}
|
||||
<div className="flex justify-center">
|
||||
<Button
|
||||
onClick={handleSave}
|
||||
className="bg-black hover:bg-gray-800 px-12 h-11 content-text-base font-medium"
|
||||
>
|
||||
저장
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ProjectAssignPage;
|
||||
@@ -147,7 +147,7 @@ const ProjectInfoPage = () => {
|
||||
resultCodeList: updateCodeArray,
|
||||
assignUserIdList: outsourceUserArray,
|
||||
}
|
||||
console.log(requestUpdateProject, projectInfo.prjctIdx)
|
||||
|
||||
await nextApi.patch(`/project/${projectInfo.prjctIdx}`, requestUpdateProject);
|
||||
|
||||
alert("저장되었습니다.");
|
||||
@@ -476,6 +476,7 @@ console.log(requestUpdateProject, projectInfo.prjctIdx)
|
||||
{projectInfo.useContactSenario && (
|
||||
<div className="ml-6 border rounded p-4 bg-gray-50 text-sm text-gray-600">
|
||||
<KriEditor
|
||||
//editorMode={"both"}
|
||||
value={projectInfo.contactSenario ?? "<p></p>"}
|
||||
onChange={(html: string) => handleChange("contactSenario", html)}
|
||||
placeholder="컨택 시나리오를 작성해 주세요"
|
||||
|
||||
@@ -17,7 +17,7 @@ import {NONE_HTTP_ERROR} from "@/const/commonConst";
|
||||
|
||||
const LoginPage = () => {
|
||||
const searchParams = useSearchParams();
|
||||
const { setFromLoginResponse } = useAuth();
|
||||
const { auth, setFromLoginResponse } = useAuth();
|
||||
const { withLoadingAsync } = useLoading();
|
||||
const { get: getSeatNumberStorage, set: setSeatNumberStorage } = useStorage(StorageKeys.SeatNumber);
|
||||
const { get: getLoginTypeStorage, set: setLoginTypeStorage } = useStorage(StorageKeys.LoginType);
|
||||
@@ -61,8 +61,6 @@ const LoginPage = () => {
|
||||
// 저장 실패는 치명적이지 않으므로 콘솔 로깅만
|
||||
console.warn("Failed to persist SeatNumber to secure storage:", e);
|
||||
}
|
||||
// 메인 페이지로 이동 (보호 라우트 진입)
|
||||
window.location.replace("/");
|
||||
}).catch((e) => {
|
||||
const err = apiError(e);
|
||||
console.error(err.status, err.code, err.message);
|
||||
@@ -80,6 +78,12 @@ const LoginPage = () => {
|
||||
);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if(auth.user){
|
||||
window.location.replace("/");
|
||||
}
|
||||
}, [auth]);
|
||||
|
||||
// URL 쿼리 파라미터에서 type 수신
|
||||
useEffect(() => {
|
||||
const typeParam = searchParams.get("type") ?? "";
|
||||
|
||||
@@ -10,11 +10,41 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
const [action] = slug;
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if (action === "prjct-outsource") {
|
||||
if (action === "prjct-outsource" && slug.length === 2) {
|
||||
const result = await contactApi.get<string[]>(`/assign/prjct-outsource/${slug[1]}`);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if (action === "prjct-fieldwork" && slug.length === 2) {
|
||||
const result = await contactApi.get<string[]>(`/assign/prjct-fieldwork/${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 === "prjct-fieldwork" && slug.length === 2) {
|
||||
const body = await req.json().catch(() => null);
|
||||
if (!body) {
|
||||
return NextResponse.json(
|
||||
{ message: "요청 바디가 없습니다." },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
await contactApi.put(`/assign/prjct-fieldwork/${slug[1]}`, body);
|
||||
return new NextResponse(null, { status: 204 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
|
||||
@@ -35,6 +35,11 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if(action === "fieldwork"){
|
||||
const result = await contactApi.get<UserInfo[]>("/user/fieldwork");
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if (slug.length === 1) {
|
||||
const userId = action;
|
||||
const result = await contactApi.get<UserInfo>(`/user/${encodeURIComponent(userId)}`);
|
||||
|
||||
Reference in New Issue
Block a user