From 5768eabbe9c9002bc6f3e2864c77bbe802b570f1 Mon Sep 17 00:00:00 2001 From: adrian mustea Date: Tue, 14 May 2024 14:54:30 +0300 Subject: [PATCH] check if max per user is reached --- .../src/components/Referral/index.tsx | 14 ++++++++++++-- .../src/components/StartReferralQuests/index.tsx | 4 ++-- wondrous-bot-admin/src/graphql/queries/referral.ts | 8 ++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/wondrous-bot-admin/src/components/Referral/index.tsx b/wondrous-bot-admin/src/components/Referral/index.tsx index ec1767345..00745ab0e 100644 --- a/wondrous-bot-admin/src/components/Referral/index.tsx +++ b/wondrous-bot-admin/src/components/Referral/index.tsx @@ -12,7 +12,7 @@ import { BG_TYPES } from "utils/constants"; import { StyledLink } from "./styles"; import { useQuery } from "@apollo/client"; import { useLocation } from "react-router-dom"; -import { GET_REFERRAL_CAMPAIGN_BY_EXTERNAL_ID, GET_REFERRAL_CODE_INFO } from "graphql/queries/referral"; +import { GET_REFERRAL_CAMPAIGN_BY_EXTERNAL_ID, GET_REFERRAL_CODE_INFO, GET_REFERRAL_USER_LIMIT_REACHED } from "graphql/queries/referral"; import StartReferralQuests from "components/StartReferralQuests"; const StartReferralPage = () => { @@ -41,6 +41,15 @@ const StartReferralPage = () => { skip: !referralCampaignExternalId, }); + const {data: referralLimitReached, loading: referralLimitLoading} = useQuery(GET_REFERRAL_USER_LIMIT_REACHED, { + variables: { + referralCode + }, + skip: !referralCode + }); + + const {hasReachedLimit = false} = referralLimitReached?.getReferralUserLimitReached || {}; + return ( <> { flexDirection="column" flex="1" > - {!data?.getReferralCampaignByReferralExternalId || loading ? ( + {!data?.getReferralCampaignByReferralExternalId || loading || referralLimitLoading ? ( ) : ( { ); }; -const StartReferralQuests = ({ referralCampaign, referralCode, referralCampaignExternalId, referralCodeInfo }) => { +const StartReferralQuests = ({ referralCampaign, referralCode, referralCampaignExternalId, referralCodeInfo, hasReachedLimit }) => { const [infoModalQuestId, setInfoModalQuestId] = useState(null); const discordUrlParams = { referralCode, @@ -84,7 +84,7 @@ const StartReferralQuests = ({ referralCampaign, referralCode, referralCampaignE const endDate = referralCampaign?.endDate ? moment(referralCampaign?.endDate) : null; const hasEnded = referralCampaign?.status !== REFERRAL_STATUSES.ACTIVE || - (endDate && endDate.isBefore(moment().utcOffset(0)?.endOf("day")?.toISOString())); + (endDate && endDate.isBefore(moment().utcOffset(0)?.endOf("day")?.toISOString())) || hasReachedLimit; return ( <> diff --git a/wondrous-bot-admin/src/graphql/queries/referral.ts b/wondrous-bot-admin/src/graphql/queries/referral.ts index b1ccdc7ab..23633831e 100644 --- a/wondrous-bot-admin/src/graphql/queries/referral.ts +++ b/wondrous-bot-admin/src/graphql/queries/referral.ts @@ -97,3 +97,11 @@ export const GET_REFERRAL_CODE_INFO = gql` } } `; + +export const GET_REFERRAL_USER_LIMIT_REACHED = gql` + query getReferralUserLimitReached($referralCode: String!) { + getReferralUserLimitReached(referralCode: $referralCode) { + hasReachedLimit + } + } +`;