Browse Source

feat(debug): add comprehensive logging for number inputs, answers, and progress tracker

master
mortezaei 2 days ago
parent
commit
47f884517d
  1. 6
      src/app/questions-list/[slug]/question-detail-client.tsx
  2. 23
      src/components/Componentes/question-number.tsx
  3. 3
      src/components/Componentes/question-progress-tracker.tsx

6
src/app/questions-list/[slug]/question-detail-client.tsx

@ -205,6 +205,12 @@ function QuestionFlowWrapper({
}
}
if (question.type === "number") {
console.log(
`[DETAIL_LOG] id=${question.id}, answer=${JSON.stringify(answer)}, hasAnswer=${hasAnswer}, isAnswered=${isAnswered}`,
);
}
return (
<div
key={question.id}

23
src/components/Componentes/question-number.tsx

@ -80,10 +80,19 @@ export default function QuestionNumber({
useEffect(() => {
if (typeof value === "string" && value.length > 0) {
const normalized = normalizeNumberString(value);
console.log(
`[NUM_LOG] useEffect normalize: id=${question.id}, value="${value}", normalized="${normalized}"`,
);
if (!NUMBER_INPUT_PATTERN.test(normalized)) {
console.log(
`[NUM_LOG] useEffect clearing invalid value: id=${question.id}, value="${value}"`,
);
setAnswerValue(question, null);
} else if (normalized !== value) {
const parsed = parseFloat(normalized);
console.log(
`[NUM_LOG] useEffect updating normalized: id=${question.id}, parsed=${parsed}`,
);
setAnswerValue(
question,
Number.isNaN(parsed) ? normalized : parsed,
@ -113,6 +122,10 @@ export default function QuestionNumber({
? normalizedRaw
: "";
console.log(
`[NUM_LOG] Render: id=${question.id}, value=${JSON.stringify(value)}, inputValue="${inputValue}", isOutOfRange=${isOutOfRange}`,
);
const isMonthlyIncome = question.ui_config?.currency_enabled === true;
const currencyStorageKey =
question.ui_config?.currency_storage_key || "marriage:income:currency";
@ -324,16 +337,26 @@ export default function QuestionNumber({
const normalized = normalizeNumberString(raw);
const cleaned = normalized.replace(/[^0-9.-]/g, "");
console.log(
`[NUM_LOG] onChange: id=${question.id}, raw="${raw}", normalized="${normalized}", cleaned="${cleaned}"`,
);
if (cleaned === "" || cleaned === "-") {
console.log(`[NUM_LOG] onChange clearing value (empty)`);
setAnswerValue(question, null);
return;
}
if (!NUMBER_INPUT_PATTERN.test(cleaned)) {
console.log(`[NUM_LOG] onChange rejected pattern: "${cleaned}"`);
return;
}
const parsed = parseFloat(cleaned);
console.log(
`[NUM_LOG] onChange calling setAnswerValue with:`,
Number.isNaN(parsed) ? cleaned : parsed,
);
setAnswerValue(
question,
Number.isNaN(parsed) ? cleaned : parsed,

3
src/components/Componentes/question-progress-tracker.tsx

@ -130,6 +130,9 @@ export function QuestionProgressTracker({
setTotal(nextTotal);
setAnswered(nextAnswered);
console.log(
`[PROG_LOG] updateProgress: answered=${nextAnswered}/${nextTotal}, passedIndexes=[${Array.from(passedQuestionIndexes).join(",")}]`,
);
}, [passedQuestionIndexes]);
useEffect(() => {

Loading…
Cancel
Save