better-auth-ui 3.2.5

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.
Files changed (226) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/auth-hooks-IOEvlYYv.d.cts +6966 -0
  4. package/dist/auth-hooks-IOEvlYYv.d.ts +6966 -0
  5. package/dist/auth-mutators-DdqOmQ32.d.cts +29 -0
  6. package/dist/auth-mutators-DdqOmQ32.d.ts +29 -0
  7. package/dist/auth-ui-provider-BsH3xJDw.d.ts +697 -0
  8. package/dist/auth-ui-provider-DhZfncd3.d.cts +697 -0
  9. package/dist/chunk-BDFQSFBU.js +750 -0
  10. package/dist/chunk-CRAHKL2C.cjs +801 -0
  11. package/dist/chunk-MJPOA6PK.js +801 -0
  12. package/dist/chunk-SV64DXGW.cjs +750 -0
  13. package/dist/index.cjs +12618 -0
  14. package/dist/index.d.cts +771 -0
  15. package/dist/index.d.ts +771 -0
  16. package/dist/index.js +12618 -0
  17. package/dist/instantdb.cjs +189 -0
  18. package/dist/instantdb.d.cts +36 -0
  19. package/dist/instantdb.d.ts +36 -0
  20. package/dist/instantdb.js +189 -0
  21. package/dist/metafile-cjs.json +1 -0
  22. package/dist/metafile-esm.json +1 -0
  23. package/dist/server.cjs +194 -0
  24. package/dist/server.d.cts +35 -0
  25. package/dist/server.d.ts +35 -0
  26. package/dist/server.js +194 -0
  27. package/dist/style.css +1 -0
  28. package/dist/tanstack.cjs +153 -0
  29. package/dist/tanstack.d.cts +18 -0
  30. package/dist/tanstack.d.ts +18 -0
  31. package/dist/tanstack.js +153 -0
  32. package/dist/triplit.cjs +201 -0
  33. package/dist/triplit.d.cts +31 -0
  34. package/dist/triplit.d.ts +31 -0
  35. package/dist/triplit.js +201 -0
  36. package/dist/utils-C5R37WDe.d.cts +3 -0
  37. package/dist/utils-C5R37WDe.d.ts +3 -0
  38. package/dist/view-paths-CHSJf5dv.d.cts +645 -0
  39. package/dist/view-paths-CHSJf5dv.d.ts +645 -0
  40. package/package.json +156 -0
  41. package/src/components/account/account-view.tsx +220 -0
  42. package/src/components/auth/auth-callback.tsx +36 -0
  43. package/src/components/auth/auth-form.tsx +277 -0
  44. package/src/components/auth/auth-view.tsx +389 -0
  45. package/src/components/auth/email-otp-button.tsx +53 -0
  46. package/src/components/auth/forms/email-otp-form.tsx +288 -0
  47. package/src/components/auth/forms/forgot-password-form.tsx +168 -0
  48. package/src/components/auth/forms/magic-link-form.tsx +191 -0
  49. package/src/components/auth/forms/recover-account-form.tsx +138 -0
  50. package/src/components/auth/forms/reset-password-form.tsx +215 -0
  51. package/src/components/auth/forms/sign-in-form.tsx +289 -0
  52. package/src/components/auth/forms/sign-up-form.tsx +788 -0
  53. package/src/components/auth/forms/two-factor-form.tsx +372 -0
  54. package/src/components/auth/magic-link-button.tsx +54 -0
  55. package/src/components/auth/one-tap.tsx +48 -0
  56. package/src/components/auth/otp-input-group.tsx +65 -0
  57. package/src/components/auth/passkey-button.tsx +85 -0
  58. package/src/components/auth/provider-button.tsx +141 -0
  59. package/src/components/auth/sign-out.tsx +25 -0
  60. package/src/components/auth-loading.tsx +21 -0
  61. package/src/components/captcha/captcha.tsx +79 -0
  62. package/src/components/captcha/recaptcha-badge.tsx +61 -0
  63. package/src/components/captcha/recaptcha-v2.tsx +58 -0
  64. package/src/components/captcha/recaptcha-v3.tsx +73 -0
  65. package/src/components/email/email-template.tsx +216 -0
  66. package/src/components/form-error.tsx +27 -0
  67. package/src/components/organization/accept-invitation-card.tsx +362 -0
  68. package/src/components/organization/create-organization-dialog.tsx +395 -0
  69. package/src/components/organization/delete-organization-card.tsx +101 -0
  70. package/src/components/organization/delete-organization-dialog.tsx +209 -0
  71. package/src/components/organization/invitation-cell.tsx +156 -0
  72. package/src/components/organization/invite-member-dialog.tsx +258 -0
  73. package/src/components/organization/leave-organization-dialog.tsx +150 -0
  74. package/src/components/organization/member-cell.tsx +187 -0
  75. package/src/components/organization/organization-cell-view.tsx +122 -0
  76. package/src/components/organization/organization-cell.tsx +154 -0
  77. package/src/components/organization/organization-invitations-card.tsx +94 -0
  78. package/src/components/organization/organization-logo-card.tsx +308 -0
  79. package/src/components/organization/organization-logo.tsx +120 -0
  80. package/src/components/organization/organization-members-card.tsx +155 -0
  81. package/src/components/organization/organization-name-card.tsx +204 -0
  82. package/src/components/organization/organization-settings-cards.tsx +67 -0
  83. package/src/components/organization/organization-slug-card.tsx +223 -0
  84. package/src/components/organization/organization-switcher.tsx +512 -0
  85. package/src/components/organization/organization-view.tsx +228 -0
  86. package/src/components/organization/organizations-card.tsx +72 -0
  87. package/src/components/organization/personal-account-view.tsx +115 -0
  88. package/src/components/organization/remove-member-dialog.tsx +144 -0
  89. package/src/components/organization/update-member-role-dialog.tsx +213 -0
  90. package/src/components/organization/user-invitations-card.tsx +238 -0
  91. package/src/components/password-input.tsx +56 -0
  92. package/src/components/provider-icons.tsx +385 -0
  93. package/src/components/redirect-to-sign-in.tsx +16 -0
  94. package/src/components/redirect-to-sign-up.tsx +16 -0
  95. package/src/components/settings/account/account-cell.tsx +158 -0
  96. package/src/components/settings/account/accounts-card.tsx +75 -0
  97. package/src/components/settings/account/delete-account-card.tsx +65 -0
  98. package/src/components/settings/account/delete-account-dialog.tsx +231 -0
  99. package/src/components/settings/account/update-avatar-card.tsx +198 -0
  100. package/src/components/settings/account/update-field-card.tsx +282 -0
  101. package/src/components/settings/account/update-name-card.tsx +39 -0
  102. package/src/components/settings/account/update-username-card.tsx +42 -0
  103. package/src/components/settings/account-settings-cards.tsx +123 -0
  104. package/src/components/settings/api-key/api-key-cell.tsx +108 -0
  105. package/src/components/settings/api-key/api-key-delete-dialog.tsx +162 -0
  106. package/src/components/settings/api-key/api-key-display-dialog.tsx +110 -0
  107. package/src/components/settings/api-key/api-keys-card.tsx +98 -0
  108. package/src/components/settings/api-key/create-api-key-dialog.tsx +376 -0
  109. package/src/components/settings/passkey/passkey-cell.tsx +113 -0
  110. package/src/components/settings/passkey/passkeys-card.tsx +111 -0
  111. package/src/components/settings/providers/provider-cell.tsx +152 -0
  112. package/src/components/settings/providers/providers-card.tsx +108 -0
  113. package/src/components/settings/security/change-email-card.tsx +200 -0
  114. package/src/components/settings/security/change-password-card.tsx +326 -0
  115. package/src/components/settings/security/session-cell.tsx +120 -0
  116. package/src/components/settings/security/sessions-card.tsx +58 -0
  117. package/src/components/settings/security-settings-cards.tsx +111 -0
  118. package/src/components/settings/shared/session-freshness-dialog.tsx +97 -0
  119. package/src/components/settings/shared/settings-action-button.tsx +51 -0
  120. package/src/components/settings/shared/settings-card-footer.tsx +94 -0
  121. package/src/components/settings/shared/settings-card-header.tsx +67 -0
  122. package/src/components/settings/shared/settings-card.tsx +106 -0
  123. package/src/components/settings/skeletons/input-field-skeleton.tsx +18 -0
  124. package/src/components/settings/skeletons/settings-cell-skeleton.tsx +37 -0
  125. package/src/components/settings/two-factor/backup-codes-dialog.tsx +113 -0
  126. package/src/components/settings/two-factor/two-factor-card.tsx +63 -0
  127. package/src/components/settings/two-factor/two-factor-password-dialog.tsx +226 -0
  128. package/src/components/signed-in.tsx +20 -0
  129. package/src/components/signed-out.tsx +20 -0
  130. package/src/components/ui/alert.tsx +66 -0
  131. package/src/components/ui/avatar.tsx +53 -0
  132. package/src/components/ui/button.tsx +59 -0
  133. package/src/components/ui/card.tsx +92 -0
  134. package/src/components/ui/checkbox.tsx +32 -0
  135. package/src/components/ui/dialog.tsx +143 -0
  136. package/src/components/ui/drawer.tsx +135 -0
  137. package/src/components/ui/dropdown-menu.tsx +257 -0
  138. package/src/components/ui/form.tsx +167 -0
  139. package/src/components/ui/input-otp.tsx +77 -0
  140. package/src/components/ui/input.tsx +21 -0
  141. package/src/components/ui/label.tsx +24 -0
  142. package/src/components/ui/select.tsx +185 -0
  143. package/src/components/ui/separator.tsx +28 -0
  144. package/src/components/ui/skeleton.tsx +13 -0
  145. package/src/components/ui/tabs.tsx +66 -0
  146. package/src/components/ui/textarea.tsx +18 -0
  147. package/src/components/user-avatar.tsx +147 -0
  148. package/src/components/user-button.tsx +409 -0
  149. package/src/components/user-view.tsx +138 -0
  150. package/src/hooks/use-auth-data.ts +184 -0
  151. package/src/hooks/use-authenticate.ts +62 -0
  152. package/src/hooks/use-captcha.tsx +138 -0
  153. package/src/hooks/use-current-organization.ts +59 -0
  154. package/src/hooks/use-hydrated.ts +13 -0
  155. package/src/hooks/use-lang.ts +32 -0
  156. package/src/hooks/use-success-transition.ts +51 -0
  157. package/src/hooks/use-theme.ts +39 -0
  158. package/src/index.ts +65 -0
  159. package/src/instantdb.ts +1 -0
  160. package/src/lib/auth-data-cache.ts +90 -0
  161. package/src/lib/auth-ui-provider.tsx +658 -0
  162. package/src/lib/gravatar-utils.ts +58 -0
  163. package/src/lib/image-utils.ts +55 -0
  164. package/src/lib/instantdb/model-names.ts +24 -0
  165. package/src/lib/instantdb/use-instant-options.ts +98 -0
  166. package/src/lib/instantdb/use-list-accounts.ts +38 -0
  167. package/src/lib/instantdb/use-list-sessions.ts +53 -0
  168. package/src/lib/instantdb/use-session.ts +55 -0
  169. package/src/lib/organization-refetcher.tsx +56 -0
  170. package/src/lib/social-providers.ts +144 -0
  171. package/src/lib/tanstack/auth-ui-provider-tanstack.tsx +49 -0
  172. package/src/lib/tanstack/use-tanstack-options.ts +112 -0
  173. package/src/lib/triplit/model-names.ts +24 -0
  174. package/src/lib/triplit/use-conditional-query.ts +82 -0
  175. package/src/lib/triplit/use-list-accounts.ts +31 -0
  176. package/src/lib/triplit/use-list-sessions.ts +33 -0
  177. package/src/lib/triplit/use-session.ts +42 -0
  178. package/src/lib/triplit/use-triplit-hooks.ts +68 -0
  179. package/src/lib/triplit/use-triplit-token.ts +44 -0
  180. package/src/lib/utils.ts +105 -0
  181. package/src/lib/view-paths.ts +55 -0
  182. package/src/localization/admin-error-codes.ts +20 -0
  183. package/src/localization/anonymous-error-codes.ts +6 -0
  184. package/src/localization/api-key-error-codes.ts +32 -0
  185. package/src/localization/auth-localization.ts +740 -0
  186. package/src/localization/base-error-codes.ts +27 -0
  187. package/src/localization/captcha-error-codes.ts +17 -0
  188. package/src/localization/email-otp-error-codes.ts +7 -0
  189. package/src/localization/generic-oauth-error-codes.ts +3 -0
  190. package/src/localization/haveibeenpwned-error-codes.ts +4 -0
  191. package/src/localization/multi-session-error-codes.ts +3 -0
  192. package/src/localization/organization-error-codes.ts +57 -0
  193. package/src/localization/passkey-error-codes.ts +10 -0
  194. package/src/localization/phone-number-error-codes.ts +10 -0
  195. package/src/localization/stripe-localization.ts +12 -0
  196. package/src/localization/two-factor-error-codes.ts +12 -0
  197. package/src/localization/username-error-codes.ts +9 -0
  198. package/src/server.ts +4 -0
  199. package/src/style.css +1 -0
  200. package/src/tanstack.ts +1 -0
  201. package/src/triplit.ts +1 -0
  202. package/src/types/account-options.ts +35 -0
  203. package/src/types/additional-fields.ts +21 -0
  204. package/src/types/any-auth-client.ts +6 -0
  205. package/src/types/api-key.ts +9 -0
  206. package/src/types/auth-client.ts +37 -0
  207. package/src/types/auth-hooks.ts +61 -0
  208. package/src/types/auth-mutators.ts +17 -0
  209. package/src/types/avatar-options.ts +29 -0
  210. package/src/types/captcha-options.ts +32 -0
  211. package/src/types/captcha-provider.ts +6 -0
  212. package/src/types/credentials-options.ts +32 -0
  213. package/src/types/delete-user-options.ts +7 -0
  214. package/src/types/fetch-error.ts +6 -0
  215. package/src/types/generic-oauth-options.ts +16 -0
  216. package/src/types/gravatar-options.ts +21 -0
  217. package/src/types/image.ts +7 -0
  218. package/src/types/invitation.ts +10 -0
  219. package/src/types/link.ts +7 -0
  220. package/src/types/organization-options.ts +106 -0
  221. package/src/types/password-validation.ts +16 -0
  222. package/src/types/profile.ts +15 -0
  223. package/src/types/refetch.ts +1 -0
  224. package/src/types/render-toast.ts +9 -0
  225. package/src/types/sign-up-options.ts +7 -0
  226. package/src/types/social-options.ts +16 -0
