SPB Git

Repository Public

FollowupsPage.tsx 5.4 KB 120 lines tsx

1// SP Mail Next — écran « Suivis » : rappels échus (à traiter) et à venir, dans toutes les boîtes ; terminer, relancer,2// replanifier, annuler, ouvrir la conversation.3import { useEffect } from "react"4import { t } from "../../i18n"5import { displayName } from "../../mail/address"6import { mailboxAddress } from "../../next/nav"7import { remindersCollection, splitReminders, type Reminder } from "../../next/snooze"8import { cancelReminder, fmtWhen, markReminderDone, openRearm, threadLink } from "../../next/snoozeUi"9import { S } from "../../state/app"10import { linkProps } from "../../state/session"11import { shallowEqual, useStore } from "../../state/store"12import { Icon } from "../kit"13import { WhenError, WhenSkeleton, inboxHref } from "./SnoozedPage"14import "./snooze.css"1516function Item({ r, many, online }: { r: Reminder; many: boolean; online: boolean }) {17  const subject = r.subject.trim() || t("nx.snooze.noSubject")18  const who = r.counterpart ? displayName(r.counterpart) : t("nx.snooze.unknown")19  const href = threadLink(r, false)20  const due = r.status === "due"21  const body = (22    <>23      <span className="nx-when-who truncate">{who}</span>24      <span className="nx-when-subject truncate">{subject}</span>25    </>26  )27  return (28    <li className={`nx-when-item${due ? " due" : ""}`} data-testid="followup-item" data-status={r.status} data-subject={subject}>29      <span className="nx-when-main">30        {href ? (31          <a {...linkProps(href)} className="nx-when-link" title={t("nx.when.openMessage", { subject })}>32            {body}33          </a>34        ) : (35          <span className="nx-when-link">{body}</span>36        )}37        {r.note ? <span className="nx-when-note">{r.note}</span> : null}38        <span className="nx-meta nx-when-meta">39          <Icon name="alarm" small />40          <span>{t(due ? "nx.followups.dueSince" : "nx.followups.dueOn", { date: fmtWhen(due ? (r.fired_at ?? r.due_at) : r.due_at) })}</span>41          {r.only_if_no_reply && !due ? <span>· {t("nx.followups.ifNoReply")}</span> : null}42          {many ? <span className="truncate nx-when-box">· {mailboxAddress(r.mailbox_id)}</span> : null}43        </span>44      </span>45      <span className="nx-when-actions">46        <button type="button" className={`btn small${due ? " primary" : ""}`} disabled={!online} aria-label={t("nx.followups.doneNamed", { subject })} onClick={() => void markReminderDone(r)}>47          {t("nx.followups.done")}48        </button>49        <button type="button" className="btn small" disabled={!online} aria-label={t(due ? "nx.followups.rearmNamed" : "nx.followups.rescheduleNamed", { subject })} onClick={() => openRearm(r)}>50          {due ? t("nx.followups.rearm") : t("nx.followups.reschedule")}51        </button>52        <button type="button" className="icon-btn" disabled={!online} aria-label={t("nx.followups.cancelNamed", { subject })} title={t("nx.followups.cancel")} onClick={() => void cancelReminder(r)}>53          <Icon name="close" />54        </button>55      </span>56    </li>57  )58}5960function Section({ id, title, items, none, many, online }: { id: string; title: string; items: Reminder[]; none: string; many: boolean; online: boolean }) {61  return (62    <section className="nx-when-section" aria-labelledby={id} data-section={id}>63      <h2 id={id} className="nx-when-heading">64        {title}65        {items.length ? <span className="badge">{items.length}</span> : null}66      </h2>67      {items.length ? (68        <ul className="nx-list nx-card nx-when-list">69          {items.map((r) => (70            <Item key={r.id} r={r} many={many} online={online} />71          ))}72        </ul>73      ) : (74        <p className="nx-note nx-when-none">{none}</p>75      )}76    </section>77  )78}7980export default function FollowupsPage() {81  const { items, loaded, error } = useStore(remindersCollection.store, (s) => ({ items: s.items, loaded: s.loaded, error: s.error }), shallowEqual)82  const online = useStore(S, (s) => s.online)83  const many = useStore(S, (s) => (s.me?.mailboxes.length ?? 0) > 1)84  useEffect(() => void remindersCollection.refresh(), [])85  const { due, pending } = splitReminders(items)86  return (87    <div className="nx-page nx-when-page" data-testid="followups-page">88      <header className="nx-head">89        <h1>{t("nx.followups.title")}</h1>90        {due.length + pending.length ? <span className="nx-sub">{t("nx.followups.sub", { due: due.length, pending: pending.length })}</span> : null}91      </header>92      {!online ? (93        <p className="banner" role="status">94          <Icon name="offline" small />95          <span>{t("nx.offline")}</span>96        </p>97      ) : null}98      {!loaded && error ? (99        <WhenError retry={() => void remindersCollection.refresh()} />100      ) : !loaded ? (101        <WhenSkeleton />102      ) : due.length + pending.length === 0 ? (103        <div className="nx-empty nx-card">104          <Icon name="alarm" />105          <p>{t("nx.followups.empty")}</p>106          <p className="nx-note">{t("nx.followups.emptyHint")}</p>107          <a {...linkProps(inboxHref())} className="btn">108            {t("nx.back")}109          </a>110        </div>111      ) : (112        <>113          <Section id="nx-followups-due" title={t("nx.followups.due")} items={due} none={t("nx.followups.noneDue")} many={many} online={online} />114          <Section id="nx-followups-pending" title={t("nx.followups.pending")} items={pending} none={t("nx.followups.nonePending")} many={many} online={online} />115        </>116      )}117    </div>118  )119}120
Files main
Menu

Theme