diff --git a/api/server/handlers/user/create_test.go b/api/server/handlers/user/create_test.go index 5f724ab044e..de502d7c72d 100644 --- a/api/server/handlers/user/create_test.go +++ b/api/server/handlers/user/create_test.go @@ -245,6 +245,6 @@ func TestCreateUserReferralCode(t *testing.T) { // This is the default lenth of a shortuuid desiredLenth := 22 assert.NotEmpty(t, gotUser.ReferralCode, "referral code should not be empty") - assert.Len(t, gotUser.ReferralCode, desiredLenth, "referral code should be 20 characters long") + assert.Len(t, gotUser.ReferralCode, desiredLenth, "referral code should be 22 characters long") assert.Equal(t, gotUser.ReferralRewardClaimed, false, "referral reward claimed should be false for new user") } diff --git a/dashboard/src/lib/hooks/useStripe.tsx b/dashboard/src/lib/hooks/useStripe.tsx index c83bbdad560..07c1e813ae8 100644 --- a/dashboard/src/lib/hooks/useStripe.tsx +++ b/dashboard/src/lib/hooks/useStripe.tsx @@ -471,4 +471,4 @@ export const useClaimReferralReward = (): (() => void) => { // Return a function that can be called to execute the mutation return () => referralsReq.mutate(); -}; \ No newline at end of file +}; diff --git a/dashboard/src/main/auth/Register.tsx b/dashboard/src/main/auth/Register.tsx index c78bc96ff42..3d218714521 100644 --- a/dashboard/src/main/auth/Register.tsx +++ b/dashboard/src/main/auth/Register.tsx @@ -1,5 +1,6 @@ import React, { useContext, useEffect, useState } from "react"; import styled from "styled-components"; +import { useLocation } from "react-router-dom"; import Heading from "components/form-components/Heading"; import Button from "components/porter/Button"; @@ -74,6 +75,16 @@ const Register: React.FC = ({ authenticate }) => { { value: "Other", label: "Other" }, ]; + const { search } = useLocation() + const searchParams = new URLSearchParams(search) + const referralCodeFromUrl = searchParams.get("referral") + + useEffect(() => { + if (referralCodeFromUrl) { + setReferralCode(referralCodeFromUrl); + } + }, [referralCodeFromUrl]); // Only re-run the effect if referralCodeFromUrl changes + const handleRegister = (): void => { const isHosted = window.location.hostname === "cloud.porter.run"; if (!emailRegex.test(email)) { diff --git a/dashboard/src/main/home/project-settings/ReferralsPage.tsx b/dashboard/src/main/home/project-settings/ReferralsPage.tsx index 4bc811740df..c0cecb72a3a 100644 --- a/dashboard/src/main/home/project-settings/ReferralsPage.tsx +++ b/dashboard/src/main/home/project-settings/ReferralsPage.tsx @@ -3,12 +3,14 @@ import Spacer from "components/porter/Spacer"; import Text from "components/porter/Text"; import { useClaimReferralReward, useReferralDetails, useReferrals } from "lib/hooks/useStripe"; import Button from "components/porter/Button"; +import Link from "components/porter/Link"; function ReferralsPage(): JSX.Element { const referralRewardRequirement = 5; const { referralDetails } = useReferralDetails(); const { referralsCount } = useReferrals(); const claimReferralReward = useClaimReferralReward(); + const baseUrl = window.location.origin; const eligibleForReward = (): boolean => { if (referralsCount === null) { @@ -66,6 +68,16 @@ function ReferralsPage(): JSX.Element { Refer people to Porter to earn credits. + {referralDetails !== null && ( + <> + + Your referral link is {" "} + +