Skip to content

Commit

Permalink
Merge pull request #991 from KeneePatel/fix-986
Browse files Browse the repository at this point in the history
Fix: Refactor QuestBanner to use banner object instead of questId
  • Loading branch information
Marchand-Nicolas authored Dec 17, 2024
2 parents a3e6af6 + edb21c9 commit 1bc8ad0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
27 changes: 12 additions & 15 deletions components/quests/questBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
import { FunctionComponent, useMemo } from "react";
import questBanners from "../../public/utils/questbanners.json";
import { FunctionComponent } from "react";
import styles from "@styles/quests.module.css";
import Button from "@components/UI/button";
import type { Banner } from "types/backTypes";

type QuestBannerProps = {
questId: string;
banner: Banner;
};

const QuestBanner: FunctionComponent<QuestBannerProps> = ({ questId }) => {
const bannerDetails = useMemo(() => {
return questBanners.find((banner) => banner.questId === questId);
}, [questId]);
return bannerDetails ? (
const QuestBanner: FunctionComponent<QuestBannerProps> = ({ banner }) => {
return banner ? (
<div className={styles.questBanner}>
<div
className={styles.questBannerImage}
style={{ backgroundImage: `url(${bannerDetails.image})` }}
style={{ backgroundImage: `url(${banner.image})` }}
/>
<div className={styles.questBannerContent}>
<h2 className={styles.questBannerTitle}>
{bannerDetails.tag ? (
<span className={styles.bannerTag}>{bannerDetails.tag} - </span>
{banner.tag ? (
<span className={styles.bannerTag}>{banner.tag} - </span>
) : null}
{bannerDetails.title}
{banner.title}
</h2>
<p>{bannerDetails.description}</p>
<p>{banner.description}</p>
<div className="w-fit">
<Button
onClick={() => {
window.open(bannerDetails.href, "_blank");
window.open(banner.href, "_blank");
}}
>
{bannerDetails.cta}
{banner.cta}
</Button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/quests/questDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ const QuestDetails: FunctionComponent<QuestDetailsProps> = ({
/>
);
})}
<QuestBanner questId={questId} />
{quest.banner && <QuestBanner banner={quest.banner} />}
<Reward
quest={quest}
hasNftReward={hasNftReward}
Expand Down
9 changes: 9 additions & 0 deletions constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export const QuestDefault = {
additional_desc: null,
visible: false,
boosts: [],
banner: {
questId: "",
tag: "optional",
title: "loading",
description: "loading",
cta: "",
href: "",
image: "",
},
};

export const basicAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789-";
Expand Down
11 changes: 0 additions & 11 deletions public/utils/questbanners.json

This file was deleted.

20 changes: 15 additions & 5 deletions types/backTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ type QuestDocument = {
id: number;
name: string;
desc: string;
additional_desc: string | null;
issuer: string;
category: string;
rewards_endpoint: string;
logo: string;
rewards_img: string;
rewards_title: string;
rewards_description: string | null;
rewards_nfts: NFTItem[];
img_card: string;
title_card: string;
Expand All @@ -20,8 +22,16 @@ type QuestDocument = {
mandatory_domain: string | null;
expired: boolean;
visible: boolean;
rewards_description: string | null;
additional_desc: string | null;
banner?: Banner;
};

type Banner = {
image: string;
tag?: string;
title: string;
description: string;
href: string;
cta: string;
};

type ClaimableQuestDocument = QuestDocument & {
Expand Down Expand Up @@ -625,9 +635,9 @@ export type ArgentTokenValue = {
ccyValue: string;
ethDayChange: string;
ccyDayChange: string;
}
};

export type ArgentUserToken = {
tokenAddress: string;
tokenBalance: string;
}
tokenBalance: string;
};

0 comments on commit 1bc8ad0

Please sign in to comment.