mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
refactor(medications): hand the lifecycle controls the medication
LifecycleManageBody takes the medication (id, name, active, course status) instead of one prop per field. The call site in medication-detail-tabs.tsx shrinks to one line, so the course status reaches the controls without growing a file the size ratchet holds.
This commit is contained in:
3 files changed
+19
-22
No files matched your search
@@ -923,12 +923,7 @@ export function MedicationDetailTabs({
|
||||
defaultOpen={false}
|
||||
>
|
||||
<div className="py-3">
|
||||
<LifecycleManageBody
|
||||
medicationId={id}
|
||||
medicationName={medication.name}
|
||||
active={medication.active}
|
||||
courseStatus={served.courseStatus}
|
||||
/>
|
||||
<LifecycleManageBody medication={medication} />
|
||||
</div>
|
||||
{/* v1.40 (#1024) — the courses: when it was taken, and a new
|
||||
course once the last one has ended. */}
|
||||
|
||||
@@ -66,10 +66,12 @@ describe("End is offered only for a running course", () => {
|
||||
<I18nProvider initialLocale="en">
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<LifecycleManageBody
|
||||
medicationId="med-1"
|
||||
medicationName="Example"
|
||||
active={true}
|
||||
courseStatus={courseStatus}
|
||||
medication={{
|
||||
id: "med-1",
|
||||
name: "Example",
|
||||
active: true,
|
||||
courseStatus,
|
||||
}}
|
||||
/>
|
||||
</QueryClientProvider>
|
||||
</I18nProvider>,
|
||||
|
||||
@@ -83,23 +83,23 @@ const PAUSE_HELPER_ID = "medication-detail-pause-helper";
|
||||
* Bare (no section / card chrome); the caller supplies its own grouping.
|
||||
*/
|
||||
export function LifecycleManageBody({
|
||||
medicationId,
|
||||
medicationName,
|
||||
active,
|
||||
courseStatus,
|
||||
medication,
|
||||
onAfterAction,
|
||||
}: {
|
||||
medicationId: string;
|
||||
medicationName: string;
|
||||
active: boolean;
|
||||
/** Where today sits in the course (server-resolved). */
|
||||
courseStatus?: CourseStatus;
|
||||
medication: {
|
||||
id: string;
|
||||
name: string;
|
||||
active: boolean;
|
||||
/** Where today sits in the course (server-resolved). */
|
||||
courseStatus?: CourseStatus;
|
||||
};
|
||||
onAfterAction?: () => void;
|
||||
}) {
|
||||
const { t } = useTranslations();
|
||||
const queryClient = useQueryClient();
|
||||
const medicationId = medication.id;
|
||||
|
||||
const [paused, setPaused] = useState(!active);
|
||||
const [paused, setPaused] = useState(!medication.active);
|
||||
const [tier1Busy, setTier1Busy] = useState(false);
|
||||
|
||||
async function tier1Toggle(pauseNext: boolean) {
|
||||
@@ -158,10 +158,10 @@ export function LifecycleManageBody({
|
||||
/>
|
||||
</label>
|
||||
|
||||
{canEndCourse(courseStatus) && (
|
||||
{canEndCourse(medication.courseStatus) && (
|
||||
<EndCourseControl
|
||||
medicationId={medicationId}
|
||||
medicationName={medicationName}
|
||||
medicationName={medication.name}
|
||||
onAfterAction={onAfterAction}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user