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

♻️ 통신을 URL 쿼리 파라미터 형식으로 변경 #43

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 19 additions & 5 deletions src/entities/program/ui/ProgramNavigation/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import React from 'react';
import { useNavigationStore } from '@/shared/stores/useNavigationStore';
'use client';

import { useSearchParams, useRouter } from 'next/navigation';
import React, { useEffect, useState } from 'react';

const ProgramNavigation: React.FC = () => {
const { navigation, setNavigation } = useNavigationStore();
const searchParams = useSearchParams();
const router = useRouter();
const [navigation, setNavigation] = useState<string>('standard');

useEffect(() => {
const currentNavigation = searchParams.get('navigation') || 'standard';
setNavigation(currentNavigation);
}, [searchParams]);

const handleNavigationChange = (newNavigation: string) => {
router.push(`${window.location.pathname}?navigation=${newNavigation}`);
setNavigation(newNavigation);
};

return (
<div className="flex justify-center gap-[18px]">
<button
className={`text-h2 ${
navigation === 'standard' ? 'text-black' : 'text-gray-500'
}`}
onClick={() => setNavigation('standard')}
onClick={() => handleNavigationChange('standard')}
>
일반 프로그램
</button>
<button
className={`text-h2 ${
navigation === 'training' ? 'text-black' : 'text-gray-500'
}`}
onClick={() => setNavigation('training')}
onClick={() => handleNavigationChange('training')}
>
연수 프로그램
</button>
Expand Down
7 changes: 5 additions & 2 deletions src/shared/model/footerActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ export const deleteActions = (fetchExpoList: () => Promise<void>) => ({
}
},
});
export const routeActions = (router: ReturnType<typeof useRouter>) => ({
export const routeActions = (
router: ReturnType<typeof useRouter>,
navigation: string,
) => ({
RouteActions: (id: number) => {
router.push(`/program/detail/${id}`);
router.push(`/program/detail/${id}?navigation=${navigation}`);
},
});
11 changes: 0 additions & 11 deletions src/shared/stores/useNavigationStore.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/widgets/expo-detail/ui/ExpoActionPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ const ExpoActionPanel = ({ params }: ExpoActionPanelProps) => {
</div>
<Button
onClick={() => {
router.push(`/program/${params}`);
router.push(`/program/${params}?navigation=standard`);
}}
text="프로그램"
style="main100"
/>

<Button
onClick={() => {
router.push(`/expo-manage/${params}`);
Expand Down
5 changes: 3 additions & 2 deletions src/widgets/program-detail/ui/ProgramDetailForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import axios from 'axios';
import { useSearchParams } from 'next/navigation';
import React, { useEffect, useState } from 'react';
import { useNavigationStore } from '@/shared/stores/useNavigationStore';
import { TableForm } from '@/shared/ui/Table';

interface TrainingProgram {
Expand All @@ -28,7 +28,8 @@ interface StandardProgram {
}

const ProgramDetailForm = ({ id }: { id: number }) => {
const { navigation } = useNavigationStore();
const searchParams = useSearchParams();
const navigation = searchParams.get('navigation') || 'standard'; // URL 쿼리 파라미터에서 navigation 값 가져오기
const [data, setData] = useState<TrainingProgram[] | StandardProgram[]>([]);

useEffect(() => {
Expand Down
18 changes: 9 additions & 9 deletions src/widgets/program/ui/ProgramForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use client';

import axios from 'axios';
import { useRouter } from 'next/navigation';
import React, { useEffect, useMemo, useState } from 'react';
import { useRouter, useSearchParams } from 'next/navigation';
import React, { useEffect, useState, useMemo } from 'react';
import { ProgramNavigation } from '@/entities/program';
import { routeActions } from '@/shared/model/footerActions';
import { useNavigationStore } from '@/shared/stores/useNavigationStore';
import { TableForm } from '@/shared/ui/Table';

interface Program {
Expand All @@ -17,15 +16,15 @@ interface Program {
}

const ProgramForm = ({ id }: { id: string }) => {
const searchParams = useSearchParams();
const navigation = searchParams.get('navigation') || 'standard';
const [expoData, setExpoData] = useState<Program[]>([]);
const { navigation } = useNavigationStore();
const router = useRouter();

const requestPrintCategories = useMemo(() => {
if (navigation === 'training') {
return ['번호', '프로그램', '시작시간', '종료시간', '상태'];
}
return ['번호', '프로그램', '시작시간', '종료시간'];
return navigation === 'training'
? ['번호', '프로그램', '시작시간', '종료시간', '상태']
: ['번호', '프로그램', '시작시간', '종료시간'];
}, [navigation]);

useEffect(() => {
Expand All @@ -42,6 +41,7 @@ const ProgramForm = ({ id }: { id: string }) => {
console.error('Error fetching expo data:', error);
}
};

fetchExpoData();
}, [id, navigation]);

Expand All @@ -54,7 +54,7 @@ const ProgramForm = ({ id }: { id: string }) => {
maxHeight="414px"
footerType="route"
text="프로그램 수"
actions={routeActions(router)}
actions={routeActions(router, navigation)}
/>
</div>
);
Expand Down