-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add : 외출 수락 및 외출자 조회
- Loading branch information
Showing
9 changed files
with
480 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
"use client"; | ||
import { OutAcceptApi, GetClass } from "@/api/outList"; | ||
import { applicationOK, earlyReturnHome } from "@/api/type"; | ||
import BackGround from "@/components/background"; | ||
import Button from "@/components/button"; | ||
import Dropdown from "@/components/dropdown"; | ||
import NonReturn from "@/components/list/application"; | ||
import Modal from "@/components/modal"; | ||
import { getFullToday } from "@/util/date"; | ||
import { getStudentString } from "@/util/util"; | ||
import React, { useEffect, useState } from "react"; | ||
|
||
const OutAccept = () => { | ||
const [selectedTab, setSelectedTab] = useState<boolean>(true); | ||
const [applicationData, setApplicationData] = useState<applicationOK[]>(); | ||
const [earlyData, setEarlyData] = useState<earlyReturnHome[]>(); | ||
const [selectGrade, setSelectGrade] = useState<number>(1); | ||
const [selectClass, setSelectClass] = useState<number>(1); | ||
const [selectedStudents, setSelectedStudents] = useState<string[]>([]); | ||
const [acmodal, setAcModal] = useState<boolean>(false); | ||
const [nomodal, setNomodal] = useState<boolean>(false); | ||
const [selectedStudentName, setSelectedStudentName] = useState<string[]>([]); | ||
const { mutate: outAcceptMutate } = GetClass(); | ||
const { mutate: AcceptMutate } = OutAcceptApi(); | ||
|
||
useEffect(() => { | ||
AcceptDataList(); | ||
}, [selectedTab]); | ||
|
||
useEffect(() => { | ||
AcceptDataList(); | ||
}, [selectGrade, selectClass]); | ||
|
||
const handleGradeChange = (selectedOption: number) => { | ||
if (selectedOption === 5) { | ||
setSelectGrade(5); | ||
setSelectClass(5); | ||
} else { | ||
setSelectGrade(selectedOption); | ||
} | ||
}; | ||
|
||
const handleClassChange = (selectedOption: number) => { | ||
if (selectGrade === 5) { | ||
alert("학년을 선택해주세요"); | ||
setSelectClass(selectedOption); | ||
} else { | ||
setSelectClass(selectedOption); | ||
} | ||
}; | ||
|
||
const AcceptDataList = async () => { | ||
try { | ||
if (selectGrade && selectClass) { | ||
const reqOption = selectedTab ? "application" : "early-return"; | ||
await outAcceptMutate( | ||
{ | ||
type: reqOption, | ||
grade: selectGrade, | ||
class: selectClass, | ||
}, | ||
{ | ||
onSuccess: (data) => { | ||
setApplicationData(data); | ||
}, | ||
onError: (error) => { | ||
console.log(error); | ||
}, | ||
} | ||
); | ||
} | ||
} catch (error) { | ||
console.error("Out accept error", error); | ||
} | ||
}; | ||
|
||
const handleAcceptListClick = (id: string, name: string) => { | ||
const isStudentSelected = selectedStudents.includes(id); | ||
if (isStudentSelected) { | ||
setSelectedStudents((prevSelectedStudents) => | ||
prevSelectedStudents.filter((selectedStudent) => selectedStudent !== id) | ||
); | ||
setSelectedStudentName((prevSelectedStudentName) => | ||
prevSelectedStudentName.filter( | ||
(selectedStudentName) => selectedStudentName !== name | ||
) | ||
); | ||
} else { | ||
setSelectedStudents((prevSelectedStudents) => [ | ||
...prevSelectedStudents, | ||
id, | ||
]); | ||
setSelectedStudentName((prevSelectedStudentName) => [ | ||
...prevSelectedStudentName, | ||
name, | ||
]); | ||
} | ||
}; | ||
|
||
const Accept = () => { | ||
setAcModal(true); | ||
}; | ||
|
||
const onCancel = () => { | ||
setAcModal(false); | ||
setNomodal(false); | ||
}; | ||
|
||
const No = () => { | ||
setNomodal(true); | ||
}; | ||
|
||
const onClickTab = (tab: boolean) => { | ||
setSelectedTab(tab); | ||
}; | ||
|
||
const confirmReturn = async () => { | ||
try { | ||
if (selectGrade && selectClass) { | ||
const reqOption = selectedTab ? "application" : "early-return"; | ||
await AcceptMutate( | ||
{ | ||
type: reqOption, | ||
status: "NO", | ||
ids: selectedStudents, | ||
}, | ||
{ | ||
onSuccess: () => { | ||
setNomodal(false); | ||
}, | ||
onError: (error) => { | ||
console.error("Out accept error", error); | ||
setNomodal(false); | ||
}, | ||
} | ||
); | ||
} | ||
} catch (error) { | ||
alert("외출 거절에 실패하였습니다"); | ||
setNomodal(false); | ||
} | ||
}; | ||
|
||
const Acceptconfirm = async () => { | ||
try { | ||
if (selectGrade && selectClass) { | ||
const reqOption = selectedTab ? "application" : "early-return"; | ||
await AcceptMutate( | ||
{ | ||
type: reqOption, | ||
status: "OK", | ||
ids: selectedStudents, | ||
}, | ||
{ | ||
onSuccess: () => { | ||
setAcModal(false); | ||
// location.reload(); | ||
}, | ||
onError: (error) => { | ||
console.error("Out accept error", error); | ||
setAcModal(false); | ||
}, | ||
} | ||
); | ||
} | ||
} catch (error) { | ||
alert("외출 수락에 실패하였습니다"); | ||
setAcModal(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<BackGround | ||
title="외출자 수락" | ||
subTitle={getFullToday()} | ||
TabOK={true} | ||
TabOnclick={onClickTab} | ||
Dropdown={ | ||
<div className=" flex w-full justify-between min-w-fit items-center gap-1"> | ||
<div className=" flex gap-2"> | ||
<Dropdown type="all" onChange={handleGradeChange} /> | ||
<Dropdown type="class" onChange={handleClassChange} /> | ||
</div> | ||
<div className=" flex gap-2 w-32"> | ||
<Button colorType="red" buttonSize="extraSmall2" onClick={No}> | ||
거절 | ||
</Button> | ||
<Button | ||
colorType="primary" | ||
buttonSize="extraSmall2" | ||
onClick={Accept} | ||
> | ||
수락 | ||
</Button> | ||
</div> | ||
</div> | ||
} | ||
> | ||
<div className=" overflow-y-scroll gap-4 flex flex-col"> | ||
{selectedTab | ||
? applicationData?.map((item, index) => ( | ||
<NonReturn | ||
id={item.id} | ||
type="accept" | ||
key={index} | ||
returnTime={`${item.start_time}~${item.end_time}`} | ||
name={getStudentString(item)} | ||
onClick={() => handleAcceptListClick(item.id, item.username)} | ||
reason={item.reason} | ||
/> | ||
)) | ||
: applicationData?.map((item, index) => ( | ||
<NonReturn | ||
id={item.id} | ||
type="accept" | ||
key={index} | ||
returnTime={`${item.start_time}~`} | ||
name={getStudentString(item)} | ||
onClick={() => handleAcceptListClick(item.id, item.username)} | ||
reason={item.reason} | ||
/> | ||
))} | ||
</div> | ||
{acmodal && ( | ||
<Modal | ||
type="button" | ||
buttonMessage="수락" | ||
onConfirm={Acceptconfirm} | ||
onCancel={onCancel} | ||
heading1={`${ | ||
selectedStudentName.length > 1 | ||
? `${selectedStudentName[0]} 학생 외 ${ | ||
selectedStudentName.length - 1 | ||
}명` | ||
: selectedStudentName.length === 1 | ||
? `${selectedStudentName[0]} 학생` | ||
: "" | ||
}`} | ||
/> | ||
)} | ||
{nomodal && ( | ||
<Modal | ||
type="button" | ||
buttonMessage="거절" | ||
onConfirm={confirmReturn} | ||
onCancel={onCancel} | ||
heading1={`${ | ||
selectedStudentName.length > 1 | ||
? `${selectedStudentName[0]} 학생 외 ${ | ||
selectedStudentName.length - 1 | ||
}명` | ||
: selectedStudentName.length === 1 | ||
? `${selectedStudentName[0]} 학생` | ||
: "" | ||
}`} | ||
/> | ||
)} | ||
</BackGround> | ||
); | ||
}; | ||
|
||
export default OutAccept; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.