Skip to content

Commit

Permalink
fix: 온보딩 완료 후 SeniorId 받아와서 프로필 등록시 온보딩 정보 불러오기
Browse files Browse the repository at this point in the history
  • Loading branch information
se0jinYoon committed Nov 18, 2024
1 parent 3b52a73 commit d6666d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/pages/onboarding/hooks/useJoinQuery.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useMutation } from '@tanstack/react-query';
import { joinAxios } from '../apis/joinAxios';
import { JoinPropType } from '../type';
import { setRole } from '@utils/storage';
import { setRole, setSeniorId } from '@utils/storage';

const useJoinQuery = () => {
const mutation = useMutation({
mutationFn: (requestBody: JoinPropType) => joinAxios(requestBody),
onSuccess: (data) => {
setRole(data.data.data.role);
setSeniorId(data.data.data.seniorId + '');
},
onError: (error) => {
console.log('🔴 join patch Error: ', error);
Expand Down
9 changes: 5 additions & 4 deletions src/pages/seniorProfile/SeniorProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ import { Header } from '../../components/commons/Header';
import ProgressBar from '../../components/commons/ProgressBar';
import theme from '../../styles/theme';
import { useNavigate } from 'react-router-dom';
import { getSeniorNickname } from '@utils/storage';
import { getSeniorId, getSeniorNickname } from '@utils/storage';

const SeniorProfilePage = () => {
const [step, setStep] = useState(0);
const [profile, setProfile] = useState<seniorProfileRegisterType>(seniorProfileInitial);

const navigate = useNavigate();
const nickname = getSeniorNickname();
const seniorId = getSeniorId() ?? '';
const userName = step >= 2 && step <= 4 ? nickname : '';

useEffect(() => {
if (!nickname) navigate('/');
}, [nickname]);
if (seniorId === '' || !nickname) navigate('/');
}, [nickname, seniorId]);

const getComponent = () => {
switch (step) {
Expand All @@ -44,7 +45,7 @@ const SeniorProfilePage = () => {
case 5:
return <TimeSelect profile={profile} setProfile={setProfile} setStep={setStep} />;
case 6:
return <PreView setStep={setStep} profile={profile} seniorId="" />;
return <PreView setStep={setStep} profile={profile} seniorId={seniorId} />;
case 7:
return <Complete />;
default:
Expand Down
6 changes: 1 addition & 5 deletions src/pages/seniorProfile/components/preView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ interface preViewPropType {

const PreView = ({ seniorId, profile, setStep, variant = 'default' }: preViewPropType) => {
// 선배 카드 정보 조회 (온보딩 정보)
const {
data: cardData,
error: cardDataError,
isLoading: isCardDataLoading,
} = useSeniorCardQuery(seniorId, variant === 'secondary');
const { data: cardData, error: cardDataError, isLoading: isCardDataLoading } = useSeniorCardQuery(seniorId, true);
// 선배 상세 프로필 조회 (프로필 정보)
const {
data: profileData,
Expand Down
9 changes: 9 additions & 0 deletions src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const clearStorage = () => {
localStorage.removeItem('seonyakToken');
localStorage.removeItem('seonyakRole');
localStorage.removeItem('seniorNickname');
localStorage.removeItem('seniorId');
};

// 온보딩 완료 후 프로필 등록 안 하고 이탈한 선배 정보 저장
Expand All @@ -28,3 +29,11 @@ export const setSeniorNickname = (nickname: string) => {
export const getSeniorNickname = () => {
return localStorage.getItem('seniorNickname');
};

export const setSeniorId = (id: string) => {
localStorage.setItem('seniorId', id);
}

export const getSeniorId = () => {
return localStorage.getItem('seniorId');
}

0 comments on commit d6666d7

Please sign in to comment.