From ba5cb3c18e7c20da9e720fbd25703b2ef9487485 Mon Sep 17 00:00:00 2001 From: igorntwari Date: Wed, 10 Jul 2024 17:20:18 +0200 Subject: [PATCH 01/21] test: add partial challenge tests --- .../cards/challenge/_partials/Button.test.tsx | 68 +++++++++++++++++ .../challenge/_partials/FormTeam.test.tsx | 36 +++++++++ .../_partials/InvatationButtom.test.tsx | 51 +++++++++++++ .../challenge/_partials/Learning.test.tsx | 44 +++++++++++ .../_partials/ReplyToInvitation.test.tsx | 73 +++++++++++++++++++ .../cards/challenge/_partials/Reward.test.tsx | 52 +++++++++++++ .../cards/challenge/_partials/Button.tsx | 12 ++- .../cards/challenge/_partials/FormTeam.tsx | 2 +- .../challenge/_partials/InvitationButton.tsx | 3 +- .../cards/challenge/_partials/Learning.tsx | 10 ++- .../challenge/_partials/ReplyToInvitation.tsx | 2 +- .../cards/challenge/_partials/Reward.tsx | 2 +- 12 files changed, 343 insertions(+), 12 deletions(-) create mode 100644 __tests__/components/cards/challenge/_partials/Button.test.tsx create mode 100644 __tests__/components/cards/challenge/_partials/FormTeam.test.tsx create mode 100644 __tests__/components/cards/challenge/_partials/InvatationButtom.test.tsx create mode 100644 __tests__/components/cards/challenge/_partials/Learning.test.tsx create mode 100644 __tests__/components/cards/challenge/_partials/ReplyToInvitation.test.tsx create mode 100644 __tests__/components/cards/challenge/_partials/Reward.test.tsx diff --git a/__tests__/components/cards/challenge/_partials/Button.test.tsx b/__tests__/components/cards/challenge/_partials/Button.test.tsx new file mode 100644 index 00000000..fbdb2c86 --- /dev/null +++ b/__tests__/components/cards/challenge/_partials/Button.test.tsx @@ -0,0 +1,68 @@ +import Button, { ButtonProps } from "@/components/cards/challenge/_partials/Button"; +import { renderWithRedux } from "@__mocks__/renderWithRedux"; +import "@testing-library/jest-dom"; +import { screen, fireEvent } from '@testing-library/react'; +import { useRouter } from 'next/router'; + +jest.mock("next/router", () => ({ + useRouter: jest.fn(), +})); + +const mockPush = jest.fn(); + +(useRouter as jest.Mock).mockReturnValue({ + push: mockPush, + events: { + on: jest.fn(), + off: jest.fn(), + emit: jest.fn(), + }, + isFallback: false, +}); + +const buttonProps: ButtonProps = { + text: "Test Button", + onClick: jest.fn(), + loading: true, +}; + +function RenderButton(props: ButtonProps = buttonProps) { + renderWithRedux( + - - - + return ( +
+
+

{t("page.index.communities.partnering.title")}

+

{t("page.index.communities.partnering.subtitle")}

+
+
+
+
{t("partnering.card.text")}
- ); - +
+ + + +
+
+
+ ); } diff --git a/src/components/cards/Reputation.tsx b/src/components/cards/Reputation.tsx index 365c38ee..2a29e855 100644 --- a/src/components/cards/Reputation.tsx +++ b/src/components/cards/Reputation.tsx @@ -41,7 +41,10 @@ export default function ReputationCard({ details = {} }: ReputationCardProps): R useLink={false} /> {details?.score && ( - + diff --git a/src/components/cards/Submission.tsx b/src/components/cards/Submission.tsx index 30493099..0cb48e84 100644 --- a/src/components/cards/Submission.tsx +++ b/src/components/cards/Submission.tsx @@ -23,7 +23,7 @@ interface SubmissionCardProps { date: string; }; children?: ReactNode; - testId?:string; + testId?: string; } /** diff --git a/src/components/cards/TranslationBox.tsx b/src/components/cards/TranslationBox.tsx index f6e2b831..0b69a629 100755 --- a/src/components/cards/TranslationBox.tsx +++ b/src/components/cards/TranslationBox.tsx @@ -66,7 +66,7 @@ export default function TranslationBox({ text, defaultLocale, disabled, textCont const [locale, setLocale] = useState(""); const [loading, setLoading] = useState(false); const [description, setDescription] = useState(""); - const [reverted, setReverted] =useState(false) + const [reverted, setReverted] = useState(false); const { t } = useTranslation(); const router = useRouter(); @@ -102,7 +102,7 @@ export default function TranslationBox({ text, defaultLocale, disabled, textCont } setLoading(false); - setReverted(false) + setReverted(false); }, [getDefaultLocale, text]); /** @@ -122,9 +122,9 @@ export default function TranslationBox({ text, defaultLocale, disabled, textCont useEffect(() => { setDescription(translated ? t("ui.translated") : t("ui.translate")); - if(!translated && !reverted){ - translate() - } + if (!translated && !reverted) { + translate(); + } }, [translated]); const translatable = currentLocale !== defaultLocale && !disabled && getLocaleName(defaultLocale); diff --git a/src/components/cards/User.tsx b/src/components/cards/User.tsx index 67e5a9ab..d2aa0314 100644 --- a/src/components/cards/User.tsx +++ b/src/components/cards/User.tsx @@ -33,7 +33,7 @@ interface UserProps { submission?: Submission; teamMembers?: User[]; onClick?: () => void; - testId?: string + testId?: string; } /** @@ -52,7 +52,20 @@ interface UserProps { } * @returns {ReactElement} */ -export default function UserCard({ boxLayout, link, bordered, expanded, user, badge = "", timestamp, children, className, teamMembers, onClick, testId = "userId" }: UserProps): ReactElement { +export default function UserCard({ + boxLayout, + link, + bordered, + expanded, + user, + badge = "", + timestamp, + children, + className, + teamMembers, + onClick, + testId = "userId", +}: UserProps): ReactElement { const { locale, push } = useRouter(); const colors = useSelector((state) => state.ui.colors); @@ -77,7 +90,7 @@ export default function UserCard({ boxLayout, link, bordered, expanded, user, ba "pl-5 sm:pl-7.5": !boxLayout, "cursor-pointer": link, }); - console.log("this is the user test id", testId) + console.log("this is the user test id", testId); return (
@@ -105,8 +118,9 @@ export default function UserCard({ boxLayout, link, bordered, expanded, user, ba )}
diff --git a/src/components/cards/challenge/Challenge.tsx b/src/components/cards/challenge/Challenge.tsx index 9ee46249..71b82de5 100644 --- a/src/components/cards/challenge/Challenge.tsx +++ b/src/components/cards/challenge/Challenge.tsx @@ -23,7 +23,7 @@ export interface ChallengeCardProps { isCourseEnd?: boolean; testId?: string; } -export default function ChallengeCard({ data, community, isCourseEnd, testId ='challenge-card' }: ChallengeCardProps) { +export default function ChallengeCard({ data, community, isCourseEnd, testId = "challenge-card" }: ChallengeCardProps) { const { t } = useTranslation(); const link = `/communities/${community.slug}/challenges/${data.id}`; const expiresAt = useMemo(() => (data.expiresAt ? new Date(data.expiresAt).toLocaleDateString() : null), [data.expiresAt]); @@ -52,8 +52,9 @@ export default function ChallengeCard({ data, community, isCourseEnd, testId ='c
{learningMaterialsCount && ( -

{`${learningMaterialsCount} Learning ${learningMaterialsCount === 1 ? "material" : "materials" - } included`}

+

{`${learningMaterialsCount} Learning ${ + learningMaterialsCount === 1 ? "material" : "materials" + } included`}

)}
diff --git a/src/components/cards/challenge/ConfirmTeamInvitation.tsx b/src/components/cards/challenge/ConfirmTeamInvitation.tsx index 0b821527..4d39d05f 100644 --- a/src/components/cards/challenge/ConfirmTeamInvitation.tsx +++ b/src/components/cards/challenge/ConfirmTeamInvitation.tsx @@ -14,7 +14,7 @@ export interface ConfirmTeamInvitationProps { title: string; text: string; invite: Invite; - testId?: string + testId?: string; } /** @@ -25,11 +25,9 @@ export interface ConfirmTeamInvitationProps { * @param {ConfirmTeamInvitationProps} { index, title, text, invites } * @returns {ReactElement} */ -export default function ConfirmTeamInvitation({ index, title, text, invite,testId = 'confirmTeamInvitation' }: ConfirmTeamInvitationProps): ReactElement { +export default function ConfirmTeamInvitation({ index, title, text, invite, testId = "confirmTeamInvitation" }: ConfirmTeamInvitationProps): ReactElement { return ( -
+
diff --git a/src/components/cards/challenge/Overview.tsx b/src/components/cards/challenge/Overview.tsx index 9f6468dd..c6336062 100644 --- a/src/components/cards/challenge/Overview.tsx +++ b/src/components/cards/challenge/Overview.tsx @@ -55,7 +55,7 @@ export default function Overview({ challenge, community }: Props) {
{shortenNumber(reward.amount)} - {reward?.fiatCurrency ? `${reward?.fiatCurrency} in` : ''} + {reward?.fiatCurrency ? `${reward?.fiatCurrency} in` : ""} {reward?.token} {t("communities.overview.challenge.rewards")}
diff --git a/src/components/cards/challenge/_partials/Button.tsx b/src/components/cards/challenge/_partials/Button.tsx index 780bc9bc..5e3adbaf 100644 --- a/src/components/cards/challenge/_partials/Button.tsx +++ b/src/components/cards/challenge/_partials/Button.tsx @@ -6,10 +6,10 @@ export interface ButtonProps { text: string; onClick: () => void; loading: boolean; - buttonTestId?: string; + testId?: string; } -export default function Button({ text, onClick, loading, buttonTestId }: ButtonProps) { +export default function Button({ text, onClick, loading, testId }: ButtonProps) { const [isTextVisible, setIsTextVisible] = useState(false); return (
setIsTextVisible(true)} onMouseLeave={() => setIsTextVisible(false)} onClick={onClick} - data-testid={buttonTestId} + data-testid={testId} > <> {loading ? ( diff --git a/src/components/cards/challenge/_partials/InvitationButton.tsx b/src/components/cards/challenge/_partials/InvitationButton.tsx index 78fb01aa..08f944d5 100644 --- a/src/components/cards/challenge/_partials/InvitationButton.tsx +++ b/src/components/cards/challenge/_partials/InvitationButton.tsx @@ -13,7 +13,7 @@ import CheckIcon from "@/icons/check.svg"; export interface InvitationButtonProps { text: "accept" | "decline"; confirmInvitation: (text: "accept" | "decline") => void; - testId?: string + testId?: string; } /** @@ -24,7 +24,7 @@ export interface InvitationButtonProps { * @param {InvitationButtonProps} { text } * @returns {ReactElement} */ -export default function InvitationButton({ text, confirmInvitation,testId}: InvitationButtonProps): ReactElement { +export default function InvitationButton({ text, confirmInvitation, testId }: InvitationButtonProps): ReactElement { const buttonClassNames = classNames(`flex items-center bg-white border text-sm px-3 py-1 gap-2`, { "text-green-700 border-green-700": text === "accept", "text-red-700 border-red-700": text === "decline", diff --git a/src/components/cards/challenge/_partials/ReplyToInvitation.tsx b/src/components/cards/challenge/_partials/ReplyToInvitation.tsx index 2d125138..4270ee81 100644 --- a/src/components/cards/challenge/_partials/ReplyToInvitation.tsx +++ b/src/components/cards/challenge/_partials/ReplyToInvitation.tsx @@ -16,10 +16,10 @@ interface MultiSelector { export interface InvitationProps { invite_id: string; team_ref: string; - testId?: string + testId?: string; } -export default function ReplyToInvitation({ invite_id, team_ref,testId = 'reply-to-invitation' }: InvitationProps) { +export default function ReplyToInvitation({ invite_id, team_ref, testId = "reply-to-invitation" }: InvitationProps) { const dispatch = useDispatch(); const [loading, setLoading] = useState(false); const [canReply, setCanReply] = useState(false); diff --git a/src/components/cards/course/index.tsx b/src/components/cards/course/index.tsx index 30e817ac..e10f60a5 100644 --- a/src/components/cards/course/index.tsx +++ b/src/components/cards/course/index.tsx @@ -6,8 +6,6 @@ import { DurationBadge } from "@/components/badges/Duration"; import { useTranslation } from "next-i18next"; import { useSelector } from "@/hooks/useTypedSelector"; - - interface CourseCardProps { title: string; description: string; @@ -33,9 +31,7 @@ export default function CourseCard({ title, description, link, level, learningMo
- - {t('communities.overview.challenge.course')} - + {t("communities.overview.challenge.course")}
diff --git a/src/components/cards/profile/Referral.tsx b/src/components/cards/profile/Referral.tsx index fbbc44a6..07884b50 100644 --- a/src/components/cards/profile/Referral.tsx +++ b/src/components/cards/profile/Referral.tsx @@ -30,13 +30,13 @@ export default function Referral({ referral }: ReferralProps): ReactElement { const joinedAt = useMemo(() => DateManager.fromNow(referral.created_at, locale), [locale, referral.created_at]); const rewardAt = useMemo(() => (referral.rewarded ? DateManager.fromNow(referral.updated_at, locale) : null), [locale, referral.rewarded, referral.updated_at]); const status = (evaluation: Evaluation) => { - if (!evaluation) return t("referrals.challenge.evaluation.status.pending") - return t(evaluation?.reward ? "referrals.challenge.evaluation.status.passed" : "referrals.challenge.evaluation.status.failed") - } + if (!evaluation) return t("referrals.challenge.evaluation.status.pending"); + return t(evaluation?.reward ? "referrals.challenge.evaluation.status.passed" : "referrals.challenge.evaluation.status.failed"); + }; const formatDate = (date: Date) => { - return date ? DateManager.fromNow(date, locale) : null - } + return date ? DateManager.fromNow(date, locale) : null; + }; return (
@@ -44,24 +44,38 @@ export default function Referral({ referral }: ReferralProps): ReactElement {

{referral.user?.displayName} - {t("referrals.joined")} {joinedAt} + + {t("referrals.joined")} {joinedAt} +

    - {referral.user.submissions.length ? referral.user.submissions.map((submission) => ( -
  • - - - {status(submission.metadata.evaluation)} {submission.challengeData.name} {t("referrals.submission.challenge")} + {referral.user.submissions.length ? ( + referral.user.submissions.map((submission) => ( +
  • + + + {status(submission.metadata.evaluation)}{" "} + + {submission.challengeData.name} {t("referrals.submission.challenge")} + + + {!submission?.metadata?.evaluation && ( + + {" "} + + {t("referrals.challenge.evaluation.pending")} + + )} - {!submission?.metadata?.evaluation && {t("referrals.challenge.evaluation.pending")}} - - {formatDate(submission.updated_at)} -
  • - ) - ) : <>} + {formatDate(submission.updated_at)} + + )) + ) : ( + <> + )} {referral?.rewarded && referral.metadata && referral.metadata.reward && (
  • @@ -77,8 +91,8 @@ export default function Referral({ referral }: ReferralProps): ReactElement { )}
-
-
-
+
+
+
); } diff --git a/src/components/popups/NotificationPopup.tsx b/src/components/popups/NotificationPopup.tsx index 43f4200b..d2b5bf40 100644 --- a/src/components/popups/NotificationPopup.tsx +++ b/src/components/popups/NotificationPopup.tsx @@ -62,15 +62,9 @@ export default function NotificationPopup({ buttonStyles }: NotificationPopupPro
  • -
  • {isNotificationVisible && ( diff --git a/src/components/popups/profile-settings/EmailForm.tsx b/src/components/popups/profile-settings/EmailForm.tsx index 140609e1..5e5c285a 100644 --- a/src/components/popups/profile-settings/EmailForm.tsx +++ b/src/components/popups/profile-settings/EmailForm.tsx @@ -110,7 +110,7 @@ export default function EditEmail({ show, onClose }: EditProfileProps): ReactEle message: "This must be a valid email address", }, validate: (val: string) => { - if (watch('email') !== val) return "Emails should match." + if (watch("email") !== val) return "Emails should match."; }, })} /> diff --git a/src/components/sections/bounties/Navigation.tsx b/src/components/sections/bounties/Navigation.tsx index 1f819bf1..8e4c619c 100644 --- a/src/components/sections/bounties/Navigation.tsx +++ b/src/components/sections/bounties/Navigation.tsx @@ -30,7 +30,7 @@ interface BountiesNavigationMultiSelector { * @export * @returns {ReactElement} */ -export default function BountiesNavigation({testId}: {testId?: string}): ReactElement { +export default function BountiesNavigation({ testId }: { testId?: string }): ReactElement { const { t } = useTranslation(); const router = useRouter(); const { colors, bounties } = useMultiSelector({ diff --git a/src/components/sections/challenges/Learning.tsx b/src/components/sections/challenges/Learning.tsx index 3a48c0c2..3bc281b2 100644 --- a/src/components/sections/challenges/Learning.tsx +++ b/src/components/sections/challenges/Learning.tsx @@ -37,10 +37,7 @@ export default function Learning({ courses, learningModules, community }: { cour
    {learningModules?.map((learning) => ( - + ))}
    diff --git a/src/components/sections/challenges/_partials/HackathonPrize.tsx b/src/components/sections/challenges/_partials/HackathonPrize.tsx index 35d8a12f..1fc09bb9 100644 --- a/src/components/sections/challenges/_partials/HackathonPrize.tsx +++ b/src/components/sections/challenges/_partials/HackathonPrize.tsx @@ -3,16 +3,16 @@ import { shortenNumber } from "@/utilities"; import { useTranslation } from "react-i18next"; export default function HackathonPrize({ reward, description }: { reward: Reward; description: string }) { - const { t } = useTranslation() + const { t } = useTranslation(); const { first, second, third } = reward?.distribution || ({} as Distribution); const amount = shortenNumber(reward?.amount); return ( <>
    - {reward?.fiatCurrency ? - t('communities.overview.reward.fiat.prize.pool', { amount, currency: reward.fiatCurrency, token: reward?.token }) : - t('communities.overview.reward.crypto.prize.pool', { amount, token: reward?.token })} + {reward?.fiatCurrency + ? t("communities.overview.reward.fiat.prize.pool", { amount, currency: reward.fiatCurrency, token: reward?.token }) + : t("communities.overview.reward.crypto.prize.pool", { amount, token: reward?.token })} {description}
    diff --git a/src/components/sections/communities/overview/LearningMaterials.tsx b/src/components/sections/communities/overview/LearningMaterials.tsx index 674d9347..876595e7 100644 --- a/src/components/sections/communities/overview/LearningMaterials.tsx +++ b/src/components/sections/communities/overview/LearningMaterials.tsx @@ -1,5 +1,5 @@ -import CourseCard from "@/components/cards/course" -import { useMultiSelector } from "@/hooks/useTypedSelector" +import CourseCard from "@/components/cards/course"; +import { useMultiSelector } from "@/hooks/useTypedSelector"; import { LearningModuleCard } from "@/components/cards/LearningModule"; import { Course, LearningModule } from "@/types/course"; import { Community } from "@/types/community"; @@ -9,51 +9,49 @@ import { useTranslation } from "next-i18next"; import CommunityNavItem from "./_partials/NavItem"; interface LearningMaterialsSectionProps { - community: Community; - learningModules: LearningModule[], - courses: Course[], - loading: boolean + community: Community; + learningModules: LearningModule[]; + courses: Course[]; + loading: boolean; } export default function LearningMaterialsOverview() { - const { t } = useTranslation() - const { courses, learningModules, community, loading } = useMultiSelector({ - courses: (state: IRootState) => state.learningMaterials.courses, - learningModules: (state: IRootState) => state.learningMaterials.learningModules, - community: (state: IRootState) => state.communities.current, - loading: (state: IRootState) => state.learningMaterials.loading - }) + const { t } = useTranslation(); + const { courses, learningModules, community, loading } = useMultiSelector({ + courses: (state: IRootState) => state.learningMaterials.courses, + learningModules: (state: IRootState) => state.learningMaterials.learningModules, + community: (state: IRootState) => state.communities.current, + loading: (state: IRootState) => state.learningMaterials.loading, + }); - if (loading) return ; + if (loading) return ; - return ( - <> - + +
    + {courses?.map((course) => { + return ( + -
    - {courses?.map((course) => { - return - })} -
    -
    - {learningModules?.map((module) => { - return - })} -
    - - ) + ); + })} +
    +
    + {learningModules?.map((module) => { + return ; + })} +
    + + ); } - diff --git a/src/components/sections/communities/overview/Sidebar.tsx b/src/components/sections/communities/overview/Sidebar.tsx index 595c44f1..16ef07a6 100644 --- a/src/components/sections/communities/overview/Sidebar.tsx +++ b/src/components/sections/communities/overview/Sidebar.tsx @@ -60,23 +60,19 @@ export default function Sidebar(): JSX.Element { url={links.learningMaterialsLink} title={t("communities.overview.learning-materials.title")} description={t("communities.overview.learning-materials.description")} - className={classNames("pt-6", - { - "text-tertiary": !isActive(links.learningMaterialsLink), - } - )} + className={classNames("pt-6", { + "text-tertiary": !isActive(links.learningMaterialsLink), + })} /> {hasCurrentCommunity && (
    diff --git a/src/components/sections/communities/overview/Wrapper.tsx b/src/components/sections/communities/overview/Wrapper.tsx index d08b3962..2a1a17ea 100644 --- a/src/components/sections/communities/overview/Wrapper.tsx +++ b/src/components/sections/communities/overview/Wrapper.tsx @@ -16,7 +16,7 @@ interface WrapperProps { /** * Wrapper component to provide a layout for children and filter props. * @param {WrapperProps} props - The properties to configure the Wrapper component. - * @returns {JSX.Element} A styled Wrapper component containing a MainHeaderSection, CommunitySidebar, + * @returns {JSX.Element} A styled Wrapper component containing a MainHeaderSection, CommunitySidebar, * optional filter component, and children content. */ export default function Wrapper({ children, filter }: WrapperProps): JSX.Element { @@ -34,4 +34,4 @@ export default function Wrapper({ children, filter }: WrapperProps): JSX.Element
    ); -}; +} diff --git a/src/components/sections/communities/overview/_partials/NavItem.tsx b/src/components/sections/communities/overview/_partials/NavItem.tsx index e18fd3b6..3dce2265 100644 --- a/src/components/sections/communities/overview/_partials/NavItem.tsx +++ b/src/components/sections/communities/overview/_partials/NavItem.tsx @@ -1,12 +1,12 @@ import Link from "next/link"; -export default function CommunityNavItem({ title, description, className = "", url = "" }: { title: string; description: string; className?: string, url?: string }) { - const Component = url ? Link : "div"; +export default function CommunityNavItem({ title, description, className = "", url = "" }: { title: string; description: string; className?: string; url?: string }) { + const Component = url ? Link : "div"; - return ( - -
    {title}
    -
    {description}
    -
    - ) + return ( + +
    {title}
    +
    {description}
    +
    + ); } diff --git a/src/components/sections/communities/overview/scoreboard/index.tsx b/src/components/sections/communities/overview/scoreboard/index.tsx index 0b8c85cb..445e35bf 100644 --- a/src/components/sections/communities/overview/scoreboard/index.tsx +++ b/src/components/sections/communities/overview/scoreboard/index.tsx @@ -27,11 +27,7 @@ export default function ScoreboardOverview(): ReactElement { return ( <> - + {loading ? (
    diff --git a/src/components/sections/feedbacks/Form.tsx b/src/components/sections/feedbacks/Form.tsx index 5ce463ba..281c3328 100644 --- a/src/components/sections/feedbacks/Form.tsx +++ b/src/components/sections/feedbacks/Form.tsx @@ -113,7 +113,7 @@ export default function Form({ onSave }: FormProps): ReactElement { return (
    -
    +
    diff --git a/src/components/sections/homepage/Testimonials.tsx b/src/components/sections/homepage/Testimonials.tsx index 7c66529e..f7580113 100644 --- a/src/components/sections/homepage/Testimonials.tsx +++ b/src/components/sections/homepage/Testimonials.tsx @@ -75,15 +75,15 @@ const stories = (t: TFunction<"translation", undefined, "translation">): Testimo ]; }; -export default function TestimonialsSection({testId="testimonialsSectionId"}: {testId?: string}): ReactElement { +export default function TestimonialsSection({ testId = "testimonialsSectionId" }: { testId?: string }): ReactElement { const { t } = useTranslation(); return (
    -
    - - - -
    +
    + + + +
    ); } diff --git a/src/components/sections/learning-modules/InteractiveModule/Item.tsx b/src/components/sections/learning-modules/InteractiveModule/Item.tsx index f1e4b2fe..6dc1b99f 100644 --- a/src/components/sections/learning-modules/InteractiveModule/Item.tsx +++ b/src/components/sections/learning-modules/InteractiveModule/Item.tsx @@ -17,7 +17,7 @@ interface InteractiveModuleItemProps { correct: number; }; }; - goToNextItem: () => void + goToNextItem: () => void; } /** diff --git a/src/components/sections/profile/Header.tsx b/src/components/sections/profile/Header.tsx index 8db2e4c2..6b74c795 100644 --- a/src/components/sections/profile/Header.tsx +++ b/src/components/sections/profile/Header.tsx @@ -68,7 +68,7 @@ export default function ProfileHeader() { const triggerKYCVerification = () => { dispatch(openVerificationModal({})); - dispatch(toggleBodyScrolling(true)) + dispatch(toggleBodyScrolling(true)); }; const { canConnectDiscord, triggerDiscordOauth } = useDiscordConnect(); diff --git a/src/components/sections/profile/overview/Achievements.tsx b/src/components/sections/profile/overview/Achievements.tsx index 05c4edad..8a8f457f 100644 --- a/src/components/sections/profile/overview/Achievements.tsx +++ b/src/components/sections/profile/overview/Achievements.tsx @@ -27,13 +27,13 @@ export default function ProfileOverviewAchievements(): ReactElement { ))}
    {showAll ? ( - ) : ( -
    diff --git a/src/store/feature/bouties.slice.ts b/src/store/feature/bouties.slice.ts index 7a480a20..d84d1e0b 100644 --- a/src/store/feature/bouties.slice.ts +++ b/src/store/feature/bouties.slice.ts @@ -11,7 +11,7 @@ interface InitialState { const initialState: InitialState = { bountiesList: [], filteredBountyList: [], - isLoading: false + isLoading: false, }; /** @@ -32,7 +32,7 @@ const bountiesSlice = createSlice({ }, setLoading: (state, action) => { state.isLoading = action.payload; - } + }, }, }); diff --git a/src/store/feature/learningMaterials.slice.ts b/src/store/feature/learningMaterials.slice.ts index fba286ac..f0640523 100644 --- a/src/store/feature/learningMaterials.slice.ts +++ b/src/store/feature/learningMaterials.slice.ts @@ -3,39 +3,39 @@ import { createSlice } from "@reduxjs/toolkit"; import { HYDRATE } from "next-redux-wrapper"; interface InitialState { - learningModules: LearningModule[] | null; - courses: Course[] | null; - loading: boolean + learningModules: LearningModule[] | null; + courses: Course[] | null; + loading: boolean; } const initialState: InitialState = { - learningModules: null, - courses: null, - loading: false -} + learningModules: null, + courses: null, + loading: false, +}; const learningMaterialsSlice = createSlice({ - name: "learningMaterials", - initialState, - reducers: { - setCourseList: (state, action) => { - state.courses = action.payload - }, - setLearningModulesList: (state, action) => { - state.learningModules = action.payload - }, - setLoading: (state, action) => { - state.loading = action.payload - } + name: "learningMaterials", + initialState, + reducers: { + setCourseList: (state, action) => { + state.courses = action.payload; + }, + setLearningModulesList: (state, action) => { + state.learningModules = action.payload; + }, + setLoading: (state, action) => { + state.loading = action.payload; + }, + }, + extraReducers: { + [HYDRATE]: (state, action) => { + return { + ...state, + ...action.payload.learningMaterials, + }; }, - extraReducers: { - [HYDRATE]: (state, action) => { - return { - ...state, - ...action.payload.learningMaterials, - }; - }, - } -}) + }, +}); -export const { setCourseList, setLearningModulesList, setLoading } = learningMaterialsSlice.actions +export const { setCourseList, setLearningModulesList, setLoading } = learningMaterialsSlice.actions; -export default learningMaterialsSlice \ No newline at end of file +export default learningMaterialsSlice; diff --git a/src/store/index.ts b/src/store/index.ts index cced7036..65135128 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -82,7 +82,7 @@ export interface IRootState { payouts: ReturnType; teams: ReturnType; invites: ReturnType; - learningMaterials: ReturnType + learningMaterials: ReturnType; } export type IRootService = { diff --git a/src/store/services/community.service.ts b/src/store/services/community.service.ts index 13de31c5..be0b7e72 100644 --- a/src/store/services/community.service.ts +++ b/src/store/services/community.service.ts @@ -56,26 +56,24 @@ export const communityService = createApi({ query: ({ locale, slug }: { locale?: string; slug: string }) => ({ url: `/communities/${slug}/learning-materials`, headers: { - "accept-language": locale - } + "accept-language": locale, + }, }), onQueryStarted: async (_, { dispatch, queryFulfilled }) => { try { - dispatch(setLoading(true)) - const { data } = await queryFulfilled - dispatch(setCourseList(data.courses)) - dispatch(setLearningModulesList(data.learningModules)) - return data - } - catch (error) { - dispatch(setError(error)) - return null - } - finally { - dispatch(setLoading(false)) + dispatch(setLoading(true)); + const { data } = await queryFulfilled; + dispatch(setCourseList(data.courses)); + dispatch(setLearningModulesList(data.learningModules)); + return data; + } catch (error) { + dispatch(setError(error)); + return null; + } finally { + dispatch(setLoading(false)); } - } - }) + }, + }), }), }); @@ -97,5 +95,5 @@ export const fetchCurrentCommunity = ({ slug, locale }: { slug: string; locale?: }); }; -export const fetchLearningMaterials = ({ slug, locale }: { slug: string; locale?: string }) => communityService.endpoints.fetchLearningMaterials.initiate({ slug, locale }) +export const fetchLearningMaterials = ({ slug, locale }: { slug: string; locale?: string }) => communityService.endpoints.fetchLearningMaterials.initiate({ slug, locale }); export const { useGetCommunitiesQuery } = communityService; diff --git a/src/store/services/learningModules.service.ts b/src/store/services/learningModules.service.ts index a41aea16..fd155d6f 100644 --- a/src/store/services/learningModules.service.ts +++ b/src/store/services/learningModules.service.ts @@ -35,7 +35,6 @@ export const learningModulesService = createApi({ }, }), onQueryStarted: async (_, { dispatch, queryFulfilled }) => { - const { data } = await queryFulfilled; dispatch(setLearningModuleList(data)); }, diff --git a/src/store/services/referrals.service.ts b/src/store/services/referrals.service.ts index 6cf63331..d8c39d0b 100644 --- a/src/store/services/referrals.service.ts +++ b/src/store/services/referrals.service.ts @@ -35,7 +35,7 @@ const referralsService = createApi({ onQueryStarted: async ({ startAfter }, { dispatch, queryFulfilled, getState }) => { const state = getState() as any; try { - dispatch(setLoading(true)) + dispatch(setLoading(true)); const { data } = await queryFulfilled; const list: Referral[] = []; if (startAfter) { @@ -48,8 +48,7 @@ const referralsService = createApi({ dispatch(setUserReferralsList(list)); dispatch(setCount(data?.count)); dispatch(setHasMoreReferrals(data?.list?.length > 0 ? true : false)); - dispatch(setLoading(false)) - + dispatch(setLoading(false)); } catch (error) { console.log("error in fetching the userFetchReferrals ", error); } diff --git a/src/types/community.d.ts b/src/types/community.d.ts index 8ddedfd1..2acb5c1e 100644 --- a/src/types/community.d.ts +++ b/src/types/community.d.ts @@ -43,11 +43,11 @@ export interface Colors { }; } interface ReferralSubmission extends Submission { - challengeData: Challenge, - link: string + challengeData: Challenge; + link: string; } interface UserReferral extends User { - submissions: ReferralSubmission[] + submissions: ReferralSubmission[]; } export interface Referral { id: string; diff --git a/src/types/course.d.ts b/src/types/course.d.ts index b1b28360..2aac07f5 100644 --- a/src/types/course.d.ts +++ b/src/types/course.d.ts @@ -174,8 +174,8 @@ export type LearningModule = { order: number; course: string; interactiveModules: InteractiveModule[]; - courses: Course[], - level?: number, + courses: Course[]; + level?: number; }; export type InteractiveModule = { diff --git a/src/utilities/Address.ts b/src/utilities/Address.ts index 7dd7d344..e0f93472 100644 --- a/src/utilities/Address.ts +++ b/src/utilities/Address.ts @@ -87,7 +87,7 @@ export const truncateAlgoAddress = (address: string): string => { */ export const defaultAddressTruncate = (address: string): string => { return truncateHandler(address, defaultRegex, (match) => { - return`${match?.[1]}…${match?.[2]}` + return `${match?.[1]}…${match?.[2]}`; }); }; @@ -112,8 +112,8 @@ export const truncateAddress = (rawAddress: string, token: string = "eth"): stri return truncateAlgoAddress(address); case "eth": return truncateEthAddress(address); - default: - return defaultAddressTruncate(address) + default: + return defaultAddressTruncate(address); } }; diff --git a/src/utilities/Routing.ts b/src/utilities/Routing.ts index 47d3b120..d425a1ef 100644 --- a/src/utilities/Routing.ts +++ b/src/utilities/Routing.ts @@ -1,7 +1,7 @@ import { NextRouter } from "next/router"; export function localePath(router: NextRouter, path: string) { - const locale = router.locale !== router.defaultLocale ? router.locale : ''; - // remove duplicate slashes - return `/${locale}/${path}`.replace(/\/\/+/g, '/') + const locale = router.locale !== router.defaultLocale ? router.locale : ""; + // remove duplicate slashes + return `/${locale}/${path}`.replace(/\/\/+/g, "/"); } diff --git a/src/utilities/errors/NotFoundError.ts b/src/utilities/errors/NotFoundError.ts index bb8cb9bc..5736f4ab 100644 --- a/src/utilities/errors/NotFoundError.ts +++ b/src/utilities/errors/NotFoundError.ts @@ -8,9 +8,8 @@ * @extends {Error} */ export class NotFoundError extends Error { - constructor(message = "Not found!") { - super(message); - this.name = "NotFoundError"; - } + constructor(message = "Not found!") { + super(message); + this.name = "NotFoundError"; } - \ No newline at end of file +} From 4adffb153ee38fe47abe81a1a993e51889b8dee2 Mon Sep 17 00:00:00 2001 From: igorntwari Date: Tue, 3 Sep 2024 10:05:57 +0200 Subject: [PATCH 21/21] refactor: add proper type coerciaon --- src/components/badges/Duration.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/badges/Duration.tsx b/src/components/badges/Duration.tsx index e3a2b70d..4a759d9c 100644 --- a/src/components/badges/Duration.tsx +++ b/src/components/badges/Duration.tsx @@ -14,7 +14,7 @@ export const DurationBadge = ({ value, type = "gray" }: DurationBadgeProps) => { if (!value) { return 0; } - if (isNaN(Number(value))) return value; + if (Number.isNaN(Number(value))) return value; return DateManager.humanize(value, router.locale as string); }, [router.locale, value]);