Skip to content
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
314 changes: 314 additions & 0 deletions frontend/src/app/(main)/admin/concerts/create-view.tsx

Large diffs are not rendered by default.

134 changes: 62 additions & 72 deletions frontend/src/app/(main)/admin/concerts/detail/view.tsx

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions frontend/src/app/(main)/admin/concerts/new/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client";

import { useState } from "react";
import AdminGate from "../../admin-gate";
import { CreateConcert } from "../create-view";
import { OrganizerConcertEditor } from "../detail/view";

export default function NewConcertPage() {
const [concertId, setConcertId] = useState<number | null>(null);
return (
<AdminGate lead={<>공연 정보와 좌석 배치를 설정하고, 같은 화면에서 가격과 회차를 이어서 관리해요.</>}>
{concertId === null ? (
<>
<CreateConcert onCreated={setConcertId}>
<section className="fq-concert-manage-section">
<span className="fq-eyebrow">구역별 가격</span>
<p className="fq-hint">공연 정보를 저장하면 선택한 좌석 배치의 구역별 가격을 설정할 수 있어요.</p>
</section>
<section className="fq-concert-manage-section">
<span className="fq-eyebrow">공연 회차</span>
<p className="fq-hint">공연 정보를 저장하면 이 화면에서 회차와 예매 일정을 등록할 수 있어요.</p>
</section>
</CreateConcert>
</>
) : (
<OrganizerConcertEditor id={concertId} />
)}
</AdminGate>
);
}
151 changes: 11 additions & 140 deletions frontend/src/app/(main)/admin/concerts/page.tsx
Original file line number Diff line number Diff line change
@@ -1,160 +1,33 @@
"use client";

import LineArt from "@/components/LineArt";
import Link from "next/link";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { OrganizerConcertEditor } from "./detail/view";
import LoadError from "@/components/LoadError";
import { useToast } from "@/components/Toast";
import { ApiError, api } from "@/lib/api";
import { api } from "@/lib/api";
import { dateOnly, dateTime } from "@/lib/format";
import { useLoad } from "@/lib/hooks";
import type { OrganizerConcert, OrganizerConcertPage, OrganizerVenue } from "@/lib/types";
import AdminGate from "../admin-gate";
import { firstFieldError, iso, toLocal } from "../form-utils";
import { SlotPicker } from "../slot-picker";
import { concertStage } from "./status";

export default function AdminConcertsPage() {
return (
<AdminGate lead={<>공연을 초안으로 만들고 예매 오픈, 가격, 회차를 정한 뒤 공개해요. 주최자는 본인 공연만, 관리자는 모든 공연을 봐요.</>}>
<CreateConcert />
<MyConcerts />
<AdminGate lead={<>공연을 만들고 예매 오픈, 가격, 회차를 정한 뒤 공개해요. 주최자는 본인 공연만, 관리자는 모든 공연을 봐요.</>}>
<ConcertWorkspace />
</AdminGate>
);
}

const day = (offset: number) => new Date(Date.now() + offset * 86400_000).toLocaleDateString("sv-SE");
/** 내일 20시 */
const tomorrowEvening = () => {
const d = new Date(Date.now() + 86400_000);
d.setHours(20, 0, 0, 0);
return toLocal(d.getTime());
};

