Skip to content

Commit f90d37c

Browse files
committed
♻️ [refactor] : 회원 수정 api 연결
1 parent a2269b9 commit f90d37c

File tree

6 files changed

+102
-18
lines changed

6 files changed

+102
-18
lines changed

src/api/admin.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { NewLabelTypes, UserRegistrationApiProps } from '@/types/admin'
1+
import type { NewLabelTypes, UserRegistrationApiProps, UserUpdateValue } from '@/types/admin'
22
import type { LabelDataTypes } from '@/types/common'
33
import { axiosInstance, formDataAxiosInstance } from '@/utils/axios'
44

@@ -39,3 +39,13 @@ export const addMemberAdminByCsv = async (formdata: FormData) => {
3939
const response = await formDataAxiosInstance.post('/api/managements/members/upload', formdata)
4040
return response.data
4141
}
42+
43+
export const getMemberDetailAdmin = async (id: string) => {
44+
const response = await axiosInstance.get(`api/managements/members/${id}/details`)
45+
return response.data
46+
}
47+
48+
export const updateMemberAdmin = async (id: string, data: UserUpdateValue) => {
49+
const response = await axiosInstance.post(`api/managements/members/${id}`, data)
50+
return response.data
51+
}

src/components/member-management/MemberManagementListCard.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
:is-status="tab.isStatus" />
1111
<div class="w-[180px] flex gap-2 justify-center items-center shrink-0">
1212
<button
13-
@click="router.push(`/user-update`)"
13+
@click="router.push(`/user-update?id=${info.memberId}`)"
1414
class="button-medium-primary">
1515
수정
1616
</button>
@@ -57,15 +57,15 @@
5757
</template>
5858