@@ -0,0 +1,395 @@
1
+ "use client"
2
+
3
+ import { zodResolver } from "@hookform/resolvers/zod"
4
+ import { Loader2, Trash2Icon, UploadCloudIcon } from "lucide-react"
5
+ import {
6
+ type ComponentProps,
7
+ useContext,
8
+ useMemo,
9
+ useRef,
10
+ useState
11
+ } from "react"
12
+ import { useForm } from "react-hook-form"
13
+ import * as z from "zod"
14
+
15
+ import { AuthUIContext } from "../../lib/auth-ui-provider"
16
+ import { fileToBase64, resizeAndCropImage } from "../../lib/image-utils"
17
+ import { cn, getLocalizedError } from "../../lib/utils"
18
+ import type { AuthLocalization } from "../../localization/auth-localization"
19
+ import type { SettingsCardClassNames } from "../settings/shared/settings-card"
20
+ import { Button } from "../ui/button"
21
+ import {
22
+ Dialog,
23
+ DialogContent,
24
+ DialogDescription,
25
+ DialogFooter,
26
+ DialogHeader,
27
+ DialogTitle
28
+ } from "../ui/dialog"
29
+ import {
30
+ DropdownMenu,
31
+ DropdownMenuContent,
32
+ DropdownMenuItem,
33
+ DropdownMenuTrigger
34
+ } from "../ui/dropdown-menu"
35
+ import {
36
+ Form,
37
+ FormControl,
38
+ FormField,
39
+ FormItem,
40
+ FormLabel,
41
+ FormMessage
42
+ } from "../ui/form"
43
+ import { Input } from "../ui/input"
44
+ import { OrganizationLogo } from "./organization-logo"
45
+
46
+ export interface CreateOrganizationDialogProps
47
+ extends ComponentProps<typeof Dialog> {
48
+ className?: string
49
+ classNames?: SettingsCardClassNames
50
+ localization?: AuthLocalization
51
+ }
52
+
53
+ export function CreateOrganizationDialog({
54
+ className,
55
+ classNames,
56
+ localization: localizationProp,
57
+ onOpenChange,
58
+ ...props
59
+ }: CreateOrganizationDialogProps) {
60
+ const {
61
+ authClient,
62
+ localization: contextLocalization,
63
+ organization: organizationOptions,
64
+ navigate,
65
+ toast
66
+ } = useContext(AuthUIContext)
67
+
68
+ const localization = useMemo(
69
+ () => ({ ...contextLocalization, ...localizationProp }),
70
+ [contextLocalization, localizationProp]
71
+ )
72
+
73
+ const [logo, setLogo] = useState<string | null>(null)
74
+ const [logoPending, setLogoPending] = useState(false)
75
+
76
+ const fileInputRef = useRef<HTMLInputElement>(null)
77
+ const openFileDialog = () => fileInputRef.current?.click()
78
+
79
+ const formSchema = z.object({
80
+ logo: z.string().optional(),
81
+ name: z.string().min(1, {
82
+ message: `${localization.ORGANIZATION_NAME} ${localization.IS_REQUIRED}`
83
+ }),
84
+ slug: z
85
+ .string()
86
+ .min(1, {
87
+ message: `${localization.ORGANIZATION_SLUG} ${localization.IS_REQUIRED}`
88
+ })
89
+ .regex(/^[a-z0-9-]+$/, {
90
+ message: `${localization.ORGANIZATION_SLUG} ${localization.IS_INVALID}`
91
+ })
92
+ })
93
+
94
+ const form = useForm({
95
+ resolver: zodResolver(formSchema),
96
+ defaultValues: {
97
+ logo: "",
98
+ name: "",
99
+ slug: ""
100
+ }
101
+ })
102
+
103
+ const isSubmitting = form.formState.isSubmitting
104
+
105
+ const handleLogoChange = async (file: File) => {
106
+ if (!organizationOptions?.logo) return
107
+
108
+ setLogoPending(true)
109
+
110
+ try {
111
+ const resizedFile = await resizeAndCropImage(
112
+ file,
113
+ crypto.randomUUID(),
114
+ organizationOptions.logo.size,
115
+ organizationOptions.logo.extension
116
+ )
117
+
118
+ let image: string | undefined | null
119
+
120
+ if (organizationOptions?.logo.upload) {
121
+ image = await organizationOptions.logo.upload(resizedFile)
122
+ } else {
123
+ image = await fileToBase64(resizedFile)
124
+ }
125
+
126
+ setLogo(image || null)
127
+ form.setValue("logo", image || "")
128
+ } catch (error) {
129
+ toast({
130
+ variant: "error",
131
+ message: getLocalizedError({ error, localization })
132
+ })
133
+ }
134
+
135
+ setLogoPending(false)
136
+ }
137
+
138
+ const deleteLogo = async () => {
139
+ setLogoPending(true)
140
+
141
+ const currentUrl = logo || undefined
142
+ if (currentUrl && organizationOptions?.logo?.delete) {
143
+ await organizationOptions.logo.delete(currentUrl)
144
+ }
145
+
146
+ setLogo(null)
147
+ form.setValue("logo", "")
148
+ setLogoPending(false)
149
+ }
150
+
151
+ async function onSubmit({ name, slug, logo }: z.infer<typeof formSchema>) {
152
+ try {
153
+ const organization = await authClient.organization.create({
154
+ name,
155
+ slug,
156
+ logo,
157
+ fetchOptions: { throw: true }
158
+ })
159
+
160
+ if (organizationOptions?.pathMode === "slug") {
161
+ navigate(`${organizationOptions.basePath}/${organization.slug}`)
162
+ return
163
+ }
164
+
165
+ await authClient.organization.setActive({
166
+ organizationId: organization.id
167
+ })
168
+
169
+ onOpenChange?.(false)
170
+ form.reset()
171
+ setLogo(null)
172
+
173
+ toast({
174
+ variant: "success",
175
+ message: localization.CREATE_ORGANIZATION_SUCCESS
176
+ })
177
+ } catch (error) {
178
+ toast({
179
+ variant: "error",
180
+ message: getLocalizedError({ error, localization })
181
+ })
182
+ }
183
+ }
184
+
185
+ return (
186
+ <Dialog onOpenChange={onOpenChange} {...props}>
187
+ <DialogContent className={classNames?.dialog?.content}>
188
+ <DialogHeader className={classNames?.dialog?.header}>
189
+ <DialogTitle
190
+ className={cn("text-lg md:text-xl", classNames?.title)}
191
+ >
192
+ {localization.CREATE_ORGANIZATION}
193
+ </DialogTitle>
194
+
195
+ <DialogDescription
196
+ className={cn(
197
+ "text-xs md:text-sm",
198
+ classNames?.description
199
+ )}
200
+ >
201
+ {localization.ORGANIZATIONS_INSTRUCTIONS}
202
+ </DialogDescription>
203
+ </DialogHeader>
204
+
205
+ <Form {...form}>
206
+ <form
207
+ onSubmit={form.handleSubmit(onSubmit)}
208
+ className="space-y-6"
209
+ >
210
+ {organizationOptions?.logo && (
211
+ <FormField
212
+ control={form.control}
213
+ name="logo"
214
+ render={() => (
215
+ <FormItem>
216
+ <input
217
+ ref={fileInputRef}
218
+ accept="image/*"
219
+ disabled={logoPending}
220
+ hidden
221
+ type="file"
222
+ onChange={(e) => {
223
+ const file =
224
+ e.target.files?.item(0)
225
+ if (file) handleLogoChange(file)
226
+ e.target.value = ""
227
+ }}
228
+ />
229
+
230
+ <FormLabel>
231
+ {localization.LOGO}
232
+ </FormLabel>
233
+
234
+ <div className="flex items-center gap-4">
235
+ <DropdownMenu>
236
+ <DropdownMenuTrigger asChild>
237
+ <Button
238
+ className="size-fit rounded-full"
239
+ size="icon"
240
+ type="button"
241
+ variant="ghost"
242
+ >
243
+ <OrganizationLogo
244
+ className="size-16"
245
+ isPending={
246
+ logoPending
247
+ }
248
+ localization={
249
+ localization
250
+ }
251
+ organization={{
252
+ name: form.watch(
253
+ "name"
254
+ ),
255
+ logo
256
+ }}
257
+ />
258
+ </Button>
259
+ </DropdownMenuTrigger>
260
+
261
+ <DropdownMenuContent
262
+ align="start"
263
+ onCloseAutoFocus={(e) =>
264
+ e.preventDefault()
265
+ }
266
+ >
267
+ <DropdownMenuItem
268
+ onClick={openFileDialog}
269
+ disabled={logoPending}
270
+ >
271
+ <UploadCloudIcon />
272
+
273
+ {
274
+ localization.UPLOAD_LOGO
275
+ }
276
+ </DropdownMenuItem>
277
+
278
+ {logo && (
279
+ <DropdownMenuItem
280
+ onClick={deleteLogo}
281
+ disabled={
282
+ logoPending
283
+ }
284
+ variant="destructive"
285
+ >
286
+ <Trash2Icon />
287
+
288
+ {
289
+ localization.DELETE_LOGO
290
+ }
291
+ </DropdownMenuItem>
292
+ )}
293
+ </DropdownMenuContent>
294
+ </DropdownMenu>
295
+
296
+ <Button
297
+ disabled={logoPending}
298
+ variant="outline"
299
+ onClick={openFileDialog}
300
+ type="button"
301
+ >
302
+ {logoPending && (
303
+ <Loader2 className="animate-spin" />
304
+ )}
305
+
306
+ {localization.UPLOAD}
307
+ </Button>
308
+ </div>
309
+
310
+ <FormMessage />
311
+ </FormItem>
312
+ )}
313
+ />
314
+ )}
315
+
316
+ <FormField
317
+ control={form.control}
318
+ name="name"
319
+ render={({ field }) => (
320
+ <FormItem>
321
+ <FormLabel>
322
+ {localization.ORGANIZATION_NAME}
323
+ </FormLabel>
324
+
325
+ <FormControl>
326
+ <Input
327
+ placeholder={
328
+ localization.ORGANIZATION_NAME_PLACEHOLDER
329
+ }
330
+ {...field}
331
+ />
332
+ </FormControl>
333
+
334
+ <FormMessage />
335
+ </FormItem>
336
+ )}
337
+ />
338
+
339
+ <FormField
340
+ control={form.control}
341
+ name="slug"
342
+ render={({ field }) => (
343
+ <FormItem>
344
+ <FormLabel>
345
+ {localization.ORGANIZATION_SLUG}
346
+ </FormLabel>
347
+
348
+ <FormControl>
349
+ <Input
350
+ placeholder={
351
+ localization.ORGANIZATION_SLUG_PLACEHOLDER
352
+ }
353
+ {...field}
354
+ />
355
+ </FormControl>
356
+
357
+ <FormMessage />
358
+ </FormItem>
359
+ )}
360
+ />
361
+
362
+ <DialogFooter className={classNames?.dialog?.footer}>
363
+ <Button
364
+ type="button"
365
+ variant="outline"
366
+ onClick={() => onOpenChange?.(false)}
367
+ className={cn(
368
+ classNames?.button,
369
+ classNames?.outlineButton
370
+ )}
371
+ >
372
+ {localization.CANCEL}
373
+ </Button>
374
+
375
+ <Button
376
+ type="submit"
377
+ className={cn(
378
+ classNames?.button,
379
+ classNames?.primaryButton
380
+ )}
381
+ disabled={isSubmitting}
382
+ >
383
+ {isSubmitting && (
384
+ <Loader2 className="animate-spin" />
385
+ )}
386
+
387
+ {localization.CREATE_ORGANIZATION}
388
+ </Button>
389
+ </DialogFooter>
390
+ </form>
391
+ </Form>
392
+ </DialogContent>
393
+ </Dialog>
394
+ )
395
+ }
@@ -0,0 +1,101 @@
1
+ "use client"
2
+
3
+ import type { Organization } from "better-auth/plugins/organization"
4
+ import { useContext, useMemo, useState } from "react"
5
+
6
+ import { useCurrentOrganization } from "../../hooks/use-current-organization"
7
+ import { AuthUIContext } from "../../lib/auth-ui-provider"
8
+ import type { SettingsCardProps } from "../settings/shared/settings-card"
9
+ import { SettingsCard } from "../settings/shared/settings-card"
10
+ import { DeleteOrganizationDialog } from "./delete-organization-dialog"
11
+
12
+ export function DeleteOrganizationCard({
13
+ className,
14
+ classNames,
15
+ localization: localizationProp,
16
+ slug,
17
+ ...props
18
+ }: SettingsCardProps & { slug?: string }) {
19
+ const { localization: contextLocalization } = useContext(AuthUIContext)
20
+
21
+ const localization = useMemo(
22
+ () => ({ ...contextLocalization, ...localizationProp }),
23
+ [contextLocalization, localizationProp]
24
+ )
25
+
26
+ const { data: organization } = useCurrentOrganization({ slug })
27
+
28
+ if (!organization)
29
+ return (
30
+ <SettingsCard
31
+ className={className}
32
+ classNames={classNames}
33
+ actionLabel={localization?.DELETE_ORGANIZATION}
34
+ description={localization?.DELETE_ORGANIZATION_DESCRIPTION}
35
+ isPending
36
+ title={localization?.DELETE_ORGANIZATION}
37
+ variant="destructive"
38
+ />
39
+ )
40
+
41
+ return (
42
+ <DeleteOrganizationForm
43
+ className={className}
44
+ classNames={classNames}
45
+ localization={localization}
46
+ organization={organization}
47
+ {...props}
48
+ />
49
+ )
50
+ }
51
+
52
+ function DeleteOrganizationForm({
53
+ className,
54
+ classNames,
55
+ localization: localizationProp,
56
+ organization
57
+ }: SettingsCardProps & { organization: Organization }) {
58
+ const {
59
+ localization: contextLocalization,
60
+ hooks: { useHasPermission }
61
+ } = useContext(AuthUIContext)
62
+
63
+ const localization = useMemo(
64
+ () => ({ ...contextLocalization, ...localizationProp }),
65
+ [contextLocalization, localizationProp]
66
+ )
67
+
68
+ const { data: hasPermission, isPending } = useHasPermission({
69
+ organizationId: organization.id,
70
+ permissions: {
71
+ organization: ["delete"]
72
+ }
73
+ })
74
+
75
+ const [showDialog, setShowDialog] = useState(false)
76
+
77
+ if (!hasPermission?.success) return null
78
+
79
+ return (
80
+ <>
81
+ <SettingsCard
82
+ className={className}
83
+ classNames={classNames}
84
+ actionLabel={localization?.DELETE_ORGANIZATION}
85
+ description={localization?.DELETE_ORGANIZATION_DESCRIPTION}
86
+ isPending={isPending}
87
+ title={localization?.DELETE_ORGANIZATION}
88
+ variant="destructive"
89
+ action={() => setShowDialog(true)}
90
+ />
91
+
92
+ <DeleteOrganizationDialog
93
+ classNames={classNames}
94
+ localization={localization}
95
+ open={showDialog}
96
+ onOpenChange={setShowDialog}
97
+ organization={organization}
98
+ />
99
+ </>
100
+ )
101
+ }