diff --git a/src/pages/saju/components/ActionCard.jsx b/src/pages/saju/components/ActionCard.jsx new file mode 100644 index 0000000..74965ae --- /dev/null +++ b/src/pages/saju/components/ActionCard.jsx @@ -0,0 +1,28 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; + +const ICON = { + today: 'β', + heart: 'β₯', + book: 'π', +}; + +export default function ActionCard({ to, icon, title, desc, variant = 'saju', disabled = false }) { + const cls = `saju-action-card saju-action-card--${variant}`; + if (disabled) { + return ( + + {ICON[icon] || 'β¦'} + {title} + {desc || 'μ€λΉ μ€'} + + ); + } + return ( + + {ICON[icon] || 'β¦'} + {title} + {desc} + + ); +} diff --git a/src/pages/saju/components/SajuInputForm.jsx b/src/pages/saju/components/SajuInputForm.jsx new file mode 100644 index 0000000..a3bf0ec --- /dev/null +++ b/src/pages/saju/components/SajuInputForm.jsx @@ -0,0 +1,42 @@ +import React from 'react'; + +export default function SajuInputForm({ form, onChange, onSubmit, loading, error }) { + return ( +
+ ); +} diff --git a/src/pages/saju/hooks/useSajuForm.js b/src/pages/saju/hooks/useSajuForm.js new file mode 100644 index 0000000..86f276b --- /dev/null +++ b/src/pages/saju/hooks/useSajuForm.js @@ -0,0 +1,64 @@ +import { useState, useCallback } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { sajuInterpret } from '../../../api'; + +const INITIAL_FORM = { + name: '', + year: '', + month: '', + day: '', + hour: '', + gender: 'male', + calendar_type: 'solar', +}; + +export default function useSajuForm() { + const [form, setForm] = useState(INITIAL_FORM); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + const navigate = useNavigate(); + + const handleChange = useCallback((field, value) => { + setForm((prev) => ({ ...prev, [field]: value })); + }, []); + + const handleSubmit = useCallback(async (e) => { + if (e?.preventDefault) e.preventDefault(); + setError(null); + + if (!form.year || !form.month || !form.day) { + setError('μλ μμΌμ λͺ¨λ μ λ ₯ν΄μ£ΌμΈμ.'); + return; + } + const year = parseInt(form.year, 10); + const month = parseInt(form.month, 10); + const day = parseInt(form.day, 10); + if (year < 1900 || year > 2100 || month < 1 || month > 12 || day < 1 || day > 31) { + setError('μ¬λ°λ₯Έ μλ μμΌμ μ λ ₯ν΄μ£ΌμΈμ.'); + return; + } + + setLoading(true); + try { + const body = { + year, + month, + day, + gender: form.gender, + calendar_type: form.calendar_type, + }; + if (form.hour !== '') { + body.hour = parseInt(form.hour, 10); + } + const result = await sajuInterpret(body); + navigate(`/saju/result?rid=${result.reading_id}`); + } catch (err) { + console.error('μ¬μ£Ό λΆμ μ€ν¨', err); + setError(err.message || 'μ μ ν λ€μ μλν΄μ£ΌμΈμ.'); + } finally { + setLoading(false); + } + }, [form, navigate]); + + return { form, handleChange, handleSubmit, loading, error }; +}