mirror of
https://github.com/ktds-dg0501/kt-event-marketing-fe.git
synced 2025-12-06 10:16:25 +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 {
|
export interface EventData {
|
||||||
eventDraftId?: number;
|
eventDraftId?: number;
|
||||||
|
eventId?: string;
|
||||||
objective?: EventObjective;
|
objective?: EventObjective;
|
||||||
recommendation?: {
|
recommendation?: {
|
||||||
recommendation: {
|
recommendation: {
|
||||||
@ -95,14 +96,15 @@ export default function EventCreatePage() {
|
|||||||
<funnel.Render
|
<funnel.Render
|
||||||
objective={({ history }) => (
|
objective={({ history }) => (
|
||||||
<ObjectiveStep
|
<ObjectiveStep
|
||||||
onNext={(objective) => {
|
onNext={({ objective, eventId }) => {
|
||||||
history.push('recommendation', { objective });
|
history.push('recommendation', { objective, eventId });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
recommendation={({ context, history }) => (
|
recommendation={({ context, history }) => (
|
||||||
<RecommendationStep
|
<RecommendationStep
|
||||||
objective={context.objective}
|
objective={context.objective}
|
||||||
|
eventId={context.eventId}
|
||||||
onNext={(recommendation) => {
|
onNext={(recommendation) => {
|
||||||
history.push('channel', { ...context, recommendation });
|
history.push('channel', { ...context, recommendation });
|
||||||
}}
|
}}
|
||||||
|
|||||||
@ -67,15 +67,34 @@ const objectives: ObjectiveOption[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
interface ObjectiveStepProps {
|
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) {
|
export default function ObjectiveStep({ onNext }: ObjectiveStepProps) {
|
||||||
const [selected, setSelected] = useState<EventObjective | null>(null);
|
const [selected, setSelected] = useState<EventObjective | null>(null);
|
||||||
|
|
||||||
const handleNext = () => {
|
const handleNext = () => {
|
||||||
if (selected) {
|
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 추천 요청
|
// 컴포넌트 마운트 시 AI 추천 요청
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!eventId && objective) {
|
if (initialEventId) {
|
||||||
// Step 1: 이벤트 생성
|
// eventId가 있으면 바로 AI 추천 요청
|
||||||
createEventAndRequestAI();
|
requestAIRecommendations(initialEventId);
|
||||||
} else if (eventId) {
|
} else {
|
||||||
// 이미 eventId가 있으면 AI 추천 요청
|
setError('이벤트 ID가 없습니다');
|
||||||
requestAIRecommendations(eventId);
|
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
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) => {
|
const requestAIRecommendations = async (evtId: string) => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -289,10 +269,10 @@ export default function RecommendationStep({
|
|||||||
size="large"
|
size="large"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setError(null);
|
setError(null);
|
||||||
if (eventId) {
|
if (initialEventId) {
|
||||||
requestAIRecommendations(eventId);
|
requestAIRecommendations(initialEventId);
|
||||||
} else {
|
} else {
|
||||||
createEventAndRequestAI();
|
setError('이벤트 ID가 없습니다. 이전 단계로 돌아가서 다시 시도하세요.');
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user