5959
<script setup lang="ts">
60-
import type { ListCardProps, Role } from '@/types/common'
61-
import ListCardTab from '../lists/ListCardTab.vue'
6260
import type { MemberManagementListData } from '@/types/admin'
63-
import { useRouter } from 'vue-router'
64-
import ModalView from '../ModalView.vue'
65-
import { ref } from 'vue'
61+
import type { ListCardProps, Role } from '@/types/common'
6662
import { axiosInstance } from '@/utils/axios'
67-
import { useQueryClient } from '@tanstack/vue-query'
6863
import { formatDate } from '@/utils/date'
64+
import { useQueryClient } from '@tanstack/vue-query'
65+
import { ref } from 'vue'
66+
import { useRouter } from 'vue-router'
67+
import ListCardTab from '../lists/ListCardTab.vue'
68+
import ModalView from '../ModalView.vue'
6969
7070
const roleContent = (role: Role) => {
7171
return role === 'ROLE_USER' ? '사용자' : role === 'ROLE_MANAGER' ? '담당자' : '관리자'

src/components/request-task/RequestTaskInput.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
:value="modelValue"
1414
:disabled="isEdit"
1515
@input="updateValue(($event.target as HTMLInputElement).value)"
16-
:placeholder="placeholderText" />
16+
:placeholder="placeholderText"
17+
:class="{ 'text-gray-500': isEdit, 'text-black': !isEdit }" />
1718
<p
1819
v-if="isInvalidateState === 'input'"
1920
class="text-red-1 text-xs absolute top-[calc(100%+4px)]">

src/components/user-manage/UserUpdate.vue

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@
1515
:placeholderText="'회원의 아이디를 입력해주세요'"
1616
:isEdit="true"
1717
:labelName="'아이디'" />
18-
<RequestTaskInput
19-
v-model="userRegistrationForm.email"
20-
:placeholderText="'회원의 이메일을 입력해주세요'"
21-
:labelName="'이메일'" />
18+
<div class="flex w-full gap-2">
19+
<RequestTaskInput
20+
v-model="userRegistrationForm.nickname"
21+
:is-edit="true"
22+
:placeholderText="'이메일은 아이디와 동일합니다'"
23+
:labelName="'이메일'" />
24+
<RequestTaskInput
25+
v-model="userRegistrationForm.email"
26+
:placeholderText="'@kakao.com'"
27+
:label-name="'도메인'"
28+
:is-edit="true"
29+
:is-not-required="false" />
30+
</div>
2231
<RequestTaskDropdown
2332
v-model="userRegistrationForm.role"
2433
:options="RoleKeys"
@@ -44,9 +53,16 @@
4453
</template>
4554

4655
<script lang="ts" setup>
47-
import { INITIAL_USER_REGISTRATION, RoleKeys } from '@/constants/admin'
48-
import { ref } from 'vue'
49-
import { useRouter } from 'vue-router'
56+
import { getMemberDetailAdmin, updateMemberAdmin } from '@/api/admin'
57+
import {
58+
INITIAL_USER_REGISTRATION,
59+
RoleKeys,
60+
RoleMapping,
61+
RoleTypeMapping
62+
} from '@/constants/admin'
63+
import type { UserRegistrationProps } from '@/types/admin'
64+
import { onMounted, ref, watch } from 'vue'
65+
import { useRoute, useRouter } from 'vue-router'
5066
import FormButtonContainer from '../common/FormButtonContainer.vue'
5167
import FormCheckbox from '../common/FormCheckbox.vue'
5268
import ModalView from '../ModalView.vue'
@@ -57,15 +73,52 @@ import DepartmentDropDown from './DepartmentDropDown.vue'
5773
const isModalVisible = ref(false)
5874
const userRegistrationForm = ref(INITIAL_USER_REGISTRATION)
5975
76+
const route = useRoute()
6077
const router = useRouter()
78+
const userId = ref(route.query.id)
79+
const userData = ref<UserRegistrationProps | null>(null)
80+
console.log(userId.value, '유저 아이디')
81+
82+
watch(
83+
() => router.currentRoute.value.query.id,
84+
newId => {
85+
userId.value = newId
86+
}
87+
)
88+
onMounted(async () => {
89+
if (typeof userId.value === 'string') {
90+
userData.value = await getMemberDetailAdmin(userId.value)
91+
}
92+
if (userData.value) {
93+
if (userData.value.role in RoleMapping) {
94+
userRegistrationForm.value = {
95+
...userData.value,
96+
role: RoleMapping[userData.value.role as keyof typeof RoleMapping]
97+
}
98+
}
99+
}
100+
})
101+
61102
const handleCancel = () => {
62103
userRegistrationForm.value = { ...INITIAL_USER_REGISTRATION }
63104
isModalVisible.value = false
64105
router.back()
65106
}
66107
67-
const handleSubmit = () => {
68-
console.log(userRegistrationForm.value)
108+
const handleSubmit = async () => {
109+
if (typeof userId.value === 'string') {
110+
const userData = {
111+
role: RoleTypeMapping[userRegistrationForm.value.role],
112+
email: null,
113+
name: userRegistrationForm.value.name,
114+
isReviewer: userRegistrationForm.value.isReviewer,
115+
departmentId: userRegistrationForm.value.departmentId,
116+
departmentRole: userRegistrationForm.value.departmentRole
117+
}
118+
console.log(userData, '수정할 데이터')
119+
console.log(userId.value, '수정할 아이디')
120+
await updateMemberAdmin(userId.value, userData)
121+
}
69122
isModalVisible.value = true
70123
}
71124
</script>

src/constants/admin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,10 @@ export const RoleTypeMapping: { [key in RoleTypes]: RoleTypesEnum } = {
6363
관리자: 'ROLE_ADMIN'
6464
}
6565

66+
export const RoleMapping: { [key in RoleTypesEnum]: RoleTypes } = {
67+
ROLE_USER: '사용자',
68+
ROLE_MANAGER: '담당자',
69+
ROLE_ADMIN: '관리자'
70+
}
71+
6672
export const RoleKeys: RoleTypes[] = Object.keys(RoleTypeMapping) as RoleTypes[]

src/types/admin.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export interface UserRegistrationProps {
4242
departmentRole: string
4343
}
4444

45+
export interface UserInfoForAdmin extends UserRegistrationProps {
46+
profileImageUrl: string
47+
departmentName: string
48+
}
49+
4550
export type RoleTypes = '관리자' | '사용자' | '담당자'
4651

4752
export type RoleTypesEnum = 'ROLE_ADMIN' | 'ROLE_USER' | 'ROLE_MANAGER'
@@ -110,3 +115,12 @@ export interface UserRegistrationApiProps {
110115
role: RoleTypesEnum
111116
departmentRole: string
112117
}
118+
119+
export interface UserUpdateValue {
120+
name: string
121+
email: null
122+
isReviewer: boolean
123+
departmentId: number
124+
role: RoleTypesEnum
125+
departmentRole: string
126+
}

0 commit comments

Comments
 (0)