Skip to content

Commit

Permalink
FIX(user): 회원가입 중 카카오 API로 받아온 주소 정보를 redux에 저장
Browse files Browse the repository at this point in the history
- 기존: useState로 관리
- 변경: redux-toolkit으로 관리
- 변경이유: 페이지 전환 시 주소 정보가 초기화되는 문제를 해결하기 위해 변경

ref: #62
  • Loading branch information
hwna00 committed Sep 18, 2023
1 parent d860179 commit d008673
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions packages/apps/user/src/components/SignUpForm/SignUpForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
7 changes: 5 additions & 2 deletions packages/apps/user/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
},
Expand Down Expand Up @@ -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;
12 changes: 5 additions & 7 deletions packages/apps/user/src/views/Auth/SignUp/Step2.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {
Button,
FormControl,
FormErrorMessage,
FormLabel,
HStack,
Input,
InputGroup,
InputLeftAddon,
Expand All @@ -13,22 +11,22 @@ 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();
const errors = useSelector(state => state.signUp.errors);

const handleComplete = data => {
onClose();
setAddress(data.address);
dispatch(setAddress(data.address));
};

return (
Expand Down

0 comments on commit d008673

Please sign in to comment.