-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable user to collect special badge
- Loading branch information
1 parent
7a57edd
commit dd68161
Showing
15 changed files
with
102 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
apps/govquests-api/rails_app/app/graphql/mutations/collect_badge.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
apps/govquests-frontend/src/domains/gamification/graphql/collectBadge.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { graphql } from "gql.tada"; | ||
|
||
export const COLLECT_BADGE = graphql(` | ||
mutation CollectBadge($badgeId: ID!, $badgeType: String!) { | ||
collectBadge(input: { badgeId: $badgeId, badgeType: $badgeType }) { | ||
badgeEarned | ||
errors | ||
} | ||
} | ||
`); |
14 changes: 14 additions & 0 deletions
14
apps/govquests-frontend/src/domains/gamification/hooks/useCollectBadge.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { collectBadge } from "../services/collectBadgeService"; | ||
import { CollectBadgeResult, CollectBadgeVariables } from "../types/badgeTypes"; | ||
|
||
export const useCollectBadge = () => { | ||
const queryClient = useQueryClient(); | ||
return useMutation<CollectBadgeResult, Error, CollectBadgeVariables>({ | ||
mutationFn: collectBadge, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: ["specialBadge"] }); | ||
queryClient.invalidateQueries({ queryKey: ["specialBadges"] }); | ||
}, | ||
}); | ||
}; |
10 changes: 10 additions & 0 deletions
10
apps/govquests-frontend/src/domains/gamification/services/collectBadgeService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { API_URL } from "@/lib/utils"; | ||
import request from "graphql-request"; | ||
import { COLLECT_BADGE } from "../graphql/collectBadge"; | ||
import { CollectBadgeResult, CollectBadgeVariables } from "../types/badgeTypes"; | ||
|
||
export const collectBadge = async ( | ||
variables: CollectBadgeVariables, | ||
): Promise<CollectBadgeResult> => { | ||
return await request(API_URL, COLLECT_BADGE, variables); | ||
}; |
6 changes: 5 additions & 1 deletion
6
apps/govquests-frontend/src/domains/gamification/types/badgeTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { ResultOf } from "gql.tada"; | ||
import { ResultOf, VariablesOf } from "gql.tada"; | ||
import { BadgeQuery } from "../graphql/badgeQuery"; | ||
import { COLLECT_BADGE } from "../graphql/collectBadge"; | ||
|
||
export type Badge = ResultOf<typeof BadgeQuery>["badge"]; | ||
|
||
export type CollectBadgeVariables = VariablesOf<typeof COLLECT_BADGE>; | ||
export type CollectBadgeResult = ResultOf<typeof COLLECT_BADGE>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters