[feat] solution: 미니 블로그·이용후기·예약요청 추가, /s/stay 목업·발행 사이트 UI 다수 수정
인앱 미니 블로그(AI 자동 포스트, 이메일 승인)·이용후기(즉시 게시)·예약 요청(메일 발송)을
새로 붙였고, 병행해서 /s/stay 목업과 발행 사이트 공통 렌더러(UnitsSection·FestivalSection·
LocalGuideSection·WeatherSection 등)의 UI 버그를 다수 고쳤다. 범위가 넓지만 한 주 분량
작업을 한 커밋으로 묶어 달라는 요청에 따라 하나로 묶는다.
- solution/backend: post/review/booking_request 라우터·서비스·CRUD 추가, 스케줄러에
블로그 초안 생성(새벽 4:10)·발송(아침 9:00) cron 등록, 마이그레이션 4건 추가
- solution/frontend, admin/frontend: 생성된 API 클라이언트 갱신, 리뷰 모더레이션·
블로그 글 관리 페이지 추가
- solution/site/src: 객실 상세+실시간예약(날짜선택·연락처 폼)을 모달로 통합, 축제·
주변안내 카드 클릭 시 모달 전환, 후기 목록 카드 UI, 공용 Modal 컴포넌트 신설,
날씨 문구 동기화 버그 수정(하늘줄·기온줄 한 타이머로), 시설·편의 가능/불가 아이콘
색상 하이라이트, 헤더 메뉴 순서를 실제 섹션 순서에 맞춤, 하단 탭바 아이콘 정렬 버그
(line-height) 수정, 추천일정 점선 연결+데스크톱 자동펼침/모바일 축소, 채널 라벨에
크롤링 원문("NOL")이 새던 것을 bookingLabel() 로 교체
- solution/site/scripts/mockup: /s/stay 패치 스크립트·주입 CSS·JS 다수 수정, stay4~6
빌드 스크립트 추가(다른 세션 작업)
테스트: solution/site `npx tsc --noEmit` 통과, `npx vitest run` 93 passed,
solution/backend `pytest tests/test_booking_request.py` 6 passed(로컬 DB 대상).
예약 요청 메일은 실제 발송까지 확인(place 66894a1b 소유자 이메일 누락을 DB에서 보정).
This commit is contained in:
1 parent
29af37f158
commit
872d00f3c4
338 files changed
+74988
-9283
No files matched your search
@@ -0,0 +1,723 @@
|
||||
import {useEffect, useMemo, useState} from 'react';
|
||||
import {useNavigate, useSearchParams} from 'react-router';
|
||||
import {Loader2, Pencil, Plus, Save, Send, Sparkles, X} from 'lucide-react';
|
||||
import {
|
||||
useApproveMyPost,
|
||||
useEditMyPost,
|
||||
useGenerateMyPostForDate,
|
||||
useGenerateMyPosts,
|
||||
useGetGenerationHistory,
|
||||
useGetMyPost,
|
||||
useListMyPosts,
|
||||
useListUpcomingPosts,
|
||||
type PostData,
|
||||
} from '@/api';
|
||||
import {AppShell, EmptyState, PageContainer} from '@/components/layout/AppShell';
|
||||
import {Badge} from '@/components/ui/badge';
|
||||
import {Button} from '@/components/ui/button';
|
||||
import {Dialog} from '@/components/ui/dialog';
|
||||
import {notify, notifyApiError} from '@/lib/notify';
|
||||
import {cn} from '@/lib/utils';
|
||||
|
||||
type BadgeVariant = 'default' | 'outline' | 'warning' | 'success';
|
||||
|
||||
// common/enums.py PostStatus 와 값이 같아야 한다. DB 는 숫자만 준다 — 라벨은 화면 몫이다.
|
||||
// 카드(카로셀 · 달력 모달) 안에서만 쓴다 — 달력 칸 자체는 발행완료/발행실패만 보여준다.
|
||||
const STATUS_LABEL: Record<number, {label: string; variant: BadgeVariant}> = {
|
||||
1: {label: '생성됨', variant: 'default'},
|
||||
2: {label: '발송 대기', variant: 'default'},
|
||||
3: {label: '메일 보냄 · 승인 대기', variant: 'warning'},
|
||||
4: {label: '승인됨 · 반영 중', variant: 'success'},
|
||||
5: {label: '게재됨', variant: 'success'},
|
||||
6: {label: '건너뜀', variant: 'outline'},
|
||||
};
|
||||
|
||||
// common/enums.py PostTopicKind.
|
||||
const TOPIC_LABEL: Record<number, string> = {
|
||||
1: '날씨',
|
||||
2: '축제',
|
||||
3: '계절',
|
||||
4: '주변',
|
||||
5: '이용 안내',
|
||||
};
|
||||
|
||||
// crud/post_crud.py PostCRUD._EDITABLE 과 같아야 한다 — 승인·게재·건너뜀은 되돌릴 수 없다.
|
||||
const EDITABLE_STATUSES = new Set([2, 3]);
|
||||
const SENT_STATUS = 3;
|
||||
const PUBLISHED_STATUS = 5;
|
||||
|
||||
const WEEKDAYS = ['일', '월', '화', '수', '목', '금', '토'];
|
||||
const UPCOMING_DAYS = 7;
|
||||
|
||||
function currentMonth(): string {
|
||||
const now = new Date();
|
||||
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function monthLabel(month: string): string {
|
||||
const [year, mon] = month.split('-').map(Number);
|
||||
return `${year}년 ${mon}월`;
|
||||
}
|
||||
|
||||
function shiftMonth(month: string, delta: number): string {
|
||||
const [year, mon] = month.split('-').map(Number);
|
||||
const date = new Date(year, mon - 1 + delta, 1);
|
||||
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
type YMD = {year: number; month: number; day: number};
|
||||
|
||||
/** scheduled_date("YYYY-MM-DD")를 파싱한다 — 타임존 없는 순수 날짜라 문자열만 자르면 된다. */
|
||||
function parseScheduled(scheduledDate: string): YMD {
|
||||
const [year, month, day] = scheduledDate.split('-').map(Number);
|
||||
return {year, month, day};
|
||||
}
|
||||
|
||||
function dayOf(scheduledDate: string): number {
|
||||
return parseScheduled(scheduledDate).day;
|
||||
}
|
||||
|
||||
function todayKst(): YMD {
|
||||
const kst = new Date(Date.now() + 9 * 60 * 60 * 1000);
|
||||
return {year: kst.getUTCFullYear(), month: kst.getUTCMonth() + 1, day: kst.getUTCDate()};
|
||||
}
|
||||
|
||||
function addDays(base: YMD, days: number): YMD {
|
||||
const d = new Date(Date.UTC(base.year, base.month - 1, base.day + days));
|
||||
return {year: d.getUTCFullYear(), month: d.getUTCMonth() + 1, day: d.getUTCDate()};
|
||||
}
|
||||
|
||||
function sameDate(a: YMD, b: YMD): boolean {
|
||||
return a.year === b.year && a.month === b.month && a.day === b.day;
|
||||
}
|
||||
|
||||
function isBeforeToday(year: number, month: number, day: number, today: YMD): boolean {
|
||||
if (year !== today.year) return year < today.year;
|
||||
if (month !== today.month) return month < today.month;
|
||||
return day < today.day;
|
||||
}
|
||||
|
||||
function isoDate(year: number, month: number, day: number): string {
|
||||
return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function todayIso(): string {
|
||||
const t = todayKst();
|
||||
return isoDate(t.year, t.month, t.day);
|
||||
}
|
||||
|
||||
function addDaysIso(iso: string, days: number): string {
|
||||
const [y, m, d] = iso.split('-').map(Number);
|
||||
const next = new Date(Date.UTC(y, m - 1, d + days));
|
||||
return isoDate(next.getUTCFullYear(), next.getUTCMonth() + 1, next.getUTCDate());
|
||||
}
|
||||
|
||||
function lastDayOfMonthIso(month: string): string {
|
||||
const [year, mon] = month.split('-').map(Number);
|
||||
const lastDay = new Date(Date.UTC(year, mon, 0)).getUTCDate();
|
||||
return isoDate(year, mon, lastDay);
|
||||
}
|
||||
|
||||
/** 카드에 다는 날짜 표시 — 날짜는 전부 쓰고, 오늘·내일만 chip 을 더 단다(사장님 지시). */
|
||||
function dateLabel(scheduledDate: string): {text: string; chip: '오늘' | '내일' | null} {
|
||||
const d = parseScheduled(scheduledDate);
|
||||
const today = todayKst();
|
||||
const text = `${d.month}월 ${d.day}일`;
|
||||
if (sameDate(d, today)) return {text, chip: '오늘'};
|
||||
if (sameDate(d, addDays(today, 1))) return {text, chip: '내일'};
|
||||
return {text, chip: null};
|
||||
}
|
||||
|
||||
/**
|
||||
* 달력 칸에 다는 배지. 검수 대기(REVIEWED)처럼 아직 메일도 안 나간 상태는 아무것도
|
||||
* 보여주지 않는다(사장님 지시: "발행전인건 표시하지 말고") — 메일 발송 여부는 그 자체가
|
||||
* 크론잡이 실제로 돌았다는 확인이라 별도로 보여준다(사장님 지시: "완료되었는지 여부도
|
||||
* 출력해야할꺼같아").
|
||||
*/
|
||||
function publishBadge(post: PostData): {label: string; className: string} | null {
|
||||
if (post.status === PUBLISHED_STATUS) return {label: '발행완료', className: 'bg-success/15 text-success'};
|
||||
if (post.build_failed) return {label: '발행실패', className: 'bg-destructive/10 text-destructive'};
|
||||
if (post.status === SENT_STATUS) return {label: '발송완료', className: 'bg-primary/10 text-primary'};
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 수정 폼 — 저장하면 그대로 승인된다(메일의 "수정해서 올리기"와 같은 규칙). */
|
||||
function PostEditor({placeId, post, onDone}: {placeId: string; post: PostData; onDone: () => void}) {
|
||||
const [body, setBody] = useState(post.body);
|
||||
const editMutation = useEditMyPost();
|
||||
|
||||
const handleSave = async () => {
|
||||
try {
|
||||
const res = await editMutation.mutateAsync({placeId, postId: post.post_id, data: {body}});
|
||||
if (!res.result?.success) {
|
||||
notify.error(res.msg || '저장하지 못했습니다. 요금·시간·전화번호처럼 확인되지 않은 내용은 빼 주세요.');
|
||||
return;
|
||||
}
|
||||
notify.success('저장하고 승인했습니다. 사이트에 반영되기까지 몇 분 걸립니다.');
|
||||
onDone();
|
||||
} catch (error) {
|
||||
notifyApiError(error, '저장하지 못했습니다.');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mt-3 space-y-2">
|
||||
<textarea
|
||||
value={body}
|
||||
onChange={(event) => setBody(event.target.value)}
|
||||
rows={5}
|
||||
className="w-full rounded-md border border-border bg-muted/50 px-3 py-2 text-sm text-foreground outline-none transition-colors focus:border-ring focus:bg-card focus:ring-1 focus:ring-ring"
|
||||
/>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button size="sm" variant="primary" isLoading={editMutation.isPending} onClick={handleSave}>
|
||||
<Save />
|
||||
저장하고 승인
|
||||
</Button>
|
||||
<Button size="sm" variant="ghost" onClick={onDone} disabled={editMutation.isPending}>
|
||||
<X />
|
||||
취소
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PostCard({placeId, post, onChanged}: {placeId: string; post: PostData; onChanged: () => void}) {
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const status = STATUS_LABEL[post.status] ?? STATUS_LABEL[1];
|
||||
const editable = EDITABLE_STATUSES.has(post.status);
|
||||
const approveMutation = useApproveMyPost();
|
||||
const {text, chip} = post.scheduled_date ? dateLabel(post.scheduled_date) : {text: '', chip: null};
|
||||
|
||||
const handlePublish = async () => {
|
||||
try {
|
||||
const res = await approveMutation.mutateAsync({placeId, postId: post.post_id});
|
||||
if (!res.result?.success) {
|
||||
notify.error(res.msg || '발행하지 못했습니다.');
|
||||
return;
|
||||
}
|
||||
notify.success('발행했습니다. 사이트에 반영되기까지 몇 분 걸립니다.');
|
||||
onChanged();
|
||||
} catch (error) {
|
||||
notifyApiError(error, '발행하지 못했습니다.');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col rounded-lg border border-border bg-card p-3.5 shadow-lg">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-1.5">
|
||||
{chip && (
|
||||
<span className="rounded-full bg-primary px-2 py-0.5 text-[11px] font-bold text-primary-foreground">
|
||||
{chip}
|
||||
</span>
|
||||
)}
|
||||
{text && <span className="text-xs font-medium text-muted-foreground">{text}</span>}
|
||||
</div>
|
||||
<Badge variant={status.variant}>{status.label}</Badge>
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-muted-foreground">{TOPIC_LABEL[post.topic_kind] ?? '기타'}</p>
|
||||
{!isEditing && <p className="mt-2 line-clamp-6 flex-1 text-sm leading-relaxed">{post.body}</p>}
|
||||
{isEditing && (
|
||||
<PostEditor
|
||||
placeId={placeId}
|
||||
post={post}
|
||||
onDone={() => {
|
||||
setIsEditing(false);
|
||||
onChanged();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{editable && !isEditing && (
|
||||
<div className="mt-3 flex items-center gap-1.5 border-t border-border pt-3">
|
||||
<Button size="sm" variant="ghost" className="flex-1" onClick={() => setIsEditing(true)}>
|
||||
<Pencil />
|
||||
수정
|
||||
</Button>
|
||||
<Button size="sm" variant="primary" className="flex-1" isLoading={approveMutation.isPending} onClick={handlePublish}>
|
||||
<Send />
|
||||
바로 발행
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 카로셀용 미리보기 카드 — 누르면 모달이 뜬다. 수정·발행은 모달 안에서만 한다. */
|
||||
function PostPreviewCard({post, onClick}: {post: PostData; onClick: () => void}) {
|
||||
const status = STATUS_LABEL[post.status] ?? STATUS_LABEL[1];
|
||||
const {text, chip} = post.scheduled_date ? dateLabel(post.scheduled_date) : {text: '', chip: null};
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className="flex h-full w-full flex-col rounded-lg border border-border bg-card p-3.5 text-left shadow-lg transition-colors hover:bg-muted"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-1.5">
|
||||
{chip && (
|
||||
<span className="rounded-full bg-primary px-2 py-0.5 text-[11px] font-bold text-primary-foreground">
|
||||
{chip}
|
||||
</span>
|
||||
)}
|
||||
{text && <span className="text-xs font-medium text-muted-foreground">{text}</span>}
|
||||
</div>
|
||||
<Badge variant={status.variant}>{status.label}</Badge>
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-muted-foreground">{TOPIC_LABEL[post.topic_kind] ?? '기타'}</p>
|
||||
<p className="mt-2 line-clamp-6 flex-1 text-sm leading-relaxed">{post.body}</p>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 겹쳐 쌓은 글 카드 카로셀 — 오늘부터 일주일치만(당장 챙길 것). 가로로 스크롤하면 카드가
|
||||
* 하나씩 앞으로 나온다. 마우스를 올리면 그 카드가 가려지지 않고 맨 앞으로 온다.
|
||||
* ★ 카드를 눌러도 그 자리에서 고치지 않는다 — 달력 칸과 똑같이 모달을 연다(사장님 지시:
|
||||
* "카드클릭해도 모달나와서 수정가능하게 해야지").
|
||||
*/
|
||||
function PostCarousel({posts, onSelectPost}: {posts: PostData[]; onSelectPost: (post: PostData) => void}) {
|
||||
const [hoveredId, setHoveredId] = useState<string | null>(null);
|
||||
|
||||
return (
|
||||
<div className="flex snap-x snap-mandatory overflow-x-auto px-1 pt-1 pb-4">
|
||||
{posts.map((post, index) => {
|
||||
const hovered = hoveredId === post.post_id;
|
||||
return (
|
||||
<div
|
||||
key={post.post_id}
|
||||
onMouseEnter={() => setHoveredId(post.post_id)}
|
||||
onMouseLeave={() => setHoveredId(null)}
|
||||
className={cn(
|
||||
'w-72 shrink-0 snap-start transition-transform duration-150',
|
||||
index > 0 && '-ml-10',
|
||||
hovered && 'scale-105',
|
||||
)}
|
||||
style={{zIndex: hovered ? 999 : posts.length - index}}
|
||||
>
|
||||
<PostPreviewCard post={post} onClick={() => onSelectPost(post)} />
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 달력 한 장. **글이 0건이어도 항상 뜬다** — 그날그날 뭐가 있는지 훑어보는 게 목적이라
|
||||
* 목록이 비었다고 화면 자체가 사라지면 "이 달은 아무것도 없다"는 걸 확인할 방법이 없다.
|
||||
* ★ 여기서는 발행완료/발행실패만 표시한다(사장님 지시) — 칸을 누르면 모달로 전체 내용을 본다.
|
||||
* ★ 빈 날짜(오늘 이후)를 누르면 그 날짜 하나만 콕 집어 생성한다(사장님 지시: "개별적으로
|
||||
* 새로 만들수있게 해줘"). 지난 날짜는 이제 와서 만들 이유가 없어 클릭을 막는다.
|
||||
*/
|
||||
function Calendar({month, postsByDay, onSelectPost, onGenerateDay, generatingDay}: {
|
||||
month: string;
|
||||
postsByDay: Map<number, PostData>;
|
||||
onSelectPost: (post: PostData) => void;
|
||||
onGenerateDay: (date: string) => void;
|
||||
generatingDay: string | null;
|
||||
}) {
|
||||
const [year, mon] = month.split('-').map(Number);
|
||||
const daysInMonth = new Date(Date.UTC(year, mon, 0)).getUTCDate();
|
||||
const firstWeekday = new Date(Date.UTC(year, mon - 1, 1)).getUTCDay();
|
||||
const today = todayKst();
|
||||
const isCurrentMonth = today.year === year && today.month === mon;
|
||||
|
||||
const cells: (number | null)[] = [
|
||||
...Array.from({length: firstWeekday}, () => null),
|
||||
...Array.from({length: daysInMonth}, (_, i) => i + 1),
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden rounded-lg border border-border">
|
||||
<div className="grid grid-cols-7 border-b border-border bg-muted/40">
|
||||
{WEEKDAYS.map((label) => (
|
||||
<div key={label} className="py-2 text-center text-xs font-medium text-muted-foreground">
|
||||
{label}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid grid-cols-7">
|
||||
{cells.map((day, index) => {
|
||||
if (day === null) {
|
||||
return <div key={`blank-${index}`} className="aspect-square border-b border-r border-border/60 bg-muted/10" />;
|
||||
}
|
||||
const post = postsByDay.get(day);
|
||||
const badge = post ? publishBadge(post) : null;
|
||||
const isToday = isCurrentMonth && today.day === day;
|
||||
const isPast = isBeforeToday(year, mon, day, today);
|
||||
const cellDate = isoDate(year, mon, day);
|
||||
const isGenerating = generatingDay === cellDate;
|
||||
const clickable = !!post || (!isPast && !isGenerating);
|
||||
const handleClick = post
|
||||
? () => onSelectPost(post)
|
||||
: (!isPast && !isGenerating ? () => onGenerateDay(cellDate) : undefined);
|
||||
return (
|
||||
<div
|
||||
key={day}
|
||||
role={clickable ? 'button' : undefined}
|
||||
tabIndex={clickable ? 0 : undefined}
|
||||
onClick={handleClick}
|
||||
onKeyDown={handleClick ? (event) => event.key === 'Enter' && handleClick() : undefined}
|
||||
className={cn(
|
||||
'group flex aspect-square flex-col items-start gap-1 border-b border-r border-border/60 p-1.5 text-left sm:p-2',
|
||||
clickable && 'cursor-pointer transition-colors hover:bg-muted',
|
||||
isGenerating && 'cursor-wait',
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
'flex size-5 items-center justify-center rounded-full text-xs tabular-nums',
|
||||
isToday ? 'bg-primary text-primary-foreground font-semibold' : 'text-foreground',
|
||||
)}
|
||||
>
|
||||
{day}
|
||||
</span>
|
||||
{post && (
|
||||
<p className="line-clamp-2 w-full text-[10px] leading-tight break-all text-muted-foreground">
|
||||
{post.body.slice(0, 20)}
|
||||
</p>
|
||||
)}
|
||||
{badge && (
|
||||
<span className={cn('mt-auto rounded px-1 py-0.5 text-[9px] font-medium', badge.className)}>
|
||||
{badge.label}
|
||||
</span>
|
||||
)}
|
||||
{!post && !isPast && (
|
||||
<span
|
||||
className={cn(
|
||||
'mt-auto flex items-center gap-0.5 text-[10px] text-muted-foreground transition-opacity',
|
||||
isGenerating ? 'opacity-100' : 'opacity-0 group-hover:opacity-100',
|
||||
)}
|
||||
>
|
||||
{isGenerating ? <Loader2 className="size-3 animate-spin" /> : <Plus className="size-3" />}
|
||||
{isGenerating ? '만드는 중' : '생성'}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
type Tab = 'main' | 'history';
|
||||
const TAB_LABEL: Record<Tab, string> = {main: '블로그', history: '생성 이력'};
|
||||
|
||||
/** 생성 이력 — 언제 몇 건 만들었는지(사장님 지시: "생성이력도 있어야해 몇개 생성했는지"). */
|
||||
function GenerationHistoryList({placeId}: {placeId: string}) {
|
||||
const {data, isLoading} = useGetGenerationHistory(placeId);
|
||||
const batches = data?.batches ?? [];
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-16 text-muted-foreground">
|
||||
<Loader2 className="size-5 animate-spin" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (batches.length === 0) {
|
||||
return <p className="text-sm text-muted-foreground">아직 생성한 적이 없습니다.</p>;
|
||||
}
|
||||
|
||||
return (
|
||||
<ul className="divide-y divide-border rounded-lg border border-border">
|
||||
{batches.map((batch) => {
|
||||
const at = new Date(batch.created_at);
|
||||
const label = Number.isNaN(at.getTime())
|
||||
? batch.created_at
|
||||
: at.toLocaleString('ko-KR', {month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit'});
|
||||
return (
|
||||
<li key={batch.created_at} className="flex items-center justify-between px-4 py-3 text-sm">
|
||||
<span className="text-muted-foreground">{label}</span>
|
||||
<span className="font-semibold tabular-nums">{batch.count}건</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 이번 달(또는 고른 달) 생성된 미니 블로그 글. 기획: docs/MINI_BLOG.md
|
||||
*
|
||||
* ★ 사이트 하나를 고르고 들어온다 — `/sites` 카드의 관리 메뉴가 `?placeId=` 를 채운다.
|
||||
* 여러 사이트를 가진 사장님도 있어 전역 메뉴 하나로는 어느 사이트인지 알 수 없다.
|
||||
* ★ 화면이 둘로 나뉜다 — 위 카로셀은 "당장 챙길 것"(오늘부터 일주일)을 편집·발행하는 곳,
|
||||
* 아래 달력은 한 달 전체를 훑어보는 곳(칸을 누르면 모달로 본다).
|
||||
*/
|
||||
export function BlogPostsPage() {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const navigate = useNavigate();
|
||||
const placeId = searchParams.get('placeId') ?? '';
|
||||
|
||||
// 메일 "수정하기" 링크 — 그날짜리 자동 로그인(auto) 은 provider.tsx 의 세션 복구에서
|
||||
// 이미 처리됐다(라우트 가드보다 먼저 처리해야 해서 여기가 아니라 거기다). 여기서는
|
||||
// postId 로 그 글을 찾아 모달만 연다.
|
||||
const linkedPostId = searchParams.get('postId');
|
||||
|
||||
useEffect(() => {
|
||||
if (!searchParams.has('auto')) return;
|
||||
const next = new URLSearchParams(searchParams);
|
||||
next.delete('auto');
|
||||
setSearchParams(next, {replace: true});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const {data: linkedPostData} = useGetMyPost(placeId, linkedPostId ?? '', {
|
||||
query: {enabled: !!placeId && !!linkedPostId},
|
||||
});
|
||||
|
||||
// 과거 달·너무 먼 미래는 볼 이유가 없다 — 이번 달부터 1년 뒤까지만 넘겨볼 수 있다.
|
||||
const minMonth = currentMonth();
|
||||
const maxMonth = shiftMonth(minMonth, 12);
|
||||
const [month, setMonth] = useState(minMonth);
|
||||
const [modalPost, setModalPost] = useState<PostData | null>(null);
|
||||
const [tab, setTab] = useState<Tab>('main');
|
||||
|
||||
useEffect(() => {
|
||||
const linkedPost = linkedPostData?.posts?.[0];
|
||||
if (!linkedPost) return;
|
||||
setModalPost(linkedPost);
|
||||
const next = new URLSearchParams(searchParams);
|
||||
next.delete('postId');
|
||||
setSearchParams(next, {replace: true});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [linkedPostData]);
|
||||
|
||||
const {data, isLoading, isError, error, refetch} = useListMyPosts(placeId, {month});
|
||||
const posts = useMemo(() => data?.posts ?? [], [data]);
|
||||
const postsByDay = useMemo(() => {
|
||||
const map = new Map<number, PostData>();
|
||||
for (const post of posts) {
|
||||
if (!post.scheduled_date) continue;
|
||||
map.set(dayOf(post.scheduled_date), post);
|
||||
}
|
||||
return map;
|
||||
}, [posts]);
|
||||
|
||||
const {data: upcomingData, refetch: refetchUpcoming} = useListUpcomingPosts(placeId, {days: UPCOMING_DAYS});
|
||||
const upcomingPosts = useMemo(() => upcomingData?.posts ?? [], [upcomingData]);
|
||||
|
||||
const generateMutation = useGenerateMyPosts();
|
||||
const generateOneMutation = useGenerateMyPostForDate();
|
||||
const generatingDay = generateOneMutation.isPending ? (generateOneMutation.variables?.params.date ?? null) : null;
|
||||
|
||||
const [rangeDialogOpen, setRangeDialogOpen] = useState(false);
|
||||
const [rangeStart, setRangeStart] = useState(todayIso());
|
||||
const [rangeEnd, setRangeEnd] = useState(addDaysIso(todayIso(), 29));
|
||||
|
||||
const refetchAll = () => {
|
||||
void refetch();
|
||||
void refetchUpcoming();
|
||||
};
|
||||
|
||||
const handleGenerate = async () => {
|
||||
try {
|
||||
const res = await generateMutation.mutateAsync({placeId, params: {start: rangeStart, end: rangeEnd}});
|
||||
if (!res.result?.success) {
|
||||
notify.error(res.msg || '생성하지 못했습니다.');
|
||||
return;
|
||||
}
|
||||
notify.success(res.msg ?? `${res.created}건 만들었습니다.`);
|
||||
setRangeDialogOpen(false);
|
||||
refetchAll();
|
||||
} catch (generateError) {
|
||||
notifyApiError(generateError, '생성하지 못했습니다.');
|
||||
}
|
||||
};
|
||||
|
||||
const handleGenerateDay = async (date: string) => {
|
||||
try {
|
||||
const res = await generateOneMutation.mutateAsync({placeId, params: {date}});
|
||||
if (!res.result?.success) {
|
||||
notify.error(res.msg || '이 날짜엔 만들지 못했습니다.');
|
||||
return;
|
||||
}
|
||||
notify.success(res.msg ?? '만들었습니다.');
|
||||
refetchAll();
|
||||
if (res.post) setModalPost(res.post);
|
||||
} catch (generateOneError) {
|
||||
notifyApiError(generateOneError, '만들지 못했습니다.');
|
||||
}
|
||||
};
|
||||
|
||||
const generateButton = (
|
||||
<Button size="sm" variant="primary" onClick={() => setRangeDialogOpen(true)}>
|
||||
<Sparkles />
|
||||
지금 생성하기
|
||||
</Button>
|
||||
);
|
||||
|
||||
const maxGenerateDate = lastDayOfMonthIso(maxMonth);
|
||||
|
||||
if (!placeId) {
|
||||
return (
|
||||
<AppShell>
|
||||
<PageContainer title="블로그 글" description="어느 사이트의 글을 볼지 먼저 골라 주세요.">
|
||||
<EmptyState
|
||||
title="사이트를 먼저 선택하세요"
|
||||
description="내 사이트 목록에서 사이트를 고르면 그 사이트의 글이 보입니다."
|
||||
action={
|
||||
<Button size="sm" onClick={() => navigate('/sites')}>
|
||||
내 사이트로
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
</PageContainer>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<AppShell>
|
||||
<PageContainer title="블로그 글" description="AI 가 만든 글이 매일 조금씩 쌓입니다. 마음에 안 들면 고쳐서 올리세요." actions={generateButton}>
|
||||
{/* 탭은 생성 이력만 따로 뺀다 — 카로셀·달력은 계속 같이 보인다(사장님 지시: "탭으로
|
||||
나누지 말고 달력 위에 이번 주 카드들 보여주라고 했지"). */}
|
||||
<div className="mb-4 flex w-fit items-center gap-0.5 rounded-md border border-border p-0.5">
|
||||
{(Object.keys(TAB_LABEL) as Tab[]).map((key) => (
|
||||
<button
|
||||
key={key}
|
||||
type="button"
|
||||
aria-pressed={tab === key}
|
||||
onClick={() => setTab(key)}
|
||||
className={cn(
|
||||
'h-8 cursor-pointer rounded px-3 text-xs font-medium transition-colors',
|
||||
tab === key ? 'bg-muted text-foreground' : 'text-muted-foreground hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
{TAB_LABEL[key]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{tab === 'main' && (
|
||||
<>
|
||||
{upcomingPosts.length > 0 ? (
|
||||
<PostCarousel posts={upcomingPosts} onSelectPost={setModalPost} />
|
||||
) : (
|
||||
<p className="mb-3 text-sm text-muted-foreground">앞으로 일주일 안에 예정된 글이 없습니다.</p>
|
||||
)}
|
||||
|
||||
{/* 이전 달 · 월 · 다음 달 — 달력 바로 위(사장님 지시). */}
|
||||
<div className="mt-4 mb-3 flex items-center gap-1">
|
||||
<Button size="sm" variant="ghost" onClick={() => setMonth((m) => (m <= minMonth ? m : shiftMonth(m, -1)))}>
|
||||
이전 달
|
||||
</Button>
|
||||
<span className="px-2 text-sm font-medium tabular-nums">{monthLabel(month)}</span>
|
||||
<Button size="sm" variant="ghost" onClick={() => setMonth((m) => (m >= maxMonth ? m : shiftMonth(m, 1)))}>
|
||||
다음 달
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{isLoading && (
|
||||
<div className="flex items-center justify-center py-20 text-muted-foreground">
|
||||
<Loader2 className="size-5 animate-spin" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isError && (
|
||||
<EmptyState
|
||||
title="글을 불러오지 못했습니다"
|
||||
description={(error as Error)?.message ?? '잠시 후 다시 시도해 주세요.'}
|
||||
action={
|
||||
<Button size="sm" onClick={() => refetch()}>
|
||||
다시 시도
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{!isLoading && !isError && (
|
||||
<>
|
||||
{posts.length === 0 && (
|
||||
<p className="mb-3 text-sm text-muted-foreground">
|
||||
이 달엔 생성된 글이 없습니다. 새벽마다(04:10) 채워지거나, 지금 생성하기를 눌러 바로 만들 수 있습니다.
|
||||
</p>
|
||||
)}
|
||||
|
||||
<Calendar
|
||||
month={month}
|
||||
postsByDay={postsByDay}
|
||||
onSelectPost={setModalPost}
|
||||
onGenerateDay={handleGenerateDay}
|
||||
generatingDay={generatingDay}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{tab === 'history' && <GenerationHistoryList placeId={placeId} />}
|
||||
</PageContainer>
|
||||
|
||||
<Dialog
|
||||
open={!!modalPost}
|
||||
onClose={() => setModalPost(null)}
|
||||
title={modalPost?.scheduled_date ? `${dateLabel(modalPost.scheduled_date).text} 글` : '글'}
|
||||
>
|
||||
{modalPost && (
|
||||
<PostCard
|
||||
placeId={placeId}
|
||||
post={modalPost}
|
||||
onChanged={() => {
|
||||
refetchAll();
|
||||
setModalPost(null);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Dialog>
|
||||
|
||||
<Dialog
|
||||
open={rangeDialogOpen}
|
||||
onClose={() => setRangeDialogOpen(false)}
|
||||
title="지금 생성하기"
|
||||
description="채울 구간을 고르세요. 이미 글이 있는 날짜는 건너뛰고, 새로 쓸 소재가 떨어지면 거기서 멈춥니다."
|
||||
footer={
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button size="sm" variant="ghost" onClick={() => setRangeDialogOpen(false)} disabled={generateMutation.isPending}>
|
||||
취소
|
||||
</Button>
|
||||
<Button size="sm" variant="primary" isLoading={generateMutation.isPending} onClick={handleGenerate}>
|
||||
<Sparkles />
|
||||
생성
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<label className="flex flex-1 flex-col gap-1 text-xs text-muted-foreground">
|
||||
시작일
|
||||
<input
|
||||
type="date"
|
||||
value={rangeStart}
|
||||
min={todayIso()}
|
||||
max={rangeEnd || maxGenerateDate}
|
||||
onChange={(event) => setRangeStart(event.target.value)}
|
||||
className="rounded-md border border-border bg-muted/50 px-2 py-1.5 text-sm text-foreground outline-none focus:border-ring focus:bg-card focus:ring-1 focus:ring-ring"
|
||||
/>
|
||||
</label>
|
||||
<span className="mt-5 text-muted-foreground">~</span>
|
||||
<label className="flex flex-1 flex-col gap-1 text-xs text-muted-foreground">
|
||||
끝일
|
||||
<input
|
||||
type="date"
|
||||
value={rangeEnd}
|
||||
min={rangeStart || todayIso()}
|
||||
max={maxGenerateDate}
|
||||
onChange={(event) => setRangeEnd(event.target.value)}
|
||||
className="rounded-md border border-border bg-muted/50 px-2 py-1.5 text-sm text-foreground outline-none focus:border-ring focus:bg-card focus:ring-1 focus:ring-ring"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</Dialog>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
// 라우트 모듈은 default export 를 요구한다(routes.ts 가 이 파일을 가리킨다).
|
||||
export default BlogPostsPage;
|
||||
@@ -2,10 +2,12 @@ import {useMemo, useState} from 'react';
|
||||
import {Link, useNavigate} from 'react-router';
|
||||
import {
|
||||
Building2,
|
||||
CalendarClock,
|
||||
Coffee,
|
||||
ExternalLink,
|
||||
Loader2,
|
||||
MoreHorizontal,
|
||||
Newspaper,
|
||||
Pencil,
|
||||
Plus,
|
||||
Search,
|
||||
@@ -415,7 +417,7 @@ export function SitesPage() {
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
aria-label="더보기"
|
||||
aria-label="관리 메뉴"
|
||||
isLoading={busyId === row.place_id}
|
||||
onClick={() => setMenuId(menuId === row.place_id ? null : row.place_id)}
|
||||
>
|
||||
@@ -426,19 +428,59 @@ export function SitesPage() {
|
||||
|
||||
{menuId === row.place_id && (
|
||||
<>
|
||||
{/* 바깥을 눌러 닫는다. 메뉴 하나짜리라 팝오버 라이브러리를 들이지 않는다. */}
|
||||
{/* 바깥을 눌러 닫는다. 메뉴가 몇 줄 안 돼 팝오버 라이브러리를 들이지 않는다. */}
|
||||
<button
|
||||
type="button"
|
||||
aria-label="닫기"
|
||||
className="fixed inset-0 z-10 cursor-default"
|
||||
onClick={() => setMenuId(null)}
|
||||
/>
|
||||
<div className="absolute right-3.5 bottom-12 z-20 w-44 rounded-md border border-border bg-card py-1 shadow-md">
|
||||
<div className="absolute right-3.5 bottom-12 z-20 w-52 rounded-md border border-border bg-card py-1 shadow-md">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMenuId(null);
|
||||
navigate(editHref);
|
||||
}}
|
||||
className="flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-muted"
|
||||
>
|
||||
<Pencil className="size-3.5" />
|
||||
디자인·컨텐츠 관리
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMenuId(null);
|
||||
navigate(`/blog?placeId=${row.place_id}`);
|
||||
}}
|
||||
className="flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-muted"
|
||||
>
|
||||
<Newspaper className="size-3.5" />
|
||||
미니블로그 관리
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMenuId(null);
|
||||
// ★ 예약 요청은 DB 에 안 남는다(2026-09-16 대표 지시, booking_request.py) —
|
||||
// 메일로만 가고 우리 쪽엔 로그 한 줄만 남는다. 목록 화면을 만들려면
|
||||
// 그 결정부터 뒤집어야 한다 — 지금은 안내만 한다.
|
||||
notify.info(
|
||||
'예약 요청은 메일로만 전달됩니다',
|
||||
'연락처를 따로 저장하지 않기로 했습니다(2026-09-16). 목록이 필요하면 먼저 이 방침을 바꿔야 합니다.',
|
||||
);
|
||||
}}
|
||||
className="flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-muted"
|
||||
>
|
||||
<CalendarClock className="size-3.5" />
|
||||
예약요청 관리
|
||||
</button>
|
||||
<div className="my-1 border-t border-border" />
|
||||
<button
|
||||
type="button"
|
||||
disabled={row.status !== SiteStatus.PUBLISHED}
|
||||
onClick={() => handleUnpublish(row)}
|
||||
className="w-full cursor-pointer px-3 py-2 text-left text-xs transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-40"
|
||||
className="w-full cursor-pointer px-3 py-2 text-left text-xs text-destructive transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-40"
|
||||
>
|
||||
발행 내리기
|
||||
</button>
|
||||
|
||||
Reference in new issue
Block a user