From f6a57a832b9251c37d1651cb219b7b74e688ec63 Mon Sep 17 00:00:00 2001 From: arch-spatula Date: Mon, 9 Jan 2023 11:09:34 +0900 Subject: [PATCH] =?UTF-8?q?remove:=20addPill=20=EC=82=AD=EC=A0=9C=20#1=20#?= =?UTF-8?q?2=20#3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit addPill이 custom hook으로 이동할 것이기 때문에 MyPage에서 삭제합니다. --- src/screen/MyPage.jsx | 103 ++++++++++-------------------------------- 1 file changed, 23 insertions(+), 80 deletions(-) diff --git a/src/screen/MyPage.jsx b/src/screen/MyPage.jsx index f2f5ec1..b2174eb 100644 --- a/src/screen/MyPage.jsx +++ b/src/screen/MyPage.jsx @@ -1,40 +1,32 @@ import styled from '@emotion/native'; import { Text, View } from 'react-native'; import { useQuery, useMutation, useQueryClient } from 'react-query'; -import { - getDocs, - onSnapshot, - addDoc, - query, - collection, - orderBy, - where, -} from 'firebase/firestore'; +import { getDocs, query, collection, orderBy, where } from 'firebase/firestore'; import { createUserWithEmailAndPassword, signInWithEmailAndPassword, } from 'firebase/auth'; import { dbService, authService } from '../shared/firebase'; import { getAuth } from 'firebase/auth'; -import { v4 as uuid } from 'uuid'; import { ManageList } from '../components'; const adminInfo = { id: 'catchPillAdmin@email.com', pw: '123456', }; - +// { navigation: { navigate } } const MyPage = () => { // 회원가입입니다. - const handlesSignUp = () => { - createUserWithEmailAndPassword(authService, adminInfo.id, adminInfo.pw) - .then((userData) => console.log(userData.user)) - .catch((error) => { - const errorMessage = error.message; - console.log('회원가입 실패', errorMessage); - }); + const handlesSignUp = (id, pw) => { + return createUserWithEmailAndPassword( + authService, + adminInfo.id, + adminInfo.pw, + ); }; + useMutation(() => handlesSignUp(id, pw)); + // 로그인입니다. const handleLogin = () => { signInWithEmailAndPassword(authService, adminInfo.id, adminInfo.pw) @@ -76,56 +68,7 @@ const MyPage = () => { } = useQuery('pill-list', () => getUsersPillList(uid), { enabled: !!uid, select: (data) => { - return data.docs.map((doc) => { - // console.log('doc', doc); - return { - id: doc.id, - userId: doc?.data()?.userId, - pillName: doc?.data()?.pillName, - time: doc?.data()?.time, - isTaken: doc?.data()?.isTaken, - }; - }); - }, - }); - - const queryClient = useQueryClient(); - - // 새로운 약 목록을 추가하는 Mutation 함수입니다. - const postNewPill = (newPill) => { - const selectedDoc = collection(dbService, 'pill'); - return addDoc(selectedDoc, newPill); - }; - - // console.log('getUid', uid); - - const newPill = { - // id: uuid(), - userId: uid, - pillName: '점심약', - time: '12:00', - isTaken: false, - }; - - const { mutate: addPill } = useMutation(() => postNewPill(newPill), { - onMutate: async () => { - // 재요청으로 인한 덮어쓰기를 막습니다. - await queryClient.cancelQueries('pill-list'); - const previousPillData = queryClient.getQueryData('pill-list'); - queryClient.setQueriesData('pill-list', (oldPillData) => { - return { ...oldPillData, docs: [...oldPillData?.docs, newPill] }; - }); - return { previousPillData }; - }, - onError: (_, __, context) => { - queryClient.setQueriesData('pill-list', context.previousPillData); - }, - onSuccess: (data) => { - console.log('data', data); - }, - onSettled: () => { - // 클라이언트 상태가 서버 상태랑 동일하게 싱크를 맞추어줍니다. - queryClient.invalidateQueries('pill-list'); + return data.docs.map((doc) => ({ ...doc.data(), id: doc.id })); }, }); @@ -134,17 +77,17 @@ const MyPage = () => { )); // 에러 핸들링: 통신 실패의 경우 보여주는 화면입니다. - // if (isError) { - // return ( - // - // 나의 약관리 - // - // 에러 - // {error.errorMessage} - // - // - // ); - // } + if (isError) { + return ( + + 나의 약관리 + + 에러 + {error.errorMessage} + + + ); + } // 통신 중 if (isLoading) { @@ -165,7 +108,7 @@ const MyPage = () => { handleLogin()}> 임시 로그인 - addPill(newPill)}> + console.log('약추가')}> 약추가 {renderPillList}