Skip to content

Commit 897e995

Browse files
authored
fix: 대학 검색 필터 분기 및 조건 전달 로직 수정 (#461)
* fix: 대학 검색 조건에 중국권 필터 옵션 추가 * fix: 대학 조건 검색에서 유효한 필터 쿼리만 전달 * fix: 대학 검색 결과의 필터 분기 조건 보정
1 parent 57b1a1a commit 897e995

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

apps/web/src/app/university/SearchResultsContent.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import CloudSpinnerPage from "@/components/ui/CloudSpinnerPage";
1212
import FloatingUpBtn from "@/components/ui/FloatingUpBtn";
1313
import UniversityCards from "@/components/university/UniversityCards";
14+
import { COUNTRY_CODE_MAP } from "@/constants/university";
1415
import { type CountryCode, type LanguageTestType, RegionEnumExtend } from "@/types/university";
1516
import RegionFilter from "./RegionFilter";
1617
import SearchBar from "./SearchBar";
@@ -32,9 +33,12 @@ const SearchResultsContent = () => {
3233
const countries = searchParams.getAll("countryCode");
3334

3435
// URL에서 전달된 국가 목록을 기본으로 사용
35-
const filteredCountries = countries as CountryCode[];
36+
const filteredCountries = countries.filter((country): country is CountryCode =>
37+
Object.hasOwn(COUNTRY_CODE_MAP, country),
38+
);
39+
const hasFilterParams = Boolean(lang) || filteredCountries.length > 0;
3640

37-
if (!lang || !countries) {
41+
if (!hasFilterParams) {
3842
return {
3943
isTextSearch: true,
4044
searchText: text,

apps/web/src/app/university/[homeUniversity]/search/_ui/SearchPageContent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ const SearchPageContent = ({ homeUniversitySlug }: SearchPageContentProps) => {
5454
// 필터 검색
5555
const onSubmit: SubmitHandler<SearchFormData> = (data) => {
5656
const queryParams = new URLSearchParams();
57+
const availableCountryCodeSet = new Set(availableCountries.map(([code]) => code as CountryCode));
5758

5859
if (data.languageTestType) {
5960
queryParams.append("languageTestType", data.languageTestType);
6061
}
6162

6263
[data.country1, data.country2, data.country3].forEach((code) => {
63-
if (code) {
64+
if (code && availableCountryCodeSet.has(code)) {
6465
queryParams.append("countryCode", code);
6566
}
6667
});

apps/web/src/app/university/list/[homeUniversityName]/SearchResultsContent.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import CloudSpinnerPage from "@/components/ui/CloudSpinnerPage";
1212
import FloatingUpBtn from "@/components/ui/FloatingUpBtn";
1313
import UniversityCards from "@/components/university/UniversityCards";
14+
import { COUNTRY_CODE_MAP } from "@/constants/university";
1415
import { type CountryCode, type HomeUniversityName, type LanguageTestType, RegionEnumExtend } from "@/types/university";
1516
import RegionFilter from "../../RegionFilter";
1617
import SearchBar from "../../SearchBar";
@@ -36,9 +37,12 @@ const SearchResultsContentInner = ({ homeUniversityName }: SearchResultsContentI
3637
const countries = searchParams.getAll("countryCode");
3738

3839
// URL에서 전달된 국가 목록을 기본으로 사용
39-
const filteredCountries = countries as CountryCode[];
40+
const filteredCountries = countries.filter((country): country is CountryCode =>
41+
Object.hasOwn(COUNTRY_CODE_MAP, country),
42+
);
43+
const hasFilterParams = Boolean(lang) || filteredCountries.length > 0;
4044

41-
if (!lang || !countries) {
45+
if (!hasFilterParams) {
4246
return {
4347
isTextSearch: true,
4448
searchText: text,

apps/web/src/app/university/search/PageContent.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const SchoolSearchForm = ({ homeUniversitySlug }: SchoolSearchFormProps) => {
4848

4949
const onSubmit: SubmitHandler<SearchFormData> = (data) => {
5050
const queryParams = new URLSearchParams();
51+
const availableCountryCodeSet = new Set(availableCountries.map(([code]) => code as CountryCode));
5152

5253
if (data.searchText) {
5354
queryParams.append("searchText", data.searchText);
@@ -57,11 +58,15 @@ const SchoolSearchForm = ({ homeUniversitySlug }: SchoolSearchFormProps) => {
5758
}
5859

5960
[data.country1, data.country2, data.country3].forEach((code) => {
60-
if (code) {
61+
if (code && availableCountryCodeSet.has(code)) {
6162
queryParams.append("countryCode", code);
6263
}
6364
});
6465

66+
if (data.regions && data.regions.length > 0) {
67+
data.regions.forEach((region) => queryParams.append("region", region));
68+
}
69+
6570
const queryString = queryParams.toString();
6671
router.push(`/university/${homeUniversitySlug}?${queryString}`);
6772
};

apps/web/src/constants/university.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
type TestScoreInfo,
88
} from "@/types/university";
99

10-
export const REGIONS_SEARCH = ["유럽권", "미주권", "아시아권"] as const;
10+
export const REGIONS_SEARCH = ["유럽권", "미주권", "아시아권", "중국권"] as const;
1111

1212
export const REGIONS_KO = ["유럽권", "미주권", "아시아권", "중국권"];
1313

0 commit comments

Comments
 (0)