Skip to content
Merged
14 changes: 10 additions & 4 deletions frontend/src/app/(learn)/(main)/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { serverApiFetch } from "@/lib/api-server";
import type { OwnerProfileView } from "@/shared/api/public-profile";
import { PublicProfileCard } from "@/components/profile/public-profile-card";
import { buttonVariants } from "@/components/ui/button";
import { ShareProfileButton } from "@/components/profile/share-profile-button";

export const metadata: Metadata = { title: "Profile" };

Expand All @@ -15,14 +16,19 @@ export default async function ProfilePage() {
<div className="w-full">
<header className="flex flex-col gap-6 border-b px-4 pb-7 pt-6 sm:flex-row sm:items-end sm:justify-between sm:px-6 lg:px-8">
<div>
<p className="mb-2 text-xs font-medium uppercase tracking-wide text-primary">Your learning identity</p>
<h1 className="text-[32px] leading-tight tracking-[-0.035em] sm:text-[40px]">Profile</h1>
<p className="mt-2 max-w-xl text-lg text-muted-foreground">
This is what the public sees on your shared profile page.
Who you are becoming, the milestones behind you, and where your learning goes next. Your shared profile page shows the same card, without your quiz average.
</p>
</div>
<Link href="/settings/profile" className={buttonVariants({ variant: "outline", size: "sm" })}>
Edit in settings
</Link>
{/* Page actions live here, not in the profile card: the card is what others see. */}
<div className="flex shrink-0 items-center gap-2">
<Link href="/settings/profile" className={buttonVariants({ variant: "outline", size: "sm" })}>
{owner.profilePublic ? "Edit in settings" : "Make profile public"}
</Link>
{owner.profilePublic ? <ShareProfileButton shareUrl={`/u/${owner.slug}`} /> : null}
</div>
</header>
<PublicProfileCard profile={owner} variant="owner" />
</div>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/u/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ async function fetchPublic(slug: string): Promise<PublicProfileView | null> {
function tagline(profile: PublicProfileView): string {
return (
[profile.headline, profile.learningInPublic ? "Learning in public" : null].filter(Boolean).join(" · ") ||
"A verified learning profile on Buildment."
"A verified learning profile on Edorax."
);
}

export async function generateMetadata({ params }: { params: Promise<Params> }): Promise<Metadata> {
const { slug } = await params;
const profile = await fetchPublic(slug);
if (!profile) return { title: "Profile not found · Buildment" };
const title = `${profile.name} · Buildment`;
if (!profile) return { title: "Profile not found · Edorax" };
const title = `${profile.name} · Edorax`;
const description = tagline(profile);
return {
title,
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/blocks/capstone-check/CapstoneCheckClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ApiError, apiFetch } from "@/lib/api-client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";
import { celebrate } from "@/lib/celebrate";
import type { SanitizedCapstoneCheckConfig } from "@/shared/blocks/capstone-check/schema";
import type { AutomatedCheckResult, CapstoneCheckState, CapstoneCheckView } from "@/shared/blocks/capstone-check/report";
import { CertificateCard } from "./CertificateCard";
Expand Down Expand Up @@ -162,13 +163,22 @@ export function CapstoneCheckClient({
const [busy, setBusy] = useState<"check" | "send" | null>(null);
const [showHistory, setShowHistory] = useState(false);
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
const cardRef = useRef<HTMLElement>(null);
const celebratedCheckIdRef = useRef<string | null>(
initialState?.checks[0]?.report?.completed ? initialState.checks[0].id : null
);

const running = latest?.status === "QUEUED" || latest?.status === "RUNNING";

const refresh = useCallback(async () => {
try {
const result = await apiFetch<{ state: CapstoneCheckState }>(`/api/v1/blocks/${encodeURIComponent(id)}/capstone`);
setState(result.state);
const newest = result.state.checks[0];
if (newest?.report?.completed && newest.id !== celebratedCheckIdRef.current) {
celebratedCheckIdRef.current = newest.id;
celebrate("medium", cardRef.current);
}
} catch {
// A failed poll is retried on the next tick.
}
Expand Down Expand Up @@ -214,6 +224,7 @@ export function CapstoneCheckClient({
setBusy("send");
try {
await apiFetch(`/api/v1/blocks/${encodeURIComponent(id)}/capstone/send`, { method: "POST", json: { checkId: latest.id } });
celebrate("small", cardRef.current);
await refresh();
} catch (caught) {
setError(caught instanceof ApiError ? caught.message : "Could not send it. Try again.");
Expand All @@ -226,7 +237,7 @@ export function CapstoneCheckClient({
const outOfChecks = state.remainingToday <= 0;

return (
<section className="not-prose my-6 border bg-card text-card-foreground" aria-labelledby={`capstone-${id}`}>
<section ref={cardRef} className="not-prose my-6 border bg-card text-card-foreground" aria-labelledby={`capstone-${id}`}>
<header className="space-y-2 border-b px-4 py-4 sm:px-6">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground">Capstone check</p>
<h3 id={`capstone-${id}`} className="font-heading text-lg font-bold leading-snug tracking-tight">{config.title}</h3>
Expand Down
26 changes: 23 additions & 3 deletions frontend/src/blocks/capstone-check/CertificateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { Award } from "lucide-react";
import { apiFetch } from "@/lib/api-client";
import { cn } from "@/lib/utils";
import { buttonVariants } from "@/components/ui/button";
import type { CertificateView, MyCertificateState } from "@/shared/lib/certificates";
import type { MyCertificateState } from "@/shared/lib/certificates";
import { RewardCelebrationDialog, type RewardCelebration } from "@/components/rewards/reward-celebration-dialog";

// Shown at the end of a finished course (and under a capstone check). Certificates are issued
// automatically, so this gives the learner the verify link and Add to LinkedIn at any time.

export function CertificateCard({ courseSlug }: { courseSlug: string }) {
const [state, setState] = useState<MyCertificateState | null>(null);
const [celebration, setCelebration] = useState<RewardCelebration | null>(null);

useEffect(() => {
let live = true;
Expand All @@ -29,12 +31,29 @@ export function CertificateCard({ courseSlug }: { courseSlug: string }) {

useEffect(() => {
if (!state?.eligibility.eligible || state.certificate) return;
let live = true;
const timer = window.setInterval(() => {
apiFetch<MyCertificateState>(`/api/v1/courses/${encodeURIComponent(courseSlug)}/certificate`)
.then(setState)
.then((result) => {
if (!live) return;
setState(result);
if (result.certificate) {
setCelebration({
size: "large",
icon: Award,
kicker: "Certificate issued",
title: result.certificate.title,
description: `Issued to ${result.certificate.recipientName}. Anyone can check it with code ${result.certificate.code}.`,
action: { label: "View certificate", href: `/verify/${result.certificate.code}` },
});
}
})
.catch(() => undefined);
}, 5000);
return () => window.clearInterval(timer);
return () => {
live = false;
window.clearInterval(timer);
};
}, [courseSlug, state?.certificate, state?.eligibility.eligible]);

if (!state || !state.eligibility.offered) return null;
Expand Down Expand Up @@ -68,6 +87,7 @@ export function CertificateCard({ courseSlug }: { courseSlug: string }) {
{state.eligibility.missing.map((item) => <li key={item}>{item}</li>)}
</ul>
)}
<RewardCelebrationDialog reward={celebration} onClose={() => setCelebration(null)} />
</section>
);
}
10 changes: 2 additions & 8 deletions frontend/src/components/learn/dashboard/leaderboard-card.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { toast } from "@/components/ui/app-toast";
import { useState, useTransition } from "react";
import { ChevronDown, Trophy } from "lucide-react";
import { Button } from "@/components/ui/button";
Expand Down Expand Up @@ -111,18 +112,16 @@ export function LeaderboardCard({
}) {
const [view, setView] = useState(initial);
const [courseId, setCourseId] = useState(initialCourseId);
const [error, setError] = useState<string | null>(null);
const [pending, startTransition] = useTransition();

if (!view || view.status === "disabled") return null;

function run(work: () => Promise<LeaderboardView | null>) {
setError(null);
startTransition(async () => {
try {
setView(await work());
} catch {
setError("Something went wrong. Please try again.");
toast("Something went wrong. Please try again.", "error");
}
});
}
Expand Down Expand Up @@ -235,11 +234,6 @@ export function LeaderboardCard({
</div>
</div>
)}
{error ? (
<p className="mt-3 text-xs text-destructive" role="alert">
{error}
</p>
) : null}
</div>
</section>
);
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/learn/dashboard/mentee-dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import { formatStudyAmount } from "@/lib/format-study-duration";
import { CourseCertificateLink } from "@/components/learn/course-certificate-link";
import { WeeklyGoalEditor } from "@/components/learn/dashboard/weekly-goal-editor";
import { WeeklyQuests } from "@/components/learn/dashboard/weekly-quests";
import { UnclaimedAchievementsBanner } from "@/components/learn/dashboard/unclaimed-achievements-banner";
import { LeagueGoalCard } from "@/components/learn/dashboard/league-goal-card";
import { WeeklyLeagueCelebration } from "@/components/learn/leaderboard/weekly-league-celebration";
import { CourseStageLine, LearningMomentum } from "@/components/learn/dashboard/gamification";
import { StarterOnboarding } from "@/components/learn/dashboard/starter-onboarding";
import { QuickGoalNudge } from "@/components/learn/dashboard/quick-goal-nudge";
Expand Down Expand Up @@ -533,6 +535,9 @@ export function MenteeDashboard({
{visibility.showQuickGoalNudge && !hasGoal && model.overview.chaptersCompleted > 0 ? (
<QuickGoalNudge />
) : null}
{showsGameElements(model.gamification) ? (
<UnclaimedAchievementsBanner unclaimed={model.unclaimedAchievements} />
) : null}
{visibility.showWeeklyQuests || visibility.showLeagueGoal ? (
<div className="space-y-4">
{visibility.showWeeklyQuests ? <WeeklyQuests /> : null}
Expand All @@ -552,6 +557,7 @@ export function MenteeDashboard({
) : null}
</div>
)}
<WeeklyLeagueCelebration view={model.leaderboard} />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"use client";

import { useEffect, useRef } from "react";
import Link from "next/link";
import { ArrowRight, Trophy } from "lucide-react";
import { buttonVariants } from "@/components/ui/button";
import { celebrate } from "@/lib/celebrate";

const STORAGE_PREFIX = "buildment:achievements-ready:";

export type UnclaimedAchievementsInfo = {
count: number;
totalCredits: number;
ids: string[];
};

/**
* Surfaces newly unlocked achievements right on the dashboard (and plays a gentle celebration
* once per newly unlocked set) so learners don't miss rewards waiting on `/profile`.
*/
export function UnclaimedAchievementsBanner({ unclaimed }: { unclaimed: UnclaimedAchievementsInfo | null | undefined }) {
const bannerRef = useRef<HTMLDivElement>(null);

useEffect(() => {
if (!unclaimed || unclaimed.count <= 0) return;
const key = STORAGE_PREFIX + unclaimed.ids.join(",");
try {
if (window.localStorage.getItem(key) === "1") return;
window.localStorage.setItem(key, "1");
} catch {
/* Ignore storage failures. */
}
const timer = window.setTimeout(() => {
if (bannerRef.current) celebrate("small", bannerRef.current);
}, 350);
return () => window.clearTimeout(timer);
}, [unclaimed]);

if (!unclaimed || unclaimed.count <= 0) return null;

const noun = unclaimed.count === 1 ? "achievement" : "achievements";
return (
<section
ref={bannerRef}
aria-label="Unclaimed achievements"
className="flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-brand-yellow/60 bg-brand-yellow/10 p-4 sm:px-5"
>
<div className="flex min-w-0 items-center gap-3">
<span className="grid size-10 shrink-0 place-items-center rounded-xl bg-brand-yellow text-[#0a0f2c]">
<Trophy className="size-5" aria-hidden />
</span>
<div className="min-w-0">
<p className="text-sm font-semibold text-foreground">
You unlocked {unclaimed.count} {noun}
</p>
<p className="text-xs text-muted-foreground">
+{unclaimed.totalCredits.toLocaleString()} Build Credits ready to claim on your profile.
</p>
</div>
</div>
<Link href="/profile#achievements-heading" className={buttonVariants({ size: "sm" })}>
Claim on profile
<ArrowRight className="size-4" aria-hidden />
</Link>
</section>
);
}
30 changes: 23 additions & 7 deletions frontend/src/components/learn/dashboard/weekly-quests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import { useEffect, useRef, useState } from "react";
import { useRouter } from "next/navigation";
import { CheckCircle2, Gift, X } from "lucide-react";
import { CheckCircle2, Gift, Trophy, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { InfoTip } from "@/components/ui/info-tip";
import { toast } from "@/components/ui/app-toast";
import { playFeedback } from "@/lib/sound-feedback";
import { celebrate } from "@/lib/celebrate";
import { RewardCelebrationDialog, type RewardCelebration } from "@/components/rewards/reward-celebration-dialog";
import type { WeeklyQuestsView } from "@/shared/api/quests";

// Weekly quests: a compact entry at the top of the dashboard; the full mission
Expand All @@ -17,6 +18,7 @@ export function WeeklyQuests() {
const [state, setState] = useState<WeeklyQuestsView | null>(null);
const [busy, setBusy] = useState<string | null>(null);
const [open, setOpen] = useState(false);
const [allCleared, setAllCleared] = useState<RewardCelebration | null>(null);

useEffect(() => {
let cancelled = false;
Expand All @@ -42,7 +44,7 @@ export function WeeklyQuests() {
if (!open && dialog.open) dialog.close();
}, [open]);

async function claim(id: string) {
async function claim(id: string, anchor: HTMLElement) {
setBusy(id);
try {
const res = await fetch(`/api/v1/learner/quests/${id}/claim`, { method: "POST" });
Expand All @@ -51,9 +53,22 @@ export function WeeklyQuests() {
toast(json?.message ?? "Could not claim this quest", "error");
return;
}
setState(json.data);
playFeedback("success");
toast("Quest reward claimed", "success");
const next = json.data as WeeklyQuestsView;
setState(next);
if (next.total > 0 && next.quests.every((quest) => quest.claimed)) {
setOpen(false);
setAllCleared({
size: "large",
icon: Trophy,
kicker: "Weekly quests cleared",
title: `All ${next.total} quests complete!`,
description: "You cleared every quest for this week. Fresh quests arrive Monday.",
action: { label: "Spend in rewards", href: "/rewards" },
});
} else {
celebrate("small", anchor);
toast("Quest reward claimed", "success");
}
router.refresh();
} catch {
toast("Could not claim this quest", "error");
Expand Down Expand Up @@ -157,7 +172,7 @@ export function WeeklyQuests() {
disabled={busy === quest.id}
loading={busy === quest.id}
loadingLabel="Claiming…"
onClick={() => void claim(quest.id)}
onClick={(event) => void claim(quest.id, event.currentTarget)}
>
Claim
</Button>
Expand All @@ -179,6 +194,7 @@ export function WeeklyQuests() {
})}
</ul>
</dialog>
<RewardCelebrationDialog reward={allCleared} onClose={() => setAllCleared(null)} />
</>
);
}
Loading
Loading