Skip to content

Commit

Permalink
check if max per user is reached (#2264) (#2265)
Browse files Browse the repository at this point in the history
* check if max per user is reached

* add external id

---------

Co-authored-by: Adrian <[email protected]>
  • Loading branch information
terryli0095 and Lamperoyge committed May 17, 2024
1 parent 7989077 commit 777962f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
15 changes: 13 additions & 2 deletions wondrous-bot-admin/src/components/Referral/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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 (
<>
<PageWrapper
Expand All @@ -64,10 +74,11 @@ const StartReferralPage = () => {
flexDirection="column"
flex="1"
>
{!data?.getReferralCampaignByReferralExternalId || loading ? (
{!data?.getReferralCampaignByReferralExternalId || loading || referralLimitLoading ? (
<PageSpinner color="#fee2ca" />
) : (
<StartReferralQuests
hasReachedLimit={hasReachedLimit}
referralCampaign={data?.getReferralCampaignByReferralExternalId}
referralCode={referralCode}
referralCodeInfo={referralCodeInfoData?.getReferralCodeInfo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const TopBarMessage = ({ displayName, hasEnded, orgId }) => {
);
};

const StartReferralQuests = ({ referralCampaign, referralCode, referralCampaignExternalId, referralCodeInfo }) => {
const StartReferralQuests = ({ referralCampaign, referralCode, referralCampaignExternalId, referralCodeInfo, hasReachedLimit }) => {
const [infoModalQuestId, setInfoModalQuestId] = useState(null);
const discordUrlParams = {
referralCode,
Expand Down Expand Up @@ -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 (
<>
Expand Down
8 changes: 8 additions & 0 deletions wondrous-bot-admin/src/graphql/queries/referral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
`;
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 777962f

Please sign in to comment.