generated from pricelees/issue-pr-template
refactor: 예약 페이지에서의 프론트엔드 지역 선택 오류 해결 및 홈페이지 인기 테마 API 처리 로직 수정
This commit is contained in:
parent
48ef315f14
commit
475c1da119
@ -1,6 +1,12 @@
|
|||||||
import apiClient from "@_api/apiClient";
|
import apiClient from "@_api/apiClient";
|
||||||
import type { AdminScheduleSummaryListResponse, ScheduleCreateRequest, ScheduleCreateResponse, ScheduleStatus, ScheduleUpdateRequest, ScheduleWithThemeListResponse } from "./scheduleTypes";
|
|
||||||
import type {AuditInfo} from "@_api/common/commonTypes";
|
import type {AuditInfo} from "@_api/common/commonTypes";
|
||||||
|
import type {
|
||||||
|
AdminScheduleSummaryListResponse,
|
||||||
|
ScheduleCreateRequest,
|
||||||
|
ScheduleCreateResponse,
|
||||||
|
ScheduleUpdateRequest,
|
||||||
|
ScheduleWithThemeListResponse
|
||||||
|
} from "./scheduleTypes";
|
||||||
|
|
||||||
// admin
|
// admin
|
||||||
export const fetchAdminSchedules = async (storeId: string, date?: string, themeId?: string): Promise<AdminScheduleSummaryListResponse> => {
|
export const fetchAdminSchedules = async (storeId: string, date?: string, themeId?: string): Promise<AdminScheduleSummaryListResponse> => {
|
||||||
|
|||||||
@ -12,11 +12,11 @@ export const getStores = async (sidoCode?: string, sigunguCode?: string): Promis
|
|||||||
const queryParams: string[] = [];
|
const queryParams: string[] = [];
|
||||||
|
|
||||||
if (sidoCode && sidoCode.trim() !== '') {
|
if (sidoCode && sidoCode.trim() !== '') {
|
||||||
queryParams.push(`sidoCode=${sidoCode}`);
|
queryParams.push(`sido=${sidoCode}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sigunguCode && sigunguCode.trim() !== '') {
|
if (sigunguCode && sigunguCode.trim() !== '') {
|
||||||
queryParams.push(`sigunguCode=${sigunguCode}`);
|
queryParams.push(`sigungu=${sigunguCode}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseUrl = `/stores`;
|
const baseUrl = `/stores`;
|
||||||
|
|||||||
@ -42,3 +42,7 @@ export const fetchThemesByIds = async (request: ThemeIdListResponse): Promise<Th
|
|||||||
export const fetchThemeById = async (id: string): Promise<ThemeInfoResponse> => {
|
export const fetchThemeById = async (id: string): Promise<ThemeInfoResponse> => {
|
||||||
return await apiClient.get<ThemeInfoResponse>(`/themes/${id}`);
|
return await apiClient.get<ThemeInfoResponse>(`/themes/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const fetchMostReservedThemes = async (count: number): Promise<ThemeInfoListResponse> => {
|
||||||
|
return await apiClient.get<ThemeInfoListResponse>(`/themes/most-reserved?count=${count}`);
|
||||||
|
};
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import {fetchMostReservedThemeIds} from '@_api/reservation/reservationAPI';
|
|
||||||
import '@_css/home-page-v2.css';
|
import '@_css/home-page-v2.css';
|
||||||
import React, {useEffect, useState} from 'react';
|
import React, {useEffect, useState} from 'react';
|
||||||
import {useNavigate} from 'react-router-dom';
|
import {useNavigate} from 'react-router-dom';
|
||||||
import {fetchThemesByIds} from '@_api/theme/themeAPI';
|
import {fetchMostReservedThemes} from '@_api/theme/themeAPI';
|
||||||
import {DifficultyKoreanMap, mapThemeResponse, type ThemeInfoResponse} from '@_api/theme/themeTypes';
|
import {DifficultyKoreanMap, mapThemeResponse, type ThemeInfoResponse} from '@_api/theme/themeTypes';
|
||||||
|
|
||||||
const HomePage: React.FC = () => {
|
const HomePage: React.FC = () => {
|
||||||
@ -13,19 +12,8 @@ const HomePage: React.FC = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
const themeIds = await fetchMostReservedThemeIds().then(res => {
|
const themeFetchCount = 10;
|
||||||
const themeIds = res.themeIds;
|
const response = await fetchMostReservedThemes(themeFetchCount);
|
||||||
if (themeIds.length === 0) {
|
|
||||||
setRanking([]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return themeIds;
|
|
||||||
})
|
|
||||||
|
|
||||||
if (themeIds === undefined) return;
|
|
||||||
if (themeIds.length === 0) return;
|
|
||||||
|
|
||||||
const response = await fetchThemesByIds({ themeIds: themeIds });
|
|
||||||
setRanking(response.themes.map(mapThemeResponse));
|
setRanking(response.themes.map(mapThemeResponse));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error fetching ranking:', err);
|
console.error('Error fetching ranking:', err);
|
||||||
|
|||||||
@ -60,9 +60,13 @@ const ReservationStep1Page: React.FC = () => {
|
|||||||
}, [selectedSido]);
|
}, [selectedSido]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (selectedSido) {
|
||||||
getStores(selectedSido, selectedSigungu)
|
getStores(selectedSido, selectedSigungu)
|
||||||
.then(res => setStoreList(res.stores))
|
.then(res => setStoreList(res.stores))
|
||||||
.catch(handleError);
|
.catch(handleError);
|
||||||
|
} else {
|
||||||
|
setStoreList([]);
|
||||||
|
}
|
||||||
setSelectedStore(null);
|
setSelectedStore(null);
|
||||||
}, [selectedSido, selectedSigungu]);
|
}, [selectedSido, selectedSigungu]);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user