@stackframe/react 2.7.20

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 (316) hide show
  1. package/CHANGELOG.md +1415 -0
  2. package/LICENSE +7 -0
  3. package/README.md +26 -0
  4. package/dist/components/credential-sign-in.d.mts +5 -0
  5. package/dist/components/credential-sign-in.d.ts +5 -0
  6. package/dist/components/credential-sign-in.js +103 -0
  7. package/dist/components/credential-sign-in.js.map +1 -0
  8. package/dist/components/credential-sign-up.d.mts +7 -0
  9. package/dist/components/credential-sign-up.d.ts +7 -0
  10. package/dist/components/credential-sign-up.js +138 -0
  11. package/dist/components/credential-sign-up.js.map +1 -0
  12. package/dist/components/elements/form-warning.d.mts +7 -0
  13. package/dist/components/elements/form-warning.d.ts +7 -0
  14. package/dist/components/elements/form-warning.js +39 -0
  15. package/dist/components/elements/form-warning.js.map +1 -0
  16. package/dist/components/elements/maybe-full-page.d.mts +11 -0
  17. package/dist/components/elements/maybe-full-page.d.ts +11 -0
  18. package/dist/components/elements/maybe-full-page.js +74 -0
  19. package/dist/components/elements/maybe-full-page.js.map +1 -0
  20. package/dist/components/elements/separator-with-text.d.mts +7 -0
  21. package/dist/components/elements/separator-with-text.d.ts +7 -0
  22. package/dist/components/elements/separator-with-text.js +41 -0
  23. package/dist/components/elements/separator-with-text.js.map +1 -0
  24. package/dist/components/elements/sidebar-layout.d.mts +19 -0
  25. package/dist/components/elements/sidebar-layout.d.ts +19 -0
  26. package/dist/components/elements/sidebar-layout.js +126 -0
  27. package/dist/components/elements/sidebar-layout.js.map +1 -0
  28. package/dist/components/elements/ssr-layout-effect.d.mts +8 -0
  29. package/dist/components/elements/ssr-layout-effect.d.ts +8 -0
  30. package/dist/components/elements/ssr-layout-effect.js +47 -0
  31. package/dist/components/elements/ssr-layout-effect.js.map +1 -0
  32. package/dist/components/elements/user-avatar.d.mts +13 -0
  33. package/dist/components/elements/user-avatar.d.ts +13 -0
  34. package/dist/components/elements/user-avatar.js +41 -0
  35. package/dist/components/elements/user-avatar.js.map +1 -0
  36. package/dist/components/iframe-preventer.d.mts +8 -0
  37. package/dist/components/iframe-preventer.d.ts +8 -0
  38. package/dist/components/iframe-preventer.js +52 -0
  39. package/dist/components/iframe-preventer.js.map +1 -0
  40. package/dist/components/link.d.mts +14 -0
  41. package/dist/components/link.d.ts +14 -0
  42. package/dist/components/link.js +51 -0
  43. package/dist/components/link.js.map +1 -0
  44. package/dist/components/magic-link-sign-in.d.mts +5 -0
  45. package/dist/components/magic-link-sign-in.d.ts +5 -0
  46. package/dist/components/magic-link-sign-in.js +151 -0
  47. package/dist/components/magic-link-sign-in.js.map +1 -0
  48. package/dist/components/message-cards/known-error-message-card.d.mts +9 -0
  49. package/dist/components/message-cards/known-error-message-card.d.ts +9 -0
  50. package/dist/components/message-cards/known-error-message-card.js +61 -0
  51. package/dist/components/message-cards/known-error-message-card.js.map +1 -0
  52. package/dist/components/message-cards/message-card.d.mts +14 -0
  53. package/dist/components/message-cards/message-card.d.ts +14 -0
  54. package/dist/components/message-cards/message-card.js +45 -0
  55. package/dist/components/message-cards/message-card.js.map +1 -0
  56. package/dist/components/message-cards/predefined-message-card.d.mts +8 -0
  57. package/dist/components/message-cards/predefined-message-card.d.ts +8 -0
  58. package/dist/components/message-cards/predefined-message-card.js +107 -0
  59. package/dist/components/message-cards/predefined-message-card.js.map +1 -0
  60. package/dist/components/oauth-button-group.d.mts +14 -0
  61. package/dist/components/oauth-button-group.d.ts +14 -0
  62. package/dist/components/oauth-button-group.js +43 -0
  63. package/dist/components/oauth-button-group.js.map +1 -0
  64. package/dist/components/oauth-button.d.mts +8 -0
  65. package/dist/components/oauth-button.d.ts +8 -0
  66. package/dist/components/oauth-button.js +210 -0
  67. package/dist/components/oauth-button.js.map +1 -0
  68. package/dist/components/passkey-button.d.mts +7 -0
  69. package/dist/components/passkey-button.d.ts +7 -0
  70. package/dist/components/passkey-button.js +58 -0
  71. package/dist/components/passkey-button.js.map +1 -0
  72. package/dist/components/profile-image-editor.d.mts +11 -0
  73. package/dist/components/profile-image-editor.d.ts +11 -0
  74. package/dist/components/profile-image-editor.js +162 -0
  75. package/dist/components/profile-image-editor.js.map +1 -0
  76. package/dist/components/selected-team-switcher.d.mts +21 -0
  77. package/dist/components/selected-team-switcher.d.ts +21 -0
  78. package/dist/components/selected-team-switcher.js +119 -0
  79. package/dist/components/selected-team-switcher.js.map +1 -0
  80. package/dist/components/team-icon.d.mts +18 -0
  81. package/dist/components/team-icon.d.ts +18 -0
  82. package/dist/components/team-icon.js +39 -0
  83. package/dist/components/team-icon.js.map +1 -0
  84. package/dist/components/user-button.d.mts +15 -0
  85. package/dist/components/user-button.d.ts +15 -0
  86. package/dist/components/user-button.js +120 -0
  87. package/dist/components/user-button.js.map +1 -0
  88. package/dist/components-page/account-settings.d.mts +24 -0
  89. package/dist/components-page/account-settings.d.ts +24 -0
  90. package/dist/components-page/account-settings.js +1095 -0
  91. package/dist/components-page/account-settings.js.map +1 -0
  92. package/dist/components-page/auth-page.d.mts +24 -0
  93. package/dist/components-page/auth-page.d.ts +24 -0
  94. package/dist/components-page/auth-page.js +123 -0
  95. package/dist/components-page/auth-page.js.map +1 -0
  96. package/dist/components-page/email-verification.d.mts +8 -0
  97. package/dist/components-page/email-verification.d.ts +8 -0
  98. package/dist/components-page/email-verification.js +100 -0
  99. package/dist/components-page/email-verification.js.map +1 -0
  100. package/dist/components-page/error-page.d.mts +8 -0
  101. package/dist/components-page/error-page.d.ts +8 -0
  102. package/dist/components-page/error-page.js +97 -0
  103. package/dist/components-page/error-page.js.map +1 -0
  104. package/dist/components-page/forgot-password.d.mts +10 -0
  105. package/dist/components-page/forgot-password.d.ts +10 -0
  106. package/dist/components-page/forgot-password.js +117 -0
  107. package/dist/components-page/forgot-password.js.map +1 -0
  108. package/dist/components-page/magic-link-callback.d.mts +8 -0
  109. package/dist/components-page/magic-link-callback.d.ts +8 -0
  110. package/dist/components-page/magic-link-callback.js +110 -0
  111. package/dist/components-page/magic-link-callback.js.map +1 -0
  112. package/dist/components-page/oauth-callback.d.mts +7 -0
  113. package/dist/components-page/oauth-callback.d.ts +7 -0
  114. package/dist/components-page/oauth-callback.js +75 -0
  115. package/dist/components-page/oauth-callback.js.map +1 -0
  116. package/dist/components-page/password-reset.d.mts +12 -0
  117. package/dist/components-page/password-reset.d.ts +12 -0
  118. package/dist/components-page/password-reset.js +179 -0
  119. package/dist/components-page/password-reset.js.map +1 -0
  120. package/dist/components-page/sign-in.d.mts +10 -0
  121. package/dist/components-page/sign-in.d.ts +10 -0
  122. package/dist/components-page/sign-in.js +44 -0
  123. package/dist/components-page/sign-in.js.map +1 -0
  124. package/dist/components-page/sign-out.d.mts +7 -0
  125. package/dist/components-page/sign-out.d.ts +7 -0
  126. package/dist/components-page/sign-out.js +57 -0
  127. package/dist/components-page/sign-out.js.map +1 -0
  128. package/dist/components-page/sign-up.d.mts +11 -0
  129. package/dist/components-page/sign-up.d.ts +11 -0
  130. package/dist/components-page/sign-up.js +47 -0
  131. package/dist/components-page/sign-up.js.map +1 -0
  132. package/dist/components-page/stack-handler.d.mts +51 -0
  133. package/dist/components-page/stack-handler.d.ts +51 -0
  134. package/dist/components-page/stack-handler.js +244 -0
  135. package/dist/components-page/stack-handler.js.map +1 -0
  136. package/dist/components-page/team-creation.d.mts +7 -0
  137. package/dist/components-page/team-creation.d.ts +7 -0
  138. package/dist/components-page/team-creation.js +92 -0
  139. package/dist/components-page/team-creation.js.map +1 -0
  140. package/dist/components-page/team-invitation.d.mts +8 -0
  141. package/dist/components-page/team-invitation.d.ts +8 -0
  142. package/dist/components-page/team-invitation.js +144 -0
  143. package/dist/components-page/team-invitation.js.map +1 -0
  144. package/dist/esm/components/credential-sign-in.js +79 -0
  145. package/dist/esm/components/credential-sign-in.js.map +1 -0
  146. package/dist/esm/components/credential-sign-up.js +104 -0
  147. package/dist/esm/components/credential-sign-up.js.map +1 -0
  148. package/dist/esm/components/elements/form-warning.js +15 -0
  149. package/dist/esm/components/elements/form-warning.js.map +1 -0
  150. package/dist/esm/components/elements/maybe-full-page.js +50 -0
  151. package/dist/esm/components/elements/maybe-full-page.js.map +1 -0
  152. package/dist/esm/components/elements/separator-with-text.js +17 -0
  153. package/dist/esm/components/elements/separator-with-text.js.map +1 -0
  154. package/dist/esm/components/elements/sidebar-layout.js +102 -0
  155. package/dist/esm/components/elements/sidebar-layout.js.map +1 -0
  156. package/dist/esm/components/elements/ssr-layout-effect.js +23 -0
  157. package/dist/esm/components/elements/ssr-layout-effect.js.map +1 -0
  158. package/dist/esm/components/elements/user-avatar.js +16 -0
  159. package/dist/esm/components/elements/user-avatar.js.map +1 -0
  160. package/dist/esm/components/iframe-preventer.js +28 -0
  161. package/dist/esm/components/iframe-preventer.js.map +1 -0
  162. package/dist/esm/components/link.js +26 -0
  163. package/dist/esm/components/link.js.map +1 -0
  164. package/dist/esm/components/magic-link-sign-in.js +127 -0
  165. package/dist/esm/components/magic-link-sign-in.js.map +1 -0
  166. package/dist/esm/components/message-cards/known-error-message-card.js +37 -0
  167. package/dist/esm/components/message-cards/known-error-message-card.js.map +1 -0
  168. package/dist/esm/components/message-cards/message-card.js +21 -0
  169. package/dist/esm/components/message-cards/message-card.js.map +1 -0
  170. package/dist/esm/components/message-cards/predefined-message-card.js +83 -0
  171. package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -0
  172. package/dist/esm/components/oauth-button-group.js +19 -0
  173. package/dist/esm/components/oauth-button-group.js.map +1 -0
  174. package/dist/esm/components/oauth-button.js +176 -0
  175. package/dist/esm/components/oauth-button.js.map +1 -0
  176. package/dist/esm/components/passkey-button.js +34 -0
  177. package/dist/esm/components/passkey-button.js.map +1 -0
  178. package/dist/esm/components/profile-image-editor.js +126 -0
  179. package/dist/esm/components/profile-image-editor.js.map +1 -0
  180. package/dist/esm/components/selected-team-switcher.js +107 -0
  181. package/dist/esm/components/selected-team-switcher.js.map +1 -0
  182. package/dist/esm/components/team-icon.js +14 -0
  183. package/dist/esm/components/team-icon.js.map +1 -0
  184. package/dist/esm/components/user-button.js +96 -0
  185. package/dist/esm/components/user-button.js.map +1 -0
  186. package/dist/esm/components-page/account-settings.js +1058 -0
  187. package/dist/esm/components-page/account-settings.js.map +1 -0
  188. package/dist/esm/components-page/auth-page.js +99 -0
  189. package/dist/esm/components-page/auth-page.js.map +1 -0
  190. package/dist/esm/components-page/email-verification.js +66 -0
  191. package/dist/esm/components-page/email-verification.js.map +1 -0
  192. package/dist/esm/components-page/error-page.js +73 -0
  193. package/dist/esm/components-page/error-page.js.map +1 -0
  194. package/dist/esm/components-page/forgot-password.js +92 -0
  195. package/dist/esm/components-page/forgot-password.js.map +1 -0
  196. package/dist/esm/components-page/magic-link-callback.js +76 -0
  197. package/dist/esm/components-page/magic-link-callback.js.map +1 -0
  198. package/dist/esm/components-page/oauth-callback.js +51 -0
  199. package/dist/esm/components-page/oauth-callback.js.map +1 -0
  200. package/dist/esm/components-page/password-reset.js +145 -0
  201. package/dist/esm/components-page/password-reset.js.map +1 -0
  202. package/dist/esm/components-page/sign-in.js +19 -0
  203. package/dist/esm/components-page/sign-in.js.map +1 -0
  204. package/dist/esm/components-page/sign-out.js +23 -0
  205. package/dist/esm/components-page/sign-out.js.map +1 -0
  206. package/dist/esm/components-page/sign-up.js +23 -0
  207. package/dist/esm/components-page/sign-up.js.map +1 -0
  208. package/dist/esm/components-page/stack-handler.js +223 -0
  209. package/dist/esm/components-page/stack-handler.js.map +1 -0
  210. package/dist/esm/components-page/team-creation.js +68 -0
  211. package/dist/esm/components-page/team-creation.js.map +1 -0
  212. package/dist/esm/components-page/team-invitation.js +110 -0
  213. package/dist/esm/components-page/team-invitation.js.map +1 -0
  214. package/dist/esm/generated/global-css.js +6 -0
  215. package/dist/esm/generated/global-css.js.map +1 -0
  216. package/dist/esm/generated/quetzal-translations.js +2397 -0
  217. package/dist/esm/generated/quetzal-translations.js.map +1 -0
  218. package/dist/esm/global.d.js +1 -0
  219. package/dist/esm/global.d.js.map +1 -0
  220. package/dist/esm/index.js +46 -0
  221. package/dist/esm/index.js.map +1 -0
  222. package/dist/esm/lib/auth.js +98 -0
  223. package/dist/esm/lib/auth.js.map +1 -0
  224. package/dist/esm/lib/cookie.js +244 -0
  225. package/dist/esm/lib/cookie.js.map +1 -0
  226. package/dist/esm/lib/hooks.js +30 -0
  227. package/dist/esm/lib/hooks.js.map +1 -0
  228. package/dist/esm/lib/stack-app.js +2398 -0
  229. package/dist/esm/lib/stack-app.js.map +1 -0
  230. package/dist/esm/lib/translations.js +23 -0
  231. package/dist/esm/lib/translations.js.map +1 -0
  232. package/dist/esm/providers/stack-provider-client.js +29 -0
  233. package/dist/esm/providers/stack-provider-client.js.map +1 -0
  234. package/dist/esm/providers/stack-provider.js +25 -0
  235. package/dist/esm/providers/stack-provider.js.map +1 -0
  236. package/dist/esm/providers/theme-provider.js +71 -0
  237. package/dist/esm/providers/theme-provider.js.map +1 -0
  238. package/dist/esm/providers/translation-provider-client.js +18 -0
  239. package/dist/esm/providers/translation-provider-client.js.map +1 -0
  240. package/dist/esm/providers/translation-provider.js +18 -0
  241. package/dist/esm/providers/translation-provider.js.map +1 -0
  242. package/dist/esm/utils/browser-script.js +112 -0
  243. package/dist/esm/utils/browser-script.js.map +1 -0
  244. package/dist/esm/utils/constants.js +66 -0
  245. package/dist/esm/utils/constants.js.map +1 -0
  246. package/dist/esm/utils/url.js +30 -0
  247. package/dist/esm/utils/url.js.map +1 -0
  248. package/dist/generated/global-css.d.mts +3 -0
  249. package/dist/generated/global-css.d.ts +3 -0
  250. package/dist/generated/global-css.js +31 -0
  251. package/dist/generated/global-css.js.map +1 -0
  252. package/dist/generated/quetzal-translations.d.mts +4 -0
  253. package/dist/generated/quetzal-translations.d.ts +4 -0
  254. package/dist/generated/quetzal-translations.js +2423 -0
  255. package/dist/generated/quetzal-translations.js.map +1 -0
  256. package/dist/global.d.d.mts +2 -0
  257. package/dist/global.d.d.ts +2 -0
  258. package/dist/global.d.js +2 -0
  259. package/dist/global.d.js.map +1 -0
  260. package/dist/index.d.mts +41 -0
  261. package/dist/index.d.ts +41 -0
  262. package/dist/index.js +103 -0
  263. package/dist/index.js.map +1 -0
  264. package/dist/lib/auth.d.mts +33 -0
  265. package/dist/lib/auth.d.ts +33 -0
  266. package/dist/lib/auth.js +125 -0
  267. package/dist/lib/auth.js.map +1 -0
  268. package/dist/lib/cookie.d.mts +33 -0
  269. package/dist/lib/cookie.d.ts +33 -0
  270. package/dist/lib/cookie.js +291 -0
  271. package/dist/lib/cookie.js.map +1 -0
  272. package/dist/lib/hooks.d.mts +41 -0
  273. package/dist/lib/hooks.d.ts +41 -0
  274. package/dist/lib/hooks.js +56 -0
  275. package/dist/lib/hooks.js.map +1 -0
  276. package/dist/lib/stack-app.d.mts +775 -0
  277. package/dist/lib/stack-app.d.ts +775 -0
  278. package/dist/lib/stack-app.js +2438 -0
  279. package/dist/lib/stack-app.js.map +1 -0
  280. package/dist/lib/translations.d.mts +5 -0
  281. package/dist/lib/translations.d.ts +5 -0
  282. package/dist/lib/translations.js +58 -0
  283. package/dist/lib/translations.js.map +1 -0
  284. package/dist/providers/stack-provider-client.d.mts +27 -0
  285. package/dist/providers/stack-provider-client.d.ts +27 -0
  286. package/dist/providers/stack-provider-client.js +65 -0
  287. package/dist/providers/stack-provider-client.js.map +1 -0
  288. package/dist/providers/stack-provider.d.mts +30 -0
  289. package/dist/providers/stack-provider.d.ts +30 -0
  290. package/dist/providers/stack-provider.js +46 -0
  291. package/dist/providers/stack-provider.js.map +1 -0
  292. package/dist/providers/theme-provider.d.mts +40 -0
  293. package/dist/providers/theme-provider.d.ts +40 -0
  294. package/dist/providers/theme-provider.js +105 -0
  295. package/dist/providers/theme-provider.js.map +1 -0
  296. package/dist/providers/translation-provider-client.d.mts +14 -0
  297. package/dist/providers/translation-provider-client.d.ts +14 -0
  298. package/dist/providers/translation-provider-client.js +43 -0
  299. package/dist/providers/translation-provider-client.js.map +1 -0
  300. package/dist/providers/translation-provider.d.mts +10 -0
  301. package/dist/providers/translation-provider.d.ts +10 -0
  302. package/dist/providers/translation-provider.js +43 -0
  303. package/dist/providers/translation-provider.js.map +1 -0
  304. package/dist/utils/browser-script.d.mts +7 -0
  305. package/dist/utils/browser-script.d.ts +7 -0
  306. package/dist/utils/browser-script.js +137 -0
  307. package/dist/utils/browser-script.js.map +1 -0
  308. package/dist/utils/constants.d.mts +79 -0
  309. package/dist/utils/constants.d.ts +79 -0
  310. package/dist/utils/constants.js +99 -0
  311. package/dist/utils/constants.js.map +1 -0
  312. package/dist/utils/url.d.mts +4 -0
  313. package/dist/utils/url.d.ts +4 -0
  314. package/dist/utils/url.js +56 -0
  315. package/dist/utils/url.js.map +1 -0
  316. package/package.json +96 -0
