SPB Git

Repository Public

page.tsx 5.8 KB 114 lines tsx

1import { requireAdmin } from "@/server/session";2import { nowMs } from "@/server/clock";3import { listExceptions, listRules } from "@/server/booking/service";4import { fmtDateTime, minutesLabel } from "@/server/booking/tz";5import { ActionButton, ActionForm } from "@/components/admin/ActionForm";6import { exceptionAddAction, exceptionDeleteAction, rulesSaveAction } from "../../../actions";7import { PageTitle } from "../../../doc";89export const metadata = { title: "Disponibilités" };10const DAYS = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"];1112export default async function Availability() {13  await requireAdmin();14  const rules = listRules();15  const exceptions = listExceptions(nowMs() - 24 * 3600_000);16  const text = (wd: number) =>17    rules18      .filter((r) => r.weekday === wd)19      .map((r) => `${minutesLabel(r.start_min)}-${minutesLabel(r.end_min)}`)20      .join(", ");21  return (22    <>23      <PageTitle title="Disponibilités" intro="Heures de travail hebdomadaires, congés, plages bloquées et ouvertures exceptionnelles. Tout est à l’heure du Québec ; les changements d’heure sont gérés automatiquement." />24      <div className="grid gap-6 lg:grid-cols-2">25        <section className="card p-4 sm:p-5" aria-labelledby="hours">26          <h2 id="hours" className="text-navy-900 font-serif text-xl">27            Heures de travail28          </h2>29          <p className="text-ink-700 mt-1 text-sm">Une ou plusieurs plages par jour, séparées par des virgules. Laissez vide pour un jour fermé.</p>30          <ActionForm action={rulesSaveAction} submitLabel="Enregistrer les heures" className="mt-4">31            <div className="flex flex-col gap-3">32              {DAYS.map((d, i) => (33                <div key={d} className="grid items-center gap-1 sm:grid-cols-[7rem_1fr]">34                  <label htmlFor={`wd${i + 1}`} className="text-ink-900 text-sm font-semibold">35                    {d}36                  </label>37                  <input id={`wd${i + 1}`} name={`wd${i + 1}`} defaultValue={text(i + 1)} className="field-input" placeholder="Fermé" inputMode="text" autoComplete="off" />38                </div>39              ))}40            </div>41            <p className="field-help mt-2">Exemple : 09:00-12:00, 13:00-17:00 (tranches de 15 minutes).</p>42          </ActionForm>43        </section>4445        <div className="flex flex-col gap-6">46          <section className="card p-4 sm:p-5" aria-labelledby="exc">47            <h2 id="exc" className="text-navy-900 font-serif text-xl">48              Bloquer une plage ou ajouter une ouverture49            </h2>50            <ActionForm action={exceptionAddAction} submitLabel="Ajouter" className="mt-4" resetOnOk>51              <div className="grid gap-4 sm:grid-cols-2">52                <div className="sm:col-span-2">53                  <label htmlFor="kind" className="field-label">54                    Type55                  </label>56                  <select id="kind" name="kind" className="field-input" defaultValue="block">57                    <option value="block">Bloquer (congé, indisponibilité)</option>58                    <option value="open">Ouvrir exceptionnellement (hors heures habituelles)</option>59                  </select>60                </div>61                <div>62                  <label htmlFor="start" className="field-label">63                    Début64                  </label>65                  <input id="start" name="start" type="datetime-local" required step={900} className="field-input" />66                </div>67                <div>68                  <label htmlFor="end" className="field-label">69                    Fin70                  </label>71                  <input id="end" name="end" type="datetime-local" step={900} className="field-input" />72                </div>73                <label className="flex min-h-11 items-center gap-3 sm:col-span-2">74                  <input type="checkbox" name="allday" className="accent-slate-500 h-5 w-5" />75                  <span className="text-ink-900 text-sm font-semibold">Journées entières (les heures sont ignorées)</span>76                </label>77                <div className="sm:col-span-2">78                  <label htmlFor="note" className="field-label">79                    Note (interne)80                  </label>81                  <input id="note" name="note" maxLength={200} className="field-input" placeholder="Vacances, formation…" />82                </div>83              </div>84            </ActionForm>85          </section>8687          <section className="card p-4 sm:p-5" aria-labelledby="list">88            <h2 id="list" className="text-navy-900 font-serif text-xl">89              Exceptions à venir90            </h2>91            {exceptions.length === 0 ? (92              <p className="text-ink-500 mt-2 text-sm">Aucune exception.</p>93            ) : (94              <ul className="divide-pale-300/70 mt-2 divide-y">95                {exceptions.map((e) => (96                  <li key={e.id} className="flex flex-wrap items-center justify-between gap-2 py-3">97                    <div className="min-w-0 text-sm">98                      <span className={`badge ${e.kind === "block" ? "badge-red" : "badge-green"}`}>{e.kind === "block" ? "Bloqué" : "Ouverture"}</span>99                      <p className="text-ink-900 mt-1 first-letter:uppercase">{fmtDateTime(e.start_utc)}</p>100                      <p className="text-ink-500">au {fmtDateTime(e.end_utc)}</p>101                      {e.note ? <p className="text-ink-500 text-xs">{e.note}</p> : null}102                    </div>103                    <ActionButton action={exceptionDeleteAction} hidden={{ id: e.id }} label="Retirer" className="abtn abtn-sm abtn-danger" />104                  </li>105                ))}106              </ul>107            )}108          </section>109        </div>110      </div>111    </>112  );113}114
Files main
Menu

Theme