diff --git a/src/api/common.ts b/src/api/common.ts index 73c05ae7..c318e696 100644 --- a/src/api/common.ts +++ b/src/api/common.ts @@ -1,4 +1,9 @@ -import { axiosInstance } from '../utils/axios' +import { axiosInstance, formDataAxiosInstance } from '../utils/axios' + +export const patchEditInfo = async (formdata: FormData) => { + const response = await formDataAxiosInstance.patch('/api/members/info', formdata) + return response.data +} export const getNotification = async (pageNum: number, sizeNum: number) => { const response = await axiosInstance.get(`/api/notifications?page=${pageNum}&size=${sizeNum}`) @@ -8,13 +13,11 @@ export const getNotification = async (pageNum: number, sizeNum: number) => { export const patchNotificationRead = async (notificationId: number) => { const response = await axiosInstance.patch(`/api/notification/${notificationId}`) - console.log(notificationId) return response.data } export const getNotifiCount = async () => { const response = await axiosInstance.get(`/api/notifications/count`) - console.log(response.data) return response.data } diff --git a/src/api/user.ts b/src/api/user.ts index 72940f3b..2f981710 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,13 +1,7 @@ import type { Status } from '@/types/common' -import type { userInfo } from '@/types/user' import type { RequestApprovePostTypes } from '@/types/manager' import { axiosInstance, formDataAxiosInstance } from '@/utils/axios' -export const patchEditInfo = async (formdata: userInfo, image: File) => { - const response = await formDataAxiosInstance.post('/api/tasks', formdata, image) - return response.data -} - export const postTaskRequest = async (formdata: FormData) => { const response = await formDataAxiosInstance.post('/api/tasks', formdata) return response.data diff --git a/src/components/EditInformation.vue b/src/components/EditInformation.vue index 17e774de..c913ef9a 100644 --- a/src/components/EditInformation.vue +++ b/src/components/EditInformation.vue @@ -10,8 +10,8 @@

프로필 사진

프로필 이미지 @@ -33,7 +33,7 @@ + v-model="info.name" />

아이디

@@ -55,17 +55,17 @@

알림 수신 여부

+ :isChecked="info.notificationSettingInfo.agit" /> + :isChecked="info.notificationSettingInfo.kakaoWork" /> + :isChecked="info.notificationSettingInfo.email" />
@@ -94,8 +94,7 @@ import FormCheckbox from './common/FormCheckbox.vue' const router = useRouter() import { useMemberStore } from '@/stores/member' import { storeToRefs } from 'pinia' -import { patchEditInfo } from '@/api/user' -import +import { patchEditInfo } from '@/api/common' const memberStore = useMemberStore() const { info } = storeToRefs(memberStore) @@ -105,20 +104,6 @@ const previewUrl = ref(null) const isModalVisible = ref(false) -const memberForm = ref({ - isAgitChecked: false, - isKakaoWorkChecked: false, - isEmailChecked: false -}) - -const formData = new FormData() - -const requestData: any = { - name: info.value.memberName, - agitNotification: memberForm.value.isAgitChecked, - emailNotification: memberForm.value.isEmailChecked, - kakaoWorkNotification: memberForm.value.isKakaoWorkChecked -} const handleCancel = () => { router.back() } @@ -136,9 +121,30 @@ const handleFileUpload = (event: Event) => { } } -const handleSubmit = () => { - isModalVisible.value = true - console.log(requestData) - patchEditInfo(requestData, selectedFile.value) +const handleSubmit = async () => { + const formData = new FormData() + const memberInfo = { + name: info.value.name, + agitNotification: info.value.notificationSettingInfo.agit, + emailNotification: info.value.notificationSettingInfo.email, + kakaoWorkNotification: info.value.notificationSettingInfo.kakaoWork + } + + const jsonMemberInfo = JSON.stringify(memberInfo) + const newBlob = new Blob([jsonMemberInfo], { type: 'application/json' }) + + formData.append('memberInfo', newBlob) + + if (selectedFile.value) { + formData.append('profileImage', selectedFile.value) + } + + try { + await patchEditInfo(formData) + isModalVisible.value = true + await memberStore.updateMemberInfoWithToken() + } catch (error) { + console.error('요청 실패:', error) + } } diff --git a/src/components/top-bar/NotificationModal.vue b/src/components/top-bar/NotificationModal.vue index 9027748c..02e83f48 100644 --- a/src/components/top-bar/NotificationModal.vue +++ b/src/components/top-bar/NotificationModal.vue @@ -85,7 +85,6 @@ const hasNext = ref(true) const loadMoreNotifications = async ($state: any) => { try { const response = await getNotification(page.value, pageSize) - console.log(response) if (response.isFirst) { notifications.value = response.content diff --git a/src/components/top-bar/SideBar.vue b/src/components/top-bar/SideBar.vue index 7ba44dde..69b1e411 100644 --- a/src/components/top-bar/SideBar.vue +++ b/src/components/top-bar/SideBar.vue @@ -40,9 +40,9 @@
프로필 이미지
info.value.memberRole) -const name = computed(() => info.value.memberName) +const role = computed(() => info.value.role) +const name = computed(() => info.value.name) const nickname = computed(() => info.value.nickname) const filteredMenu = computed(() => { diff --git a/src/components/top-bar/TopBar.vue b/src/components/top-bar/TopBar.vue index f761b739..4576347f 100644 --- a/src/components/top-bar/TopBar.vue +++ b/src/components/top-bar/TopBar.vue @@ -29,9 +29,9 @@ type="button" @click="toggleProfile"> 프로필 이미지
{ } const originUrl = route.path.split('/')[1] - if (info.value.memberRole === 'ROLE_USER') { + if (info.value.role === 'ROLE_USER') { if (!PERMITTED_URL.ROLE_USER.includes(originUrl)) router.push('/my-request') - } else if (info.value.memberRole === 'ROLE_MANAGER') { + } else if (info.value.role === 'ROLE_MANAGER') { if (!PERMITTED_URL.ROLE_MANAGER.includes(originUrl)) router.push('/my-task') - } else if (info.value.memberRole === 'ROLE_ADMIN') { + } else if (info.value.role === 'ROLE_ADMIN') { if (!PERMITTED_URL.ROLE_ADMIN.includes(originUrl)) router.push('/member-management') } else { if (!PERMITTED_URL.UNKNOWN.includes(originUrl)) { @@ -121,7 +121,7 @@ watch(isLogined, newValue => { watch( () => info.value, async newInfo => { - if (newInfo.memberName && isLogined) { + if (newInfo.name && isLogined) { await fetchNotificationCount() } }, diff --git a/src/stores/member.ts b/src/stores/member.ts index f4e45b13..3c164ea2 100644 --- a/src/stores/member.ts +++ b/src/stores/member.ts @@ -6,14 +6,19 @@ import Cookies from 'js-cookie' export const useMemberStore = defineStore('memberInfo', () => { const info = ref({ - memberName: '', + name: '', nickname: '', - imageUrl: '', - memberRole: '', + profileImageUrl: '', + role: '', memberStatus: '', email: '', departmentName: '', - departmentRole: '' + departmentRole: '', + notificationSettingInfo: { + agit: false, + email: false, + kakaoWork: false + } }) const refreshToken = ref(Cookies.get('refreshToken') || '') @@ -21,36 +26,29 @@ export const useMemberStore = defineStore('memberInfo', () => { async function updateMemberInfoWithToken() { const response = await axiosInstance.get('/api/members/info') - console.log('API Response:', response.data) updateMemberInfo(response.data) isLogined.value = true } - function updateMemberInfo(responseData: any) { + function updateMemberInfo(responseData: User) { info.value = { - memberName: responseData.name || '', - nickname: responseData.nicknanme || '', + name: responseData.name || '', + nickname: responseData.nickname || '', email: responseData.email || '', - imageUrl: responseData.profileImageUrl || '', - memberRole: responseData.role || '', + profileImageUrl: responseData.profileImageUrl || '', + role: responseData.role || '', memberStatus: responseData.memberStatus || '', departmentName: responseData.departmentName || '', - departmentRole: responseData.departmentRole || '' + departmentRole: responseData.departmentRole || '', + notificationSettingInfo: { + agit: responseData.notificationSettingInfo.agit, + email: responseData.notificationSettingInfo.email, + kakaoWork: responseData.notificationSettingInfo.kakaoWork + } } - console.log('Updated member info:', info.value) } function logout() { - info.value = { - memberName: '', - nickname: '', - imageUrl: '', - memberRole: '', - memberStatus: '', - email: '', - departmentName: '', - departmentRole: '' - } isLogined.value = false Cookies.remove('accessToken') Cookies.remove('refreshToken') diff --git a/src/types/auth.ts b/src/types/auth.ts index 3e91977d..43a1407d 100644 --- a/src/types/auth.ts +++ b/src/types/auth.ts @@ -1,12 +1,17 @@ export interface User { - memberName: string + name: string nickname: string email: string - imageUrl: string - memberRole: string + profileImageUrl: string + role: string memberStatus: string departmentName: string departmentRole: string + notificationSettingInfo: { + agit: boolean + email: boolean + kakaoWork: boolean + } } export interface loginDataTypes { diff --git a/src/types/user.ts b/src/types/user.ts index 9572ef1b..2a131fbe 100644 --- a/src/types/user.ts +++ b/src/types/user.ts @@ -1,13 +1,6 @@ import type { LabelDataTypes, Status } from './common' import type { ManagerTypes } from './manager' -export interface userInfo { - name: string - agitNotification: boolean - emailNotification: boolean - kakaoWorkNotification: boolean -} - export interface MyRequestListData { taskId: number taskCode: string diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index 0654f0b8..a5617ef9 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -62,7 +62,7 @@ const handleLogin = async () => { const sessionId = '000' const res = await postLogin(loginData, sessionId) if (res) { - switch (res.memberInfo.memberRole) { + switch (res.memberInfo.role) { case 'ROLE_ADMIN': router.push('/member-management') break