-
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.
* feat: 사용자 조회 API 스펙 변경 (#37) * feat: 학과 교육과정 url 추가 (#37) * feat: 학과 선택바 추가 (#37) * feat: API 권한 수정 (#37) * feat: 학과 조회 (#37) * feat: 학과 업데이트 (#37) * feat: 학과 초기값 설정 (#37)
- Loading branch information
1 parent
01ea306
commit 5c082ab
Showing
9 changed files
with
107 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Department} from '../types/Department' | ||
import {Base} from '../types/Result' | ||
import api from './config' | ||
|
||
export const fetchDepartments = async ( | ||
params?: Record<string, string> | ||
): Promise<Base<Department>> => { | ||
const res = await api.get('/api/v1/departments', {params}) | ||
return res.data | ||
} |
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,51 @@ | ||
import {useEffect, useState} from 'react' | ||
import {fetchDepartments} from '../../api/departmentApi' | ||
import {Base} from '../../types/Result' | ||
import {Department} from '../../types/Department' | ||
import useCustomMypage, {TCustomMypage} from '../../hooks/useCustomMypage' | ||
import useCustomMove, {TCustomMove} from '../../hooks/useCustomMove' | ||
|
||
interface ChangeDepartmentProps { | ||
department: string | ||
} | ||
|
||
const ChangeDepartment: React.FC<ChangeDepartmentProps> = ({department}) => { | ||
const {departmentChange}: TCustomMypage = useCustomMypage() | ||
const {reload}: TCustomMove = useCustomMove() | ||
const [departments, setDepartments] = useState<Base<Department>>() | ||
const [selectedDepartmentId, setSelectedDepartmentId] = useState<number | undefined>() | ||
|
||
useEffect(() => { | ||
fetchDepartments({isEditable: 'true'}).then((data: Base<Department>) => { | ||
setDepartments(data) | ||
const initialDepartment = data.content.find(dept => dept.name === department) | ||
if (initialDepartment) { | ||
setSelectedDepartmentId(initialDepartment.id) | ||
} | ||
}) | ||
}, [department]) | ||
|
||
const handleSelectChange = (event: React.ChangeEvent<HTMLSelectElement>) => { | ||
const departmentId: number = parseInt(event.target.value, 10) | ||
departmentChange({departmentId: departmentId}).then(success => { | ||
if (success) { | ||
alert('학과가 업데이트 되었습니다.') | ||
reload() | ||
} | ||
}) | ||
} | ||
|
||
return ( | ||
<td className="regi_box" style={{width: '90%', marginLeft: '0', marginRight: '1rem'}}> | ||
<select id="major" value={selectedDepartmentId} onChange={handleSelectChange}> | ||
{departments?.content?.map(department => ( | ||
<option key={department.id} value={department.id}> | ||
{department.name} | ||
</option> | ||
))} | ||
</select> | ||
</td> | ||
) | ||
} | ||
|
||
export default ChangeDepartment |
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
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,8 @@ | ||
export interface Department { | ||
id: number | ||
college: string | ||
name: string | ||
subDomain: string | ||
isEditable: boolean | ||
code: string | ||
} |
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,7 +1,7 @@ | ||
export interface MemberInfo { | ||
id: number | ||
username: string | ||
name: string | ||
department: string | ||
email: string | ||
deptCode: string | ||
deptEditable: boolean | ||
} |