@krak-stack/auth 0.1.53 → 0.1.55

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.
@@ -1,3 +1,4 @@
1
+ import { createElement as _createElement } from "react";
1
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
3
4
  import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
@@ -7,16 +8,18 @@ import { AsyncResult, Atom } from "effect/unstable/reactivity";
7
8
  import { Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
8
9
  import { createContext, useContext, useEffect, useEffectEvent, useRef, useState, } from "react";
9
10
  import { DataTable, DataTableRelationshipCell, } from "@/components/ui/data-table";
10
- import { ImageField, SelectField, SubmitButton, SubmitError, TextField, } from "@/components/ui/effect-form";
11
+ import { ErrorMessage, ImageField, SelectField, SubmitButton, SubmitError, TextField, } from "@/components/ui/effect-form";
11
12
  import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
12
13
  import { AppBrand } from "@/components/ui/app-brand";
13
- import { FieldSet } from "@/components/ui/field";
14
+ import { Field, FieldLabel, FieldSet } from "@/components/ui/field";
15
+ import { Input } from "@/components/ui/input";
14
16
  import { Badge } from "@/components/ui/badge";
15
17
  import { Button } from "@/components/ui/button";
16
18
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
17
19
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
20
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
18
21
  import { Separator } from "@/components/ui/separator";
19
- import { OrganizationMetadata, } from "@krak-stack/auth/schema";
22
+ import { OrganizationEmail, OrganizationAddress, OrganizationMetadata, OrganizationPhone, OrganizationSocial, OrganizationTranslation, OrganizationWebsite, decodeOrganizationMetadata, } from "@krak-stack/auth/schema";
20
23
  import { isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, } from "../roles";
21
24
  import { authClientApi } from "./auth-client-api";
22
25
  import { useKrakstackAuth } from "./auth-provider";
@@ -28,7 +31,20 @@ import { assetPath, assetUrl, cn } from "./utils";
28
31
  const messages = {
29
32
  en: {
30
33
  api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
31
- organization_contact_email: "Contact email",
34
+ organization_contact: "Contact methods",
35
+ organization_contact_add_email: "Add email",
36
+ organization_contact_add_phone: "Add phone",
37
+ organization_contact_add_social: "Add social profile",
38
+ organization_contact_add_website: "Add website",
39
+ organization_contact_email_type: "Email",
40
+ organization_contact_extension: "Extension",
41
+ organization_contact_label: "Label",
42
+ organization_contact_phone_type: "Phone",
43
+ organization_contact_platform: "Platform",
44
+ organization_contact_remove: "Remove contact method",
45
+ organization_contact_social_type: "Social",
46
+ organization_contact_url: "URL",
47
+ organization_contact_website_type: "Website",
32
48
  organization_create_description: "Create a workspace for team-based access.",
33
49
  organization_create_error: "Could not create the organization.",
34
50
  organization_copy_id: "Copy organization ID",
@@ -62,10 +78,17 @@ const messages = {
62
78
  organization_invite_member_description: "Send an invitation to join this organization with the selected role.",
63
79
  organization_invite_member_title: "Invite a member",
64
80
  organization_loading: "Loading...",
65
- organization_location: "Location",
81
+ organization_address: "Address",
82
+ organization_address_add: "Add address",
83
+ organization_address_country: "Country",
84
+ organization_address_locality: "City or locality",
85
+ organization_address_postal_code: "Postal code",
86
+ organization_address_region: "State, province, or region",
87
+ organization_address_street: "Street address",
66
88
  organization_parent: "Parent organization",
67
89
  organization_parent_description: "Optionally group this organization under another organization.",
68
90
  organization_parent_none: "No parent organization",
91
+ organization_profile: "Profile",
69
92
  organization_icon: "Icon",
70
93
  organization_logo: "Logo",
71
94
  organization_logo_upload_error: "Could not upload the organization logo.",
@@ -88,7 +111,7 @@ const messages = {
88
111
  organization_role_member: "Member",
89
112
  organization_role_owner: "Owner",
90
113
  organization_role_support: "Support",
91
- organization_slug: "Organization slug",
114
+ organization_slug: "Slug",
92
115
  organization_slug_description: "Leave blank to generate one from the name.",
93
116
  organization_switcher_empty: "You do not belong to any organizations yet.",
94
117
  organization_switcher_label: "Organization",
@@ -96,8 +119,6 @@ const messages = {
96
119
  organization_switcher_no_other_organizations: "No other organizations.",
97
120
  organization_switcher_personal: "Personal",
98
121
  organization_translation_description: "Localized organization details stored in metadata.",
99
- organization_translation_english: "English profile",
100
- organization_translation_french: "French profile",
101
122
  organization_translation_name: "Name",
102
123
  organization_update_error: "Could not update the organization.",
103
124
  table_empty: "No results.",
@@ -119,7 +140,20 @@ const messages = {
119
140
  },
120
141
  fr: {
121
142
  api_key_rate_limit_notice: "Les clés API sont soumises aux mêmes limites de débit que votre compte.",
122
- organization_contact_email: "E-mail de contact",
143
+ organization_contact: "Moyens de contact",
144
+ organization_contact_add_email: "Ajouter un courriel",
145
+ organization_contact_add_phone: "Ajouter un téléphone",
146
+ organization_contact_add_social: "Ajouter un profil social",
147
+ organization_contact_add_website: "Ajouter un site Web",
148
+ organization_contact_email_type: "Courriel",
149
+ organization_contact_extension: "Poste",
150
+ organization_contact_label: "Libellé",
151
+ organization_contact_phone_type: "Téléphone",
152
+ organization_contact_platform: "Plateforme",
153
+ organization_contact_remove: "Supprimer le moyen de contact",
154
+ organization_contact_social_type: "Réseau social",
155
+ organization_contact_url: "URL",
156
+ organization_contact_website_type: "Site Web",
123
157
  organization_create_description: "Créez un espace de travail pour l'accès en équipe.",
124
158
  organization_create_error: "Impossible de créer l'organisation.",
125
159
  organization_copy_id: "Copier l'ID de l'organisation",
@@ -153,10 +187,17 @@ const messages = {
153
187
  organization_invite_member_description: "Envoyez une invitation à rejoindre cette organisation avec le rôle sélectionné.",
154
188
  organization_invite_member_title: "Inviter un membre",
155
189
  organization_loading: "Chargement...",
156
- organization_location: "Emplacement",
190
+ organization_address: "Adresse",
191
+ organization_address_add: "Ajouter une adresse",
192
+ organization_address_country: "Pays",
193
+ organization_address_locality: "Ville ou localité",
194
+ organization_address_postal_code: "Code postal",
195
+ organization_address_region: "État, province ou région",
196
+ organization_address_street: "Adresse municipale",
157
197
  organization_parent: "Organisation parente",
158
198
  organization_parent_description: "Regroupez facultativement cette organisation sous une autre organisation.",
159
199
  organization_parent_none: "Aucune organisation parente",
200
+ organization_profile: "Profil",
160
201
  organization_icon: "Icône",
161
202
  organization_logo: "Logo",
162
203
  organization_logo_upload_error: "Impossible de téléverser le logo de l'organisation.",
@@ -179,7 +220,7 @@ const messages = {
179
220
  organization_role_member: "Membre",
180
221
  organization_role_owner: "Propriétaire",
181
222
  organization_role_support: "Support",
182
- organization_slug: "Slug de l'organisation",
223
+ organization_slug: "Slug",
183
224
  organization_slug_description: "Laissez vide pour en générer un à partir du nom.",
184
225
  organization_switcher_empty: "Vous n'appartenez encore à aucune organisation.",
185
226
  organization_switcher_label: "Organisation",
@@ -187,8 +228,6 @@ const messages = {
187
228
  organization_switcher_no_other_organizations: "Aucune autre organisation.",
188
229
  organization_switcher_personal: "Personnel",
189
230
  organization_translation_description: "Détails localisés de l'organisation stockés dans les métadonnées.",
190
- organization_translation_english: "Profil anglais",
191
- organization_translation_french: "Profil français",
192
231
  organization_translation_name: "Nom",
193
232
  organization_update_error: "Impossible de mettre à jour l'organisation.",
194
233
  table_empty: "Aucun résultat.",
@@ -243,10 +282,10 @@ const userInvitationsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make
243
282
  },
244
283
  catch: (error) => error,
245
284
  }))));
246
- const invitationOrganizationProfileAtom = Atom.family(({ baseUrl, organizationId, }) => authClientApi(baseUrl).query("authExtra", "getOrganizationPublicProfile", {
247
- query: { organizationId },
285
+ const invitationOrganizationProfileAtom = Atom.family(({ baseUrl, locale, organizationId, }) => authClientApi(baseUrl).query("authExtra", "getOrganizationPublicProfile", {
286
+ query: { locale, organizationId },
248
287
  timeToLive: "5 minutes",
249
- serializationKey: `invitation-organization:${organizationId}`,
288
+ serializationKey: `invitation-organization:${organizationId}:${locale}`,
250
289
  }));
251
290
  const emptyUserInvitationsAtom = Atom.make(Effect.try({
252
291
  try: () => [],
@@ -299,16 +338,144 @@ const organizationImageSchema = Schema.Union([
299
338
  const organizationFormBuilder = FormBuilder.empty
300
339
  .addField("parentId", Schema.String)
301
340
  .addField("slug", Schema.String)
341
+ .addField("emails", Schema.Array(OrganizationEmail))
342
+ .addField("phones", Schema.Array(OrganizationPhone))
343
+ .addField("websites", Schema.Array(OrganizationWebsite))
344
+ .addField("socials", Schema.Array(OrganizationSocial))
345
+ .addField("addresses", Schema.Array(OrganizationAddress))
302
346
  .addField("enName", Schema.String)
303
347
  .addField("enLogo", organizationImageSchema)
304
348
  .addField("enIcon", organizationImageSchema)
305
- .addField("enContactEmail", Schema.String)
306
- .addField("enLocation", Schema.String)
307
349
  .addField("frName", Schema.String)
308
350
  .addField("frLogo", organizationImageSchema)
309
- .addField("frIcon", organizationImageSchema)
310
- .addField("frContactEmail", Schema.String)
311
- .addField("frLocation", Schema.String);
351
+ .addField("frIcon", organizationImageSchema);
352
+ const socialPlatform = (value) => {
353
+ switch (value) {
354
+ case "facebook":
355
+ case "github":
356
+ case "instagram":
357
+ case "linkedin":
358
+ case "tiktok":
359
+ case "x":
360
+ case "youtube":
361
+ return value;
362
+ default:
363
+ return null;
364
+ }
365
+ };
366
+ const contactLabel = (translations, locale) => translations?.find((translation) => translation.locale === locale)?.label ??
367
+ "";
368
+ const contactTranslations = (translations, locale, label) => [
369
+ ...(translations ?? []).filter((translation) => translation.locale !== locale),
370
+ ...(label ? [{ locale, label }] : []),
371
+ ];
372
+ const EmailsField = ({ field, props }) => {
373
+ const m = useOrganizationMessages();
374
+ return (_jsx(RepeatableContactField, { addLabel: m.organization_contact_add_email(), emptyValue: {
375
+ email: "",
376
+ translations: [{ locale: props.locale, label: "" }],
377
+ }, error: Option.isSome(field.error) ? field.error.value : undefined, path: field.path, values: field.value, onChange: field.onChange, render: (contact, index, update) => (_jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(ContactInput, { id: `${field.path}-${index}-email`, label: m.organization_contact_email_type(), placeholder: "team@example.com", type: "email", value: contact.email, onBlur: field.onBlur, onChange: (email) => update({ ...contact, email }) }), _jsx(ContactLabelInput, { id: `${field.path}-${index}-label`, locale: props.locale, translations: contact.translations, onBlur: field.onBlur, onChange: (translations) => update({
378
+ ...contact,
379
+ translations,
380
+ }) })] })) }));
381
+ };
382
+ const PhonesField = ({ field, props }) => {
383
+ const m = useOrganizationMessages();
384
+ return (_jsx(RepeatableContactField, { addLabel: m.organization_contact_add_phone(), emptyValue: {
385
+ number: "",
386
+ translations: [{ locale: props.locale, label: "" }],
387
+ }, error: Option.isSome(field.error) ? field.error.value : undefined, path: field.path, values: field.value, onChange: field.onChange, render: (phone, index, update) => (_jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(ContactInput, { id: `${field.path}-${index}-number`, label: m.organization_contact_phone_type(), placeholder: "+1 514 555 0100", type: "tel", value: phone.number, onBlur: field.onBlur, onChange: (number) => update({ ...phone, number }) }), _jsx(ContactInput, { id: `${field.path}-${index}-extension`, label: m.organization_contact_extension(), value: phone.extension ?? "", onBlur: field.onBlur, onChange: (extension) => update({
388
+ ...phone,
389
+ ...(extension ? { extension } : { extension: undefined }),
390
+ }) }), _jsx(ContactLabelInput, { id: `${field.path}-${index}-label`, locale: props.locale, translations: phone.translations, onBlur: field.onBlur, onChange: (translations) => update({
391
+ ...phone,
392
+ translations,
393
+ }) })] })) }));
394
+ };
395
+ function ContactInput({ className, id, label, onBlur, onChange, placeholder, type = "text", value, }) {
396
+ return (_jsxs("div", { className: className, children: [_jsx(FieldLabel, { htmlFor: id, children: label }), _jsx(Input, { id: id, className: "mt-2", value: value, type: type, placeholder: placeholder, onBlur: onBlur, onChange: (event) => onChange(event.target.value) })] }));
397
+ }
398
+ function ContactLabelInput({ id, locale, onBlur, onChange, translations, }) {
399
+ const m = useOrganizationMessages();
400
+ return (_jsx(ContactInput, { id: id, label: m.organization_contact_label(), value: contactLabel(translations, locale), onBlur: onBlur, onChange: (label) => onChange(contactTranslations(translations, locale, label)) }));
401
+ }
402
+ const WebsitesField = ({ field, props }) => {
403
+ const m = useOrganizationMessages();
404
+ return (_jsx(RepeatableContactField, { addLabel: m.organization_contact_add_website(), emptyValue: {
405
+ url: "",
406
+ translations: [{ locale: props.locale, label: "" }],
407
+ }, error: Option.isSome(field.error) ? field.error.value : undefined, path: field.path, values: field.value, onChange: field.onChange, render: (website, index, update) => (_jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(ContactInput, { id: `${field.path}-${index}-url`, label: m.organization_contact_url(), placeholder: "https://example.com", type: "url", value: website.url, onBlur: field.onBlur, onChange: (url) => update({ ...website, url }) }), _jsx(ContactLabelInput, { id: `${field.path}-${index}-label`, locale: props.locale, translations: website.translations, onBlur: field.onBlur, onChange: (translations) => update({
408
+ ...website,
409
+ translations,
410
+ }) })] })) }));
411
+ };
412
+ function RepeatableContactField({ addLabel, emptyValue, error, onChange, path, render, values, }) {
413
+ const m = useOrganizationMessages();
414
+ return (_jsx(Field, { children: _jsxs("div", { className: "flex flex-col gap-3", children: [values.map((value, index) => (_jsxs("div", { className: "bg-muted/20 relative rounded-lg border p-4 pr-12", children: [render(value, index, (next) => onChange(values.map((item, itemIndex) => itemIndex === index ? next : item))), _jsx(Button, { type: "button", variant: "ghost", size: "icon", className: "absolute top-2 right-2", "aria-label": m.organization_contact_remove(), onClick: () => onChange(values.filter((_, itemIndex) => itemIndex !== index)), children: _jsx(Trash2, {}) })] }, `${path}-${index}`))), _jsxs(Button, { type: "button", variant: "outline", size: "sm", className: "self-start", onClick: () => onChange([...values, emptyValue]), children: [_jsx(Plus, {}), addLabel] }), error ? _jsx(ErrorMessage, { text: error }) : null] }) }));
415
+ }
416
+ function SocialPlatformSelect({ value, onChange, }) {
417
+ const m = useOrganizationMessages();
418
+ const items = [
419
+ { label: "Facebook", value: "facebook" },
420
+ { label: "GitHub", value: "github" },
421
+ { label: "Instagram", value: "instagram" },
422
+ { label: "LinkedIn", value: "linkedin" },
423
+ { label: "TikTok", value: "tiktok" },
424
+ { label: "X", value: "x" },
425
+ { label: "YouTube", value: "youtube" },
426
+ ];
427
+ return (_jsxs("div", { children: [_jsx(FieldLabel, { children: m.organization_contact_platform() }), _jsxs(Select, { items: items, value: value, onValueChange: (next) => {
428
+ const platform = socialPlatform(next);
429
+ if (platform)
430
+ onChange(platform);
431
+ }, children: [_jsx(SelectTrigger, { className: "mt-2 w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: items.map((item) => (_jsx(SelectItem, { value: item.value, children: item.label }, item.value))) })] })] }));
432
+ }
433
+ const SocialsField = ({ field, props }) => {
434
+ const m = useOrganizationMessages();
435
+ return (_jsx(RepeatableContactField, { addLabel: m.organization_contact_add_social(), emptyValue: {
436
+ platform: "linkedin",
437
+ url: "",
438
+ translations: [{ locale: props.locale, label: "" }],
439
+ }, error: Option.isSome(field.error) ? field.error.value : undefined, path: field.path, values: field.value, onChange: field.onChange, render: (social, index, update) => (_jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(SocialPlatformSelect, { value: social.platform, onChange: (platform) => update({ ...social, platform }) }), _jsx(ContactInput, { id: `${field.path}-${index}-url`, label: m.organization_contact_url(), placeholder: "https://example.com/profile", type: "url", value: social.url, onBlur: field.onBlur, onChange: (url) => update({ ...social, url }) }), _jsx(ContactLabelInput, { id: `${field.path}-${index}-label`, locale: props.locale, translations: social.translations, onBlur: field.onBlur, onChange: (translations) => update({
440
+ ...social,
441
+ translations,
442
+ }) })] })) }));
443
+ };
444
+ const AddressesField = ({ field, props }) => {
445
+ const m = useOrganizationMessages();
446
+ const inputs = [
447
+ {
448
+ key: "streetAddress",
449
+ label: m.organization_address_street(),
450
+ className: "sm:col-span-2",
451
+ },
452
+ { key: "locality", label: m.organization_address_locality() },
453
+ { key: "region", label: m.organization_address_region() },
454
+ { key: "postalCode", label: m.organization_address_postal_code() },
455
+ { key: "country", label: m.organization_address_country() },
456
+ ];
457
+ return (_jsx(RepeatableContactField, { addLabel: m.organization_address_add(), emptyValue: {
458
+ translations: [{ locale: props.locale, label: "" }],
459
+ }, error: Option.isSome(field.error) ? field.error.value : undefined, path: field.path, values: field.value, onChange: field.onChange, render: (address, index, update) => (_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx(ContactLabelInput, { id: `${field.path}-${index}-label`, locale: props.locale, translations: address.translations, onBlur: field.onBlur, onChange: (translations) => update({
460
+ ...address,
461
+ translations,
462
+ }) }), inputs.map((input) => (_createElement(ContactInput, { ...(input.className ? { className: input.className } : {}), id: `${field.path}-${index}-${input.key}`, key: input.key, label: input.label, value: address[input.key] ?? "", onBlur: field.onBlur, onChange: (value) => update({ ...address, [input.key]: value }) })))] })) }));
463
+ };
464
+ const organizationFormFields = {
465
+ parentId: SelectField,
466
+ slug: TextField,
467
+ emails: EmailsField,
468
+ phones: PhonesField,
469
+ websites: WebsitesField,
470
+ socials: SocialsField,
471
+ addresses: AddressesField,
472
+ enName: TextField,
473
+ enLogo: ImageField,
474
+ enIcon: ImageField,
475
+ frName: TextField,
476
+ frLogo: ImageField,
477
+ frIcon: ImageField,
478
+ };
312
479
  const inviteMemberFormBuilder = FormBuilder.empty
313
480
  .addField("email", Schema.NonEmptyString)
314
481
  .addField("role", Schema.String);
@@ -331,7 +498,6 @@ const isOrganizationSlugConflict = (error) => {
331
498
  return normalized.includes("organization already exists");
332
499
  });
333
500
  };
334
- const nullableString = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
335
501
  const decodeUploadedAsset = Schema.decodeUnknownPromise(ExtraUploadedAsset);
336
502
  const uploadImageAsset = async (file, m, uploadImage) => {
337
503
  const payload = new FormData();
@@ -345,15 +511,7 @@ const uploadImageAsset = async (file, m, uploadImage) => {
345
511
  }
346
512
  };
347
513
  const currentOrganizationLocale = () => getLocale() === "fr" ? "fr" : "en";
348
- const parseOrganizationMetadata = (metadata) => {
349
- try {
350
- const value = typeof metadata === "string" ? JSON.parse(metadata) : metadata;
351
- return Schema.decodeUnknownSync(OrganizationMetadata)(value);
352
- }
353
- catch {
354
- return { translations: [] };
355
- }
356
- };
514
+ const parseOrganizationMetadata = decodeOrganizationMetadata;
357
515
  const findOrganizationTranslation = (organization, locale = currentOrganizationLocale()) => {
358
516
  const translations = parseOrganizationMetadata(organization.metadata).translations;
359
517
  return (translations.find((translation) => translation.locale === locale) ??
@@ -390,22 +548,39 @@ const organizationParentOptions = (organizations, m, excludedOrganizationId) =>
390
548
  })),
391
549
  ];
392
550
  const organizationFormDefaults = (organization, baseUrl) => {
393
- const translations = parseOrganizationMetadata(organization?.metadata).translations;
551
+ const metadata = parseOrganizationMetadata(organization?.metadata);
552
+ const translations = metadata.translations;
394
553
  const en = translations.find((translation) => translation.locale === "en");
395
554
  const fr = translations.find((translation) => translation.locale === "fr");
555
+ const emails = Array.from(metadata.emails ?? []);
556
+ for (const translation of translations) {
557
+ if (translation.contactEmail &&
558
+ !emails.some((email) => email.email === translation.contactEmail)) {
559
+ emails.push({
560
+ email: translation.contactEmail,
561
+ translations: [
562
+ {
563
+ locale: translation.locale,
564
+ label: translation.locale === "fr" ? "Courriel" : "Email",
565
+ },
566
+ ],
567
+ });
568
+ }
569
+ }
396
570
  return {
397
571
  parentId: organization?.parentId ?? noParentOrganization,
398
572
  slug: organization?.slug ?? "",
573
+ emails,
574
+ phones: Array.from(metadata.phones ?? []),
575
+ websites: Array.from(metadata.websites ?? []),
576
+ socials: Array.from(metadata.socials ?? []),
577
+ addresses: Array.from(metadata.addresses ?? []),
399
578
  enName: en?.name || organization?.name || "",
400
579
  enLogo: assetUrl(en?.logo, baseUrl) || null,
401
580
  enIcon: assetUrl(en?.icon, baseUrl) || null,
402
- enContactEmail: en?.contactEmail ?? "",
403
- enLocation: en?.location ?? "",
404
581
  frName: fr?.name ?? "",
405
582
  frLogo: assetUrl(fr?.logo, baseUrl) || null,
406
583
  frIcon: assetUrl(fr?.icon, baseUrl) || null,
407
- frContactEmail: fr?.contactEmail ?? "",
408
- frLocation: fr?.location ?? "",
409
584
  };
410
585
  };
411
586
  const organizationLogoFromForm = async (value, m, uploadImage) => {
@@ -449,7 +624,16 @@ const invitationStatusLabel = (status, m) => {
449
624
  }
450
625
  };
451
626
  const formatOrganizationDate = (date) => new Intl.DateTimeFormat(getLocale(), { dateStyle: "medium" }).format(new Date(date));
452
- const organizationMetadataFromForm = async (value, m, uploadImage) => {
627
+ const organizationMetadataFromForm = async (value, m, uploadImage, existingMetadata) => {
628
+ const existing = parseOrganizationMetadata(existingMetadata);
629
+ const decodedExistingMetadata = typeof existingMetadata === "string"
630
+ ? Option.getOrNull(Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown))(existingMetadata))
631
+ : existingMetadata;
632
+ const preservedMetadata = typeof decodedExistingMetadata === "object" &&
633
+ decodedExistingMetadata !== null &&
634
+ !Array.isArray(decodedExistingMetadata)
635
+ ? decodedExistingMetadata
636
+ : {};
453
637
  const translations = [];
454
638
  const enName = value.enName.trim();
455
639
  const frName = value.frName.trim();
@@ -457,14 +641,98 @@ const organizationMetadataFromForm = async (value, m, uploadImage) => {
457
641
  const enIcon = await organizationLogoFromForm(value.enIcon, m, uploadImage);
458
642
  const frLogo = await organizationLogoFromForm(value.frLogo, m, uploadImage);
459
643
  const frIcon = await organizationLogoFromForm(value.frIcon, m, uploadImage);
644
+ const localized = (values) => (values ?? []).flatMap((translation) => {
645
+ const label = translation.label.trim();
646
+ return label ? [{ ...translation, label }] : [];
647
+ });
648
+ const emails = value.emails.flatMap((email) => {
649
+ const address = email.email.trim();
650
+ return address
651
+ ? [
652
+ {
653
+ email: address,
654
+ translations: localized(email.translations),
655
+ },
656
+ ]
657
+ : [];
658
+ });
659
+ const phones = value.phones.flatMap((phone) => {
660
+ const number = phone.number.trim();
661
+ return number
662
+ ? [
663
+ {
664
+ number,
665
+ ...(phone.extension?.trim()
666
+ ? { extension: phone.extension.trim() }
667
+ : {}),
668
+ translations: localized(phone.translations),
669
+ },
670
+ ]
671
+ : [];
672
+ });
673
+ const websites = value.websites.flatMap((website) => {
674
+ const url = website.url.trim();
675
+ return url ? [{ url, translations: localized(website.translations) }] : [];
676
+ });
677
+ const socials = value.socials.flatMap((social) => {
678
+ const url = social.url.trim();
679
+ return url
680
+ ? [
681
+ {
682
+ platform: social.platform,
683
+ url,
684
+ translations: localized(social.translations),
685
+ },
686
+ ]
687
+ : [];
688
+ });
689
+ const addresses = value.addresses.flatMap((input) => {
690
+ const normalized = {
691
+ ...(input.streetAddress?.trim()
692
+ ? { streetAddress: input.streetAddress.trim() }
693
+ : {}),
694
+ ...(input.locality?.trim() ? { locality: input.locality.trim() } : {}),
695
+ ...(input.region?.trim() ? { region: input.region.trim() } : {}),
696
+ ...(input.postalCode?.trim()
697
+ ? { postalCode: input.postalCode.trim() }
698
+ : {}),
699
+ ...(input.country?.trim() ? { country: input.country.trim() } : {}),
700
+ };
701
+ return Object.keys(normalized).length
702
+ ? [
703
+ {
704
+ ...normalized,
705
+ translations: localized(input.translations),
706
+ },
707
+ ]
708
+ : [];
709
+ });
710
+ const localizedEmail = (locale) => emails.find((email) => email.translations.some((translation) => translation.locale === locale))?.email ??
711
+ emails[0]?.email ??
712
+ null;
713
+ const localizedLocation = (locale) => {
714
+ const address = addresses.find((item) => item.translations.some((translation) => translation.locale === locale)) ?? addresses[0];
715
+ if (!address) {
716
+ return existing.translations.find((translation) => translation.locale === locale)?.location;
717
+ }
718
+ return [
719
+ address.streetAddress,
720
+ [address.locality, address.region, address.postalCode]
721
+ .filter(Boolean)
722
+ .join(" "),
723
+ address.country,
724
+ ]
725
+ .filter(Boolean)
726
+ .join(", ");
727
+ };
460
728
  if (enName) {
461
729
  translations.push({
462
730
  locale: "en",
463
731
  name: enName,
464
732
  logo: enLogo,
465
733
  icon: enIcon,
466
- contactEmail: nullableString(value.enContactEmail),
467
- location: nullableString(value.enLocation),
734
+ contactEmail: localizedEmail("en"),
735
+ location: localizedLocation("en") ?? null,
468
736
  });
469
737
  }
470
738
  if (frName) {
@@ -473,13 +741,21 @@ const organizationMetadataFromForm = async (value, m, uploadImage) => {
473
741
  name: frName,
474
742
  logo: frLogo,
475
743
  icon: frIcon,
476
- contactEmail: nullableString(value.frContactEmail),
477
- location: nullableString(value.frLocation),
744
+ contactEmail: localizedEmail("fr"),
745
+ location: localizedLocation("fr") ?? null,
478
746
  });
479
747
  }
480
- return { translations };
748
+ return {
749
+ ...preservedMetadata,
750
+ translations,
751
+ emails,
752
+ phones,
753
+ websites,
754
+ socials,
755
+ addresses,
756
+ };
481
757
  };
482
- export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side = "bottom", className, defaultDialog = null, hideTrigger = false, menuActions, renderUnauthenticated, locked = false, organizationWhitelist, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
758
+ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side = "bottom", className, defaultDialog = null, features, hideTrigger = false, menuActions, renderUnauthenticated, allowedOrganizationIds, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
483
759
  const auth = useKrakstackAuth();
484
760
  const authClient = providedAuthClient ?? auth?.authClient;
485
761
  if (!authClient) {
@@ -492,6 +768,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
492
768
  const activeOrganization = authClient.useActiveOrganization();
493
769
  const lastAuthRefreshVersion = useRef(auth?.authRefreshVersion ?? 0);
494
770
  const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
771
+ const [editingOrganizationLocale, setEditingOrganizationLocale] = useState(currentOrganizationLocale);
495
772
  const dialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
496
773
  const invitationsAtom = session.data
497
774
  ? userInvitationsAtom(authClient)
@@ -512,6 +789,9 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
512
789
  const activeMemberRole = normalizeOrganizationRole(activeOrganization.data?.members.find((member) => member.userId === session.data?.user.id)?.role);
513
790
  const canManageApiKeys = activeMemberRole === "owner" || activeMemberRole === "admin";
514
791
  const canUpdateOrganization = canManageApiKeys;
792
+ const canSwitchOrganizations = features?.organizationSwitching ?? true;
793
+ const canCreateOrganization = features?.organizationCreation ?? true;
794
+ const canViewOrganizationInvitations = features?.userInvitations ?? true;
515
795
  const setDialog = (next) => {
516
796
  const nextDialog = typeof next === "function" ? next(dialog) : next;
517
797
  if (nextDialog === dialog)
@@ -541,16 +821,18 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
541
821
  }
542
822
  const active = activeOrganization.data;
543
823
  const activeName = active?.name;
544
- const visibleOrganizations = organizations.data?.filter((organization) => !organizationWhitelist ||
545
- organizationWhitelist.includes(organization.id)) ?? [];
546
- const selectableOrganizations = !locked
824
+ const visibleOrganizations = organizations.data?.filter((organization) => !allowedOrganizationIds ||
825
+ allowedOrganizationIds.includes(organization.id)) ?? [];
826
+ const selectableOrganizations = canSwitchOrganizations
547
827
  ? visibleOrganizations.filter((organization) => organization.id !== active?.id)
548
828
  : [];
549
- const hasOrganizationListItems = organizations.isPending || Boolean(organizations.error) || !locked;
829
+ const hasOrganizationListItems = organizations.isPending ||
830
+ Boolean(organizations.error) ||
831
+ canSwitchOrganizations;
550
832
  const refreshAfterInvitationAction = async (previousActiveId) => {
551
833
  refreshUserInvitations();
552
834
  await refresh();
553
- if (locked && previousActiveId) {
835
+ if (!canSwitchOrganizations && previousActiveId) {
554
836
  const result = await authClient.organization.setActive({
555
837
  organizationId: previousActiveId,
556
838
  });
@@ -568,7 +850,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
568
850
  ? { imageSrc: activeDisplay.image }
569
851
  : {}) }), _jsx(ChevronsUpDown, { className: "text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden" })] }) }), _jsx(DropdownMenuContent, { className: "min-w-64 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: activeDisplay.name, subtitle: activeSubtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.image
570
852
  ? { imageSrc: activeDisplay.image }
571
- : {}) }) }), menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizations.error ? (_jsx(DropdownMenuItem, { disabled: true, children: organizations.error.message })) : null, !locked && selectableOrganizations.length ? (selectableOrganizations.map((organization) => {
853
+ : {}) }) }), menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizations.error ? (_jsx(DropdownMenuItem, { disabled: true, children: organizations.error.message })) : null, canSwitchOrganizations && selectableOrganizations.length ? (selectableOrganizations.map((organization) => {
572
854
  const display = organizationDisplay(organization, m, baseUrl);
573
855
  return (_jsx(DropdownMenuItem, { onClick: async () => {
574
856
  const result = await authClient.organization.setActive({
@@ -579,18 +861,18 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
579
861
  onChange?.(organization);
580
862
  }
581
863
  }, children: _jsx(AppBrand, { to: null, label: display.name, subtitle: organizationSwitcherSubtitle(organization, display.subtitle, m), icon: Building2, className: "w-full text-left [&>div:first-child]:size-7", ...(display.image ? { imageSrc: display.image } : {}) }) }, organization.id));
582
- })) : !locked && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
864
+ })) : canSwitchOrganizations && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
583
865
  ? m.organization_switcher_no_other_organizations()
