From 50639d7e919e4fcfc8e27e2ae0ddad4f772eaa2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20de=20Vasconcelos?= Date: Fri, 10 Jan 2025 22:56:13 +0000 Subject: [PATCH] Enhance Review2024 quiz final result: calculate total points, define point tiers, and update translations for feedback messages. Adjust points prop in Review2024QuizWrapper for testing. --- .../Review2024QuizFinalResult/index.tsx | 22 +++++++++++++--- .../Review2024QuizWrapper/index.tsx | 2 +- frontend/components/review-2024/_data/quiz.ts | 2 +- frontend/i18n/translations/pt.json | 25 ++++++++++++++++++- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/frontend/components/review-2024/Review2024QuizFinalResult/index.tsx b/frontend/components/review-2024/Review2024QuizFinalResult/index.tsx index a4937614..dbdc02d5 100644 --- a/frontend/components/review-2024/Review2024QuizFinalResult/index.tsx +++ b/frontend/components/review-2024/Review2024QuizFinalResult/index.tsx @@ -3,9 +3,9 @@ /* * */ import { LottiePlayer } from '@/components/common/LottiePlayer'; -import { allQuizData } from '@/components/review-2024/_data/quiz'; import { useTranslations } from 'next-intl'; +import { allQuizData } from '../_data/quiz'; import styles from './styles.module.css'; /* * */ @@ -24,6 +24,22 @@ export function Review2024QuizFinalResult({ points }: Props) { const t = useTranslations('review-2024.Review2024QuizFinalResult'); + // + // B. Transform data + + const totalPoints = allQuizData.reduce((acc, quiz) => acc + quiz._points, 0); + + const pointTiers = [ + { _id: 'terrible', value: totalPoints * 0.2 }, + { _id: 'bad', value: totalPoints * 0.4 }, + { _id: 'acceptable', value: totalPoints * 0.6 }, + { _id: 'very_good', value: totalPoints * 0.8 }, + { _id: 'incredible', value: totalPoints - 1 }, + { _id: 'perfect', value: totalPoints }, + ]; + + const pointTier = pointTiers.find(tier => tier.value >= points) || pointTiers[0]; + // // C. Render components @@ -34,9 +50,9 @@ export function Review2024QuizFinalResult({ points }: Props) { -

Parabéns!

+

{t(`${pointTier._id}.title`)}

-

{t('points', { points: points, total: allQuizData.length })}

+

{t(`${pointTier._id}.subtitle`, { points: points })}

); diff --git a/frontend/components/review-2024/Review2024QuizWrapper/index.tsx b/frontend/components/review-2024/Review2024QuizWrapper/index.tsx index 57403c00..126b5c88 100644 --- a/frontend/components/review-2024/Review2024QuizWrapper/index.tsx +++ b/frontend/components/review-2024/Review2024QuizWrapper/index.tsx @@ -61,7 +61,7 @@ export function Review2024QuizWrapper({ answerStatus, points, progress, setAnswe return (
- +
); diff --git a/frontend/components/review-2024/_data/quiz.ts b/frontend/components/review-2024/_data/quiz.ts index d0ba04ce..105c9a59 100644 --- a/frontend/components/review-2024/_data/quiz.ts +++ b/frontend/components/review-2024/_data/quiz.ts @@ -8,7 +8,7 @@ export interface Review2024QuizAnswerSchema { export interface Review2024QuizSchema { _id: string - _points?: number + _points: number answers: Review2024QuizAnswerSchema[] colors: { border?: string diff --git a/frontend/i18n/translations/pt.json b/frontend/i18n/translations/pt.json index 7d1eab16..2f410d15 100644 --- a/frontend/i18n/translations/pt.json +++ b/frontend/i18n/translations/pt.json @@ -1203,7 +1203,30 @@ } }, "Review2024QuizFinalResult": { - "points": "Já tens {points, plural, =1 {# ponto} other {# pontos}}!" + "acceptable": { + "subtitle": "{points, plural, =1 {Ganhaste só # ponto...} other {Ganhaste só # pontos...}}!", + "title": "Aceitável" + }, + "bad": { + "subtitle": "{points, plural, =1 {Ganhaste só # ponto...} other {Ganhaste só # pontos...}}!", + "title": "Não muito bom..." + }, + "incredible": { + "subtitle": "{points, plural, =1 {Ganhaste só # ponto...} other {Ganhaste só # pontos...}}!", + "title": "Incrível!" + }, + "perfect": { + "subtitle": "{points, plural, =1 {Ganhaste só # ponto...} other {Ganhaste só # pontos...}}!", + "title": "Uau. Perfeito. Sem falhas." + }, + "terrible": { + "subtitle": "{points, plural, =1 {Ganhaste só # ponto...} other {Ganhaste só # pontos...}}!", + "title": "Terrível..." + }, + "very_good": { + "subtitle": "{points, plural, =1 {Ganhaste só # ponto...} other {Ganhaste só # pontos...}}!", + "title": "Boa!" + } }, "Review2024QuizPoints": { "points": "{points, plural, =0 {Joga para ganhar pontos!} =1 {Já tens # ponto} other {Já tens # pontos}}"