fse-theme-default 0.6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fse-theme-default",
3
- "version": "0.6.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",
@@ -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>
@@ -124,6 +133,14 @@ const { t, nav_groups, user, lang_prefix } = ssr<ShellContext>();
124
133
  </NavLink>
125
134
  )}
126
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
+
127
144
  {user && (
128
145
  <NavLink href={`${lang_prefix}/settings`} label={t.nav.settings ?? "Settings"}>
129
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">
@@ -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,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>
@@ -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
- const { t, error } = ssr<{ error?: string }>();
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 enctype="multipart/form-data">
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
- import { pageProps } from "fse-ssr/client";
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 form = document.getElementById("login-form") as HTMLFormElement;
76
- const password = document.getElementById("password") as HTMLInputElement;
77
- const repeatPassword = document.getElementById("repeat_password") as HTMLInputElement;
78
- const submitBtn = document.getElementById("submit-btn") as HTMLButtonElement;
79
-
80
- if (form && password && repeatPassword && submitBtn) {
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
- function checkPasswords() {
90
- submitBtn.disabled = password.value !== repeatPassword.value;
91
- }
92
- password.addEventListener("input", checkPasswords);
93
- repeatPassword.addEventListener("input", checkPasswords);
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);
@@ -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 { t, rows, filter_role, roles } = ssr<UsersPage>();
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>
@@ -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 {
package/src/types.ts CHANGED
@@ -192,4 +192,10 @@ export interface ShellContext {
192
192
  /** Present (true) only while maintenance mode is on — on pages an
193
193
  * admin sees, and on the login page. */
194
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;
195
201
  }
package/theme.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "fse-theme-default",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Default full_stack_engine theme: app shell, design system, auth pages, emails and the generic model CRUD pages."
5
5
  }