create-mana 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +28 -2
- package/bin/create-mana.mjs +5 -0
- package/kits/auth/files/src/api/auth.ts +100 -0
- package/kits/auth/files/src/api/profile.ts +48 -0
- package/kits/auth/files/src/api/types.ts +28 -0
- package/kits/auth/files/src/components/AppLayout.mana +31 -0
- package/kits/auth/files/src/components/VerifyBanner.mana +47 -0
- package/kits/auth/files/src/router/routes.ts +31 -0
- package/kits/auth/files/src/shared/events.ts +11 -0
- package/kits/auth/files/src/stores/session.ts +99 -0
- package/kits/auth/files/src/views/ForgotPassword.mana +83 -0
- package/kits/auth/files/src/views/Home.mana +15 -0
- package/kits/auth/files/src/views/Profile.mana +172 -0
- package/kits/auth/files/src/views/Register.mana +86 -0
- package/kits/auth/files/src/views/ResetPassword.mana +90 -0
- package/kits/auth/files/src/views/SignIn.mana +84 -0
- package/kits/auth/files/src/views/VerifyEmail.mana +78 -0
- package/kits/auth/files/tests/auth.test.mjs +93 -0
- package/kits/auth/files/tests/home.test.mjs +38 -0
- package/kits/auth/files/tests/profile.test.mjs +68 -0
- package/kits/auth/files/tests/support/users.mjs +2 -0
- package/kits/auth/kit.json +80 -0
- package/kits/base/files/README.md +39 -0
- package/kits/base/kit.json +7 -0
- package/kits/organisations/files/src/api/auth.ts +124 -0
- package/kits/organisations/files/src/api/members.ts +243 -0
- package/kits/organisations/files/src/api/notifications.ts +63 -0
- package/kits/organisations/files/src/api/organisations.ts +41 -0
- package/kits/organisations/files/src/api/scope.ts +98 -0
- package/kits/organisations/files/src/api/types.ts +72 -0
- package/kits/organisations/files/src/assets/styles/organisations.css +46 -0
- package/kits/organisations/files/src/components/AppLayout.mana +90 -0
- package/kits/organisations/files/src/components/NotificationBell.mana +35 -0
- package/kits/organisations/files/src/components/NotificationList.mana +112 -0
- package/kits/organisations/files/src/components/OrganisationSwitcher.mana +171 -0
- package/kits/organisations/files/src/composables/notifications.ts +28 -0
- package/kits/organisations/files/src/router/routes.ts +43 -0
- package/kits/organisations/files/src/shared/roles.ts +10 -0
- package/kits/organisations/files/src/stores/notifications.ts +41 -0
- package/kits/organisations/files/src/stores/session.ts +158 -0
- package/kits/organisations/files/src/utilities/format.ts +15 -0
- package/kits/organisations/files/src/views/Forbidden.mana +28 -0
- package/kits/organisations/files/src/views/Home.mana +15 -0
- package/kits/organisations/files/src/views/Invite.mana +156 -0
- package/kits/organisations/files/src/views/InviteMember.mana +99 -0
- package/kits/organisations/files/src/views/Members.mana +218 -0
- package/kits/organisations/files/src/views/NoOrganisation.mana +184 -0
- package/kits/organisations/files/src/views/Notifications.mana +30 -0
- package/kits/organisations/files/src/views/OrganisationForm.mana +76 -0
- package/kits/organisations/files/src/views/OrganisationSettings.mana +62 -0
- package/kits/organisations/files/src/views/Profile.mana +213 -0
- package/kits/organisations/files/src/views/Register.mana +113 -0
- package/kits/organisations/files/tests/auth.test.mjs +82 -0
- package/kits/organisations/files/tests/home.test.mjs +43 -0
- package/kits/organisations/files/tests/members.test.mjs +89 -0
- package/kits/organisations/files/tests/notifications.test.mjs +49 -0
- package/kits/organisations/files/tests/organisations.test.mjs +70 -0
- package/kits/organisations/files/tests/profile.test.mjs +79 -0
- package/kits/organisations/files/tests/support/users.mjs +3 -0
- package/kits/organisations/kit.json +51 -0
- package/lib/compose.mjs +209 -0
- package/lib/new.mjs +161 -0
- package/lib/prompts.mjs +182 -0
- package/package.json +36 -4
- package/template/.nvmrc +1 -0
- package/template/README.md +23 -0
- package/template/_gitignore +25 -0
- package/template/index.html +17 -0
- package/template/package.json +22 -0
- package/template/public/favicon.svg +1 -0
- package/template/public/icons.svg +24 -0
- package/template/src/App.mana +15 -0
- package/template/src/api/ApiError.ts +17 -0
- package/template/src/api/client.ts +116 -0
- package/template/src/assets/styles/main.css +158 -0
- package/template/src/components/AppLogo.mana +20 -0
- package/template/src/components/Button.mana +25 -0
- package/template/src/components/ConfirmHost.mana +43 -0
- package/template/src/components/TextField.mana +60 -0
- package/template/src/components/ToastHost.mana +40 -0
- package/template/src/composables/media.ts +19 -0
- package/template/src/composables/unsaved.ts +29 -0
- package/template/src/main.ts +25 -0
- package/template/src/router/index.ts +14 -0
- package/template/src/router/routes.ts +11 -0
- package/template/src/stores/confirm.ts +45 -0
- package/template/src/stores/toasts.ts +64 -0
- package/template/src/utilities/query.ts +40 -0
- package/template/src/utilities/timers.ts +12 -0
- package/template/src/views/Home.mana +12 -0
- package/template/src/views/NotFound.mana +13 -0
- package/template/tests/home.test.mjs +29 -0
- package/template/tests/support/api.mjs +44 -0
- package/template/tests/support/check.mjs +15 -0
- package/template/tests/support/dom.mjs +45 -0
- package/template/tests/support/paths.mjs +54 -0
- package/template/tests/support/settle.mjs +15 -0
- package/template/tsconfig.json +35 -0
- package/template/vite.config.ts +29 -0
- package/versions.json +3 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* Members: /members ("members"),
|
|
4
|
+
* for the organisation's owner and admins (its route middleware, S11).
|
|
5
|
+
*
|
|
6
|
+
* Everyone in the organisation, with their role. The owner and admins change
|
|
7
|
+
* a role from its select, which applies at once and says so, and remove
|
|
8
|
+
* someone, confirmed first; never the owner, nor themselves, and an admin
|
|
9
|
+
* never another admin. Only the owner sees Make owner on an admin's row,
|
|
10
|
+
* which hands ownership over, confirmed first; the owner becomes an admin
|
|
11
|
+
* (the session's user follows, S15).
|
|
12
|
+
* Then the invitations waiting, each with its role, who sent it and when it
|
|
13
|
+
* expires (7 days, S9), and Resend and Revoke. Invite someone opens a page of
|
|
14
|
+
* its own.
|
|
15
|
+
* It loads with resource(), reading the organisation you're in; each change
|
|
16
|
+
* answers with the list as it now is. Refusals show as toasts.
|
|
17
|
+
*/
|
|
18
|
+
import { computed, ref, resource, watch } from "@mana-js/mana";
|
|
19
|
+
|
|
20
|
+
import ApiError from "@/api/ApiError";
|
|
21
|
+
import * as api from "@/api/members";
|
|
22
|
+
import type { Invitation, Member, MemberList } from "@/api/members";
|
|
23
|
+
import type { Role } from "@/api/types";
|
|
24
|
+
import { ROLES } from "@/shared/roles";
|
|
25
|
+
import { useConfirm } from "@/stores/confirm";
|
|
26
|
+
import { useSession } from "@/stores/session";
|
|
27
|
+
import { useToasts } from "@/stores/toasts";
|
|
28
|
+
import { fullDate } from "@/utilities/format";
|
|
29
|
+
|
|
30
|
+
// The roles a member can be given; ownership is transferred instead.
|
|
31
|
+
const ROLE_OPTIONS: readonly Role[] = ["admin", "member"];
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<script setup lang="ts">
|
|
35
|
+
defineOptions({ name: "Members" });
|
|
36
|
+
|
|
37
|
+
const sessionStore = useSession();
|
|
38
|
+
const confirmStore = useConfirm();
|
|
39
|
+
const toastStore = useToasts();
|
|
40
|
+
|
|
41
|
+
const loaded = resource(() => sessionStore.organisation?.id == null ? null : api.members(sessionStore.organisation.id));
|
|
42
|
+
// The list as the last change answered it, else as loaded.
|
|
43
|
+
const changed = ref<MemberList | null>(null);
|
|
44
|
+
const list = computed(() => changed.value ?? loaded.data);
|
|
45
|
+
const status = ref("");
|
|
46
|
+
const busy = ref(false);
|
|
47
|
+
|
|
48
|
+
watch(() => loaded.data, () => changed.value = null);
|
|
49
|
+
|
|
50
|
+
const owner = computed(() => sessionStore.role == "owner");
|
|
51
|
+
|
|
52
|
+
// The organisation you're in: what the API's calls on its members are made to.
|
|
53
|
+
function organisationId() {
|
|
54
|
+
const id = sessionStore.organisation?.id;
|
|
55
|
+
|
|
56
|
+
if(id === undefined)
|
|
57
|
+
throw new ApiError("You're not working in an organisation.");
|
|
58
|
+
|
|
59
|
+
return id;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Whether you can change or remove a member.
|
|
63
|
+
function manageable(member: Member) {
|
|
64
|
+
return !member.you && member.role != "owner" && (owner.value || member.role != "admin");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function article(role: Role) {
|
|
68
|
+
return role == "admin" || role == "owner" ? "an" : "a";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function run(work: () => Promise<MemberList>, title: string, done: string) {
|
|
72
|
+
if(busy.value)
|
|
73
|
+
return false;
|
|
74
|
+
|
|
75
|
+
busy.value = true;
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
changed.value = await work();
|
|
79
|
+
status.value = done;
|
|
80
|
+
|
|
81
|
+
return true;
|
|
82
|
+
} catch(error) {
|
|
83
|
+
toastStore.error(title, error instanceof ApiError ? error.message : "Something went wrong. Try again.");
|
|
84
|
+
|
|
85
|
+
return false;
|
|
86
|
+
} finally {
|
|
87
|
+
busy.value = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// A role chosen in a member's select applies at once; a refusal puts the select back.
|
|
92
|
+
async function changeRole(member: Member, event: Event) {
|
|
93
|
+
const select = event.target;
|
|
94
|
+
|
|
95
|
+
if(!(select instanceof HTMLSelectElement))
|
|
96
|
+
return;
|
|
97
|
+
|
|
98
|
+
const chosen = select.value;
|
|
99
|
+
const role = ROLE_OPTIONS.find(option => option == chosen);
|
|
100
|
+
|
|
101
|
+
if(!role || role == member.role)
|
|
102
|
+
return;
|
|
103
|
+
|
|
104
|
+
if(!await run(() => api.changeRole(organisationId(), member.id, role), "Couldn't change the role", `${member.name} is now ${article(role)} ${ROLES[role].label.toLowerCase()}.`))
|
|
105
|
+
select.value = member.role;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function remove(member: Member) {
|
|
109
|
+
const yes = await confirmStore.ask({
|
|
110
|
+
title: `Remove ${member.name}?`,
|
|
111
|
+
text: `They lose access to ${sessionStore.organisation?.name ?? "the organisation"} at once. The entries they recorded stay, with their name on them.`,
|
|
112
|
+
confirm: "Remove",
|
|
113
|
+
danger: true,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if(yes)
|
|
117
|
+
await run(() => api.removeMember(organisationId(), member.id), "Couldn't remove them", `${member.name} has been removed.`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function transfer(member: Member) {
|
|
121
|
+
const yes = await confirmStore.ask({
|
|
122
|
+
title: `Make ${member.name} the owner?`,
|
|
123
|
+
text: "You'll become an admin. Only the owner can transfer ownership, and only to an admin.",
|
|
124
|
+
confirm: "Transfer ownership",
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if(!yes || busy.value)
|
|
128
|
+
return;
|
|
129
|
+
|
|
130
|
+
busy.value = true;
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
sessionStore.receive(await api.transferOwnership(organisationId(), member.id));
|
|
134
|
+
status.value = `${member.name} is now the owner; you're an admin.`;
|
|
135
|
+
loaded.reload();
|
|
136
|
+
} catch(error) {
|
|
137
|
+
toastStore.error("Couldn't transfer ownership", error instanceof ApiError ? error.message : "Something went wrong. Try again.");
|
|
138
|
+
} finally {
|
|
139
|
+
busy.value = false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function resend(invitation: Invitation) {
|
|
144
|
+
void run(() => api.resendInvitation(organisationId(), invitation.id), "Couldn't resend the invitation", `The invitation went to ${invitation.email} again.`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function revoke(invitation: Invitation) {
|
|
148
|
+
void run(() => api.revokeInvitation(organisationId(), invitation.id), "Couldn't revoke the invitation", `The invitation to ${invitation.email} is revoked.`);
|
|
149
|
+
}
|
|
150
|
+
</script>
|
|
151
|
+
|
|
152
|
+
<template>
|
|
153
|
+
<div class="page-head">
|
|
154
|
+
<h1>Members</h1>
|
|
155
|
+
<div class="spacer"></div>
|
|
156
|
+
<RouterLink class="btn primary" :to="{ name: 'members.invite' }">Invite someone</RouterLink>
|
|
157
|
+
</div>
|
|
158
|
+
|
|
159
|
+
<p class="status-line" role="status">{{ status }}</p>
|
|
160
|
+
|
|
161
|
+
<div class="alert" role="alert" m-if="loaded.error && !list">
|
|
162
|
+
We couldn't load the members.
|
|
163
|
+
<button type="button" class="link-button" @click="loaded.reload()">Try again</button>.
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
<div class="card" aria-busy="true" aria-label="Loading the members" m-else-if="!list">
|
|
167
|
+
<span class="skeleton" style="width:30%;height:14px"></span>
|
|
168
|
+
<span class="skeleton" style="width:100%;height:140px;margin-top:12px"></span>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<Template m-else>
|
|
172
|
+
<section class="card" aria-labelledby="members-title" :aria-busy="busy">
|
|
173
|
+
<div class="card-head"><h2 id="members-title">Everyone in it</h2><span class="muted">{{ list.members.length }}</span></div>
|
|
174
|
+
<div class="table-wrap">
|
|
175
|
+
<table class="members">
|
|
176
|
+
<thead>
|
|
177
|
+
<tr><th scope="col">Name</th><th scope="col">Role</th><th scope="col"><span class="visually-hidden">Actions</span></th></tr>
|
|
178
|
+
</thead>
|
|
179
|
+
<tbody>
|
|
180
|
+
<tr m-for="member in list.members" :key="member.id">
|
|
181
|
+
<td class="who">{{ member.name }}<span m-if="member.you"> (you)</span><small>{{ member.email }}</small></td>
|
|
182
|
+
<td>
|
|
183
|
+
<select :aria-label="'Role for ' + member.name" :value="member.role" :disabled="busy" m-if="manageable(member)" @change="changeRole(member, $event)">
|
|
184
|
+
<option m-for="role in ROLE_OPTIONS" :value="role">{{ ROLES[role].label }}</option>
|
|
185
|
+
</select>
|
|
186
|
+
<span m-else>{{ ROLES[member.role].label }}</span>
|
|
187
|
+
</td>
|
|
188
|
+
<td class="actions">
|
|
189
|
+
<button type="button" class="link-button" m-if="owner && member.role == 'admin'" :disabled="busy" @click="transfer(member)">Make owner</button>
|
|
190
|
+
<button type="button" class="link-button danger" m-if="manageable(member)" :disabled="busy" @click="remove(member)">Remove</button>
|
|
191
|
+
</td>
|
|
192
|
+
</tr>
|
|
193
|
+
</tbody>
|
|
194
|
+
</table>
|
|
195
|
+
</div>
|
|
196
|
+
</section>
|
|
197
|
+
|
|
198
|
+
<section class="card" aria-labelledby="invitations-title">
|
|
199
|
+
<div class="card-head"><h2 id="invitations-title">Invitations waiting</h2></div>
|
|
200
|
+
<p class="empty" m-if="!list.invitations.length">None. Invite someone to share it.</p>
|
|
201
|
+
<table class="members" m-else>
|
|
202
|
+
<tbody>
|
|
203
|
+
<tr m-for="invitation in list.invitations" :key="invitation.id">
|
|
204
|
+
<td class="who">{{ invitation.email }}<small>{{ ROLES[invitation.role].label }} · sent by {{ invitation.invitedBy }} on {{ fullDate(invitation.sentAt) }} · expires {{ fullDate(invitation.expiresAt) }}</small></td>
|
|
205
|
+
<td class="actions">
|
|
206
|
+
<button type="button" class="link-button" :disabled="busy" @click="resend(invitation)">Resend</button>
|
|
207
|
+
<button type="button" class="link-button danger" :disabled="busy" @click="revoke(invitation)">Revoke</button>
|
|
208
|
+
</td>
|
|
209
|
+
</tr>
|
|
210
|
+
</tbody>
|
|
211
|
+
</table>
|
|
212
|
+
</section>
|
|
213
|
+
</Template>
|
|
214
|
+
</template>
|
|
215
|
+
|
|
216
|
+
<style scoped>
|
|
217
|
+
.status-line { min-height: 1.5em; margin: -8px 0 8px; color: var(--muted); font-size: 13px; }
|
|
218
|
+
</style>
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* The page for someone in no organisation: /no-organisation
|
|
4
|
+
* ("organisations.none"), on its own like the sign-in pages. Someone lands
|
|
5
|
+
* here when they've been removed from their only organisation: the router's
|
|
6
|
+
* `organisation` middleware sends them, and `without-organisation` sends
|
|
7
|
+
* anyone who does work in one away.
|
|
8
|
+
*
|
|
9
|
+
* It offers two ways in:
|
|
10
|
+
* the invitations waiting for their email, loaded with resource(), each with
|
|
11
|
+
* who sent it, its role and when it expires — Accept (which joins it and
|
|
12
|
+
* opens its dashboard, S9) or Decline; an expired one says so and can only
|
|
13
|
+
* be declined, whoever sent it being the one to ask for a new one
|
|
14
|
+
* starting an organisation of their own: its its name,
|
|
15
|
+
* of which they're the owner, as New organisation is
|
|
16
|
+
* Anything the app has told them — being removed from the organisation they were in is the usual thing — is listed above those, as a
|
|
17
|
+
* section of this page (they have no frame, so no page of their own for it), with the bell beside the logo: a link to it, with how many are unread,
|
|
18
|
+
* shown once they have any. It's kept current as the frame's is (a minute, or the tab coming back).
|
|
19
|
+
* and, below, Sign out. The API's answer about a field shows on it, anything
|
|
20
|
+
* else as a toast.
|
|
21
|
+
*/
|
|
22
|
+
import { computed, reactive, ref, resource, useRouter } from "@mana-js/mana";
|
|
23
|
+
|
|
24
|
+
import ApiError from "@/api/ApiError";
|
|
25
|
+
import * as members from "@/api/members";
|
|
26
|
+
import type { UserInvitation } from "@/api/members";
|
|
27
|
+
import type { NewOrganisation } from "@/api/types";
|
|
28
|
+
import AppLogo from "@/components/AppLogo.mana";
|
|
29
|
+
import NotificationBell from "@/components/NotificationBell.mana";
|
|
30
|
+
import NotificationList from "@/components/NotificationList.mana";
|
|
31
|
+
import TextField from "@/components/TextField.mana";
|
|
32
|
+
import { useNotificationCount } from "@/composables/notifications";
|
|
33
|
+
import { ROLES } from "@/shared/roles";
|
|
34
|
+
import { useNotifications } from "@/stores/notifications";
|
|
35
|
+
import { useSession } from "@/stores/session";
|
|
36
|
+
import { useToasts } from "@/stores/toasts";
|
|
37
|
+
import { fullDate } from "@/utilities/format";
|
|
38
|
+
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<script setup lang="ts">
|
|
42
|
+
defineOptions({ name: "NoOrganisation" });
|
|
43
|
+
|
|
44
|
+
const router = useRouter();
|
|
45
|
+
const sessionStore = useSession();
|
|
46
|
+
const notificationsStore = useNotifications();
|
|
47
|
+
const notificationPage = ref(1);
|
|
48
|
+
|
|
49
|
+
useNotificationCount();
|
|
50
|
+
const toastStore = useToasts();
|
|
51
|
+
|
|
52
|
+
const invitations = resource(() => members.userInvitations());
|
|
53
|
+
const form = reactive<NewOrganisation>({ name: "" });
|
|
54
|
+
const errors = reactive<{ name?: string }>({});
|
|
55
|
+
const busy = ref(false);
|
|
56
|
+
const creating = ref(false);
|
|
57
|
+
|
|
58
|
+
const waiting = computed(() => invitations.data ?? []);
|
|
59
|
+
|
|
60
|
+
function failed(title: string, error: unknown) {
|
|
61
|
+
toastStore.error(title, error instanceof ApiError ? error.message : "Something went wrong. Try again.");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function accept(invitation: UserInvitation) {
|
|
65
|
+
if(busy.value)
|
|
66
|
+
return;
|
|
67
|
+
|
|
68
|
+
busy.value = true;
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
sessionStore.receive(await members.acceptUserInvitation(invitation.id));
|
|
72
|
+
await router.replace({ name: "dashboard" });
|
|
73
|
+
} catch(error) {
|
|
74
|
+
failed("Couldn't accept the invitation", error);
|
|
75
|
+
invitations.reload();
|
|
76
|
+
} finally {
|
|
77
|
+
busy.value = false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function decline(invitation: UserInvitation) {
|
|
82
|
+
if(busy.value)
|
|
83
|
+
return;
|
|
84
|
+
|
|
85
|
+
busy.value = true;
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
await members.declineUserInvitation(invitation.id);
|
|
89
|
+
invitations.reload();
|
|
90
|
+
} catch(error) {
|
|
91
|
+
failed("Couldn't decline the invitation", error);
|
|
92
|
+
} finally {
|
|
93
|
+
busy.value = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function create() {
|
|
98
|
+
errors.name = form.name.trim() ? undefined : "Enter the organisation's name.";
|
|
99
|
+
|
|
100
|
+
if(errors.name || creating.value)
|
|
101
|
+
return;
|
|
102
|
+
|
|
103
|
+
creating.value = true;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
await sessionStore.createOrganisation({ name: form.name.trim() });
|
|
107
|
+
await router.replace({ name: "dashboard" });
|
|
108
|
+
} catch(error) {
|
|
109
|
+
if(error instanceof ApiError && error.field == "name")
|
|
110
|
+
errors[error.field] = error.message;
|
|
111
|
+
else
|
|
112
|
+
failed("Couldn't create the organisation", error);
|
|
113
|
+
} finally {
|
|
114
|
+
creating.value = false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function signOut() {
|
|
119
|
+
await sessionStore.signOut();
|
|
120
|
+
}
|
|
121
|
+
</script>
|
|
122
|
+
|
|
123
|
+
<template>
|
|
124
|
+
<div class="auth none">
|
|
125
|
+
<div class="top">
|
|
126
|
+
<AppLogo />
|
|
127
|
+
<NotificationBell target="#none-notifications" m-if="notificationsStore.total > 0" />
|
|
128
|
+
</div>
|
|
129
|
+
|
|
130
|
+
<h1>You're not in an organisation</h1>
|
|
131
|
+
<p class="lead">You can join one you've been invited to, or start your own.</p>
|
|
132
|
+
|
|
133
|
+
<section id="none-notifications" aria-labelledby="none-notifications-title" m-if="notificationsStore.total > 0">
|
|
134
|
+
<h2 id="none-notifications-title">Notifications</h2>
|
|
135
|
+
<NotificationList :page="notificationPage" @turn="notificationPage = $event" />
|
|
136
|
+
</section>
|
|
137
|
+
|
|
138
|
+
<section aria-labelledby="none-invitations-title">
|
|
139
|
+
<h2 id="none-invitations-title">Invitations waiting</h2>
|
|
140
|
+
|
|
141
|
+
<p class="hint" role="status" m-if="!invitations.data && !invitations.error">Looking for invitations…</p>
|
|
142
|
+
|
|
143
|
+
<div class="alert" role="alert" m-else-if="invitations.error">
|
|
144
|
+
We couldn't load your invitations.
|
|
145
|
+
<button type="button" class="link-button" @click="invitations.reload()">Try again</button>.
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<p class="hint" m-else-if="!waiting.length">None waiting for {{ sessionStore.user?.email }}. If someone has invited you, ask them to send it again.</p>
|
|
149
|
+
|
|
150
|
+
<ul class="invitations" m-else>
|
|
151
|
+
<li m-for="invitation in waiting" :key="invitation.id" class="card">
|
|
152
|
+
<b>{{ invitation.organisation }}</b>
|
|
153
|
+
<span class="muted">{{ ROLES[invitation.role].label }} · from {{ invitation.invitedBy }} · {{ invitation.expired ? "expired " : "expires " }}{{ fullDate(invitation.expiresAt) }}</span>
|
|
154
|
+
<span class="actions">
|
|
155
|
+
<button type="button" class="btn primary" :disabled="busy || invitation.expired" @click="accept(invitation)">Accept</button>
|
|
156
|
+
<button type="button" class="btn" :disabled="busy" @click="decline(invitation)">Decline</button>
|
|
157
|
+
</span>
|
|
158
|
+
</li>
|
|
159
|
+
</ul>
|
|
160
|
+
</section>
|
|
161
|
+
|
|
162
|
+
<form novalidate :class="{ 'is-submitting': creating }" :aria-busy="creating" aria-labelledby="none-create-title" @submit.prevent="create">
|
|
163
|
+
<h2 id="none-create-title">Start your own</h2>
|
|
164
|
+
|
|
165
|
+
<TextField id="organisation-name" label="Organisation name" autocomplete="organization" :error="errors.name" m-model="form.name" />
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
<div class="submit">
|
|
169
|
+
<button type="submit" class="btn primary" :disabled="creating">{{ creating ? "Creating…" : "Create organisation" }}</button>
|
|
170
|
+
</div>
|
|
171
|
+
</form>
|
|
172
|
+
|
|
173
|
+
<p class="hint"><button type="button" class="link-button" @click="signOut()">Sign out</button> of {{ sessionStore.user?.email }}</p>
|
|
174
|
+
</div>
|
|
175
|
+
</template>
|
|
176
|
+
|
|
177
|
+
<style scoped>
|
|
178
|
+
.none { width: min(100%, 460px); }
|
|
179
|
+
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
180
|
+
.none section, .none form { margin: 0 0 24px; }
|
|
181
|
+
.invitations { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
|
|
182
|
+
.invitations .card { display: grid; gap: 4px; padding: 12px 14px; }
|
|
183
|
+
.invitations .actions { display: flex; gap: 8px; margin-top: 8px; }
|
|
184
|
+
</style>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* Notifications, at /notifications ("notifications"), inside AppLayout: what the app has told the user, newest first, 25 to
|
|
4
|
+
* a page (`?page=2`), their own wherever they work — an invitation of theirs accepted, being removed from an organisation. The list is
|
|
5
|
+
* NotificationList's, which is also a section of the page for someone in no organisation.
|
|
6
|
+
*/
|
|
7
|
+
import { computed, useRoute, useRouter } from "@mana-js/mana";
|
|
8
|
+
|
|
9
|
+
import NotificationList from "@/components/NotificationList.mana";
|
|
10
|
+
import { pageParam } from "@/utilities/query";
|
|
11
|
+
|
|
12
|
+
defineOptions({ name: "Notifications" });
|
|
13
|
+
|
|
14
|
+
const route = useRoute();
|
|
15
|
+
const router = useRouter();
|
|
16
|
+
|
|
17
|
+
const page = computed(() => pageParam(route.query.page));
|
|
18
|
+
|
|
19
|
+
function turnTo(next: number) {
|
|
20
|
+
void router.push({ name: "notifications", query: next > 1 ? { page: String(next) } : {} });
|
|
21
|
+
}
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<div class="page-head">
|
|
26
|
+
<h1>Notifications</h1>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<NotificationList :page="page" @turn="turnTo" />
|
|
30
|
+
</template>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* The New organisation page: /organisations/new ("organisations.create"),
|
|
4
|
+
* inside AppLayout, opened from the organisation switcher. A page, as the app's
|
|
5
|
+
* forms are: the name and the base currency, as on Create account.
|
|
6
|
+
* The user owns it; its chart of accounts starts from the template and
|
|
7
|
+
* its dashboard shows the first steps.
|
|
8
|
+
*
|
|
9
|
+
* Creating it makes it the organisation you're working in and opens its
|
|
10
|
+
* dashboard; AppLayout keys its pages by organisation. The API's answer
|
|
11
|
+
* about a field shows on it, anything else as a toast. Back and Cancel
|
|
12
|
+
* return to where you were.
|
|
13
|
+
*/
|
|
14
|
+
import { reactive, ref, useRouter } from "@mana-js/mana";
|
|
15
|
+
|
|
16
|
+
import ApiError from "@/api/ApiError";
|
|
17
|
+
import type { NewOrganisation } from "@/api/types";
|
|
18
|
+
import TextField from "@/components/TextField.mana";
|
|
19
|
+
import { useSession } from "@/stores/session";
|
|
20
|
+
import { useToasts } from "@/stores/toasts";
|
|
21
|
+
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<script setup lang="ts">
|
|
25
|
+
defineOptions({ name: "OrganisationForm" });
|
|
26
|
+
|
|
27
|
+
const router = useRouter();
|
|
28
|
+
const sessionStore = useSession();
|
|
29
|
+
const toastStore = useToasts();
|
|
30
|
+
|
|
31
|
+
const form = reactive<NewOrganisation>({ name: "" });
|
|
32
|
+
const errors = reactive<{ name?: string }>({});
|
|
33
|
+
const saving = ref(false);
|
|
34
|
+
|
|
35
|
+
async function submit() {
|
|
36
|
+
errors.name = form.name.trim() ? undefined : "Enter the organisation's name.";
|
|
37
|
+
|
|
38
|
+
if(errors.name || saving.value)
|
|
39
|
+
return;
|
|
40
|
+
|
|
41
|
+
saving.value = true;
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
await sessionStore.createOrganisation({ name: form.name.trim() });
|
|
45
|
+
await router.push({ name: "dashboard" });
|
|
46
|
+
} catch(error) {
|
|
47
|
+
if(error instanceof ApiError && error.field == "name")
|
|
48
|
+
errors.name = error.message;
|
|
49
|
+
else
|
|
50
|
+
toastStore.error("Couldn't create the organisation", error instanceof ApiError ? error.message : "Something went wrong. Try again.");
|
|
51
|
+
} finally {
|
|
52
|
+
saving.value = false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function back() {
|
|
57
|
+
router.back();
|
|
58
|
+
}
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<template>
|
|
62
|
+
<button type="button" class="back link-button" @click="back()">← Back</button>
|
|
63
|
+
<div class="page-head"><h1>New organisation</h1></div>
|
|
64
|
+
|
|
65
|
+
<form class="card form-narrow" novalidate :class="{ 'is-submitting': saving }" @submit.prevent="submit">
|
|
66
|
+
<p class="lead">You'll be its owner. Its chart of accounts starts from the small-business template, and its dashboard shows the first steps.</p>
|
|
67
|
+
|
|
68
|
+
<TextField id="organisation-name" label="Organisation name" autocomplete="organization" :error="errors.name" m-model="form.name" />
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
<div class="form-foot">
|
|
72
|
+
<button type="submit" class="btn primary" :disabled="saving">{{ saving ? "Creating…" : "Create organisation" }}</button>
|
|
73
|
+
<button type="button" class="btn" @click="back()">Cancel</button>
|
|
74
|
+
</div>
|
|
75
|
+
</form>
|
|
76
|
+
</template>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* Organisation settings: /settings ("settings"), for the owner and admins (the `role` middleware): the organisation's name, which is saved as a whole, and the switcher shows it at once.
|
|
4
|
+
*/
|
|
5
|
+
import { reactive, ref, resource, watch } from "@mana-js/mana";
|
|
6
|
+
|
|
7
|
+
import ApiError from "@/api/ApiError";
|
|
8
|
+
import TextField from "@/components/TextField.mana";
|
|
9
|
+
import { useSession } from "@/stores/session";
|
|
10
|
+
import { useToasts } from "@/stores/toasts";
|
|
11
|
+
|
|
12
|
+
defineOptions({ name: "OrganisationSettings" });
|
|
13
|
+
|
|
14
|
+
const sessionStore = useSession();
|
|
15
|
+
const toastStore = useToasts();
|
|
16
|
+
const settings = resource(() => sessionStore.organisationSettings());
|
|
17
|
+
const form = reactive({ name: "" });
|
|
18
|
+
const error = ref<string | undefined>(undefined);
|
|
19
|
+
const saving = ref(false);
|
|
20
|
+
const saved = ref(false);
|
|
21
|
+
|
|
22
|
+
watch(() => settings.data, data => {
|
|
23
|
+
if(data)
|
|
24
|
+
form.name = data.name;
|
|
25
|
+
}, { immediate: true });
|
|
26
|
+
|
|
27
|
+
async function save() {
|
|
28
|
+
error.value = form.name.trim() ? undefined : "Enter the organisation's name.";
|
|
29
|
+
|
|
30
|
+
if(error.value || saving.value)
|
|
31
|
+
return;
|
|
32
|
+
|
|
33
|
+
saving.value = true;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
await sessionStore.saveOrganisation({ name: form.name.trim() });
|
|
37
|
+
saved.value = true;
|
|
38
|
+
} catch(failure) {
|
|
39
|
+
if(failure instanceof ApiError && failure.field == "name")
|
|
40
|
+
error.value = failure.message;
|
|
41
|
+
else
|
|
42
|
+
toastStore.error("Couldn't save the settings", failure instanceof ApiError ? failure.message : "Something went wrong. Try again.");
|
|
43
|
+
} finally {
|
|
44
|
+
saving.value = false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<template>
|
|
50
|
+
<main class="page">
|
|
51
|
+
<div class="page-head"><h1>Settings</h1></div>
|
|
52
|
+
|
|
53
|
+
<form class="card form-narrow" novalidate aria-labelledby="settings-title" :class="{ 'is-submitting': saving }" @submit.prevent="save">
|
|
54
|
+
<div class="card-head"><h2 id="settings-title">{{ sessionStore.organisation?.name }}</h2></div>
|
|
55
|
+
<TextField id="organisation-name" label="Name" :error="error" m-model="form.name" />
|
|
56
|
+
<div class="form-foot">
|
|
57
|
+
<button type="submit" class="btn primary" :disabled="saving">{{ saving ? "Saving…" : "Save changes" }}</button>
|
|
58
|
+
<span class="saved" role="status" m-if="saved">Saved.</span>
|
|
59
|
+
</div>
|
|
60
|
+
</form>
|
|
61
|
+
</main>
|
|
62
|
+
</template>
|