|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import Image from "next/image"; |
| 4 | +import Link from "next/link"; |
| 5 | +import { useEffect, useState } from "react"; |
| 6 | + |
| 7 | +import { getUniversityListPublicApi } from "@/services/university"; |
| 8 | +import { shortenLanguageTestName } from "@/utils/universityUtils"; |
| 9 | + |
| 10 | +import ButtonTab from "@/components/ui/ButtonTab"; |
| 11 | +import CheveronRightFilled from "@/components/ui/icon/ChevronRightFilled"; |
| 12 | + |
| 13 | +import { languageTestShortMapping } from "@/types/score"; |
| 14 | +import { ListUniversity, regionMapping } from "@/types/university"; |
| 15 | + |
| 16 | +const UniversityList = () => { |
| 17 | + const [region, setRegion] = useState<"전체" | "영미권" | "유럽권" | "아시아권">("전체"); |
| 18 | + const [universities, setUniversities] = useState<ListUniversity[]>([]); |
| 19 | + |
| 20 | + useEffect(() => { |
| 21 | + const fetchUniversities = async () => { |
| 22 | + try { |
| 23 | + const response = await getUniversityListPublicApi(regionMapping[region]); |
| 24 | + setUniversities(response.data.slice(0, 3)); |
| 25 | + } catch { |
| 26 | + setUniversities([]); |
| 27 | + } |
| 28 | + }; |
| 29 | + |
| 30 | + fetchUniversities(); |
| 31 | + }, [region]); |
| 32 | + |
| 33 | + return ( |
| 34 | + <div className="flex flex-col gap-2"> |
| 35 | + <div className="flex justify-between"> |
| 36 | + <span className="text-lg font-semibold leading-snug text-[#44413D]">전체 학교 리스트</span> |
| 37 | + <Link href="/university"> |
| 38 | + <span className="text-[13px] font-semibold leading-snug text-[#76797D] underline decoration-solid decoration-auto underline-offset-auto"> |
| 39 | + 더보기 |
| 40 | + </span> |
| 41 | + </Link> |
| 42 | + </div> |
| 43 | + <div className=""> |
| 44 | + <ButtonTab // TODO: 디자인 변경 |
| 45 | + choices={["전체", "영미권", "유럽권", "아시아권", "중국권"]} |
| 46 | + choice={region} |
| 47 | + setChoice={setRegion} |
| 48 | + color={{ |
| 49 | + activeBtn: "bg-primary-100", |
| 50 | + deactiveBtn: "bg-k-50", |
| 51 | + activeBtnFont: "text-primary", |
| 52 | + deactiveBtnFont: "text-k-300", |
| 53 | + background: "white", |
| 54 | + }} |
| 55 | + /> |
| 56 | + </div> |
| 57 | + <UniversityCards colleges={universities} /> |
| 58 | + </div> |
| 59 | + ); |
| 60 | +}; |
| 61 | + |
| 62 | +export default UniversityList; |
| 63 | + |
| 64 | +type UniversityCardsProps = { |
| 65 | + colleges: ListUniversity[]; |
| 66 | + style?: React.CSSProperties; |
| 67 | +}; |
| 68 | + |
| 69 | +const UniversityCards = ({ colleges, style }: UniversityCardsProps) => ( |
| 70 | + <div className="flex flex-col gap-2" style={style}> |
| 71 | + {colleges.map((university) => ( |
| 72 | + <UniversityCard key={university.id} university={university} /> |
| 73 | + ))} |
| 74 | + </div> |
| 75 | +); |
| 76 | + |
| 77 | +type UniversityCardProps = { |
| 78 | + university: ListUniversity; |
| 79 | +}; |
| 80 | + |
| 81 | +const UniversityCard = ({ university }: UniversityCardProps) => { |
| 82 | + const convertedKoreanName = |
| 83 | + university.term !== process.env.NEXT_PUBLIC_CURRENT_TERM |
| 84 | + ? `${university.koreanName}(${university.term})` |
| 85 | + : university.koreanName; |
| 86 | + return ( |
| 87 | + <Link |
| 88 | + className="relative flex h-[91px] gap-5 overflow-hidden rounded-lg bg-k-50 p-5 no-underline" |
| 89 | + href={`/university/${university.id}`} |
| 90 | + > |
| 91 | + <div className="flex items-center"> |
| 92 | + <Image |
| 93 | + className="h-[55px] w-[55px] rounded-full object-cover" |
| 94 | + src={`${process.env.NEXT_PUBLIC_IMAGE_URL}/${university.logoImageUrl}`} |
| 95 | + width={55} |
| 96 | + height={55} |
| 97 | + alt={convertedKoreanName || "대학 이미지"} |
| 98 | + /> |
| 99 | + </div> |
| 100 | + |
| 101 | + <div className="flex flex-1 flex-col gap-1"> |
| 102 | + <div className="flex justify-between"> |
| 103 | + <span className="truncate font-serif text-base font-semibold leading-normal text-black"> |
| 104 | + {convertedKoreanName} |
| 105 | + </span> |
| 106 | + <div className="flex shrink-0 gap-2.5"> |
| 107 | + <span className="text-sm font-semibold leading-normal text-primary"> |
| 108 | + {university.country} | {university.region} |
| 109 | + </span> |
| 110 | + <svg xmlns="http://www.w3.org/2000/svg" width="21" height="20" viewBox="0 0 21 20" fill="none"> |
| 111 | + <path |
| 112 | + d="M9.51953 14L13.5195 10L9.51953 6" |
| 113 | + stroke="#5F6268" |
| 114 | + stroke-linecap="round" |
| 115 | + stroke-linejoin="round" |
| 116 | + /> |
| 117 | + </svg> |
| 118 | + </div> |
| 119 | + </div> |
| 120 | + <div className="flex gap-2.5"> |
| 121 | + {university.languageRequirements.slice(0, 3).map((requirement) => ( |
| 122 | + <span |
| 123 | + key={requirement.languageTestType} |
| 124 | + className="whitespace-nowrap text-sm font-medium leading-normal text-[#919397]" |
| 125 | + > |
| 126 | + {languageTestShortMapping[requirement.languageTestType] || ""} {requirement.minScore || ""} |
| 127 | + </span> |
| 128 | + ))} |
| 129 | + </div> |
| 130 | + </div> |
| 131 | + |
| 132 | + <div className="absolute right-[9.77px] top-[38px] h-6 w-6"></div> |
| 133 | + </Link> |
| 134 | + ); |
| 135 | +}; |
0 commit comments