mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
fix(cycle): trim duplicate phase card, drop redundant disclaimers, tidy settings
Remove the duplicate phase-education card from the calendar tab, keeping the single instance under the wheel and surfacing its "you often notice this here" chip row there. Drop the generic prediction-estimate caption on the predictions tab for every goal except AVOID_PREGNANCY, where the contraceptive-safety caveat stays as a deliberate medical note. Stop rendering the associations-not-causes footer on the insights crosstab. In the cycle settings, align card-header descriptions with their titles, and remove the standalone cycle export + purge affordances now that cycle data rides the main export and account-level delete. Move the web-push enable action into the card header row.
This commit is contained in:
1 parent
8d716c617d
commit
546835a937
10 files changed
+134
-208
No files matched your search
@@ -103,18 +103,16 @@ describe("<PhaseEducationCard>", () => {
|
||||
expect(off).toContain("Still learning your cycle");
|
||||
});
|
||||
|
||||
it("omits the chip row in the compact variant", () => {
|
||||
it("renders the chip row when the user has symptoms clustering in this phase", () => {
|
||||
const html = render(
|
||||
<PhaseEducationCard
|
||||
compact
|
||||
phase="LUTEAL"
|
||||
symptomPatterns={[lutealCramps]}
|
||||
{...okGate}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain("progesterone");
|
||||
expect(html).not.toContain("cycle-phase-education-chips");
|
||||
// The compact variant still carries the log nudge.
|
||||
expect(html).toContain("cycle-phase-education-chips");
|
||||
expect(html).toContain("Log today");
|
||||
});
|
||||
});
|
||||
@@ -37,12 +37,13 @@ const emptyHistory: CycleHistoryResponse = {
|
||||
};
|
||||
|
||||
describe("<PredictionsPanel>", () => {
|
||||
it("renders the next-period range + the fixed disclaimer", () => {
|
||||
it("renders the next-period range and shows the disclaimer under the AVOID_PREGNANCY goal", () => {
|
||||
const html = render(
|
||||
<PredictionsPanel
|
||||
prediction={basePrediction}
|
||||
rawChartMode={false}
|
||||
history={emptyHistory}
|
||||
goal="AVOID_PREGNANCY"
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('data-slot="cycle-disclaimer"');
|
||||
@@ -51,6 +52,21 @@ describe("<PredictionsPanel>", () => {
|
||||
expect(html).toContain("–");
|
||||
});
|
||||
|
||||
it("suppresses the generic estimate disclaimer for non-AVOID_PREGNANCY goals", () => {
|
||||
const html = render(
|
||||
<PredictionsPanel
|
||||
prediction={basePrediction}
|
||||
rawChartMode={false}
|
||||
history={emptyHistory}
|
||||
goal="GENERAL_HEALTH"
|
||||
/>,
|
||||
);
|
||||
expect(html).not.toContain('data-slot="cycle-disclaimer"');
|
||||
expect(html).not.toContain("Estimates only, not medical advice.");
|
||||
// The range still renders.
|
||||
expect(html).toContain("–");
|
||||
});
|
||||
|
||||
it("renders the fertile window only when the prediction carries one", () => {
|
||||
const withFertile: CyclePrediction = {
|
||||
...basePrediction,
|
||||
|
||||
@@ -215,9 +215,6 @@ export function CyclePhaseCrosstab({
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
<p className="text-muted-foreground mt-3 text-xs">
|
||||
{t("cycle.insights.crosstab.footer")}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import { NativeSelect } from "@/components/ui/native-select";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import type { CycleGoal, CycleProfileDTO } from "./types";
|
||||
import { useUpdateCyclePrefs, useDeleteAllCycleData } from "./use-cycle";
|
||||
import { useUpdateCyclePrefs } from "./use-cycle";
|
||||
|
||||
/**
|
||||
* v1.15.0 — the single-page cycle settings form.
|
||||
@@ -50,8 +50,6 @@ function numOrEmpty(v: number | null): string {
|
||||
export function CycleSettings({ profile }: { profile: CycleProfileDTO }) {
|
||||
const { t } = useTranslations();
|
||||
const update = useUpdateCyclePrefs();
|
||||
const purge = useDeleteAllCycleData();
|
||||
const [confirmingPurge, setConfirmingPurge] = useState(false);
|
||||
|
||||
const [goal, setGoal] = useState<CycleGoal>(profile.goal);
|
||||
const [rawChartMode, setRawChartMode] = useState(profile.rawChartMode);
|
||||
@@ -228,87 +226,10 @@ export function CycleSettings({ profile }: { profile: CycleProfileDTO }) {
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<Separator />
|
||||
|
||||
{/* Data export / delete */}
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm font-medium">{t("cycle.settings.dataTitle")}</p>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{t("cycle.settings.dataDescription")}
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2 pt-1">
|
||||
<Button variant="outline" size="sm" asChild>
|
||||
<a href="/api/export/health-record" download>
|
||||
{t("cycle.settings.export")}
|
||||
</a>
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" asChild>
|
||||
<Link href="/settings/account">
|
||||
{t("cycle.settings.deleteData")}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Cycle-only hard purge (post-Dobbs threat model): removes every
|
||||
cycle row + the cycle audit trail + reminder ledger, distinct
|
||||
from the account-level delete. Two-step confirm — no accidental
|
||||
destructive tap. */}
|
||||
<div className="border-destructive/30 mt-3 space-y-2 rounded-md border p-3">
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{t("cycle.settings.purgeDescription")}
|
||||
</p>
|
||||
{confirmingPurge ? (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-sm font-medium" role="alert">
|
||||
{t("cycle.settings.purgeConfirm")}
|
||||
</span>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
disabled={purge.isPending}
|
||||
onClick={async () => {
|
||||
try {
|
||||
await purge.mutateAsync();
|
||||
} finally {
|
||||
setConfirmingPurge(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{purge.isPending ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin motion-reduce:animate-none" />
|
||||
) : null}
|
||||
{t("cycle.settings.purgeConfirmAction")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setConfirmingPurge(false)}
|
||||
>
|
||||
{t("cycle.settings.purgeCancel")}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="text-destructive border-destructive/40 hover:bg-destructive/10"
|
||||
onClick={() => setConfirmingPurge(true)}
|
||||
>
|
||||
{t("cycle.settings.purgeData")}
|
||||
</Button>
|
||||
)}
|
||||
{purge.isSuccess ? (
|
||||
<span className="text-muted-foreground text-sm" role="status">
|
||||
{t("cycle.settings.purgeDone")}
|
||||
</span>
|
||||
) : null}
|
||||
{purge.isError ? (
|
||||
<span className="text-destructive text-sm" role="alert">
|
||||
{t("cycle.settings.purgeError")}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{/* Cycle data export + delete live with the main Settings → Export and
|
||||
Account surfaces (cycle rows ride the full-backup export and the
|
||||
account-level delete), so the standalone affordances are not
|
||||
duplicated here. */}
|
||||
|
||||
<div className="flex items-center justify-end gap-3 pt-2">
|
||||
{update.isSuccess ? (
|
||||
|
||||
@@ -208,11 +208,11 @@ export function CycleView() {
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Compact phase-education card beneath the wheel — chip row omitted
|
||||
here (compact); the full card lives on the calendar tab. */}
|
||||
{/* Phase-education card beneath the wheel — the single instance,
|
||||
including the "you often notice this here" chip row sourced from
|
||||
the user's own symptom-by-phase history. */}
|
||||
{!loading && !calendarError ? (
|
||||
<PhaseEducationCard
|
||||
compact
|
||||
animate={play}
|
||||
phase={wheel.phase}
|
||||
symptomPatterns={insights.data?.symptomPatterns ?? []}
|
||||
@@ -241,16 +241,6 @@ export function CycleView() {
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="calendar" className="mt-4 space-y-4">
|
||||
{!loading && !calendarError ? (
|
||||
<PhaseEducationCard
|
||||
phase={wheel.phase}
|
||||
symptomPatterns={insights.data?.symptomPatterns ?? []}
|
||||
predictionEnabled={calProfile?.predictionEnabled ?? false}
|
||||
rawChartMode={calProfile?.rawChartMode ?? false}
|
||||
cyclesObserved={calProfile?.cyclesObserved ?? 0}
|
||||
onLogToday={() => openSheet(today)}
|
||||
/>
|
||||
) : null}
|
||||
<Card>
|
||||
<CardContent className="py-4">
|
||||
{loading ? (
|
||||
@@ -292,6 +282,7 @@ export function CycleView() {
|
||||
rawChartMode={calendar.data?.profile.rawChartMode ?? false}
|
||||
history={history.data}
|
||||
fallbackDisclaimer={disclaimerText}
|
||||
goal={goal}
|
||||
/>
|
||||
<CycleHistoryChart history={history.data} animate={play} />
|
||||
<BbtChart
|
||||
|
||||
@@ -51,8 +51,6 @@ export interface PhaseEducationCardProps {
|
||||
onLogToday: () => void;
|
||||
/** Ride the wheel's once-per-session reveal — no independent animation. */
|
||||
animate?: boolean;
|
||||
/** Compact variant beneath the wheel (tighter padding, no chip row). */
|
||||
compact?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
@@ -64,7 +62,6 @@ export function PhaseEducationCard({
|
||||
cyclesObserved,
|
||||
onLogToday,
|
||||
animate = false,
|
||||
compact = false,
|
||||
className,
|
||||
}: PhaseEducationCardProps) {
|
||||
const { t } = useTranslations();
|
||||
@@ -118,8 +115,7 @@ export function PhaseEducationCard({
|
||||
aria-label={t("cycle.phaseEducation.title")}
|
||||
style={{ "--tile-hue": hue } as React.CSSProperties}
|
||||
className={cn(
|
||||
"wellness-tile rounded-xl",
|
||||
compact ? "px-4 py-4" : "px-5 py-5",
|
||||
"wellness-tile rounded-xl px-5 py-5",
|
||||
animate && "wellness-tile-rise",
|
||||
className,
|
||||
)}
|
||||
@@ -159,10 +155,9 @@ export function PhaseEducationCard({
|
||||
{t(PHASE_WHATS_HAPPENING_KEY[phase as CyclePhase])}
|
||||
</p>
|
||||
|
||||
{/* Zone 3 — the user's OWN clustered symptoms for this phase. The
|
||||
compact variant under the wheel omits the chip row to stay light;
|
||||
the calendar-tab variant shows it. */}
|
||||
{!compact && chips.length > 0 ? (
|
||||
{/* Zone 3 — the user's OWN clustered symptoms for this phase
|
||||
("you often notice this here"). */}
|
||||
{chips.length > 0 ? (
|
||||
<div className="mt-4">
|
||||
<p className="text-muted-foreground text-xs font-medium">
|
||||
{t("cycle.phaseEducation.commonHere")}
|
||||
|
||||
@@ -53,6 +53,10 @@ export interface PredictionsPanelProps {
|
||||
history: CycleHistoryResponse | undefined;
|
||||
/** Fallback disclaimer when no prediction carries one. */
|
||||
fallbackDisclaimer?: string;
|
||||
/** The active cycle goal — only AVOID_PREGNANCY surfaces the (deliberate)
|
||||
* contraceptive-safety caveat here; every other goal drops the generic
|
||||
* "predictions are estimates" line so it does not repeat under every graph. */
|
||||
goal?: string;
|
||||
}
|
||||
|
||||
export function PredictionsPanel({
|
||||
@@ -60,10 +64,18 @@ export function PredictionsPanel({
|
||||
rawChartMode,
|
||||
history,
|
||||
fallbackDisclaimer,
|
||||
goal,
|
||||
}: PredictionsPanelProps) {
|
||||
const { t } = useTranslations();
|
||||
|
||||
const disclaimer = prediction?.disclaimer ?? fallbackDisclaimer ?? "";
|
||||
// Only the AVOID_PREGNANCY goal shows a disclaimer here: it surfaces the
|
||||
// fertile window, so the stronger "not a contraceptive method" caveat is a
|
||||
// deliberate medical safety note. For all other goals the generic
|
||||
// estimate-caveat is suppressed (it already lives once with the data).
|
||||
const disclaimer =
|
||||
goal === "AVOID_PREGNANCY"
|
||||
? (prediction?.disclaimer ?? fallbackDisclaimer ?? "")
|
||||
: "";
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
|
||||
@@ -335,27 +335,6 @@ export function useDeleteDayLog() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hard-delete EVERY cycle row the user owns (day-logs, cycles, predictions,
|
||||
* the cycle audit trail, and the cycle reminder-delivery ledger rows). The
|
||||
* privacy "purge" the post-Dobbs threat model promises — distinct from the
|
||||
* per-row soft-delete. Invalidates the whole cycle prefix + the nav gate.
|
||||
*/
|
||||
export function useDeleteAllCycleData() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
const res = await fetch("/api/cycle/all", { method: "DELETE" });
|
||||
if (!res.ok) throw new Error(`Request failed: ${res.status}`);
|
||||
return unwrap<{ purged: boolean }>(res);
|
||||
},
|
||||
onSuccess: () => {
|
||||
void invalidateKeys(qc, cycleDependentKeys);
|
||||
void qc.invalidateQueries({ queryKey: queryKeys.authMe() });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export interface CyclePrefsPatch {
|
||||
enabled?: boolean;
|
||||
goal?: CycleProfileDTO["goal"];
|
||||
|
||||
@@ -66,22 +66,32 @@ export function SettingsCardHeader({
|
||||
className,
|
||||
}: SettingsCardHeaderProps) {
|
||||
return (
|
||||
<header className={cn("space-y-1", className)}>
|
||||
<div className="flex flex-wrap items-start justify-between gap-2">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Icon className="text-primary h-5 w-5 shrink-0" aria-hidden="true" />
|
||||
<h2 id={titleId} className="text-lg font-semibold">
|
||||
{title}
|
||||
</h2>
|
||||
{titleAccessory}
|
||||
<header className={cn("flex items-start gap-2", className)}>
|
||||
<Icon
|
||||
className="text-primary mt-0.5 h-5 w-5 shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{/* Title + description share one column to the RIGHT of the icon, so the
|
||||
description left-aligns with the title rather than slipping back under
|
||||
the icon gutter. */}
|
||||
<div className="min-w-0 flex-1 space-y-1">
|
||||
<div className="flex flex-wrap items-start justify-between gap-2">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<h2 id={titleId} className="text-lg font-semibold">
|
||||
{title}
|
||||
</h2>
|
||||
{titleAccessory}
|
||||
</div>
|
||||
{status ? (
|
||||
<div className="flex shrink-0 items-center gap-2">{status}</div>
|
||||
) : null}
|
||||
</div>
|
||||
{status ? <div className="flex shrink-0 items-center gap-2">{status}</div> : null}
|
||||
{description ? (
|
||||
<div className="text-muted-foreground space-y-1 text-xs">
|
||||
{description}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
{description ? (
|
||||
<div className="text-muted-foreground space-y-1 text-xs">
|
||||
{description}
|
||||
</div>
|
||||
) : null}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -155,73 +155,80 @@ export function WebPushCard() {
|
||||
}
|
||||
}
|
||||
|
||||
// The primary action sits in the header row (right of the title) rather than
|
||||
// bottom-left, so an inactive card does not waste a wide empty band before
|
||||
// its enable button. The loading spinner rides the same slot; the
|
||||
// unsupported / denied notices stay in the body.
|
||||
const headerAction = loading ? (
|
||||
<Loader2 className="text-muted-foreground h-4 w-4 animate-spin motion-reduce:animate-none" />
|
||||
) : !isSupported || isDenied ? null : (
|
||||
<div className="flex flex-wrap items-center justify-end gap-2">
|
||||
{isSubscribed ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="min-h-11"
|
||||
onClick={handleUnsubscribe}
|
||||
disabled={actionLoading}
|
||||
>
|
||||
{actionLoading && (
|
||||
<Loader2 className="mr-1 h-3.5 w-3.5 animate-spin motion-reduce:animate-none" />
|
||||
)}
|
||||
{t("settings.webPushUnsubscribe")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="min-h-11"
|
||||
onClick={handleSubscribe}
|
||||
disabled={actionLoading}
|
||||
>
|
||||
{actionLoading ? (
|
||||
<Loader2 className="mr-1 h-3.5 w-3.5 animate-spin motion-reduce:animate-none" />
|
||||
) : (
|
||||
<BellRing className="mr-1 h-3.5 w-3.5" />
|
||||
)}
|
||||
{t("settings.webPushSubscribe")}
|
||||
</Button>
|
||||
)}
|
||||
{isSubscribed && (
|
||||
<TestConnectionButton endpoint="/api/notifications/web-push/test" />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="bg-card border-border rounded-xl border p-6">
|
||||
<SettingsCardHeader
|
||||
icon={BellRing}
|
||||
title={t("settings.webPush")}
|
||||
description={t("settings.webPushDescription")}
|
||||
status={headerAction}
|
||||
/>
|
||||
|
||||
<div className="mt-4 space-y-4">
|
||||
{loading ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<Loader2 className="text-muted-foreground h-4 w-4 animate-spin motion-reduce:animate-none" />
|
||||
</div>
|
||||
) : !isSupported ? (
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{t("settings.webPushNotSupported")}
|
||||
</p>
|
||||
) : isDenied ? (
|
||||
<p className="text-destructive text-sm">
|
||||
{t("settings.webPushDenied")}
|
||||
</p>
|
||||
) : (
|
||||
<div className="flex flex-wrap items-start gap-2">
|
||||
{isSubscribed ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="min-h-11"
|
||||
onClick={handleUnsubscribe}
|
||||
disabled={actionLoading}
|
||||
>
|
||||
{actionLoading && (
|
||||
<Loader2 className="mr-1 h-3.5 w-3.5 animate-spin motion-reduce:animate-none" />
|
||||
)}
|
||||
{t("settings.webPushUnsubscribe")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="min-h-11"
|
||||
onClick={handleSubscribe}
|
||||
disabled={actionLoading}
|
||||
>
|
||||
{actionLoading ? (
|
||||
<Loader2 className="mr-1 h-3.5 w-3.5 animate-spin motion-reduce:animate-none" />
|
||||
) : (
|
||||
<BellRing className="mr-1 h-3.5 w-3.5" />
|
||||
)}
|
||||
{t("settings.webPushSubscribe")}
|
||||
</Button>
|
||||
)}
|
||||
{isSubscribed && (
|
||||
<TestConnectionButton endpoint="/api/notifications/web-push/test" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{(!loading && !isSupported) || (!loading && isDenied) || msg ? (
|
||||
<div className="mt-4 space-y-4">
|
||||
{!loading && !isSupported ? (
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{t("settings.webPushNotSupported")}
|
||||
</p>
|
||||
) : !loading && isDenied ? (
|
||||
<p className="text-destructive text-sm">
|
||||
{t("settings.webPushDenied")}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{msg && (
|
||||
<p
|
||||
role="alert"
|
||||
className={`text-sm ${msgType === "success" ? "text-success" : "text-destructive"}`}
|
||||
>
|
||||
{msg}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{msg && (
|
||||
<p
|
||||
role="alert"
|
||||
className={`text-sm ${msgType === "success" ? "text-success" : "text-destructive"}`}
|
||||
>
|
||||
{msg}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user