function CreateConcert() {
const toast = useToast();
function ConcertWorkspace() {
const [selectedId, setSelectedId] = useState<number | null>(null);
const router = useRouter();
const [f, setF] = useState({ venueId: 0, layoutId: 0, title: "", description: "", periodStartDate: day(14), periodEndDate: day(15), durationMinutes: 120, bookingOpensAt: tomorrowEvening() });
const [error, setError] = useState<string | null>(null);
const [saving, setSaving] = useState(false);
const venues = useLoad(() => api<OrganizerVenue[]>("/api/organizer/venues"));
const venue = venues.data?.find((v) => v.venueId === f.venueId);

// 목록이 오면 첫 공연장과 첫 배치를 미리 골라 둔다
useEffect(() => {
const first = venues.data?.[0];
if (first && f.venueId === 0) setF((p) => ({ ...p, venueId: first.venueId, layoutId: first.layouts[0]?.layoutId ?? 0 }));
}, [venues.data, f.venueId]);

const submit = async (e: React.FormEvent) => {
e.preventDefault();
if (!f.title.trim()) return setError("공연 제목을 입력해 주세요.");
if (!f.venueId || !f.layoutId) return setError("공연장과 좌석 배치를 골라 주세요.");
if ((f.periodStartDate === "") !== (f.periodEndDate === "")) return setError("공연 기간은 시작일과 종료일을 함께 정해 주세요.");
if (f.periodStartDate && f.periodStartDate > f.periodEndDate) return setError("공연 종료일은 시작일과 같거나 뒤여야 해요.");
setError(null);
setSaving(true);
try {
const r = await api<OrganizerConcert>("/api/organizer/concerts", {
method: "POST",
body: {
venueId: f.venueId,
layoutId: f.layoutId,
title: f.title.trim(),
description: f.description || null,
periodStartDate: f.periodStartDate || null,
periodEndDate: f.periodEndDate || null,
durationMinutes: f.durationMinutes || null,
bookingOpensAt: f.bookingOpensAt ? iso(f.bookingOpensAt) : null,
},
});
toast(`공연 #${r.concertId} 초안을 만들었어요`, "ok");
router.push(`/admin/concerts/detail?id=${r.concertId}`);
} catch (err) {
const ex = err as ApiError;
setError(firstFieldError(ex.details) ?? ex.message);
} finally {
setSaving(false);
}
};

return (
<form className="fq-card is-pad fq-form fq-admin" onSubmit={submit} noValidate>
<span className="fq-eyebrow">공연 초안 만들기</span>
<div className="fq-field">
<label htmlFor="c-title">공연 제목</label>
<input id="c-title" className="fq-input" maxLength={200} value={f.title} onChange={(e) => setF({ ...f, title: e.target.value })} placeholder="NOVA 월드투어 서울" />
</div>
<div className="fq-field">
<label htmlFor="c-desc">소개</label>
<textarea id="c-desc" className="fq-input" maxLength={5000} value={f.description} onChange={(e) => setF({ ...f, description: e.target.value })} />
</div>
<div className="fq-form-2">
<div className="fq-field">
<label htmlFor="c-venue">공연장</label>
<p className="fq-hint">{venue ? venue.address : "공연장을 골라 주세요"}</p>
{venues.error ? (
<p className="fq-err">공연장 목록을 불러오지 못했어요. {venues.error.message}</p>
) : !venues.data ? (
<div className="fq-skel" style={{ height: 44 }} />
) : venues.data.length === 0 ? (
<p className="fq-muted">등록된 공연장이 없어요.</p>
) : (
<select id="c-venue" className="fq-input" value={f.venueId} onChange={(e) => { const v = venues.data?.find((x) => x.venueId === Number(e.target.value)); setF({ ...f, venueId: Number(e.target.value), layoutId: v?.layouts[0]?.layoutId ?? 0 }); }}>
{venues.data.map((v) => (
<option key={v.venueId} value={v.venueId}>
{v.name}
</option>
))}
</select>
)}
</div>
<div className="fq-field">
<label htmlFor="c-layout">좌석 배치</label>
<p className="fq-hint">만든 뒤 상세 화면에서 바꿀 수 있어요</p>
<select id="c-layout" className="fq-input" value={f.layoutId} disabled={!venue || venue.layouts.length === 0} onChange={(e) => setF({ ...f, layoutId: Number(e.target.value) })}>
{venue?.layouts.length === 0 ? <option value={0}>등록된 배치가 없어요</option> : null}
{venue?.layouts.map((l) => (
<option key={l.layoutId} value={l.layoutId}>
{l.name}, {l.sellableSeats}석
</option>
))}
</select>
</div>
</div>
<div className="fq-form-2" style={{ gridTemplateColumns: "repeat(auto-fit, minmax(160px, 1fr))" }}>
<div className="fq-field">
<label htmlFor="c-start">공연 시작일</label>
<input id="c-start" className="fq-input" type="date" value={f.periodStartDate} onChange={(e) => setF({ ...f, periodStartDate: e.target.value })} />
</div>
<div className="fq-field">
<label htmlFor="c-end">공연 종료일</label>
<input id="c-end" className="fq-input" type="date" value={f.periodEndDate} onChange={(e) => setF({ ...f, periodEndDate: e.target.value })} />
</div>
<div className="fq-field">
<label htmlFor="c-dur">공연 시간 (분)</label>
<input id="c-dur" className="fq-input" type="number" min={1} value={f.durationMinutes} onChange={(e) => setF({ ...f, durationMinutes: Number(e.target.value) })} />
</div>
</div>
<div className="fq-field">
<label htmlFor="c-opens">예매 오픈</label>
<p className="fq-hint">모든 회차의 예매가 이 시각에 열려요. 비워 두면 상세 화면에서 정해요</p>
<SlotPicker id="c-opens" label="예매 오픈" value={f.bookingOpensAt} onChange={(v) => setF({ ...f, bookingOpensAt: v })} />
</div>
{error ? (
<p className="fq-err" role="alert">
{error}
</p>
) : null}
<button className="fq-btn is-grad" disabled={saving}>
{saving ? "만드는 중…" : "초안 만들기"}
</button>
</form>
);
if (selectedId) return <OrganizerConcertEditor id={selectedId} onDeleted={() => setSelectedId(null)} />;
return <><div className="fq-row"><button type="button" className="fq-btn is-grad" onClick={() => router.push("/admin/concerts/new")}>공연 만들기</button></div><MyConcerts onSelect={setSelectedId} /></>;
}

function MyConcerts() {
function MyConcerts({ onSelect }: { onSelect: (id: number) => void }) {
const { data, error } = useLoad(() => api<OrganizerConcertPage>("/api/organizer/concerts?size=100"));
return (
<section className="fq-section fq-admin-list" style={{ marginTop: 22 }}>
Expand Down Expand Up @@ -184,9 +57,7 @@ function MyConcerts() {
</small>
</div>
<div className="fq-order-r">
<Link className="fq-btn is-ghost is-sm" href={`/admin/concerts/detail?id=${c.concertId}`}>
관리
</Link>
<button type="button" className="fq-btn is-ghost is-sm" onClick={() => onSelect(c.concertId)}>관리</button>
</div>
</li>
);
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/app/(main)/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@
.fq-admin-list {
max-width: 860px;
}
.fq-concert-create {
max-width: 1120px;
width: min(100%, 1120px);
}
@media (max-width: 640px) {
.fq-concert-create { width: 100%; }
}
.fq-variant-row {
display: grid;
grid-template-columns: 0.7fr 1.3fr 1fr 0.8fr auto;
Expand All @@ -631,3 +638,8 @@
grid-template-columns: 1fr 1fr;
}
}
.fq-concert-manage { max-width: 1240px; width: min(100%, 1240px); gap: 0; }
.fq-concert-manage-sections { display: grid; gap: 0; }
.fq-concert-manage-section { padding: 24px 0; border-top: 1px solid var(--ux-line-2); }
@media (max-width: 640px) { .fq-concert-manage { width: 100%; } }
.fq-concert-manage .fq-form-2 > .fq-field > :is(.fq-input, .fq-slot) { margin-top: 0; }
25 changes: 25 additions & 0 deletions frontend/src/app/(main)/performances/pending-reservation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export type PendingReservation = { key: string; seatIds: number[] };

function storageKey(memberId: number, performanceId: number) {
return `fanq.ticketReservation.${memberId}.${performanceId}`;
}

export function loadPendingReservation(memberId: number, performanceId: number): PendingReservation | null {
try {
const value = JSON.parse(sessionStorage.getItem(storageKey(memberId, performanceId)) ?? 'null');
if (!value || typeof value.key !== 'string' || !value.key.trim() || value.key.length > 100
|| !Array.isArray(value.seatIds) || value.seatIds.length === 0
|| value.seatIds.some((id: unknown) => !Number.isSafeInteger(id) || Number(id) <= 0)
|| new Set(value.seatIds).size !== value.seatIds.length) return null;
return { key: value.key, seatIds: value.seatIds };
} catch { return null; }
}

export function savePendingReservation(memberId: number, performanceId: number, request: PendingReservation): boolean {
try { sessionStorage.setItem(storageKey(memberId, performanceId), JSON.stringify(request)); return true; }
catch { return false; }
}

export function clearPendingReservation(memberId: number, performanceId: number) {
try { sessionStorage.removeItem(storageKey(memberId, performanceId)); } catch { /* 저장소를 사용할 수 없음 */ }
}
Loading
Loading