@byline/admin 2.5.2 → 2.6.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/fields/array/array-field.d.ts +14 -0
- package/dist/fields/array/array-field.js +177 -0
- package/dist/fields/array/array-field.module.js +11 -0
- package/dist/fields/array/array-field_module.css +32 -0
- package/dist/fields/blocks/blocks-field.d.ts +13 -0
- package/dist/fields/blocks/blocks-field.js +245 -0
- package/dist/fields/blocks/blocks-field.module.js +26 -0
- package/dist/fields/blocks/blocks-field_module.css +107 -0
- package/dist/fields/checkbox/checkbox-field.d.ts +16 -0
- package/dist/fields/checkbox/checkbox-field.js +28 -0
- package/dist/fields/checkbox/checkbox-field.module.js +6 -0
- package/dist/fields/checkbox/checkbox-field_module.css +4 -0
- package/dist/fields/column-formatter.d.ts +20 -0
- package/dist/fields/column-formatter.js +15 -0
- package/dist/fields/date-time-formatter.d.ts +16 -0
- package/dist/fields/date-time-formatter.js +8 -0
- package/dist/fields/datetime/datetime-field.d.ts +16 -0
- package/dist/fields/datetime/datetime-field.js +37 -0
- package/dist/fields/datetime/datetime-field.module.js +5 -0
- package/dist/fields/datetime/datetime-field_module.css +4 -0
- package/dist/fields/draggable-context-menu.d.ts +6 -0
- package/dist/fields/draggable-context-menu.js +85 -0
- package/dist/fields/draggable-context-menu.module.js +15 -0
- package/dist/fields/draggable-context-menu_module.css +91 -0
- package/dist/fields/field-helpers.d.ts +26 -0
- package/dist/fields/field-helpers.js +50 -0
- package/dist/fields/field-renderer.d.ts +37 -0
- package/dist/fields/field-renderer.js +206 -0
- package/dist/fields/field-renderer.module.js +8 -0
- package/dist/fields/field-renderer_module.css +11 -0
- package/dist/fields/field-services-context.d.ts +16 -0
- package/dist/fields/field-services-context.js +13 -0
- package/dist/fields/field-services-types.d.ts +63 -0
- package/dist/fields/field-services-types.js +1 -0
- package/dist/fields/file/file-field.d.ts +19 -0
- package/dist/fields/file/file-field.js +225 -0
- package/dist/fields/file/file-field.module.js +18 -0
- package/dist/fields/file/file-field_module.css +131 -0
- package/dist/fields/file/file-upload-field.d.ts +21 -0
- package/dist/fields/file/file-upload-field.js +130 -0
- package/dist/fields/file/file-upload-field.module.js +15 -0
- package/dist/fields/file/file-upload-field_module.css +74 -0
- package/dist/fields/group/group-field.d.ts +15 -0
- package/dist/fields/group/group-field.js +59 -0
- package/dist/fields/group/group-field.module.js +9 -0
- package/dist/fields/group/group-field_module.css +27 -0
- package/dist/fields/image/image-field.d.ts +19 -0
- package/dist/fields/image/image-field.js +241 -0
- package/dist/fields/image/image-field.module.js +22 -0
- package/dist/fields/image/image-field_module.css +121 -0
- package/dist/fields/image/image-upload-field.d.ts +21 -0
- package/dist/fields/image/image-upload-field.js +190 -0
- package/dist/fields/image/image-upload-field.module.js +19 -0
- package/dist/fields/image/image-upload-field_module.css +92 -0
- package/dist/fields/local-date-time.d.ts +27 -0
- package/dist/fields/local-date-time.js +49 -0
- package/dist/fields/locale-badge.d.ts +18 -0
- package/dist/fields/locale-badge.js +10 -0
- package/dist/fields/locale-badge.module.js +5 -0
- package/dist/fields/locale-badge_module.css +27 -0
- package/dist/fields/numerical/numerical-field.d.ts +18 -0
- package/dist/fields/numerical/numerical-field.js +74 -0
- package/dist/fields/relation/relation-display.d.ts +40 -0
- package/dist/fields/relation/relation-display.js +61 -0
- package/dist/fields/relation/relation-display.module.js +9 -0
- package/dist/fields/relation/relation-display_module.css +21 -0
- package/dist/fields/relation/relation-field.d.ts +18 -0
- package/dist/fields/relation/relation-field.js +138 -0
- package/dist/fields/relation/relation-field.module.js +13 -0
- package/dist/fields/relation/relation-field_module.css +62 -0
- package/dist/fields/relation/relation-picker.d.ts +59 -0
- package/dist/fields/relation/relation-picker.js +237 -0
- package/dist/fields/relation/relation-picker.module.js +26 -0
- package/dist/fields/relation/relation-picker_module.css +124 -0
- package/dist/fields/relation/relation-summary.d.ts +31 -0
- package/dist/fields/relation/relation-summary.js +50 -0
- package/dist/fields/relation/relation-summary.module.js +11 -0
- package/dist/fields/relation/relation-summary_module.css +37 -0
- package/dist/fields/select/select-field.d.ts +16 -0
- package/dist/fields/select/select-field.js +50 -0
- package/dist/fields/select/select-field.module.js +5 -0
- package/dist/fields/select/select-field_module.css +4 -0
- package/dist/fields/sortable-item.d.ts +15 -0
- package/dist/fields/sortable-item.js +81 -0
- package/dist/fields/sortable-item.module.js +22 -0
- package/dist/fields/sortable-item_module.css +124 -0
- package/dist/fields/text/text-field.d.ts +20 -0
- package/dist/fields/text/text-field.js +104 -0
- package/dist/fields/text/text-field.module.js +6 -0
- package/dist/fields/text/text-field_module.css +5 -0
- package/dist/fields/text-area/text-area-field.d.ts +20 -0
- package/dist/fields/text-area/text-area-field.js +105 -0
- package/dist/fields/text-area/text-area-field.module.js +6 -0
- package/dist/fields/text-area/text-area-field_module.css +5 -0
- package/dist/fields/use-field-change-handler.d.ts +23 -0
- package/dist/fields/use-field-change-handler.js +52 -0
- package/dist/forms/document-actions.d.ts +48 -0
- package/dist/forms/document-actions.js +475 -0
- package/dist/forms/document-actions.module.js +34 -0
- package/dist/forms/document-actions_module.css +118 -0
- package/dist/forms/form-context.d.ts +89 -0
- package/dist/forms/form-context.js +466 -0
- package/dist/forms/form-renderer.d.ts +98 -0
- package/dist/forms/form-renderer.js +597 -0
- package/dist/forms/form-renderer.module.js +46 -0
- package/dist/forms/form-renderer_module.css +245 -0
- package/dist/forms/navigation-guard.d.ts +54 -0
- package/dist/forms/navigation-guard.js +22 -0
- package/dist/forms/path-widget.d.ts +36 -0
- package/dist/forms/path-widget.js +116 -0
- package/dist/forms/path-widget.module.js +8 -0
- package/dist/forms/path-widget_module.css +29 -0
- package/dist/forms/upload-executor.d.ts +57 -0
- package/dist/forms/upload-executor.js +94 -0
- package/dist/lib/translate-validation-error.d.ts +36 -0
- package/dist/lib/translate-validation-error.js +11 -0
- package/dist/modules/admin-account/commands.d.ts +2 -1
- package/dist/modules/admin-account/commands.js +13 -2
- package/dist/modules/admin-account/components/change-password.js +45 -36
- package/dist/modules/admin-account/components/container.js +185 -134
- package/dist/modules/admin-account/components/preferences.d.ts +8 -0
- package/dist/modules/admin-account/components/preferences.js +152 -0
- package/dist/modules/admin-account/components/preferences.module.js +11 -0
- package/dist/modules/admin-account/components/preferences_module.css +41 -0
- package/dist/modules/admin-account/components/update.js +50 -31
- package/dist/modules/admin-account/index.d.ts +3 -3
- package/dist/modules/admin-account/index.js +2 -2
- package/dist/modules/admin-account/schemas.d.ts +4 -0
- package/dist/modules/admin-account/schemas.js +4 -1
- package/dist/modules/admin-account/service.d.ts +1 -0
- package/dist/modules/admin-account/service.js +8 -0
- package/dist/modules/admin-permissions/components/inspector.js +31 -41
- package/dist/modules/admin-roles/components/create.js +43 -26
- package/dist/modules/admin-roles/components/permissions.js +26 -35
- package/dist/modules/admin-roles/components/update.js +26 -16
- package/dist/modules/admin-users/components/create.js +60 -40
- package/dist/modules/admin-users/components/roles.js +9 -15
- package/dist/modules/admin-users/components/set-password.js +30 -31
- package/dist/modules/admin-users/components/update.js +58 -39
- package/dist/modules/admin-users/dto.js +1 -0
- package/dist/modules/admin-users/repository.d.ts +17 -0
- package/dist/modules/admin-users/schemas.d.ts +4 -0
- package/dist/modules/admin-users/schemas.js +6 -2
- package/dist/modules/auth/components/sign-in-form.js +10 -8
- package/dist/presentation/group.d.ts +27 -0
- package/dist/presentation/group.js +14 -0
- package/dist/presentation/group.module.js +6 -0
- package/dist/presentation/group_module.css +19 -0
- package/dist/presentation/row.d.ts +25 -0
- package/dist/presentation/row.js +8 -0
- package/dist/presentation/row.module.js +5 -0
- package/dist/presentation/row_module.css +18 -0
- package/dist/presentation/tabs.d.ts +25 -0
- package/dist/presentation/tabs.js +39 -0
- package/dist/presentation/tabs.module.js +10 -0
- package/dist/presentation/tabs_module.css +68 -0
- package/dist/react.d.ts +66 -0
- package/dist/react.js +36 -0
- package/dist/services/admin-services-types.d.ts +16 -0
- package/dist/widgets/diff-viewer/diff-modal.d.ts +22 -0
- package/dist/widgets/diff-viewer/diff-modal.js +149 -0
- package/dist/widgets/diff-viewer/diff-modal.module.js +14 -0
- package/dist/widgets/diff-viewer/diff-modal_module.css +56 -0
- package/dist/widgets/status-badge/status-badge.d.ts +25 -0
- package/dist/widgets/status-badge/status-badge.js +37 -0
- package/dist/widgets/status-badge/status-badge.module.js +7 -0
- package/dist/widgets/status-badge/status-badge_module.css +20 -0
- package/package.json +14 -4
- package/src/fields/array/array-field.module.css +48 -0
- package/src/fields/array/array-field.tsx +267 -0
- package/src/fields/blocks/blocks-field.module.css +148 -0
- package/src/fields/blocks/blocks-field.tsx +323 -0
- package/src/fields/checkbox/checkbox-field.module.css +4 -0
- package/src/fields/checkbox/checkbox-field.tsx +54 -0
- package/src/fields/column-formatter.tsx +31 -0
- package/src/fields/date-time-formatter.tsx +22 -0
- package/src/fields/datetime/datetime-field.module.css +13 -0
- package/src/fields/datetime/datetime-field.tsx +54 -0
- package/src/fields/draggable-context-menu.module.css +127 -0
- package/src/fields/draggable-context-menu.tsx +87 -0
- package/src/fields/field-helpers.ts +69 -0
- package/src/fields/field-renderer.module.css +22 -0
- package/src/fields/field-renderer.tsx +288 -0
- package/src/fields/field-services-context.tsx +35 -0
- package/src/fields/field-services-types.ts +68 -0
- package/src/fields/file/file-field.module.css +153 -0
- package/src/fields/file/file-field.tsx +286 -0
- package/src/fields/file/file-upload-field.module.css +101 -0
- package/src/fields/file/file-upload-field.tsx +187 -0
- package/src/fields/group/group-field.module.css +43 -0
- package/src/fields/group/group-field.tsx +84 -0
- package/src/fields/image/image-field.module.css +155 -0
- package/src/fields/image/image-field.tsx +306 -0
- package/src/fields/image/image-upload-field.module.css +123 -0
- package/src/fields/image/image-upload-field.tsx +276 -0
- package/src/fields/local-date-time.tsx +88 -0
- package/src/fields/locale-badge.module.css +37 -0
- package/src/fields/locale-badge.tsx +32 -0
- package/src/fields/numerical/numerical-field.tsx +114 -0
- package/src/fields/relation/relation-display.module.css +36 -0
- package/src/fields/relation/relation-display.tsx +138 -0
- package/src/fields/relation/relation-field.module.css +83 -0
- package/src/fields/relation/relation-field.tsx +211 -0
- package/src/fields/relation/relation-picker.module.css +168 -0
- package/src/fields/relation/relation-picker.tsx +343 -0
- package/src/fields/relation/relation-summary.module.css +55 -0
- package/src/fields/relation/relation-summary.tsx +123 -0
- package/src/fields/select/select-field.module.css +13 -0
- package/src/fields/select/select-field.tsx +61 -0
- package/src/fields/sortable-item.module.css +167 -0
- package/src/fields/sortable-item.tsx +106 -0
- package/src/fields/text/text-field.module.css +13 -0
- package/src/fields/text/text-field.tsx +146 -0
- package/src/fields/text-area/text-area-field.module.css +13 -0
- package/src/fields/text-area/text-area-field.tsx +147 -0
- package/src/fields/use-field-change-handler.ts +112 -0
- package/src/forms/document-actions.module.css +160 -0
- package/src/forms/document-actions.tsx +482 -0
- package/src/forms/form-context.tsx +704 -0
- package/src/forms/form-renderer.module.css +321 -0
- package/src/forms/form-renderer.tsx +891 -0
- package/src/forms/navigation-guard.tsx +98 -0
- package/src/forms/path-widget.module.css +41 -0
- package/src/forms/path-widget.test.tsx +217 -0
- package/src/forms/path-widget.tsx +183 -0
- package/src/forms/upload-executor.ts +192 -0
- package/src/lib/translate-validation-error.ts +56 -0
- package/src/modules/admin-account/commands.ts +13 -0
- package/src/modules/admin-account/components/change-password.tsx +46 -31
- package/src/modules/admin-account/components/container.tsx +83 -38
- package/src/modules/admin-account/components/preferences.module.css +60 -0
- package/src/modules/admin-account/components/preferences.tsx +203 -0
- package/src/modules/admin-account/components/update.tsx +53 -27
- package/src/modules/admin-account/index.ts +3 -0
- package/src/modules/admin-account/schemas.ts +13 -0
- package/src/modules/admin-account/service.ts +12 -0
- package/src/modules/admin-permissions/components/inspector.tsx +22 -14
- package/src/modules/admin-roles/components/create.tsx +51 -23
- package/src/modules/admin-roles/components/permissions.tsx +25 -21
- package/src/modules/admin-roles/components/update.tsx +37 -19
- package/src/modules/admin-users/components/create.tsx +63 -34
- package/src/modules/admin-users/components/roles.tsx +9 -8
- package/src/modules/admin-users/components/set-password.tsx +34 -28
- package/src/modules/admin-users/components/update.tsx +58 -36
- package/src/modules/admin-users/dto.ts +1 -0
- package/src/modules/admin-users/repository.ts +17 -0
- package/src/modules/admin-users/schemas.ts +12 -0
- package/src/modules/auth/components/sign-in-form.tsx +14 -8
- package/src/presentation/group.module.css +41 -0
- package/src/presentation/group.tsx +40 -0
- package/src/presentation/row.module.css +32 -0
- package/src/presentation/row.tsx +33 -0
- package/src/presentation/tabs.module.css +107 -0
- package/src/presentation/tabs.tsx +84 -0
- package/src/react.ts +84 -0
- package/src/services/admin-services-types.ts +18 -0
- package/src/widgets/diff-viewer/diff-modal.module.css +79 -0
- package/src/widgets/diff-viewer/diff-modal.tsx +186 -0
- package/src/widgets/status-badge/status-badge.module.css +31 -0
- package/src/widgets/status-badge/status-badge.tsx +71 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Map a stable validation-error code (emitted by a `@byline/core/validation`
|
|
10
|
+
* schema) onto its translation. Returns the original input unchanged when
|
|
11
|
+
* the code is not in the map, so non-coded error messages (free-form
|
|
12
|
+
* Zod messages, server-supplied strings) pass through.
|
|
13
|
+
*
|
|
14
|
+
* Why a separate translator: `@byline/core` stays i18n-agnostic — schemas
|
|
15
|
+
* emit codes, not text — so it has no dependency on `@byline/i18n` or
|
|
16
|
+
* any locale data. This package owns the translation surface and keeps
|
|
17
|
+
* the mapping in one place, so callers across the admin shell don't
|
|
18
|
+
* each maintain their own code-to-key lookup.
|
|
19
|
+
*
|
|
20
|
+
* Adding a new code: extend the source schema in `@byline/core/validation`
|
|
21
|
+
* and add the matching key here.
|
|
22
|
+
*/
|
|
23
|
+
import type { UseTranslationReturn } from '@byline/i18n/react';
|
|
24
|
+
type Translate = UseTranslationReturn['t'];
|
|
25
|
+
/**
|
|
26
|
+
* Translate a validation error code into the active locale's message.
|
|
27
|
+
*
|
|
28
|
+
* Pass the raw error string straight out of Zod (e.g. via
|
|
29
|
+
* `firstError(field.state.meta.errors)`). When the string matches a
|
|
30
|
+
* known code, the corresponding translation is returned; otherwise the
|
|
31
|
+
* input flows through unchanged.
|
|
32
|
+
*
|
|
33
|
+
* Designed for the `errorText={…}` slot on form inputs.
|
|
34
|
+
*/
|
|
35
|
+
export declare function translateValidationError(t: Translate, message: string | undefined): string | undefined;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const VALIDATION_CODE_KEYS = {
|
|
2
|
+
'password.tooShort': 'validation.password.tooShort',
|
|
3
|
+
'password.tooLong': 'validation.password.tooLong',
|
|
4
|
+
'password.complexity': 'validation.password.complexity'
|
|
5
|
+
};
|
|
6
|
+
function translateValidationError(t, message) {
|
|
7
|
+
if (null == message) return message;
|
|
8
|
+
const key = VALIDATION_CODE_KEYS[message];
|
|
9
|
+
return key ? t(key) : message;
|
|
10
|
+
}
|
|
11
|
+
export { translateValidationError };
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { type Command } from '../../lib/create-command.js';
|
|
9
9
|
import type { AdminStore } from '../../store.js';
|
|
10
|
-
import type { AccountResponse, ChangeAccountPasswordRequest, GetAccountRequest, UpdateAccountRequest } from './schemas.js';
|
|
10
|
+
import type { AccountResponse, ChangeAccountPasswordRequest, GetAccountRequest, SetPreferredLocaleRequest, UpdateAccountRequest } from './schemas.js';
|
|
11
11
|
/**
|
|
12
12
|
* Transport-agnostic commands for admin-account self-service.
|
|
13
13
|
*
|
|
@@ -25,3 +25,4 @@ export interface AdminAccountCommandDeps {
|
|
|
25
25
|
export declare const getAccountCommand: Command<GetAccountRequest, AccountResponse, AdminAccountCommandDeps>;
|
|
26
26
|
export declare const updateAccountCommand: Command<UpdateAccountRequest, AccountResponse, AdminAccountCommandDeps>;
|
|
27
27
|
export declare const changeAccountPasswordCommand: Command<ChangeAccountPasswordRequest, AccountResponse, AdminAccountCommandDeps>;
|
|
28
|
+
export declare const setPreferredLocaleCommand: Command<SetPreferredLocaleRequest, AccountResponse, AdminAccountCommandDeps>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createCommand } from "../../lib/create-command.js";
|
|
2
2
|
import { adminUserResponseSchema } from "../admin-users/schemas.js";
|
|
3
|
-
import { changeAccountPasswordRequestSchema, getAccountRequestSchema, updateAccountRequestSchema } from "./schemas.js";
|
|
3
|
+
import { changeAccountPasswordRequestSchema, getAccountRequestSchema, setPreferredLocaleRequestSchema, updateAccountRequestSchema } from "./schemas.js";
|
|
4
4
|
import { AdminAccountService } from "./service.js";
|
|
5
5
|
function serviceOf(deps) {
|
|
6
6
|
return new AdminAccountService({
|
|
@@ -40,4 +40,15 @@ const changeAccountPasswordCommand = createCommand({
|
|
|
40
40
|
},
|
|
41
41
|
handler: ({ input, deps, actor })=>serviceOf(deps).changePassword(actor.id, input)
|
|
42
42
|
});
|
|
43
|
-
|
|
43
|
+
const setPreferredLocaleCommand = createCommand({
|
|
44
|
+
method: 'setPreferredLocale',
|
|
45
|
+
auth: {
|
|
46
|
+
authenticated: true
|
|
47
|
+
},
|
|
48
|
+
schemas: {
|
|
49
|
+
input: setPreferredLocaleRequestSchema,
|
|
50
|
+
output: adminUserResponseSchema
|
|
51
|
+
},
|
|
52
|
+
handler: ({ input, deps, actor })=>serviceOf(deps).setPreferredLocale(actor.id, input.locale)
|
|
53
|
+
});
|
|
54
|
+
export { changeAccountPasswordCommand, getAccountCommand, setPreferredLocaleCommand, updateAccountCommand };
|
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useState } from "react";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
4
|
import { revalidateLogic, useForm } from "@tanstack/react-form-start";
|
|
5
5
|
import { passwordSchema } from "@byline/core/validation";
|
|
6
|
+
import { useTranslation } from "@byline/i18n/react";
|
|
6
7
|
import { Alert, Button, InputPassword, LoaderEllipsis } from "@byline/ui/react";
|
|
7
8
|
import classnames from "classnames";
|
|
8
9
|
import { z } from "zod";
|
|
10
|
+
import { translateValidationError } from "../../../lib/translate-validation-error.js";
|
|
9
11
|
import { useBylineAdminServices } from "../../../services/admin-services-context.js";
|
|
10
12
|
import change_password_module from "./change-password.module.js";
|
|
11
|
-
const changePasswordFormSchema = z.object({
|
|
12
|
-
currentPassword: z.string().min(1, {
|
|
13
|
-
message: 'Please enter your current password'
|
|
14
|
-
}),
|
|
15
|
-
newPassword: passwordSchema,
|
|
16
|
-
confirm: z.string({
|
|
17
|
-
message: 'Please confirm the new password'
|
|
18
|
-
})
|
|
19
|
-
}).refine((v)=>v.newPassword === v.confirm, {
|
|
20
|
-
message: 'New passwords do not match',
|
|
21
|
-
path: [
|
|
22
|
-
'confirm'
|
|
23
|
-
]
|
|
24
|
-
});
|
|
25
13
|
function ChangeAccountPassword({ account, onClose, onSuccess }) {
|
|
26
14
|
const { changeAccountPassword } = useBylineAdminServices();
|
|
15
|
+
const { t } = useTranslation('byline-admin');
|
|
27
16
|
const [formError, setFormError] = useState(null);
|
|
28
17
|
const [successMessage, setSuccessMessage] = useState(null);
|
|
18
|
+
const changePasswordFormSchema = useMemo(()=>z.object({
|
|
19
|
+
currentPassword: z.string().min(1, {
|
|
20
|
+
message: t('account.changePassword.errors.currentRequired')
|
|
21
|
+
}),
|
|
22
|
+
newPassword: passwordSchema,
|
|
23
|
+
confirm: z.string({
|
|
24
|
+
message: t('account.changePassword.errors.confirmRequired')
|
|
25
|
+
})
|
|
26
|
+
}).refine((v)=>v.newPassword === v.confirm, {
|
|
27
|
+
message: t('account.changePassword.errors.mismatch'),
|
|
28
|
+
path: [
|
|
29
|
+
'confirm'
|
|
30
|
+
]
|
|
31
|
+
}), [
|
|
32
|
+
t
|
|
33
|
+
]);
|
|
29
34
|
const form = useForm({
|
|
30
35
|
defaultValues: {
|
|
31
36
|
currentPassword: '',
|
|
@@ -50,7 +55,7 @@ function ChangeAccountPassword({ account, onClose, onSuccess }) {
|
|
|
50
55
|
newPassword: value.newPassword
|
|
51
56
|
}
|
|
52
57
|
});
|
|
53
|
-
setSuccessMessage('
|
|
58
|
+
setSuccessMessage(t('account.changePassword.feedback.updated'));
|
|
54
59
|
form.reset({
|
|
55
60
|
currentPassword: '',
|
|
56
61
|
newPassword: '',
|
|
@@ -59,19 +64,23 @@ function ChangeAccountPassword({ account, onClose, onSuccess }) {
|
|
|
59
64
|
onSuccess?.(updated);
|
|
60
65
|
} catch (err) {
|
|
61
66
|
const code = getErrorCode(err);
|
|
62
|
-
if ('admin.account.invalidCurrentPassword' === code)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
...meta
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
if ('admin.account.invalidCurrentPassword' === code) {
|
|
68
|
+
const message = t('account.changePassword.errors.currentIncorrect');
|
|
69
|
+
form.setFieldMeta('currentPassword', (meta)=>({
|
|
70
|
+
...meta,
|
|
71
|
+
errorMap: {
|
|
72
|
+
...meta.errorMap,
|
|
73
|
+
onServer: message
|
|
74
|
+
},
|
|
75
|
+
errors: [
|
|
76
|
+
message
|
|
77
|
+
]
|
|
78
|
+
}));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if ('admin.users.versionConflict' === code) return void setFormError(t('common.errors.versionConflict'));
|
|
82
|
+
if ('admin.account.notFound' === code) return void setFormError(t('common.errors.accountNotFound'));
|
|
83
|
+
setFormError(t('account.changePassword.errors.couldNotChange'));
|
|
75
84
|
}
|
|
76
85
|
}
|
|
77
86
|
});
|
|
@@ -96,12 +105,12 @@ function ChangeAccountPassword({ account, onClose, onSuccess }) {
|
|
|
96
105
|
}) : null,
|
|
97
106
|
/*#__PURE__*/ jsx("p", {
|
|
98
107
|
className: "muted",
|
|
99
|
-
children:
|
|
108
|
+
children: t('account.changePassword.intro')
|
|
100
109
|
}),
|
|
101
110
|
/*#__PURE__*/ jsx(form.Field, {
|
|
102
111
|
name: "currentPassword",
|
|
103
112
|
children: (field)=>/*#__PURE__*/ jsx(InputPassword, {
|
|
104
|
-
label:
|
|
113
|
+
label: t('account.changePassword.fields.current'),
|
|
105
114
|
id: "currentPassword",
|
|
106
115
|
name: field.name,
|
|
107
116
|
value: field.state.value,
|
|
@@ -116,14 +125,14 @@ function ChangeAccountPassword({ account, onClose, onSuccess }) {
|
|
|
116
125
|
/*#__PURE__*/ jsx(form.Field, {
|
|
117
126
|
name: "newPassword",
|
|
118
127
|
children: (field)=>/*#__PURE__*/ jsx(InputPassword, {
|
|
119
|
-
label:
|
|
128
|
+
label: t('account.changePassword.fields.new'),
|
|
120
129
|
id: "newPassword",
|
|
121
130
|
name: field.name,
|
|
122
131
|
value: field.state.value,
|
|
123
132
|
onBlur: field.handleBlur,
|
|
124
133
|
onChange: (e)=>field.handleChange(e.currentTarget.value),
|
|
125
134
|
error: field.state.meta.errors.length > 0,
|
|
126
|
-
errorText: firstError(field.state.meta.errors),
|
|
135
|
+
errorText: translateValidationError(t, firstError(field.state.meta.errors)),
|
|
127
136
|
autoComplete: "new-password",
|
|
128
137
|
required: true
|
|
129
138
|
})
|
|
@@ -131,7 +140,7 @@ function ChangeAccountPassword({ account, onClose, onSuccess }) {
|
|
|
131
140
|
/*#__PURE__*/ jsx(form.Field, {
|
|
132
141
|
name: "confirm",
|
|
133
142
|
children: (field)=>/*#__PURE__*/ jsx(InputPassword, {
|
|
134
|
-
label:
|
|
143
|
+
label: t('account.changePassword.fields.confirm'),
|
|
135
144
|
id: "confirm",
|
|
136
145
|
name: field.name,
|
|
137
146
|
value: field.state.value,
|
|
@@ -152,7 +161,7 @@ function ChangeAccountPassword({ account, onClose, onSuccess }) {
|
|
|
152
161
|
size: "sm",
|
|
153
162
|
onClick: onClose,
|
|
154
163
|
className: classnames('byline-account-change-password-action', change_password_module.action),
|
|
155
|
-
children: successMessage ? '
|
|
164
|
+
children: successMessage ? t('common.actions.close') : t('common.actions.cancel')
|
|
156
165
|
}),
|
|
157
166
|
/*#__PURE__*/ jsx(form.Subscribe, {
|
|
158
167
|
selector: (state)=>({
|
|
@@ -168,7 +177,7 @@ function ChangeAccountPassword({ account, onClose, onSuccess }) {
|
|
|
168
177
|
className: classnames('byline-account-change-password-action', change_password_module.action),
|
|
169
178
|
children: true === isSubmitting ? /*#__PURE__*/ jsx(LoaderEllipsis, {
|
|
170
179
|
size: 42
|
|
171
|
-
}) : '
|
|
180
|
+
}) : t('common.actions.save')
|
|
172
181
|
})
|
|
173
182
|
})
|
|
174
183
|
]
|