@@ -0,0 +1,1095 @@
1
+ "use client";
2
+ "use strict";
3
+ "use client";
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+
32
+ // src/components-page/account-settings.tsx
33
+ var account_settings_exports = {};
34
+ __export(account_settings_exports, {
35
+ AccountSettings: () => AccountSettings,
36
+ EditableText: () => EditableText,
37
+ TeamCreation: () => TeamCreation,
38
+ useDeleteAccountSection: () => useDeleteAccountSection
39
+ });
40
+ module.exports = __toCommonJS(account_settings_exports);
41
+ var import_yup = require("@hookform/resolvers/yup");
42
+ var import_stack_shared = require("@stackframe/stack-shared");
43
+ var import_password = require("@stackframe/stack-shared/dist/helpers/password");
44
+ var import_use_async_callback = require("@stackframe/stack-shared/dist/hooks/use-async-callback");
45
+ var import_schema_fields = require("@stackframe/stack-shared/dist/schema-fields");
46
+ var import_crypto = require("@stackframe/stack-shared/dist/utils/crypto");
47
+ var import_errors = require("@stackframe/stack-shared/dist/utils/errors");
48
+ var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
49
+ var import_stack_ui = require("@stackframe/stack-ui");
50
+ var import_lucide_react = require("lucide-react");
51
+ var import_otp = require("oslo/otp");
52
+ var QRCode = __toESM(require("qrcode"));
53
+ var import_react = __toESM(require("react"));
54
+ var import_react_hook_form = require("react-hook-form");
55
+ var yup = __toESM(require("yup"));
56
+ var import__ = require("..");
57
+ var import_form_warning = require("../components/elements/form-warning");
58
+ var import_maybe_full_page = require("../components/elements/maybe-full-page");
59
+ var import_sidebar_layout = require("../components/elements/sidebar-layout");
60
+ var import_user_avatar = require("../components/elements/user-avatar");
61
+ var import_profile_image_editor = require("../components/profile-image-editor");
62
+ var import_team_icon = require("../components/team-icon");
63
+ var import_translations = require("../lib/translations");
64
+ var import_jsx_runtime = require("react/jsx-runtime");
65
+ var Icon = ({ name }) => {
66
+ const LucideIcon = import_lucide_react.icons[name];
67
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LucideIcon, { className: "mr-2 h-4 w-4" });
68
+ };
69
+ function AccountSettings(props) {
70
+ const { t } = (0, import_translations.useTranslation)();
71
+ const user = (0, import__.useUser)({ or: "redirect" });
72
+ const teams = user.useTeams();
73
+ const stackApp = (0, import__.useStackApp)();
74
+ const project = stackApp.useProject();
75
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_maybe_full_page.MaybeFullPage, { fullPage: !!props.fullPage, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "self-stretch flex-grow w-full", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
76
+ import_sidebar_layout.SidebarLayout,
77
+ {
78
+ items: [
79
+ {
80
+ title: t("My Profile"),
81
+ type: "item",
82
+ id: "profile",
83
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { name: "Contact" }),
84
+ content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProfilePage, {})
85
+ },
86
+ {
87
+ title: t("Emails & Auth"),
88
+ type: "item",
89
+ id: "auth",
90
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { name: "ShieldCheck" }),
91
+ content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmailsAndAuthPageSkeleton, {}), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmailsAndAuthPage, {}) })
92
+ },
93
+ {
94
+ title: t("Settings"),
95
+ type: "item",
96
+ id: "settings",
97
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { name: "Settings" }),
98
+ content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SettingsPage, {})
99
+ },
100
+ ...props.extraItems?.map((item) => ({
101
+ title: item.title,
102
+ type: "item",
103
+ id: item.id,
104
+ icon: (() => {
105
+ const iconName = item.iconName;
106
+ if (iconName) {
107
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { name: iconName });
108
+ } else if (item.icon) {
109
+ return item.icon;
110
+ }
111
+ return null;
112
+ })(),
113
+ content: item.content
114
+ })) || [],
115
+ ...teams.length > 0 || project.config.clientTeamCreationEnabled ? [{
116
+ title: t("Teams"),
117
+ type: "divider"
118
+ }] : [],
119
+ ...teams.map((team) => ({
120
+ title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2 items-center w-full", children: [
121
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_team_icon.TeamIcon, { team }),
122
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { className: "max-w-[320px] md:w-[90%] truncate", children: team.displayName })
123
+ ] }),
124
+ type: "item",
125
+ id: `team-${team.id}`,
126
+ content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TeamPage, { team })
127
+ })),
128
+ ...project.config.clientTeamCreationEnabled ? [{
129
+ title: t("Create a team"),
130
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { name: "CirclePlus" }),
131
+ type: "item",
132
+ id: "team-creation",
133
+ content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TeamCreation, {})
134
+ }] : []
135
+ ].filter((p) => p.type === "divider" || p.content),
136
+ title: t("Account Settings")
137
+ }
138
+ ) }) });
139
+ }
140
+ function Section(props) {
141
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col sm:flex-row gap-2", children: [
142
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "sm:flex-1 flex flex-col justify-center", children: [
143
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { className: "font-medium", children: props.title }),
144
+ props.description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "footnote", children: props.description })
145
+ ] }),
146
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "sm:flex-1 sm:items-end flex flex-col gap-2 ", children: props.children })
147
+ ] });
148
+ }
149
+ function PageLayout(props) {
150
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-6", children: [
151
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Separator, {}),
152
+ import_react.default.Children.map(props.children, (child) => child && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
153
+ child,
154
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Separator, {})
155
+ ] }))
156
+ ] });
157
+ }
158
+ function ProfilePage() {
159
+ const { t } = (0, import_translations.useTranslation)();
160
+ const user = (0, import__.useUser)({ or: "redirect" });
161
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PageLayout, { children: [
162
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
163
+ Section,
164
+ {
165
+ title: t("User name"),
166
+ description: t("This is a display name and is not used for authentication"),
167
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
168
+ EditableText,
169
+ {
170
+ value: user.displayName || "",
171
+ onSave: async (newDisplayName) => {
172
+ await user.update({ displayName: newDisplayName });
173
+ }
174
+ }
175
+ )
176
+ }
177
+ ),
178
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
179
+ Section,
180
+ {
181
+ title: t("Profile image"),
182
+ description: t("Upload your own image as your avatar"),
183
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
184
+ import_profile_image_editor.ProfileImageEditor,
185
+ {
186
+ user,
187
+ onProfileImageUrlChange: async (profileImageUrl) => {
188
+ await user.update({ profileImageUrl });
189
+ }
190
+ }
191
+ )
192
+ }
193
+ )
194
+ ] });
195
+ }
196
+ function EmailsSection() {
197
+ const { t } = (0, import_translations.useTranslation)();
198
+ const user = (0, import__.useUser)({ or: "redirect" });
199
+ const contactChannels = user.useContactChannels();
200
+ const [addingEmail, setAddingEmail] = (0, import_react.useState)(contactChannels.length === 0);
201
+ const [addingEmailLoading, setAddingEmailLoading] = (0, import_react.useState)(false);
202
+ const [addedEmail, setAddedEmail] = (0, import_react.useState)(null);
203
+ const isLastEmail = contactChannels.filter((x) => x.usedForAuth && x.type === "email").length === 1;
204
+ (0, import_react.useEffect)(() => {
205
+ if (addedEmail) {
206
+ (0, import_promises.runAsynchronously)(async () => {
207
+ const cc = contactChannels.find((x) => x.value === addedEmail);
208
+ if (cc && !cc.isVerified) {
209
+ await cc.sendVerificationEmail();
210
+ }
211
+ setAddedEmail(null);
212
+ });
213
+ }
214
+ }, [contactChannels, addedEmail]);
215
+ const emailSchema = (0, import_schema_fields.yupObject)({
216
+ email: (0, import_schema_fields.strictEmailSchema)(t("Please enter a valid email address")).notOneOf(contactChannels.map((x) => x.value), t("Email already exists")).defined().nonEmpty(t("Email is required"))
217
+ });
218
+ const { register, handleSubmit, formState: { errors }, reset } = (0, import_react_hook_form.useForm)({
219
+ resolver: (0, import_yup.yupResolver)(emailSchema)
220
+ });
221
+ const onSubmit = async (data) => {
222
+ setAddingEmailLoading(true);
223
+ try {
224
+ await user.createContactChannel({ type: "email", value: data.email, usedForAuth: false });
225
+ setAddedEmail(data.email);
226
+ } finally {
227
+ setAddingEmailLoading(false);
228
+ }
229
+ setAddingEmail(false);
230
+ reset();
231
+ };
232
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
233
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col md:flex-row justify-between mb-4 gap-4", children: [
234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { className: "font-medium", children: t("Emails") }),
235
+ addingEmail ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
236
+ "form",
237
+ {
238
+ onSubmit: (e) => {
239
+ e.preventDefault();
240
+ (0, import_promises.runAsynchronously)(handleSubmit(onSubmit));
241
+ },
242
+ className: "flex flex-col",
243
+ children: [
244
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
245
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
246
+ import_stack_ui.Input,
247
+ {
248
+ ...register("email"),
249
+ placeholder: t("Enter email")
250
+ }
251
+ ),
252
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { type: "submit", loading: addingEmailLoading, children: t("Add") }),
253
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
254
+ import_stack_ui.Button,
255
+ {
256
+ variant: "secondary",
257
+ onClick: () => {
258
+ setAddingEmail(false);
259
+ reset();
260
+ },
261
+ children: t("Cancel")
262
+ }
263
+ )
264
+ ] }),
265
+ errors.email && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form_warning.FormWarningText, { text: errors.email.message })
266
+ ]
267
+ }
268
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex md:justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { variant: "secondary", onClick: () => setAddingEmail(true), children: t("Add an email") }) })
269
+ ] }),
270
+ contactChannels.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "border rounded-md", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Table, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableBody, { children: contactChannels.filter((x) => x.type === "email").sort((a, b) => {
271
+ if (a.isPrimary !== b.isPrimary) return a.isPrimary ? -1 : 1;
272
+ if (a.isVerified !== b.isVerified) return a.isVerified ? -1 : 1;
273
+ return 0;
274
+ }).map((x) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_stack_ui.TableRow, { children: [
275
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableCell, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col md:flex-row gap-2 md:gap-4", children: [
276
+ x.value,
277
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
278
+ x.isPrimary ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Badge, { children: t("Primary") }) : null,
279
+ !x.isVerified ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Badge, { variant: "destructive", children: t("Unverified") }) : null,
280
+ x.usedForAuth ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Badge, { variant: "outline", children: t("Used for sign-in") }) : null
281
+ ] })
282
+ ] }) }),
283
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableCell, { className: "flex justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.ActionCell, { items: [
284
+ ...!x.isVerified ? [{
285
+ item: t("Send verification email"),
286
+ onClick: async () => {
287
+ await x.sendVerificationEmail();
288
+ }
289
+ }] : [],
290
+ ...!x.isPrimary && x.isVerified ? [{
291
+ item: t("Set as primary"),
292
+ onClick: async () => {
293
+ await x.update({ isPrimary: true });
294
+ }
295
+ }] : !x.isPrimary ? [{
296
+ item: t("Set as primary"),
297
+ onClick: async () => {
298
+ },
299
+ disabled: true,
300
+ disabledTooltip: t("Please verify your email first")
301
+ }] : [],
302
+ ...!x.usedForAuth && x.isVerified ? [{
303
+ item: t("Use for sign-in"),
304
+ onClick: async () => {
305
+ try {
306
+ await x.update({ usedForAuth: true });
307
+ } catch (e) {
308
+ if (e instanceof import_stack_shared.KnownErrors.ContactChannelAlreadyUsedForAuthBySomeoneElse) {
309
+ alert(t("This email is already used for sign-in by another user."));
310
+ }
311
+ }
312
+ }
313
+ }] : [],
314
+ ...x.usedForAuth && !isLastEmail ? [{
315
+ item: t("Stop using for sign-in"),
316
+ onClick: async () => {
317
+ await x.update({ usedForAuth: false });
318
+ }
319
+ }] : x.usedForAuth ? [{
320
+ item: t("Stop using for sign-in"),
321
+ onClick: async () => {
322
+ },
323
+ disabled: true,
324
+ disabledTooltip: t("You can not remove your last sign-in email")
325
+ }] : [],
326
+ ...!isLastEmail || !x.usedForAuth ? [{
327
+ item: t("Remove"),
328
+ onClick: async () => {
329
+ await x.delete();
330
+ },
331
+ danger: true
332
+ }] : [{
333
+ item: t("Remove"),
334
+ onClick: async () => {
335
+ },
336
+ disabled: true,
337
+ disabledTooltip: t("You can not remove your last sign-in email")
338
+ }]
339
+ ] }) })
340
+ ] }, x.id)) }) }) }) : null
341
+ ] });
342
+ }
343
+ function EmailsAndAuthPage() {
344
+ const passwordSection = usePasswordSection();
345
+ const mfaSection = useMfaSection();
346
+ const otpSection = useOtpSection();
347
+ const passkeySection = usePasskeySection();
348
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PageLayout, { children: [
349
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmailsSection, {}),
350
+ passwordSection,
351
+ passkeySection,
352
+ otpSection,
353
+ mfaSection
354
+ ] });
355
+ }
356
+ function EmailsAndAuthPageSkeleton() {
357
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PageLayout, { children: [
358
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Skeleton, { className: "h-9 w-full mt-1" }),
359
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Skeleton, { className: "h-9 w-full mt-1" }),
360
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Skeleton, { className: "h-9 w-full mt-1" }),
361
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Skeleton, { className: "h-9 w-full mt-1" })
362
+ ] });
363
+ }
364
+ function usePasskeySection() {
365
+ const { t } = (0, import_translations.useTranslation)();
366
+ const user = (0, import__.useUser)({ or: "throw" });
367
+ const stackApp = (0, import__.useStackApp)();
368
+ const project = stackApp.useProject();
369
+ const contactChannels = user.useContactChannels();
370
+ const hasPasskey = user.passkeyAuthEnabled;
371
+ const isLastAuth = user.passkeyAuthEnabled && !user.hasPassword && user.oauthProviders.length === 0 && !user.otpAuthEnabled;
372
+ const [showConfirmationModal, setShowConfirmationModal] = (0, import_react.useState)(false);
373
+ const hasValidEmail = contactChannels.filter((x) => x.type === "email" && x.isVerified && x.usedForAuth).length > 0;
374
+ if (!project.config.passkeyEnabled) {
375
+ return null;
376
+ }
377
+ const handleDeletePasskey = async () => {
378
+ await user.update({ passkeyAuthEnabled: false });
379
+ setShowConfirmationModal(false);
380
+ };
381
+ const handleAddNewPasskey = async () => {
382
+ await user.registerPasskey();
383
+ };
384
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, { title: t("Passkey"), description: hasPasskey ? t("Passkey registered") : t("Register a passkey"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex md:justify-end gap-2", children: [
385
+ !hasValidEmail && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "label", children: t("To enable Passkey sign-in, please add a verified sign-in email.") }),
386
+ hasValidEmail && hasPasskey && isLastAuth && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "label", children: t("Passkey sign-in is enabled and cannot be disabled as it is currently the only sign-in method") }),
387
+ !hasPasskey && hasValidEmail && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { onClick: handleAddNewPasskey, variant: "secondary", children: t("Add new passkey") }) }),
388
+ hasValidEmail && hasPasskey && !isLastAuth && !showConfirmationModal && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
389
+ import_stack_ui.Button,
390
+ {
391
+ variant: "secondary",
392
+ onClick: () => setShowConfirmationModal(true),
393
+ children: t("Delete Passkey")
394
+ }
395
+ ),
396
+ hasValidEmail && hasPasskey && !isLastAuth && showConfirmationModal && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
397
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "destructive", children: t("Are you sure you want to disable Passkey sign-in? You will not be able to sign in with your passkey anymore.") }),
398
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
399
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
400
+ import_stack_ui.Button,
401
+ {
402
+ variant: "destructive",
403
+ onClick: handleDeletePasskey,
404
+ children: t("Disable")
405
+ }
406
+ ),
407
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
408
+ import_stack_ui.Button,
409
+ {
410
+ variant: "secondary",
411
+ onClick: () => setShowConfirmationModal(false),
412
+ children: t("Cancel")
413
+ }
414
+ )
415
+ ] })
416
+ ] })
417
+ ] }) }) });
418
+ }
419
+ function useOtpSection() {
420
+ const { t } = (0, import_translations.useTranslation)();
421
+ const user = (0, import__.useUser)({ or: "throw" });
422
+ const project = (0, import__.useStackApp)().useProject();
423
+ const contactChannels = user.useContactChannels();
424
+ const isLastAuth = user.otpAuthEnabled && !user.hasPassword && user.oauthProviders.length === 0 && !user.passkeyAuthEnabled;
425
+ const [disabling, setDisabling] = (0, import_react.useState)(false);
426
+ const hasValidEmail = contactChannels.filter((x) => x.type === "email" && x.isVerified && x.usedForAuth).length > 0;
427
+ if (!project.config.magicLinkEnabled) {
428
+ return null;
429
+ }
430
+ const handleDisableOTP = async () => {
431
+ await user.update({ otpAuthEnabled: false });
432
+ setDisabling(false);
433
+ };
434
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, { title: t("OTP sign-in"), description: user.otpAuthEnabled ? t("OTP/magic link sign-in is currently enabled.") : t("Enable sign-in via magic link or OTP sent to your sign-in emails."), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex md:justify-end", children: hasValidEmail ? user.otpAuthEnabled ? !isLastAuth ? !disabling ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
435
+ import_stack_ui.Button,
436
+ {
437
+ variant: "secondary",
438
+ onClick: () => setDisabling(true),
439
+ children: t("Disable OTP")
440
+ }
441
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
442
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "destructive", children: t("Are you sure you want to disable OTP sign-in? You will not be able to sign in with only emails anymore.") }),
443
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
444
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
445
+ import_stack_ui.Button,
446
+ {
447
+ variant: "destructive",
448
+ onClick: handleDisableOTP,
449
+ children: t("Disable")
450
+ }
451
+ ),
452
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
453
+ import_stack_ui.Button,
454
+ {
455
+ variant: "secondary",
456
+ onClick: () => setDisabling(false),
457
+ children: t("Cancel")
458
+ }
459
+ )
460
+ ] })
461
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "label", children: t("OTP sign-in is enabled and cannot be disabled as it is currently the only sign-in method") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
462
+ import_stack_ui.Button,
463
+ {
464
+ variant: "secondary",
465
+ onClick: async () => {
466
+ await user.update({ otpAuthEnabled: true });
467
+ },
468
+ children: t("Enable OTP")
469
+ }
470
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "label", children: t("To enable OTP sign-in, please add a verified sign-in email.") }) }) });
471
+ }
472
+ function SettingsPage() {
473
+ const deleteAccountSection = useDeleteAccountSection();
474
+ const signOutSection = useSignOutSection();
475
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PageLayout, { children: [
476
+ deleteAccountSection,
477
+ signOutSection
478
+ ] });
479
+ }
480
+ function usePasswordSection() {
481
+ const { t } = (0, import_translations.useTranslation)();
482
+ const user = (0, import__.useUser)({ or: "throw" });
483
+ const contactChannels = user.useContactChannels();
484
+ const [changingPassword, setChangingPassword] = (0, import_react.useState)(false);
485
+ const [loading, setLoading] = (0, import_react.useState)(false);
486
+ const passwordSchema = (0, import_schema_fields.yupObject)({
487
+ oldPassword: user.hasPassword ? import_schema_fields.passwordSchema.defined().nonEmpty(t("Please enter your old password")) : (0, import_schema_fields.yupString)(),
488
+ newPassword: import_schema_fields.passwordSchema.defined().nonEmpty(t("Please enter your password")).test({
489
+ name: "is-valid-password",
490
+ test: (value, ctx) => {
491
+ const error = (0, import_password.getPasswordError)(value);
492
+ if (error) {
493
+ return ctx.createError({ message: error.message });
494
+ } else {
495
+ return true;
496
+ }
497
+ }
498
+ }),
499
+ newPasswordRepeat: (0, import_schema_fields.yupString)().nullable().oneOf([yup.ref("newPassword"), "", null], t("Passwords do not match")).defined().nonEmpty(t("Please repeat your password"))
500
+ });
501
+ const { register, handleSubmit, setError, formState: { errors }, clearErrors, reset } = (0, import_react_hook_form.useForm)({
502
+ resolver: (0, import_yup.yupResolver)(passwordSchema)
503
+ });
504
+ const hasValidEmail = contactChannels.filter((x) => x.type === "email" && x.usedForAuth).length > 0;
505
+ const onSubmit = async (data) => {
506
+ setLoading(true);
507
+ try {
508
+ const { oldPassword, newPassword } = data;
509
+ const error = user.hasPassword ? await user.updatePassword({ oldPassword, newPassword }) : await user.setPassword({ password: newPassword });
510
+ if (error) {
511
+ setError("oldPassword", { type: "manual", message: t("Incorrect password") });
512
+ } else {
513
+ reset();
514
+ setChangingPassword(false);
515
+ }
516
+ } finally {
517
+ setLoading(false);
518
+ }
519
+ };
520
+ const registerPassword = register("newPassword");
521
+ const registerPasswordRepeat = register("newPasswordRepeat");
522
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
523
+ Section,
524
+ {
525
+ title: t("Password"),
526
+ description: user.hasPassword ? t("Update your password") : t("Set a password for your account"),
527
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex flex-col gap-4", children: !changingPassword ? hasValidEmail ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
528
+ import_stack_ui.Button,
529
+ {
530
+ variant: "secondary",
531
+ onClick: () => setChangingPassword(true),
532
+ children: user.hasPassword ? t("Update password") : t("Set password")
533
+ }
534
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "label", children: t("To set a password, please add a sign-in email.") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
535
+ "form",
536
+ {
537
+ onSubmit: (e) => (0, import_promises.runAsynchronouslyWithAlert)(handleSubmit(onSubmit)(e)),
538
+ noValidate: true,
539
+ children: [
540
+ user.hasPassword && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
541
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Label, { htmlFor: "old-password", className: "mb-1", children: t("Old password") }),
542
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
543
+ import_stack_ui.Input,
544
+ {
545
+ id: "old-password",
546
+ type: "password",
547
+ autoComplete: "current-password",
548
+ ...register("oldPassword")
549
+ }
550
+ ),
551
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form_warning.FormWarningText, { text: errors.oldPassword?.message?.toString() })
552
+ ] }),
553
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Label, { htmlFor: "new-password", className: "mt-4 mb-1", children: t("New password") }),
554
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
555
+ import_stack_ui.PasswordInput,
556
+ {
557
+ id: "new-password",
558
+ autoComplete: "new-password",
559
+ ...registerPassword,
560
+ onChange: (e) => {
561
+ clearErrors("newPassword");
562
+ clearErrors("newPasswordRepeat");
563
+ (0, import_promises.runAsynchronously)(registerPassword.onChange(e));
564
+ }
565
+ }
566
+ ),
567
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form_warning.FormWarningText, { text: errors.newPassword?.message?.toString() }),
568
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Label, { htmlFor: "repeat-password", className: "mt-4 mb-1", children: t("Repeat new password") }),
569
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
570
+ import_stack_ui.PasswordInput,
571
+ {
572
+ id: "repeat-password",
573
+ autoComplete: "new-password",
574
+ ...registerPasswordRepeat,
575
+ onChange: (e) => {
576
+ clearErrors("newPassword");
577
+ clearErrors("newPasswordRepeat");
578
+ (0, import_promises.runAsynchronously)(registerPasswordRepeat.onChange(e));
579
+ }
580
+ }
581
+ ),
582
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form_warning.FormWarningText, { text: errors.newPasswordRepeat?.message?.toString() }),
583
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mt-6 flex gap-4", children: [
584
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { type: "submit", loading, children: user.hasPassword ? t("Update Password") : t("Set Password") }),
585
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
586
+ import_stack_ui.Button,
587
+ {
588
+ variant: "secondary",
589
+ onClick: () => {
590
+ setChangingPassword(false);
591
+ reset();
592
+ },
593
+ children: t("Cancel")
594
+ }
595
+ )
596
+ ] })
597
+ ]
598
+ }
599
+ ) })
600
+ }
601
+ );
602
+ }
603
+ function useMfaSection() {
604
+ const { t } = (0, import_translations.useTranslation)();
605
+ const project = (0, import__.useStackApp)().useProject();
606
+ const user = (0, import__.useUser)({ or: "throw" });
607
+ const [generatedSecret, setGeneratedSecret] = (0, import_react.useState)(null);
608
+ const [qrCodeUrl, setQrCodeUrl] = (0, import_react.useState)(null);
609
+ const [mfaCode, setMfaCode] = (0, import_react.useState)("");
610
+ const [isMaybeWrong, setIsMaybeWrong] = (0, import_react.useState)(false);
611
+ const isEnabled = user.isMultiFactorRequired;
612
+ const [handleSubmit, isLoading] = (0, import_use_async_callback.useAsyncCallback)(async () => {
613
+ await user.update({
614
+ totpMultiFactorSecret: generatedSecret
615
+ });
616
+ setGeneratedSecret(null);
617
+ setQrCodeUrl(null);
618
+ setMfaCode("");
619
+ }, [generatedSecret, user]);
620
+ (0, import_react.useEffect)(() => {
621
+ setIsMaybeWrong(false);
622
+ (0, import_promises.runAsynchronouslyWithAlert)(async () => {
623
+ if (generatedSecret && await new import_otp.TOTPController().verify(mfaCode, generatedSecret)) {
624
+ await handleSubmit();
625
+ }
626
+ setIsMaybeWrong(true);
627
+ });
628
+ }, [mfaCode, generatedSecret, handleSubmit]);
629
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
630
+ Section,
631
+ {
632
+ title: t("Multi-factor authentication"),
633
+ description: isEnabled ? t("Multi-factor authentication is currently enabled.") : t("Multi-factor authentication is currently disabled."),
634
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-4", children: [
635
+ !isEnabled && generatedSecret && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
636
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { children: t("Scan this QR code with your authenticator app:") }),
637
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { width: 200, height: 200, src: qrCodeUrl ?? (0, import_errors.throwErr)("TOTP QR code failed to generate"), alt: t("TOTP multi-factor authentication QR code") }),
638
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { children: t("Then, enter your six-digit MFA code:") }),
639
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
640
+ import_stack_ui.Input,
641
+ {
642
+ value: mfaCode,
643
+ onChange: (e) => {
644
+ setIsMaybeWrong(false);
645
+ setMfaCode(e.target.value);
646
+ },
647
+ placeholder: "123456",
648
+ maxLength: 6,
649
+ disabled: isLoading
650
+ }
651
+ ),
652
+ isMaybeWrong && mfaCode.length === 6 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "destructive", children: t("Incorrect code. Please try again.") }),
653
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
654
+ import_stack_ui.Button,
655
+ {
656
+ variant: "secondary",
657
+ onClick: () => {
658
+ setGeneratedSecret(null);
659
+ setQrCodeUrl(null);
660
+ setMfaCode("");
661
+ },
662
+ children: t("Cancel")
663
+ }
664
+ ) })
665
+ ] }),
666
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex gap-2", children: isEnabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
667
+ import_stack_ui.Button,
668
+ {
669
+ variant: "secondary",
670
+ onClick: async () => {
671
+ await user.update({
672
+ totpMultiFactorSecret: null
673
+ });
674
+ },
675
+ children: t("Disable MFA")
676
+ }
677
+ ) : !generatedSecret && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
678
+ import_stack_ui.Button,
679
+ {
680
+ variant: "secondary",
681
+ onClick: async () => {
682
+ const secret = (0, import_crypto.generateRandomValues)(new Uint8Array(20));
683
+ setQrCodeUrl(await generateTotpQrCode(project, user, secret));
684
+ setGeneratedSecret(secret);
685
+ },
686
+ children: t("Enable MFA")
687
+ }
688
+ ) })
689
+ ] })
690
+ }
691
+ );
692
+ }
693
+ async function generateTotpQrCode(project, user, secret) {
694
+ const uri = (0, import_otp.createTOTPKeyURI)(project.displayName, user.primaryEmail ?? user.id, secret);
695
+ return await QRCode.toDataURL(uri);
696
+ }
697
+ function useSignOutSection() {
698
+ const { t } = (0, import_translations.useTranslation)();
699
+ const user = (0, import__.useUser)({ or: "throw" });
700
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
701
+ Section,
702
+ {
703
+ title: t("Sign out"),
704
+ description: t("End your current session"),
705
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
706
+ import_stack_ui.Button,
707
+ {
708
+ variant: "secondary",
709
+ onClick: () => user.signOut(),
710
+ children: t("Sign out")
711
+ }
712
+ ) })
713
+ }
714
+ );
715
+ }
716
+ function TeamPage(props) {
717
+ const teamUserProfileSection = useTeamUserProfileSection(props);
718
+ const teamProfileImageSection = useTeamProfileImageSection(props);
719
+ const teamDisplayNameSection = useTeamDisplayNameSection(props);
720
+ const leaveTeamSection = useLeaveTeamSection(props);
721
+ const memberInvitationSection = useMemberInvitationSection(props);
722
+ const memberListSection = useMemberListSection(props);
723
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PageLayout, { children: [
724
+ teamUserProfileSection,
725
+ memberListSection,
726
+ memberInvitationSection,
727
+ teamProfileImageSection,
728
+ teamDisplayNameSection,
729
+ leaveTeamSection
730
+ ] });
731
+ }
732
+ function useLeaveTeamSection(props) {
733
+ const { t } = (0, import_translations.useTranslation)();
734
+ const user = (0, import__.useUser)({ or: "redirect" });
735
+ const [leaving, setLeaving] = (0, import_react.useState)(false);
736
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
737
+ Section,
738
+ {
739
+ title: t("Leave Team"),
740
+ description: t("leave this team and remove your team profile"),
741
+ children: !leaving ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
742
+ import_stack_ui.Button,
743
+ {
744
+ variant: "secondary",
745
+ onClick: () => setLeaving(true),
746
+ children: t("Leave team")
747
+ }
748
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
749
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "destructive", children: t("Are you sure you want to leave the team?") }),
750
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
751
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
752
+ import_stack_ui.Button,
753
+ {
754
+ variant: "destructive",
755
+ onClick: async () => {
756
+ await user.leaveTeam(props.team);
757
+ window.location.reload();
758
+ },
759
+ children: t("Leave")
760
+ }
761
+ ),
762
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
763
+ import_stack_ui.Button,
764
+ {
765
+ variant: "secondary",
766
+ onClick: () => setLeaving(false),
767
+ children: t("Cancel")
768
+ }
769
+ )
770
+ ] })
771
+ ] })
772
+ }
773
+ );
774
+ }
775
+ function useTeamProfileImageSection(props) {
776
+ const { t } = (0, import_translations.useTranslation)();
777
+ const user = (0, import__.useUser)({ or: "redirect" });
778
+ const updateTeamPermission = user.usePermission(props.team, "$update_team");
779
+ if (!updateTeamPermission) {
780
+ return null;
781
+ }
782
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
783
+ Section,
784
+ {
785
+ title: t("Team profile image"),
786
+ description: t("Upload an image for your team"),
787
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
788
+ import_profile_image_editor.ProfileImageEditor,
789
+ {
790
+ user: props.team,
791
+ onProfileImageUrlChange: async (profileImageUrl) => {
792
+ await props.team.update({ profileImageUrl });
793
+ }
794
+ }
795
+ )
796
+ }
797
+ );
798
+ }
799
+ function useTeamDisplayNameSection(props) {
800
+ const { t } = (0, import_translations.useTranslation)();
801
+ const user = (0, import__.useUser)({ or: "redirect" });
802
+ const updateTeamPermission = user.usePermission(props.team, "$update_team");
803
+ if (!updateTeamPermission) {
804
+ return null;
805
+ }
806
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
807
+ Section,
808
+ {
809
+ title: t("Team display name"),
810
+ description: t("Change the display name of your team"),
811
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
812
+ EditableText,
813
+ {
814
+ value: props.team.displayName,
815
+ onSave: async (newDisplayName) => await props.team.update({ displayName: newDisplayName })
816
+ }
817
+ )
818
+ }
819
+ );
820
+ }
821
+ function useTeamUserProfileSection(props) {
822
+ const { t } = (0, import_translations.useTranslation)();
823
+ const user = (0, import__.useUser)({ or: "redirect" });
824
+ const profile = user.useTeamProfile(props.team);
825
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
826
+ Section,
827
+ {
828
+ title: t("Team user name"),
829
+ description: t("Overwrite your user display name in this team"),
830
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
831
+ EditableText,
832
+ {
833
+ value: profile.displayName || "",
834
+ onSave: async (newDisplayName) => {
835
+ await profile.update({ displayName: newDisplayName });
836
+ }
837
+ }
838
+ )
839
+ }
840
+ );
841
+ }
842
+ function useMemberInvitationSection(props) {
843
+ const { t } = (0, import_translations.useTranslation)();
844
+ const invitationSchema = (0, import_schema_fields.yupObject)({
845
+ email: (0, import_schema_fields.strictEmailSchema)(t("Please enter a valid email address")).defined().nonEmpty(t("Please enter an email address"))
846
+ });
847
+ const user = (0, import__.useUser)({ or: "redirect" });
848
+ const inviteMemberPermission = user.usePermission(props.team, "$invite_members");
849
+ const readMemberPermission = user.usePermission(props.team, "$read_members");
850
+ const removeMemberPermission = user.usePermission(props.team, "$remove_members");
851
+ if (!inviteMemberPermission) {
852
+ return null;
853
+ }
854
+ let invitationsToShow = [];
855
+ if (readMemberPermission) {
856
+ invitationsToShow = props.team.useInvitations();
857
+ }
858
+ const { register, handleSubmit, formState: { errors }, watch } = (0, import_react_hook_form.useForm)({
859
+ resolver: (0, import_yup.yupResolver)(invitationSchema)
860
+ });
861
+ const [loading, setLoading] = (0, import_react.useState)(false);
862
+ const [invitedEmail, setInvitedEmail] = (0, import_react.useState)(null);
863
+ const onSubmit = async (data) => {
864
+ setLoading(true);
865
+ try {
866
+ await props.team.inviteUser({ email: data.email });
867
+ setInvitedEmail(data.email);
868
+ } finally {
869
+ setLoading(false);
870
+ }
871
+ };
872
+ (0, import_react.useEffect)(() => {
873
+ setInvitedEmail(null);
874
+ }, [watch("email")]);
875
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
876
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
877
+ Section,
878
+ {
879
+ title: t("Invite member"),
880
+ description: t("Invite a user to your team through email"),
881
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
882
+ "form",
883
+ {
884
+ onSubmit: (e) => (0, import_promises.runAsynchronouslyWithAlert)(handleSubmit(onSubmit)(e)),
885
+ noValidate: true,
886
+ className: "w-full",
887
+ children: [
888
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-4 sm:flex-row w-full", children: [
889
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
890
+ import_stack_ui.Input,
891
+ {
892
+ placeholder: t("Email"),
893
+ ...register("email")
894
+ }
895
+ ),
896
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { type: "submit", loading, children: t("Invite User") })
897
+ ] }),
898
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form_warning.FormWarningText, { text: errors.email?.message?.toString() }),
899
+ invitedEmail && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_stack_ui.Typography, { type: "label", variant: "secondary", children: [
900
+ "Invited ",
901
+ invitedEmail
902
+ ] })
903
+ ]
904
+ }
905
+ )
906
+ }
907
+ ),
908
+ invitationsToShow.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_stack_ui.Table, { className: "mt-6", children: [
909
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_stack_ui.TableRow, { children: [
910
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableHead, { className: "w-[200px]", children: t("Outstanding invitations") }),
911
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableHead, { className: "w-[60px]", children: t("Expires") }),
912
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableHead, { className: "w-[36px] max-w-[36px]" })
913
+ ] }) }),
914
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableBody, { children: invitationsToShow.map((invitation, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_stack_ui.TableRow, { children: [
915
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableCell, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { children: invitation.recipientEmail }) }),
916
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableCell, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", children: invitation.expiresAt.toLocaleString() }) }),
917
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableCell, { align: "right", className: "max-w-[36px]", children: removeMemberPermission && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { onClick: async () => await invitation.revoke(), size: "icon", variant: "ghost", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Trash, { className: "w-4 h-4" }) }) })
918
+ ] }, invitation.id)) })
919
+ ] }) })
920
+ ] });
921
+ }
922
+ function useMemberListSection(props) {
923
+ const { t } = (0, import_translations.useTranslation)();
924
+ const user = (0, import__.useUser)({ or: "redirect" });
925
+ const readMemberPermission = user.usePermission(props.team, "$read_members");
926
+ const inviteMemberPermission = user.usePermission(props.team, "$invite_members");
927
+ if (!readMemberPermission && !inviteMemberPermission) {
928
+ return null;
929
+ }
930
+ const users = props.team.useUsers();
931
+ if (!readMemberPermission) {
932
+ return null;
933
+ }
934
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
935
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { className: "font-medium mb-2", children: t("Members") }),
936
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "border rounded-md", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_stack_ui.Table, { children: [
937
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_stack_ui.TableRow, { children: [
938
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableHead, { className: "w-[100px]", children: t("User") }),
939
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableHead, { className: "w-[200px]", children: t("Name") })
940
+ ] }) }),
941
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableBody, { children: users.map(({ id, teamProfile }, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_stack_ui.TableRow, { children: [
942
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableCell, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_user_avatar.UserAvatar, { user: teamProfile }) }),
943
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableCell, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { children: teamProfile.displayName }) })
944
+ ] }, id)) })
945
+ ] }) })
946
+ ] });
947
+ }
948
+ function TeamCreation() {
949
+ const { t } = (0, import_translations.useTranslation)();
950
+ const teamCreationSchema = (0, import_schema_fields.yupObject)({
951
+ displayName: (0, import_schema_fields.yupString)().defined().nonEmpty(t("Please enter a team name"))
952
+ });
953
+ const { register, handleSubmit, formState: { errors } } = (0, import_react_hook_form.useForm)({
954
+ resolver: (0, import_yup.yupResolver)(teamCreationSchema)
955
+ });
956
+ const app = (0, import__.useStackApp)();
957
+ const project = app.useProject();
958
+ const user = (0, import__.useUser)({ or: "redirect" });
959
+ const navigate = app.useNavigate();
960
+ const [loading, setLoading] = (0, import_react.useState)(false);
961
+ if (!project.config.clientTeamCreationEnabled) {
962
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.MessageCard, { title: t("Team creation is not enabled") });
963
+ }
964
+ const onSubmit = async (data) => {
965
+ setLoading(true);
966
+ let team;
967
+ try {
968
+ team = await user.createTeam({ displayName: data.displayName });
969
+ } finally {
970
+ setLoading(false);
971
+ }
972
+ navigate(`#team-${team.id}`);
973
+ };
974
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageLayout, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, { title: t("Create a Team"), description: t("Enter a display name for your new team"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
975
+ "form",
976
+ {
977
+ onSubmit: (e) => (0, import_promises.runAsynchronouslyWithAlert)(handleSubmit(onSubmit)(e)),
978
+ noValidate: true,
979
+ className: "flex gap-2 flex-col sm:flex-row",
980
+ children: [
981
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col flex-1", children: [
982
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
983
+ import_stack_ui.Input,
984
+ {
985
+ id: "displayName",
986
+ type: "text",
987
+ ...register("displayName")
988
+ }
989
+ ),
990
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form_warning.FormWarningText, { text: errors.displayName?.message?.toString() })
991
+ ] }),
992
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { type: "submit", loading, children: t("Create") })
993
+ ]
994
+ }
995
+ ) }) });
996
+ }
997
+ function useDeleteAccountSection() {
998
+ const { t } = (0, import_translations.useTranslation)();
999
+ const user = (0, import__.useUser)({ or: "redirect" });
1000
+ const app = (0, import__.useStackApp)();
1001
+ const project = app.useProject();
1002
+ const [deleting, setDeleting] = (0, import_react.useState)(false);
1003
+ if (!project.config.clientUserDeletionEnabled) {
1004
+ return null;
1005
+ }
1006
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1007
+ Section,
1008
+ {
1009
+ title: t("Delete Account"),
1010
+ description: t("Permanently remove your account and all associated data"),
1011
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "stack-scope flex flex-col items-stretch", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Accordion, { type: "single", collapsible: true, className: "w-full", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_stack_ui.AccordionItem, { value: "item-1", children: [
1012
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.AccordionTrigger, { children: t("Danger zone") }),
1013
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.AccordionContent, { children: !deleting ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1014
+ import_stack_ui.Button,
1015
+ {
1016
+ variant: "destructive",
1017
+ onClick: () => setDeleting(true),
1018
+ children: t("Delete account")
1019
+ }
1020
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
1021
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "destructive", children: t("Are you sure you want to delete your account? This action is IRREVERSIBLE and will delete ALL associated data.") }),
1022
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
1023
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1024
+ import_stack_ui.Button,
1025
+ {
1026
+ variant: "destructive",
1027
+ onClick: async () => {
1028
+ await user.delete();
1029
+ await app.redirectToHome();
1030
+ },
1031
+ children: t("Delete Account")
1032
+ }
1033
+ ),
1034
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1035
+ import_stack_ui.Button,
1036
+ {
1037
+ variant: "secondary",
1038
+ onClick: () => setDeleting(false),
1039
+ children: t("Cancel")
1040
+ }
1041
+ )
1042
+ ] })
1043
+ ] }) })
1044
+ ] }) }) })
1045
+ }
1046
+ );
1047
+ }
1048
+ function EditableText(props) {
1049
+ const [editing, setEditing] = (0, import_react.useState)(false);
1050
+ const [editingValue, setEditingValue] = (0, import_react.useState)(props.value);
1051
+ const { t } = (0, import_translations.useTranslation)();
1052
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex items-center gap-2", children: editing ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1053
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1054
+ import_stack_ui.Input,
1055
+ {
1056
+ value: editingValue,
1057
+ onChange: (e) => setEditingValue(e.target.value)
1058
+ }
1059
+ ),
1060
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1061
+ import_stack_ui.Button,
1062
+ {
1063
+ size: "sm",
1064
+ onClick: async () => {
1065
+ await props.onSave?.(editingValue);
1066
+ setEditing(false);
1067
+ },
1068
+ children: t("Save")
1069
+ }
1070
+ ),
1071
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1072
+ import_stack_ui.Button,
1073
+ {
1074
+ size: "sm",
1075
+ variant: "secondary",
1076
+ onClick: () => {
1077
+ setEditingValue(props.value);
1078
+ setEditing(false);
1079
+ },
1080
+ children: t("Cancel")
1081
+ }
1082
+ )
1083
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1084
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { children: props.value }),
1085
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { onClick: () => setEditing(true), size: "icon", variant: "ghost", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Edit, { className: "w-4 h-4" }) })
1086
+ ] }) });
1087
+ }
1088
+ // Annotate the CommonJS export names for ESM import in node:
1089
+ 0 && (module.exports = {
1090
+ AccountSettings,
1091
+ EditableText,
1092
+ TeamCreation,
1093
+ useDeleteAccountSection
1094
+ });
1095
+ //# sourceMappingURL=account-settings.js.map