From d0054d2826ed6e36a866e409f1aff78fbc0ee794 Mon Sep 17 00:00:00 2001 From: Dindb-dong Date: Thu, 24 Oct 2024 15:10:44 +0900 Subject: [PATCH] =?UTF-8?q?1.=20UserType=20=EC=88=98=EC=A0=95(=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EA=B0=80=EC=9E=85=EC=97=90=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=95=84=EB=93=9C)=202.=20userRole=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80:=20getUserRole()=EB=A1=9C=20=EB=A6=AC=ED=8F=BC?= =?UTF-8?q?=EB=9F=AC/=EC=97=85=EC=94=A8=EB=9F=AC=20=EA=B5=AC=EB=B6=84=20?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=203.=20=ED=86=A0=ED=81=B0=20=EB=B0=9C?= =?UTF-8?q?=EA=B8=89=20=EB=B0=8F=20=EC=9C=A0=EC=A0=80=EB=A1=A4=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=EC=9A=A9=20=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?4.=20=EC=9E=84=EC=8B=9C=EC=A0=80=EC=9E=A5=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20(=EA=B8=B0=EC=A1=B4=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=EB=93=B1=EB=A1=9D=20api=20=EC=88=98=EC=A0=95?= =?UTF-8?q?)=205.=20userContext=20=EC=A0=84=EC=97=AD=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=206.=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=EC=97=90=EC=84=9C=20useUser()=EB=A1=9C=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=EB=8D=B0=EC=9D=B4=ED=84=B0=20=ED=8C=A8=EC=B9=98?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?7.=20FixMyPage=EC=88=98=EC=A0=95:=20=ED=94=84=EB=A1=9C=ED=95=84?= =?UTF-8?q?=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?api=20=EC=97=B0=EA=B2=B0,=20=EC=9C=A0=EC=A0=80=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20api?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.tsx | 38 ++-- ios/Podfile.lock | 2 +- src/common/Context.tsx | 52 +++-- src/common/requests.js | 18 +- src/common/storage.js | 14 +- src/components/Auth/BasicForm.tsx | 4 +- src/components/Auth/Login.tsx | 65 ++++-- .../Auth/Reformer/ReformFormCareer.tsx | 1 - src/components/Home/Market/ReformerMarket.tsx | 8 +- .../Home/Market/ServiceRegistration.tsx | 66 +++++- src/hooks/useLoginGuard.ts | 2 +- src/pages/FixMyPage.tsx | 84 +++++-- src/pages/MyPage.tsx | 213 +++++++++--------- 13 files changed, 364 insertions(+), 203 deletions(-) diff --git a/App.tsx b/App.tsx index 37680e8..4e3d719 100644 --- a/App.tsx +++ b/App.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useContext, useState } from 'react'; import { View, TouchableOpacity, Text } from 'react-native'; import { NavigationContainer, @@ -20,7 +20,7 @@ import MyPageIcon from './src/assets/navbar/MyPage.svg'; import SignIn from './src/components/Auth/SignIn'; import { GestureHandlerRootView } from 'react-native-gesture-handler'; import { BottomBarProvider, useBottomBar } from './contexts/BottomBarContext'; -import { LoginProvider, UserProvider } from './src/common/Context'; +import { LoginContext, LoginProvider, UserProvider } from './src/common/Context'; import Reformer from './src/components/Auth/Reformer/Reformer'; import SplashScreen from './src/common/SplashScreen'; @@ -51,24 +51,24 @@ function App(): React.JSX.Element { return ( - {/* */} - - {!isSplashFinished ? ( - - ) : ( - ({ - headerShown: false, - })}> - - - - - )} - + + + {!isSplashFinished ? ( + + ) : ( + ({ + headerShown: false, + })}> + + + + + )} + + - {/* */} ); @@ -100,7 +100,7 @@ const CustomTab = ({ state, descriptors, navigation }: BottomTabBarProps) => { }}> {state.routes.map((route, index) => { const isFocused = state.index == index; - const onPress = () => { + const onPress = () => { // 하단 탭바 추가하면 여기 수정해야합니다!!!! if (route.name == '홈') { if (isFocused) navigation.reset({ diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 1c2e46a..cf01855 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1381,6 +1381,6 @@ SPEC CHECKSUMS: SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Yoga: e64aa65de36c0832d04e8c7bd614396c77a80047 -PODFILE CHECKSUM: 9d5dd46d976583e66c0ee47e0ae94858ed97b4e4 +PODFILE CHECKSUM: b8f4cca6d6e91fc876518892e2c92ed5612ccfb9 COCOAPODS: 1.15.2 diff --git a/src/common/Context.tsx b/src/common/Context.tsx index 72a6274..917a97b 100644 --- a/src/common/Context.tsx +++ b/src/common/Context.tsx @@ -1,41 +1,67 @@ import React, { ReactNode, createContext, useContext, useEffect, useState } from 'react'; -import { getAccessToken } from './storage'; +import { getAccessToken, setNickname, setUserRole } from './storage'; import Request from './requests'; import { Alert } from 'react-native'; type UserType = { - nickname?: string; - marketname?: string; - introduce?: string; - link?: string; email: string; - region: string; - is_reformer: boolean; - is_consumer: boolean; - + phone: string; + nickname: string; + agreement_terms: boolean; + adress: string; + profile_image_url: string; + introduce: string; + is_active: boolean; + role: string; }; export const UserContext = createContext<{ user: UserType | null; + role: string; setUser: (user: UserType) => void; + setRole: (role: string) => void; }>({ user: null, + role: '', setUser: () => { }, + setRole: () => { }, }); export const UserProvider = ({ children }: { children: ReactNode }) => { + function sanitizeUserData(data: any) { // null 오류 안 나도록 기본값 설정 + return { + email: data.email || "", + phone: data.phone || "", + nickname: data.nickname || "", + agreement_terms: data.agreement_terms !== undefined ? data.agreement_terms : false, + adress: data.address || "", + profile_image_url: data.profile_image_url || "https://image.made-in-china.com/2f0j00efRbSJMtHgqG/Denim-Bag-Youth-Fashion-Casual-Small-Mini-Square-Ladies-Shoulder-Bag-Women-Wash-Bags.webp", + introduce: data.introduce || "", + is_active: data.is_active !== undefined ? data.is_active : false, + role: data.role || "customer" + }; + } + const [user, setUser] = useState(null); + const [role, setRole] = useState(''); // 빈 문자열로 초기화 const [loading, setLoading] = useState(true); const [error, setError] = useState(''); const request = Request(); useEffect(() => { const fetchUserData = async () => { + const accessToken = await getAccessToken(); + const headers = { + Authorization: `Bearer ${accessToken}` + } try { - // Request의 get 메소드를 사용하여 유저 정보를 가져옴 - const response = await request.get('api/user', {}, {}); // API URL에 맞게 수정 + const response = await request.get(`/api/user`, {}, headers); if (response && response.status === 200) { - setUser(response.data); // 전역 상태에 유저 데이터를 저장 + console.log('유저 데이터를 저장합니다.'); + const sanitizedUserData = sanitizeUserData(response.data); + setUser(sanitizedUserData); // 전역 상태에 유저 데이터를 저장 + setUserRole(sanitizedUserData.role); + console.log('Saving credentials:', sanitizedUserData); } else { setError('유저 정보를 불러오는 중 문제가 발생했습니다.'); } @@ -51,7 +77,7 @@ export const UserProvider = ({ children }: { children: ReactNode }) => { fetchUserData(); // Provider가 마운트될 때 유저 데이터 가져옴 }, []); return ( - + {children} ); diff --git a/src/common/requests.js b/src/common/requests.js index 9f4102a..1166127 100644 --- a/src/common/requests.js +++ b/src/common/requests.js @@ -92,7 +92,7 @@ export default function Request() { ...headers, }, }); - console.log('request test => ', response); + // console.log('request test => ', response); return response; }); }; @@ -105,11 +105,11 @@ export default function Request() { ...headers, }, }); - console.log('headers', { - Authorization: headerValue, - ...headers, - }); - console.log('request test => ', response); + // console.log('headers', { + // Authorization: headerValue, + // ...headers, + // }); + // console.log('request test => ', response); return response; }); }; @@ -122,7 +122,7 @@ export default function Request() { ...headers, }, }); - console.log('request test => ', response); + // console.log('request test => ', response); return response; }); }; @@ -137,7 +137,7 @@ export default function Request() { ...headers, }, }); - console.log('request test => ', response); + // console.log('request test => ', response); return response; }); }; @@ -150,7 +150,7 @@ export default function Request() { ...headers, }, }); - console.log('request test => ', response); + // console.log('request test => ', response); return response; }); }; diff --git a/src/common/storage.js b/src/common/storage.js index 9410d71..74e2ad0 100644 --- a/src/common/storage.js +++ b/src/common/storage.js @@ -35,13 +35,16 @@ function removeSecureValue(key) { const nicknameKeyName = 'nickname'; const accessTokenKeyName = 'accessToken'; const refreshTokenKeyName = 'refreshToken'; +const userRole = 'customer'; +// reformer, admin export async function getNickname() { return await getSecureValue(nicknameKeyName); } export function setNickname(nickname) { - setSecureValue(nicknameKeyName, nickname); + const sanitizedNickname = nickname || ""; // 기본값 설정 + setSecureValue(nicknameKeyName, sanitizedNickname); } export function removeNickname() { @@ -76,6 +79,15 @@ export function removeRefreshToken() { removeSecureValue(refreshTokenKeyName); } +export async function getUserRole() { + const role = await getSecureValue(userRole); + return role; +} + +export function setUserRole(role) { + setSecureValue(userRole, role); +} + const marketUUIDKeyName = 'marketUUID'; // market_uuid 저장 함수 diff --git a/src/components/Auth/BasicForm.tsx b/src/components/Auth/BasicForm.tsx index 2003530..e3de548 100644 --- a/src/components/Auth/BasicForm.tsx +++ b/src/components/Auth/BasicForm.tsx @@ -122,13 +122,13 @@ export default function BasicForm({ navigation, route }: FormProps) { '^(?=.*[a-zA-Z])(?=.*[!@#$%^*+=-])(?=.*[0-9]).{8,15}$', ); - const handleLogin = async () => { + const handleLogin = async () => { // 로그인 API 사용해서 토큰 발급 const params = { email: form.mail + '@' + form.domain, password: form.password } const response = await request.post(`/api/user/login`, params); - processLoginResponse2( + await processLoginResponse2( // userRole 설정 함수 response ); }; diff --git a/src/components/Auth/Login.tsx b/src/components/Auth/Login.tsx index 37ba7f8..949414e 100644 --- a/src/components/Auth/Login.tsx +++ b/src/components/Auth/Login.tsx @@ -16,8 +16,9 @@ import { setAccessToken, setNickname, setRefreshToken, + setUserRole } from '../../common/storage'; -import { LoginContext } from '../../common/Context'; +import { LoginContext, useUser } from '../../common/Context'; interface LoginProps { navigation: any; @@ -30,6 +31,18 @@ interface LoginInputProps { onChangeText: (text: string) => void; } +type UserType = { + email: string; + phone: string; + nickname: string; + agreement_terms: boolean; + adress: string; + profile_image_url: string; + introduce: string; + is_active: boolean; + role: string; +}; + function LoginInput({ placeholder, secure = false, @@ -60,43 +73,57 @@ function LoginInput({ ); } -export const processLoginResponse2 = ( // 리폼러 회원가입 시에 사용하는 토큰 발급용 코드 - response: any, +export const processLoginResponse2 = async ( // 회원가입시에 사용하는 토큰 발급 및 role 설정용 코드 + response_: any, // 구분 ) => { // const navigation = useNavigation>(); - if (response?.status == 200) { - const accessToken = response.data.access; - const refreshToken = response.data.refresh; + const request = Request(); + if (response_?.status == 200) { + const accessToken = response_.data.access; + const refreshToken = response_.data.refresh; + const headers = { + Authorization: `Bearer ${accessToken}` + } setAccessToken(accessToken); setRefreshToken(refreshToken); console.log({ accessToken }, ',', { refreshToken }); - } else if (response.status == 400) { + try { // 유저 롤 설정 // 근데 이걸 꼭 여기서 할 필요가 있나? 혹시 모르니 만들어두긴 함 + const response = await request.get(`/api/user`, {}, headers) + if (response?.status === 200) { + const user_role = response.data.role; + setUserRole(user_role); + } + } catch (err) { + console.log(err); + } + } else if (response_.status == 400) { Alert.alert( - response.data.extra.fields !== undefined - ? response.data.extra.fields.detail - : response.data.message, + response_.data.extra.fields !== undefined + ? response_.data.extra.fields.detail + : response_.data.message, ); } else { Alert.alert('예상치 못한 오류가 발생하였습니다.'); } }; -export const processLoginResponse = ( +export async function processLoginResponse( // 통상 로그인시 호출 함수 response: any, navigate: () => void, setLogin: (value: boolean) => void, -) => { + setUser: (user: UserType) => void // setUser 전달 +) { // const navigation = useNavigation>(); if (response?.status == 200) { - const accessToken = response.data.access; - const refreshToken = response.data.refresh; - setNickname('임시 닉네임'); // 수정 필요: 유저 데이터 get해와서, 거기 있는 닉네임으로 변경. - // 없으면 (리폼러가 프로필 등록을 안했으면) -> ''으로 설정 -> 마이페이지 접근 불가하게. 마이페이지는 닉네임이 블랭크 아니어야만 접근 가능하게. isLogin이 true일때만 getUserData하게 하면 될듯. + const accessToken = await response.data.access; + const refreshToken = await response.data.refresh; setAccessToken(accessToken); setRefreshToken(refreshToken); console.log({ accessToken }, ',', { refreshToken }); setLogin(true); - navigate(); + navigate(); // 인자로 전달받은 네비게이팅 수행 + console.log('로그인 성공'); + } else if (response.status == 400) { Alert.alert( response.data.extra.fields !== undefined @@ -110,11 +137,12 @@ export const processLoginResponse = ( export default function Login({ navigation, route }: LoginProps) { const { isLogin, setLogin } = useContext(LoginContext); + const { user, setUser } = useUser(); // useUser 훅 사용 const { width, height } = Dimensions.get('window'); const [form, setForm] = useState({ email: '', password: '' }); const request = Request(); - const handleLogin = async () => { + const handleLogin = async () => { // 로그인 함수 const response = await request.post(`/api/user/login`, form); processLoginResponse( response, @@ -124,6 +152,7 @@ export default function Login({ navigation, route }: LoginProps) { else navigation.navigate('Home'); }, setLogin, + setUser // setUser 전달, ); }; diff --git a/src/components/Auth/Reformer/ReformFormCareer.tsx b/src/components/Auth/Reformer/ReformFormCareer.tsx index 054d20d..a17fd18 100644 --- a/src/components/Auth/Reformer/ReformFormCareer.tsx +++ b/src/components/Auth/Reformer/ReformFormCareer.tsx @@ -26,7 +26,6 @@ import { useNavigation } from '@react-navigation/native'; import { StackNavigationProp } from '@react-navigation/stack'; import { SignInParams } from '../SignIn'; import { getAccessToken, getMarketUUID, setMarketUUID } from '../../../common/storage'; -import { processLoginResponse2 } from '../Login'; const SelectView = styled.View` display: flex; diff --git a/src/components/Home/Market/ReformerMarket.tsx b/src/components/Home/Market/ReformerMarket.tsx index 951ff54..f9dde6d 100644 --- a/src/components/Home/Market/ReformerMarket.tsx +++ b/src/components/Home/Market/ReformerMarket.tsx @@ -147,14 +147,14 @@ const CategoryButton = styled.TouchableOpacity` border-width: 1px; border-color: #612fef; background-color: ${( - { props }: { props: any }, // TODO: 나중에 props의 type specify 필요 - ) => (props.pressed ? '#612FEF' : '#FFFFFF')}; + { props }: { props: any }, // TODO: 나중에 props의 type specify 필요 +) => (props.pressed ? '#612FEF' : '#FFFFFF')}; `; const CategoryButtonText = styled.Text` color: ${( - { props }: { props: any }, // TODO: 나중에 props의 type specify 필요 - ) => (props.pressed ? '#FFFFFF' : '#222222')}; + { props }: { props: any }, // TODO: 나중에 props의 type specify 필요 +) => (props.pressed ? '#FFFFFF' : '#222222')}; `; const CategoryBox = styled.View` diff --git a/src/components/Home/Market/ServiceRegistration.tsx b/src/components/Home/Market/ServiceRegistration.tsx index b37b31b..cd7fb5a 100644 --- a/src/components/Home/Market/ServiceRegistration.tsx +++ b/src/components/Home/Market/ServiceRegistration.tsx @@ -315,7 +315,7 @@ const ServiceRegistrationPage = ({ } }; - const handleSubmit = async () => { + const handleSubmit = async (temp: boolean) => { const accessToken = await getAccessToken(); const market_uuid = await getMarketUUID(); // let localPeriod = ''; // 얘는 나중에 개별 서비스 get해올 때 조건 걸어놓으면 될듯 @@ -344,11 +344,43 @@ const ServiceRegistrationPage = ({ service_style: formattedStyles, service_material: formattedMaterials, service_option: formattedOptions, + temporary: temp, }; const headers = { Authorization: `Bearer ${accessToken}` }; - if ( + if (temp) { // 임시저장 눌렀을 경우 + const params_ = { + service_title: name || '임시 저장 서비스', + service_content: inputText || '임시 설명', + service_category: form.category || '기타(외주)', + service_period: makingTime || 0, + basic_price: parseInt(price, 10) || 10000, + max_price: parseInt(maxPrice, 10) || 20000, + service_style: formattedStyles || [{ style_name: "빈티지" }], + service_material: formattedMaterials || [{ material_name: "면" }], + service_option: formattedOptions || [{ + option_content: '임시설명', + option_name: "임시옵션", + option_price: 1000, + }], + temporary: temp, + }; + try { + const response = await request.post(`/api/market/${market_uuid}/service`, params_, headers) + if (response?.status === 201) { + console.log(params_); + const service_uuid = await response?.data.service_uuid; + console.log("Service UUID:", service_uuid); + // navigation.navigate('ReformerProfilePage'); + console.log("임시등록 성공!"); + } + } catch (err) { + console.error(err); + } + navigation.navigate('TempStorage'); + } + else if ( // 일반 등록일 경우, 필수 필드 모두 채워야함 !(form.category == '') && !(name == '') && !(styles.length == 0) && @@ -370,7 +402,8 @@ const ServiceRegistrationPage = ({ } catch (err) { console.error(err); } - } else { + + } else { // 누락된거 있는 경우 Alert.alert('필수 사항들을 모두 입력해주세요'); } } @@ -577,12 +610,12 @@ const ServiceRegistrationPage = ({ handleNextPage()}> + onPress={() => handleSubmit(true)}> 임시저장 handleSubmit()}> + onPress={() => handleSubmit(false)}> 등록 @@ -590,12 +623,25 @@ const ServiceRegistrationPage = ({ ); + const handleGoBack = () => { + Alert.alert( + "정말로 나가시겠습니까?", + "", + [ + { text: "임시저장", onPress: () => handleSubmit(true) }, + { text: "아니오", onPress: () => { } }, + { text: "네", onPress: navigation.goBack, style: "destructive" } + ], + { cancelable: false } + ); + } + return ( { }} + onPressLeft={() => handleGoBack()} rightButton="None" onPressRight={() => { }} saved={0} @@ -1105,15 +1151,15 @@ const ServiceRegistrationPage = ({ 2. 서비스 완성본의 이미지를 업로드해요.{'\n'} - 제공하는 서비스의 완성본 예시나 작업 이미지를 서비스 설명과 함께 첨부하시면 업씨러의 선택에 - 도움이 됩니다 :D - + 제공하는 서비스의 완성본 예시나 작업 이미지를 서비스 설명과 함께 첨부하시면 업씨러의 선택에 + 도움이 됩니다 :D + { setIsOpen(!isOpen); }}> {'\n'}{'\n'}닫기 - + diff --git a/src/hooks/useLoginGuard.ts b/src/hooks/useLoginGuard.ts index e2c9a04..f4d6efd 100644 --- a/src/hooks/useLoginGuard.ts +++ b/src/hooks/useLoginGuard.ts @@ -5,7 +5,7 @@ import { useCallback, useContext } from 'react'; import { StackProps } from '../../App'; import { LoginContext } from '../common/Context'; -export default function useLoginGuard() { +export default function useLoginGuard() { // 로그인 상태면 콜백함수 호출, 아니면 회원가입 페이지로 const { isLogin } = useContext(LoginContext); const navigation = useNavigation>(); diff --git a/src/pages/FixMyPage.tsx b/src/pages/FixMyPage.tsx index 3f04c77..40127b1 100644 --- a/src/pages/FixMyPage.tsx +++ b/src/pages/FixMyPage.tsx @@ -31,7 +31,7 @@ type ProfileType = { }; function ProfilePic({ form, setForm }: ProfileProps) { - const [photo, setPhoto] = useState(form.profile_image); + const [photo, setPhoto] = useState(form.profile_image); // 프로필 사진은 form.profile_image.uri? const [handleAddButtonPress, handleImagePress] = useImagePicker(setPhoto); useEffect(() => { @@ -67,12 +67,12 @@ function ProfilePic({ form, setForm }: ProfileProps) { paddingVertical: 0, paddingHorizontal: 0, marginBottom: 0, + opacity: 10 }}> {photo !== undefined && ( {photo.fileName} )} @@ -99,10 +99,66 @@ function ProfilePic({ form, setForm }: ProfileProps) { const FixMyPage = ({ navigation, route }: FixMyPageProps) => { const { isLogin, setLogin } = useContext(LoginContext); const request = Request(); + const userInfo = route.params.userInfo; + const [form, setForm] = useState({ + profile_image: userInfo.profile_image, + nickname: userInfo.nickname, + introduce: userInfo.introduce, + }); + + const UpdateImage = async () => { + const accessToken = await getAccessToken(); + const headers = { + Authorization: `Bearer ${accessToken}`, + 'Content-Type': 'multipart/form-data', // multipart/form-data 설정 + }; + const formData = new FormData(); + formData.append('profile_image', { + uri: form.profile_image?.uri, // 파일의 URI + type: 'image/jpeg', // 이미지 형식 (예: 'image/jpeg') + name: form.profile_image?.fileName || 'profile.jpg', // 파일 이름 + }); + try { + const response = await request.post(`/api/user/profile-image`, formData, headers) + if (response && response.status === 201) { + console.log('프로필 이미지 수정 성공') + } else { + console.log('이미지 업로드 실패'); + console.log(response); + } + } + catch (err) { + console.error(err) + } + } + + const UpdateUser = async () => { // 유저 프로필 업데이트 + const accessToken = await getAccessToken(); + const headers = { + Authorization: `Bearer ${accessToken}` + } + const data = { + nickname: form.nickname, + introduce: form.introduce, + } + try { + const response = await request.put(`/api/user`, data, headers); + if (response && response.status === 200) { + await UpdateImage(); // 유저 프로필 이미지 업데이트 + console.log('유저 데이터 업데이트 성공', response.data); + navigation.navigate({ name: 'MyPage', params: { userInfo: userInfo }, merge: true }); + } + else { + console.log(response); + } + } catch (err) { + console.error(err); + } + } + const Logout = async () => { const accessToken = await getAccessToken(); const refreshToken = await getRefreshToken(); - setLogin(false); const params = { refresh: refreshToken } @@ -111,25 +167,23 @@ const FixMyPage = ({ navigation, route }: FixMyPageProps) => { } try { const response = await request.post(`/api/user/logout`, params, headers) - if (response && response.status === 205) { + if (response && response.status === 200) { console.log('로그아웃 합니다.') removeAccessToken(); removeRefreshToken(); + setLogin(false); console.log('AccessToken: ', { accessToken }, '| RefreshToken: ', { refreshToken }); - navigation.getParent()?.reset({ index: 0, // 스택 초기화 routes: [{ name: 'Home' }], }); } else { - console.error('Unexpected response status: ', response?.status); + console.log(response); } - } catch (err) { console.error(err) } - }; function handleLogout(): () => void { @@ -146,14 +200,6 @@ const FixMyPage = ({ navigation, route }: FixMyPageProps) => { } } - const userInfo = route.params.userInfo; - - const [form, setForm] = useState({ - profile_image: userInfo.profile_image, - nickname: userInfo.nickname, - introduce: userInfo.introduce, - }); - useEffect(() => { userInfo.nickname = form.nickname; userInfo.introduce = form.introduce; @@ -174,10 +220,6 @@ const FixMyPage = ({ navigation, route }: FixMyPageProps) => { }; }; - function handleSave(): () => void { - return () => { navigation.navigate({ name: 'MyPage', params: { userInfo: userInfo }, merge: true }); }; - } - const { width } = Dimensions.get('screen'); return ( @@ -220,7 +262,7 @@ const FixMyPage = ({ navigation, route }: FixMyPageProps) => { /> -