@krak-stack/auth 0.2.1 → 0.2.2
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 +1314 -70
- package/dist/auth/api.group.d.ts +578 -20
- package/dist/auth/schema.d.ts +489 -30
- package/dist/auth/schema.js +14 -1
- package/dist/components/auth-atoms.d.ts +130 -20
- package/dist/components/auth-client-api.d.ts +578 -20
- package/dist/components/contact-fields.d.ts +40 -0
- package/dist/components/contact-fields.js +86 -0
- package/dist/components/organization-switcher.js +30 -125
- package/dist/components/user-button.d.ts +73 -0
- package/dist/components/user-button.js +148 -3
- package/dist/schema.d.ts +279 -12
- package/dist/schema.js +162 -42
- package/dist/server/api.group.d.ts +128 -0
- package/dist/server/schema.d.ts +64 -0
- package/dist/service.d.ts +1412 -40
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FormReact } from "@lucas-barake/effect-form-react";
|
|
2
|
+
import type { ContactEmail, ContactLocale, ContactPhone, ContactSocial, ContactTranslation, ContactWebsite, OrganizationAddress } from "@krak-stack/auth/schema";
|
|
3
|
+
export type ContactFieldMessages = {
|
|
4
|
+
addEmail: string;
|
|
5
|
+
addPhone: string;
|
|
6
|
+
addSocial: string;
|
|
7
|
+
addWebsite: string;
|
|
8
|
+
email: string;
|
|
9
|
+
extension: string;
|
|
10
|
+
label: string;
|
|
11
|
+
phone: string;
|
|
12
|
+
platform: string;
|
|
13
|
+
remove: string;
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
16
|
+
export type ContactAddressFieldMessages = ContactFieldMessages & {
|
|
17
|
+
addAddress: string;
|
|
18
|
+
country: string;
|
|
19
|
+
locality: string;
|
|
20
|
+
postalCode: string;
|
|
21
|
+
region: string;
|
|
22
|
+
street: string;
|
|
23
|
+
};
|
|
24
|
+
type ContactFieldProps = {
|
|
25
|
+
locale: ContactLocale;
|
|
26
|
+
maxItems?: number;
|
|
27
|
+
messages: ContactFieldMessages;
|
|
28
|
+
};
|
|
29
|
+
type ContactAddressFieldProps = {
|
|
30
|
+
locale: ContactLocale;
|
|
31
|
+
messages: ContactAddressFieldMessages;
|
|
32
|
+
};
|
|
33
|
+
export declare const contactTranslations: (translations: ReadonlyArray<ContactTranslation> | undefined, locale: ContactLocale, label: string) => ContactTranslation[];
|
|
34
|
+
export declare const contactLimitReached: (valueCount: number, maxItems?: number) => boolean;
|
|
35
|
+
export declare const ContactEmailsField: FormReact.FieldComponent<ReadonlyArray<ContactEmail>, ContactFieldProps>;
|
|
36
|
+
export declare const ContactPhonesField: FormReact.FieldComponent<ReadonlyArray<ContactPhone>, ContactFieldProps>;
|
|
37
|
+
export declare const ContactWebsitesField: FormReact.FieldComponent<ReadonlyArray<ContactWebsite>, ContactFieldProps>;
|
|
38
|
+
export declare const ContactSocialsField: FormReact.FieldComponent<ReadonlyArray<ContactSocial>, ContactFieldProps>;
|
|
39
|
+
export declare const ContactAddressesField: FormReact.FieldComponent<ReadonlyArray<OrganizationAddress>, ContactAddressFieldProps>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FormReact } from "@lucas-barake/effect-form-react";
|
|
4
|
+
import { Option } from "effect";
|
|
5
|
+
import { Plus, Trash2 } from "lucide-react";
|
|
6
|
+
import { ErrorMessage } from "@krak-stack/registry/effect-form";
|
|
7
|
+
import { Button } from "@/components/ui/button";
|
|
8
|
+
import { Field, FieldLabel } from "@/components/ui/field";
|
|
9
|
+
import { Input } from "@/components/ui/input";
|
|
10
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
|
|
11
|
+
const socialPlatform = (value) => {
|
|
12
|
+
switch (value) {
|
|
13
|
+
case "facebook":
|
|
14
|
+
case "github":
|
|
15
|
+
case "instagram":
|
|
16
|
+
case "linkedin":
|
|
17
|
+
case "tiktok":
|
|
18
|
+
case "x":
|
|
19
|
+
case "youtube":
|
|
20
|
+
return value;
|
|
21
|
+
default:
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const contactLabel = (translations, locale) => translations?.find((translation) => translation.locale === locale)?.label ??
|
|
26
|
+
"";
|
|
27
|
+
export const contactTranslations = (translations, locale, label) => [
|
|
28
|
+
...(translations ?? []).filter((translation) => translation.locale !== locale && Boolean(translation.label.trim())),
|
|
29
|
+
...(label.trim() ? [{ locale, label }] : []),
|
|
30
|
+
];
|
|
31
|
+
export const contactLimitReached = (valueCount, maxItems) => maxItems !== undefined && valueCount >= maxItems;
|
|
32
|
+
const ContactInput = ({ className, id, label, onBlur, onChange, placeholder, type = "text", value, }) => (_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) })] }));
|
|
33
|
+
const ContactLabelInput = ({ id, locale, messages, onBlur, onChange, translations, }) => (_jsx(ContactInput, { id: id, label: messages.label, value: contactLabel(translations, locale), onBlur: onBlur, onChange: (label) => onChange(contactTranslations(translations, locale, label)) }));
|
|
34
|
+
const RepeatableContactField = ({ addLabel, emptyValue, error, maxItems, onChange, path, removeLabel, render, values, }) => (_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": removeLabel, onClick: () => onChange(values.filter((_, itemIndex) => itemIndex !== index)), children: _jsx(Trash2, {}) })] }, `${path}-${index}`))), _jsxs(Button, { type: "button", variant: "outline", size: "sm", className: "self-start", "aria-label": addLabel, disabled: contactLimitReached(values.length, maxItems), onClick: () => onChange([...values, emptyValue]), children: [_jsx(Plus, {}), addLabel] }), error ? _jsx(ErrorMessage, { text: error }) : null] }) }));
|
|
35
|
+
const SocialPlatformSelect = ({ messages, value, onChange, }) => {
|
|
36
|
+
const items = [
|
|
37
|
+
{ label: "Facebook", value: "facebook" },
|
|
38
|
+
{ label: "GitHub", value: "github" },
|
|
39
|
+
{ label: "Instagram", value: "instagram" },
|
|
40
|
+
{ label: "LinkedIn", value: "linkedin" },
|
|
41
|
+
{ label: "TikTok", value: "tiktok" },
|
|
42
|
+
{ label: "X", value: "x" },
|
|
43
|
+
{ label: "YouTube", value: "youtube" },
|
|
44
|
+
];
|
|
45
|
+
return (_jsxs("div", { children: [_jsx(FieldLabel, { children: messages.platform }), _jsxs(Select, { items: items, value: value, onValueChange: (next) => {
|
|
46
|
+
const platform = socialPlatform(next);
|
|
47
|
+
if (platform)
|
|
48
|
+
onChange(platform);
|
|
49
|
+
}, 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))) })] })] }));
|
|
50
|
+
};
|
|
51
|
+
export const ContactEmailsField = ({ field, props }) => (_jsx(RepeatableContactField, { addLabel: props.messages.addEmail, emptyValue: {
|
|
52
|
+
email: "",
|
|
53
|
+
translations: [{ locale: props.locale, label: "" }],
|
|
54
|
+
}, error: Option.isSome(field.error) ? field.error.value : undefined, maxItems: props.maxItems, path: field.path, removeLabel: props.messages.remove, 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: props.messages.email, 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, messages: props.messages, translations: contact.translations, onBlur: field.onBlur, onChange: (translations) => update({ ...contact, translations }) })] })) }));
|
|
55
|
+
export const ContactPhonesField = ({ field, props }) => (_jsx(RepeatableContactField, { addLabel: props.messages.addPhone, emptyValue: {
|
|
56
|
+
number: "",
|
|
57
|
+
translations: [{ locale: props.locale, label: "" }],
|
|
58
|
+
}, error: Option.isSome(field.error) ? field.error.value : undefined, maxItems: props.maxItems, path: field.path, removeLabel: props.messages.remove, 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: props.messages.phone, 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: props.messages.extension, value: phone.extension ?? "", onBlur: field.onBlur, onChange: (extension) => update({
|
|
59
|
+
...phone,
|
|
60
|
+
...(extension ? { extension } : { extension: undefined }),
|
|
61
|
+
}) }), _jsx(ContactLabelInput, { id: `${field.path}-${index}-label`, locale: props.locale, messages: props.messages, translations: phone.translations, onBlur: field.onBlur, onChange: (translations) => update({ ...phone, translations }) })] })) }));
|
|
62
|
+
export const ContactWebsitesField = ({ field, props }) => (_jsx(RepeatableContactField, { addLabel: props.messages.addWebsite, emptyValue: {
|
|
63
|
+
url: "",
|
|
64
|
+
translations: [{ locale: props.locale, label: "" }],
|
|
65
|
+
}, error: Option.isSome(field.error) ? field.error.value : undefined, maxItems: props.maxItems, path: field.path, removeLabel: props.messages.remove, 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: props.messages.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, messages: props.messages, translations: website.translations, onBlur: field.onBlur, onChange: (translations) => update({ ...website, translations }) })] })) }));
|
|
66
|
+
export const ContactSocialsField = ({ field, props }) => (_jsx(RepeatableContactField, { addLabel: props.messages.addSocial, emptyValue: {
|
|
67
|
+
platform: "linkedin",
|
|
68
|
+
url: "",
|
|
69
|
+
translations: [{ locale: props.locale, label: "" }],
|
|
70
|
+
}, error: Option.isSome(field.error) ? field.error.value : undefined, maxItems: props.maxItems, path: field.path, removeLabel: props.messages.remove, values: field.value, onChange: field.onChange, render: (social, index, update) => (_jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(SocialPlatformSelect, { messages: props.messages, value: social.platform, onChange: (platform) => update({ ...social, platform }) }), _jsx(ContactInput, { id: `${field.path}-${index}-url`, label: props.messages.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, messages: props.messages, translations: social.translations, onBlur: field.onBlur, onChange: (translations) => update({ ...social, translations }) })] })) }));
|
|
71
|
+
export const ContactAddressesField = ({ field, props }) => {
|
|
72
|
+
const inputs = [
|
|
73
|
+
{
|
|
74
|
+
key: "streetAddress",
|
|
75
|
+
label: props.messages.street,
|
|
76
|
+
className: "sm:col-span-2",
|
|
77
|
+
},
|
|
78
|
+
{ key: "locality", label: props.messages.locality },
|
|
79
|
+
{ key: "region", label: props.messages.region },
|
|
80
|
+
{ key: "postalCode", label: props.messages.postalCode },
|
|
81
|
+
{ key: "country", label: props.messages.country },
|
|
82
|
+
];
|
|
83
|
+
return (_jsx(RepeatableContactField, { addLabel: props.messages.addAddress, emptyValue: {
|
|
84
|
+
translations: [{ locale: props.locale, label: "" }],
|
|
85
|
+
}, error: Option.isSome(field.error) ? field.error.value : undefined, maxItems: undefined, path: field.path, removeLabel: props.messages.remove, 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, messages: props.messages, translations: address.translations, onBlur: field.onBlur, onChange: (translations) => update({ ...address, translations }) }), 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 }) })))] })) }));
|
|
86
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createElement as _createElement } from "react";
|
|
2
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
2
|
import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
4
3
|
import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
@@ -7,17 +6,15 @@ import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
|
7
6
|
import { ArrowLeft, Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
|
|
8
7
|
import { createContext, useContext, useEffect, useEffectEvent, useRef, useState, } from "react";
|
|
9
8
|
import { DataTable, DataTableRelationshipCell, } from "@krak-stack/registry/data-table";
|
|
10
|
-
import {
|
|
9
|
+
import { CheckboxField, ImageField, SelectField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
|
|
11
10
|
import { EditingLocaleSwitcher } from "@krak-stack/registry/editing-locale-switcher";
|
|
12
11
|
import { AppBrand } from "@krak-stack/registry/app-brand";
|
|
13
|
-
import {
|
|
14
|
-
import { Input } from "@/components/ui/input";
|
|
12
|
+
import { FieldSet } from "@/components/ui/field";
|
|
15
13
|
import { Badge } from "@/components/ui/badge";
|
|
16
14
|
import { Button } from "@/components/ui/button";
|
|
17
15
|
import { CopyButton } from "@krak-stack/registry/copy-button";
|
|
18
16
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
19
17
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
20
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
|
|
21
18
|
import { Separator } from "@/components/ui/separator";
|
|
22
19
|
import { OrganizationEmail, OrganizationAddress, OrganizationMetadata, OrganizationPhone, OrganizationSocial, OrganizationTranslation, OrganizationWebsite, decodeOrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
23
20
|
import { isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, parseRoleList, } from "../roles.js";
|
|
@@ -28,6 +25,7 @@ import { parseApiKeyReferrers } from "./api-key.js";
|
|
|
28
25
|
import { ApiKeyPermissions } from "./api-key-permissions.js";
|
|
29
26
|
import { ApiKeyRateLimit, apiKeyUsagePercent } from "./api-key-rate-limit.js";
|
|
30
27
|
import { ApiKeyReferrers, apiKeyReferrers } from "./api-key-referrers.js";
|
|
28
|
+
import { ContactAddressesField, ContactEmailsField, ContactPhonesField, ContactSocialsField, ContactWebsitesField, } from "./contact-fields.js";
|
|
31
29
|
import { useOpenedOnce } from "./hooks.js";
|
|
32
30
|
import { invitationDisplayStatus, isInvitationExpired, useInvitationExpirationClock, } from "./invitation-expiration.js";
|
|
33
31
|
import { ExtraUploadedAsset } from "../extra/schema.js";
|
|
@@ -332,6 +330,25 @@ const organizationMessageFns = (labels) => {
|
|
|
332
330
|
};
|
|
333
331
|
const OrganizationMessagesContext = createContext(organizationMessageFns(organizationSwitcherMessages()));
|
|
334
332
|
const useOrganizationMessages = () => useContext(OrganizationMessagesContext);
|
|
333
|
+
const organizationContactFieldMessages = (m) => ({
|
|
334
|
+
addAddress: m.organization_address_add(),
|
|
335
|
+
addEmail: m.organization_contact_add_email(),
|
|
336
|
+
addPhone: m.organization_contact_add_phone(),
|
|
337
|
+
addSocial: m.organization_contact_add_social(),
|
|
338
|
+
addWebsite: m.organization_contact_add_website(),
|
|
339
|
+
country: m.organization_address_country(),
|
|
340
|
+
email: m.organization_contact_email_type(),
|
|
341
|
+
extension: m.organization_contact_extension(),
|
|
342
|
+
label: m.organization_contact_label(),
|
|
343
|
+
locality: m.organization_address_locality(),
|
|
344
|
+
phone: m.organization_contact_phone_type(),
|
|
345
|
+
platform: m.organization_contact_platform(),
|
|
346
|
+
postalCode: m.organization_address_postal_code(),
|
|
347
|
+
region: m.organization_address_region(),
|
|
348
|
+
remove: m.organization_contact_remove(),
|
|
349
|
+
street: m.organization_address_street(),
|
|
350
|
+
url: m.organization_contact_url(),
|
|
351
|
+
});
|
|
335
352
|
const normalizeInvitationRole = (role) => {
|
|
336
353
|
const normalized = normalizeOrganizationRole(role);
|
|
337
354
|
return normalized === "support" ? "member" : normalized;
|
|
@@ -390,126 +407,14 @@ const organizationFormBuilder = FormBuilder.empty
|
|
|
390
407
|
.addField("frName", Schema.String)
|
|
391
408
|
.addField("frLogo", organizationImageSchema)
|
|
392
409
|
.addField("frIcon", organizationImageSchema);
|
|
393
|
-
const socialPlatform = (value) => {
|
|
394
|
-
switch (value) {
|
|
395
|
-
case "facebook":
|
|
396
|
-
case "github":
|
|
397
|
-
case "instagram":
|
|
398
|
-
case "linkedin":
|
|
399
|
-
case "tiktok":
|
|
400
|
-
case "x":
|
|
401
|
-
case "youtube":
|
|
402
|
-
return value;
|
|
403
|
-
default:
|
|
404
|
-
return null;
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
const contactLabel = (translations, locale) => translations?.find((translation) => translation.locale === locale)?.label ??
|
|
408
|
-
"";
|
|
409
|
-
const contactTranslations = (translations, locale, label) => [
|
|
410
|
-
...(translations ?? []).filter((translation) => translation.locale !== locale),
|
|
411
|
-
...(label ? [{ locale, label }] : []),
|
|
412
|
-
];
|
|
413
|
-
const EmailsField = ({ field, props }) => {
|
|
414
|
-
const m = useOrganizationMessages();
|
|
415
|
-
return (_jsx(RepeatableContactField, { addLabel: m.organization_contact_add_email(), emptyValue: {
|
|
416
|
-
email: "",
|
|
417
|
-
translations: [{ locale: props.locale, label: "" }],
|
|
418
|
-
}, 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({
|
|
419
|
-
...contact,
|
|
420
|
-
translations,
|
|
421
|
-
}) })] })) }));
|
|
422
|
-
};
|
|
423
|
-
const PhonesField = ({ field, props }) => {
|
|
424
|
-
const m = useOrganizationMessages();
|
|
425
|
-
return (_jsx(RepeatableContactField, { addLabel: m.organization_contact_add_phone(), emptyValue: {
|
|
426
|
-
number: "",
|
|
427
|
-
translations: [{ locale: props.locale, label: "" }],
|
|
428
|
-
}, 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({
|
|
429
|
-
...phone,
|
|
430
|
-
...(extension ? { extension } : { extension: undefined }),
|
|
431
|
-
}) }), _jsx(ContactLabelInput, { id: `${field.path}-${index}-label`, locale: props.locale, translations: phone.translations, onBlur: field.onBlur, onChange: (translations) => update({
|
|
432
|
-
...phone,
|
|
433
|
-
translations,
|
|
434
|
-
}) })] })) }));
|
|
435
|
-
};
|
|
436
|
-
function ContactInput({ className, id, label, onBlur, onChange, placeholder, type = "text", value, }) {
|
|
437
|
-
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) })] }));
|
|
438
|
-
}
|
|
439
|
-
function ContactLabelInput({ id, locale, onBlur, onChange, translations, }) {
|
|
440
|
-
const m = useOrganizationMessages();
|
|
441
|
-
return (_jsx(ContactInput, { id: id, label: m.organization_contact_label(), value: contactLabel(translations, locale), onBlur: onBlur, onChange: (label) => onChange(contactTranslations(translations, locale, label)) }));
|
|
442
|
-
}
|
|
443
|
-
const WebsitesField = ({ field, props }) => {
|
|
444
|
-
const m = useOrganizationMessages();
|
|
445
|
-
return (_jsx(RepeatableContactField, { addLabel: m.organization_contact_add_website(), emptyValue: {
|
|
446
|
-
url: "",
|
|
447
|
-
translations: [{ locale: props.locale, label: "" }],
|
|
448
|
-
}, 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({
|
|
449
|
-
...website,
|
|
450
|
-
translations,
|
|
451
|
-
}) })] })) }));
|
|
452
|
-
};
|
|
453
|
-
function RepeatableContactField({ addLabel, emptyValue, error, onChange, path, render, values, }) {
|
|
454
|
-
const m = useOrganizationMessages();
|
|
455
|
-
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] }) }));
|
|
456
|
-
}
|
|
457
|
-
function SocialPlatformSelect({ value, onChange, }) {
|
|
458
|
-
const m = useOrganizationMessages();
|
|
459
|
-
const items = [
|
|
460
|
-
{ label: "Facebook", value: "facebook" },
|
|
461
|
-
{ label: "GitHub", value: "github" },
|
|
462
|
-
{ label: "Instagram", value: "instagram" },
|
|
463
|
-
{ label: "LinkedIn", value: "linkedin" },
|
|
464
|
-
{ label: "TikTok", value: "tiktok" },
|
|
465
|
-
{ label: "X", value: "x" },
|
|
466
|
-
{ label: "YouTube", value: "youtube" },
|
|
467
|
-
];
|
|
468
|
-
return (_jsxs("div", { children: [_jsx(FieldLabel, { children: m.organization_contact_platform() }), _jsxs(Select, { items: items, value: value, onValueChange: (next) => {
|
|
469
|
-
const platform = socialPlatform(next);
|
|
470
|
-
if (platform)
|
|
471
|
-
onChange(platform);
|
|
472
|
-
}, 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))) })] })] }));
|
|
473
|
-
}
|
|
474
|
-
const SocialsField = ({ field, props }) => {
|
|
475
|
-
const m = useOrganizationMessages();
|
|
476
|
-
return (_jsx(RepeatableContactField, { addLabel: m.organization_contact_add_social(), emptyValue: {
|
|
477
|
-
platform: "linkedin",
|
|
478
|
-
url: "",
|
|
479
|
-
translations: [{ locale: props.locale, label: "" }],
|
|
480
|
-
}, 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({
|
|
481
|
-
...social,
|
|
482
|
-
translations,
|
|
483
|
-
}) })] })) }));
|
|
484
|
-
};
|
|
485
|
-
const AddressesField = ({ field, props }) => {
|
|
486
|
-
const m = useOrganizationMessages();
|
|
487
|
-
const inputs = [
|
|
488
|
-
{
|
|
489
|
-
key: "streetAddress",
|
|
490
|
-
label: m.organization_address_street(),
|
|
491
|
-
className: "sm:col-span-2",
|
|
492
|
-
},
|
|
493
|
-
{ key: "locality", label: m.organization_address_locality() },
|
|
494
|
-
{ key: "region", label: m.organization_address_region() },
|
|
495
|
-
{ key: "postalCode", label: m.organization_address_postal_code() },
|
|
496
|
-
{ key: "country", label: m.organization_address_country() },
|
|
497
|
-
];
|
|
498
|
-
return (_jsx(RepeatableContactField, { addLabel: m.organization_address_add(), emptyValue: {
|
|
499
|
-
translations: [{ locale: props.locale, label: "" }],
|
|
500
|
-
}, 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({
|
|
501
|
-
...address,
|
|
502
|
-
translations,
|
|
503
|
-
}) }), 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 }) })))] })) }));
|
|
504
|
-
};
|
|
505
410
|
const organizationFormFields = {
|
|
506
411
|
parentId: SelectField,
|
|
507
412
|
slug: TextField,
|
|
508
|
-
emails:
|
|
509
|
-
phones:
|
|
510
|
-
websites:
|
|
511
|
-
socials:
|
|
512
|
-
addresses:
|
|
413
|
+
emails: ContactEmailsField,
|
|
414
|
+
phones: ContactPhonesField,
|
|
415
|
+
websites: ContactWebsitesField,
|
|
416
|
+
socials: ContactSocialsField,
|
|
417
|
+
addresses: ContactAddressesField,
|
|
513
418
|
enName: TextField,
|
|
514
419
|
enLogo: ImageField,
|
|
515
420
|
enIcon: ImageField,
|
|
@@ -558,7 +463,7 @@ const organizationFailureMessage = (cause, fallback) => {
|
|
|
558
463
|
};
|
|
559
464
|
const decodeUploadedAsset = Schema.decodeUnknownEffect(ExtraUploadedAsset);
|
|
560
465
|
const OrganizationMetadataRecord = Schema.Record(Schema.String, Schema.Json);
|
|
561
|
-
const normalizeOrganizationMetadata = (metadata) => Schema.decodeUnknownEffect(
|
|
466
|
+
const normalizeOrganizationMetadata = (metadata) => Schema.decodeUnknownEffect(OrganizationMetadataRecord)(metadata);
|
|
562
467
|
const uploadImageAsset = (file, m, uploadImage) => {
|
|
563
468
|
const payload = new FormData();
|
|
564
469
|
payload.append("file", file);
|
|
@@ -1168,7 +1073,7 @@ function EditOrganizationSection({ baseUrl, editingLocale, organization, onUpdat
|
|
|
1168
1073
|
height: 96,
|
|
1169
1074
|
suggestedWidth: 512,
|
|
1170
1075
|
suggestedHeight: 512,
|
|
1171
|
-
} })] })] }), _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 })] }) }) }));
|
|
1076
|
+
} })] })] }), _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, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) })] }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationFormSection, { title: m.organization_address(), children: _jsx(form.addresses, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
|
|
1172
1077
|
}
|
|
1173
1078
|
function CreateOrganizationSection({ baseUrl, editingLocale, organizations, onCreated, }) {
|
|
1174
1079
|
const m = useOrganizationMessages();
|
|
@@ -1251,7 +1156,7 @@ function CreateOrganizationSection({ baseUrl, editingLocale, organizations, onCr
|
|
|
1251
1156
|
height: 96,
|
|
1252
1157
|
suggestedWidth: 512,
|
|
1253
1158
|
suggestedHeight: 512,
|
|
1254
|
-
} })] })] }), _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 })] }) }) }));
|
|
1159
|
+
} })] })] }), _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, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) })] }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationFormSection, { title: m.organization_address(), children: _jsx(form.addresses, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
|
|
1255
1160
|
}
|
|
1256
1161
|
function OrganizationFormSection({ children, description, title, }) {
|
|
1257
1162
|
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] }));
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
1
2
|
import { type ComponentProps, type ReactNode } from "react";
|
|
2
3
|
import { DropdownMenuContent } from "@/components/ui/dropdown-menu";
|
|
4
|
+
import { type ContactEmail as ContactEmailValue, type ContactPhone as ContactPhoneValue, type ContactSocial as ContactSocialValue, type ContactWebsite as ContactWebsiteValue, UserMetadata } from "../schema.js";
|
|
3
5
|
declare const messages: {
|
|
4
6
|
readonly en: {
|
|
5
7
|
readonly table_empty: "No results.";
|
|
@@ -89,6 +91,22 @@ declare const messages: {
|
|
|
89
91
|
readonly user_form_title: "Account";
|
|
90
92
|
readonly user_form_update_error: "Unable to update your account.";
|
|
91
93
|
readonly user_loading: "Loading...";
|
|
94
|
+
readonly user_contact_add_email: "Add email";
|
|
95
|
+
readonly user_contact_add_phone: "Add phone";
|
|
96
|
+
readonly user_contact_add_social: "Add social profile";
|
|
97
|
+
readonly user_contact_add_website: "Add website";
|
|
98
|
+
readonly user_contact_description: "Add up to 8 public contacts of each type, separately from the email used to sign in.";
|
|
99
|
+
readonly user_contact_email_type: "Email";
|
|
100
|
+
readonly user_contact_extension: "Extension";
|
|
101
|
+
readonly user_contact_label: "Label";
|
|
102
|
+
readonly user_contact_phone_type: "Phone";
|
|
103
|
+
readonly user_contact_platform: "Platform";
|
|
104
|
+
readonly user_contact_remove: "Remove contact method";
|
|
105
|
+
readonly user_contact_social_type: "Social";
|
|
106
|
+
readonly user_contact_title: "Contact methods";
|
|
107
|
+
readonly user_contact_url: "URL";
|
|
108
|
+
readonly user_contact_validation_error: "Review your contact methods and keep the total metadata below 2 KB.";
|
|
109
|
+
readonly user_contact_website_type: "Website";
|
|
92
110
|
readonly user_profile_description: "Update your public profile details.";
|
|
93
111
|
readonly user_profile_image_upload_error: "Could not upload your profile photo.";
|
|
94
112
|
readonly user_profile_photo_upload_label: "Profile photo";
|
|
@@ -198,6 +216,22 @@ declare const messages: {
|
|
|
198
216
|
readonly user_form_title: "Compte";
|
|
199
217
|
readonly user_form_update_error: "Impossible de mettre à jour votre compte.";
|
|
200
218
|
readonly user_loading: "Chargement...";
|
|
219
|
+
readonly user_contact_add_email: "Ajouter un courriel";
|
|
220
|
+
readonly user_contact_add_phone: "Ajouter un téléphone";
|
|
221
|
+
readonly user_contact_add_social: "Ajouter un profil social";
|
|
222
|
+
readonly user_contact_add_website: "Ajouter un site Web";
|
|
223
|
+
readonly user_contact_description: "Ajoutez jusqu’à 8 coordonnées publiques de chaque type, distinctes du courriel utilisé pour vous connecter.";
|
|
224
|
+
readonly user_contact_email_type: "Courriel";
|
|
225
|
+
readonly user_contact_extension: "Poste";
|
|
226
|
+
readonly user_contact_label: "Libellé";
|
|
227
|
+
readonly user_contact_phone_type: "Téléphone";
|
|
228
|
+
readonly user_contact_platform: "Plateforme";
|
|
229
|
+
readonly user_contact_remove: "Supprimer le moyen de contact";
|
|
230
|
+
readonly user_contact_social_type: "Réseau social";
|
|
231
|
+
readonly user_contact_title: "Moyens de contact";
|
|
232
|
+
readonly user_contact_url: "URL";
|
|
233
|
+
readonly user_contact_validation_error: "Vérifiez vos moyens de contact et limitez les métadonnées totales à 2 Ko.";
|
|
234
|
+
readonly user_contact_website_type: "Site Web";
|
|
201
235
|
readonly user_profile_description: "Mettez à jour les informations de votre profil public.";
|
|
202
236
|
readonly user_profile_image_upload_error: "Impossible de téléverser votre photo de profil.";
|
|
203
237
|
readonly user_profile_photo_upload_label: "Photo de profil";
|
|
@@ -222,6 +256,45 @@ declare const messages: {
|
|
|
222
256
|
};
|
|
223
257
|
type UserButtonMessageKey = keyof (typeof messages)["en"];
|
|
224
258
|
export type UserButtonMessages = Partial<Record<UserButtonMessageKey, string>>;
|
|
259
|
+
type UserFormType = {
|
|
260
|
+
name: string;
|
|
261
|
+
image: File | string | null;
|
|
262
|
+
emails: ReadonlyArray<ContactEmailValue>;
|
|
263
|
+
phones: ReadonlyArray<ContactPhoneValue>;
|
|
264
|
+
websites: ReadonlyArray<ContactWebsiteValue>;
|
|
265
|
+
socials: ReadonlyArray<ContactSocialValue>;
|
|
266
|
+
};
|
|
267
|
+
export declare const UserContactEmailsForm: Schema.$Array<Schema.Struct<{
|
|
268
|
+
readonly email: Schema.String;
|
|
269
|
+
readonly translations: Schema.$Array<Schema.Struct<{
|
|
270
|
+
readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
|
|
271
|
+
readonly label: Schema.String;
|
|
272
|
+
}>>;
|
|
273
|
+
}>>;
|
|
274
|
+
export declare const UserContactPhonesForm: Schema.$Array<Schema.Struct<{
|
|
275
|
+
readonly number: Schema.String;
|
|
276
|
+
readonly extension: Schema.optional<Schema.String>;
|
|
277
|
+
readonly translations: Schema.$Array<Schema.Struct<{
|
|
278
|
+
readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
|
|
279
|
+
readonly label: Schema.String;
|
|
280
|
+
}>>;
|
|
281
|
+
}>>;
|
|
282
|
+
export declare const UserContactWebsitesForm: Schema.$Array<Schema.Struct<{
|
|
283
|
+
readonly url: Schema.String;
|
|
284
|
+
readonly translations: Schema.$Array<Schema.Struct<{
|
|
285
|
+
readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
|
|
286
|
+
readonly label: Schema.String;
|
|
287
|
+
}>>;
|
|
288
|
+
}>>;
|
|
289
|
+
export declare const UserContactSocialsForm: Schema.$Array<Schema.Struct<{
|
|
290
|
+
readonly platform: Schema.Literals<readonly ["facebook", "github", "instagram", "linkedin", "tiktok", "x", "youtube"]>;
|
|
291
|
+
readonly url: Schema.String;
|
|
292
|
+
readonly translations: Schema.$Array<Schema.Struct<{
|
|
293
|
+
readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
|
|
294
|
+
readonly label: Schema.String;
|
|
295
|
+
}>>;
|
|
296
|
+
}>>;
|
|
297
|
+
export declare const userMetadataFromForm: (value: UserFormType) => UserMetadata;
|
|
225
298
|
export type UserButtonProps = {
|
|
226
299
|
baseUrl?: string | undefined;
|
|
227
300
|
signOutRedirect?: string;
|