@krak-stack/auth 0.1.54 → 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.
- package/dist/api.d.ts +215 -6
- package/dist/components/auth-client-api.d.ts +43 -0
- package/dist/components/member-required.js +21 -7
- package/dist/components/organization-switcher.d.ts +46 -10
- package/dist/components/organization-switcher.js +377 -127
- package/dist/extra/api.group.d.ts +43 -0
- package/dist/extra/schema.d.ts +43 -0
- package/dist/extra/schema.js +13 -1
- package/dist/schema.d.ts +165 -2
- package/dist/schema.js +203 -9
- package/dist/server/api.group.d.ts +129 -6
- package/dist/server/schema.d.ts +86 -4
- package/dist/service.d.ts +368 -36
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
-
|
|
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: "
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
311
|
-
|
|
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 =
|
|
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
|
|
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:
|
|
467
|
-
location:
|
|
734
|
+
contactEmail: localizedEmail("en"),
|
|
735
|
+
location: localizedLocation("en") ?? null,
|
|
468
736
|
});
|
|
469
737
|
}
|
|
470
738
|
if (frName) {
|
|
@@ -473,11 +741,19 @@ const organizationMetadataFromForm = async (value, m, uploadImage) => {
|
|
|
473
741
|
name: frName,
|
|
474
742
|
logo: frLogo,
|
|
475
743
|
icon: frIcon,
|
|
476
|
-
contactEmail:
|
|
477
|
-
location:
|
|
744
|
+
contactEmail: localizedEmail("fr"),
|
|
745
|
+
location: localizedLocation("fr") ?? null,
|
|
478
746
|
});
|
|
479
747
|
}
|
|
480
|
-
return {
|
|
748
|
+
return {
|
|
749
|
+
...preservedMetadata,
|
|
750
|
+
translations,
|
|
751
|
+
emails,
|
|
752
|
+
phones,
|
|
753
|
+
websites,
|
|
754
|
+
socials,
|
|
755
|
+
addresses,
|
|
756
|
+
};
|
|
481
757
|
};
|
|
482
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();
|
|
@@ -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)
|
|
@@ -595,7 +872,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
595
872
|
}, children: [_jsx(Copy, {}), m.organization_copy_id()] }));
|
|
596
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) => {
|
|
597
874
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
598
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-
|
|
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) => {
|
|
599
876
|
setDialog(null);
|
|
600
877
|
const activeResult = await authClient.organization.setActive({
|
|
601
878
|
organizationId: organization.id,
|
|
@@ -607,7 +884,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
607
884
|
}
|
|
608
885
|
} })] }) }), _jsx(Dialog, { open: dialog === "manage" && canUpdateOrganization, onOpenChange: (open) => {
|
|
609
886
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
610
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-
|
|
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) => {
|
|
611
888
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
612
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 () => {
|
|
613
890
|
setDialog(null);
|
|
@@ -701,8 +978,10 @@ const userInvitationColumns = ({ baseUrl, m, now, }) => [
|
|
|
701
978
|
},
|
|
702
979
|
];
|
|
703
980
|
function InvitationOrganizationBrand({ baseUrl, invitation, }) {
|
|
981
|
+
const locale = useKrakstackAuth()?.locale ?? currentOrganizationLocale();
|
|
704
982
|
const profileResult = useAtomValue(invitationOrganizationProfileAtom({
|
|
705
983
|
baseUrl,
|
|
984
|
+
locale,
|
|
706
985
|
organizationId: invitation.organizationId,
|
|
707
986
|
}));
|
|
708
987
|
const profile = AsyncResult.match(profileResult, {
|
|
@@ -731,34 +1010,20 @@ const userInvitationRowActions = ({ m, actingInvitationId, now, onAccept, onReje
|
|
|
731
1010
|
onClick: onReject,
|
|
732
1011
|
},
|
|
733
1012
|
];
|
|
734
|
-
function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated, }) {
|
|
1013
|
+
function EditOrganizationSection({ authClient, baseUrl, editingLocale, organization, onUpdated, }) {
|
|
735
1014
|
const m = useOrganizationMessages();
|
|
736
1015
|
const uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
|
|
737
1016
|
const [defaultLocale] = useState(currentOrganizationLocale);
|
|
738
|
-
const [editingLocale, setEditingLocale] = useState(defaultLocale);
|
|
739
1017
|
const defaultValues = organizationFormDefaults(organization, baseUrl);
|
|
740
1018
|
const [form] = useState(() => FormReact.make(organizationFormBuilder, {
|
|
741
|
-
fields:
|
|
742
|
-
parentId: SelectField,
|
|
743
|
-
slug: TextField,
|
|
744
|
-
enName: TextField,
|
|
745
|
-
enLogo: ImageField,
|
|
746
|
-
enIcon: ImageField,
|
|
747
|
-
enContactEmail: TextField,
|
|
748
|
-
enLocation: TextField,
|
|
749
|
-
frName: TextField,
|
|
750
|
-
frLogo: ImageField,
|
|
751
|
-
frIcon: ImageField,
|
|
752
|
-
frContactEmail: TextField,
|
|
753
|
-
frLocation: TextField,
|
|
754
|
-
},
|
|
1019
|
+
fields: organizationFormFields,
|
|
755
1020
|
onSubmit: (_, { decoded: value }) => Effect.tryPromise({
|
|
756
1021
|
try: async () => {
|
|
757
1022
|
const name = organizationNameFromForm(value, defaultLocale);
|
|
758
1023
|
if (!name)
|
|
759
1024
|
throw new Error(m.organization_name_required());
|
|
760
1025
|
const slug = value.slug.trim().toLowerCase();
|
|
761
|
-
const metadata = await organizationMetadataFromForm(value, m, uploadImage);
|
|
1026
|
+
const metadata = await organizationMetadataFromForm(value, m, uploadImage, organization.metadata);
|
|
762
1027
|
const result = await authClient.organization.update({
|
|
763
1028
|
organizationId: organization.id,
|
|
764
1029
|
data: { name, slug, metadata },
|
|
@@ -776,53 +1041,39 @@ function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated,
|
|
|
776
1041
|
}));
|
|
777
1042
|
const submit = useAtomSet(form.submit);
|
|
778
1043
|
const submitResult = useAtomValue(form.submit);
|
|
779
|
-
return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.Initialize, { defaultValues: defaultValues, children: _jsxs("form", { className: "flex
|
|
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) => {
|
|
780
1045
|
event.preventDefault();
|
|
781
1046
|
event.stopPropagation();
|
|
782
1047
|
submit();
|
|
783
|
-
}, children: [_jsx(form.slug, { label: m.organization_slug(), required: true }), _jsx(Separator, { className: "my-2" }),
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
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 })] }) }) }));
|
|
804
1069
|
}
|
|
805
|
-
function CreateOrganizationSection({ authClient, baseUrl, organizations, onCreated, }) {
|
|
1070
|
+
function CreateOrganizationSection({ authClient, baseUrl, editingLocale, organizations, onCreated, }) {
|
|
806
1071
|
const m = useOrganizationMessages();
|
|
807
1072
|
const uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
|
|
808
1073
|
const [defaultLocale] = useState(currentOrganizationLocale);
|
|
809
|
-
const [editingLocale, setEditingLocale] = useState(defaultLocale);
|
|
810
1074
|
const defaultValues = organizationFormDefaults(undefined, baseUrl);
|
|
811
1075
|
const [form] = useState(() => FormReact.make(organizationFormBuilder, {
|
|
812
|
-
fields:
|
|
813
|
-
parentId: SelectField,
|
|
814
|
-
slug: TextField,
|
|
815
|
-
enName: TextField,
|
|
816
|
-
enLogo: ImageField,
|
|
817
|
-
enIcon: ImageField,
|
|
818
|
-
enContactEmail: TextField,
|
|
819
|
-
enLocation: TextField,
|
|
820
|
-
frName: TextField,
|
|
821
|
-
frLogo: ImageField,
|
|
822
|
-
frIcon: ImageField,
|
|
823
|
-
frContactEmail: TextField,
|
|
824
|
-
frLocation: TextField,
|
|
825
|
-
},
|
|
1076
|
+
fields: organizationFormFields,
|
|
826
1077
|
onSubmit: (_, { decoded: value }) => Effect.tryPromise({
|
|
827
1078
|
try: async () => {
|
|
828
1079
|
const name = organizationNameFromForm(value, defaultLocale);
|
|
@@ -870,38 +1121,37 @@ function CreateOrganizationSection({ authClient, baseUrl, organizations, onCreat
|
|
|
870
1121
|
lastGeneratedSlug.current = generatedSlug;
|
|
871
1122
|
setSlug(generatedSlug);
|
|
872
1123
|
}, [defaultLocale, setSlug, values]);
|
|
873
|
-
return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.Initialize, { defaultValues: defaultValues, children: _jsxs("form", { className: "flex
|
|
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) => {
|
|
874
1125
|
event.preventDefault();
|
|
875
1126
|
event.stopPropagation();
|
|
876
1127
|
submit();
|
|
877
|
-
}, 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" }),
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
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 })] }) }) }));
|
|
898
1149
|
}
|
|
899
|
-
function
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
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] }));
|
|
905
1155
|
}
|
|
906
1156
|
function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, organization, currentUserId, active, onLeft, }) {
|
|
907
1157
|
const m = useOrganizationMessages();
|