@krak-stack/auth 0.1.47 → 0.1.49
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/dist/api.d.ts +22 -2
- package/dist/components/admin-organization-form.js +0 -1
- package/dist/components/admin-organizations.js +0 -1
- package/dist/components/admin-users.js +0 -1
- package/dist/components/auth-client-api.d.ts +132 -122
- package/dist/components/auth-client.d.ts +24 -55
- package/dist/components/auth-client.js +23 -12
- package/dist/components/auth-forms.js +15 -12
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +1 -0
- package/dist/components/member-required.d.ts +43 -0
- package/dist/components/member-required.js +177 -0
- package/dist/components/organization-switcher.d.ts +12 -0
- package/dist/components/organization-switcher.js +118 -48
- package/dist/extra/api.group.d.ts +11 -1
- package/dist/extra/api.group.js +10 -1
- package/dist/extra/schema.d.ts +14 -0
- package/dist/extra/schema.js +32 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/service.d.ts +28 -0
- package/package.json +3 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { AuthUiClient } from "./auth-client";
|
|
3
|
+
declare const defaultMessages: {
|
|
4
|
+
readonly en: {
|
|
5
|
+
readonly member_required_title: "Organization access required";
|
|
6
|
+
readonly member_required_description: "You need organization access to continue.";
|
|
7
|
+
readonly member_required_org_description: "You need access to {organization} before opening the admin area.";
|
|
8
|
+
readonly member_required_no_permission: "Your account is signed in, but it does not have access to this organization.";
|
|
9
|
+
readonly member_required_invite_found: "You have a pending invitation to {organization}. Accept it to continue.";
|
|
10
|
+
readonly member_required_accept_invite: "Accept invitation";
|
|
11
|
+
readonly member_required_accepting_invite: "Accepting...";
|
|
12
|
+
readonly member_required_accept_error: "Could not accept the invitation.";
|
|
13
|
+
readonly member_required_contact: "Contact organization";
|
|
14
|
+
readonly member_required_contact_description: "If you expected access, contact the organization administrator.";
|
|
15
|
+
readonly member_required_copy_email: "Copy email";
|
|
16
|
+
readonly member_required_copied_email: "Copied email";
|
|
17
|
+
};
|
|
18
|
+
readonly fr: {
|
|
19
|
+
readonly member_required_title: "Accès à l'organisation requis";
|
|
20
|
+
readonly member_required_description: "Vous devez disposer d'un accès à l'organisation pour continuer.";
|
|
21
|
+
readonly member_required_org_description: "Vous devez avoir accès à {organization} avant d'ouvrir l'administration.";
|
|
22
|
+
readonly member_required_no_permission: "Votre compte est connecté, mais il ne dispose pas d'un accès à cette organisation.";
|
|
23
|
+
readonly member_required_invite_found: "Vous avez une invitation en attente pour {organization}. Acceptez-la pour continuer.";
|
|
24
|
+
readonly member_required_accept_invite: "Accepter l'invitation";
|
|
25
|
+
readonly member_required_accepting_invite: "Acceptation...";
|
|
26
|
+
readonly member_required_accept_error: "Impossible d'accepter l'invitation.";
|
|
27
|
+
readonly member_required_contact: "Contacter l'organisation";
|
|
28
|
+
readonly member_required_contact_description: "Si vous pensiez avoir accès, contactez l'administrateur de l'organisation.";
|
|
29
|
+
readonly member_required_copy_email: "Copier l'e-mail";
|
|
30
|
+
readonly member_required_copied_email: "E-mail copié";
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
type MemberRequiredLabels = (typeof defaultMessages)["en"];
|
|
34
|
+
export type MemberRequiredMessages = Partial<MemberRequiredLabels>;
|
|
35
|
+
export type MemberRequiredProps = {
|
|
36
|
+
authClient?: AuthUiClient | undefined;
|
|
37
|
+
organizationId: string;
|
|
38
|
+
contactEmail?: string | undefined;
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
messages?: MemberRequiredMessages | undefined;
|
|
41
|
+
};
|
|
42
|
+
export declare function MemberRequired({ authClient: providedAuthClient, organizationId, contactEmail, children, messages, }: MemberRequiredProps): import("react").JSX.Element;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useAtomSuspense } from "@effect/atom-react";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { Atom } from "effect/unstable/reactivity";
|
|
5
|
+
import { Check, Loader2, Mail, ShieldAlert } from "lucide-react";
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import { Button } from "@/components/ui/button";
|
|
8
|
+
import { CopyButton } from "@/components/ui/copy-button";
|
|
9
|
+
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card";
|
|
10
|
+
import { useKrakstackAuth } from "./auth-provider";
|
|
11
|
+
const defaultMessages = {
|
|
12
|
+
en: {
|
|
13
|
+
member_required_title: "Organization access required",
|
|
14
|
+
member_required_description: "You need organization access to continue.",
|
|
15
|
+
member_required_org_description: "You need access to {organization} before opening the admin area.",
|
|
16
|
+
member_required_no_permission: "Your account is signed in, but it does not have access to this organization.",
|
|
17
|
+
member_required_invite_found: "You have a pending invitation to {organization}. Accept it to continue.",
|
|
18
|
+
member_required_accept_invite: "Accept invitation",
|
|
19
|
+
member_required_accepting_invite: "Accepting...",
|
|
20
|
+
member_required_accept_error: "Could not accept the invitation.",
|
|
21
|
+
member_required_contact: "Contact organization",
|
|
22
|
+
member_required_contact_description: "If you expected access, contact the organization administrator.",
|
|
23
|
+
member_required_copy_email: "Copy email",
|
|
24
|
+
member_required_copied_email: "Copied email",
|
|
25
|
+
},
|
|
26
|
+
fr: {
|
|
27
|
+
member_required_title: "Accès à l'organisation requis",
|
|
28
|
+
member_required_description: "Vous devez disposer d'un accès à l'organisation pour continuer.",
|
|
29
|
+
member_required_org_description: "Vous devez avoir accès à {organization} avant d'ouvrir l'administration.",
|
|
30
|
+
member_required_no_permission: "Votre compte est connecté, mais il ne dispose pas d'un accès à cette organisation.",
|
|
31
|
+
member_required_invite_found: "Vous avez une invitation en attente pour {organization}. Acceptez-la pour continuer.",
|
|
32
|
+
member_required_accept_invite: "Accepter l'invitation",
|
|
33
|
+
member_required_accepting_invite: "Acceptation...",
|
|
34
|
+
member_required_accept_error: "Impossible d'accepter l'invitation.",
|
|
35
|
+
member_required_contact: "Contacter l'organisation",
|
|
36
|
+
member_required_contact_description: "Si vous pensiez avoir accès, contactez l'administrateur de l'organisation.",
|
|
37
|
+
member_required_copy_email: "Copier l'e-mail",
|
|
38
|
+
member_required_copied_email: "E-mail copié",
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const isFullOrganization = (value) => {
|
|
42
|
+
if (typeof value !== "object" || value === null)
|
|
43
|
+
return false;
|
|
44
|
+
if (!("id" in value) || typeof value.id !== "string")
|
|
45
|
+
return false;
|
|
46
|
+
if (!("name" in value) || typeof value.name !== "string")
|
|
47
|
+
return false;
|
|
48
|
+
if (!("slug" in value) || typeof value.slug !== "string")
|
|
49
|
+
return false;
|
|
50
|
+
if (!("displayName" in value) || typeof value.displayName !== "string") {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
const interpolate = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
|
|
56
|
+
const labels = (locale, overrides) => ({
|
|
57
|
+
...(locale === "fr" ? defaultMessages.fr : defaultMessages.en),
|
|
58
|
+
...overrides,
|
|
59
|
+
});
|
|
60
|
+
const invitationMatches = (invitation, organizationId) => invitation.status === "pending" && invitation.organizationId === organizationId;
|
|
61
|
+
const organizationContactEmail = (organization, fallback) => organization?.contactEmail ?? fallback ?? null;
|
|
62
|
+
const organizationDisplayName = (invitation, organization, fallback) => organization?.displayName ??
|
|
63
|
+
organization?.name ??
|
|
64
|
+
invitation?.organization?.name ??
|
|
65
|
+
invitation?.organizationName ??
|
|
66
|
+
fallback;
|
|
67
|
+
const organizationProfileUrl = (baseUrl, organizationId) => {
|
|
68
|
+
const root = baseUrl?.trim() ||
|
|
69
|
+
(typeof window === "undefined" ? "" : window.location.origin);
|
|
70
|
+
const url = new URL("/api/auth/organization-profile", root);
|
|
71
|
+
url.searchParams.set("organizationId", organizationId);
|
|
72
|
+
return url;
|
|
73
|
+
};
|
|
74
|
+
const getOrganizationPublicProfile = async (baseUrl, organizationId) => {
|
|
75
|
+
const response = await fetch(organizationProfileUrl(baseUrl, organizationId), {
|
|
76
|
+
credentials: "include",
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok)
|
|
79
|
+
return null;
|
|
80
|
+
const body = await response.json();
|
|
81
|
+
return isFullOrganization(body) ? body : null;
|
|
82
|
+
};
|
|
83
|
+
const accessAtom = Atom.family((authClient) => Atom.family((key) => {
|
|
84
|
+
const { baseUrl, organizationId } = JSON.parse(key);
|
|
85
|
+
return Atom.keepAlive(Atom.make(Effect.tryPromise({
|
|
86
|
+
try: async () => {
|
|
87
|
+
const activeResult = await authClient.organization.setActive({
|
|
88
|
+
organizationId,
|
|
89
|
+
});
|
|
90
|
+
if (!activeResult.error)
|
|
91
|
+
return { allowed: true };
|
|
92
|
+
const [organization, invitationsResult] = await Promise.all([
|
|
93
|
+
getOrganizationPublicProfile(baseUrl, organizationId).catch(() => null),
|
|
94
|
+
authClient.organization.listUserInvitations({}),
|
|
95
|
+
]);
|
|
96
|
+
return {
|
|
97
|
+
allowed: false,
|
|
98
|
+
organization,
|
|
99
|
+
invitation: invitationsResult.data?.find((item) => invitationMatches(item, organizationId)) ?? null,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
catch: (error) => error,
|
|
103
|
+
})));
|
|
104
|
+
}));
|
|
105
|
+
const accessAtomKey = ({ authRefreshVersion, baseUrl, organizationId, userId, }) => JSON.stringify({ authRefreshVersion, baseUrl, organizationId, userId });
|
|
106
|
+
export function MemberRequired({ authClient: providedAuthClient, organizationId, contactEmail, children, messages, }) {
|
|
107
|
+
const auth = useKrakstackAuth();
|
|
108
|
+
const authClient = providedAuthClient ?? auth?.authClient;
|
|
109
|
+
const baseUrl = auth?.baseUrl;
|
|
110
|
+
const authRefreshVersion = auth?.authRefreshVersion ?? 0;
|
|
111
|
+
const locale = auth?.locale;
|
|
112
|
+
const refreshAuth = auth?.refreshAuth;
|
|
113
|
+
if (!authClient) {
|
|
114
|
+
throw new Error("KrakstackAuthProvider is required to use authClient.");
|
|
115
|
+
}
|
|
116
|
+
const session = authClient.useSession();
|
|
117
|
+
const userId = session.data?.user.id;
|
|
118
|
+
const currentAccessKey = accessAtomKey({
|
|
119
|
+
authRefreshVersion,
|
|
120
|
+
baseUrl,
|
|
121
|
+
organizationId,
|
|
122
|
+
userId,
|
|
123
|
+
});
|
|
124
|
+
const [allowedAccessKey, setAllowedAccessKey] = useState(null);
|
|
125
|
+
if (allowedAccessKey === currentAccessKey)
|
|
126
|
+
return _jsx(_Fragment, { children: children });
|
|
127
|
+
return (_jsx(MemberRequiredGate, { accessKey: currentAccessKey, authClient: authClient, contactEmail: contactEmail, locale: locale, messages: messages, onAccessAllowed: () => setAllowedAccessKey(currentAccessKey), organizationId: organizationId, refreshAuth: refreshAuth, children: children }));
|
|
128
|
+
}
|
|
129
|
+
function MemberRequiredGate({ accessKey, authClient, contactEmail, children, locale, messages, onAccessAllowed, organizationId, refreshAuth, }) {
|
|
130
|
+
const m = labels(locale, messages);
|
|
131
|
+
const accessResult = useAtomSuspense(accessAtom(authClient)(accessKey), {
|
|
132
|
+
suspendOnWaiting: true,
|
|
133
|
+
});
|
|
134
|
+
const [accepting, setAccepting] = useState(false);
|
|
135
|
+
const [error, setError] = useState(null);
|
|
136
|
+
const access = accessResult.value;
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
if (!access.allowed)
|
|
139
|
+
return;
|
|
140
|
+
onAccessAllowed();
|
|
141
|
+
}, [access.allowed, onAccessAllowed]);
|
|
142
|
+
if (access.allowed)
|
|
143
|
+
return _jsx(_Fragment, { children: children });
|
|
144
|
+
const { invitation, organization } = access;
|
|
145
|
+
const displayName = organizationDisplayName(invitation, organization, organizationId);
|
|
146
|
+
const resolvedContactEmail = organizationContactEmail(organization, contactEmail);
|
|
147
|
+
const acceptInvitation = async () => {
|
|
148
|
+
if (!invitation)
|
|
149
|
+
return;
|
|
150
|
+
setAccepting(true);
|
|
151
|
+
setError(null);
|
|
152
|
+
const result = await authClient.organization.acceptInvitation({
|
|
153
|
+
invitationId: invitation.id,
|
|
154
|
+
});
|
|
155
|
+
if (result.error) {
|
|
156
|
+
setAccepting(false);
|
|
157
|
+
setError(result.error.message ?? m.member_required_accept_error);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
await authClient.organization.setActive({
|
|
161
|
+
organizationId: invitation.organizationId,
|
|
162
|
+
});
|
|
163
|
+
refreshAuth?.();
|
|
164
|
+
onAccessAllowed();
|
|
165
|
+
setAccepting(false);
|
|
166
|
+
};
|
|
167
|
+
return (_jsx("main", { className: "relative grid min-h-screen place-items-center px-6 py-10", children: _jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx("div", { className: "bg-destructive/10 text-destructive mb-2 flex size-10 items-center justify-center rounded-md", children: _jsx(ShieldAlert, {}) }), _jsx(CardTitle, { children: m.member_required_title }), _jsx(CardDescription, { children: interpolate(m.member_required_org_description, {
|
|
168
|
+
organization: displayName,
|
|
169
|
+
}) })] }), _jsxs(CardContent, { className: "space-y-3", children: [invitation ? (_jsx("p", { className: "text-muted-foreground text-sm", children: interpolate(m.member_required_invite_found, {
|
|
170
|
+
organization: displayName,
|
|
171
|
+
}) })) : (_jsx("p", { className: "text-muted-foreground text-sm", children: m.member_required_contact_description })), resolvedContactEmail ? (_jsxs("div", { className: "bg-muted/50 flex items-center justify-between gap-3 rounded-md border px-3 py-2 text-sm", children: [_jsxs("span", { className: "flex min-w-0 items-center gap-2 font-medium", children: [_jsx(Mail, { className: "text-muted-foreground size-4 shrink-0" }), _jsx("span", { className: "truncate", children: resolvedContactEmail })] }), _jsx(CopyButton, { value: resolvedContactEmail, valueDescription: resolvedContactEmail, variant: "ghost", className: "shrink-0", messages: {
|
|
172
|
+
copy: m.member_required_copy_email,
|
|
173
|
+
copied: m.member_required_copied_email,
|
|
174
|
+
} })] })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }), _jsx(CardFooter, { className: "flex flex-wrap gap-2", children: invitation ? (_jsxs(Button, { onClick: acceptInvitation, disabled: accepting, children: [accepting ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(Check, { className: "size-4" })), accepting
|
|
175
|
+
? m.member_required_accepting_invite
|
|
176
|
+
: m.member_required_accept_invite] })) : null })] }) }));
|
|
177
|
+
}
|
|
@@ -22,6 +22,10 @@ declare const messages: {
|
|
|
22
22
|
readonly organization_invitation_reject_error: "Could not decline the invitation.";
|
|
23
23
|
readonly organization_invitation_rejected: "Invitation declined.";
|
|
24
24
|
readonly organization_invitation_status: "Status";
|
|
25
|
+
readonly organization_invitation_status_accepted: "Accepted";
|
|
26
|
+
readonly organization_invitation_status_canceled: "Canceled";
|
|
27
|
+
readonly organization_invitation_status_pending: "Pending";
|
|
28
|
+
readonly organization_invitation_status_rejected: "Rejected";
|
|
25
29
|
readonly organization_invitations_description: "Track invitations that have not been accepted yet.";
|
|
26
30
|
readonly organization_invitations_empty: "No pending invitations.";
|
|
27
31
|
readonly organization_invitations_heading: "Pending invitations";
|
|
@@ -39,6 +43,8 @@ declare const messages: {
|
|
|
39
43
|
readonly organization_logo_upload_error: "Could not upload the organization logo.";
|
|
40
44
|
readonly organization_member_email: "Email";
|
|
41
45
|
readonly organization_member_joined: "Joined";
|
|
46
|
+
readonly organization_member_leave: "Leave organization";
|
|
47
|
+
readonly organization_member_leave_error: "Could not leave the organization.";
|
|
42
48
|
readonly organization_member_remove: "Remove member";
|
|
43
49
|
readonly organization_member_remove_error: "Could not remove the member.";
|
|
44
50
|
readonly organization_member_role: "Role";
|
|
@@ -102,6 +108,10 @@ declare const messages: {
|
|
|
102
108
|
readonly organization_invitation_reject_error: "Impossible de refuser l'invitation.";
|
|
103
109
|
readonly organization_invitation_rejected: "Invitation refusée.";
|
|
104
110
|
readonly organization_invitation_status: "Statut";
|
|
111
|
+
readonly organization_invitation_status_accepted: "Acceptée";
|
|
112
|
+
readonly organization_invitation_status_canceled: "Annulée";
|
|
113
|
+
readonly organization_invitation_status_pending: "En attente";
|
|
114
|
+
readonly organization_invitation_status_rejected: "Refusée";
|
|
105
115
|
readonly organization_invitations_description: "Suivez les invitations qui n'ont pas encore été acceptées.";
|
|
106
116
|
readonly organization_invitations_empty: "Aucune invitation en attente.";
|
|
107
117
|
readonly organization_invitations_heading: "Invitations en attente";
|
|
@@ -119,6 +129,8 @@ declare const messages: {
|
|
|
119
129
|
readonly organization_logo_upload_error: "Impossible de téléverser le logo de l'organisation.";
|
|
120
130
|
readonly organization_member_email: "Courriel";
|
|
121
131
|
readonly organization_member_joined: "Arrivée";
|
|
132
|
+
readonly organization_member_leave: "Quitter l'organisation";
|
|
133
|
+
readonly organization_member_leave_error: "Impossible de quitter l'organisation.";
|
|
122
134
|
readonly organization_member_remove: "Retirer le membre";
|
|
123
135
|
readonly organization_member_remove_error: "Impossible de retirer le membre.";
|
|
124
136
|
readonly organization_member_role: "Rôle";
|
|
@@ -4,7 +4,7 @@ import { useStore } from "@tanstack/react-form";
|
|
|
4
4
|
import {} from "@tanstack/react-table";
|
|
5
5
|
import { Effect, Schema } from "effect";
|
|
6
6
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
7
|
-
import { Building2, Check, ChevronsUpDown, Copy, KeyRound, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
|
|
7
|
+
import { Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
|
|
8
8
|
import { createContext, useContext, useEffect, useEffectEvent, useRef, useState, } from "react";
|
|
9
9
|
import { DataTable, DataTableRelationshipCell, } from "@/components/ui/data-table";
|
|
10
10
|
import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
|
|
@@ -16,7 +16,7 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, }
|
|
|
16
16
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
17
17
|
import { Separator } from "@/components/ui/separator";
|
|
18
18
|
import { OrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
19
|
-
import {
|
|
19
|
+
import { isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, } from "../roles";
|
|
20
20
|
import { authClientApi } from "./auth-client-api";
|
|
21
21
|
import { useKrakstackAuth } from "./auth-provider";
|
|
22
22
|
import { createApiKey } from "./api-key";
|
|
@@ -44,6 +44,10 @@ const messages = {
|
|
|
44
44
|
organization_invitation_reject_error: "Could not decline the invitation.",
|
|
45
45
|
organization_invitation_rejected: "Invitation declined.",
|
|
46
46
|
organization_invitation_status: "Status",
|
|
47
|
+
organization_invitation_status_accepted: "Accepted",
|
|
48
|
+
organization_invitation_status_canceled: "Canceled",
|
|
49
|
+
organization_invitation_status_pending: "Pending",
|
|
50
|
+
organization_invitation_status_rejected: "Rejected",
|
|
47
51
|
organization_invitations_description: "Track invitations that have not been accepted yet.",
|
|
48
52
|
organization_invitations_empty: "No pending invitations.",
|
|
49
53
|
organization_invitations_heading: "Pending invitations",
|
|
@@ -61,6 +65,8 @@ const messages = {
|
|
|
61
65
|
organization_logo_upload_error: "Could not upload the organization logo.",
|
|
62
66
|
organization_member_email: "Email",
|
|
63
67
|
organization_member_joined: "Joined",
|
|
68
|
+
organization_member_leave: "Leave organization",
|
|
69
|
+
organization_member_leave_error: "Could not leave the organization.",
|
|
64
70
|
organization_member_remove: "Remove member",
|
|
65
71
|
organization_member_remove_error: "Could not remove the member.",
|
|
66
72
|
organization_member_role: "Role",
|
|
@@ -124,6 +130,10 @@ const messages = {
|
|
|
124
130
|
organization_invitation_reject_error: "Impossible de refuser l'invitation.",
|
|
125
131
|
organization_invitation_rejected: "Invitation refusée.",
|
|
126
132
|
organization_invitation_status: "Statut",
|
|
133
|
+
organization_invitation_status_accepted: "Acceptée",
|
|
134
|
+
organization_invitation_status_canceled: "Annulée",
|
|
135
|
+
organization_invitation_status_pending: "En attente",
|
|
136
|
+
organization_invitation_status_rejected: "Refusée",
|
|
127
137
|
organization_invitations_description: "Suivez les invitations qui n'ont pas encore été acceptées.",
|
|
128
138
|
organization_invitations_empty: "Aucune invitation en attente.",
|
|
129
139
|
organization_invitations_heading: "Invitations en attente",
|
|
@@ -141,6 +151,8 @@ const messages = {
|
|
|
141
151
|
organization_logo_upload_error: "Impossible de téléverser le logo de l'organisation.",
|
|
142
152
|
organization_member_email: "Courriel",
|
|
143
153
|
organization_member_joined: "Arrivée",
|
|
154
|
+
organization_member_leave: "Quitter l'organisation",
|
|
155
|
+
organization_member_leave_error: "Impossible de quitter l'organisation.",
|
|
144
156
|
organization_member_remove: "Retirer le membre",
|
|
145
157
|
organization_member_remove_error: "Impossible de retirer le membre.",
|
|
146
158
|
organization_member_role: "Rôle",
|
|
@@ -204,6 +216,10 @@ const organizationMessageFns = (labels) => new Proxy({}, {
|
|
|
204
216
|
});
|
|
205
217
|
const OrganizationMessagesContext = createContext(organizationMessageFns(organizationSwitcherMessages()));
|
|
206
218
|
const useOrganizationMessages = () => useContext(OrganizationMessagesContext);
|
|
219
|
+
const normalizeInvitationRole = (role) => {
|
|
220
|
+
const normalized = normalizeOrganizationRole(role);
|
|
221
|
+
return normalized === "support" ? "member" : normalized;
|
|
222
|
+
};
|
|
207
223
|
const userInvitationsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make(Effect.tryPromise({
|
|
208
224
|
try: async () => {
|
|
209
225
|
const result = await authClient.organization.listUserInvitations({});
|
|
@@ -215,7 +231,10 @@ const userInvitationsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make
|
|
|
215
231
|
},
|
|
216
232
|
catch: (error) => error,
|
|
217
233
|
}))));
|
|
218
|
-
const emptyUserInvitationsAtom = Atom.make(Effect.
|
|
234
|
+
const emptyUserInvitationsAtom = Atom.make(Effect.try({
|
|
235
|
+
try: () => [],
|
|
236
|
+
catch: (error) => error,
|
|
237
|
+
}));
|
|
219
238
|
const organizationMembersAtom = Atom.family((authClient) => Atom.family((organizationId) => Atom.keepAlive(Atom.make(Effect.tryPromise({
|
|
220
239
|
try: async () => {
|
|
221
240
|
const [membersResult, invitationsResult] = await Promise.all([
|
|
@@ -350,6 +369,20 @@ const organizationRoleLabel = (role, m) => {
|
|
|
350
369
|
return m.organization_role_member();
|
|
351
370
|
}
|
|
352
371
|
};
|
|
372
|
+
const invitationStatusLabel = (status, m) => {
|
|
373
|
+
switch (status) {
|
|
374
|
+
case "accepted":
|
|
375
|
+
return m.organization_invitation_status_accepted();
|
|
376
|
+
case "canceled":
|
|
377
|
+
return m.organization_invitation_status_canceled();
|
|
378
|
+
case "pending":
|
|
379
|
+
return m.organization_invitation_status_pending();
|
|
380
|
+
case "rejected":
|
|
381
|
+
return m.organization_invitation_status_rejected();
|
|
382
|
+
default:
|
|
383
|
+
return status;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
353
386
|
const formatOrganizationDate = (date) => new Intl.DateTimeFormat(getLocale(), { dateStyle: "medium" }).format(new Date(date));
|
|
354
387
|
const organizationMetadataFromForm = async (value, m, uploadImage) => {
|
|
355
388
|
const translations = [];
|
|
@@ -413,6 +446,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
413
446
|
const loadingUserInvitations = invitationsResult._tag === "Initial";
|
|
414
447
|
const activeMemberRole = normalizeOrganizationRole(activeOrganization.data?.members.find((member) => member.userId === session.data?.user.id)?.role);
|
|
415
448
|
const canManageApiKeys = activeMemberRole === "owner" || activeMemberRole === "admin";
|
|
449
|
+
const canUpdateOrganization = canManageApiKeys;
|
|
416
450
|
const setDialog = (next) => {
|
|
417
451
|
const nextDialog = typeof next === "function" ? next(dialog) : next;
|
|
418
452
|
if (nextDialog === dialog)
|
|
@@ -481,9 +515,12 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
481
515
|
? m.organization_switcher_no_other_organizations()
|
|
482
516
|
: m.organization_switcher_empty() })) : null, !locked ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: openCreate, children: [_jsx(Plus, {}), m.organization_create_title()] }), _jsxs(DropdownMenuItem, { onClick: () => {
|
|
483
517
|
setDialog("invitations");
|
|
484
|
-
}, children: [_jsx(Mail, {}), _jsxs("span", { className: "flex flex-1 items-center justify-between gap-3", children: [m.organization_user_invitations_title(), userInvitations.length ? (_jsx(Badge, { variant: "secondary", children: userInvitations.length })) : null] })] })] })) : null, activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}),
|
|
485
|
-
|
|
486
|
-
|
|
518
|
+
}, children: [_jsx(Mail, {}), _jsxs("span", { className: "flex flex-1 items-center justify-between gap-3", children: [m.organization_user_invitations_title(), userInvitations.length ? (_jsx(Badge, { variant: "secondary", children: userInvitations.length })) : null] })] })] })) : null, activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), (() => {
|
|
519
|
+
const organizationId = activeOrganization.data.id;
|
|
520
|
+
return (_jsxs(DropdownMenuItem, { onClick: () => {
|
|
521
|
+
void navigator.clipboard.writeText(organizationId);
|
|
522
|
+
}, children: [_jsx(Copy, {}), m.organization_copy_id()] }));
|
|
523
|
+
})(), canUpdateOrganization ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null] })) : null] }) })] })), _jsx(Dialog, { open: dialog === "create", onOpenChange: (open) => {
|
|
487
524
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
488
525
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { authClient: authClient, baseUrl: baseUrl, onCreated: async (organization) => {
|
|
489
526
|
setDialog(null);
|
|
@@ -495,15 +532,22 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
495
532
|
onCreate?.(organization);
|
|
496
533
|
onChange?.(organization);
|
|
497
534
|
}
|
|
498
|
-
} })] }) }), _jsx(Dialog, { open: dialog === "manage", onOpenChange: (open) => {
|
|
535
|
+
} })] }) }), _jsx(Dialog, { open: dialog === "manage" && canUpdateOrganization, onOpenChange: (open) => {
|
|
499
536
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
500
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
537
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx(Separator, {}), activeOrganization.data && canUpdateOrganization ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
501
538
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
502
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members"
|
|
539
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, canManageMembers: canManageApiKeys, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members", onLeft: async () => {
|
|
540
|
+
setDialog(null);
|
|
541
|
+
auth?.refreshAuth();
|
|
542
|
+
await refresh();
|
|
543
|
+
onChange?.(null);
|
|
544
|
+
} })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
|
|
503
545
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
504
546
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations" && !locked, onOpenChange: (open) => {
|
|
505
547
|
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
506
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError,
|
|
548
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization.data
|
|
549
|
+
? { activeOrganizationId: activeOrganization.data.id }
|
|
550
|
+
: {}), onActionComplete: refreshAfterInvitationAction })] }) })] }));
|
|
507
551
|
}
|
|
508
552
|
function UserInvitationsManager({ authClient, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
509
553
|
const m = useOrganizationMessages();
|
|
@@ -558,7 +602,7 @@ const userInvitationColumns = ({ m, }) => [
|
|
|
558
602
|
{
|
|
559
603
|
accessorKey: "status",
|
|
560
604
|
header: m.organization_invitation_status(),
|
|
561
|
-
cell: ({ row }) => _jsx(Badge, { children: row.original.status }),
|
|
605
|
+
cell: ({ row }) => (_jsx(Badge, { children: invitationStatusLabel(row.original.status, m) })),
|
|
562
606
|
},
|
|
563
607
|
{
|
|
564
608
|
accessorKey: "expiresAt",
|
|
@@ -647,16 +691,6 @@ function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated,
|
|
|
647
691
|
suggestedHeight: 512,
|
|
648
692
|
} })) }), _jsx(form.AppField, { name: "frContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "frLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }) }));
|
|
649
693
|
}
|
|
650
|
-
function CreateOrganizationSlugAutoFill({ form, }) {
|
|
651
|
-
const name = useStore(form.store, (state) => state.values.name);
|
|
652
|
-
const slugIsDirty = useStore(form.store, (state) => state.fieldMeta.slug?.isDirty ?? false);
|
|
653
|
-
useEffect(() => {
|
|
654
|
-
if (!slugIsDirty) {
|
|
655
|
-
form.setFieldValue("slug", slugify(name), { dontUpdateMeta: true });
|
|
656
|
-
}
|
|
657
|
-
}, [form, name, slugIsDirty]);
|
|
658
|
-
return null;
|
|
659
|
-
}
|
|
660
694
|
function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
|
|
661
695
|
const m = useOrganizationMessages();
|
|
662
696
|
const uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
|
|
@@ -713,11 +747,18 @@ function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
|
|
|
713
747
|
}
|
|
714
748
|
},
|
|
715
749
|
});
|
|
750
|
+
const name = useStore(form.store, (state) => state.values.name);
|
|
751
|
+
const slugIsDirty = useStore(form.store, (state) => state.fieldMeta.slug?.isDirty ?? false);
|
|
752
|
+
useEffect(() => {
|
|
753
|
+
if (!slugIsDirty) {
|
|
754
|
+
form.setFieldValue("slug", slugify(name), { dontUpdateMeta: true });
|
|
755
|
+
}
|
|
756
|
+
}, [form, name, slugIsDirty]);
|
|
716
757
|
return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.AppForm, { children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
|
|
717
758
|
event.preventDefault();
|
|
718
759
|
event.stopPropagation();
|
|
719
760
|
form.handleSubmit();
|
|
720
|
-
}, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), description: m.organization_slug_description() })) }), _jsx(
|
|
761
|
+
}, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), description: m.organization_slug_description() })) }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), size: {
|
|
721
762
|
width: 175,
|
|
722
763
|
height: 50,
|
|
723
764
|
suggestedWidth: 350,
|
|
@@ -746,7 +787,7 @@ function OrganizationTranslationHeader({ locale, editingLocale, onEditingLocaleC
|
|
|
746
787
|
: m.organization_translation_french();
|
|
747
788
|
return (_jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: title }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_translation_description() })] }), _jsx(EditingLocaleSwitcher, { value: editingLocale, onValueChange: onEditingLocaleChange })] }));
|
|
748
789
|
}
|
|
749
|
-
function OrganizationMembersManager({ authClient, baseUrl, organization, currentUserId, active, }) {
|
|
790
|
+
function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, organization, currentUserId, active, onLeft, }) {
|
|
750
791
|
const m = useOrganizationMessages();
|
|
751
792
|
const hasOpened = useOpenedOnce(active);
|
|
752
793
|
const membersAtom = hasOpened
|
|
@@ -756,11 +797,17 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
756
797
|
const refreshMembers = useAtomRefresh(membersAtom);
|
|
757
798
|
const [error, setError] = useState(null);
|
|
758
799
|
const [cancellingInvitationId, setCancellingInvitationId] = useState(null);
|
|
759
|
-
const
|
|
760
|
-
|
|
761
|
-
|
|
800
|
+
const [leavingOrganization, setLeavingOrganization] = useState(false);
|
|
801
|
+
const [lastMembersData, setLastMembersData] = useState(null);
|
|
802
|
+
const currentMembersData = AsyncResult.match(membersResult, {
|
|
803
|
+
onInitial: () => null,
|
|
804
|
+
onFailure: () => null,
|
|
762
805
|
onSuccess: ({ value }) => value,
|
|
763
806
|
});
|
|
807
|
+
const membersData = currentMembersData ?? lastMembersData ?? {
|
|
808
|
+
members: [],
|
|
809
|
+
invitations: [],
|
|
810
|
+
};
|
|
764
811
|
const members = membersData.members;
|
|
765
812
|
const invitations = membersData.invitations;
|
|
766
813
|
const [memberRoleOverrides, setMemberRoleOverrides] = useState({});
|
|
@@ -773,20 +820,21 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
773
820
|
onFailure: () => m.organization_members_load_error(),
|
|
774
821
|
onSuccess: () => null,
|
|
775
822
|
});
|
|
776
|
-
const loading = membersResult._tag === "Initial";
|
|
777
|
-
const
|
|
778
|
-
const
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
823
|
+
const loading = !lastMembersData && membersResult._tag === "Initial";
|
|
824
|
+
const canInviteMembers = canManageMembers;
|
|
825
|
+
const canRemoveMembers = canManageMembers;
|
|
826
|
+
useEffect(() => {
|
|
827
|
+
if (!currentMembersData)
|
|
828
|
+
return;
|
|
829
|
+
setLastMembersData(currentMembersData);
|
|
830
|
+
}, [currentMembersData]);
|
|
783
831
|
const inviteForm = useAppForm({
|
|
784
832
|
defaultValues: { email: "", role: "member" },
|
|
785
833
|
onSubmit: async ({ value, formApi }) => {
|
|
786
834
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
787
835
|
const result = await authClient.organization.inviteMember({
|
|
788
836
|
email: value.email.trim(),
|
|
789
|
-
role:
|
|
837
|
+
role: normalizeInvitationRole(value.role),
|
|
790
838
|
organizationId: organization.id,
|
|
791
839
|
});
|
|
792
840
|
if (result.error) {
|
|
@@ -836,6 +884,19 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
836
884
|
}
|
|
837
885
|
refreshMembers();
|
|
838
886
|
};
|
|
887
|
+
const leaveOrganization = async () => {
|
|
888
|
+
setLeavingOrganization(true);
|
|
889
|
+
setError(null);
|
|
890
|
+
const result = await authClient.organization.leave({
|
|
891
|
+
organizationId: organization.id,
|
|
892
|
+
});
|
|
893
|
+
setLeavingOrganization(false);
|
|
894
|
+
if (result.error) {
|
|
895
|
+
setError(result.error.message ?? m.organization_member_leave_error());
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
await onLeft();
|
|
899
|
+
};
|
|
839
900
|
const cancelInvitation = async (invitation) => {
|
|
840
901
|
setCancellingInvitationId(invitation.id);
|
|
841
902
|
setError(null);
|
|
@@ -849,26 +910,28 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
849
910
|
}
|
|
850
911
|
refreshMembers();
|
|
851
912
|
};
|
|
852
|
-
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [_jsx(inviteForm.AppForm, { children: _jsxs("form", { className: "grid gap-4
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
913
|
+
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [canInviteMembers ? (_jsx("div", { className: "min-h-40 rounded-lg border p-4", children: _jsx(inviteForm.AppForm, { children: _jsxs("form", { className: "grid gap-4 sm:grid-cols-[minmax(0,1fr)_12rem_auto] sm:items-end", onSubmit: (event) => {
|
|
914
|
+
event.preventDefault();
|
|
915
|
+
event.stopPropagation();
|
|
916
|
+
inviteForm.handleSubmit();
|
|
917
|
+
}, children: [_jsxs("div", { className: "sm:col-span-3", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(UserPlus, { className: "size-4" }), m.organization_invite_member_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invite_member_description() })] }), _jsx(inviteForm.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.organization_member_email(), placeholder: "teammate@example.com", type: "email", required: true })) }), _jsx(inviteForm.AppField, { name: "role", children: (field) => (_jsx(field.SelectField, { label: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
918
|
+
label: organizationRoleLabel(role, m),
|
|
919
|
+
value: role,
|
|
920
|
+
})) })) }), _jsx("div", { className: "self-end", children: _jsx(inviteForm.SubmitButton, {}) }), _jsx(inviteForm.FormError, {})] }) }) })) : null, membersError ? (_jsx("p", { className: "text-destructive text-sm", children: membersError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: memberColumns({
|
|
860
921
|
m,
|
|
861
922
|
baseUrl,
|
|
862
|
-
canChangeRoles:
|
|
923
|
+
canChangeRoles: canManageMembers,
|
|
863
924
|
onRoleChange: updateRole,
|
|
864
|
-
}), data: displayedMembers, emptyLabel:
|
|
925
|
+
}), data: displayedMembers, emptyLabel: m.organization_members_empty(), exportFileName: `${organization.slug}-members.csv`, features: { gallery: false }, isLoading: loading, searchState: "local", rowActions: memberRowActions({
|
|
865
926
|
m,
|
|
866
927
|
canRemoveMembers,
|
|
867
928
|
currentUserId,
|
|
929
|
+
leavingOrganization,
|
|
930
|
+
onLeave: leaveOrganization,
|
|
868
931
|
onRemove: removeMember,
|
|
869
932
|
}) }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_invitations_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invitations_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: invitationColumns({
|
|
870
933
|
m,
|
|
871
|
-
}), data: invitations, emptyLabel:
|
|
934
|
+
}), data: invitations, emptyLabel: m.organization_invitations_empty(), exportFileName: `${organization.slug}-invitations.csv`, features: { gallery: false }, isLoading: loading, searchState: "local", rowActions: invitationRowActions({
|
|
872
935
|
m,
|
|
873
936
|
cancellingInvitationId,
|
|
874
937
|
onCancel: cancelInvitation,
|
|
@@ -899,7 +962,7 @@ const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
|
899
962
|
return (_jsx(DataTableRelationshipCell, { emptyLabel: m.organization_member_role(), manageLabel: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
900
963
|
label: organizationRoleLabel(role, m),
|
|
901
964
|
value: role,
|
|
902
|
-
})), value: roleOptions, onAdd: (value) => {
|
|
965
|
+
})), value: roleOptions, from: "/", onAdd: (value) => {
|
|
903
966
|
if (!isOrganizationRole(value))
|
|
904
967
|
return;
|
|
905
968
|
onRoleChange(member, Array.from(new Set([...roles, value])));
|
|
@@ -917,7 +980,14 @@ const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
|
917
980
|
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.createdAt) })),
|
|
918
981
|
},
|
|
919
982
|
];
|
|
920
|
-
const memberRowActions = ({ m, canRemoveMembers, currentUserId, onRemove, }) => [
|
|
983
|
+
const memberRowActions = ({ m, canRemoveMembers, currentUserId, leavingOrganization, onLeave, onRemove, }) => [
|
|
984
|
+
{
|
|
985
|
+
name: m.organization_member_leave(),
|
|
986
|
+
icon: _jsx(LogOut, {}),
|
|
987
|
+
variant: "destructive",
|
|
988
|
+
visible: (member) => member.userId === currentUserId && !leavingOrganization,
|
|
989
|
+
onClick: onLeave,
|
|
990
|
+
},
|
|
921
991
|
{
|
|
922
992
|
name: m.organization_member_remove(),
|
|
923
993
|
icon: _jsx(Trash2, {}),
|
|
@@ -942,7 +1012,7 @@ const invitationColumns = ({ m, }) => [
|
|
|
942
1012
|
{
|
|
943
1013
|
accessorKey: "status",
|
|
944
1014
|
header: m.organization_invitation_status(),
|
|
945
|
-
cell: ({ row }) => _jsx(Badge, { children: row.original.status }),
|
|
1015
|
+
cell: ({ row }) => (_jsx(Badge, { children: invitationStatusLabel(row.original.status, m) })),
|
|
946
1016
|
},
|
|
947
1017
|
{
|
|
948
1018
|
accessorKey: "expiresAt",
|