@openpeepshq/react 0.11.0 → 0.11.1
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/components/post/post-form/EventForm.js +2 -2
- package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -0
- package/dist/hooks/settings/useNotificationPreferences.js +7 -2
- package/dist/pages/admin/ApiKeys.js +14 -6
- package/dist/pages/admin/ConfigurationEmail.js +2 -2
- package/dist/pages/admin/ConfigurationSso.js +1 -1
- package/dist/pages/auth/RequestResetPassword.js +1 -1
- package/dist/pages/settings/NotificationPreferences.js +7 -3
- package/dist/pages/settings/NotificationPreferences.test.d.ts +1 -0
- package/dist/pages/settings/NotificationPreferences.test.js +119 -0
- package/package.json +4 -4
- package/src/components/post/post-form/EventForm.tsx +2 -2
- package/src/hooks/settings/useNotificationPreferences.ts +12 -1
- package/src/pages/admin/ApiKeys.tsx +20 -9
- package/src/pages/admin/ConfigurationEmail.tsx +2 -2
- package/src/pages/admin/ConfigurationSso.tsx +2 -1
- package/src/pages/auth/RequestResetPassword.tsx +1 -1
- package/src/pages/settings/NotificationPreferences.tsx +38 -12
|
@@ -30,9 +30,9 @@ export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit =
|
|
|
30
30
|
defaultValue: 'Describe your event',
|
|
31
31
|
}) }), _jsx(ComposePreviewLinks, { content: event.content }), _jsx("h2", { className: "text-lg", children: t('events.form.dateAndTimeTitle', {
|
|
32
32
|
defaultValue: 'Date and Time',
|
|
33
|
-
}) }), _jsx(Label, { title: t('events.
|
|
33
|
+
}) }), _jsx(Label, { title: t('events.startDate', { defaultValue: 'Start Date' }), htmlFor: "event-start", children: _jsx(Input, { id: "event-start", type: "datetime-local", step: 60, value: dateToInputValue(event.start, eventTimeZone), onChange: (e) => changeStart(toIso(e.target.value, eventTimeZone)), "data-testid": "events-start-input" }) }), _jsx(Label, { description: t('events.form.addEndDate', {
|
|
34
34
|
defaultValue: 'Add end date and time',
|
|
35
|
-
}), forCheckbox: true, children: _jsx("input", { type: "checkbox", checked: showEndDate, onChange: (e) => toggleEndDate(e.target.checked) }) }), showEndDate ? (_jsxs(_Fragment, { children: [_jsx(Label, { title: t('events.
|
|
35
|
+
}), forCheckbox: true, children: _jsx("input", { type: "checkbox", checked: showEndDate, onChange: (e) => toggleEndDate(e.target.checked) }) }), showEndDate ? (_jsxs(_Fragment, { children: [_jsx(Label, { title: t('events.endDate', { defaultValue: 'End Date' }), htmlFor: "event-end", children: _jsx(Input, { id: "event-end", type: "datetime-local", step: 60, value: dateToInputValue(event.end, eventTimeZone), onChange: (e) => changeEnd(toIso(e.target.value, eventTimeZone)) }) }), endBeforeStart ? (_jsx("p", { className: "text-destructive text-sm", children: t('events.form.endBeforeStart', {
|
|
36
36
|
defaultValue: 'The end date and time must be after the start date and time.',
|
|
37
37
|
}) })) : null] })) : null, _jsx(Label, { title: t('events.form.timezone', { defaultValue: 'Timezone' }), htmlFor: "event-timezone", children: _jsx("select", { id: "event-timezone", className: "bg-background w-full rounded-md border px-3 py-2 text-sm", value: eventTimeZone, onChange: (e) => setTimeZone(e.target.value), children: TIMEZONES.map((tz) => (_jsx("option", { value: tz, children: tz }, tz))) }) }), !occurrenceEdit ? (_jsxs(_Fragment, { children: [_jsx(Label, { title: t('events.form.repeat.title', { defaultValue: 'Repeat' }), htmlFor: "event-repeat", children: _jsxs("select", { id: "event-repeat", className: "bg-background w-full rounded-md border px-3 py-2 text-sm", value: repeatFreq, onChange: (e) => applyFreq(e.target.value), "data-testid": "events-repeat-input", children: [_jsx("option", { value: "none", children: t('events.form.repeat.none', {
|
|
38
38
|
defaultValue: 'Does not repeat',
|
|
@@ -15,6 +15,7 @@ export declare const useNotificationPreferences: ({ ensurePush, }?: UseNotificat
|
|
|
15
15
|
} | undefined;
|
|
16
16
|
}[];
|
|
17
17
|
settings: ProfileSettings;
|
|
18
|
+
dirty: boolean;
|
|
18
19
|
setTypeSettings: (type: string, next: ProfileNotificationSettings) => void;
|
|
19
20
|
save: () => Promise<void>;
|
|
20
21
|
saving: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import { deepSet, } from '@openpeepshq/common';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { deepEqual, deepSet, } from '@openpeepshq/common';
|
|
3
3
|
import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
|
|
4
4
|
import { useT } from '../../i18n/context.js';
|
|
5
5
|
import { useCurrentProfile } from '../../components/layout/IdentityContext.js';
|
|
@@ -20,6 +20,10 @@ export const useNotificationPreferences = ({ ensurePush, } = {}) => {
|
|
|
20
20
|
if (settingsQuery.data)
|
|
21
21
|
setSettings(settingsQuery.data);
|
|
22
22
|
}, [settingsQuery.data]);
|
|
23
|
+
// Unsaved local edits. Clears once the post-save refetch lands the
|
|
24
|
+
// server copy; stays set when a save fails.
|
|
25
|
+
const dirty = useMemo(() => !!settingsQuery.data &&
|
|
26
|
+
!deepEqual(settings.notifications, settingsQuery.data.notifications), [settings, settingsQuery.data]);
|
|
23
27
|
const setTypeSettings = (type, next) => {
|
|
24
28
|
setSettings((current) => {
|
|
25
29
|
const copy = { ...current };
|
|
@@ -70,6 +74,7 @@ export const useNotificationPreferences = ({ ensurePush, } = {}) => {
|
|
|
70
74
|
me,
|
|
71
75
|
types: notificationTypesQuery.data ?? [],
|
|
72
76
|
settings,
|
|
77
|
+
dirty,
|
|
73
78
|
setTypeSettings,
|
|
74
79
|
save,
|
|
75
80
|
saving,
|
|
@@ -87,8 +87,10 @@ export const AdminApiKeys = () => {
|
|
|
87
87
|
const cardLabels = {
|
|
88
88
|
expiresLabel: t('admin.apiKeys.expiresAt', { defaultValue: 'Expires at' }),
|
|
89
89
|
neverLabel: t('common.states.never', { defaultValue: 'Never' }),
|
|
90
|
-
revokeLabel: t('
|
|
91
|
-
revokedLabel: t('
|
|
90
|
+
revokeLabel: t('settings.accessTokens.revoke', { defaultValue: 'Revoke' }),
|
|
91
|
+
revokedLabel: t('settings.accessTokens.revoked', {
|
|
92
|
+
defaultValue: 'Revoked',
|
|
93
|
+
}),
|
|
92
94
|
noScopesLabel: t('admin.apiKeys.noScopes', { defaultValue: 'No scopes' }),
|
|
93
95
|
};
|
|
94
96
|
return (_jsxs("div", { className: "space-y-6 p-4", children: [_jsxs("section", { className: "space-y-3 rounded-md border p-4", children: [_jsx("h2", { className: "text-lg font-medium", children: t('admin.apiKeys.createTitle', {
|
|
@@ -97,7 +99,9 @@ export const AdminApiKeys = () => {
|
|
|
97
99
|
defaultValue: 'Create a service token for integrations. Copy the token value when it is created.',
|
|
98
100
|
}) }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "svc-name", children: t('common.labels.name', { defaultValue: 'Name' }) }), _jsx(Input, { id: "svc-name", value: form.name, onChange: (e) => setForm((f) => ({ ...f, name: e.target.value })) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "svc-description", children: t('common.labels.description', {
|
|
99
101
|
defaultValue: 'Description',
|
|
100
|
-
}) }), _jsx(Input, { id: "svc-description", value: form.description ?? '', onChange: (e) => setForm((f) => ({ ...f, description: e.target.value })) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "svc-expiration", children: t('
|
|
102
|
+
}) }), _jsx(Input, { id: "svc-description", value: form.description ?? '', onChange: (e) => setForm((f) => ({ ...f, description: e.target.value })) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "svc-expiration", children: t('settings.accessTokens.expiration', {
|
|
103
|
+
defaultValue: 'Expiration',
|
|
104
|
+
}) }), _jsx("select", { id: "svc-expiration", className: "border-input bg-background w-full rounded-md border px-2 py-2 text-sm", value: form.expirationTime ?? '30d', onChange: (e) => setForm((f) => ({ ...f, expirationTime: e.target.value })), children: EXPIRATION_OPTIONS.map((option) => (_jsx("option", { value: option.value, children: t(`settings.accessTokens.expirationOptions.${option.labelKey}`, {
|
|
101
105
|
defaultValue: EXPIRATION_OPTION_DEFAULTS[option.labelKey],
|
|
102
106
|
}) }, option.value))) })] }), _jsx("p", { className: "text-sm font-medium", children: t('admin.apiKeys.scopes', { defaultValue: 'Scopes' }) }), (form.scopes ?? []).map((scope, index) => (_jsxs("div", { className: "flex flex-wrap items-end gap-2", children: [_jsx("select", { className: "border-input bg-background rounded-md border px-2 py-2 text-sm", value: scope.scopeLevel ?? 'read', onChange: (e) => setForm((f) => ({
|
|
103
107
|
...f,
|
|
@@ -125,12 +129,16 @@ export const AdminApiKeys = () => {
|
|
|
125
129
|
{ scopeLevel: 'read', resource: { type: 'profiles', id: '*' } },
|
|
126
130
|
],
|
|
127
131
|
})), children: t('admin.apiKeys.addScope', { defaultValue: 'Add Scope' }) }), error ? (_jsx(Toast, { variant: "error", onDismiss: () => setError(undefined), children: error })) : null, _jsx(Button, { variant: "default", disabled: creating, action: create, children: creating
|
|
128
|
-
? t('
|
|
132
|
+
? t('settings.accessTokens.creating', {
|
|
133
|
+
defaultValue: 'Creating...',
|
|
134
|
+
})
|
|
129
135
|
: t('admin.apiKeys.create', {
|
|
130
136
|
defaultValue: 'Create Service Token',
|
|
131
|
-
}) }), createdToken ? (_jsxs("div", { className: "rounded-md border p-3", children: [_jsx("p", { className: "text-sm font-semibold", children: t('
|
|
137
|
+
}) }), createdToken ? (_jsxs("div", { className: "rounded-md border p-3", children: [_jsx("p", { className: "text-sm font-semibold", children: t('settings.accessTokens.copyWarning', {
|
|
132
138
|
defaultValue: 'Copy this token now. It will not be shown again.',
|
|
133
|
-
}) }), _jsxs("div", { className: "mt-2 flex items-start gap-2", children: [_jsx("code", { className: "break-all text-sm", children: createdToken }), _jsx("button", { type: "button", title: t('
|
|
139
|
+
}) }), _jsxs("div", { className: "mt-2 flex items-start gap-2", children: [_jsx("code", { className: "break-all text-sm", children: createdToken }), _jsx("button", { type: "button", title: t('settings.accessTokens.copy', {
|
|
140
|
+
defaultValue: 'Copy',
|
|
141
|
+
}), onClick: () => void navigator.clipboard.writeText(createdToken), children: _jsx(Copy, { className: "size-4" }) })] })] })) : null] }), _jsxs("section", { className: "space-y-3 rounded-md border p-4", children: [_jsx("h2", { className: "text-lg font-medium", children: t('admin.apiKeys.listTitle', {
|
|
134
142
|
defaultValue: 'Service Access Tokens',
|
|
135
143
|
}) }), activeTokens.length === 0 ? (_jsx("p", { className: "text-muted-foreground text-sm", children: t('admin.apiKeys.empty', {
|
|
136
144
|
defaultValue: 'No active service access tokens.',
|
|
@@ -91,7 +91,7 @@ export function AdminConfigurationEmail() {
|
|
|
91
91
|
}
|
|
92
92
|
return (_jsxs("div", { className: "space-y-6 p-4", children: [_jsx("p", { className: "text-sm opacity-80", children: t('configuration.email.intro') }), _jsx(Form, { ...form, children: _jsxs("form", { className: "flex flex-col gap-6", onSubmit: onSubmit, children: [_jsxs("section", { className: "flex flex-col gap-4", "aria-labelledby": "email-config-transport-heading", children: [_jsx("h3", { id: "email-config-transport-heading", className: "text-base font-semibold", children: t('configuration.email.sections.transport') }), _jsx(FormField, { control: form.control, name: "transportConfig.host", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.host') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "text", "data-testid": "admin-email-host" }) }), _jsx(FormMessage, {})] })) }), _jsx(FormField, { control: form.control, name: "transportConfig.port", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.port') }), _jsx(FormControl, { children: _jsx(Input, { type: "number", value: Number.isNaN(field.value) ? '' : field.value, onChange: (e) => field.onChange(e.target.value === ''
|
|
93
93
|
? Number.NaN
|
|
94
|
-
: Number(e.target.value)), "data-testid": "admin-email-port" }) }), _jsx(FormMessage, {})] })) }), _jsx(FormField, { control: form.control, name: "transportConfig.auth.user", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.authUser') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "text", value: field.value ?? '' }) }), _jsx(FormMessage, {})] })) }), _jsx(FormField, { control: form.control, name: "transportConfig.auth.pass", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.authPass') }), _jsx(FormDescription, { children: t('configuration.email.fields.authPassDescription') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "password", value: field.value ?? '' }) }), _jsx(FormMessage, {})] })) })] }), _jsx(ExpandableBox, { initialOpen: false, title: _jsx("p", { className: "text-base font-semibold", children: t('configuration.email.sections.general') }), children: _jsxs("div", { className: "flex flex-col gap-4 pt-1", children: [_jsx(FormField, { control: form.control, name: "service", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.service') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "text" }) }), _jsx(FormMessage, {})] })) }), _jsx(FormField, { control: form.control, name: "defaultTemplatePath", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.defaultTemplatePath') }), _jsx(FormDescription, { children: t('configuration.email.fields.defaultTemplatePathDescription') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "text" }) }), _jsx(FormMessage, {})] })) }), _jsx(FormField, { control: form.control, name: "defaultFrom", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.defaultFrom') }), _jsx(FormDescription, { children: t('configuration.email.fields.defaultFromDescription') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "text", value: field.value ?? '' }) }), _jsx(FormMessage, {})] })) })] }) }), _jsx("span", { className: "flex justify-end pt-2", children: _jsx(Button, { type: "submit", title: t('common.submit', { defaultValue: 'Submit' }), disabled: !form.formState.isValid || unchanged, loading: form.formState.isSubmitting, variant: "default", "data-testid": "admin-email-submit", children: t('common.submit', { defaultValue: 'Submit' }) }) })] }) }), _jsxs("div", { className: "bg-surface-2 rounded-lg p-4", children: [_jsx("p", { className: "font-medium", children: t('configuration.email.testTitle') }), _jsx("p", { className: "mb-3 text-sm opacity-80", children: t('configuration.email.testHint') }), _jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-end", children: [_jsxs("label", { className: "flex-1", children: [_jsx("span", { children: t('configuration.email.testRecipient') }), _jsx("input", { type: "email", value: testRecipient, onChange: (e) => setTestRecipient(e.target.value), className: "op-input rounded", placeholder: t('configuration.email.testRecipientPlaceholder'), autoComplete: "email", "data-testid": "admin-email-test-recipient" })] }), _jsx(Button, { variant: "secondary", title: t('configuration.email.
|
|
94
|
+
: Number(e.target.value)), "data-testid": "admin-email-port" }) }), _jsx(FormMessage, {})] })) }), _jsx(FormField, { control: form.control, name: "transportConfig.auth.user", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.authUser') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "text", value: field.value ?? '' }) }), _jsx(FormMessage, {})] })) }), _jsx(FormField, { control: form.control, name: "transportConfig.auth.pass", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.authPass') }), _jsx(FormDescription, { children: t('configuration.email.fields.authPassDescription') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "password", value: field.value ?? '' }) }), _jsx(FormMessage, {})] })) })] }), _jsx(ExpandableBox, { initialOpen: false, title: _jsx("p", { className: "text-base font-semibold", children: t('configuration.email.sections.general') }), children: _jsxs("div", { className: "flex flex-col gap-4 pt-1", children: [_jsx(FormField, { control: form.control, name: "service", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.service') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "text" }) }), _jsx(FormMessage, {})] })) }), _jsx(FormField, { control: form.control, name: "defaultTemplatePath", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.defaultTemplatePath') }), _jsx(FormDescription, { children: t('configuration.email.fields.defaultTemplatePathDescription') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "text" }) }), _jsx(FormMessage, {})] })) }), _jsx(FormField, { control: form.control, name: "defaultFrom", render: ({ field }) => (_jsxs(FormItem, { children: [_jsx(FormLabel, { children: t('configuration.email.fields.defaultFrom') }), _jsx(FormDescription, { children: t('configuration.email.fields.defaultFromDescription') }), _jsx(FormControl, { children: _jsx(Input, { ...field, type: "text", value: field.value ?? '' }) }), _jsx(FormMessage, {})] })) })] }) }), _jsx("span", { className: "flex justify-end pt-2", children: _jsx(Button, { type: "submit", title: t('common.submit', { defaultValue: 'Submit' }), disabled: !form.formState.isValid || unchanged, loading: form.formState.isSubmitting, variant: "default", "data-testid": "admin-email-submit", children: t('common.submit', { defaultValue: 'Submit' }) }) })] }) }), _jsxs("div", { className: "bg-surface-2 rounded-lg p-4", children: [_jsx("p", { className: "font-medium", children: t('configuration.email.testTitle') }), _jsx("p", { className: "mb-3 text-sm opacity-80", children: t('configuration.email.testHint') }), _jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-end", children: [_jsxs("label", { className: "flex-1", children: [_jsx("span", { children: t('configuration.email.testRecipient') }), _jsx("input", { type: "email", value: testRecipient, onChange: (e) => setTestRecipient(e.target.value), className: "op-input rounded", placeholder: t('configuration.email.testRecipientPlaceholder'), autoComplete: "email", "data-testid": "admin-email-test-recipient" })] }), _jsx(Button, { variant: "secondary", title: t('configuration.email.testTitle'), action: handleSendTest, disabled: sending, "data-testid": "admin-email-send-test", children: sending
|
|
95
95
|
? t('common.states.loading')
|
|
96
|
-
: t('configuration.email.
|
|
96
|
+
: t('configuration.email.testTitle') })] }), _jsx("p", { className: "mt-3 text-xs opacity-70", children: t('configuration.email.bounceNote') })] }), status ? (_jsx(Toast, { variant: status.type, testId: "admin-email-toast", onDismiss: () => setStatus(null), children: status.message })) : null] }));
|
|
97
97
|
}
|
|
@@ -84,7 +84,7 @@ export function AdminConfigurationSso() {
|
|
|
84
84
|
];
|
|
85
85
|
return (_jsxs("div", { className: "space-y-8 p-4", children: [_jsx("p", { className: "text-sm opacity-80", children: t('configuration.sso.intro') }), _jsx(Label, { title: t('configuration.sso.onlySSO'), description: t('configuration.sso.onlySSODescription'), forCheckbox: true, children: _jsx(Switch, { checked: !!sso.onlySSO, onCheckedChange: (onlySSO) => void persist({ onlySSO }), "data-testid": "admin-sso-only" }) }), _jsxs("section", { className: "space-y-3", children: [_jsx("h3", { className: "text-base font-semibold", children: t('configuration.sso.providers') }), listed.length === 0 ? (_jsx("p", { className: "text-muted-foreground text-sm", children: t('configuration.sso.empty') })) : (listed.map((item) => {
|
|
86
86
|
const isEditing = editing?.bucket === item.bucket && editing.id === item.id;
|
|
87
|
-
return (_jsxs("div", { className: "bg-surface-2 space-y-3 rounded-lg p-4", "data-testid": `admin-sso-provider-${item.id}`, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("div", { children: [_jsx("p", { className: "font-medium", children: item.name }), _jsxs("p", { className: "text-muted-foreground text-xs", children: [t(`configuration.sso.
|
|
87
|
+
return (_jsxs("div", { className: "bg-surface-2 space-y-3 rounded-lg p-4", "data-testid": `admin-sso-provider-${item.id}`, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("div", { children: [_jsx("p", { className: "font-medium", children: item.name }), _jsxs("p", { className: "text-muted-foreground text-xs", children: [t(`configuration.sso.types.${item.kind}.title`), " \u00B7", ' ', item.id] })] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { variant: "outline", size: "sm", title: t('configuration.sso.editProvider'), action: () => {
|
|
88
88
|
if (isEditing) {
|
|
89
89
|
setEditing(undefined);
|
|
90
90
|
setEditForm(undefined);
|
|
@@ -44,7 +44,7 @@ export function RequestResetPassword() {
|
|
|
44
44
|
defaultValue: 'Email',
|
|
45
45
|
}), children: _jsx(Input, { type: "email", "data-testid": "auth-request-reset-email", value: email, onChange: (e) => setEmail(e.target.value), required: true, placeholder: t('auth.requestResetPassword.emailPlaceholder', {
|
|
46
46
|
defaultValue: 'you@email.org',
|
|
47
|
-
}) }) }), error && (_jsx("p", { className: "text-error border-error/40 rounded-md border p-2 text-sm", children: error })), notice && (_jsx(Toast, { variant: "success", testId: "auth-request-reset-success", onDismiss: () => setNotice(null), children: notice })), _jsx(Button, { title: t('auth.requestResetPassword.
|
|
47
|
+
}) }) }), error && (_jsx("p", { className: "text-error border-error/40 rounded-md border p-2 text-sm", children: error })), notice && (_jsx(Toast, { variant: "success", testId: "auth-request-reset-success", onDismiss: () => setNotice(null), children: notice })), _jsx(Button, { title: t('auth.requestResetPassword.heading', {
|
|
48
48
|
defaultValue: 'Request Password Reset',
|
|
49
49
|
}), action: handleSubmit, variant: "default", className: "w-full", "data-testid": "auth-request-reset-submit", children: t('auth.requestResetPassword.proceed', { defaultValue: 'Proceed' }) })] }) }));
|
|
50
50
|
}
|
|
@@ -103,7 +103,7 @@ export function NotificationPreferences() {
|
|
|
103
103
|
const { client } = useOpenpeeps();
|
|
104
104
|
const serverInfo = useServerInfo();
|
|
105
105
|
const vapidKey = serverInfo.vapid.publicKey;
|
|
106
|
-
const { me, types, settings, setTypeSettings, save, saving, status, clearStatus, } = useNotificationPreferences({
|
|
106
|
+
const { me, types, settings, setTypeSettings, save, saving, status, clearStatus, dirty, } = useNotificationPreferences({
|
|
107
107
|
ensurePush: vapidKey
|
|
108
108
|
? async () => {
|
|
109
109
|
await subscribePushNotifications({
|
|
@@ -122,7 +122,11 @@ export function NotificationPreferences() {
|
|
|
122
122
|
defaultValue: 'Push settings',
|
|
123
123
|
}) }), _jsx(PushSettingsPanel, {}), _jsx("h2", { className: "mb-2 text-lg font-medium", children: t('settings.notifications.description', {
|
|
124
124
|
defaultValue: 'Choose how you want to be notified about activity.',
|
|
125
|
-
}) }), types.map((nt) => (_jsx(NotificationSettingRow, { notificationType: nt, settings: settings.notifications?.[nt.type], onChange: (next) => setTypeSettings(nt.type, next) }, nt.type))), status ? (_jsx(Toast, { variant: status.type, onDismiss: clearStatus, children: status.message })) : null,
|
|
125
|
+
}) }), types.map((nt) => (_jsx(NotificationSettingRow, { notificationType: nt, settings: settings.notifications?.[nt.type], onChange: (next) => setTypeSettings(nt.type, next) }, nt.type))), status ? (_jsx(Toast, { variant: status.type, onDismiss: clearStatus, children: status.message })) : null, dirty ? (_jsxs("div", { "data-testid": "settings-unsaved-bar", className: "border-border bg-surface sticky bottom-0 z-10 mt-4 flex items-center justify-between gap-4 rounded-t-lg border-t p-3 shadow-lg", children: [_jsx("p", { className: "text-sm font-medium", children: t('settings.notifications.unsavedChanges', {
|
|
126
|
+
defaultValue: 'You have unsaved changes.',
|
|
127
|
+
}) }), _jsx(Button, { variant: "default", action: save, disabled: saving, "data-testid": "settings-save-button", children: saving
|
|
128
|
+
? t('common.submitting', { defaultValue: 'Submitting…' })
|
|
129
|
+
: t('common.submit', { defaultValue: 'Submit' }) })] })) : (_jsx("div", { className: "pt-3", children: _jsx(Button, { variant: "default", className: "w-full", action: save, disabled: saving, "data-testid": "settings-save-button", children: saving
|
|
126
130
|
? t('common.submitting', { defaultValue: 'Submitting…' })
|
|
127
|
-
: t('common.submit', { defaultValue: 'Submit' }) }) })] }));
|
|
131
|
+
: t('common.submit', { defaultValue: 'Submit' }) }) }))] }));
|
|
128
132
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
import { act, createElement } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
const { hookState } = vi.hoisted(() => ({
|
|
6
|
+
hookState: {
|
|
7
|
+
dirty: false,
|
|
8
|
+
saving: false,
|
|
9
|
+
save: () => { },
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
vi.mock('../../index', () => ({
|
|
13
|
+
useT: () => (key, opts) => {
|
|
14
|
+
const translations = {
|
|
15
|
+
'common.submit': 'Submit',
|
|
16
|
+
'common.submitting': 'Submitting…',
|
|
17
|
+
'settings.notifications.unsavedChanges': 'You have unsaved changes.',
|
|
18
|
+
'settings.notifications.description': 'Choose how you want to be notified about activity.',
|
|
19
|
+
'settings.notifications.pushSettings': 'Push settings',
|
|
20
|
+
'settings.notifications.serverPushDisabled': 'Push notifications are not configured on this server.',
|
|
21
|
+
};
|
|
22
|
+
return (translations[key] ?? key).replace(/\{\{(\w+)\}\}/g, (_match, name) => opts?.[name] ?? '');
|
|
23
|
+
},
|
|
24
|
+
useOpenpeeps: () => ({
|
|
25
|
+
client: {},
|
|
26
|
+
openpeepsApi: { testPushSubscriptionAction: () => vi.fn(async () => { }) },
|
|
27
|
+
}),
|
|
28
|
+
useSetPageHeader: () => undefined,
|
|
29
|
+
usePushSubscription: () => ({
|
|
30
|
+
isSubscribed: false,
|
|
31
|
+
isLoading: false,
|
|
32
|
+
hasServiceWorker: false,
|
|
33
|
+
isSupported: false,
|
|
34
|
+
subscribe: vi.fn(async () => null),
|
|
35
|
+
unsubscribe: vi.fn(async () => { }),
|
|
36
|
+
}),
|
|
37
|
+
getPushSubscription: vi.fn(),
|
|
38
|
+
isBraveBrowser: () => false,
|
|
39
|
+
subscribePushNotifications: vi.fn(async () => { }),
|
|
40
|
+
}));
|
|
41
|
+
vi.mock('../../components', () => ({
|
|
42
|
+
useServerInfo: () => ({ vapid: { publicKey: undefined } }),
|
|
43
|
+
}));
|
|
44
|
+
vi.mock('../../hooks', () => ({
|
|
45
|
+
useNotificationPreferences: () => ({
|
|
46
|
+
me: { id: 'me' },
|
|
47
|
+
types: [],
|
|
48
|
+
settings: { notifications: {} },
|
|
49
|
+
dirty: hookState.dirty,
|
|
50
|
+
saving: hookState.saving,
|
|
51
|
+
save: () => hookState.save(),
|
|
52
|
+
status: null,
|
|
53
|
+
setTypeSettings: () => { },
|
|
54
|
+
clearStatus: () => { },
|
|
55
|
+
}),
|
|
56
|
+
}));
|
|
57
|
+
vi.mock('@openpeepshq/react-ui', () => ({
|
|
58
|
+
Button: (props) => createElement('button', {
|
|
59
|
+
'data-testid': props['data-testid'],
|
|
60
|
+
disabled: props.disabled,
|
|
61
|
+
onClick: typeof props.action === 'function'
|
|
62
|
+
? () => {
|
|
63
|
+
props.action();
|
|
64
|
+
}
|
|
65
|
+
: undefined,
|
|
66
|
+
}, props.children),
|
|
67
|
+
Toast: (props) => createElement('div', null, props.children),
|
|
68
|
+
}));
|
|
69
|
+
import { NotificationPreferences } from './NotificationPreferences.js';
|
|
70
|
+
describe('NotificationPreferences', () => {
|
|
71
|
+
let root;
|
|
72
|
+
let container;
|
|
73
|
+
beforeEach(() => {
|
|
74
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
75
|
+
hookState.dirty = false;
|
|
76
|
+
hookState.saving = false;
|
|
77
|
+
hookState.save = vi.fn();
|
|
78
|
+
container = document.createElement('div');
|
|
79
|
+
document.body.appendChild(container);
|
|
80
|
+
root = createRoot(container);
|
|
81
|
+
});
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
act(() => {
|
|
84
|
+
root?.unmount();
|
|
85
|
+
});
|
|
86
|
+
container?.remove();
|
|
87
|
+
root = undefined;
|
|
88
|
+
container = undefined;
|
|
89
|
+
});
|
|
90
|
+
const render = (element) => {
|
|
91
|
+
act(() => {
|
|
92
|
+
root?.render(element);
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
it('shows only the inline save button while there are no unsaved changes', () => {
|
|
96
|
+
render(createElement(NotificationPreferences));
|
|
97
|
+
expect(container?.querySelector('[data-testid=settings-unsaved-bar]')).toBeNull();
|
|
98
|
+
expect(container?.querySelectorAll('[data-testid=settings-save-button]')).toHaveLength(1);
|
|
99
|
+
});
|
|
100
|
+
it('shows the sticky unsaved bar with the single save button when dirty', () => {
|
|
101
|
+
hookState.dirty = true;
|
|
102
|
+
render(createElement(NotificationPreferences));
|
|
103
|
+
const bar = container?.querySelector('[data-testid=settings-unsaved-bar]');
|
|
104
|
+
expect(bar).not.toBeNull();
|
|
105
|
+
expect(bar?.textContent).toContain('You have unsaved changes.');
|
|
106
|
+
const buttons = container?.querySelectorAll('[data-testid=settings-save-button]');
|
|
107
|
+
expect(buttons).toHaveLength(1);
|
|
108
|
+
expect(bar?.querySelector('[data-testid=settings-save-button]')).not.toBeNull();
|
|
109
|
+
});
|
|
110
|
+
it('saves via the bar button when dirty', () => {
|
|
111
|
+
hookState.dirty = true;
|
|
112
|
+
render(createElement(NotificationPreferences));
|
|
113
|
+
const button = container?.querySelector('[data-testid=settings-unsaved-bar] [data-testid=settings-save-button]');
|
|
114
|
+
act(() => {
|
|
115
|
+
button.click();
|
|
116
|
+
});
|
|
117
|
+
expect(hookState.save).toHaveBeenCalledTimes(1);
|
|
118
|
+
});
|
|
119
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/react",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"emoji-picker-element": "^1.29.1",
|
|
39
39
|
"heic2any": "^0.0.4",
|
|
40
40
|
"i18next": "^24.2.3",
|
|
41
|
-
"i18next-http-backend": "^
|
|
41
|
+
"i18next-http-backend": "^4.0.10",
|
|
42
42
|
"js-base64": "^3.7.7",
|
|
43
43
|
"livekit-client": "2.19.2",
|
|
44
44
|
"lucide-react": "^0.469.0",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
"react-i18next": "^15.4.1",
|
|
52
52
|
"simple-icons": "^16.31.0",
|
|
53
53
|
"uuidv7": "^1.0.2",
|
|
54
|
-
"@openpeepshq/common": "^0.6.1",
|
|
55
54
|
"@openpeepshq/client": "^0.3.0",
|
|
55
|
+
"@openpeepshq/react-ui": "^0.5.1",
|
|
56
56
|
"@openpeepshq/greenscreen": "^0.2.1",
|
|
57
|
-
"@openpeepshq/
|
|
57
|
+
"@openpeepshq/common": "^0.6.2"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^18.3.0 || ^19.0.0",
|
|
@@ -139,7 +139,7 @@ export const EventForm = ({
|
|
|
139
139
|
</h2>
|
|
140
140
|
|
|
141
141
|
<Label
|
|
142
|
-
title={t('events.
|
|
142
|
+
title={t('events.startDate', { defaultValue: 'Start Date' })}
|
|
143
143
|
htmlFor="event-start"
|
|
144
144
|
>
|
|
145
145
|
<Input
|
|
@@ -168,7 +168,7 @@ export const EventForm = ({
|
|
|
168
168
|
{showEndDate ? (
|
|
169
169
|
<>
|
|
170
170
|
<Label
|
|
171
|
-
title={t('events.
|
|
171
|
+
title={t('events.endDate', { defaultValue: 'End Date' })}
|
|
172
172
|
htmlFor="event-end"
|
|
173
173
|
>
|
|
174
174
|
<Input
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
deepEqual,
|
|
3
4
|
deepSet,
|
|
4
5
|
type ProfileNotificationSettings,
|
|
5
6
|
type ProfileSettings,
|
|
@@ -40,6 +41,15 @@ export const useNotificationPreferences = ({
|
|
|
40
41
|
if (settingsQuery.data) setSettings(settingsQuery.data);
|
|
41
42
|
}, [settingsQuery.data]);
|
|
42
43
|
|
|
44
|
+
// Unsaved local edits. Clears once the post-save refetch lands the
|
|
45
|
+
// server copy; stays set when a save fails.
|
|
46
|
+
const dirty = useMemo(
|
|
47
|
+
() =>
|
|
48
|
+
!!settingsQuery.data &&
|
|
49
|
+
!deepEqual(settings.notifications, settingsQuery.data.notifications),
|
|
50
|
+
[settings, settingsQuery.data],
|
|
51
|
+
);
|
|
52
|
+
|
|
43
53
|
const setTypeSettings = (type: string, next: ProfileNotificationSettings) => {
|
|
44
54
|
setSettings((current) => {
|
|
45
55
|
const copy = { ...current };
|
|
@@ -93,6 +103,7 @@ export const useNotificationPreferences = ({
|
|
|
93
103
|
me,
|
|
94
104
|
types: notificationTypesQuery.data ?? [],
|
|
95
105
|
settings,
|
|
106
|
+
dirty,
|
|
96
107
|
setTypeSettings,
|
|
97
108
|
save,
|
|
98
109
|
saving,
|
|
@@ -169,8 +169,10 @@ export const AdminApiKeys = () => {
|
|
|
169
169
|
const cardLabels = {
|
|
170
170
|
expiresLabel: t('admin.apiKeys.expiresAt', { defaultValue: 'Expires at' }),
|
|
171
171
|
neverLabel: t('common.states.never', { defaultValue: 'Never' }),
|
|
172
|
-
revokeLabel: t('
|
|
173
|
-
revokedLabel: t('
|
|
172
|
+
revokeLabel: t('settings.accessTokens.revoke', { defaultValue: 'Revoke' }),
|
|
173
|
+
revokedLabel: t('settings.accessTokens.revoked', {
|
|
174
|
+
defaultValue: 'Revoked',
|
|
175
|
+
}),
|
|
174
176
|
noScopesLabel: t('admin.apiKeys.noScopes', { defaultValue: 'No scopes' }),
|
|
175
177
|
};
|
|
176
178
|
|
|
@@ -214,7 +216,9 @@ export const AdminApiKeys = () => {
|
|
|
214
216
|
</div>
|
|
215
217
|
<div className="space-y-2">
|
|
216
218
|
<Label htmlFor="svc-expiration">
|
|
217
|
-
{t('
|
|
219
|
+
{t('settings.accessTokens.expiration', {
|
|
220
|
+
defaultValue: 'Expiration',
|
|
221
|
+
})}
|
|
218
222
|
</Label>
|
|
219
223
|
<select
|
|
220
224
|
id="svc-expiration"
|
|
@@ -226,9 +230,12 @@ export const AdminApiKeys = () => {
|
|
|
226
230
|
>
|
|
227
231
|
{EXPIRATION_OPTIONS.map((option) => (
|
|
228
232
|
<option key={option.value} value={option.value}>
|
|
229
|
-
{t(
|
|
230
|
-
|
|
231
|
-
|
|
233
|
+
{t(
|
|
234
|
+
`settings.accessTokens.expirationOptions.${option.labelKey}`,
|
|
235
|
+
{
|
|
236
|
+
defaultValue: EXPIRATION_OPTION_DEFAULTS[option.labelKey],
|
|
237
|
+
},
|
|
238
|
+
)}
|
|
232
239
|
</option>
|
|
233
240
|
))}
|
|
234
241
|
</select>
|
|
@@ -324,7 +331,9 @@ export const AdminApiKeys = () => {
|
|
|
324
331
|
|
|
325
332
|
<Button variant="default" disabled={creating} action={create}>
|
|
326
333
|
{creating
|
|
327
|
-
? t('
|
|
334
|
+
? t('settings.accessTokens.creating', {
|
|
335
|
+
defaultValue: 'Creating...',
|
|
336
|
+
})
|
|
328
337
|
: t('admin.apiKeys.create', {
|
|
329
338
|
defaultValue: 'Create Service Token',
|
|
330
339
|
})}
|
|
@@ -333,7 +342,7 @@ export const AdminApiKeys = () => {
|
|
|
333
342
|
{createdToken ? (
|
|
334
343
|
<div className="rounded-md border p-3">
|
|
335
344
|
<p className="text-sm font-semibold">
|
|
336
|
-
{t('
|
|
345
|
+
{t('settings.accessTokens.copyWarning', {
|
|
337
346
|
defaultValue:
|
|
338
347
|
'Copy this token now. It will not be shown again.',
|
|
339
348
|
})}
|
|
@@ -342,7 +351,9 @@ export const AdminApiKeys = () => {
|
|
|
342
351
|
<code className="break-all text-sm">{createdToken}</code>
|
|
343
352
|
<button
|
|
344
353
|
type="button"
|
|
345
|
-
title={t('
|
|
354
|
+
title={t('settings.accessTokens.copy', {
|
|
355
|
+
defaultValue: 'Copy',
|
|
356
|
+
})}
|
|
346
357
|
onClick={() => void navigator.clipboard.writeText(createdToken)}
|
|
347
358
|
>
|
|
348
359
|
<Copy className="size-4" />
|
|
@@ -328,14 +328,14 @@ export function AdminConfigurationEmail() {
|
|
|
328
328
|
</label>
|
|
329
329
|
<Button
|
|
330
330
|
variant="secondary"
|
|
331
|
-
title={t('configuration.email.
|
|
331
|
+
title={t('configuration.email.testTitle')}
|
|
332
332
|
action={handleSendTest}
|
|
333
333
|
disabled={sending}
|
|
334
334
|
data-testid="admin-email-send-test"
|
|
335
335
|
>
|
|
336
336
|
{sending
|
|
337
337
|
? t('common.states.loading')
|
|
338
|
-
: t('configuration.email.
|
|
338
|
+
: t('configuration.email.testTitle')}
|
|
339
339
|
</Button>
|
|
340
340
|
</div>
|
|
341
341
|
<p className="mt-3 text-xs opacity-70">
|
|
@@ -171,7 +171,8 @@ export function AdminConfigurationSso() {
|
|
|
171
171
|
<div>
|
|
172
172
|
<p className="font-medium">{item.name}</p>
|
|
173
173
|
<p className="text-muted-foreground text-xs">
|
|
174
|
-
{t(`configuration.sso.
|
|
174
|
+
{t(`configuration.sso.types.${item.kind}.title`)} ·{' '}
|
|
175
|
+
{item.id}
|
|
175
176
|
</p>
|
|
176
177
|
</div>
|
|
177
178
|
<div className="flex gap-2">
|
|
@@ -234,6 +234,7 @@ export function NotificationPreferences() {
|
|
|
234
234
|
saving,
|
|
235
235
|
status,
|
|
236
236
|
clearStatus,
|
|
237
|
+
dirty,
|
|
237
238
|
} = useNotificationPreferences({
|
|
238
239
|
ensurePush: vapidKey
|
|
239
240
|
? async () => {
|
|
@@ -282,19 +283,44 @@ export function NotificationPreferences() {
|
|
|
282
283
|
</Toast>
|
|
283
284
|
) : null}
|
|
284
285
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
data-testid="settings-save-button"
|
|
286
|
+
{dirty ? (
|
|
287
|
+
// Sticky so the save control stays reachable when the form is
|
|
288
|
+
// longer than the viewport (the "where do I save this?" gap).
|
|
289
|
+
<div
|
|
290
|
+
data-testid="settings-unsaved-bar"
|
|
291
|
+
className="border-border bg-surface sticky bottom-0 z-10 mt-4 flex items-center justify-between gap-4 rounded-t-lg border-t p-3 shadow-lg"
|
|
292
292
|
>
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
293
|
+
<p className="text-sm font-medium">
|
|
294
|
+
{t('settings.notifications.unsavedChanges', {
|
|
295
|
+
defaultValue: 'You have unsaved changes.',
|
|
296
|
+
})}
|
|
297
|
+
</p>
|
|
298
|
+
<Button
|
|
299
|
+
variant="default"
|
|
300
|
+
action={save}
|
|
301
|
+
disabled={saving}
|
|
302
|
+
data-testid="settings-save-button"
|
|
303
|
+
>
|
|
304
|
+
{saving
|
|
305
|
+
? t('common.submitting', { defaultValue: 'Submitting…' })
|
|
306
|
+
: t('common.submit', { defaultValue: 'Submit' })}
|
|
307
|
+
</Button>
|
|
308
|
+
</div>
|
|
309
|
+
) : (
|
|
310
|
+
<div className="pt-3">
|
|
311
|
+
<Button
|
|
312
|
+
variant="default"
|
|
313
|
+
className="w-full"
|
|
314
|
+
action={save}
|
|
315
|
+
disabled={saving}
|
|
316
|
+
data-testid="settings-save-button"
|
|
317
|
+
>
|
|
318
|
+
{saving
|
|
319
|
+
? t('common.submitting', { defaultValue: 'Submitting…' })
|
|
320
|
+
: t('common.submit', { defaultValue: 'Submit' })}
|
|
321
|
+
</Button>
|
|
322
|
+
</div>
|
|
323
|
+
)}
|
|
298
324
|
</section>
|
|
299
325
|
);
|
|
300
326
|
}
|