Popup kit in components/ui.tsx; plan for popups everywhere
- ReadCard, Field, Fields and ModalButtons move from components/customer/ReadCard.tsx into components/ui.tsx, next to Modal, FormError and PageMessage. - useSubmit moves from components/install/shared.ts into components/ui.tsx. - The customer and install components import them from @/components/ui. No visible change. - docs/POPUPS-PLAN.md: every inline add or edit left in the Hub, and the plan for 2.16.0 and 2.17.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,8 +4,7 @@ import React, { useState } from "react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { PRODUCT_NAMES, type Product } from "@/lib/products";
|
||||
import type { Licence } from "@/lib/types";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { ModalButtons } from "./ReadCard";
|
||||
import { FormError, Modal, ModalButtons } from "@/components/ui";
|
||||
import { endOfDay, type Done } from "./shared";
|
||||
|
||||
/** A new licence for a product the church doesn't have yet. Accounts comes free with the first other one. */
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
import React, { useState } from "react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { centsFrom, day, money, randInput } from "@/lib/billing";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { Field, Fields, ModalButtons, ReadCard } from "./ReadCard";
|
||||
import { Field, Fields, FormError, Modal, ModalButtons, ReadCard } from "@/components/ui";
|
||||
import { ADDRESS_OPTIONS, changed, type AddressType, type CustomerBillingData, type Done } from "./shared";
|
||||
|
||||
/** Whether the included domain is due for renewal within 30 days. */
|
||||
|
||||
@@ -4,8 +4,7 @@ import React, { useState } from "react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { money } from "@/lib/billing";
|
||||
import type { Customer } from "@/lib/types";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { Field, Fields, ModalButtons, ReadCard } from "./ReadCard";
|
||||
import { Field, Fields, FormError, Modal, ModalButtons, ReadCard } from "@/components/ui";
|
||||
import { changed, type Done } from "./shared";
|
||||
|
||||
/** The church's AI allowance, shared by all its sites (Hub 2.0). Hub 2.14.0: its own card; the page holds the popup (the AI tile opens it too). */
|
||||
|
||||
@@ -6,8 +6,7 @@ import { api, errorText } from "@/lib/api";
|
||||
import { day, todayYmd } from "@/lib/billing";
|
||||
import type { Customer } from "@/lib/types";
|
||||
import { EmailList, emailsOf } from "@/components/EmailList";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { Field, Fields, ModalButtons, ReadCard } from "./ReadCard";
|
||||
import { Field, Fields, FormError, Modal, ModalButtons, ReadCard } from "@/components/ui";
|
||||
import { changed, type CustomerBillingData, type Done } from "./shared";
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,8 +9,7 @@ import { ago, fmtDate } from "@/lib/format";
|
||||
import { KEY_WHERE, PRODUCT_NAMES } from "@/lib/products";
|
||||
import { PLANS_BY_PRODUCT } from "@/lib/tiers";
|
||||
import type { Licence, LicenceStatus } from "@/lib/types";
|
||||
import { Badge, FormError, Menu, Modal } from "@/components/ui";
|
||||
import { ModalButtons } from "./ReadCard";
|
||||
import { Badge, FormError, Menu, Modal, ModalButtons } from "@/components/ui";
|
||||
import { changed, dateInput, endOfDay, reportText, suggestedTier, type BillingLicence, type Done, type Plan } from "./shared";
|
||||
|
||||
const HEARTBEAT = "The site picks it up with its next heartbeat (within 15 minutes).";
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
import React from "react";
|
||||
import { Pencil } from "lucide-react";
|
||||
|
||||
/** A card that shows settings as text, with an Edit button that opens their popup. */
|
||||
export function ReadCard({ title, onEdit, editLabel = "Edit", actions, children }: {
|
||||
title: React.ReactNode; onEdit?: () => void; editLabel?: string; actions?: React.ReactNode; children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<section className="card space-y-3">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h2 className="font-semibold">{title}</h2>
|
||||
<div className="flex gap-2">
|
||||
{actions}
|
||||
{onEdit && <button type="button" className="btn-secondary px-2.5 py-1.5" onClick={onEdit}><Pencil className="h-3.5 w-3.5" /> {editLabel}</button>}
|
||||
</div>
|
||||
</div>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
/** One "label: value" row of a read view; a blank value shows as a dash. */
|
||||
export function Field({ label, children, wide }: { label: string; children: React.ReactNode; wide?: boolean }) {
|
||||
const empty = children == null || children === "" || children === false;
|
||||
return (
|
||||
<div className={wide ? "sm:col-span-2" : ""}>
|
||||
<dt className="text-xs text-slate-500">{label}</dt>
|
||||
<dd className={`mt-0.5 break-words text-sm ${empty ? "text-slate-400" : "text-slate-900"}`}>{empty ? "—" : children}</dd>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Fields({ children }: { children: React.ReactNode }) {
|
||||
return <dl className="grid gap-3 sm:grid-cols-2">{children}</dl>;
|
||||
}
|
||||
|
||||
/** Save and Cancel at the foot of a popup form. `danger` for what can't be undone (Hub 2.15.0). */
|
||||
export function ModalButtons({ busy, onCancel, label = "Save", busyLabel = "Saving…", danger, disabled }: {
|
||||
busy: boolean; onCancel: () => void; label?: string; busyLabel?: string; danger?: boolean; disabled?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2 pt-1">
|
||||
<button className={danger ? "btn-danger" : "btn-primary"} disabled={busy || disabled} aria-busy={busy}>{busy ? busyLabel : label}</button>
|
||||
<button type="button" className="btn-secondary" onClick={onCancel}>Cancel</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,8 +3,7 @@
|
||||
import React, { useState } from "react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { CYCLE, day, type BillingCycle } from "@/lib/billing";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { Field, Fields, ModalButtons, ReadCard } from "./ReadCard";
|
||||
import { Field, Fields, FormError, Modal, ModalButtons, ReadCard } from "@/components/ui";
|
||||
import { changed, type CustomerBillingData, type Done } from "./shared";
|
||||
|
||||
/** The church's billing schedule: one for all its products. The page holds the popup (the Next invoice popup opens it too). */
|
||||
|
||||
@@ -3,7 +3,7 @@ import Link from "next/link";
|
||||
import { ago } from "@/lib/format";
|
||||
import { PRODUCT_NAMES, byProduct } from "@/lib/products";
|
||||
import type { Customer } from "@/lib/types";
|
||||
import { ReadCard } from "./ReadCard";
|
||||
import { ReadCard } from "@/components/ui";
|
||||
|
||||
/** The church's sites: where each product runs and when it last checked in. */
|
||||
export function SitesCard({ c }: { c: Customer }) {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { FormError, Modal, ModalButtons, useSubmit } from "@/components/ui";
|
||||
import { fromInput, toInput } from "@/components/servers";
|
||||
import { ModalButtons } from "@/components/customer/ReadCard";
|
||||
import { H, changed, post, useSubmit, withWarnings, type Done, type Install } from "./shared";
|
||||
import { H, changed, post, withWarnings, type Done, type Install } from "./shared";
|
||||
|
||||
/** Move an old (2.1.x) Events install onto the monorepo: `crosscode adopt` at a planned time. */
|
||||
export function AdoptModal({ x, onClose, onDone }: { x: Install; onClose: () => void; onDone: Done }) {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { ModalButtons } from "@/components/customer/ReadCard";
|
||||
import { post, useSubmit, withWarnings, type Done, type Install } from "./shared";
|
||||
import { FormError, Modal, ModalButtons, useSubmit } from "@/components/ui";
|
||||
import { post, withWarnings, type Done, type Install } from "./shared";
|
||||
|
||||
const PROFILES = [
|
||||
{ key: "small", label: "Small church: the essentials" },
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
import React, { useState } from "react";
|
||||
import { api } from "@/lib/api";
|
||||
import { ago, fmtDate } from "@/lib/format";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { ModalButtons } from "@/components/customer/ReadCard";
|
||||
import { useSubmit, type Detail, type Install } from "./shared";
|
||||
import { FormError, Modal, ModalButtons, useSubmit } from "@/components/ui";
|
||||
import { type Detail, type Install } from "./shared";
|
||||
|
||||
export type RemoveKind = "record" | "forget";
|
||||
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { FormError, Modal, ModalButtons, useSubmit } from "@/components/ui";
|
||||
import { fromInput, toInput } from "@/components/servers";
|
||||
import { ModalButtons } from "@/components/customer/ReadCard";
|
||||
import { H, post, productName, useSubmit, withWarnings, type Done, type Install, type UninstallPlan } from "./shared";
|
||||
import { H, post, productName, withWarnings, type Done, type Install, type UninstallPlan } from "./shared";
|
||||
|
||||
/**
|
||||
* Plan an uninstall of one product (2.12.0): the church's data is exported first, then the site
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
import React, { useState } from "react";
|
||||
import type { Release } from "@/lib/types";
|
||||
import { PRODUCT_NAMES } from "@/lib/products";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { FormError, Modal, ModalButtons, useSubmit } from "@/components/ui";
|
||||
import { fromInput, toInput } from "@/components/servers";
|
||||
import { ModalButtons } from "@/components/customer/ReadCard";
|
||||
import { H, changed, post, productName, useSubmit, withWarnings, type Done, type Install } from "./shared";
|
||||
import { H, changed, post, productName, withWarnings, type Done, type Install } from "./shared";
|
||||
|
||||
/**
|
||||
* Schedule an update of one install: at a time at least 4 hours away (the church gets notice), or
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, useState } from "react";
|
||||
import { api, ApiError, errorText } from "@/lib/api";
|
||||
import { api, ApiError } from "@/lib/api";
|
||||
import { PRODUCT_NAMES } from "@/lib/products";
|
||||
import type { Deployment, Job, ServerSummary } from "@/components/servers";
|
||||
|
||||
@@ -52,24 +51,6 @@ export async function post<T = { warnings?: string[] }>(path: string, body: Reco
|
||||
/** A success message with the Hub's warnings after it. */
|
||||
export const withWarnings = (ok: string, r?: { warnings?: string[] } | null) => `${ok}${r?.warnings?.length ? ` Note: ${r.warnings.join(" ")}` : ""}`;
|
||||
|
||||
/**
|
||||
* 2.7.1: one click is one job: `run` does nothing while the last one hasn't answered. A thrown
|
||||
* error lands in `error`, for the popup to show by its button.
|
||||
*/
|
||||
export function useSubmit() {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const inFlight = useRef(false);
|
||||
const run = async (fn: () => Promise<void>) => {
|
||||
if (inFlight.current) return;
|
||||
inFlight.current = true;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try { await fn(); } catch (e) { setError(errorText(e)); } finally { inFlight.current = false; setBusy(false); }
|
||||
};
|
||||
return { busy, error, run };
|
||||
}
|
||||
|
||||
/** 2.12.0: what an uninstall of this install takes with it, and what stops it. */
|
||||
export function uninstallPlan(d: Detail) {
|
||||
const x = d.deployment;
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
import React from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
|
||||
import { ChevronLeft, ChevronRight, MoreHorizontal, Search, X } from "lucide-react";
|
||||
import { ChevronLeft, ChevronRight, MoreHorizontal, Pencil, Search, X } from "lucide-react";
|
||||
import { errorText } from "@/lib/api";
|
||||
import type { LicenceStatus, Problem } from "@/lib/types";
|
||||
|
||||
const STATUS_TONE: Record<string, string> = {
|
||||
@@ -169,6 +170,71 @@ export function FormError({ error }: { error: string | null }) {
|
||||
return error ? <p role="alert" className="text-sm text-red-700">{error}</p> : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* One click is one job (2.7.1; shared since 2.16.0): `run` does nothing while the last one hasn't
|
||||
* answered. A thrown error lands in `error`, for the popup to show by its button.
|
||||
*/
|
||||
export function useSubmit() {
|
||||
const [busy, setBusy] = React.useState(false);
|
||||
const [error, setError] = React.useState<string | null>(null);
|
||||
const inFlight = React.useRef(false);
|
||||
const run = async (fn: () => Promise<void>) => {
|
||||
if (inFlight.current) return;
|
||||
inFlight.current = true;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try { await fn(); } catch (e) { setError(errorText(e)); } finally { inFlight.current = false; setBusy(false); }
|
||||
};
|
||||
return { busy, error, run };
|
||||
}
|
||||
|
||||
// Hub 2.14.0 (shared from 2.16.0): read views with an Edit that opens their popup.
|
||||
|
||||
/** A card that shows settings as text, with an Edit button that opens their popup. */
|
||||
export function ReadCard({ title, onEdit, editLabel = "Edit", actions, children }: {
|
||||
title: React.ReactNode; onEdit?: () => void; editLabel?: string; actions?: React.ReactNode; children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<section className="card space-y-3">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h2 className="font-semibold">{title}</h2>
|
||||
<div className="flex gap-2">
|
||||
{actions}
|
||||
{onEdit && <button type="button" className="btn-secondary px-2.5 py-1.5" onClick={onEdit}><Pencil className="h-3.5 w-3.5" /> {editLabel}</button>}
|
||||
</div>
|
||||
</div>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
/** One "label: value" row of a read view; a blank value shows as a dash. */
|
||||
export function Field({ label, children, wide }: { label: string; children: React.ReactNode; wide?: boolean }) {
|
||||
const empty = children == null || children === "" || children === false;
|
||||
return (
|
||||
<div className={wide ? "sm:col-span-2" : ""}>
|
||||
<dt className="text-xs text-slate-500">{label}</dt>
|
||||
<dd className={`mt-0.5 break-words text-sm ${empty ? "text-slate-400" : "text-slate-900"}`}>{empty ? "—" : children}</dd>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Fields({ children }: { children: React.ReactNode }) {
|
||||
return <dl className="grid gap-3 sm:grid-cols-2">{children}</dl>;
|
||||
}
|
||||
|
||||
/** Save and Cancel at the foot of a popup form. `danger` for what can't be undone (Hub 2.15.0). */
|
||||
export function ModalButtons({ busy, onCancel, label = "Save", busyLabel = "Saving…", danger, disabled }: {
|
||||
busy: boolean; onCancel: () => void; label?: string; busyLabel?: string; danger?: boolean; disabled?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2 pt-1">
|
||||
<button className={danger ? "btn-danger" : "btn-primary"} disabled={busy || disabled} aria-busy={busy}>{busy ? busyLabel : label}</button>
|
||||
<button type="button" className="btn-secondary" onClick={onCancel}>Cancel</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** A "⋯" button with a short list of actions under it. */
|
||||
export function Menu({ label = "More actions", items }: { label?: string; items: ({ label: string; onClick: () => void; danger?: boolean } | false | null | undefined)[] }) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
|
||||
Reference in New Issue
Block a user