Skip to content

Commit

Permalink
refactor: move badge logic to gamification domain
Browse files Browse the repository at this point in the history
  • Loading branch information
juliano-quatrin-nunes committed Jan 10, 2025
1 parent a29dcae commit dec675f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cn } from "@/lib/utils";
import Image from "next/image";
import Link from "next/link";
import { useFetchBadge } from "../hooks/useFetchBadge";
import { useFetchBadge } from "../../questing/hooks/useFetchBadge";

interface BadgeCardProps {
badgeId: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { graphql } from "gql.tada";

export const BadgeQuery = graphql(`
query GetBadge($id: ID!) {
badge(id: $id) {
id
displayData {
title
description
imageUrl
}
}
}
`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use client";

import { useQuery } from "@tanstack/react-query";
import { fetchBadge } from "../services/badgeService";

export const useFetchBadge = (id: string) => {
return useQuery({
queryKey: ["badge", id],
queryFn: () => fetchBadge(id),
enabled: !!id,
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { API_URL } from "@/lib/utils";
import request from "graphql-request";
import { BadgeQuery } from "../graphql/badgeQuery";

export const fetchBadge = async (id: string) => {
return await request(API_URL, BadgeQuery, { id });
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ResultOf } from "gql.tada";
import { BadgeQuery } from "../graphql/badgeQuery";

export type Badge = ResultOf<typeof BadgeQuery>["badge"];
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Quest } from "@/domains/questing/types/questTypes";
import { ArrowLeft } from "lucide-react";
import { redirect } from "next/navigation";
import QuestContentSection from "./QuestContentSection";
import { BadgeCard } from "./BadgeCard";
import { BadgeCard } from "../../gamification/components/BadgeCard";
import HtmlRender from "@/components/ui/HtmlRender";
import { IndicatorPill } from "@/components/IndicatorPill";
import RewardIndicator from "@/components/RewardIndicator";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BadgeCard } from "../BadgeCard";
import { BadgeCard } from "../../../gamification/components/BadgeCard";
import { Tracks } from "../../types/trackTypes";

interface TrackDescriptionProps {
Expand Down

0 comments on commit dec675f

Please sign in to comment.