584
- : m.organization_switcher_empty() })) : null, !locked ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: openCreate, children: [_jsx(Plus, {}), m.organization_create_title()] }), _jsxs(DropdownMenuItem, { onClick: () => {
866
+ : m.organization_switcher_empty() })) : null, canCreateOrganization || canViewOrganizationInvitations ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), canCreateOrganization ? (_jsxs(DropdownMenuItem, { onClick: openCreate, children: [_jsx(Plus, {}), m.organization_create_title()] })) : null, canViewOrganizationInvitations ? (_jsxs(DropdownMenuItem, { onClick: () => {
585
867
  setDialog("invitations");
586
- }, children: [_jsx(Mail, {}), _jsxs("span", { className: "flex flex-1 items-center justify-between gap-3", children: [m.organization_user_invitations_title(), userInvitations.length ? (_jsx(Badge, { variant: "secondary", children: userInvitations.length })) : null] })] })] })) : null, activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), (() => {
868
+ }, children: [_jsx(Mail, {}), _jsxs("span", { className: "flex flex-1 items-center justify-between gap-3", children: [m.organization_user_invitations_title(), userInvitations.length ? (_jsx(Badge, { variant: "secondary", className: "bg-secondary! text-secondary-foreground!", children: userInvitations.length })) : null] })] })) : null] })) : null, activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), (() => {
587
869
  const organizationId = activeOrganization.data.id;
588
870
  return (_jsxs(DropdownMenuItem, { onClick: () => {
589
871
  void navigator.clipboard.writeText(organizationId);
590
872
  }, children: [_jsx(Copy, {}), m.organization_copy_id()] }));
591
- })(), canUpdateOrganization ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null] })) : null] }) })] })), _jsx(Dialog, { open: dialog === "create", onOpenChange: (open) => {
873
+ })(), canUpdateOrganization ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null] })) : null] }) })] })), _jsx(Dialog, { open: dialog === "create" && canCreateOrganization, onOpenChange: (open) => {
592
874
  setDialog((current) => open ? "create" : current === "create" ? null : current);
593
- }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { authClient: authClient, baseUrl: baseUrl, organizations: visibleOrganizations, onCreated: async (organization) => {
875
+ }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-2xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() }), _jsx("div", { className: "pt-2", children: _jsx(EditingLocaleSwitcher, { value: editingOrganizationLocale, onValueChange: setEditingOrganizationLocale }) })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { authClient: authClient, baseUrl: baseUrl, editingLocale: editingOrganizationLocale, organizations: visibleOrganizations, onCreated: async (organization) => {
594
876
  setDialog(null);
595
877
  const activeResult = await authClient.organization.setActive({
596
878
  organizationId: organization.id,
@@ -602,7 +884,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
602
884
  }
603
885
  } })] }) }), _jsx(Dialog, { open: dialog === "manage" && canUpdateOrganization, onOpenChange: (open) => {
604
886
  setDialog((current) => open ? "manage" : current === "manage" ? null : current);
605
- }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx(Separator, {}), activeOrganization.data && canUpdateOrganization ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
887
+ }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-2xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() }), _jsx("div", { className: "pt-2", children: _jsx(EditingLocaleSwitcher, { value: editingOrganizationLocale, onValueChange: setEditingOrganizationLocale }) })] }), _jsx(Separator, {}), activeOrganization.data && canUpdateOrganization ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, editingLocale: editingOrganizationLocale, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
606
888
  setDialog((current) => open ? "members" : current === "members" ? null : current);
