-
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.
Merge pull request #194 from BCSDLab/feat/position-search
[직책관리] 이름검색, 동명이인처리, API변경 반영
- Loading branch information
Showing
6 changed files
with
191 additions
and
54 deletions.
There are no files selected for viewing
Binary file not shown.
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,85 @@ | ||
import { | ||
useState, useEffect, useCallback, memo, useMemo, | ||
} from 'react'; | ||
import { | ||
Typography, Box, List, TextField, ListItemText, Modal, ListItemButton, | ||
} from '@mui/material'; | ||
import { useSearchMembers } from 'query/members'; | ||
import { Member } from 'model/member'; | ||
import * as S from './style'; | ||
|
||
interface SearchMemberModalProps { | ||
open: boolean; | ||
onClose: () => void; | ||
onSelect: (member: Member) => void; | ||
} | ||
|
||
function SearchNameModal({ | ||
open, onClose, onSelect, | ||
}: SearchMemberModalProps) { | ||
const [searchQuery, setSearchQuery] = useState(''); | ||
const [searchResults, setSearchResults] = useState<Member[]>([]); | ||
|
||
const { data: membersResult } = useSearchMembers({ | ||
pageIndex: 0, pageSize: 1000, name: searchQuery, | ||
}); | ||
|
||
useEffect(() => { | ||
if (membersResult) { | ||
setSearchResults(membersResult.content); | ||
} else { | ||
setSearchResults([]); | ||
} | ||
}, [membersResult]); | ||
|
||
const handleSearchChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearchQuery(e.target.value); | ||
}, []); | ||
|
||
const renderSearchResults = useMemo(() => ( | ||
searchResults | ||
.filter((member) => (member.isDeleted === false && member.memberType === 'REGULAR')) | ||
.map((member) => ( | ||
<ListItemButton | ||
key={member.id} | ||
sx={S.listButton} | ||
onClick={() => { | ||
onSelect(member); | ||
onClose(); | ||
}} | ||
> | ||
<ListItemText primary={`${member.name} (${member.track.name})`} /> | ||
</ListItemButton> | ||
)) | ||
), [searchResults, onSelect, onClose]); | ||
|
||
return ( | ||
<Modal | ||
open={open} | ||
onClose={onClose} | ||
aria-labelledby="modal-modal-title" | ||
aria-describedby="modal-modal-description" | ||
> | ||
<Box sx={S.modalView}> | ||
<Typography id="modal-modal-title" variant="h6" component="h2"> | ||
추가할 사용자를 검색하세요 | ||
</Typography> | ||
<TextField | ||
type="text" | ||
variant="outlined" | ||
value={searchQuery} | ||
onChange={handleSearchChange} | ||
fullWidth | ||
autoFocus | ||
/> | ||
<Box sx={S.searchMemberResult}> | ||
<List> | ||
{renderSearchResults} | ||
</List> | ||
</Box> | ||
</Box> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default memo(SearchNameModal); |
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,27 @@ | ||
export const modalView = { | ||
position: 'absolute', | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
width: 400, | ||
bgcolor: 'background.paper', | ||
border: '2px solid #000', | ||
boxShadow: 24, | ||
borderRadius: 1, | ||
p: 4, | ||
}; | ||
|
||
export const searchMemberResult = { | ||
height: 300, | ||
overflow: 'auto', | ||
}; | ||
|
||
export const listButton = { | ||
border: 1, | ||
borderColor: 'gray', | ||
borderRadius: 2, | ||
marginBottom: 1, | ||
'&:hover': { | ||
backgroundColor: '#D6F3FE', | ||
}, | ||
}; |
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