mirror of
https://github.com/ktds-dg0501/kt-event-marketing-fe.git
synced 2025-12-06 06:56:24 +00:00
eventId 생성 로직을 프론트엔드로 이동 및 쿠키 저장
- ObjectiveStep에서 eventId 생성 및 쿠키 저장 - page.tsx에서 eventId를 context로 전달 - RecommendationStep에서 이벤트 생성 API 호출 제거 - eventId를 props로 받아 바로 AI 추천 요청 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
f414e1e1dd
commit
d02cfaa5fc
@ -16,6 +16,7 @@ export type EventMethod = 'online' | 'offline';
|
||||
|
||||
export interface EventData {
|
||||
eventDraftId?: number;
|
||||
eventId?: string;
|
||||
objective?: EventObjective;
|
||||
recommendation?: {
|
||||
recommendation: {
|
||||
@ -95,14 +96,15 @@ export default function EventCreatePage() {
|
||||
<funnel.Render
|
||||
objective={({ history }) => (
|
||||
<ObjectiveStep
|
||||
onNext={(objective) => {
|
||||
history.push('recommendation', { objective });
|
||||
onNext={({ objective, eventId }) => {
|
||||
history.push('recommendation', { objective, eventId });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
recommendation={({ context, history }) => (
|
||||
<RecommendationStep
|
||||
objective={context.objective}
|
||||
eventId={context.eventId}
|
||||
onNext={(recommendation) => {
|
||||
history.push('channel', { ...context, recommendation });
|
||||
}}
|
||||
|
||||
@ -67,15 +67,34 @@ const objectives: ObjectiveOption[] = [
|
||||
];
|
||||
|
||||
interface ObjectiveStepProps {
|
||||
onNext: (objective: EventObjective) => void;
|
||||
onNext: (data: { objective: EventObjective; eventId: string }) => void;
|
||||
}
|
||||
|
||||
// eventId 생성 함수
|
||||
const generateEventId = () => {
|
||||
return `evt_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
||||
};
|
||||
|
||||
// 쿠키 저장 함수
|
||||
const setCookie = (name: string, value: string, days: number = 1) => {
|
||||
const expires = new Date();
|
||||
expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
document.cookie = `${name}=${value};expires=${expires.toUTCString()};path=/`;
|
||||
};
|
||||
|
||||
export default function ObjectiveStep({ onNext }: ObjectiveStepProps) {
|
||||
const [selected, setSelected] = useState<EventObjective | null>(null);
|
||||
|
||||
const handleNext = () => {
|
||||
if (selected) {
|
||||
onNext(selected);
|
||||
// eventId 생성
|
||||
const eventId = generateEventId();
|
||||
|
||||
// 쿠키에 저장
|
||||
setCookie('eventId', eventId, 1); // 1일 동안 유지
|
||||
|
||||
// objective와 eventId를 함께 전달
|
||||
onNext({ objective: selected, eventId });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -68,34 +68,14 @@ export default function RecommendationStep({
|
||||
|
||||
// 컴포넌트 마운트 시 AI 추천 요청
|
||||
useEffect(() => {
|
||||
if (!eventId && objective) {
|
||||
// Step 1: 이벤트 생성
|
||||
createEventAndRequestAI();
|
||||
} else if (eventId) {
|
||||
// 이미 eventId가 있으면 AI 추천 요청
|
||||
requestAIRecommendations(eventId);
|
||||
if (initialEventId) {
|
||||
// eventId가 있으면 바로 AI 추천 요청
|
||||
requestAIRecommendations(initialEventId);
|
||||
} else {
|
||||
setError('이벤트 ID가 없습니다');
|
||||
}
|
||||
}, []);
|
||||
|
||||
const createEventAndRequestAI = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
// Step 1: 이벤트 목적 선택 및 생성
|
||||
const eventResponse = await eventApi.selectObjective(objective || '신규 고객 유치');
|
||||
const newEventId = eventResponse.eventId;
|
||||
setEventId(newEventId);
|
||||
|
||||
// Step 2: AI 추천 요청
|
||||
await requestAIRecommendations(newEventId);
|
||||
} catch (err: any) {
|
||||
console.error('이벤트 생성 실패:', err);
|
||||
setError(err.response?.data?.message || '이벤트 생성에 실패했습니다');
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const requestAIRecommendations = async (evtId: string) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
@ -289,10 +269,10 @@ export default function RecommendationStep({
|
||||
size="large"
|
||||
onClick={() => {
|
||||
setError(null);
|
||||
if (eventId) {
|
||||
requestAIRecommendations(eventId);
|
||||
if (initialEventId) {
|
||||
requestAIRecommendations(initialEventId);
|
||||
} else {
|
||||
createEventAndRequestAI();
|
||||
setError('이벤트 ID가 없습니다. 이전 단계로 돌아가서 다시 시도하세요.');
|
||||
}
|
||||
}}
|
||||
sx={{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user