607
889
  }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, canManageMembers: canManageApiKeys, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members", onLeft: async () => {
608
890
  setDialog(null);
@@ -611,7 +893,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
611
893
  onChange?.(null);
612
894
  } })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
613
895
  setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
614
- }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations" && !locked, onOpenChange: (open) => {
896
+ }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations" && canViewOrganizationInvitations, onOpenChange: (open) => {
615
897
  setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
616
898
  }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, baseUrl: baseUrl, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization.data
617
899
  ? { activeOrganizationId: activeOrganization.data.id }
@@ -696,8 +978,10 @@ const userInvitationColumns = ({ baseUrl, m, now, }) => [
696
978
  },
697
979
  ];
698
980
  function InvitationOrganizationBrand({ baseUrl, invitation, }) {
981
+ const locale = useKrakstackAuth()?.locale ?? currentOrganizationLocale();
699
982
  const profileResult = useAtomValue(invitationOrganizationProfileAtom({
700
983
  baseUrl,
984
+ locale,
701
985
  organizationId: invitation.organizationId,
702
986
  }));
703
987
  const profile = AsyncResult.match(profileResult, {
@@ -726,34 +1010,20 @@ const userInvitationRowActions = ({ m, actingInvitationId, now, onAccept, onReje
726
1010
  onClick: onReject,
727
1011
  },
728
1012
  ];
729
- function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated, }) {
1013
+ function EditOrganizationSection({ authClient, baseUrl, editingLocale, organization, onUpdated, }) {
730
1014
  const m = useOrganizationMessages();
731
1015
  const uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
732
1016
  const [defaultLocale] = useState(currentOrganizationLocale);
733
- const [editingLocale, setEditingLocale] = useState(defaultLocale);
734
1017
  const defaultValues = organizationFormDefaults(organization, baseUrl);
735
1018
  const [form] = useState(() => FormReact.make(organizationFormBuilder, {
736
- fields: {
737
- parentId: SelectField,
738
- slug: TextField,
739
- enName: TextField,
740
- enLogo: ImageField,
741
- enIcon: ImageField,
742
- enContactEmail: TextField,
743
- enLocation: TextField,
744
- frName: TextField,
745
- frLogo: ImageField,
746
- frIcon: ImageField,
747
- frContactEmail: TextField,
748
- frLocation: TextField,
749
- },
1019
+ fields: organizationFormFields,
750
1020
  onSubmit: (_, { decoded: value }) => Effect.tryPromise({
751
1021
  try: async () => {
752
1022
  const name = organizationNameFromForm(value, defaultLocale);
753
1023
  if (!name)
754
1024
  throw new Error(m.organization_name_required());
755
1025
  const slug = value.slug.trim().toLowerCase();
756
- const metadata = await organizationMetadataFromForm(value, m, uploadImage);
1026
+ const metadata = await organizationMetadataFromForm(value, m, uploadImage, organization.metadata);
757
1027
  const result = await authClient.organization.update({
758
1028
  organizationId: organization.id,
759
1029
  data: { name, slug, metadata },
@@ -771,53 +1041,39 @@ function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated,
771
1041
  }));
772
1042
  const submit = useAtomSet(form.submit);
773
1043
  const submitResult = useAtomValue(form.submit);
774
- return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.Initialize, { defaultValues: defaultValues, children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
1044
+ return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.Initialize, { defaultValues: defaultValues, children: _jsxs("form", { className: "flex w-full flex-col gap-4", onSubmit: (event) => {
775
1045
  event.preventDefault();
776
1046
  event.stopPropagation();
777
1047
  submit();
778
- }, children: [_jsx(form.slug, { label: m.organization_slug(), required: true }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationTranslationHeader, { locale: editingLocale, editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsxs(FieldSet, { disabled: editingLocale !== "en", className: editingLocale === "en" ? "contents" : "hidden", children: [_jsx(form.enName, { label: m.organization_translation_name() }), _jsx(form.enLogo, { label: m.organization_logo(), size: {
779
- width: 175,
780
- height: 50,
781
- suggestedWidth: 350,
782
- suggestedHeight: 100,
783
- } }), _jsx(form.enIcon, { label: m.organization_icon(), size: {
784
- width: 96,
785
- height: 96,
786
- suggestedWidth: 512,
787
- suggestedHeight: 512,
788
- } }), _jsx(form.enContactEmail, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" }), _jsx(form.enLocation, { label: m.organization_location() })] }), _jsxs(FieldSet, { disabled: editingLocale !== "fr", className: editingLocale === "fr" ? "contents" : "hidden", children: [_jsx(form.frName, { label: m.organization_translation_name() }), _jsx(form.frLogo, { label: m.organization_logo(), size: {
789
- width: 175,
790
- height: 50,
791
- suggestedWidth: 350,
792
- suggestedHeight: 100,
793
- } }), _jsx(form.frIcon, { label: m.organization_icon(), size: {
794
- width: 96,
795
- height: 96,
796
- suggestedWidth: 512,
797
- suggestedHeight: 512,
798
- } }), _jsx(form.frContactEmail, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" }), _jsx(form.frLocation, { label: m.organization_location() })] }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
1048
+ }, children: [_jsx(form.slug, { label: m.organization_slug(), required: true }), _jsx(Separator, { className: "my-2" }), _jsxs(OrganizationFormSection, { title: m.organization_profile(), description: m.organization_translation_description(), children: [_jsxs(FieldSet, { disabled: editingLocale !== "en", className: editingLocale === "en" ? "contents" : "hidden", children: [_jsx(form.enName, { label: m.organization_translation_name() }), _jsx(form.enLogo, { label: m.organization_logo(), size: {
1049
+ width: 175,
1050
+ height: 50,
1051
+ suggestedWidth: 350,
1052
+ suggestedHeight: 100,
1053
+ } }), _jsx(form.enIcon, { label: m.organization_icon(), size: {
1054
+ width: 96,
1055
+ height: 96,
1056
+ suggestedWidth: 512,
1057
+ suggestedHeight: 512,
1058
+ } })] }), _jsxs(FieldSet, { disabled: editingLocale !== "fr", className: editingLocale === "fr" ? "contents" : "hidden", children: [_jsx(form.frName, { label: m.organization_translation_name() }), _jsx(form.frLogo, { label: m.organization_logo(), size: {
1059
+ width: 175,
1060
+ height: 50,
1061
+ suggestedWidth: 350,
1062
+ suggestedHeight: 100,
1063
+ } }), _jsx(form.frIcon, { label: m.organization_icon(), size: {
1064
+ width: 96,
1065
+ height: 96,
1066
+ suggestedWidth: 512,
1067
+ suggestedHeight: 512,
1068
+ } })] })] }), _jsx(Separator, { className: "my-2" }), _jsxs(OrganizationFormSection, { title: m.organization_contact(), children: [_jsx(OrganizationContactGroup, { title: m.organization_contact_email_type(), children: _jsx(form.emails, { locale: editingLocale }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale }) })] }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationFormSection, { title: m.organization_address(), children: _jsx(form.addresses, { locale: editingLocale }) }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
799
1069
  }
800
- function CreateOrganizationSection({ authClient, baseUrl, organizations, onCreated, }) {
1070
+ function CreateOrganizationSection({ authClient, baseUrl, editingLocale, organizations, onCreated, }) {
801
1071
  const m = useOrganizationMessages();
802
1072
  const uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
803
1073
  const [defaultLocale] = useState(currentOrganizationLocale);
804
- const [editingLocale, setEditingLocale] = useState(defaultLocale);
805
1074
  const defaultValues = organizationFormDefaults(undefined, baseUrl);
806
1075
  const [form] = useState(() => FormReact.make(organizationFormBuilder, {
807
- fields: {
808
- parentId: SelectField,
809
- slug: TextField,
810
- enName: TextField,
811
- enLogo: ImageField,
812
- enIcon: ImageField,
813
- enContactEmail: TextField,
814
- enLocation: TextField,
815
- frName: TextField,
816
- frLogo: ImageField,
817
- frIcon: ImageField,
818
- frContactEmail: TextField,
819
- frLocation: TextField,
820
- },
1076
+ fields: organizationFormFields,
821
1077
  onSubmit: (_, { decoded: value }) => Effect.tryPromise({
822
1078
  try: async () => {
823
1079
  const name = organizationNameFromForm(value, defaultLocale);
@@ -865,38 +1121,37 @@ function CreateOrganizationSection({ authClient, baseUrl, organizations, onCreat
865
1121
  lastGeneratedSlug.current = generatedSlug;
866
1122
  setSlug(generatedSlug);
867
1123
  }, [defaultLocale, setSlug, values]);
868
- return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.Initialize, { defaultValues: defaultValues, children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
1124
+ return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.Initialize, { defaultValues: defaultValues, children: _jsxs("form", { className: "flex w-full flex-col gap-4", onSubmit: (event) => {
869
1125
  event.preventDefault();
870
1126
  event.stopPropagation();
871
1127
  submit();
872
- }, children: [_jsx(form.slug, { label: m.organization_slug(), description: m.organization_slug_description() }), _jsx(form.parentId, { label: m.organization_parent(), description: m.organization_parent_description(), options: organizationParentOptions(organizations, m) }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationTranslationHeader, { locale: editingLocale, editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsxs(FieldSet, { disabled: editingLocale !== "en", className: editingLocale === "en" ? "contents" : "hidden", children: [_jsx(form.enName, { label: m.organization_translation_name() }), _jsx(form.enLogo, { label: m.organization_logo(), size: {
873
- width: 175,
874
- height: 50,
875
- suggestedWidth: 350,
876
- suggestedHeight: 100,
877
- } }), _jsx(form.enIcon, { label: m.organization_icon(), size: {
878
- width: 96,
879
- height: 96,
880
- suggestedWidth: 512,
881
- suggestedHeight: 512,
882
- } }), _jsx(form.enContactEmail, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" }), _jsx(form.enLocation, { label: m.organization_location() })] }), _jsxs(FieldSet, { disabled: editingLocale !== "fr", className: editingLocale === "fr" ? "contents" : "hidden", children: [_jsx(form.frName, { label: m.organization_translation_name() }), _jsx(form.frLogo, { label: m.organization_logo(), size: {
883
- width: 175,
884
- height: 50,
885
- suggestedWidth: 350,
886
- suggestedHeight: 100,
887
- } }), _jsx(form.frIcon, { label: m.organization_icon(), size: {
888
- width: 96,
889
- height: 96,
890
- suggestedWidth: 512,
891
- suggestedHeight: 512,
892
- } }), _jsx(form.frContactEmail, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" }), _jsx(form.frLocation, { label: m.organization_location() })] }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
1128
+ }, children: [_jsx(form.slug, { label: m.organization_slug(), description: m.organization_slug_description() }), _jsx(form.parentId, { label: m.organization_parent(), description: m.organization_parent_description(), options: organizationParentOptions(organizations, m) }), _jsx(Separator, { className: "my-2" }), _jsxs(OrganizationFormSection, { title: m.organization_profile(), description: m.organization_translation_description(), children: [_jsxs(FieldSet, { disabled: editingLocale !== "en", className: editingLocale === "en" ? "contents" : "hidden", children: [_jsx(form.enName, { label: m.organization_translation_name() }), _jsx(form.enLogo, { label: m.organization_logo(), size: {
1129
+ width: 175,
1130
+ height: 50,
1131
+ suggestedWidth: 350,
1132
+ suggestedHeight: 100,
1133
+ } }), _jsx(form.enIcon, { label: m.organization_icon(), size: {
1134
+ width: 96,
1135
+ height: 96,
1136
+ suggestedWidth: 512,
1137
+ suggestedHeight: 512,
1138
+ } })] }), _jsxs(FieldSet, { disabled: editingLocale !== "fr", className: editingLocale === "fr" ? "contents" : "hidden", children: [_jsx(form.frName, { label: m.organization_translation_name() }), _jsx(form.frLogo, { label: m.organization_logo(), size: {
1139
+ width: 175,
1140
+ height: 50,
1141
+ suggestedWidth: 350,
1142
+ suggestedHeight: 100,
1143
+ } }), _jsx(form.frIcon, { label: m.organization_icon(), size: {
1144
+ width: 96,
1145
+ height: 96,
1146
+ suggestedWidth: 512,
1147
+ suggestedHeight: 512,
1148
+ } })] })] }), _jsx(Separator, { className: "my-2" }), _jsxs(OrganizationFormSection, { title: m.organization_contact(), children: [_jsx(OrganizationContactGroup, { title: m.organization_contact_email_type(), children: _jsx(form.emails, { locale: editingLocale }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale }) })] }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationFormSection, { title: m.organization_address(), children: _jsx(form.addresses, { locale: editingLocale }) }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
893
1149
  }
894
- function OrganizationTranslationHeader({ locale, editingLocale, onEditingLocaleChange, }) {
895
- const m = useOrganizationMessages();
896
- const title = locale === "en"
897
- ? m.organization_translation_english()
898
- : m.organization_translation_french();
899
- return (_jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: title }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_translation_description() })] }), _jsx(EditingLocaleSwitcher, { value: editingLocale, onValueChange: onEditingLocaleChange })] }));
1150
+ function OrganizationFormSection({ children, description, title, }) {
1151
+ return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: title }), description ? (_jsx("p", { className: "text-muted-foreground text-sm", children: description })) : null] }), children] }));
1152
+ }
1153
+ function OrganizationContactGroup({ children, title, }) {
1154
+ return (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsx("h4", { className: "text-sm font-medium", children: title }), children] }));
900
1155
  }
901
1156
  function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, organization, currentUserId, active, onLeft, }) {
902
1157
  const m = useOrganizationMessages();