Skip to content

Commit 77a389c

Browse files
committed
fix: resolve hydration error about translations
1 parent fde4463 commit 77a389c

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

src/components/cards/challenge/Challenge.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Challenge } from "@/types/course";
66
import Link from "next/link";
77
import RelatedContent from "./RelatedContent";
88
import Badges from "./Badges";
9-
import { useEffect, useMemo, useState } from "react";
10-
import { useTranslation } from "react-i18next";
9+
import { useMemo } from "react";
10+
import { useTranslation } from "next-i18next";
1111

1212
/**
1313
* `ChallengeCard` is a function component that renders a card
@@ -25,16 +25,12 @@ interface ChallengeCardProps {
2525
}
2626
export default function ChallengeCard({ data, community, isCourseEnd }: ChallengeCardProps) {
2727
const { t } = useTranslation();
28-
const [prize, setPrize] = useState("");
2928

3029
const link = `/communities/${community.slug}/challenges/${data.id}`;
3130
const expiresAt = useMemo(() => (data.expiresAt ? new Date(data.expiresAt).toLocaleDateString() : null), [data.expiresAt]);
3231
const reward = isCourseEnd ? data?.rewards?.find((reward) => reward.type === "SUBMISSION") : data?.reward;
3332
const totalReward = data?.rewards?.reduce((acc, reward) => (acc += Number(reward.amount)), 0);
3433

35-
useEffect(() => {
36-
setPrize(`${community?.slug === "celo" ? "NFT" : ""} ${t("communities.overview.challenge.certificate")}`);
37-
}, [community, t]);
3834
return (
3935
<div className="border-solid border border-gray-200 bg-gray-50 rounded-3xl mb-5 group text-gray-700">
4036
<div className="border-solid border-b border-gray-300 bg-white rounded-3xl sm:p-8 sm:pb-6 w-full p-6">
@@ -51,7 +47,9 @@ export default function ChallengeCard({ data, community, isCourseEnd }: Challeng
5147
<Certificate size="medium" name={community.slug} />
5248
<div className="md:pl-2 max-w-max">
5349
<div className="flex text-sm text-gray-700">
54-
<span className="block font-medium pr-1">{prize}</span>
50+
<span className="block font-medium pr-1">
51+
{community?.slug === "celo" && "NFT"} {t("communities.overview.challenge.certificate")}
52+
</span>
5553
</div>
5654
<div className="text-gray-400 text-xs font-normal">Upon successful completion</div>
5755
</div>

src/components/cards/challenge/Overview.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React, { useEffect, useState } from "react";
21
import Coin from "@/components/ui/Coin";
32
import { Challenge, Reward } from "@/types/course";
43
import { useTranslation } from "next-i18next";
@@ -22,7 +21,6 @@ export default function Overview({ challenge, community }: Props) {
2221
const formatToken = (token: string) => {
2322
return token.charAt(0).toUpperCase() + token.slice(1).toLowerCase();
2423
};
25-
const [prize, setPrize] = useState("");
2624
// Combine rewards by token
2725
const rewardsByToken: Reward[] = challenge.rewards.reduce((acc: Reward[], reward: Reward) => {
2826
const existingReward = acc.find((item) => item.token === reward.token);
@@ -32,10 +30,6 @@ export default function Overview({ challenge, community }: Props) {
3230

3331
const expirationDate = challenge?.expiresAt && DateManager.format(challenge.expiresAt, "MMMM d, yyyy", "en");
3432

35-
useEffect(() => {
36-
setPrize(`${community.slug === "celo" ? "NFT" : ""} ${t("communities.overview.challenge.certificate")}`);
37-
}, [community, t]);
38-
3933
return (
4034
<div className="border border-gray-200 rounded-3xl mb-5 group text-gray-700 p-6">
4135
<div className="text-gray-900 text-lg leading-normal">
@@ -47,7 +41,9 @@ export default function Overview({ challenge, community }: Props) {
4741
<Certificate size="medium" name={community.slug} />
4842
<div className="md:pl-2 max-w-max">
4943
<div className="flex text-sm text-gray-700">
50-
<span className="block font-medium pr-1">{prize}</span>
44+
<span className="block font-medium pr-1">
45+
{community?.slug === "celo" && "NFT"} {t("communities.overview.challenge.certificate")}
46+
</span>
5147
</div>
5248
<div className="text-gray-400 text-xs font-medium">{t("communities.overview.challenge.subtitle")}</div>
5349
</div>

src/pages/communities/[slug]/courses/[course_slug]/learning-modules/[id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import ChallengeOverviewCard from "@/components/cards/challenge/Overview";
1717
import LearningModuleSection from "@/components/sections/learning-modules";
1818
import useNavigation from "@/hooks/useNavigation";
1919
import ChallengeCard from "@/components/cards/challenge/Challenge";
20-
import { useTranslation } from "react-i18next";
20+
import { useTranslation } from "next-i18next";
2121
import PageNavigation from "@/components/sections/courses/PageNavigation";
2222
import { NotFoundError } from "@/utilities/errors/NotFoundError";
2323

0 commit comments

Comments
 (0)