From d00867361431afe726c3546714f67c7023166268 Mon Sep 17 00:00:00 2001 From: hwna00 Date: Mon, 18 Sep 2023 15:48:19 +0900 Subject: [PATCH] =?UTF-8?q?FIX(user):=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=A4=91=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20API?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=9B=EC=95=84=EC=98=A8=20=EC=A3=BC=EC=86=8C=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20redux=EC=97=90=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존: useState로 관리 - 변경: redux-toolkit으로 관리 - 변경이유: 페이지 전환 시 주소 정보가 초기화되는 문제를 해결하기 위해 변경 ref: #62 --- .../user/src/components/SignUpForm/SignUpForm.js | 10 +++++----- packages/apps/user/src/store.js | 7 +++++-- packages/apps/user/src/views/Auth/SignUp/Step2.js | 12 +++++------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/apps/user/src/components/SignUpForm/SignUpForm.js b/packages/apps/user/src/components/SignUpForm/SignUpForm.js index 027381c5..82a3f499 100644 --- a/packages/apps/user/src/components/SignUpForm/SignUpForm.js +++ b/packages/apps/user/src/components/SignUpForm/SignUpForm.js @@ -41,12 +41,12 @@ const SignUpForm = function ({ }, [dispatch, reactHookForm.formState]); const handleNext = useCallback(async () => { - // const isFullfilled = await reactHookForm.trigger(); + const isFullfilled = await reactHookForm.trigger(); - // if (isFullfilled) { - navigate(`/auth/sign-up/step${activeStep + 2}`); - goToNext(); - // } + if (isFullfilled) { + navigate(`/auth/sign-up/step${activeStep + 2}`); + goToNext(); + } }, [activeStep, goToNext, navigate, reactHookForm]); const handlePrev = useCallback(() => { diff --git a/packages/apps/user/src/store.js b/packages/apps/user/src/store.js index 4b52a58f..68aa788e 100644 --- a/packages/apps/user/src/store.js +++ b/packages/apps/user/src/store.js @@ -2,11 +2,14 @@ import { configureStore, createSlice } from '@reduxjs/toolkit'; const signUpSlice = createSlice({ name: 'signUp', - initialState: { errors: {}, blob: '' }, + initialState: { errors: {}, blob: '', address: '' }, reducers: { setImgBlob: (state, action) => { state.blob = action.payload; }, + setAddress: (state, action) => { + state.address = action.payload; + }, setErrors: (state, action) => { state.errors = { ...action.payload }; }, @@ -39,5 +42,5 @@ export const store = configureStore({ devTools: process.env.NODE_ENV !== 'production', }); -export const { setImgBlob, setErrors } = signUpSlice.actions; +export const { setImgBlob, setErrors, setAddress } = signUpSlice.actions; export const { setAppointDatetime } = appointmentSlice.actions; diff --git a/packages/apps/user/src/views/Auth/SignUp/Step2.js b/packages/apps/user/src/views/Auth/SignUp/Step2.js index fd2453bf..0d4d3079 100644 --- a/packages/apps/user/src/views/Auth/SignUp/Step2.js +++ b/packages/apps/user/src/views/Auth/SignUp/Step2.js @@ -1,9 +1,7 @@ import { - Button, FormControl, FormErrorMessage, FormLabel, - HStack, Input, InputGroup, InputLeftAddon, @@ -13,14 +11,14 @@ import { VStack, useDisclosure, } from '@chakra-ui/react'; -import { useState } from 'react'; import { DaumPostcodeEmbed } from 'react-daum-postcode'; -import { FaSearch } from 'react-icons/fa'; -import { useSelector } from 'react-redux'; +import { useDispatch, useSelector } from 'react-redux'; import { useOutletContext } from 'react-router-dom'; +import { setAddress } from '../../../store'; const Step2 = function () { - const [address, setAddress] = useState(); + const dispatch = useDispatch(); + const address = useSelector(state => state.signUp.address); const { register } = useOutletContext(); const { isOpen, onOpen, onClose } = useDisclosure(); @@ -28,7 +26,7 @@ const Step2 = function () { const handleComplete = data => { onClose(); - setAddress(data.address); + dispatch(setAddress(data.address)); }; return (