Skip to content

Disable referral copy until link loads - #134

Closed
absalonCRC wants to merge 1 commit into
profullstack:masterfrom
absalonCRC:fix-referral-copy-loading-state
Closed

Disable referral copy until link loads#134
absalonCRC wants to merge 1 commit into
profullstack:masterfrom
absalonCRC:fix-referral-copy-loading-state

Conversation

@absalonCRC

@absalonCRC absalonCRC commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • disable the Invite Friends Copy button until /api/referrals/code has populated a link
  • guard copyLink against empty referral-link values
  • add regression coverage for the loading window before the referral link resolves

Fixes #133

Validation

  • pnpm test:run src/app/dashboard/referrals/page.copy-loading.test.tsx
  • pnpm type-check
  • pnpm exec eslint src/app/dashboard/referrals/page.tsx src/app/dashboard/referrals/page.copy-loading.test.tsx
  • git diff --check

Bounty / payment

Submitted for the active uGig affiliate-program testing task. SOL receive address: 27sdMYXofqoM9qR13bZhccRNYeEgYn5EoHXTSJn4QWKP.

Payment fallback: PayPal cultofrozen@gmail.com

@greptile-apps

greptile-apps Bot commented May 23, 2026

Copy link
Copy Markdown

Greptile Summary

This PR disables the "Copy" button on the referrals page until the /api/referrals/code fetch resolves, preventing a clipboard write with an empty string. A new test verifies the button is disabled during the loading window and re-enables once the link arrives.

  • page.tsx: adds disabled={!referralLink} to the Copy button and disabled:opacity-50 for visual feedback; also adds a runtime guard inside copyLink that is now unreachable because a disabled button won't fire onClick.
  • page.copy-loading.test.tsx: new Vitest/RTL test using a deferred promise to assert the button's disabled/enabled state around the async fetch lifecycle.

Confidence Score: 4/5

Safe to merge; the change is narrowly scoped to disabling a button during async load with matching test coverage.

The implementation is correct and the new test covers the intended behavior. The only notable issue is that the if (!referralLink) guard inside copyLink is dead code — a disabled button never fires onClick, so that branch and its setError call will never execute.

The guard block in copyLink (lines 66–69 of page.tsx) is worth a second glance; it is otherwise harmless but unreachable.

Important Files Changed

Filename Overview
src/app/dashboard/referrals/page.tsx Adds disabled={!referralLink} to the Copy button and a now-unreachable guard inside copyLink; the guard is dead code since a disabled button never fires onClick.
src/app/dashboard/referrals/page.copy-loading.test.tsx New test using a deferred promise to verify the Copy button is disabled while /api/referrals/code is in-flight and enabled once it resolves; well-structured and covers the intended regression.

Sequence Diagram

sequenceDiagram
    participant User
    participant ReferralsPage
    participant API as /api/referrals/code

    ReferralsPage->>ReferralsPage: "mount (referralLink = "")"
    Note over ReferralsPage: Copy button disabled
    ReferralsPage->>API: fetch()
    API-->>ReferralsPage: "{ code, link }"
    ReferralsPage->>ReferralsPage: setReferralLink(link)
    Note over ReferralsPage: Copy button enabled
    User->>ReferralsPage: click Copy
    ReferralsPage->>ReferralsPage: navigator.clipboard.writeText(referralLink)
Loading

Reviews (1): Last reviewed commit: "Disable referral copy until link loads" | Re-trigger Greptile

Comment on lines 65 to +69
const copyLink = async () => {
if (!referralLink) {
setError("Referral link is still loading. Please try again.");
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Dead guard — unreachable via UI

Because the Copy button is now disabled={!referralLink}, a disabled <button> won't fire onClick, so copyLink can never be called while referralLink is empty. The if (!referralLink) block and the setError(...) call inside it are dead code; the error message will never be displayed to the user through normal interaction. The guard can be removed without changing behavior.

@ralyodio ralyodio closed this May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: referral copy button can copy an empty link before invite link loads

2 participants