diff --git a/apps/app/frontend/src/app/admin/page.tsx b/apps/app/frontend/src/app/admin/page.tsx index 4e15c25..f0a427a 100644 --- a/apps/app/frontend/src/app/admin/page.tsx +++ b/apps/app/frontend/src/app/admin/page.tsx @@ -101,6 +101,11 @@ export default async function Admin() { House of Prayer: the week, who prays when, rules, campaigns, testimonies› )} + {o?.modules.includes("prayer-requests") && me.activeRoles.some((r) => ["owner", "church_admin", "prayer_coordinator", "pastoral_care"].includes(r)) && ( + + Prayer requests: approval, escalations, replies, settings› + + )} Back to the App ); diff --git a/apps/app/frontend/src/app/admin/requests/page.tsx b/apps/app/frontend/src/app/admin/requests/page.tsx new file mode 100644 index 0000000..cc6adf0 --- /dev/null +++ b/apps/app/frontend/src/app/admin/requests/page.tsx @@ -0,0 +1,29 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { redirect } from "next/navigation"; +import { AdminRequests } from "@/components/requests/AdminRequests"; +import { loadApp, loadMe } from "@/lib/load"; + +export const metadata: Metadata = { title: "Prayer requests · Admin", robots: { index: false, follow: false } }; + +const COORDINATORS = ["owner", "church_admin", "prayer_coordinator"]; + +/** Prayer requests for the prayer team (APP-1.0-PLAN §4, §10): coordinators and Pastoral care, with 2FA. */ +export default async function AdminRequestsPage({ searchParams }: { searchParams: Promise<{ view?: string }> }) { + const [me, app, q] = await Promise.all([loadMe(), loadApp(), searchParams]); + if (!me || !me.mfa || !me.member.roles.some((r) => [...COORDINATORS, "pastoral_care"].includes(r))) redirect("/admin"); + const coordinator = me.member.roles.some((r) => COORDINATORS.includes(r)); + return ( +
+
+ ← Dashboard +

Prayer requests

+
+ {app.modules.includes("prayer-requests") ? ( + + ) : ( +

Prayer requests are switched off. An Owner or Church admin can switch them on in Settings → Modules.

+ )} +
+ ); +} diff --git a/apps/app/frontend/src/app/me/page.tsx b/apps/app/frontend/src/app/me/page.tsx index 63e1ab2..6bc313c 100644 --- a/apps/app/frontend/src/app/me/page.tsx +++ b/apps/app/frontend/src/app/me/page.tsx @@ -34,6 +34,9 @@ export default async function Me() { {app.modules.includes("house-of-prayer") && ( My prayer› )} + {app.modules.includes("prayer-requests") && ( + My prayer requests› + )} {roles.length > 0 && (

The App's admin

diff --git a/apps/app/frontend/src/app/me/requests/page.tsx b/apps/app/frontend/src/app/me/requests/page.tsx new file mode 100644 index 0000000..df7746b --- /dev/null +++ b/apps/app/frontend/src/app/me/requests/page.tsx @@ -0,0 +1,37 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { AppShell } from "@/components/AppShell"; +import { MyRequests } from "@/components/requests/MyRequests"; +import { loadMe, signInHref } from "@/lib/load"; +import { requireModule } from "@/lib/module"; +import type { MyRequest } from "@/lib/requests"; +import { backendGet } from "@/lib/prayerServer"; + +export const metadata: Metadata = { title: "My prayer requests", robots: { index: false, follow: false } }; + +/** The member's own prayer requests (APP-1.0-PLAN §4). */ +export default async function MyRequestsPage() { + await requireModule("prayer-requests"); + const me = await loadMe(); + if (!me) { + return ( + +

My prayer requests

+

Sign in to see your prayer requests.

Sign in
+
+ ); + } + const data = await backendGet<{ requests: MyRequest[] }>("/api/v1/me/requests"); + return ( + +

My prayer requests

+ {!data ? ( +

Your requests can't be loaded right now. Please try again in a minute.

+ ) : data.requests.length ? ( + + ) : ( +

You haven't asked for prayer yet.

Ask for prayer
+ )} +
+ ); +} diff --git a/apps/app/frontend/src/app/prayer/ask/page.tsx b/apps/app/frontend/src/app/prayer/ask/page.tsx new file mode 100644 index 0000000..053419c --- /dev/null +++ b/apps/app/frontend/src/app/prayer/ask/page.tsx @@ -0,0 +1,38 @@ +import type { Metadata } from "next"; +import { AppShell } from "@/components/AppShell"; +import { AskForm } from "@/components/requests/AskForm"; +import { firstName, loadMe, signInHref } from "@/lib/load"; +import { requireModule } from "@/lib/module"; +import type { RequestForm } from "@/lib/requests"; +import { backendGet } from "@/lib/prayerServer"; + +export const metadata: Metadata = { title: "Ask for prayer", robots: { index: false, follow: false } }; + +const FALLBACK: RequestForm = { anonymousAllowed: false, emergencyNumbers: [], closeAfterDays: 30 }; + +/** Ask for prayer (APP-1.0-PLAN §4). The emergency numbers show signed out too. */ +export default async function Ask() { + await requireModule("prayer-requests"); + const [me, form] = await Promise.all([loadMe(), backendGet("/api/v1/requests/form")]); + return ( + +

Ask for prayer

+ {me ? ( + + ) : ( + <> +
+

Sign in with your church account to ask for prayer. Only the people you choose will see it.

+ Sign in +
+ {(form?.emergencyNumbers.length ?? 0) > 0 && ( +
+

If you or someone else is in danger, call:

+ {form!.emergencyNumbers.map((n) =>

{n.label}: {n.number}

)} +
+ )} + + )} +
+ ); +} diff --git a/apps/app/frontend/src/app/prayer/page.tsx b/apps/app/frontend/src/app/prayer/page.tsx index b8e40bd..cf93217 100644 --- a/apps/app/frontend/src/app/prayer/page.tsx +++ b/apps/app/frontend/src/app/prayer/page.tsx @@ -3,7 +3,8 @@ import Link from "next/link"; import { AppShell } from "@/components/AppShell"; import { CampaignCard } from "@/components/prayer/CampaignCard"; import { PrayerClock } from "@/components/prayer/PrayerClock"; -import { loadMe } from "@/lib/load"; +import { redirect } from "next/navigation"; +import { loadApp, loadMe } from "@/lib/load"; import { requireModule } from "@/lib/module"; import { dayName } from "@/lib/prayer"; import { loadCampaign, loadDay, loadTestimonies } from "@/lib/prayerServer"; @@ -18,8 +19,11 @@ const DATE = /^\d{4}-\d{2}-\d{2}$/; * (`?day=`; `&slot=` opens that slot's booking sheet, after a sign-in), testimonies. */ export default async function Prayer({ searchParams }: { searchParams: Promise<{ day?: string; slot?: string }> }) { + const app = await loadApp(); + if (!app.modules.includes("house-of-prayer") && app.modules.includes("prayer-requests")) redirect("/prayer/requests"); await requireModule("house-of-prayer"); const q = await searchParams; + const requests = app.modules.includes("prayer-requests"); const [me, day, campaign, testimonies] = await Promise.all([ loadMe(), loadDay(q.day && DATE.test(q.day) ? q.day : null), @@ -34,6 +38,12 @@ export default async function Prayer({ searchParams }: { searchParams: Promise<{ {me && My prayer} {campaign && } + {requests && ( + + )} {day ? ( ) : ( diff --git a/apps/app/frontend/src/app/prayer/requests/page.tsx b/apps/app/frontend/src/app/prayer/requests/page.tsx new file mode 100644 index 0000000..c9e76cc --- /dev/null +++ b/apps/app/frontend/src/app/prayer/requests/page.tsx @@ -0,0 +1,38 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { AppShell } from "@/components/AppShell"; +import { SharedList } from "@/components/requests/SharedList"; +import { loadMe, signInHref } from "@/lib/load"; +import { requireModule } from "@/lib/module"; +import type { SharedRequest } from "@/lib/requests"; +import { backendGet } from "@/lib/prayerServer"; + +export const metadata: Metadata = { title: "Pray for others", robots: { index: false, follow: false } }; + +/** Requests shared with members (APP-1.0-PLAN §4): signed-in members only, never public. */ +export default async function Requests() { + await requireModule("prayer-requests"); + const me = await loadMe(); + const data = me ? await backendGet<{ requests: SharedRequest[] }>("/api/v1/requests") : null; + return ( + +
+

Pray for others

+ {me && My requests} +
+ Ask for prayer + {!me ? ( +
+

Prayer requests are shared only with the church's members. Sign in to see them and pray.

+ Sign in +
+ ) : !data ? ( +

The requests can't be loaded right now. Please try again in a minute.

+ ) : data.requests.length ? ( + + ) : ( +

No requests are shared right now.

+ )} +
+ ); +} diff --git a/apps/app/frontend/src/components/TabBar.tsx b/apps/app/frontend/src/components/TabBar.tsx index e1062b4..3fa93c1 100644 --- a/apps/app/frontend/src/components/TabBar.tsx +++ b/apps/app/frontend/src/components/TabBar.tsx @@ -5,18 +5,21 @@ import { usePathname } from "next/navigation"; import { BookOpen, CalendarDays, Flame, Home, UserRound } from "lucide-react"; import type { AppModule } from "@/lib/load"; -/** The bottom tab bar (APP-1.0-PLAN §1, P18): Home, Prayer, Events, Devotional, Me; only what's on. */ +/** + * The bottom tab bar (APP-1.0-PLAN §1, P18): Home, Prayer, Events, Devotional, Me; only what's on. + * Prayer shows with the House of Prayer or prayer requests (it opens requests when only they are on). + */ const TABS = [ - { href: "/", label: "Home", icon: Home, module: null }, - { href: "/prayer", label: "Prayer", icon: Flame, module: "house-of-prayer" }, - { href: "/events", label: "Events", icon: CalendarDays, module: "events" }, - { href: "/devotional", label: "Devotional", icon: BookOpen, module: "devotionals" }, - { href: "/me", label: "Me", icon: UserRound, module: null }, + { href: "/", label: "Home", icon: Home, modules: null }, + { href: "/prayer", label: "Prayer", icon: Flame, modules: ["house-of-prayer", "prayer-requests"] }, + { href: "/events", label: "Events", icon: CalendarDays, modules: ["events"] }, + { href: "/devotional", label: "Devotional", icon: BookOpen, modules: ["devotionals"] }, + { href: "/me", label: "Me", icon: UserRound, modules: null }, ] as const; export function TabBar({ modules }: { modules: AppModule[] }) { const path = usePathname(); - const tabs = TABS.filter((t) => !t.module || modules.includes(t.module)); + const tabs = TABS.filter((t) => !t.modules || t.modules.some((m) => modules.includes(m as AppModule))); return (