Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(rewards): handle empty rewards list gracefully

Steven Enamakel05e558124ead
diff --git a/app/src/pages/Rewards.tsx b/app/src/pages/Rewards.tsx
index 7b4fb02426..7952f013e9 100644
--- a/app/src/pages/Rewards.tsx
+++ b/app/src/pages/Rewards.tsx
@@ -1,12 +1,12 @@
import createDebug from 'debug';
-import { useCallback, useEffect, useState } from 'react';
-import { useNavigate } from 'react-router-dom';
+import { useCallback, useEffect, useMemo, useState } from 'react';
+import { LuGift, LuTicket, LuUsers } from 'react-icons/lu';
+import { useLocation, useNavigate } from 'react-router-dom';
import EmptyStateCard from '../components/EmptyStateCard';
-import ChipTabs from '../components/layout/ChipTabs';
-import PageSectionHeader from '../components/layout/PageSectionHeader';
-import PageWelcome from '../components/layout/PageWelcome';
-import { usePageWelcomeView } from '../components/layout/usePageWelcomeView';
+import SettingsTabbedPage from '../components/settings/layout/SettingsTabbedPage';
+import TwoPaneNav from '../components/layout/TwoPaneNav';
+import { SidebarContent } from '../components/layout/shell/SidebarSlot';
import RewardsCommunityTab from '../components/rewards/RewardsCommunityTab';
import RewardsRedeemTab from '../components/rewards/RewardsRedeemTab';
import RewardsReferralsTab from '../components/rewards/RewardsReferralsTab';
@@ -16,7 +16,19 @@ import { rewardsApi } from '../services/api/rewardsApi';
import type { RewardsSnapshot } from '../types/rewards';
import { isLocalSessionToken } from '../utils/localSession';
-type RewardsTab = 'referrals' | 'redeem' | 'rewards';
+/**
+ * The three Rewards surfaces. Each is its own page with a sidebar entry rather
+ * than a chip tab on one page: they share no state and none of them is a
+ * refinement of another, so a tab row was hiding two destinations behind a
+ * third. `?view=` is the address so a page survives a reload and can be linked.
+ */
+type RewardsView = 'rewards' | 'referrals' | 'redeem';
+
+const VIEWS: readonly RewardsView[] = ['rewards', 'referrals', 'redeem'] as const;
+
+function isRewardsView(value: string): value is RewardsView {
+ return (VIEWS as readonly string[]).includes(value);
+}
const log = createDebug('rewards');
@@ -33,13 +45,31 @@ function errorMessage(err: unknown): string {
const Rewards = () => {
const { t } = useT();
const navigate = useNavigate();
+ const location = useLocation();
const { snapshot: coreSnapshot } = useCoreState();
const isLocalSession = isLocalSessionToken(coreSnapshot.sessionToken);
- const [selectedTab, setSelectedTab] = useState<RewardsTab>('rewards');
const [rewardsSnapshot, setRewardsSnapshot] = useState<RewardsSnapshot | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
+ // Unlike the pages that kept a Welcome landing, an unrecognised (or absent)
+ // `?view=` lands on the main Rewards page rather than a fourth pseudo-view —
+ // the sidebar always highlights exactly one of the three entries.
+ const rawView = new URLSearchParams(location.search).get('view') ?? '';
+ const view: RewardsView = isRewardsView(rawView) ? rawView : 'rewards';
+
+ const setView = useCallback(
+ (next: string) => {
+ log('view changed next=%s', next);
+ const params = new URLSearchParams(location.search);
+ if (next === 'rewards') params.delete('view');
+ else params.set('view', next);
+ const search = params.toString();
+ navigate({ pathname: location.pathname, search: search ? `?${search}` : '' });
+ },
+ [location.pathname, location.search, navigate]
+ );
+
const loadRewards = useCallback(
async (signal?: { cancelled: boolean }, opts?: { silent?: boolean }) => {
const silent = opts?.silent === true;
@@ -107,133 +137,114 @@ const Rewards = () => {
};
}, [isLocalSession, loadRewards]);
- const handleTabChange = useCallback((next: RewardsTab) => {
- log('tab changed next=%s', next);
- setSelectedTab(next);
- }, []);
-
const handleRetry = useCallback(() => {
log('retry requested');
void loadRewards();
}, [loadRewards]);
- const { view, setView, nav } = usePageWelcomeView({
- ariaLabel: t('rewards.title'),
- welcomeLabel: t('rewards.welcome.nav'),
- mainLabel: t('rewards.welcome.main'),
- mainIconPath:
- 'M12 8v8m0-8l-3-3m3 3l3-3M8 14H6a2 2 0 01-2-2V7a2 2 0 012-2h2m8 9h2a2 2 0 002-2V7a2 2 0 00-2-2h-2M7 19h10',
- });
-
- if (view === 'welcome' && !isLocalSession) {
- return (
- <>
- {nav}
- <PageWelcome
- testId="rewards-welcome"
- accent="coral"
- icon="🎁"
- eyebrow={t('rewards.welcome.eyebrow')}
- title={t('rewards.welcome.title')}
- description={t('rewards.welcome.body')}
- ctas={[
- {
- label: t('rewards.welcome.ctaView'),
- icon: '🎁',
- onClick: () => setView('main'),
- testId: 'rewards-welcome-cta-view',
- },
- ]}
- featuresHeading={t('rewards.welcome.featsLabel')}
- features={[
- {
- icon: '⭐',
- title: t('rewards.welcome.feat1Title'),
- description: t('rewards.welcome.feat1Body'),
- },
- {
- icon: '🔥',
- title: t('rewards.welcome.feat2Title'),
- description: t('rewards.welcome.feat2Body'),
- },
- {
- icon: '🎟️',
- title: t('rewards.welcome.feat3Title'),
- description: t('rewards.welcome.feat3Body'),
- },
- ]}
- />
- </>
- );
- }
+ const nav = useMemo(
+ () => (
+ <SidebarContent>
+ <div className="h-full overflow-hidden">
+ <TwoPaneNav
+ ariaLabel={t('rewards.title')}
+ selected={view}
+ onSelect={setView}
+ groups={[
+ {
+ items: [
+ {
+ value: 'rewards',
+ label: t('rewards.title'),
+ icon: <LuGift className="h-4 w-4" />,
+ },
+ {
+ value: 'referrals',
+ label: t('rewards.referrals'),
+ icon: <LuUsers className="h-4 w-4" />,
+ },
+ {
+ value: 'redeem',
+ label: t('rewards.coupons'),
+ icon: <LuTicket className="h-4 w-4" />,
+ },
+ ],
+ },
+ ]}
+ />
+ </div>
+ </SidebarContent>
+ ),
+ [t, view, setView]
+ );
if (isLocalSession) {
return (
- <div className="min-h-full px-4 pt-6 pb-10">
- <div className="mx-auto max-w-3xl space-y-4">
- <EmptyStateCard
- className="shadow-soft"
- icon={
- <svg
- className="h-7 w-7 text-primary-500"
- fill="none"
- viewBox="0 0 24 24"
- stroke="currentColor"
- strokeWidth={1.5}
- aria-hidden="true">
- <path
- strokeLinecap="round"
- strokeLinejoin="round"
- d="M12 8v8m0-8l-3-3m3 3l3-3M8 14H6a2 2 0 01-2-2V7a2 2 0 012-2h2m8 9h2a2 2 0 002-2V7a2 2 0 00-2-2h-2M7 19h10"
- />
- </svg>
- }
- title={t('rewards.title')}
- description={t('rewards.localUnavailable')}
- actionLabel={t('rewards.localUnavailableCta')}
- onAction={() => navigate('/settings/account')}
- />
- </div>
+ <div className="h-full overflow-y-auto p-4">
+ <EmptyStateCard
+ className="shadow-soft"
+ icon={
+ <svg
+ className="h-7 w-7 text-primary-500"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ strokeWidth={1.5}
+ aria-hidden="true">
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ d="M12 8v8m0-8l-3-3m3 3l3-3M8 14H6a2 2 0 01-2-2V7a2 2 0 012-2h2m8 9h2a2 2 0 002-2V7a2 2 0 00-2-2h-2M7 19h10"
+ />
+ </svg>
+ }
+ title={t('rewards.title')}
+ description={t('rewards.localUnavailable')}
+ actionLabel={t('rewards.localUnavailableCta')}
+ onAction={() => navigate('/settings/account')}
+ />
</div>
);
}
+ const page =
+ view === 'referrals'
+ ? {
+ title: t('rewards.referralSection.title'),
+ description: t('rewards.referralSection.subtitle'),
+ body: <RewardsReferralsTab />,
+ }
+ : view === 'redeem'
+ ? {
+ title: t('rewards.coupon.title'),
+ description: t('rewards.coupon.subtitle'),
+ body: <RewardsRedeemTab />,
+ }
+ : {
+ title: t('rewards.title'),
+ description: t('rewards.header.desc'),
+ body: (
+ <RewardsCommunityTab
+ error={error}
+ isLoading={isLoading}
+ onRetry={handleRetry}
+ onSilentRefresh={handleSilentRefresh}
+ snapshot={rewardsSnapshot}
+ />
+ ),
+ };
+
return (
<>
{nav}
- <div className="min-h-full px-4 pt-6 pb-10">
- <div className="mx-auto max-w-3xl space-y-4">
- <PageSectionHeader
- title={t('rewards.title')}
- description={t('rewards.header.desc')}
- tabs={
- <ChipTabs<RewardsTab>
- items={[
- { id: 'referrals', label: t('rewards.referrals') },
- { id: 'rewards', label: t('rewards.title') },
- { id: 'redeem', label: t('rewards.coupons') },
- ]}
- value={selectedTab}
- onChange={handleTabChange}
- className="flex flex-wrap gap-1.5"
- />
- }
- />
-
- {selectedTab === 'referrals' ? (
- <RewardsReferralsTab />
- ) : selectedTab === 'redeem' ? (
- <RewardsRedeemTab />
- ) : (
- <RewardsCommunityTab
- error={error}
- isLoading={isLoading}
- onRetry={handleRetry}
- onSilentRefresh={handleSilentRefresh}
- snapshot={rewardsSnapshot}
- />
- )}
- </div>
+ {/* `p-4` is the gutter SettingsTabbedPage's full-bleed divider bleeds
+ through, and `h-full` is what makes the body actually scroll — the
+ content surface is `overflow-hidden`, so a `min-h-full` page (what
+ this was) grew past the card and clipped instead. */}
+ <div className="h-full p-4" data-testid="rewards-page">
+ <SettingsTabbedPage title={page.title} description={page.description}>
+ <div className="space-y-4">{page.body}</div>
+ </SettingsTabbedPage>
</div>
</>
);