feat: clinic registry DB + pipeline audit P0 fixes
## Clinic Registry - data/clinic-registry/clinic_registry_working.csv — 91개 병원 채널 마스터 DB - data/clinic-registry/INFINITH_Outbound_List.csv — BD팀 아웃바운드 리스트 (17컬럼) - data/clinic-registry/update_csv.py — 안전 CSV 업데이트 스크립트 (빈 필드만 채움) - data/clinic-registry/extract_place_ids.py — 네이버 플레이스 ID 추출기 - scripts/import-registry.ts — CSV → Supabase clinic_registry 테이블 임포트 - supabase/migrations/20260406_clinic_registry.sql — clinic_registry 테이블 스키마 ## Pipeline P0 Bug Fixes (전수 감사 후) - fix(collect-channel-data): 강남언니 rating 0-10 스케일 오변환 제거 - 기존: rating ≤ 5이면 ×2 → 4.8/10을 9.6/10으로 잘못 변환 - 수정: Firecrawl 프롬프트가 이미 0-10 지시 → rawValue 직접 신뢰 - fix(generate-report): Perplexity 단일 fetch → fetchWithRetry 교체 - maxRetries:2, backoffMs:[5000,15000], timeoutMs:90s - 기존: 타임아웃/429 시 리포트 생성 전체 실패 - 수정: 자동 재시도로 일시적 API 오류 극복 ## Docs - docs/PIPELINE_IMPROVEMENT_PLAN.md — Sprint 0/1/2 완료 표시 + 전수 감사 결과 추가 - docs/REGISTRY_FUNCTIONAL_SPECS.md, DB_SCHEMA_V3.md 외 기획 문서 다수 추가 ## New Components & Features - supabase/functions/generate-content-plan, adjust-strategy — 콘텐츠 플랜/전략 조정 - src/components/plan/EditEntryModal, StrategyAdjustmentSection — 플랜 편집 UI - supabase/functions/_shared/dataQuality, foundingYearExtractor, urlClassifier — 데이터 품질 유틸 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec991057e6
commit
d5f7f24e0a
51 files changed
+5390
-252
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { motion } from 'motion/react';
|
||||
import {
|
||||
VideoFilled,
|
||||
@@ -6,10 +7,13 @@ import {
|
||||
MegaphoneFilled,
|
||||
} from '../icons/FilledIcons';
|
||||
import { SectionWrapper } from '../report/ui/SectionWrapper';
|
||||
import EditEntryModal from './EditEntryModal';
|
||||
import type { CalendarData, ContentCategory, CalendarEntry } from '../../types/plan';
|
||||
|
||||
interface ContentCalendarProps {
|
||||
data: CalendarData;
|
||||
planId?: string;
|
||||
onEntryUpdate?: (entryId: string, updates: Partial<CalendarEntry>) => void;
|
||||
}
|
||||
|
||||
const contentTypeColors: Record<ContentCategory, { bg: string; text: string; entry: string; border: string; shadow: string }> = {
|
||||
@@ -44,9 +48,118 @@ const channelEmojiMap: Record<string, string> = {
|
||||
video: '▷',
|
||||
};
|
||||
|
||||
const statusDotColors: Record<string, string> = {
|
||||
draft: 'bg-slate-300',
|
||||
approved: 'bg-purple-400',
|
||||
published: 'bg-green-400',
|
||||
};
|
||||
|
||||
const dayHeaders = ['월', '화', '수', '목', '금', '토', '일'];
|
||||
|
||||
export default function ContentCalendar({ data }: ContentCalendarProps) {
|
||||
export default function ContentCalendar({ data, planId, onEntryUpdate }: ContentCalendarProps) {
|
||||
const [weeks, setWeeks] = useState(data.weeks);
|
||||
const [editingEntry, setEditingEntry] = useState<CalendarEntry | null>(null);
|
||||
const [filterType, setFilterType] = useState<ContentCategory | null>(null);
|
||||
const [viewMode, setViewMode] = useState<'weekly' | 'monthly'>('weekly');
|
||||
|
||||
const handleEntryClick = useCallback((entry: CalendarEntry) => {
|
||||
setEditingEntry(entry);
|
||||
}, []);
|
||||
|
||||
const handleSave = useCallback((updated: CalendarEntry) => {
|
||||
setWeeks((prev) =>
|
||||
prev.map((week) => ({
|
||||
...week,
|
||||
entries: week.entries.map((e) =>
|
||||
(e.id && e.id === updated.id) ? updated : e
|
||||
),
|
||||
}))
|
||||
);
|
||||
if (onEntryUpdate && updated.id) {
|
||||
onEntryUpdate(updated.id, updated);
|
||||
}
|
||||
setEditingEntry(null);
|
||||
}, [onEntryUpdate]);
|
||||
|
||||
const handleClose = useCallback(() => {
|
||||
setEditingEntry(null);
|
||||
}, []);
|
||||
|
||||
const toggleFilter = (type: ContentCategory) => {
|
||||
setFilterType((prev) => (prev === type ? null : type));
|
||||
};
|
||||
|
||||
// Monthly view: flatten all weeks into one 7-day grid
|
||||
const renderMonthlyView = () => {
|
||||
const allEntries = weeks.flatMap((w) => w.entries);
|
||||
const filtered = filterType
|
||||
? allEntries.filter((e) => e.contentType === filterType)
|
||||
: allEntries;
|
||||
|
||||
const dayCells: CalendarEntry[][] = Array.from({ length: 7 }, () => []);
|
||||
for (const entry of filtered) {
|
||||
if (entry.dayOfWeek >= 0 && entry.dayOfWeek <= 6) {
|
||||
dayCells[entry.dayOfWeek].push(entry);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-2xl p-5 shadow-[3px_4px_12px_rgba(0,0,0,0.06)]">
|
||||
<p className="text-sm font-bold text-[#0A1128] mb-3">월간 종합</p>
|
||||
<div className="grid grid-cols-7 gap-2">
|
||||
{dayHeaders.map((day) => (
|
||||
<div key={day} className="text-xs text-slate-400 uppercase tracking-wide text-center mb-1 font-medium">
|
||||
{day}
|
||||
</div>
|
||||
))}
|
||||
{dayCells.map((entries, dayIdx) => (
|
||||
<div
|
||||
key={dayIdx}
|
||||
className={`min-h-[100px] rounded-xl p-1.5 ${
|
||||
entries.length > 0
|
||||
? 'bg-slate-50/50 border border-slate-100'
|
||||
: 'border border-dashed border-slate-200/60'
|
||||
}`}
|
||||
>
|
||||
{entries.map((entry, entryIdx) => renderEntry(entry, entryIdx))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const renderEntry = (entry: CalendarEntry, entryIdx: number) => {
|
||||
const colors = contentTypeColors[entry.contentType];
|
||||
const Icon = contentTypeIcons[entry.contentType];
|
||||
const channelSymbol = channelEmojiMap[entry.channelIcon] || '·';
|
||||
const statusDot = statusDotColors[entry.status || 'draft'];
|
||||
|
||||
return (
|
||||
<div
|
||||
key={entry.id || entryIdx}
|
||||
className={`${colors.entry} border rounded-lg p-1.5 mb-1 last:mb-0 cursor-pointer hover:ring-2 hover:ring-purple-200 transition-all group relative`}
|
||||
onClick={() => handleEntryClick(entry)}
|
||||
>
|
||||
<div className="flex items-center gap-1 mb-0.5">
|
||||
<span className={`w-1.5 h-1.5 rounded-full ${statusDot} flex-shrink-0`} />
|
||||
<span className={`text-[9px] font-bold ${colors.text} leading-none`}>
|
||||
{channelSymbol}
|
||||
</span>
|
||||
<Icon size={10} className={colors.text} />
|
||||
</div>
|
||||
<p className="text-[11px] text-slate-700 leading-tight line-clamp-2">
|
||||
{entry.title}
|
||||
</p>
|
||||
{entry.description && (
|
||||
<p className="text-[9px] text-slate-400 leading-tight mt-0.5 line-clamp-1 hidden group-hover:block">
|
||||
{entry.description}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<SectionWrapper
|
||||
id="content-calendar"
|
||||
@@ -54,18 +167,57 @@ export default function ContentCalendar({ data }: ContentCalendarProps) {
|
||||
subtitle="콘텐츠 캘린더 (월간)"
|
||||
dark
|
||||
>
|
||||
{/* Toolbar: View Toggle + Filters */}
|
||||
<div className="flex items-center justify-between mb-4 flex-wrap gap-2" data-no-print>
|
||||
{/* View toggle */}
|
||||
<div className="flex bg-slate-100 rounded-xl p-0.5">
|
||||
<button
|
||||
onClick={() => setViewMode('weekly')}
|
||||
className={`px-3 py-1.5 text-xs font-medium rounded-lg transition-all ${
|
||||
viewMode === 'weekly'
|
||||
? 'bg-white text-[#0A1128] shadow-sm'
|
||||
: 'text-slate-500 hover:text-slate-700'
|
||||
}`}
|
||||
>
|
||||
주간
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setViewMode('monthly')}
|
||||
className={`px-3 py-1.5 text-xs font-medium rounded-lg transition-all ${
|
||||
viewMode === 'monthly'
|
||||
? 'bg-white text-[#0A1128] shadow-sm'
|
||||
: 'text-slate-500 hover:text-slate-700'
|
||||
}`}
|
||||
>
|
||||
월간
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Status legend */}
|
||||
<div className="flex gap-3 text-[10px] text-slate-400">
|
||||
<span className="flex items-center gap-1"><span className="w-1.5 h-1.5 rounded-full bg-slate-300" />초안</span>
|
||||
<span className="flex items-center gap-1"><span className="w-1.5 h-1.5 rounded-full bg-purple-400" />승인</span>
|
||||
<span className="flex items-center gap-1"><span className="w-1.5 h-1.5 rounded-full bg-green-400" />게시됨</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Monthly Summary */}
|
||||
<div className="flex flex-wrap gap-4 mb-8">
|
||||
{data.monthlySummary.map((item) => {
|
||||
const colors = contentTypeColors[item.type];
|
||||
const isActive = filterType === item.type;
|
||||
return (
|
||||
<motion.div
|
||||
key={item.type}
|
||||
className={`flex-1 min-w-[140px] rounded-2xl border p-4 ${colors.bg} ${colors.border} ${colors.shadow}`}
|
||||
className={`flex-1 min-w-[140px] rounded-2xl border p-4 cursor-pointer transition-all ${colors.bg} ${colors.border} ${colors.shadow} ${
|
||||
isActive ? 'ring-2 ring-purple-400 ring-offset-1' : ''
|
||||
} ${filterType && !isActive ? 'opacity-40' : ''}`}
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
viewport={{ once: true }}
|
||||
transition={{ duration: 0.3 }}
|
||||
onClick={() => toggleFilter(item.type)}
|
||||
data-no-print={undefined}
|
||||
>
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<span
|
||||
@@ -80,91 +232,95 @@ export default function ContentCalendar({ data }: ContentCalendarProps) {
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Weekly Calendar Grid */}
|
||||
{data.weeks.map((week, weekIdx) => {
|
||||
const dayCells: CalendarEntry[][] = Array.from({ length: 7 }, () => []);
|
||||
for (const entry of week.entries) {
|
||||
const dayIndex = entry.dayOfWeek;
|
||||
if (dayIndex >= 0 && dayIndex <= 6) {
|
||||
dayCells[dayIndex].push(entry);
|
||||
{/* Calendar Content */}
|
||||
{viewMode === 'monthly' ? (
|
||||
renderMonthlyView()
|
||||
) : (
|
||||
/* Weekly Calendar Grid */
|
||||
weeks.map((week, weekIdx) => {
|
||||
const dayCells: CalendarEntry[][] = Array.from({ length: 7 }, () => []);
|
||||
for (const entry of week.entries) {
|
||||
if (filterType && entry.contentType !== filterType) continue;
|
||||
const dayIndex = entry.dayOfWeek;
|
||||
if (dayIndex >= 0 && dayIndex <= 6) {
|
||||
dayCells[dayIndex].push(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
key={week.weekNumber}
|
||||
className="bg-white rounded-2xl p-5 mb-4 shadow-[3px_4px_12px_rgba(0,0,0,0.06)]"
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
viewport={{ once: true }}
|
||||
transition={{ duration: 0.4, delay: weekIdx * 0.1 }}
|
||||
>
|
||||
{/* Week header with theme */}
|
||||
<p className="text-sm font-bold text-[#0A1128] mb-3">{week.label}</p>
|
||||
return (
|
||||
<motion.div
|
||||
key={week.weekNumber}
|
||||
className="bg-white rounded-2xl p-5 mb-4 shadow-[3px_4px_12px_rgba(0,0,0,0.06)]"
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
viewport={{ once: true }}
|
||||
transition={{ duration: 0.4, delay: weekIdx * 0.1 }}
|
||||
>
|
||||
<p className="text-sm font-bold text-[#0A1128] mb-3">{week.label}</p>
|
||||
|
||||
<div className="grid grid-cols-7 gap-2">
|
||||
{/* Day headers */}
|
||||
{dayHeaders.map((day) => (
|
||||
<div
|
||||
key={day}
|
||||
className="text-xs text-slate-400 uppercase tracking-wide text-center mb-1 font-medium"
|
||||
>
|
||||
{day}
|
||||
</div>
|
||||
))}
|
||||
<div className="grid grid-cols-7 gap-2">
|
||||
{dayHeaders.map((day) => (
|
||||
<div
|
||||
key={day}
|
||||
className="text-xs text-slate-400 uppercase tracking-wide text-center mb-1 font-medium"
|
||||
>
|
||||
{day}
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* Day cells */}
|
||||
{dayCells.map((entries, dayIdx) => (
|
||||
<div
|
||||
key={dayIdx}
|
||||
className={`min-h-[80px] rounded-xl p-1.5 ${
|
||||
entries.length > 0
|
||||
? 'bg-slate-50/50 border border-slate-100'
|
||||
: 'border border-dashed border-slate-200/60'
|
||||
}`}
|
||||
>
|
||||
{entries.map((entry, entryIdx) => {
|
||||
const colors = contentTypeColors[entry.contentType];
|
||||
const Icon = contentTypeIcons[entry.contentType];
|
||||
const channelSymbol = channelEmojiMap[entry.channelIcon] || '·';
|
||||
return (
|
||||
<div
|
||||
key={entryIdx}
|
||||
className={`${colors.entry} border rounded-lg p-1.5 mb-1 last:mb-0`}
|
||||
>
|
||||
<div className="flex items-center gap-1 mb-0.5">
|
||||
<span className={`text-[9px] font-bold ${colors.text} leading-none`}>
|
||||
{channelSymbol}
|
||||
</span>
|
||||
<Icon size={10} className={colors.text} />
|
||||
</div>
|
||||
<p className="text-[11px] text-slate-700 leading-tight line-clamp-2">
|
||||
{entry.title}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
})}
|
||||
{dayCells.map((entries, dayIdx) => (
|
||||
<div
|
||||
key={dayIdx}
|
||||
className={`min-h-[80px] rounded-xl p-1.5 ${
|
||||
entries.length > 0
|
||||
? 'bg-slate-50/50 border border-slate-100'
|
||||
: 'border border-dashed border-slate-200/60'
|
||||
}`}
|
||||
>
|
||||
{entries.map((entry, entryIdx) => renderEntry(entry, entryIdx))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
})
|
||||
)}
|
||||
|
||||
{/* Color Legend */}
|
||||
{/* Color Legend (clickable filter) */}
|
||||
<div className="flex flex-wrap gap-3 mt-4">
|
||||
{(Object.keys(contentTypeColors) as ContentCategory[]).map((type) => {
|
||||
const colors = contentTypeColors[type];
|
||||
const isActive = filterType === type;
|
||||
return (
|
||||
<span
|
||||
<button
|
||||
key={type}
|
||||
className={`${colors.bg} ${colors.text} border ${colors.border} rounded-full px-3 py-1 text-xs font-medium ${colors.shadow}`}
|
||||
onClick={() => toggleFilter(type)}
|
||||
className={`${colors.bg} ${colors.text} border ${colors.border} rounded-full px-3 py-1 text-xs font-medium ${colors.shadow} transition-all ${
|
||||
isActive ? 'ring-2 ring-purple-300' : ''
|
||||
} ${filterType && !isActive ? 'opacity-40' : ''}`}
|
||||
>
|
||||
{contentTypeLabels[type]}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{filterType && (
|
||||
<button
|
||||
onClick={() => setFilterType(null)}
|
||||
className="text-xs text-slate-400 hover:text-slate-600 px-2 py-1 transition-colors"
|
||||
>
|
||||
필터 해제
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Edit Modal */}
|
||||
{editingEntry && (
|
||||
<EditEntryModal
|
||||
entry={editingEntry}
|
||||
onSave={handleSave}
|
||||
onClose={handleClose}
|
||||
/>
|
||||
)}
|
||||
</SectionWrapper>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { motion, AnimatePresence } from 'motion/react';
|
||||
import type { CalendarEntry, ContentCategory } from '../../types/plan';
|
||||
|
||||
interface EditEntryModalProps {
|
||||
entry: CalendarEntry | null;
|
||||
onSave: (updated: CalendarEntry) => void;
|
||||
onClose: () => void;
|
||||
onRegenerate?: (entry: CalendarEntry) => void;
|
||||
}
|
||||
|
||||
const CHANNELS = [
|
||||
{ id: 'YouTube', icon: 'youtube' },
|
||||
{ id: 'Instagram', icon: 'instagram' },
|
||||
{ id: '네이버 블로그', icon: 'blog' },
|
||||
{ id: 'Facebook', icon: 'facebook' },
|
||||
{ id: 'TikTok', icon: 'video' },
|
||||
];
|
||||
|
||||
const CONTENT_TYPES: { value: ContentCategory; label: string }[] = [
|
||||
{ value: 'video', label: '영상' },
|
||||
{ value: 'blog', label: '블로그' },
|
||||
{ value: 'social', label: '소셜' },
|
||||
{ value: 'ad', label: '광고' },
|
||||
];
|
||||
|
||||
const DAYS = ['월', '화', '수', '목', '금', '토', '일'];
|
||||
|
||||
const STATUS_OPTIONS: { value: CalendarEntry['status']; label: string; color: string }[] = [
|
||||
{ value: 'draft', label: '초안', color: 'bg-slate-200 text-slate-600' },
|
||||
{ value: 'approved', label: '승인', color: 'bg-purple-100 text-purple-700' },
|
||||
{ value: 'published', label: '게시됨', color: 'bg-green-100 text-green-700' },
|
||||
];
|
||||
|
||||
export default function EditEntryModal({ entry, onSave, onClose, onRegenerate }: EditEntryModalProps) {
|
||||
const [title, setTitle] = useState('');
|
||||
const [description, setDescription] = useState('');
|
||||
const [channel, setChannel] = useState('YouTube');
|
||||
const [channelIcon, setChannelIcon] = useState('youtube');
|
||||
const [contentType, setContentType] = useState<ContentCategory>('video');
|
||||
const [dayOfWeek, setDayOfWeek] = useState(0);
|
||||
const [status, setStatus] = useState<CalendarEntry['status']>('draft');
|
||||
|
||||
useEffect(() => {
|
||||
if (!entry) return;
|
||||
setTitle(entry.title || '');
|
||||
setDescription(entry.description || '');
|
||||
setChannel(entry.channel || 'YouTube');
|
||||
setChannelIcon(entry.channelIcon || 'youtube');
|
||||
setContentType(entry.contentType || 'video');
|
||||
setDayOfWeek(entry.dayOfWeek);
|
||||
setStatus(entry.status || 'draft');
|
||||
}, [entry]);
|
||||
|
||||
if (!entry) return null;
|
||||
|
||||
const handleChannelChange = (channelId: string) => {
|
||||
const ch = CHANNELS.find((c) => c.id === channelId);
|
||||
if (ch) {
|
||||
setChannel(ch.id);
|
||||
setChannelIcon(ch.icon);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
onSave({
|
||||
...entry,
|
||||
title,
|
||||
description,
|
||||
channel,
|
||||
channelIcon,
|
||||
contentType,
|
||||
dayOfWeek,
|
||||
status,
|
||||
isManualEdit: true,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
||||
{/* Backdrop */}
|
||||
<motion.div
|
||||
className="absolute inset-0 bg-black/40 backdrop-blur-sm"
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
onClick={onClose}
|
||||
/>
|
||||
|
||||
{/* Modal */}
|
||||
<motion.div
|
||||
className="relative w-full max-w-lg bg-white rounded-2xl shadow-xl overflow-hidden"
|
||||
initial={{ opacity: 0, scale: 0.95, y: 20 }}
|
||||
animate={{ opacity: 1, scale: 1, y: 0 }}
|
||||
exit={{ opacity: 0, scale: 0.95, y: 20 }}
|
||||
transition={{ duration: 0.2 }}
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between px-6 py-4 border-b border-slate-100">
|
||||
<h3 className="text-lg font-bold text-[#0A1128]">콘텐츠 편집</h3>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="text-slate-400 hover:text-slate-600 transition-colors"
|
||||
>
|
||||
<svg className="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Body */}
|
||||
<div className="px-6 py-5 space-y-4 max-h-[60vh] overflow-y-auto">
|
||||
{/* Title */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-600 mb-1">제목</label>
|
||||
<input
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
className="w-full px-3 py-2 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-purple-200 focus:border-purple-400 outline-none transition-all"
|
||||
placeholder="콘텐츠 제목을 입력하세요"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-600 mb-1">제작 가이드</label>
|
||||
<textarea
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
rows={3}
|
||||
className="w-full px-3 py-2 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-purple-200 focus:border-purple-400 outline-none transition-all resize-none"
|
||||
placeholder="AI가 생성한 제작 가이드 또는 직접 메모를 입력하세요"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Channel + Content Type Row */}
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-600 mb-1">채널</label>
|
||||
<select
|
||||
value={channel}
|
||||
onChange={(e) => handleChannelChange(e.target.value)}
|
||||
className="w-full px-3 py-2 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-purple-200 focus:border-purple-400 outline-none bg-white"
|
||||
>
|
||||
{CHANNELS.map((ch) => (
|
||||
<option key={ch.id} value={ch.id}>{ch.id}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-600 mb-1">유형</label>
|
||||
<select
|
||||
value={contentType}
|
||||
onChange={(e) => setContentType(e.target.value as ContentCategory)}
|
||||
className="w-full px-3 py-2 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-purple-200 focus:border-purple-400 outline-none bg-white"
|
||||
>
|
||||
{CONTENT_TYPES.map((ct) => (
|
||||
<option key={ct.value} value={ct.value}>{ct.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Day + Status Row */}
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-600 mb-1">요일</label>
|
||||
<select
|
||||
value={dayOfWeek}
|
||||
onChange={(e) => setDayOfWeek(Number(e.target.value))}
|
||||
className="w-full px-3 py-2 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-purple-200 focus:border-purple-400 outline-none bg-white"
|
||||
>
|
||||
{DAYS.map((d, i) => (
|
||||
<option key={i} value={i}>{d}요일</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-600 mb-1">상태</label>
|
||||
<div className="flex gap-2">
|
||||
{STATUS_OPTIONS.map((s) => (
|
||||
<button
|
||||
key={s.value}
|
||||
onClick={() => setStatus(s.value)}
|
||||
className={`px-3 py-2 rounded-xl text-xs font-medium transition-all ${
|
||||
status === s.value
|
||||
? `${s.color} ring-2 ring-offset-1 ring-purple-300`
|
||||
: 'bg-slate-50 text-slate-400 hover:bg-slate-100'
|
||||
}`}
|
||||
>
|
||||
{s.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer */}
|
||||
<div className="flex items-center justify-between px-6 py-4 border-t border-slate-100 bg-slate-50/50">
|
||||
{onRegenerate ? (
|
||||
<button
|
||||
onClick={() => onRegenerate(entry)}
|
||||
className="flex items-center gap-1.5 px-3 py-2 text-sm text-purple-600 hover:bg-purple-50 rounded-xl transition-colors"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
|
||||
</svg>
|
||||
AI 재생성
|
||||
</button>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="px-4 py-2 text-sm text-slate-500 hover:text-slate-700 transition-colors"
|
||||
>
|
||||
취소
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSave}
|
||||
className="px-5 py-2 text-sm font-medium text-white bg-[#6C5CE7] hover:bg-[#5A4BD6] rounded-xl transition-colors shadow-sm"
|
||||
>
|
||||
저장
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
</div>
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { motion } from 'motion/react';
|
||||
import { SectionWrapper } from '../report/ui/SectionWrapper';
|
||||
import { supabase, triggerStrategyAdjustment } from '../../lib/supabase';
|
||||
|
||||
interface StrategyAdjustmentSectionProps {
|
||||
clinicId: string | null;
|
||||
planId?: string;
|
||||
}
|
||||
|
||||
interface KpiProgress {
|
||||
metric: string;
|
||||
current: string;
|
||||
target: string;
|
||||
progress: number;
|
||||
}
|
||||
|
||||
interface StrategySuggestion {
|
||||
adjustmentType: string;
|
||||
channel: string;
|
||||
description: string;
|
||||
reason: string;
|
||||
priority: 'high' | 'medium' | 'low';
|
||||
beforeValue: string;
|
||||
afterValue: string;
|
||||
}
|
||||
|
||||
interface AdjustmentHistoryItem {
|
||||
id: string;
|
||||
adjustment_type: string;
|
||||
description: string;
|
||||
reason: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
const priorityColors: Record<string, { bg: string; text: string; dot: string }> = {
|
||||
high: { bg: 'bg-red-50', text: 'text-red-700', dot: 'bg-red-400' },
|
||||
medium: { bg: 'bg-amber-50', text: 'text-amber-700', dot: 'bg-amber-400' },
|
||||
low: { bg: 'bg-blue-50', text: 'text-blue-700', dot: 'bg-blue-400' },
|
||||
};
|
||||
|
||||
const typeLabels: Record<string, string> = {
|
||||
frequency_change: '게시 빈도 조정',
|
||||
pillar_shift: '콘텐츠 필러 전환',
|
||||
channel_add: '채널 추가',
|
||||
channel_pause: '채널 일시 중지',
|
||||
content_format_change: '포맷 변경',
|
||||
tone_shift: '톤 조정',
|
||||
other: '기타 조정',
|
||||
};
|
||||
|
||||
export default function StrategyAdjustmentSection({ clinicId, planId }: StrategyAdjustmentSectionProps) {
|
||||
const [kpiProgress, setKpiProgress] = useState<KpiProgress[]>([]);
|
||||
const [suggestions, setSuggestions] = useState<StrategySuggestion[]>([]);
|
||||
const [history, setHistory] = useState<AdjustmentHistoryItem[]>([]);
|
||||
const [overallAssessment, setOverallAssessment] = useState<string>('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isRunning, setIsRunning] = useState(false);
|
||||
const [hasData, setHasData] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!clinicId) return;
|
||||
loadExistingData();
|
||||
}, [clinicId]);
|
||||
|
||||
async function loadExistingData() {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
// Load latest performance metrics
|
||||
const { data: perf } = await supabase
|
||||
.from('performance_metrics')
|
||||
.select('kpi_progress, strategy_suggestions')
|
||||
.eq('clinic_id', clinicId!)
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(1)
|
||||
.single();
|
||||
|
||||
if (perf) {
|
||||
setKpiProgress((perf.kpi_progress as KpiProgress[]) || []);
|
||||
setSuggestions((perf.strategy_suggestions as StrategySuggestion[]) || []);
|
||||
setHasData(true);
|
||||
}
|
||||
|
||||
// Load adjustment history
|
||||
const { data: adj } = await supabase
|
||||
.from('strategy_adjustments')
|
||||
.select('id, adjustment_type, description, reason, created_at')
|
||||
.eq('clinic_id', clinicId!)
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(10);
|
||||
|
||||
if (adj) setHistory(adj);
|
||||
} catch {
|
||||
// No data yet — show empty state
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRunAdjustment() {
|
||||
if (!clinicId || isRunning) return;
|
||||
setIsRunning(true);
|
||||
try {
|
||||
const result = await triggerStrategyAdjustment(clinicId);
|
||||
if (result.success) {
|
||||
setKpiProgress(result.kpiProgress || []);
|
||||
setSuggestions(result.adjustments?.strategySuggestions || []);
|
||||
setOverallAssessment(result.adjustments?.overallAssessment || '');
|
||||
setHasData(true);
|
||||
await loadExistingData(); // Refresh history
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Strategy adjustment failed:', err);
|
||||
} finally {
|
||||
setIsRunning(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<SectionWrapper id="strategy-adjustment" title="Strategy Adjustment" subtitle="전략 조정" dark>
|
||||
<div className="flex justify-center py-12">
|
||||
<div className="w-6 h-6 border-2 border-purple-300 border-t-purple-600 rounded-full animate-spin" />
|
||||
</div>
|
||||
</SectionWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<SectionWrapper id="strategy-adjustment" title="Strategy Adjustment" subtitle="성과 기반 전략 조정" dark>
|
||||
{/* Action Button */}
|
||||
<div className="flex items-center justify-between mb-6" data-no-print>
|
||||
<p className="text-sm text-slate-500">
|
||||
채널 성과 데이터를 분석하여 콘텐츠 전략을 자동 조정합니다
|
||||
</p>
|
||||
<button
|
||||
onClick={handleRunAdjustment}
|
||||
disabled={isRunning}
|
||||
className={`flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-medium transition-all ${
|
||||
isRunning
|
||||
? 'bg-slate-100 text-slate-400 cursor-not-allowed'
|
||||
: 'bg-[#6C5CE7] text-white hover:bg-[#5A4BD6] shadow-sm'
|
||||
}`}
|
||||
>
|
||||
{isRunning ? (
|
||||
<>
|
||||
<div className="w-4 h-4 border-2 border-slate-300 border-t-slate-500 rounded-full animate-spin" />
|
||||
분석 중...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
|
||||
</svg>
|
||||
전략 조정 실행
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{!hasData ? (
|
||||
/* Empty state */
|
||||
<div className="text-center py-12 bg-white rounded-2xl border border-dashed border-slate-200">
|
||||
<div className="text-3xl mb-3">📊</div>
|
||||
<p className="text-sm font-medium text-slate-600 mb-1">아직 성과 데이터가 없습니다</p>
|
||||
<p className="text-xs text-slate-400">
|
||||
채널 분석을 2회 이상 실행하면 성과 비교 및 전략 조정이 가능합니다
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{/* Overall Assessment */}
|
||||
{overallAssessment && (
|
||||
<motion.div
|
||||
className="bg-purple-50 border border-purple-100 rounded-2xl p-4 mb-6"
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
>
|
||||
<p className="text-sm text-purple-800">{overallAssessment}</p>
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* KPI Progress */}
|
||||
{kpiProgress.length > 0 && (
|
||||
<div className="mb-8">
|
||||
<h4 className="text-sm font-bold text-[#0A1128] mb-3">KPI 달성률</h4>
|
||||
<div className="space-y-3">
|
||||
{kpiProgress.map((kpi, i) => (
|
||||
<motion.div
|
||||
key={i}
|
||||
className="bg-white rounded-xl p-4 border border-slate-100"
|
||||
initial={{ opacity: 0, x: -10 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
transition={{ delay: i * 0.05 }}
|
||||
>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-xs font-medium text-slate-600">{kpi.metric}</span>
|
||||
<span className={`text-xs font-bold ${
|
||||
kpi.progress >= 100 ? 'text-green-600' :
|
||||
kpi.progress >= 70 ? 'text-amber-600' : 'text-red-600'
|
||||
}`}>
|
||||
{kpi.progress}%
|
||||
</span>
|
||||
</div>
|
||||
<div className="w-full h-2 bg-slate-100 rounded-full overflow-hidden">
|
||||
<motion.div
|
||||
className={`h-full rounded-full ${
|
||||
kpi.progress >= 100 ? 'bg-green-400' :
|
||||
kpi.progress >= 70 ? 'bg-amber-400' : 'bg-red-400'
|
||||
}`}
|
||||
initial={{ width: 0 }}
|
||||
animate={{ width: `${Math.min(kpi.progress, 100)}%` }}
|
||||
transition={{ duration: 0.8, delay: i * 0.1 }}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-between mt-1.5 text-[10px] text-slate-400">
|
||||
<span>현재: {kpi.current}</span>
|
||||
<span>목표: {kpi.target}</span>
|
||||
</div>
|
||||
</motion.div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Strategy Suggestions */}
|
||||
{suggestions.length > 0 && (
|
||||
<div className="mb-8">
|
||||
<h4 className="text-sm font-bold text-[#0A1128] mb-3">전략 조정 제안</h4>
|
||||
<div className="space-y-3">
|
||||
{suggestions.map((s, i) => {
|
||||
const colors = priorityColors[s.priority] || priorityColors.medium;
|
||||
return (
|
||||
<motion.div
|
||||
key={i}
|
||||
className={`${colors.bg} rounded-xl p-4 border border-slate-100`}
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ delay: i * 0.08 }}
|
||||
>
|
||||
<div className="flex items-start gap-3">
|
||||
<span className={`w-2 h-2 rounded-full ${colors.dot} mt-1.5 flex-shrink-0`} />
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className={`text-xs font-bold ${colors.text}`}>
|
||||
{typeLabels[s.adjustmentType] || s.adjustmentType}
|
||||
</span>
|
||||
{s.channel && (
|
||||
<span className="text-[10px] text-slate-400 bg-white px-2 py-0.5 rounded-full">
|
||||
{s.channel}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-slate-700 mb-1">{s.description}</p>
|
||||
<p className="text-xs text-slate-500">{s.reason}</p>
|
||||
{s.beforeValue && s.afterValue && (
|
||||
<div className="flex items-center gap-2 mt-2 text-xs">
|
||||
<span className="text-slate-400 line-through">{s.beforeValue}</span>
|
||||
<span className="text-slate-400">→</span>
|
||||
<span className={`font-medium ${colors.text}`}>{s.afterValue}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Adjustment History */}
|
||||
{history.length > 0 && (
|
||||
<div>
|
||||
<h4 className="text-sm font-bold text-[#0A1128] mb-3">조정 이력</h4>
|
||||
<div className="relative border-l-2 border-slate-200 ml-2 pl-4 space-y-4">
|
||||
{history.map((item) => (
|
||||
<div key={item.id} className="relative">
|
||||
<div className="absolute -left-[21px] top-1 w-2.5 h-2.5 rounded-full bg-purple-300 border-2 border-white" />
|
||||
<div className="bg-white rounded-xl p-3 border border-slate-100">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className="text-xs font-medium text-purple-600">
|
||||
{typeLabels[item.adjustment_type] || item.adjustment_type}
|
||||
</span>
|
||||
<span className="text-[10px] text-slate-400">
|
||||
{new Date(item.created_at).toLocaleDateString('ko-KR')}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-xs text-slate-600">{item.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</SectionWrapper>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user