fse-theme-default 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/AdminSettingsSections.astro +14 -0
- package/src/components/Sidebar.astro +26 -1
- package/src/layouts/Layout.astro +12 -1
- package/src/pages/admin/settings.astro +105 -0
- package/src/pages/emails/tenant-invite.astro +46 -0
- package/src/pages/maintenance.astro +32 -0
- package/src/pages/portal/new-tenant.astro +64 -0
- package/src/pages/portal.astro +90 -0
- package/src/pages/register.astro +56 -27
- package/src/pages/users.astro +70 -1
- package/src/types/pages.ts +40 -0
- package/src/types.ts +11 -0
- package/theme.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fse-theme-default",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Default theme for full_stack_engine apps \u2014 a complete Astro project: app shell, design system, auth pages, emails and the generic metadata-driven CRUD pages. Extend it with a child theme.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT OR Apache-2.0",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Extension point: the app's and modules' own sections of the admin
|
|
4
|
+
* settings page, rendered below maintenance mode. Filled through the
|
|
5
|
+
* `admin-settings-sections` slot: every
|
|
6
|
+
* `src/slots/admin-settings-sections/*.astro` of a child theme or a module.
|
|
7
|
+
* Their data comes through `page_context("admin/settings", ...)`, their
|
|
8
|
+
* forms post to the app's or module's own routes. Overriding this file
|
|
9
|
+
* replaces every contribution.
|
|
10
|
+
*/
|
|
11
|
+
import Slot from "fse-ssr/Slot.astro";
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<Slot name="admin-settings-sections" />
|
|
@@ -14,7 +14,7 @@ import NavLink from "./NavLink.astro";
|
|
|
14
14
|
import SidebarLinks from "./SidebarLinks.astro";
|
|
15
15
|
import type { ShellContext } from "../types";
|
|
16
16
|
|
|
17
|
-
const { t, nav_groups, user, lang_prefix } = ssr<ShellContext>();
|
|
17
|
+
const { t, nav_groups, user, lang_prefix, tenant, portal_url } = ssr<ShellContext>();
|
|
18
18
|
---
|
|
19
19
|
|
|
20
20
|
<div
|
|
@@ -65,6 +65,15 @@ const { t, nav_groups, user, lang_prefix } = ssr<ShellContext>();
|
|
|
65
65
|
</div>
|
|
66
66
|
|
|
67
67
|
<nav aria-label="Main" class="flex-1 overflow-y-auto px-3 py-3 space-y-0.5">
|
|
68
|
+
{tenant && (
|
|
69
|
+
<div class="sidebar-label px-3 pb-3 mb-1 border-b border-secondary-100">
|
|
70
|
+
<p class="text-xs font-semibold uppercase tracking-wide text-secondary-400 truncate">
|
|
71
|
+
{t.tenancy.nav.tenants ?? "Tenant"}
|
|
72
|
+
</p>
|
|
73
|
+
<p class="text-sm font-semibold text-secondary-900 truncate">{tenant.name}</p>
|
|
74
|
+
</div>
|
|
75
|
+
)}
|
|
76
|
+
|
|
68
77
|
<NavLink href={`${lang_prefix}/`} label={t.nav.home ?? "Home"}>
|
|
69
78
|
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
70
79
|
<path d="M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z"></path>
|
|
@@ -116,6 +125,22 @@ const { t, nav_groups, user, lang_prefix } = ssr<ShellContext>();
|
|
|
116
125
|
</NavLink>
|
|
117
126
|
)}
|
|
118
127
|
|
|
128
|
+
{user && user.can_admin_settings && (
|
|
129
|
+
<NavLink href={`${lang_prefix}/admin/settings`} label={t.nav.admin_settings ?? "Admin settings"}>
|
|
130
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
131
|
+
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path>
|
|
132
|
+
</svg>
|
|
133
|
+
</NavLink>
|
|
134
|
+
)}
|
|
135
|
+
|
|
136
|
+
{portal_url && (
|
|
137
|
+
<NavLink href={`${portal_url}/`} label={t.tenancy.nav.switch ?? "Switch tenant"}>
|
|
138
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
139
|
+
<path d="M7 16 3 12l4-4"></path><path d="M3 12h13"></path><path d="m17 8 4 4-4 4"></path><path d="M21 12H8"></path>
|
|
140
|
+
</svg>
|
|
141
|
+
</NavLink>
|
|
142
|
+
)}
|
|
143
|
+
|
|
119
144
|
{user && (
|
|
120
145
|
<NavLink href={`${lang_prefix}/settings`} label={t.nav.settings ?? "Settings"}>
|
|
121
146
|
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
package/src/layouts/Layout.astro
CHANGED
|
@@ -12,6 +12,7 @@ import type { SsrValue } from "fse-ssr/ssr";
|
|
|
12
12
|
import Head from "../components/Head.astro";
|
|
13
13
|
import Logo from "../components/Logo.astro";
|
|
14
14
|
import Sidebar from "../components/Sidebar.astro";
|
|
15
|
+
import type { ShellContext } from "../types";
|
|
15
16
|
|
|
16
17
|
interface Props {
|
|
17
18
|
title: string | SsrValue<string>;
|
|
@@ -19,7 +20,7 @@ interface Props {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const { title, sidebar = true } = Astro.props;
|
|
22
|
-
const { lang } = ssr();
|
|
23
|
+
const { t, lang, lang_prefix, user, maintenance_mode } = ssr<ShellContext>();
|
|
23
24
|
---
|
|
24
25
|
|
|
25
26
|
<!doctype html>
|
|
@@ -54,6 +55,16 @@ const { lang } = ssr();
|
|
|
54
55
|
</script>
|
|
55
56
|
</head>
|
|
56
57
|
<body class="bg-secondary-50 text-secondary-900">
|
|
58
|
+
{maintenance_mode && (
|
|
59
|
+
<div role="status" class="relative z-50 flex flex-wrap items-center justify-center gap-x-3 gap-y-1 px-4 py-2 text-sm font-medium text-amber-900 bg-amber-50 border-b border-amber-200 dark:border-amber-900">
|
|
60
|
+
<span>{t.admin_settings.banner}</span>
|
|
61
|
+
{user && user.can_admin_settings && (
|
|
62
|
+
<a href={`${lang_prefix}/admin/settings`} class="underline underline-offset-4 hover:text-amber-700">
|
|
63
|
+
{t.nav.admin_settings}
|
|
64
|
+
</a>
|
|
65
|
+
)}
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
57
68
|
<div class="relative flex min-h-screen">
|
|
58
69
|
{sidebar && <Sidebar />}
|
|
59
70
|
<div
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* `/admin/settings` (framework `settings` module): operator switches,
|
|
4
|
+
* maintenance mode first, then the AdminSettingsSections extension point.
|
|
5
|
+
*/
|
|
6
|
+
import { ssr } from "fse-ssr/ssr";
|
|
7
|
+
import Layout from "../../layouts/Layout.astro";
|
|
8
|
+
import Card from "../../components/Card.astro";
|
|
9
|
+
import Header from "../../components/Header.astro";
|
|
10
|
+
import Modal from "../../components/Modal.astro";
|
|
11
|
+
import AdminSettingsSections from "../../components/AdminSettingsSections.astro";
|
|
12
|
+
import type { AdminSettingsPage } from "../../types/pages";
|
|
13
|
+
|
|
14
|
+
const { t, lang_prefix, maintenance_enabled, can_write } =
|
|
15
|
+
ssr<AdminSettingsPage & { lang_prefix: string }>();
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<Layout title={t.nav.admin_settings}>
|
|
19
|
+
<main class="max-w-2xl mx-auto">
|
|
20
|
+
<Header>{t.nav.admin_settings}</Header>
|
|
21
|
+
|
|
22
|
+
<Card>
|
|
23
|
+
<div class="flex flex-col divide-y divide-secondary-100">
|
|
24
|
+
|
|
25
|
+
<!-- Maintenance mode -->
|
|
26
|
+
<div class="py-6 first:pt-0 last:pb-0">
|
|
27
|
+
<div class="flex items-start justify-between flex-wrap gap-3">
|
|
28
|
+
<div class="flex-1 min-w-60">
|
|
29
|
+
<div class="flex items-center gap-2">
|
|
30
|
+
<h3 class="text-base font-semibold text-secondary-900">
|
|
31
|
+
{t.admin_settings.maintenance_title}
|
|
32
|
+
</h3>
|
|
33
|
+
{maintenance_enabled && (
|
|
34
|
+
<span class="px-2 py-0.5 text-xs font-medium rounded-full bg-amber-50 text-amber-800 border border-amber-200 dark:border-amber-900">
|
|
35
|
+
{t.admin_settings.status_on}
|
|
36
|
+
</span>
|
|
37
|
+
)}
|
|
38
|
+
{!maintenance_enabled && (
|
|
39
|
+
<span class="px-2 py-0.5 text-xs font-medium rounded-full bg-secondary-100 text-secondary-600 border border-secondary-200">
|
|
40
|
+
{t.admin_settings.status_off}
|
|
41
|
+
</span>
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
<p class="text-sm text-secondary-500 mt-1">
|
|
45
|
+
{t.admin_settings.maintenance_desc}
|
|
46
|
+
</p>
|
|
47
|
+
</div>
|
|
48
|
+
{can_write && maintenance_enabled && (
|
|
49
|
+
<button type="button" class="btn-primary shrink-0" data-open-modal="maintenance-modal">
|
|
50
|
+
{t.admin_settings.disable}
|
|
51
|
+
</button>
|
|
52
|
+
)}
|
|
53
|
+
{can_write && !maintenance_enabled && (
|
|
54
|
+
<button type="button" class="btn-danger shrink-0" data-open-modal="maintenance-modal">
|
|
55
|
+
{t.admin_settings.enable}
|
|
56
|
+
</button>
|
|
57
|
+
)}
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<AdminSettingsSections />
|
|
62
|
+
|
|
63
|
+
</div>
|
|
64
|
+
</Card>
|
|
65
|
+
</main>
|
|
66
|
+
|
|
67
|
+
{maintenance_enabled && (
|
|
68
|
+
<Modal id="maintenance-modal" title={t.admin_settings.disable}>
|
|
69
|
+
<p class="text-sm text-secondary-600 mb-5">{t.admin_settings.disable_confirm}</p>
|
|
70
|
+
<form action={`${lang_prefix}/admin/settings/maintenance`} method="POST" data-astro-reload class="flex flex-col gap-2">
|
|
71
|
+
<input type="hidden" name="enabled" value="0" />
|
|
72
|
+
<button type="submit" class="w-full btn-primary">{t.admin_settings.disable}</button>
|
|
73
|
+
<button type="button" class="w-full btn-secondary modal-close-btn" data-modal-id="maintenance-modal">
|
|
74
|
+
{t.settings.cancel}
|
|
75
|
+
</button>
|
|
76
|
+
</form>
|
|
77
|
+
</Modal>
|
|
78
|
+
)}
|
|
79
|
+
{!maintenance_enabled && (
|
|
80
|
+
<Modal id="maintenance-modal" title={t.admin_settings.enable}>
|
|
81
|
+
<p class="text-sm text-secondary-600 mb-5">{t.admin_settings.enable_confirm}</p>
|
|
82
|
+
<form action={`${lang_prefix}/admin/settings/maintenance`} method="POST" data-astro-reload class="flex flex-col gap-2">
|
|
83
|
+
<input type="hidden" name="enabled" value="1" />
|
|
84
|
+
<button type="submit" class="w-full btn-danger">{t.admin_settings.enable}</button>
|
|
85
|
+
<button type="button" class="w-full btn-secondary modal-close-btn" data-modal-id="maintenance-modal">
|
|
86
|
+
{t.settings.cancel}
|
|
87
|
+
</button>
|
|
88
|
+
</form>
|
|
89
|
+
</Modal>
|
|
90
|
+
)}
|
|
91
|
+
|
|
92
|
+
<script>
|
|
93
|
+
document.addEventListener("astro:page-load", () => {
|
|
94
|
+
document.querySelectorAll<HTMLElement>("[data-open-modal]").forEach((button) => {
|
|
95
|
+
if (button.dataset.bound) return;
|
|
96
|
+
button.dataset.bound = "1";
|
|
97
|
+
button.addEventListener("click", () => {
|
|
98
|
+
const id = button.dataset.openModal;
|
|
99
|
+
const modal = id ? (document.getElementById(id) as HTMLDialogElement | null) : null;
|
|
100
|
+
if (modal && !modal.open) modal.showModal();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
</script>
|
|
105
|
+
</Layout>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* With tenancy: an invitation into a tenant. It carries no token — it is
|
|
4
|
+
* accepted in the portal by a verified account with exactly this address.
|
|
5
|
+
*/
|
|
6
|
+
import { ssr } from "fse-ssr/ssr";
|
|
7
|
+
import EmailLayout from "../../layouts/EmailLayout.astro";
|
|
8
|
+
|
|
9
|
+
const { t, tenant_name, portal_url } = ssr<{ tenant_name: string; portal_url: string }>();
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
<EmailLayout title={t.tenancy.invite_email.subject}>
|
|
13
|
+
<h1 slot="header" style="margin: 0; color: #ffffff; font-size: 20px; font-weight: 600; letter-spacing: 0.025em;">
|
|
14
|
+
{t.tenancy.invite_email.header}
|
|
15
|
+
</h1>
|
|
16
|
+
|
|
17
|
+
<p style="margin: 0; margin-bottom: 8px; color: #231f16; font-size: 16px; line-height: 1.625;">
|
|
18
|
+
{t.tenancy.invite_email.body}
|
|
19
|
+
</p>
|
|
20
|
+
<p style="margin: 0; margin-bottom: 20px; color: #231f16; font-size: 18px; font-weight: 600;">
|
|
21
|
+
{tenant_name}
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
<div style="text-align: center; padding-top: 12px; padding-bottom: 28px;">
|
|
25
|
+
<a
|
|
26
|
+
href={portal_url}
|
|
27
|
+
target="_blank"
|
|
28
|
+
style="display: inline-block; padding: 14px 36px; background-color: #6a9b3c; color: #ffffff; text-decoration: none; font-size: 14px; font-weight: 600; border-radius: 6px; letter-spacing: 0.025em;"
|
|
29
|
+
>
|
|
30
|
+
{t.tenancy.invite_email.cta}
|
|
31
|
+
</a>
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<p style="margin: 0; margin-bottom: 12px; color: #655650; font-size: 14px; line-height: 1.5;">
|
|
35
|
+
{t.tenancy.invite_email.fallback}
|
|
36
|
+
</p>
|
|
37
|
+
<p style="margin: 0; word-break: break-all;">
|
|
38
|
+
<a href={portal_url} style="color: #6a9b3c; font-size: 12px; text-decoration: underline;">
|
|
39
|
+
{portal_url}
|
|
40
|
+
</a>
|
|
41
|
+
</p>
|
|
42
|
+
|
|
43
|
+
<p slot="footer" style="margin: 0; color: #655650; font-size: 12px; line-height: 1.625;">
|
|
44
|
+
{t.tenancy.invite_email.footer}
|
|
45
|
+
</p>
|
|
46
|
+
</EmailLayout>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* What visitors get while maintenance mode is on (the framework answers
|
|
4
|
+
* 503 with this page; see framework/src/maintenance.rs). Signing in still
|
|
5
|
+
* works, so an administrator can get past it.
|
|
6
|
+
*/
|
|
7
|
+
import { ssr } from "fse-ssr/ssr";
|
|
8
|
+
import Logo from "../components/Logo.astro";
|
|
9
|
+
import Layout from "../layouts/Layout.astro";
|
|
10
|
+
|
|
11
|
+
const { t, lang_prefix } = ssr<{ lang_prefix: string }>();
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<Layout title={t.maintenance.heading} sidebar={false}>
|
|
15
|
+
<main class="min-h-screen w-full grid place-items-center bg-secondary-50 px-4 py-12">
|
|
16
|
+
<div class="w-full max-w-md text-center flex flex-col items-center gap-6">
|
|
17
|
+
<Logo variant="auth" />
|
|
18
|
+
<div class="w-12 h-12 rounded-full bg-primary-50 border border-primary-200 flex items-center justify-center">
|
|
19
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-primary-600">
|
|
20
|
+
<path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"></path>
|
|
21
|
+
</svg>
|
|
22
|
+
</div>
|
|
23
|
+
<div>
|
|
24
|
+
<h1 class="text-lg font-semibold text-secondary-900 mb-2">{t.maintenance.heading}</h1>
|
|
25
|
+
<p class="text-sm text-secondary-500">{t.maintenance.text}</p>
|
|
26
|
+
</div>
|
|
27
|
+
<a href={`${lang_prefix}/login`} class="text-sm text-secondary-500 hover:text-secondary-800 underline underline-offset-4">
|
|
28
|
+
{t.maintenance.admin_login}
|
|
29
|
+
</a>
|
|
30
|
+
</div>
|
|
31
|
+
</main>
|
|
32
|
+
</Layout>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* With tenancy: signing up a tenant — its name and its subdomain.
|
|
4
|
+
*/
|
|
5
|
+
import { ssr } from "fse-ssr/ssr";
|
|
6
|
+
import Card from "../../components/Card.astro";
|
|
7
|
+
import Header from "../../components/Header.astro";
|
|
8
|
+
import Input from "../../components/Input.astro";
|
|
9
|
+
import Layout from "../../layouts/Layout.astro";
|
|
10
|
+
import type { NewTenantPage } from "../../types/pages";
|
|
11
|
+
|
|
12
|
+
const { t, name, slug, error, domain } = ssr<NewTenantPage>();
|
|
13
|
+
const errors = t.tenancy.errors as Record<string, string>;
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
<Layout title={t.tenancy.new.title}>
|
|
17
|
+
<main class="max-w-xl mx-auto">
|
|
18
|
+
<Header backlink="/">{t.tenancy.new.title}</Header>
|
|
19
|
+
|
|
20
|
+
<Card>
|
|
21
|
+
<p class="text-sm text-secondary-500 mb-6">{t.tenancy.new.intro}</p>
|
|
22
|
+
|
|
23
|
+
<form action="/tenants/new" method="POST" data-astro-reload class="space-y-5">
|
|
24
|
+
<Input id="name" type="text" placeholder={t.tenancy.new.name} value={name ?? ""} required={true} />
|
|
25
|
+
|
|
26
|
+
<div>
|
|
27
|
+
<label for="slug" class="block text-sm font-medium text-secondary-700 mb-1.5">
|
|
28
|
+
{t.tenancy.new.slug}
|
|
29
|
+
</label>
|
|
30
|
+
<div class="flex items-stretch rounded-lg border border-secondary-200 focus-within:border-primary-500 focus-within:ring-1 focus-within:ring-primary-500 overflow-hidden">
|
|
31
|
+
<input
|
|
32
|
+
id="slug"
|
|
33
|
+
name="slug"
|
|
34
|
+
type="text"
|
|
35
|
+
required
|
|
36
|
+
minlength="3"
|
|
37
|
+
maxlength="40"
|
|
38
|
+
pattern="[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
|
|
39
|
+
autocomplete="off"
|
|
40
|
+
spellcheck="false"
|
|
41
|
+
value={slug ?? ""}
|
|
42
|
+
class="flex-1 min-w-0 h-10 px-3 text-sm text-secondary-900 bg-white outline-hidden"
|
|
43
|
+
/>
|
|
44
|
+
<span class="flex items-center px-3 text-sm text-secondary-500 bg-secondary-50 border-l border-secondary-200">
|
|
45
|
+
.{domain}
|
|
46
|
+
</span>
|
|
47
|
+
</div>
|
|
48
|
+
<p class="mt-1.5 text-xs text-secondary-500">{t.tenancy.new.slug_help}</p>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
{error && (
|
|
52
|
+
<div class="px-4 py-3 rounded-lg bg-red-50 border border-red-200" role="alert">
|
|
53
|
+
<p class="text-sm font-medium text-red-700">{errors[error] ?? error}</p>
|
|
54
|
+
</div>
|
|
55
|
+
)}
|
|
56
|
+
|
|
57
|
+
<div class="flex items-center gap-3">
|
|
58
|
+
<button type="submit" class="btn-primary">{t.tenancy.new.submit}</button>
|
|
59
|
+
<a href="/" class="btn-secondary">{t.tenancy.new.cancel}</a>
|
|
60
|
+
</div>
|
|
61
|
+
</form>
|
|
62
|
+
</Card>
|
|
63
|
+
</main>
|
|
64
|
+
</Layout>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* With tenancy: the portal's home — the account's tenants (each opens that
|
|
4
|
+
* tenant's own sign-in), its pending invitations, and creating a tenant.
|
|
5
|
+
*/
|
|
6
|
+
import { ssr } from "fse-ssr/ssr";
|
|
7
|
+
import Card from "../components/Card.astro";
|
|
8
|
+
import Header from "../components/Header.astro";
|
|
9
|
+
import Layout from "../layouts/Layout.astro";
|
|
10
|
+
import type { PortalPage } from "../types/pages";
|
|
11
|
+
|
|
12
|
+
const { t, tenants, invites, can_create, error } = ssr<PortalPage>();
|
|
13
|
+
const errors = t.tenancy.errors as Record<string, string>;
|
|
14
|
+
const roleLabels = t.roles as Record<string, string>;
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<Layout title={t.tenancy.chooser.title}>
|
|
18
|
+
<main class="max-w-2xl mx-auto">
|
|
19
|
+
<Header>{t.tenancy.chooser.title}</Header>
|
|
20
|
+
|
|
21
|
+
{error && (
|
|
22
|
+
<div class="mb-6 px-4 py-3 rounded-lg bg-red-50 border border-red-200" role="alert">
|
|
23
|
+
<p class="text-sm font-medium text-red-700">{errors[error] ?? error}</p>
|
|
24
|
+
</div>
|
|
25
|
+
)}
|
|
26
|
+
|
|
27
|
+
{invites.length > 0 && (
|
|
28
|
+
<div class="mb-6">
|
|
29
|
+
<Card>
|
|
30
|
+
<h2 class="text-base font-semibold text-secondary-900 mb-4">
|
|
31
|
+
{t.tenancy.chooser.invites_title}
|
|
32
|
+
</h2>
|
|
33
|
+
<ul class="divide-y divide-secondary-100">
|
|
34
|
+
{invites.map((invite) => (
|
|
35
|
+
<li class="py-3 first:pt-0 last:pb-0 flex flex-wrap items-center justify-between gap-3">
|
|
36
|
+
<p class="text-sm text-secondary-700">
|
|
37
|
+
{t.tenancy.chooser.invited_to}
|
|
38
|
+
<span class="font-semibold text-secondary-900">{invite.tenant_name}</span>
|
|
39
|
+
{t.tenancy.chooser.as_role}
|
|
40
|
+
<span class="font-medium">{roleLabels[invite.role] ?? invite.role}</span>
|
|
41
|
+
</p>
|
|
42
|
+
<div class="flex gap-2">
|
|
43
|
+
<form action={`/invites/${invite.id}/accept`} method="POST" data-astro-reload>
|
|
44
|
+
<button type="submit" class="btn-primary">{t.tenancy.chooser.accept}</button>
|
|
45
|
+
</form>
|
|
46
|
+
<form action={`/invites/${invite.id}/decline`} method="POST" data-astro-reload>
|
|
47
|
+
<button type="submit" class="btn-secondary">{t.tenancy.chooser.decline}</button>
|
|
48
|
+
</form>
|
|
49
|
+
</div>
|
|
50
|
+
</li>
|
|
51
|
+
))}
|
|
52
|
+
</ul>
|
|
53
|
+
</Card>
|
|
54
|
+
</div>
|
|
55
|
+
)}
|
|
56
|
+
|
|
57
|
+
<Card>
|
|
58
|
+
<p class="text-sm text-secondary-500 mb-4">{t.tenancy.chooser.intro}</p>
|
|
59
|
+
|
|
60
|
+
{tenants.length === 0 && (
|
|
61
|
+
<p class="text-sm text-secondary-700 mb-4">{t.tenancy.chooser.none}</p>
|
|
62
|
+
)}
|
|
63
|
+
|
|
64
|
+
<ul class="space-y-2 mb-6">
|
|
65
|
+
{tenants.map((tenant) => (
|
|
66
|
+
<li>
|
|
67
|
+
<a
|
|
68
|
+
href={tenant.url}
|
|
69
|
+
data-astro-reload
|
|
70
|
+
class="flex items-center justify-between px-4 py-3 rounded-lg border border-secondary-200 hover:border-primary-400 hover:bg-primary-50 transition-colors"
|
|
71
|
+
>
|
|
72
|
+
<span>
|
|
73
|
+
<span class="block text-sm font-semibold text-secondary-900">{tenant.name}</span>
|
|
74
|
+
<span class="block text-xs text-secondary-500">{tenant.slug}</span>
|
|
75
|
+
</span>
|
|
76
|
+
<span class="text-sm font-medium text-primary-600">{t.tenancy.chooser.open}</span>
|
|
77
|
+
</a>
|
|
78
|
+
</li>
|
|
79
|
+
))}
|
|
80
|
+
</ul>
|
|
81
|
+
|
|
82
|
+
{can_create && (
|
|
83
|
+
<a href="/tenants/new" class="btn-primary">{t.tenancy.chooser.create}</a>
|
|
84
|
+
)}
|
|
85
|
+
{!can_create && (
|
|
86
|
+
<p class="text-sm text-secondary-500">{t.tenancy.chooser.limit}</p>
|
|
87
|
+
)}
|
|
88
|
+
</Card>
|
|
89
|
+
</main>
|
|
90
|
+
</Layout>
|
package/src/pages/register.astro
CHANGED
|
@@ -4,7 +4,14 @@ import Input from "../components/Input.astro";
|
|
|
4
4
|
import Logo from "../components/Logo.astro";
|
|
5
5
|
import Layout from "../layouts/Layout.astro";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// After a refused submit the server sends back what was entered (never
|
|
8
|
+
// the passwords), so only what was wrong needs typing again.
|
|
9
|
+
const { t, error, first_name, last_name, email } = ssr<{
|
|
10
|
+
error?: string;
|
|
11
|
+
first_name?: string;
|
|
12
|
+
last_name?: string;
|
|
13
|
+
email?: string;
|
|
14
|
+
}>();
|
|
8
15
|
const errors = t.errors as Record<string, string>;
|
|
9
16
|
---
|
|
10
17
|
|
|
@@ -26,15 +33,27 @@ const errors = t.errors as Record<string, string>;
|
|
|
26
33
|
</h1>
|
|
27
34
|
</div>
|
|
28
35
|
|
|
29
|
-
<form id="login-form" action="/register" method="POST" data-astro-reload
|
|
36
|
+
<form id="login-form" action="/register" method="POST" data-astro-reload>
|
|
30
37
|
<div class="px-6 py-4 flex flex-col gap-4">
|
|
31
38
|
<div class="grid grid-cols-2 gap-4">
|
|
32
|
-
<Input id="first_name" type="text" placeholder={t.register.first_name} required={true} />
|
|
33
|
-
<Input id="last_name" type="text" placeholder={t.register.last_name} required={true} />
|
|
39
|
+
<Input id="first_name" type="text" placeholder={t.register.first_name} value={first_name ?? ""} required={true} />
|
|
40
|
+
<Input id="last_name" type="text" placeholder={t.register.last_name} value={last_name ?? ""} required={true} />
|
|
41
|
+
</div>
|
|
42
|
+
<Input id="email" type="email" placeholder={t.register.email} value={email ?? ""} required={true} />
|
|
43
|
+
<div>
|
|
44
|
+
<Input id="password" type="password" placeholder={t.register.password} required={true} />
|
|
45
|
+
<!-- Shown while typing (see the script); the same texts the
|
|
46
|
+
server answers with, so both checks read alike. -->
|
|
47
|
+
<p id="password-hint" class="mt-1.5 text-xs text-red-600" aria-live="polite" hidden>
|
|
48
|
+
{errors.password_too_short}
|
|
49
|
+
</p>
|
|
50
|
+
</div>
|
|
51
|
+
<div>
|
|
52
|
+
<Input id="repeat_password" type="password" placeholder={t.register.repeat_password} required={true} />
|
|
53
|
+
<p id="repeat-hint" class="mt-1.5 text-xs text-red-600" aria-live="polite" hidden>
|
|
54
|
+
{errors.passwords_mismatch}
|
|
55
|
+
</p>
|
|
34
56
|
</div>
|
|
35
|
-
<Input id="email" type="email" placeholder={t.register.email} required={true} />
|
|
36
|
-
<Input id="password" type="password" placeholder={t.register.password} required={true} />
|
|
37
|
-
<Input id="repeat_password" type="password" placeholder={t.register.repeat_password} required={true} />
|
|
38
57
|
</div>
|
|
39
58
|
|
|
40
59
|
<div class="px-6 pb-5 pt-1">
|
|
@@ -69,29 +88,39 @@ const errors = t.errors as Record<string, string>;
|
|
|
69
88
|
</main>
|
|
70
89
|
|
|
71
90
|
<script>
|
|
72
|
-
|
|
91
|
+
/** The server's minimum (`RegisterForm`): characters, not bytes. */
|
|
92
|
+
const MIN_PASSWORD_LENGTH = 8;
|
|
73
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Checks the passwords as they are typed: too short, and a repetition
|
|
96
|
+
* that went wrong — but not one still being typed correctly. Submitting
|
|
97
|
+
* waits until both are fine; the server checks the same again.
|
|
98
|
+
*/
|
|
74
99
|
function setupRegisterForm() {
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
form.addEventListener("submit", (e) => {
|
|
82
|
-
if (password.value !== repeatPassword.value) {
|
|
83
|
-
e.preventDefault();
|
|
84
|
-
const { t } = pageProps<{ t: { register: { passwords_mismatch?: string } } }>();
|
|
85
|
-
alert(t.register.passwords_mismatch ?? "Passwords do not match");
|
|
86
|
-
}
|
|
87
|
-
});
|
|
100
|
+
const password = document.getElementById("password") as HTMLInputElement | null;
|
|
101
|
+
const repeat = document.getElementById("repeat_password") as HTMLInputElement | null;
|
|
102
|
+
const tooShort = document.getElementById("password-hint");
|
|
103
|
+
const mismatch = document.getElementById("repeat-hint");
|
|
104
|
+
const submit = document.getElementById("submit-btn") as HTMLButtonElement | null;
|
|
105
|
+
if (!password || !repeat || !tooShort || !mismatch || !submit) return;
|
|
88
106
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
107
|
+
const check = () => {
|
|
108
|
+
const length = Array.from(password.value).length;
|
|
109
|
+
const short = length > 0 && length < MIN_PASSWORD_LENGTH;
|
|
110
|
+
const differs =
|
|
111
|
+
repeat.value.length > 0 &&
|
|
112
|
+
(repeat.value.length >= password.value.length
|
|
113
|
+
? repeat.value !== password.value
|
|
114
|
+
: !password.value.startsWith(repeat.value));
|
|
115
|
+
tooShort.hidden = !short;
|
|
116
|
+
mismatch.hidden = !differs;
|
|
117
|
+
password.setAttribute("aria-invalid", String(short));
|
|
118
|
+
repeat.setAttribute("aria-invalid", String(differs));
|
|
119
|
+
submit.disabled = short || differs;
|
|
120
|
+
};
|
|
121
|
+
password.addEventListener("input", check);
|
|
122
|
+
repeat.addEventListener("input", check);
|
|
123
|
+
check();
|
|
95
124
|
}
|
|
96
125
|
|
|
97
126
|
document.addEventListener("astro:page-load", setupRegisterForm);
|
package/src/pages/users.astro
CHANGED
|
@@ -6,9 +6,20 @@ import Table from "../components/Table.astro";
|
|
|
6
6
|
import Header from "../components/Header.astro";
|
|
7
7
|
import TableFilters from "../components/TableFilters.astro";
|
|
8
8
|
import Pagination from "../components/Pagination.astro";
|
|
9
|
+
import Input from "../components/Input.astro";
|
|
9
10
|
import type { TableHeader, UsersPage } from "../types/pages";
|
|
10
11
|
|
|
11
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
t,
|
|
14
|
+
rows,
|
|
15
|
+
filter_role,
|
|
16
|
+
roles,
|
|
17
|
+
can_invite,
|
|
18
|
+
invite_roles,
|
|
19
|
+
invites,
|
|
20
|
+
invite_success,
|
|
21
|
+
invite_error,
|
|
22
|
+
} = ssr<UsersPage>();
|
|
12
23
|
|
|
13
24
|
const headers: TableHeader[] = [
|
|
14
25
|
{ title: "ID", key: "id" },
|
|
@@ -48,5 +59,63 @@ const roleLabels = t.roles as Record<string, string>;
|
|
|
48
59
|
<Table headers={headers} rows={rows} />
|
|
49
60
|
<Pagination />
|
|
50
61
|
</Card>
|
|
62
|
+
|
|
63
|
+
<!-- With tenancy: invitations. Only rendered on a tenant's page
|
|
64
|
+
(`can_invite`), so `t.tenancy` is only read where it exists. -->
|
|
65
|
+
{invite_success && (
|
|
66
|
+
<div class="mt-6 px-4 py-3 rounded-lg bg-primary-50 border border-primary-200" role="status">
|
|
67
|
+
<p class="text-sm font-medium text-primary-700">{invite_success}</p>
|
|
68
|
+
</div>
|
|
69
|
+
)}
|
|
70
|
+
{invite_error && (
|
|
71
|
+
<div class="mt-6 px-4 py-3 rounded-lg bg-red-50 border border-red-200" role="alert">
|
|
72
|
+
<p class="text-sm font-medium text-red-700">{invite_error}</p>
|
|
73
|
+
</div>
|
|
74
|
+
)}
|
|
75
|
+
{can_invite && (
|
|
76
|
+
<div class="mt-6 grid gap-6 lg:grid-cols-2">
|
|
77
|
+
<Card>
|
|
78
|
+
<h2 class="text-base font-semibold text-secondary-900 mb-1">
|
|
79
|
+
{t.tenancy.members.invite_title}
|
|
80
|
+
</h2>
|
|
81
|
+
<p class="text-sm text-secondary-500 mb-4">{t.tenancy.members.invite_desc}</p>
|
|
82
|
+
<form action="/users/invite" method="POST" data-astro-reload class="space-y-4">
|
|
83
|
+
<Input id="email" type="email" placeholder={t.tenancy.members.email} required={true} />
|
|
84
|
+
<div class="relative">
|
|
85
|
+
<select
|
|
86
|
+
name="role"
|
|
87
|
+
aria-label={t.tenancy.members.role}
|
|
88
|
+
class="w-full h-10 pl-3 pr-8 text-sm border border-secondary-200 rounded-lg bg-white focus:border-primary-500 focus:ring-1 focus:ring-primary-500 outline-hidden text-secondary-700 appearance-none"
|
|
89
|
+
>
|
|
90
|
+
{invite_roles!.map((role) => (
|
|
91
|
+
<option value={role.value}>{roleLabels[role.value] ?? role.label}</option>
|
|
92
|
+
))}
|
|
93
|
+
</select>
|
|
94
|
+
</div>
|
|
95
|
+
<button type="submit" class="btn-primary">{t.tenancy.members.send}</button>
|
|
96
|
+
</form>
|
|
97
|
+
</Card>
|
|
98
|
+
<Card>
|
|
99
|
+
<h2 class="text-base font-semibold text-secondary-900 mb-4">
|
|
100
|
+
{t.tenancy.members.pending}
|
|
101
|
+
</h2>
|
|
102
|
+
<ul class="divide-y divide-secondary-100">
|
|
103
|
+
{invites!.map((invite) => (
|
|
104
|
+
<li class="py-3 first:pt-0 last:pb-0 flex items-center justify-between gap-3">
|
|
105
|
+
<div class="min-w-0">
|
|
106
|
+
<p class="text-sm font-medium text-secondary-900 truncate">{invite.email}</p>
|
|
107
|
+
<p class="text-xs text-secondary-500">
|
|
108
|
+
{roleLabels[invite.role] ?? invite.role} · {t.tenancy.members.expires} {invite.expires_at}
|
|
109
|
+
</p>
|
|
110
|
+
</div>
|
|
111
|
+
<form action={`/users/invites/${invite.id}/delete`} method="POST" data-astro-reload>
|
|
112
|
+
<button type="submit" class="btn-secondary">{t.tenancy.members.revoke}</button>
|
|
113
|
+
</form>
|
|
114
|
+
</li>
|
|
115
|
+
))}
|
|
116
|
+
</ul>
|
|
117
|
+
</Card>
|
|
118
|
+
</div>
|
|
119
|
+
)}
|
|
51
120
|
</main>
|
|
52
121
|
</Layout>
|
package/src/types/pages.ts
CHANGED
|
@@ -34,6 +34,39 @@ export interface UsersPage {
|
|
|
34
34
|
total_pages: number;
|
|
35
35
|
total_count: number;
|
|
36
36
|
per_page: number;
|
|
37
|
+
/** With tenancy: the member may invite (holds `users.write`). */
|
|
38
|
+
can_invite?: boolean;
|
|
39
|
+
/** With tenancy: the roles the member may hand out. */
|
|
40
|
+
invite_roles?: Role[];
|
|
41
|
+
/** With tenancy: invitations not yet accepted. */
|
|
42
|
+
invites?: PendingInvite[];
|
|
43
|
+
/** With tenancy: the outcome of an invitation, as a finished sentence. */
|
|
44
|
+
invite_success?: string | null;
|
|
45
|
+
invite_error?: string | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface PendingInvite {
|
|
49
|
+
id: number;
|
|
50
|
+
email: string;
|
|
51
|
+
role: string;
|
|
52
|
+
expires_at: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** `portal` — with tenancy, the account's tenants and invitations. */
|
|
56
|
+
export interface PortalPage {
|
|
57
|
+
tenants: { name: string; slug: string; url: string }[];
|
|
58
|
+
invites: { id: number; tenant_name: string; role: string }[];
|
|
59
|
+
can_create: boolean;
|
|
60
|
+
error?: string | null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** `portal/new-tenant` — with tenancy, signing up a tenant. */
|
|
64
|
+
export interface NewTenantPage {
|
|
65
|
+
name?: string;
|
|
66
|
+
slug?: string;
|
|
67
|
+
error?: string;
|
|
68
|
+
/** `DOMAIN`: the new tenant's address is `<slug>.<domain>`. */
|
|
69
|
+
domain: string;
|
|
37
70
|
}
|
|
38
71
|
|
|
39
72
|
export interface UserPage {
|
|
@@ -53,6 +86,13 @@ export interface SettingsPage {
|
|
|
53
86
|
email_error?: string;
|
|
54
87
|
}
|
|
55
88
|
|
|
89
|
+
/** `/admin/settings` (framework `settings` module). */
|
|
90
|
+
export interface AdminSettingsPage {
|
|
91
|
+
maintenance_enabled: boolean;
|
|
92
|
+
/** Holds `admin_settings.write`: may change settings. */
|
|
93
|
+
can_write: boolean;
|
|
94
|
+
}
|
|
95
|
+
|
|
56
96
|
export interface ErrorPage {
|
|
57
97
|
error: string;
|
|
58
98
|
}
|
package/src/types.ts
CHANGED
|
@@ -179,6 +179,8 @@ export interface SessionUser {
|
|
|
179
179
|
role: string;
|
|
180
180
|
is_admin: boolean;
|
|
181
181
|
can_read_users: boolean;
|
|
182
|
+
/** Holds `admin_settings.read`: may open `/admin/settings`. */
|
|
183
|
+
can_admin_settings: boolean;
|
|
182
184
|
}
|
|
183
185
|
|
|
184
186
|
/** Context keys every page receives, whatever renders it. */
|
|
@@ -187,4 +189,13 @@ export interface ShellContext {
|
|
|
187
189
|
nav_groups: NavGroup[];
|
|
188
190
|
user?: SessionUser;
|
|
189
191
|
lang_prefix: string;
|
|
192
|
+
/** Present (true) only while maintenance mode is on — on pages an
|
|
193
|
+
* admin sees, and on the login page. */
|
|
194
|
+
maintenance_mode?: boolean;
|
|
195
|
+
/** With tenancy, on a tenant's pages: which tenant this is. */
|
|
196
|
+
tenant?: { name: string; slug: string };
|
|
197
|
+
/** With tenancy, on a tenant's pages: the portal (switch tenant, account). */
|
|
198
|
+
portal_url?: string;
|
|
199
|
+
/** With tenancy, on the portal's own pages. */
|
|
200
|
+
portal?: boolean;
|
|
190
201
|
}
|
package/theme.json
CHANGED