-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 스터디 멘토 검색 기능 추가 * chore: cursor pointer 스타일 추가
- Loading branch information
Showing
5 changed files
with
122 additions
and
30 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
118 changes: 88 additions & 30 deletions
118
apps/admin/app/studies/create-study/_components/StudyMentorSelect.tsx
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 |
---|---|---|
@@ -1,40 +1,98 @@ | ||
/* eslint-disable jsx-a11y/click-events-have-key-events */ | ||
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ | ||
"use client"; | ||
import { css } from "@styled-system/css"; | ||
import { Flex } from "@styled-system/jsx"; | ||
import { Text } from "@wow-class/ui"; | ||
import { Controller, useFormContext } from "react-hook-form"; | ||
import DropDown from "wowds-ui/DropDown"; | ||
import DropDownOption from "wowds-ui/DropDownOption"; | ||
import { createStudyApi } from "apis/study/createStudyApi"; | ||
import { useState } from "react"; | ||
import { useFormContext } from "react-hook-form"; | ||
import SearchBar from "wowds-ui/SearchBar"; | ||
|
||
type MentorListType = { | ||
memberId: number; | ||
name: string; | ||
}; | ||
|
||
const StudyMentorSelect = () => { | ||
const { control } = useFormContext(); | ||
const { setValue } = useFormContext(); | ||
const [memberList, setMemberList] = useState<MentorListType[]>([]); | ||
const [openPopup, setOpenPopup] = useState(false); | ||
const [mentor, setMentor] = useState(""); | ||
|
||
const fetchStudyMentor = async (name: string) => { | ||
const response = await createStudyApi.searchStudyMentor(name); | ||
const formatMentorList = response.map((data) => { | ||
return { | ||
memberId: data.memberId, | ||
name: data.name, | ||
}; | ||
}); | ||
setMemberList([...formatMentorList]); | ||
setOpenPopup(true); | ||
}; | ||
|
||
return ( | ||
<Controller | ||
control={control} | ||
defaultValue={0} | ||
name="mentorId" | ||
render={({ field }) => ( | ||
<Flex direction="column" gap="xl"> | ||
<Text typo="h2">스터디 멘토</Text> | ||
<DropDown | ||
{...field} | ||
placeholder="선택하세요" | ||
style={{ width: "270px" }} | ||
value={field.value ? String(field.value) : ""} | ||
onChange={({ selectedValue }) => { | ||
field.onChange(Number(selectedValue)); | ||
}} | ||
> | ||
<DropDownOption text="김유진" value="3" /> | ||
<DropDownOption text="홍서현" value="5" /> | ||
<DropDownOption text="이현영" value="15" /> | ||
</DropDown> | ||
</Flex> | ||
)} | ||
rules={{ | ||
required: true, | ||
}} | ||
/> | ||
<Flex direction="column" gap="xl"> | ||
<Text typo="h2">스터디 멘토</Text> | ||
<div style={{ position: "relative" }}> | ||
<SearchBar | ||
placeholder="멘토를 검색해주세요" | ||
style={{ width: "270px" }} | ||
value={mentor} | ||
onChange={(value) => { | ||
setMentor(value); | ||
fetchStudyMentor(value); | ||
}} | ||
/> | ||
{openPopup && mentor.length > 0 && ( | ||
<ul className={MemberListPopupStyle}> | ||
{memberList.length > 0 ? ( | ||
<> | ||
{memberList.map((data) => ( | ||
<li | ||
className={MemberListItemStyle} | ||
key={data.memberId} | ||
onClick={() => { | ||
setValue("mentorId", data.memberId, { | ||
shouldValidate: true, | ||
}); | ||
setOpenPopup(false); | ||
setMentor(data.name); | ||
}} | ||
> | ||
<Text color="sub" typo="body1"> | ||
{data.name} | ||
</Text> | ||
</li> | ||
))} | ||
</> | ||
) : ( | ||
<Text color="sub" typo="body1"> | ||
일치하는 결과가 없어요. | ||
</Text> | ||
)} | ||
</ul> | ||
)} | ||
</div> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default StudyMentorSelect; | ||
|
||
const MemberListPopupStyle = css({ | ||
position: "absolute", | ||
top: "50px", | ||
width: "320px", | ||
zIndex: 999, | ||
borderRadius: "8px", | ||
backgroundColor: "white", | ||
shadow: "mono", | ||
padding: "xs", | ||
}); | ||
|
||
const MemberListItemStyle = css({ | ||
marginY: "5px", | ||
cursor: "pointer", | ||
}); |
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,18 @@ | ||
export interface SearchStudyMentorResponseDto { | ||
memberId: number; | ||
studentId: string; | ||
name: string; | ||
phone: string; | ||
department: { | ||
code: string; | ||
name: string; | ||
}; | ||
email: string; | ||
discordUsername: string; | ||
nickname: string; | ||
requirement: { | ||
univStatus: string; | ||
discordStatus: string; | ||
bevyStatus: string; | ||
}; | ||
} |