mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
Give every empty list one empty state and one add action
EmptyState now has a single action shape: centred at its own width on the 44 px tap floor, never stretched edge to edge on some pages and compact on others; the per-call-site size switch is gone, and the dashed card takes the card radius. While a list is empty its empty state carries the add action, so the header drops its own add button there (measurements, mood, medications, labs, vaccinations, documents, illness, check-ups, visits, procedures). The dashboard medication tile of an account without medications offers 'Add a medication' instead of 'no data in the chosen range'.
This commit is contained in:
1 parent
793c19e179
commit
005cb32ea8
30 files changed
+158
-65
No files matched your search
@@ -32,6 +32,7 @@
|
||||
* `findAllByType` reconciliation; the dashboard's `next/dynamic` for
|
||||
* the wrapper itself stays intact.
|
||||
*/
|
||||
import Link from "next/link";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useEffect, useMemo, useState, useRef } from "react";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
@@ -50,6 +51,8 @@ import { ComplianceInfoTip } from "@/components/medications/card-parts/complianc
|
||||
import { TileHeader } from "@/components/insights/tile-header";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { EmptyState } from "@/components/ui/empty-state";
|
||||
import { useRecordCapabilities } from "@/hooks/use-record-capabilities";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import {
|
||||
useDateFormatPreference,
|
||||
@@ -276,6 +279,22 @@ export function MedicationComplianceChart({
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
|
||||
// An empty compliance window means one of two things: no dose fell in it,
|
||||
// or there is no medication at all. The second is not "no data in the
|
||||
// chosen range" — it is a first step, so the tile offers it. The list
|
||||
// read is the medications page's own cell (usually warm already).
|
||||
const complianceEmpty = !isLoading && !isError && (data?.length ?? 0) === 0;
|
||||
const medicationList = useQuery({
|
||||
queryKey: queryKeys.medications(),
|
||||
queryFn: () => apiGet<{ id: string }[]>("/api/medications"),
|
||||
enabled: isAuthenticated && complianceEmpty,
|
||||
});
|
||||
const noMedications =
|
||||
complianceEmpty &&
|
||||
medicationList.isSuccess &&
|
||||
(medicationList.data?.length ?? 0) === 0;
|
||||
const { canWriteDomain } = useRecordCapabilities();
|
||||
|
||||
// v1.16.0 — report the settled query to the dashboard's shared
|
||||
// reveal gate (see `onDataReady` prop doc).
|
||||
//
|
||||
@@ -533,6 +552,24 @@ export function MedicationComplianceChart({
|
||||
actionContext={displayTitle}
|
||||
onAction={() => void refetch()}
|
||||
/>
|
||||
) : !hasData && noMedications ? (
|
||||
<EmptyState
|
||||
variant="plain"
|
||||
size="compact"
|
||||
data-slot="medication-compliance-no-medications"
|
||||
className="flex h-48 items-center justify-center"
|
||||
icon={<Pill className="size-4" />}
|
||||
title={t("medications.emptyTitle")}
|
||||
action={
|
||||
canWriteDomain("medications") ? (
|
||||
<Button asChild size="sm">
|
||||
<Link href="/medications/new">
|
||||
{t("charts.medicationsEmptyAction")}
|
||||
</Link>
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
) : !hasData ? (
|
||||
<div className="text-muted-foreground flex h-48 items-center justify-center text-sm">
|
||||
{t("charts.noData")}
|
||||
|
||||
Reference in new issue
Block a user