@better-auth-ui/heroui 1.6.8 → 1.6.10
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/components/auth/api-key/api-key.d.ts +5 -1
- package/dist/components/auth/api-key/api-keys-empty.d.ts +3 -1
- package/dist/components/auth/api-key/api-keys.d.ts +9 -1
- package/dist/components/auth/api-key/create-api-key-dialog.d.ts +3 -1
- package/dist/components/auth/api-key/delete-api-key-dialog.d.ts +3 -1
- package/dist/components/auth/api-key/organization-api-keys.d.ts +14 -0
- package/dist/components/auth/delete-user/danger-zone.d.ts +1 -1
- package/dist/components/auth/delete-user/{delete-user.d.ts → delete-account.d.ts} +2 -2
- package/dist/components/auth/email/organization-invitation-email.d.ts +3 -0
- package/dist/components/auth/multi-session/switch-account-submenu-content.d.ts +3 -1
- package/dist/components/auth/multi-session/switch-account-submenu-item.d.ts +2 -1
- package/dist/components/auth/multi-session/switch-account-submenu.d.ts +2 -1
- package/dist/components/auth/organization/change-organization-logo.d.ts +4 -0
- package/dist/components/auth/organization/create-organization-dialog.d.ts +13 -0
- package/dist/components/auth/organization/delete-organization-dialog.d.ts +7 -0
- package/dist/components/auth/organization/delete-organization-skeleton.d.ts +4 -0
- package/dist/components/auth/organization/delete-organization.d.ts +5 -0
- package/dist/components/auth/organization/invite-member-dialog.d.ts +13 -0
- package/dist/components/auth/organization/leave-organization-dialog.d.ts +7 -0
- package/dist/components/auth/organization/leave-organization.d.ts +4 -0
- package/dist/components/auth/organization/organization-danger-zone.d.ts +16 -0
- package/dist/components/auth/organization/organization-invitation-row-skeleton.d.ts +5 -0
- package/dist/components/auth/organization/organization-invitation-row.d.ts +5 -0
- package/dist/components/auth/organization/organization-invitations-empty.d.ts +8 -0
- package/dist/components/auth/organization/organization-invitations.d.ts +9 -0
- package/dist/components/auth/organization/organization-logo.d.ts +15 -0
- package/dist/components/auth/organization/organization-member-row-skeleton.d.ts +4 -0
- package/dist/components/auth/organization/organization-member-row.d.ts +9 -0
- package/dist/components/auth/organization/organization-members.d.ts +9 -0
- package/dist/components/auth/organization/organization-people.d.ts +10 -0
- package/dist/components/auth/organization/organization-profile.d.ts +9 -0
- package/dist/components/auth/organization/organization-row.d.ts +8 -0
- package/dist/components/auth/organization/organization-settings.d.ts +12 -0
- package/dist/components/auth/organization/organization-switcher.d.ts +20 -0
- package/dist/components/auth/organization/organization-view-skeleton.d.ts +6 -0
- package/dist/components/auth/organization/organization-view.d.ts +15 -0
- package/dist/components/auth/organization/organization.d.ts +17 -0
- package/dist/components/auth/organization/organizations-empty.d.ts +4 -0
- package/dist/components/auth/organization/organizations-settings.d.ts +17 -0
- package/dist/components/auth/organization/organizations.d.ts +10 -0
- package/dist/components/auth/organization/remove-member-dialog.d.ts +9 -0
- package/dist/components/auth/organization/slug-field.d.ts +19 -0
- package/dist/components/auth/organization/user-invitation-row-skeleton.d.ts +4 -0
- package/dist/components/auth/organization/user-invitation-row.d.ts +10 -0
- package/dist/components/auth/organization/user-invitations-empty.d.ts +4 -0
- package/dist/components/auth/organization/user-invitations.d.ts +10 -0
- package/dist/components/auth/settings/settings.d.ts +1 -1
- package/dist/components/auth/user/user-avatar.d.ts +1 -1
- package/dist/components/auth/user/user-button.d.ts +4 -5
- package/dist/components/auth/user/user-view.d.ts +10 -4
- package/dist/email.d.ts +1 -0
- package/dist/email.js +211 -8
- package/dist/index.js +1682 -22
- package/dist/lib/auth/api-key-plugin.d.ts +5 -2
- package/dist/lib/auth/auth-plugin.d.ts +6 -2
- package/dist/lib/auth/delete-user-plugin.d.ts +4 -4
- package/dist/lib/auth/magic-link-plugin.d.ts +2 -2
- package/dist/lib/auth/multi-session-plugin.d.ts +2 -2
- package/dist/lib/auth/organization-plugin.d.ts +37 -0
- package/dist/lib/auth/passkey-plugin.d.ts +2 -2
- package/dist/lib/auth/theme-plugin.d.ts +3 -3
- package/dist/lib/auth/username-plugin.d.ts +8 -8
- package/dist/plugins.d.ts +25 -1
- package/dist/plugins.js +2824 -22
- package/dist/user-view--47tVtJ3.js +113 -0
- package/package.json +23 -18
- package/src/components/auth/api-key/api-key.tsx +25 -16
- package/src/components/auth/api-key/api-keys-empty.tsx +8 -4
- package/src/components/auth/api-key/api-keys.tsx +52 -14
- package/src/components/auth/api-key/create-api-key-dialog.tsx +15 -2
- package/src/components/auth/api-key/delete-api-key-dialog.tsx +10 -2
- package/src/components/auth/api-key/organization-api-keys.tsx +55 -0
- package/src/components/auth/delete-user/danger-zone.tsx +3 -3
- package/src/components/auth/delete-user/{delete-user.tsx → delete-account.tsx} +9 -9
- package/src/components/auth/email/organization-invitation-email.tsx +38 -0
- package/src/components/auth/error-toaster.tsx +28 -10
- package/src/components/auth/forgot-password.tsx +10 -2
- package/src/components/auth/multi-session/manage-accounts.tsx +1 -1
- package/src/components/auth/multi-session/switch-account-submenu-content.tsx +7 -2
- package/src/components/auth/multi-session/switch-account-submenu-item.tsx +4 -2
- package/src/components/auth/multi-session/switch-account-submenu.tsx +8 -4
- package/src/components/auth/organization/change-organization-logo.tsx +171 -0
- package/src/components/auth/organization/create-organization-dialog.tsx +133 -0
- package/src/components/auth/organization/delete-organization-dialog.tsx +97 -0
- package/src/components/auth/organization/delete-organization-skeleton.tsx +17 -0
- package/src/components/auth/organization/delete-organization.tsx +77 -0
- package/src/components/auth/organization/invite-member-dialog.tsx +177 -0
- package/src/components/auth/organization/leave-organization-dialog.tsx +95 -0
- package/src/components/auth/organization/leave-organization.tsx +59 -0
- package/src/components/auth/organization/organization-danger-zone.tsx +68 -0
- package/src/components/auth/organization/organization-invitation-row-skeleton.tsx +29 -0
- package/src/components/auth/organization/organization-invitation-row.tsx +97 -0
- package/src/components/auth/organization/organization-invitations-empty.tsx +39 -0
- package/src/components/auth/organization/organization-invitations.tsx +351 -0
- package/src/components/auth/organization/organization-logo.tsx +64 -0
- package/src/components/auth/organization/organization-member-row-skeleton.tsx +24 -0
- package/src/components/auth/organization/organization-member-row.tsx +157 -0
- package/src/components/auth/organization/organization-members.tsx +284 -0
- package/src/components/auth/organization/organization-people.tsx +26 -0
- package/src/components/auth/organization/organization-profile.tsx +141 -0
- package/src/components/auth/organization/organization-row.tsx +66 -0
- package/src/components/auth/organization/organization-settings.tsx +38 -0
- package/src/components/auth/organization/organization-switcher.tsx +233 -0
- package/src/components/auth/organization/organization-view-skeleton.tsx +36 -0
- package/src/components/auth/organization/organization-view.tsx +109 -0
- package/src/components/auth/organization/organization.tsx +162 -0
- package/src/components/auth/organization/organizations-empty.tsx +35 -0
- package/src/components/auth/organization/organizations-settings.tsx +36 -0
- package/src/components/auth/organization/organizations.tsx +80 -0
- package/src/components/auth/organization/remove-member-dialog.tsx +95 -0
- package/src/components/auth/organization/slug-field.tsx +111 -0
- package/src/components/auth/organization/user-invitation-row-skeleton.tsx +17 -0
- package/src/components/auth/organization/user-invitation-row.tsx +90 -0
- package/src/components/auth/organization/user-invitations-empty.tsx +30 -0
- package/src/components/auth/organization/user-invitations.tsx +59 -0
- package/src/components/auth/settings/account/change-email.tsx +1 -1
- package/src/components/auth/settings/account/user-profile.tsx +5 -5
- package/src/components/auth/settings/security/active-sessions.tsx +6 -4
- package/src/components/auth/settings/security/linked-accounts.tsx +2 -2
- package/src/components/auth/settings/settings.tsx +77 -14
- package/src/components/auth/user/user-avatar.tsx +4 -1
- package/src/components/auth/user/user-button.tsx +14 -11
- package/src/components/auth/user/user-view.tsx +32 -12
- package/src/email.ts +1 -0
- package/src/lib/auth/api-key-plugin.ts +10 -4
- package/src/lib/auth/auth-plugin.ts +6 -1
- package/src/lib/auth/organization-plugin.tsx +32 -0
- package/src/plugins.ts +25 -1
- package/dist/components/auth/additional-field.js +0 -270
- package/dist/components/auth/api-key/api-key-skeleton.js +0 -21
- package/dist/components/auth/api-key/api-key.js +0 -55
- package/dist/components/auth/api-key/api-keys-empty.js +0 -35
- package/dist/components/auth/api-key/api-keys.js +0 -41
- package/dist/components/auth/api-key/create-api-key-dialog.js +0 -74
- package/dist/components/auth/api-key/delete-api-key-dialog.js +0 -51
- package/dist/components/auth/api-key/new-api-key-dialog.js +0 -60
- package/dist/components/auth/auth-provider.js +0 -17
- package/dist/components/auth/auth.js +0 -63
- package/dist/components/auth/delete-user/danger-zone.js +0 -18
- package/dist/components/auth/delete-user/delete-user.js +0 -95
- package/dist/components/auth/email/email-changed-email.js +0 -30
- package/dist/components/auth/email/email-verification-email.js +0 -30
- package/dist/components/auth/email/magic-link-email.js +0 -30
- package/dist/components/auth/email/new-device-email.js +0 -30
- package/dist/components/auth/email/otp-email.js +0 -29
- package/dist/components/auth/email/password-changed-email.js +0 -30
- package/dist/components/auth/email/reset-password-email.js +0 -30
- package/dist/components/auth/error-toaster.js +0 -17
- package/dist/components/auth/field-separator.js +0 -18
- package/dist/components/auth/forgot-password.js +0 -89
- package/dist/components/auth/magic-link/magic-link-button.js +0 -20
- package/dist/components/auth/magic-link/magic-link.js +0 -87
- package/dist/components/auth/multi-session/manage-account.js +0 -49
- package/dist/components/auth/multi-session/manage-accounts.js +0 -34
- package/dist/components/auth/multi-session/switch-account-submenu-content.js +0 -28
- package/dist/components/auth/multi-session/switch-account-submenu-item.js +0 -20
- package/dist/components/auth/multi-session/switch-account-submenu.js +0 -24
- package/dist/components/auth/passkey/add-passkey-dialog.js +0 -65
- package/dist/components/auth/passkey/delete-passkey-dialog.js +0 -47
- package/dist/components/auth/passkey/passkey-button.js +0 -24
- package/dist/components/auth/passkey/passkey-skeleton.js +0 -17
- package/dist/components/auth/passkey/passkey.js +0 -48
- package/dist/components/auth/passkey/passkeys-empty.js +0 -35
- package/dist/components/auth/passkey/passkeys.js +0 -42
- package/dist/components/auth/provider-button.js +0 -25
- package/dist/components/auth/provider-buttons.js +0 -19
- package/dist/components/auth/reset-password.js +0 -147
- package/dist/components/auth/settings/account/account-settings.js +0 -20
- package/dist/components/auth/settings/account/change-avatar.js +0 -89
- package/dist/components/auth/settings/account/change-email.js +0 -54
- package/dist/components/auth/settings/account/user-profile.js +0 -86
- package/dist/components/auth/settings/security/active-session.js +0 -59
- package/dist/components/auth/settings/security/active-sessions.js +0 -34
- package/dist/components/auth/settings/security/change-password.js +0 -189
- package/dist/components/auth/settings/security/linked-account.js +0 -56
- package/dist/components/auth/settings/security/linked-accounts.js +0 -45
- package/dist/components/auth/settings/security/security-settings.js +0 -22
- package/dist/components/auth/settings/settings.js +0 -45
- package/dist/components/auth/sign-in.js +0 -133
- package/dist/components/auth/sign-out.js +0 -27
- package/dist/components/auth/sign-up.js +0 -212
- package/dist/components/auth/theme/appearance.js +0 -72
- package/dist/components/auth/theme/theme-toggle-item.js +0 -62
- package/dist/components/auth/user/user-avatar.js +0 -29
- package/dist/components/auth/user/user-button.js +0 -74
- package/dist/components/auth/user/user-view.js +0 -37
- package/dist/components/auth/username/sign-in-username.js +0 -148
- package/dist/components/auth/username/username-field.js +0 -53
- package/dist/lib/auth/api-key-plugin.js +0 -10
- package/dist/lib/auth/delete-user-plugin.js +0 -10
- package/dist/lib/auth/magic-link-plugin.js +0 -13
- package/dist/lib/auth/multi-session-plugin.js +0 -12
- package/dist/lib/auth/passkey-plugin.js +0 -12
- package/dist/lib/auth/theme-plugin.js +0 -23
- package/dist/lib/auth/username-plugin.js +0 -18
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type OrganizationAuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthPlugin,
|
|
5
|
+
useInviteMember
|
|
6
|
+
} from "@better-auth-ui/react"
|
|
7
|
+
import { PersonPlus } from "@gravity-ui/icons"
|
|
8
|
+
import {
|
|
9
|
+
AlertDialog,
|
|
10
|
+
Button,
|
|
11
|
+
FieldError,
|
|
12
|
+
Form,
|
|
13
|
+
Input,
|
|
14
|
+
Label,
|
|
15
|
+
ListBox,
|
|
16
|
+
Select,
|
|
17
|
+
Spinner,
|
|
18
|
+
TextField,
|
|
19
|
+
toast
|
|
20
|
+
} from "@heroui/react"
|
|
21
|
+
import { type SyntheticEvent, useEffect, useState } from "react"
|
|
22
|
+
|
|
23
|
+
import { organizationPlugin } from "../../../lib/auth/organization-plugin"
|
|
24
|
+
|
|
25
|
+
/** Props for the {@link InviteMemberDialog} component. */
|
|
26
|
+
export type InviteMemberDialogProps = {
|
|
27
|
+
isOpen: boolean
|
|
28
|
+
onOpenChange: (open: boolean) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const pickDefaultRole = (keys: string[]) =>
|
|
32
|
+
keys.includes("member") ? "member" : (keys.at(-1) ?? "")
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Render a dialog for inviting a member to the organization.
|
|
36
|
+
*
|
|
37
|
+
* @param isOpen - Whether the dialog is open
|
|
38
|
+
* @param onOpenChange - Callback for when the dialog open state changes
|
|
39
|
+
* @returns The invite member dialog as a JSX element
|
|
40
|
+
*/
|
|
41
|
+
export function InviteMemberDialog({
|
|
42
|
+
isOpen,
|
|
43
|
+
onOpenChange
|
|
44
|
+
}: InviteMemberDialogProps) {
|
|
45
|
+
const { authClient, localization } = useAuth()
|
|
46
|
+
const { localization: organizationLocalization, roles } =
|
|
47
|
+
useAuthPlugin(organizationPlugin)
|
|
48
|
+
|
|
49
|
+
const [role, setRole] = useState(() => pickDefaultRole(Object.keys(roles)))
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
setRole((current) => {
|
|
53
|
+
const keys = Object.keys(roles)
|
|
54
|
+
return keys.includes(current) ? current : pickDefaultRole(keys)
|
|
55
|
+
})
|
|
56
|
+
}, [roles])
|
|
57
|
+
|
|
58
|
+
const { mutate: inviteMember, isPending: isInviting } = useInviteMember(
|
|
59
|
+
authClient as OrganizationAuthClient,
|
|
60
|
+
{
|
|
61
|
+
onSuccess: () => {
|
|
62
|
+
onOpenChange(false)
|
|
63
|
+
toast.success(organizationLocalization.inviteMemberSuccess)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const isRoleValid = Object.keys(roles).includes(role)
|
|
69
|
+
|
|
70
|
+
const handleSubmit = (e: SyntheticEvent<HTMLFormElement>) => {
|
|
71
|
+
e.preventDefault()
|
|
72
|
+
|
|
73
|
+
if (!isRoleValid) return
|
|
74
|
+
|
|
75
|
+
const formData = new FormData(e.target as HTMLFormElement)
|
|
76
|
+
const email = formData.get("email") as string
|
|
77
|
+
|
|
78
|
+
inviteMember({
|
|
79
|
+
email: email.trim(),
|
|
80
|
+
role: role as Parameters<typeof inviteMember>[0]["role"]
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<AlertDialog.Backdrop isOpen={isOpen} onOpenChange={onOpenChange}>
|
|
86
|
+
<AlertDialog.Container>
|
|
87
|
+
<AlertDialog.Dialog>
|
|
88
|
+
<Form onSubmit={handleSubmit}>
|
|
89
|
+
<AlertDialog.CloseTrigger />
|
|
90
|
+
|
|
91
|
+
<AlertDialog.Header>
|
|
92
|
+
<AlertDialog.Icon status="default">
|
|
93
|
+
<PersonPlus />
|
|
94
|
+
</AlertDialog.Icon>
|
|
95
|
+
|
|
96
|
+
<AlertDialog.Heading>
|
|
97
|
+
{organizationLocalization.inviteMember}
|
|
98
|
+
</AlertDialog.Heading>
|
|
99
|
+
</AlertDialog.Header>
|
|
100
|
+
|
|
101
|
+
<AlertDialog.Body className="flex flex-col gap-4 overflow-visible">
|
|
102
|
+
<p className="text-muted text-sm">
|
|
103
|
+
{organizationLocalization.inviteMemberDescription}
|
|
104
|
+
</p>
|
|
105
|
+
|
|
106
|
+
<TextField
|
|
107
|
+
id="email"
|
|
108
|
+
name="email"
|
|
109
|
+
type="email"
|
|
110
|
+
isDisabled={isInviting}
|
|
111
|
+
>
|
|
112
|
+
<Label>{localization.auth.email}</Label>
|
|
113
|
+
|
|
114
|
+
<Input
|
|
115
|
+
autoFocus
|
|
116
|
+
placeholder={localization.auth.email}
|
|
117
|
+
variant="secondary"
|
|
118
|
+
required
|
|
119
|
+
/>
|
|
120
|
+
|
|
121
|
+
<FieldError />
|
|
122
|
+
</TextField>
|
|
123
|
+
|
|
124
|
+
<Select
|
|
125
|
+
name="role"
|
|
126
|
+
value={role}
|
|
127
|
+
onChange={(value) => {
|
|
128
|
+
if (typeof value === "string") setRole(value)
|
|
129
|
+
}}
|
|
130
|
+
isDisabled={isInviting}
|
|
131
|
+
variant="secondary"
|
|
132
|
+
fullWidth
|
|
133
|
+
>
|
|
134
|
+
<Label>{organizationLocalization.role}</Label>
|
|
135
|
+
|
|
136
|
+
<Select.Trigger>
|
|
137
|
+
<Select.Value />
|
|
138
|
+
<Select.Indicator />
|
|
139
|
+
</Select.Trigger>
|
|
140
|
+
|
|
141
|
+
<Select.Popover>
|
|
142
|
+
<ListBox>
|
|
143
|
+
{Object.entries(roles).map(([key, label]) => (
|
|
144
|
+
<ListBox.Item key={key} id={key} textValue={label}>
|
|
145
|
+
{label}
|
|
146
|
+
|
|
147
|
+
<ListBox.ItemIndicator />
|
|
148
|
+
</ListBox.Item>
|
|
149
|
+
))}
|
|
150
|
+
</ListBox>
|
|
151
|
+
</Select.Popover>
|
|
152
|
+
|
|
153
|
+
<FieldError />
|
|
154
|
+
</Select>
|
|
155
|
+
</AlertDialog.Body>
|
|
156
|
+
|
|
157
|
+
<AlertDialog.Footer>
|
|
158
|
+
<Button slot="close" variant="tertiary" isDisabled={isInviting}>
|
|
159
|
+
{localization.settings.cancel}
|
|
160
|
+
</Button>
|
|
161
|
+
|
|
162
|
+
<Button
|
|
163
|
+
type="submit"
|
|
164
|
+
isPending={isInviting}
|
|
165
|
+
isDisabled={!isRoleValid}
|
|
166
|
+
>
|
|
167
|
+
{isInviting && <Spinner color="current" size="sm" />}
|
|
168
|
+
|
|
169
|
+
{organizationLocalization.inviteMember}
|
|
170
|
+
</Button>
|
|
171
|
+
</AlertDialog.Footer>
|
|
172
|
+
</Form>
|
|
173
|
+
</AlertDialog.Dialog>
|
|
174
|
+
</AlertDialog.Container>
|
|
175
|
+
</AlertDialog.Backdrop>
|
|
176
|
+
)
|
|
177
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type OrganizationAuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthPlugin,
|
|
5
|
+
useLeaveOrganization
|
|
6
|
+
} from "@better-auth-ui/react"
|
|
7
|
+
import { ArrowRightFromSquare } from "@gravity-ui/icons"
|
|
8
|
+
import { AlertDialog, Button, Card, Spinner, toast } from "@heroui/react"
|
|
9
|
+
import type { Organization } from "better-auth/client"
|
|
10
|
+
|
|
11
|
+
import { organizationPlugin } from "../../../lib/auth/organization-plugin"
|
|
12
|
+
import { OrganizationView } from "./organization-view"
|
|
13
|
+
|
|
14
|
+
export type LeaveOrganizationDialogProps = {
|
|
15
|
+
isOpen: boolean
|
|
16
|
+
onOpenChange: (open: boolean) => void
|
|
17
|
+
organization: Organization
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function LeaveOrganizationDialog({
|
|
21
|
+
isOpen,
|
|
22
|
+
onOpenChange,
|
|
23
|
+
organization
|
|
24
|
+
}: LeaveOrganizationDialogProps) {
|
|
25
|
+
const { authClient, basePaths, localization, navigate } = useAuth()
|
|
26
|
+
const {
|
|
27
|
+
localization: organizationLocalization,
|
|
28
|
+
viewPaths: organizationPluginViewPaths
|
|
29
|
+
} = useAuthPlugin(organizationPlugin)
|
|
30
|
+
|
|
31
|
+
const { mutate: leaveOrganization, isPending } = useLeaveOrganization(
|
|
32
|
+
authClient as OrganizationAuthClient,
|
|
33
|
+
{
|
|
34
|
+
onSuccess: () => {
|
|
35
|
+
onOpenChange(false)
|
|
36
|
+
toast.success(organizationLocalization.leftOrganization)
|
|
37
|
+
|
|
38
|
+
navigate({
|
|
39
|
+
to: `${basePaths.settings}/${organizationPluginViewPaths.settings.organizations}`,
|
|
40
|
+
replace: true
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<AlertDialog.Backdrop isOpen={isOpen} onOpenChange={onOpenChange}>
|
|
48
|
+
<AlertDialog.Container>
|
|
49
|
+
<AlertDialog.Dialog>
|
|
50
|
+
<AlertDialog.CloseTrigger />
|
|
51
|
+
|
|
52
|
+
<AlertDialog.Header>
|
|
53
|
+
<AlertDialog.Icon status="danger">
|
|
54
|
+
<ArrowRightFromSquare />
|
|
55
|
+
</AlertDialog.Icon>
|
|
56
|
+
|
|
57
|
+
<AlertDialog.Heading>
|
|
58
|
+
{organizationLocalization.leaveOrganization}
|
|
59
|
+
</AlertDialog.Heading>
|
|
60
|
+
</AlertDialog.Header>
|
|
61
|
+
|
|
62
|
+
<AlertDialog.Body className="flex flex-col gap-4 overflow-visible">
|
|
63
|
+
<p className="text-muted text-sm">
|
|
64
|
+
{organizationLocalization.leaveOrganizationDescription}
|
|
65
|
+
</p>
|
|
66
|
+
|
|
67
|
+
<Card variant="secondary">
|
|
68
|
+
<Card.Content>
|
|
69
|
+
<OrganizationView organization={organization} hideRole />
|
|
70
|
+
</Card.Content>
|
|
71
|
+
</Card>
|
|
72
|
+
</AlertDialog.Body>
|
|
73
|
+
|
|
74
|
+
<AlertDialog.Footer>
|
|
75
|
+
<Button slot="close" variant="tertiary" isDisabled={isPending}>
|
|
76
|
+
{localization.settings.cancel}
|
|
77
|
+
</Button>
|
|
78
|
+
|
|
79
|
+
<Button
|
|
80
|
+
variant="danger"
|
|
81
|
+
isPending={isPending}
|
|
82
|
+
onPress={() =>
|
|
83
|
+
leaveOrganization({ organizationId: organization.id })
|
|
84
|
+
}
|
|
85
|
+
>
|
|
86
|
+
{isPending && <Spinner color="current" size="sm" />}
|
|
87
|
+
|
|
88
|
+
{organizationLocalization.leaveOrganization}
|
|
89
|
+
</Button>
|
|
90
|
+
</AlertDialog.Footer>
|
|
91
|
+
</AlertDialog.Dialog>
|
|
92
|
+
</AlertDialog.Container>
|
|
93
|
+
</AlertDialog.Backdrop>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type OrganizationAuthClient,
|
|
3
|
+
useActiveOrganization,
|
|
4
|
+
useAuth,
|
|
5
|
+
useAuthPlugin
|
|
6
|
+
} from "@better-auth-ui/react"
|
|
7
|
+
import { AlertDialog, Button } from "@heroui/react"
|
|
8
|
+
import { useState } from "react"
|
|
9
|
+
|
|
10
|
+
import { organizationPlugin } from "../../../lib/auth/organization-plugin"
|
|
11
|
+
import { LeaveOrganizationDialog } from "./leave-organization-dialog"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Danger-zone row to leave the active organization.
|
|
15
|
+
*/
|
|
16
|
+
export function LeaveOrganization() {
|
|
17
|
+
const { authClient } = useAuth()
|
|
18
|
+
const { localization: organizationLocalization } =
|
|
19
|
+
useAuthPlugin(organizationPlugin)
|
|
20
|
+
|
|
21
|
+
const { data: activeOrganization } = useActiveOrganization(
|
|
22
|
+
authClient as OrganizationAuthClient
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const [confirmOpen, setConfirmOpen] = useState(false)
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
|
29
|
+
<div>
|
|
30
|
+
<p className="text-sm font-medium leading-tight">
|
|
31
|
+
{organizationLocalization.leaveOrganization}
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
<p className="text-muted mt-0.5 text-xs">
|
|
35
|
+
{organizationLocalization.leaveOrganizationDescription}
|
|
36
|
+
</p>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<AlertDialog>
|
|
40
|
+
<Button
|
|
41
|
+
isDisabled={!activeOrganization}
|
|
42
|
+
size="sm"
|
|
43
|
+
variant="danger-soft"
|
|
44
|
+
onPress={() => setConfirmOpen(true)}
|
|
45
|
+
>
|
|
46
|
+
{organizationLocalization.leaveOrganization}
|
|
47
|
+
</Button>
|
|
48
|
+
|
|
49
|
+
{activeOrganization && (
|
|
50
|
+
<LeaveOrganizationDialog
|
|
51
|
+
isOpen={confirmOpen}
|
|
52
|
+
onOpenChange={setConfirmOpen}
|
|
53
|
+
organization={activeOrganization}
|
|
54
|
+
/>
|
|
55
|
+
)}
|
|
56
|
+
</AlertDialog>
|
|
57
|
+
</div>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type OrganizationAuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useHasPermission
|
|
5
|
+
} from "@better-auth-ui/react"
|
|
6
|
+
import { Card, type CardProps, cn } from "@heroui/react"
|
|
7
|
+
import type { ComponentProps } from "react"
|
|
8
|
+
|
|
9
|
+
import { DeleteOrganization } from "./delete-organization"
|
|
10
|
+
import { DeleteOrganizationSkeleton } from "./delete-organization-skeleton"
|
|
11
|
+
import { LeaveOrganization } from "./leave-organization"
|
|
12
|
+
|
|
13
|
+
export type OrganizationDangerZoneProps = {
|
|
14
|
+
className?: string
|
|
15
|
+
variant?: CardProps["variant"]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Danger zone heading with {@link LeaveOrganization} and {@link DeleteOrganization}
|
|
20
|
+
* for the active organization in a single card.
|
|
21
|
+
*
|
|
22
|
+
* Resolves the `organization:delete` permission before rendering anything to
|
|
23
|
+
* avoid flashing {@link LeaveOrganization} (and a stray separator) before the
|
|
24
|
+
* delete row appears or disappears. Inner {@link DeleteOrganization} also
|
|
25
|
+
* self-gates so it stays safe to use standalone.
|
|
26
|
+
*/
|
|
27
|
+
export function OrganizationDangerZone({
|
|
28
|
+
className,
|
|
29
|
+
variant,
|
|
30
|
+
...props
|
|
31
|
+
}: OrganizationDangerZoneProps & ComponentProps<"div">) {
|
|
32
|
+
const { authClient, localization } = useAuth()
|
|
33
|
+
|
|
34
|
+
const { data: deletePermission, isPending: deletePermissionPending } =
|
|
35
|
+
useHasPermission(authClient as OrganizationAuthClient, {
|
|
36
|
+
permissions: { organization: ["delete"] }
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const canDelete = !!deletePermission?.success
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div className={cn("flex w-full flex-col", className)} {...props}>
|
|
43
|
+
<h2 className={cn("mb-3 text-sm font-semibold text-danger")}>
|
|
44
|
+
{localization.settings.dangerZone}
|
|
45
|
+
</h2>
|
|
46
|
+
|
|
47
|
+
<Card variant={variant}>
|
|
48
|
+
<Card.Content className="gap-0">
|
|
49
|
+
{deletePermissionPending ? (
|
|
50
|
+
<DeleteOrganizationSkeleton />
|
|
51
|
+
) : (
|
|
52
|
+
<>
|
|
53
|
+
<LeaveOrganization />
|
|
54
|
+
|
|
55
|
+
{canDelete && (
|
|
56
|
+
<>
|
|
57
|
+
<div className="border-b border-dashed -mx-4 my-4" />
|
|
58
|
+
|
|
59
|
+
<DeleteOrganization />
|
|
60
|
+
</>
|
|
61
|
+
)}
|
|
62
|
+
</>
|
|
63
|
+
)}
|
|
64
|
+
</Card.Content>
|
|
65
|
+
</Card>
|
|
66
|
+
</div>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Skeleton, Table } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Placeholder row matching {@link OrganizationInvitationTableRow} while
|
|
5
|
+
* invitations load.
|
|
6
|
+
*/
|
|
7
|
+
export function OrganizationInvitationRowSkeleton() {
|
|
8
|
+
return (
|
|
9
|
+
<Table.Row>
|
|
10
|
+
<Table.Cell>
|
|
11
|
+
<Skeleton className="h-4 w-48 rounded-lg" />
|
|
12
|
+
</Table.Cell>
|
|
13
|
+
|
|
14
|
+
<Table.Cell>
|
|
15
|
+
<Skeleton className="h-4 w-36 rounded-lg" />
|
|
16
|
+
</Table.Cell>
|
|
17
|
+
|
|
18
|
+
<Table.Cell>
|
|
19
|
+
<Skeleton className="h-4 w-16 rounded-lg" />
|
|
20
|
+
</Table.Cell>
|
|
21
|
+
|
|
22
|
+
<Table.Cell>
|
|
23
|
+
<Skeleton className="h-4 w-14 rounded-full" />
|
|
24
|
+
</Table.Cell>
|
|
25
|
+
|
|
26
|
+
<Table.Cell />
|
|
27
|
+
</Table.Row>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type OrganizationAuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthPlugin,
|
|
5
|
+
useCancelInvitation,
|
|
6
|
+
useHasPermission
|
|
7
|
+
} from "@better-auth-ui/react"
|
|
8
|
+
import { Xmark } from "@gravity-ui/icons"
|
|
9
|
+
import { Button, Chip, Spinner, Table } from "@heroui/react"
|
|
10
|
+
|
|
11
|
+
import type { Invitation } from "better-auth/client"
|
|
12
|
+
|
|
13
|
+
import { organizationPlugin } from "../../../lib/auth/organization-plugin"
|
|
14
|
+
import { OrganizationInvitationRowSkeleton } from "./organization-invitation-row-skeleton"
|
|
15
|
+
|
|
16
|
+
export type OrganizationInvitationTableRowProps = {
|
|
17
|
+
invitation: Invitation
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function OrganizationInvitationTableRow({
|
|
21
|
+
invitation
|
|
22
|
+
}: OrganizationInvitationTableRowProps) {
|
|
23
|
+
const { authClient } = useAuth()
|
|
24
|
+
const { localization: organizationLocalization, roles } =
|
|
25
|
+
useAuthPlugin(organizationPlugin)
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
data: cancelInvitationPermission,
|
|
29
|
+
isPending: cancelPermissionPending
|
|
30
|
+
} = useHasPermission(authClient as OrganizationAuthClient, {
|
|
31
|
+
permissions: { invitation: ["cancel"] }
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const { mutate: cancelInvitation, isPending: cancelPending } =
|
|
35
|
+
useCancelInvitation(authClient as OrganizationAuthClient)
|
|
36
|
+
|
|
37
|
+
const roleLabel = roles?.[invitation.role] ?? invitation.role
|
|
38
|
+
|
|
39
|
+
const statusLabel =
|
|
40
|
+
organizationLocalization[invitation.status] ?? invitation.status
|
|
41
|
+
|
|
42
|
+
const statusColor =
|
|
43
|
+
invitation.status === "pending"
|
|
44
|
+
? "warning"
|
|
45
|
+
: invitation.status === "accepted"
|
|
46
|
+
? "success"
|
|
47
|
+
: invitation.status === "rejected"
|
|
48
|
+
? "danger"
|
|
49
|
+
: "default"
|
|
50
|
+
|
|
51
|
+
if (cancelPermissionPending) {
|
|
52
|
+
return <OrganizationInvitationRowSkeleton />
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Table.Row>
|
|
57
|
+
<Table.Cell className="font-medium text-sm">
|
|
58
|
+
{invitation.email}
|
|
59
|
+
</Table.Cell>
|
|
60
|
+
|
|
61
|
+
<Table.Cell className="text-muted text-xs tabular-nums whitespace-nowrap">
|
|
62
|
+
{new Date(invitation.createdAt).toLocaleString(undefined, {
|
|
63
|
+
dateStyle: "short",
|
|
64
|
+
timeStyle: "short"
|
|
65
|
+
})}
|
|
66
|
+
</Table.Cell>
|
|
67
|
+
|
|
68
|
+
<Table.Cell className="text-sm">{roleLabel}</Table.Cell>
|
|
69
|
+
|
|
70
|
+
<Table.Cell className="text-sm">
|
|
71
|
+
<Chip color={statusColor} size="sm" variant="soft">
|
|
72
|
+
{statusLabel}
|
|
73
|
+
</Chip>
|
|
74
|
+
</Table.Cell>
|
|
75
|
+
|
|
76
|
+
<Table.Cell className="text-end">
|
|
77
|
+
{cancelInvitationPermission?.success &&
|
|
78
|
+
invitation.status === "pending" && (
|
|
79
|
+
<Button
|
|
80
|
+
isIconOnly
|
|
81
|
+
size="sm"
|
|
82
|
+
variant="danger-soft"
|
|
83
|
+
isPending={cancelPending}
|
|
84
|
+
onPress={() => cancelInvitation({ invitationId: invitation.id })}
|
|
85
|
+
aria-label={organizationLocalization.cancelInvitation}
|
|
86
|
+
>
|
|
87
|
+
{cancelPending ? (
|
|
88
|
+
<Spinner color="current" size="sm" />
|
|
89
|
+
) : (
|
|
90
|
+
<Xmark />
|
|
91
|
+
)}
|
|
92
|
+
</Button>
|
|
93
|
+
)}
|
|
94
|
+
</Table.Cell>
|
|
95
|
+
</Table.Row>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useAuthPlugin } from "@better-auth-ui/react"
|
|
2
|
+
import { PaperPlane } from "@gravity-ui/icons"
|
|
3
|
+
import { Button, EmptyState } from "@heroui/react"
|
|
4
|
+
import { organizationPlugin } from "../../../lib/auth/organization-plugin"
|
|
5
|
+
|
|
6
|
+
export type OrganizationInvitationsEmptyProps = {
|
|
7
|
+
onInvitePress: () => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Empty state for {@link OrganizationInvitations} — mirrors `ApiKeysEmpty`
|
|
12
|
+
* (icon, title, description) with an "Invite member" call to action.
|
|
13
|
+
*/
|
|
14
|
+
export function OrganizationInvitationsEmpty({
|
|
15
|
+
onInvitePress
|
|
16
|
+
}: OrganizationInvitationsEmptyProps) {
|
|
17
|
+
const { localization: organizationLocalization } =
|
|
18
|
+
useAuthPlugin(organizationPlugin)
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<EmptyState className="flex flex-col items-center gap-4 text-center p-4">
|
|
22
|
+
<PaperPlane className="size-6 text-muted" />
|
|
23
|
+
|
|
24
|
+
<div className="flex flex-col gap-2">
|
|
25
|
+
<p className="text-sm font-semibold text-foreground">
|
|
26
|
+
{organizationLocalization.noInvitations}
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<span className="text-sm text-muted">
|
|
30
|
+
{organizationLocalization.organizationInvitationsEmptyDescription}
|
|
31
|
+
</span>
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<Button size="sm" onPress={onInvitePress}>
|
|
35
|
+
{organizationLocalization.inviteMember}
|
|
36
|
+
</Button>
|
|
37
|
+
</EmptyState>
|
|
38
|
+
)
|
|
39
|
+
}
|