diff --git a/wondrous-bot-admin/src/components/Referral/index.tsx b/wondrous-bot-admin/src/components/Referral/index.tsx index ec1767345..0f3b89551 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,16 @@ const StartReferralPage = () => { skip: !referralCampaignExternalId, }); + const {data: referralLimitReached, loading: referralLimitLoading} = useQuery(GET_REFERRAL_USER_LIMIT_REACHED, { + variables: { + referralCode, + referralCampaignExternalId + }, + 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..00251598c 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!, $referralCampaignExternalId: String!) { + getReferralUserLimitReached(referralCode: $referralCode , referralCampaignExternalId: $referralCampaignExternalId) { + hasReachedLimit + } + } +`; diff --git a/wondrous-bot-admin/src/services/validators/customValidation.tsx b/wondrous-bot-admin/src/services/validators/customValidation.tsx index c0ce447da..85d3b6088 100644 --- a/wondrous-bot-admin/src/services/validators/customValidation.tsx +++ b/wondrous-bot-admin/src/services/validators/customValidation.tsx @@ -1,5 +1,11 @@ export const getYouTubeVideoId = (url) => { let videoId = ""; + if (url?.includes("shorts")) { + // https://www.youtube.com/shorts/rKANnKDu5-o + const shortsRegex = /youtube\.com\/shorts\/([a-zA-Z0-9_-]+)/; + const match = url.match(shortsRegex); + return match ? match[1] : null; + } // Extract video ID from the first format: https://youtu.be/videoId const regex1 = /^https:\/\/youtu\.be\/([^\?]+)/; const match1 = url.match(regex1);