Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

라우트 정리 #157 #181

Merged
merged 13 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(route): 참여 중인 챌린지 -> 챌린지 인증 라우팅
- 쿼리파라미터로 challengeId, title 보냄 (category도 필요하지만 없음ㅠ)
- activeTab 초기화
  • Loading branch information
joojjang committed Oct 1, 2024
commit 7e5e871ff181198636e99b5f04712f2567ea09d6
16 changes: 10 additions & 6 deletions src/pages/challenge-record/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react';
import { useSearchParams } from 'react-router-dom';

import Records from './records';
import Verification from './verification';
Expand All @@ -8,10 +9,13 @@ import { TabPanel, TabPanels } from '@/components/common/tabs/tab-panels';
import TopBar, { HEADER_HEIGHT } from '@/components/features/layout/top-bar';
import styled from '@emotion/styled';

const SAMPLE_CATEGORY = '에코';
const SAMPLE_TITLE = '환경 정화 활동';

const ChallengeRecord = () => {
// ?id=:id&category=:category&title=:title
const [searchParams] = useSearchParams();
const challengeId = searchParams.get('id') || '';
const challengeCategory = searchParams.get('category') || '';
const challengeTitle = searchParams.get('title') || '';

const [activeTab, setActiveTab] = useState<number>(() => {
// 세션 스토리지에 저장된 값 | 기본값 0
const savedTab = sessionStorage.getItem('activeTab');
Expand All @@ -20,11 +24,11 @@ const ChallengeRecord = () => {
const tabsList = [
{
label: '인증 기록',
panel: <Records />,
panel: <Records challengeId={Number(challengeId)} />,
},
{
label: '인증하기',
panel: <Verification />,
panel: <Verification challengeId={Number(challengeId)} />,
},
];

Expand All @@ -37,7 +41,7 @@ const ChallengeRecord = () => {
<>
<TopBar type='Page' title='챌린지 기록' backgroundColor='#fff' />
<Wrapper>
<ChallengeTitle category={SAMPLE_CATEGORY} title={SAMPLE_TITLE} />
<ChallengeTitle category={challengeCategory} title={challengeTitle} />
<Tabs selectedTab={activeTab} onChange={handleSelectedTab}>
{tabsList.map((t, index) => (
<Tab key={t.label} label={t.label} value={index} />
Expand Down
7 changes: 3 additions & 4 deletions src/pages/challenge-record/records/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import { useParams } from 'react-router-dom';

// import { useParams } from 'react-router-dom';
import Caution from '../components/caution';
import RecordItem from '../components/record-item';
import Stamp from '../components/stamp';
Expand All @@ -16,10 +16,9 @@ import { formatDate } from '@/utils/formatters';
import { Text } from '@chakra-ui/react';
import styled from '@emotion/styled';

const Records = () => {
const { id } = useParams();
const challengeId = Number(id);
type RecordsProps = { challengeId: number };

const Records = ({ challengeId }: RecordsProps) => {
const [data, setData] = useState<ChallengeRecordData | null>(); // api 응답 데이터 전체
const [recordIdList, setRecordIdList] = useState<number[]>([]);
const [recordDetails, setRecordDetails] =
Expand Down
7 changes: 3 additions & 4 deletions src/pages/challenge-record/verification/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from 'react';
import { MdDeleteForever } from 'react-icons/md';
import { useParams } from 'react-router-dom';

// import { useParams } from 'react-router-dom';
import Caution from '../components/caution';
import { postVerification } from '@/apis/challenge-record/challenge.record.api';
import CTA, { CTAContainer } from '@/components/common/cta';
Expand All @@ -11,10 +11,9 @@ import styled from '@emotion/styled';

const MIN_CONTENT_LENGTH = 20;

const Verification = () => {
const { id } = useParams();
const challengeId = Number(id);
type VerificationProps = { challengeId: number };

const Verification = ({ challengeId }: VerificationProps) => {
const fileInput = useRef<HTMLInputElement | null>(null);
const [content, setContent] = useState('');
const [isContentValid, setIsContentValid] = useState(true);
Expand Down
6 changes: 4 additions & 2 deletions src/pages/my-challenge/components/challenge-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type ChallengeListProps = {
color: string;
BorderColor: string;
challenges: {
id: number;
challengeId: number;
title: string;
}[];
};
Expand Down Expand Up @@ -83,7 +83,9 @@ const ChallengeList = ({
cursor='pointer'
onClick={() => handleSaveTitle(challenge.title)}
>
<Link to={RouterPath.write}>
<Link
to={`/${RouterPath.challenge}/${RouterPath.record}?id=${challenge.challengeId}&title=${challenge.title}`}
>
<Text
fontSize='var(--font-size-sm)'
fontStyle='normal'
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const router = createBrowserRouter([
),
},
{
path: `:id/${RouterPath.record}`,
path: `${RouterPath.record}`,
element: (
<ProtectedRoute>
<ChallengeRecord />
Expand Down