feat(web): add auth and home pages

This commit is contained in:
dahyeon committed 2026-04-11 02:31:00 +09:00
1 parent 9fbb11c634
commit 3a86676a12
3 files changed
+319

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router';
export default function AuthCallbackPage() {
const navigate = useNavigate();
useEffect(() => {
const timer = window.setTimeout(() => navigate('/', { replace: true }), 300);
return () => window.clearTimeout(timer);
}, [navigate]);
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-20 text-center">
<span className="text-sm text-base-content/45">로그인 처리 중...</span>
</main>
);
}
+255
View File
@@ -0,0 +1,255 @@
import { Link } from 'react-router';
import { mapApiMatchToMatchDetail } from '../api/mappers';
import { useMatches, useMe } from '../api/hooks';
import { DEFAULT_COMMUNITY_ID } from '../config';
function StatusBadge({ status }: { status: string }) {
const styles: Record<string, string> = {
모집중: 'bg-green-500/15 text-green-500 border-green-500/20',
팀빌딩: 'bg-amber-500/15 text-amber-500 border-amber-500/20',
진행중: 'bg-blue-500/15 text-blue-400 border-blue-500/20',
종료: 'bg-base-content/8 text-base-content/40 border-base-content/10',
};
return (
<span
className={`inline-flex items-center text-[11px] font-semibold px-1.5 py-0.5 border ${styles[status] ?? 'bg-base-content/10 text-base-content/50 border-base-content/10'}`}
>
{status}
</span>
);
}
function MapBadge({ map }: { map: string }) {
return (
<span className="inline-flex items-center text-[11px] px-1.5 py-0.5 border border-base-content/10 text-base-content/50">
{map}
</span>
);
}
function getStatusLabel(status: string) {
switch (status) {
case 'recruiting':
return '모집중';
case 'team-built':
return '팀빌딩';
case 'in-progress':
return '진행중';
case 'finished':
return '종료';
default:
return status;
}
}
export default function HomePage() {
const upcomingMatchesQuery = useMatches({ limit: 20 }, DEFAULT_COMMUNITY_ID);
const finishedMatchesQuery = useMatches(
{ status: 'finished', limit: 10 },
DEFAULT_COMMUNITY_ID,
);
const meQuery = useMe();
if (!DEFAULT_COMMUNITY_ID) {
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-16">
<div className="border border-amber-500/20 bg-amber-500/10 p-5 text-sm text-amber-700">
`apps/web/.env.development`의 `VITE_DEFAULT_COMMUNITY_ID`를 먼저 설정해주세요.
</div>
</main>
);
}
if (upcomingMatchesQuery.isLoading || finishedMatchesQuery.isLoading) {
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-20 text-center">
<span className="text-sm text-base-content/40">매치 목록을 불러오는 중...</span>
</main>
);
}
if (upcomingMatchesQuery.error || finishedMatchesQuery.error) {
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-20 text-center">
<span className="text-sm text-red-500">
매치 목록을 불러오지 못했습니다.
</span>
</main>
);
}
const upcomingMatches =
upcomingMatchesQuery.data?.map(mapApiMatchToMatchDetail) ?? [];
const finishedMatches =
finishedMatchesQuery.data?.map(mapApiMatchToMatchDetail) ?? [];
const nextMatch = upcomingMatches[0];
const upcomingCards = nextMatch ? upcomingMatches.slice(1) : upcomingMatches;
const currentUser =
meQuery.data?.memberships.find(
(membership) => membership.community?._id === DEFAULT_COMMUNITY_ID,
)?.user ?? null;
const canManage = currentUser?.role === 'owner' || currentUser?.role === 'admin';
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6">
<section className="pt-8 pb-6">
<div className="flex items-center justify-between gap-3 mb-3">
<h2 className="text-xs font-bold text-base-content/40 uppercase tracking-widest">
다음 내전
</h2>
<div className="flex items-center gap-3">
{canManage && (
<Link
to={`/admin/communities/${DEFAULT_COMMUNITY_ID}/matches`}
className="text-xs font-bold text-base-content/35 hover:text-primary"
>
내전 관리
</Link>
)}
<Link
to={`/communities/${DEFAULT_COMMUNITY_ID}/internal-stats`}
className="text-xs font-bold text-primary hover:underline"
>
내전 전적 보기
</Link>
</div>
</div>
{nextMatch ? (
<Link to={`/match/${nextMatch.id}`} className="block group">
<div className="border border-base-content/10 bg-base-200/50 hover:bg-base-200 transition-colors">
<div className="p-5 sm:p-6">
<div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4">
<div className="space-y-2.5">
<div className="flex items-center gap-2.5 flex-wrap">
<h3 className="text-xl sm:text-2xl font-bold text-base-content leading-tight">
{nextMatch.title}
</h3>
<StatusBadge status={getStatusLabel(nextMatch.status)} />
</div>
<p className="text-sm text-base-content/50 max-w-xl leading-relaxed">
{nextMatch.description}
</p>
<div className="flex items-center gap-3 text-xs text-base-content/40 flex-wrap">
<span>{nextMatch.date} {nextMatch.time}</span>
<span className="text-base-content/15">|</span>
<span>
{nextMatch.participants.length}/{nextMatch.maxParticipants}명
</span>
<span className="text-base-content/15">|</span>
<MapBadge map={nextMatch.map} />
</div>
</div>
<div className="sm:shrink-0">
<span className="btn btn-primary btn-sm px-6 text-xs font-semibold">
상세 보기
</span>
</div>
</div>
</div>
</div>
</Link>
) : (
<div className="border border-base-content/10 bg-base-100 px-5 py-10 text-center text-sm text-base-content/40">
아직 등록된 내전이 없습니다.
</div>
)}
</section>
<section className="pb-6">
<h2 className="text-xs font-bold text-base-content/40 uppercase tracking-widest mb-3">
예정된 내전
</h2>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-px bg-base-content/10 border border-base-content/10">
{upcomingCards.length > 0 ? (
upcomingCards.map((match) => (
<Link key={match.id} to={`/match/${match.id}`}>
<div className="bg-base-100 hover:bg-base-200/50 transition-colors cursor-pointer h-full p-4">
<div className="flex items-center justify-between mb-2.5">
<h3 className="text-sm font-bold text-base-content truncate mr-2">
{match.title}
</h3>
<StatusBadge status={getStatusLabel(match.status)} />
</div>
<div className="space-y-1 text-xs text-base-content/40">
<div>{match.date} {match.time}</div>
<div>
{match.participants.length}/{match.maxParticipants}명
</div>
</div>
<div className="mt-2.5">
<MapBadge map={match.map} />
</div>
</div>
</Link>
))
) : (
<div className="bg-base-100 px-4 py-6 text-sm text-base-content/35 col-span-full">
예정된 추가 매치가 없습니다.
</div>
)}
</div>
</section>
<section className="pb-12">
<h2 className="text-xs font-bold text-base-content/40 uppercase tracking-widest mb-3">
지난 내전 기록
</h2>
<div className="border border-base-content/10 overflow-x-auto">
<table className="w-full text-left">
<thead>
<tr className="bg-base-200/60 border-b border-base-content/10 text-[11px] uppercase tracking-wider text-base-content/40">
<th className="py-2.5 px-4 font-semibold">날짜</th>
<th className="py-2.5 px-4 font-semibold">내전</th>
<th className="py-2.5 px-4 font-semibold">맵</th>
<th className="py-2.5 px-4 font-semibold">참가</th>
<th className="py-2.5 px-4 font-semibold">결과</th>
</tr>
</thead>
<tbody>
{finishedMatches.length > 0 ? (
finishedMatches.map((match) => (
<tr
key={match.id}
className="border-b border-base-content/5 last:border-b-0 hover:bg-base-content/[0.02] transition-colors"
>
<td className="py-2.5 px-4 text-xs text-base-content/40 whitespace-nowrap">
{match.date}
</td>
<td className="py-2.5 px-4">
<Link
to={`/match/${match.id}`}
className="text-sm font-medium text-base-content hover:text-primary transition-colors"
>
{match.title}
</Link>
</td>
<td className="py-2.5 px-4">
<MapBadge map={match.map} />
</td>
<td className="py-2.5 px-4 text-xs text-base-content/50">
{match.participants.length}명
</td>
<td className="py-2.5 px-4 text-xs text-base-content/50">
{match.result?.winner ? `${match.result.winner} 승리` : '-'}
</td>
</tr>
))
) : (
<tr>
<td
colSpan={5}
className="py-6 px-4 text-sm text-base-content/35 text-center"
>
아직 종료된 내전 기록이 없습니다.
</td>
</tr>
)}
</tbody>
</table>
</div>
</section>
</main>
);
}
+47
View File
@@ -0,0 +1,47 @@
import { useMsal } from "@azure/msal-react";
import {
isMsalConfigured,
MSAL_API_SCOPE,
msalInstance,
} from "../lib/auth/msal.config";
function LoginButton() {
const { instance } = useMsal();
return (
<button
type="button"
className="btn btn-primary btn-sm px-5"
onClick={() =>
void instance.loginRedirect({
scopes: [MSAL_API_SCOPE],
prompt: "select_account",
})
}
>
Entra ID 로 로그인
</button>
);
}
export default function LoginPage() {
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-20">
<div className="max-w-md border border-base-content/10 bg-base-100 p-6 shadow-sm">
<h1 className="text-xl font-bold tracking-tight">로그인</h1>
<p className="mt-2 text-sm text-base-content/50">
Entra ID 계정으로 LOLYMPUS 정보를 불러옵니다.
</p>
<div className="mt-5">
{isMsalConfigured && msalInstance ? (
<LoginButton />
) : (
<div className="text-sm text-amber-600">
MSAL 환경변수 설정이 필요합니다.
</div>
)}
</div>
</div>
</main>
);
}