// js/components/LandingPage.jsx // 랜딩 페이지 + 제품 정보 입력 폼 window.LandingPage = function({ onStart }) { const { useState, useCallback } = React; const helpers = window.PCODE_HELPERS; const [formData, setFormData] = useState({ productName: '', category: '', price: '', productLink: '' }); const [errors, setErrors] = useState({}); const [touched, setTouched] = useState({}); // 유효성 검사 const validate = useCallback((data) => { const newErrors = {}; if (!data.productName.trim()) { newErrors.productName = '제품명을 입력해주세요.'; } else if (data.productName.trim().length > 50) { newErrors.productName = '제품명은 50자 이내로 입력해주세요.'; } if (!data.category) { newErrors.category = '카테고리를 선택해주세요.'; } if (!data.price) { newErrors.price = '가격을 입력해주세요.'; } else if (Number(data.price) <= 0) { newErrors.price = '유효한 가격을 입력해주세요.'; } if (data.productLink && !helpers.isValidUrl(data.productLink)) { newErrors.productLink = '유효한 URL 형식으로 입력해주세요. (예: https://...)'; } return newErrors; }, [helpers]); // 폼이 유효한지 확인 const isFormValid = useCallback(() => { const errs = validate(formData); return Object.keys(errs).length === 0; }, [formData, validate]); // 입력 변경 핸들러 const handleChange = useCallback((field, value) => { const newData = { ...formData, [field]: value }; setFormData(newData); if (touched[field]) { const newErrors = validate(newData); setErrors(prev => ({ ...prev, [field]: newErrors[field] || null })); } }, [formData, touched, validate]); // 블러 핸들러 const handleBlur = useCallback((field) => { setTouched(prev => ({ ...prev, [field]: true })); const newErrors = validate(formData); setErrors(prev => ({ ...prev, [field]: newErrors[field] || null })); }, [formData, validate]); // 폼 제출 const handleSubmit = useCallback((e) => { e.preventDefault(); // 모든 필드 터치 표시 setTouched({ productName: true, category: true, price: true, productLink: true }); const validationErrors = validate(formData); setErrors(validationErrors); if (Object.keys(validationErrors).length === 0) { onStart(formData); } }, [formData, validate, onStart]); // 최근 결과 불러오기 const recentResults = helpers.storage.getResults().slice(0, 3); return (
제품의 MBTI를 만나세요
P-CODE는 제품의 성향을 분석해주는 16가지 유형 진단 시스템입니다.
당신의 제품이 어떤 성격을 지녔는지 알아보세요.
{item.desc}
{item.name}
진단을 시작하기 전에 제품 기본 정보를 입력해주세요