// ============================================================ // FINAFAMILY — Receitas Screen // ============================================================ const { useState, useMemo, useEffect } = React; function IncomeForm({ onClose, onSave, initialValues }) { const { members, currentMember, incomeSources } = useApp(); const today = todayLocalISO(); const sources = (incomeSources && incomeSources.length) ? incomeSources : [ { key: 'salary', label: 'Salário' }, { key: 'freelance', label: 'Freelance' }, { key: 'passive', label: 'Renda Passiva' }, { key: 'rent', label: 'Aluguel' }, { key: 'other', label: 'Outros' }, ]; const defaultSource = sources[0]?.key || 'salary'; const isEditing = !!initialValues; const [form, setForm] = useState(() => initialValues ? { ...initialValues, value: String(initialValues.value ?? ''), status: initialValues.status || 'expected', } : { desc: '', value: '', date: today, memberId: currentMember?.id || '', source: defaultSource, recurrence: 'monthly', status: 'expected', }); const [errors, setErrors] = useState({}); function set(k, v) { setForm(f => ({ ...f, [k]: v })); } function handleSave() { const e = {}; if (!form.desc || !form.desc.trim()) e.desc = 'Descrição obrigatória'; const val = parseFloat(String(form.value).replace(',', '.')); if (!form.value || isNaN(val) || val <= 0) e.value = 'Informe um valor válido'; if (Object.keys(e).length) { setErrors(e); return; } const memberId = form.memberId || currentMember?.id; onSave({ ...form, value: val, memberId, id: initialValues?.id }); onClose(); } return (
Mês de referência: {['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'][currentMonth.month - 1]} {currentMonth.year}
As {expectedIncomes.length} receita{expectedIncomes.length !== 1 ? 's' : ''} prevista{expectedIncomes.length !== 1 ? 's' : ''} deste mês serão marcadas como recebidas.