@strapi/i18n 0.0.0-next.959c5589d0d3efa25d7ca014656d9ff48c173399 → 0.0.0-next.9e9a841899e6378b6f48ab8f419e4b0cc62bdf32

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.
Files changed (136) hide show
  1. package/dist/admin/chunks/SettingsPage-B6ikxVOg.js +820 -0
  2. package/dist/admin/chunks/SettingsPage-B6ikxVOg.js.map +1 -0
  3. package/dist/admin/chunks/SettingsPage-DydtYvMJ.mjs +797 -0
  4. package/dist/admin/chunks/SettingsPage-DydtYvMJ.mjs.map +1 -0
  5. package/dist/admin/chunks/de-Cm8mYdaO.mjs +64 -0
  6. package/dist/admin/chunks/de-Cm8mYdaO.mjs.map +1 -0
  7. package/dist/admin/chunks/de-nEMWvIiY.js +66 -0
  8. package/dist/admin/chunks/de-nEMWvIiY.js.map +1 -0
  9. package/dist/admin/chunks/dk-BeUFOegB.mjs +64 -0
  10. package/dist/admin/chunks/dk-BeUFOegB.mjs.map +1 -0
  11. package/dist/admin/chunks/dk-CYATLPVe.js +66 -0
  12. package/dist/admin/chunks/dk-CYATLPVe.js.map +1 -0
  13. package/dist/admin/chunks/en-CG5cUCbD.js +81 -0
  14. package/dist/admin/chunks/en-CG5cUCbD.js.map +1 -0
  15. package/dist/admin/chunks/en-eWSaCeOb.mjs +79 -0
  16. package/dist/admin/chunks/en-eWSaCeOb.mjs.map +1 -0
  17. package/dist/admin/chunks/es-CWsogTGm.js +66 -0
  18. package/dist/admin/chunks/es-CWsogTGm.js.map +1 -0
  19. package/dist/admin/chunks/es-DqF_IdAc.mjs +64 -0
  20. package/dist/admin/chunks/es-DqF_IdAc.mjs.map +1 -0
  21. package/dist/admin/chunks/fr-CC7UFcYd.js +66 -0
  22. package/dist/admin/chunks/fr-CC7UFcYd.js.map +1 -0
  23. package/dist/admin/chunks/fr-CyARbZ3c.mjs +64 -0
  24. package/dist/admin/chunks/fr-CyARbZ3c.mjs.map +1 -0
  25. package/dist/admin/chunks/index-Dch-2xao.js +2035 -0
  26. package/dist/admin/chunks/index-Dch-2xao.js.map +1 -0
  27. package/dist/admin/chunks/index-k3BHSNs0.mjs +2006 -0
  28. package/dist/admin/chunks/index-k3BHSNs0.mjs.map +1 -0
  29. package/dist/admin/chunks/ko-Ax4NSedM.mjs +63 -0
  30. package/dist/admin/chunks/ko-Ax4NSedM.mjs.map +1 -0
  31. package/dist/admin/chunks/ko-XwGmfhoq.js +65 -0
  32. package/dist/admin/chunks/ko-XwGmfhoq.js.map +1 -0
  33. package/dist/admin/chunks/pl-B-aqvMqL.mjs +64 -0
  34. package/dist/admin/chunks/pl-B-aqvMqL.mjs.map +1 -0
  35. package/dist/admin/chunks/pl-B_vzY_ZB.js +66 -0
  36. package/dist/admin/chunks/pl-B_vzY_ZB.js.map +1 -0
  37. package/dist/admin/chunks/ru-VkPjQ-Sk.mjs +66 -0
  38. package/dist/admin/chunks/ru-VkPjQ-Sk.mjs.map +1 -0
  39. package/dist/admin/chunks/ru-WzHcJV1f.js +68 -0
  40. package/dist/admin/chunks/ru-WzHcJV1f.js.map +1 -0
  41. package/dist/admin/chunks/tr-CcWp6u3w.js +66 -0
  42. package/dist/admin/chunks/tr-CcWp6u3w.js.map +1 -0
  43. package/dist/admin/chunks/tr-DcTR88c9.mjs +64 -0
  44. package/dist/admin/chunks/tr-DcTR88c9.mjs.map +1 -0
  45. package/dist/admin/chunks/zh-C9So4SGq.js +66 -0
  46. package/dist/admin/chunks/zh-C9So4SGq.js.map +1 -0
  47. package/dist/admin/chunks/zh-Hans-DnU2bhri.js +57 -0
  48. package/dist/admin/chunks/zh-Hans-DnU2bhri.js.map +1 -0
  49. package/dist/admin/chunks/zh-Hans-L3wsRegj.mjs +55 -0
  50. package/dist/admin/chunks/zh-Hans-L3wsRegj.mjs.map +1 -0
  51. package/dist/admin/chunks/zh-RZyMiPIs.mjs +64 -0
  52. package/dist/admin/chunks/zh-RZyMiPIs.mjs.map +1 -0
  53. package/dist/admin/index.js +20 -4
  54. package/dist/admin/index.js.map +1 -1
  55. package/dist/admin/index.mjs +15 -6
  56. package/dist/admin/index.mjs.map +1 -1
  57. package/dist/admin/src/components/CMHeaderActions.d.ts +2 -2
  58. package/dist/admin/src/components/LocaleListCell.d.ts +4 -4
  59. package/dist/admin/src/components/tests/CreateLocale.test.d.ts +1 -0
  60. package/dist/admin/src/components/tests/DeleteLocale.test.d.ts +1 -0
  61. package/dist/admin/src/components/tests/EditLocale.test.d.ts +1 -0
  62. package/dist/admin/src/components/tests/LocaleListCell.test.d.ts +1 -0
  63. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +1 -1
  64. package/dist/admin/src/pages/tests/SettingsPage.test.d.ts +1 -0
  65. package/dist/admin/tests/server.d.ts +1 -0
  66. package/dist/admin/tests/utils.d.ts +6 -0
  67. package/dist/server/index.js +3651 -3361
  68. package/dist/server/index.js.map +1 -1
  69. package/dist/server/index.mjs +3633 -3344
  70. package/dist/server/index.mjs.map +1 -1
  71. package/dist/server/src/index.d.ts +6 -0
  72. package/dist/server/src/index.d.ts.map +1 -1
  73. package/dist/server/src/register.d.ts.map +1 -1
  74. package/dist/server/src/services/index.d.ts +6 -0
  75. package/dist/server/src/services/index.d.ts.map +1 -1
  76. package/dist/server/src/services/localizations.d.ts +1 -1
  77. package/dist/server/src/services/localizations.d.ts.map +1 -1
  78. package/dist/server/src/services/sanitize/index.d.ts +11 -0
  79. package/dist/server/src/services/sanitize/index.d.ts.map +1 -0
  80. package/dist/server/src/utils/index.d.ts +2 -0
  81. package/dist/server/src/utils/index.d.ts.map +1 -1
  82. package/dist/shared/contracts/content-manager.d.ts +1 -1
  83. package/dist/shared/contracts/shared.d.ts +1 -1
  84. package/package.json +18 -16
  85. package/dist/_chunks/SettingsPage-D_53Ao8I.mjs +0 -554
  86. package/dist/_chunks/SettingsPage-D_53Ao8I.mjs.map +0 -1
  87. package/dist/_chunks/SettingsPage-Z94BBMrV.js +0 -574
  88. package/dist/_chunks/SettingsPage-Z94BBMrV.js.map +0 -1
  89. package/dist/_chunks/de-9eCAqqrB.mjs +0 -66
  90. package/dist/_chunks/de-9eCAqqrB.mjs.map +0 -1
  91. package/dist/_chunks/de-DtWiGdHl.js +0 -66
  92. package/dist/_chunks/de-DtWiGdHl.js.map +0 -1
  93. package/dist/_chunks/dk-2qBjxt-P.mjs +0 -66
  94. package/dist/_chunks/dk-2qBjxt-P.mjs.map +0 -1
  95. package/dist/_chunks/dk-D8C-casx.js +0 -66
  96. package/dist/_chunks/dk-D8C-casx.js.map +0 -1
  97. package/dist/_chunks/en-BKBz3tro.js +0 -81
  98. package/dist/_chunks/en-BKBz3tro.js.map +0 -1
  99. package/dist/_chunks/en-DlXfy6Gy.mjs +0 -81
  100. package/dist/_chunks/en-DlXfy6Gy.mjs.map +0 -1
  101. package/dist/_chunks/es-DS-XFGSw.js +0 -66
  102. package/dist/_chunks/es-DS-XFGSw.js.map +0 -1
  103. package/dist/_chunks/es-DlmMVaBG.mjs +0 -66
  104. package/dist/_chunks/es-DlmMVaBG.mjs.map +0 -1
  105. package/dist/_chunks/fr-3S6ke71d.mjs +0 -66
  106. package/dist/_chunks/fr-3S6ke71d.mjs.map +0 -1
  107. package/dist/_chunks/fr-BTjekDpq.js +0 -66
  108. package/dist/_chunks/fr-BTjekDpq.js.map +0 -1
  109. package/dist/_chunks/index-BGhYo_Rs.mjs +0 -1611
  110. package/dist/_chunks/index-BGhYo_Rs.mjs.map +0 -1
  111. package/dist/_chunks/index-BOvOaxo-.js +0 -1633
  112. package/dist/_chunks/index-BOvOaxo-.js.map +0 -1
  113. package/dist/_chunks/ko-DmcGUBQ3.js +0 -65
  114. package/dist/_chunks/ko-DmcGUBQ3.js.map +0 -1
  115. package/dist/_chunks/ko-qTjQ8IMw.mjs +0 -65
  116. package/dist/_chunks/ko-qTjQ8IMw.mjs.map +0 -1
  117. package/dist/_chunks/pl-B67TSHqT.mjs +0 -66
  118. package/dist/_chunks/pl-B67TSHqT.mjs.map +0 -1
  119. package/dist/_chunks/pl-Cn5RYonZ.js +0 -66
  120. package/dist/_chunks/pl-Cn5RYonZ.js.map +0 -1
  121. package/dist/_chunks/ru-BMBgVL3s.js +0 -68
  122. package/dist/_chunks/ru-BMBgVL3s.js.map +0 -1
  123. package/dist/_chunks/ru-hagMa57T.mjs +0 -68
  124. package/dist/_chunks/ru-hagMa57T.mjs.map +0 -1
  125. package/dist/_chunks/tr-CarUU76c.js +0 -66
  126. package/dist/_chunks/tr-CarUU76c.js.map +0 -1
  127. package/dist/_chunks/tr-Dw_jmkG-.mjs +0 -66
  128. package/dist/_chunks/tr-Dw_jmkG-.mjs.map +0 -1
  129. package/dist/_chunks/zh-57YM4amO.mjs +0 -66
  130. package/dist/_chunks/zh-57YM4amO.mjs.map +0 -1
  131. package/dist/_chunks/zh-CukOviB0.js +0 -66
  132. package/dist/_chunks/zh-CukOviB0.js.map +0 -1
  133. package/dist/_chunks/zh-Hans-DSHIXAa3.js +0 -57
  134. package/dist/_chunks/zh-Hans-DSHIXAa3.js.map +0 -1
  135. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs +0 -57
  136. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/i18n",
3
- "version": "0.0.0-next.959c5589d0d3efa25d7ca014656d9ff48c173399",
3
+ "version": "0.0.0-next.9e9a841899e6378b6f48ab8f419e4b0cc62bdf32",
4
4
  "description": "Create read and update content in different languages, both from the Admin Panel and from the API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,20 +42,24 @@
42
42
  "strapi-server.js"
43
43
  ],
44
44
  "scripts": {
45
- "build": "pack-up build",
45
+ "build": "run -T npm-run-all clean --parallel build:code build:types",
46
+ "build:code": "run -T rollup -c",
47
+ "build:types": "run -T run-p build:types:server build:types:admin",
48
+ "build:types:server": "run -T tsc -p server/tsconfig.build.json --emitDeclarationOnly",
49
+ "build:types:admin": "run -T tsc -p admin/tsconfig.build.json --emitDeclarationOnly",
46
50
  "clean": "run -T rimraf ./dist",
47
51
  "lint": "run -T eslint .",
48
52
  "test:front": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js",
49
53
  "test:ts:front": "run -T tsc -p admin/tsconfig.json",
50
54
  "test:unit": "run -T jest",
51
55
  "test:unit:watch": "run -T jest --watch",
52
- "watch": "pack-up watch"
56
+ "watch": "run -T rollup -c -w"
53
57
  },
54
58
  "dependencies": {
55
59
  "@reduxjs/toolkit": "1.9.7",
56
- "@strapi/design-system": "2.0.0-rc.11",
57
- "@strapi/icons": "2.0.0-rc.11",
58
- "@strapi/utils": "0.0.0-next.959c5589d0d3efa25d7ca014656d9ff48c173399",
60
+ "@strapi/design-system": "2.0.0-rc.16",
61
+ "@strapi/icons": "2.0.0-rc.16",
62
+ "@strapi/utils": "0.0.0-next.9e9a841899e6378b6f48ab8f419e4b0cc62bdf32",
59
63
  "lodash": "4.17.21",
60
64
  "qs": "6.11.1",
61
65
  "react-intl": "6.6.2",
@@ -63,11 +67,10 @@
63
67
  "yup": "0.32.9"
64
68
  },
65
69
  "devDependencies": {
66
- "@strapi/admin": "0.0.0-next.959c5589d0d3efa25d7ca014656d9ff48c173399",
67
- "@strapi/admin-test-utils": "0.0.0-next.959c5589d0d3efa25d7ca014656d9ff48c173399",
68
- "@strapi/content-manager": "0.0.0-next.959c5589d0d3efa25d7ca014656d9ff48c173399",
69
- "@strapi/pack-up": "5.0.0",
70
- "@strapi/types": "0.0.0-next.959c5589d0d3efa25d7ca014656d9ff48c173399",
70
+ "@strapi/admin": "0.0.0-next.9e9a841899e6378b6f48ab8f419e4b0cc62bdf32",
71
+ "@strapi/admin-test-utils": "0.0.0-next.9e9a841899e6378b6f48ab8f419e4b0cc62bdf32",
72
+ "@strapi/content-manager": "0.0.0-next.9e9a841899e6378b6f48ab8f419e4b0cc62bdf32",
73
+ "@strapi/types": "0.0.0-next.9e9a841899e6378b6f48ab8f419e4b0cc62bdf32",
71
74
  "@testing-library/react": "15.0.7",
72
75
  "@testing-library/user-event": "14.5.2",
73
76
  "msw": "1.3.0",
@@ -78,15 +81,15 @@
78
81
  "styled-components": "6.1.8"
79
82
  },
80
83
  "peerDependencies": {
81
- "@strapi/admin": "^5.0.0 || ^5.0.0-beta || ^5.0.0-alpha || ^5.0.0-rc",
82
- "@strapi/content-manager": "^5.0.0 || ^5.0.0-beta || ^5.0.0-alpha || ^5.0.0-rc",
84
+ "@strapi/admin": "^5.0.0",
85
+ "@strapi/content-manager": "^5.0.0",
83
86
  "react": "^17.0.0 || ^18.0.0",
84
87
  "react-dom": "^17.0.0 || ^18.0.0",
85
88
  "react-router-dom": "^6.0.0",
86
89
  "styled-components": "^6.0.0"
87
90
  },
88
91
  "engines": {
89
- "node": ">=18.0.0 <=20.x.x",
92
+ "node": ">=18.0.0 <=22.x.x",
90
93
  "npm": ">=6.0.0"
91
94
  },
92
95
  "strapi": {
@@ -95,6 +98,5 @@
95
98
  "description": "This plugin enables to create, to read and to update content in different languages, both from the Admin Panel and from the API.",
96
99
  "required": false,
97
100
  "kind": "plugin"
98
- },
99
- "gitHead": "959c5589d0d3efa25d7ca014656d9ff48c173399"
101
+ }
100
102
  }
@@ -1,554 +0,0 @@
1
- import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
- import * as React from "react";
3
- import { useNotification, useAPIErrorHandler, useAuth, Form, useForm, InputRenderer, useField, ConfirmDialog, useRBAC, Page, Layouts } from "@strapi/admin/strapi-admin";
4
- import { Modal, Button, useId, Tabs, Flex, Typography, Divider, Box, Grid, Field, SingleSelect, SingleSelectOption, Dialog, IconButton, Table, Thead, Tr, Th, VisuallyHidden, Tbody, Td, EmptyStateLayout } from "@strapi/design-system";
5
- import { EmptyDocuments } from "@strapi/icons/symbols";
6
- import { useIntl } from "react-intl";
7
- import { Plus, Check, Trash, Pencil } from "@strapi/icons";
8
- import * as yup from "yup";
9
- import { g as getTranslation, u as useCreateLocaleMutation, a as useGetDefaultLocalesQuery, b as useDeleteLocaleMutation, c as useUpdateLocaleMutation, d as useGetLocalesQuery, P as PERMISSIONS } from "./index-BGhYo_Rs.mjs";
10
- const isBaseQueryError = (error) => {
11
- return error.name !== void 0;
12
- };
13
- const CreateLocale = ({ disabled, variant = "default" }) => {
14
- const { formatMessage } = useIntl();
15
- const [visible, setVisible] = React.useState(false);
16
- return /* @__PURE__ */ jsxs(Modal.Root, { open: visible, onOpenChange: setVisible, children: [
17
- /* @__PURE__ */ jsx(Modal.Trigger, { children: /* @__PURE__ */ jsx(
18
- Button,
19
- {
20
- variant,
21
- disabled,
22
- startIcon: /* @__PURE__ */ jsx(Plus, {}),
23
- onClick: () => setVisible(true),
24
- size: "S",
25
- children: formatMessage({
26
- id: getTranslation("Settings.list.actions.add"),
27
- defaultMessage: "Add new locale"
28
- })
29
- }
30
- ) }),
31
- /* @__PURE__ */ jsx(CreateModal, { onClose: () => setVisible(false) })
32
- ] });
33
- };
34
- const LOCALE_SCHEMA = yup.object().shape({
35
- code: yup.string().nullable().required({
36
- id: "Settings.locales.modal.create.code.error",
37
- defaultMessage: "Please select a locale"
38
- }),
39
- name: yup.string().nullable().max(50, {
40
- id: "Settings.locales.modal.create.name.error.min",
41
- defaultMessage: "The locale display name can only be less than 50 characters."
42
- }).required({
43
- id: "Settings.locales.modal.create.name.error.required",
44
- defaultMessage: "Please give the locale a display name"
45
- }),
46
- isDefault: yup.boolean()
47
- });
48
- const initialFormValues = {
49
- code: "",
50
- name: "",
51
- isDefault: false
52
- };
53
- const CreateModal = ({ onClose }) => {
54
- const titleId = useId();
55
- const { toggleNotification } = useNotification();
56
- const {
57
- _unstableFormatAPIError: formatAPIError,
58
- _unstableFormatValidationErrors: formatValidationErrors
59
- } = useAPIErrorHandler();
60
- const [createLocale] = useCreateLocaleMutation();
61
- const { formatMessage } = useIntl();
62
- const refetchPermissions = useAuth("CreateModal", (state) => state.refetchPermissions);
63
- const handleSubmit = async (values, helpers) => {
64
- try {
65
- const res = await createLocale(values);
66
- if ("error" in res) {
67
- if (isBaseQueryError(res.error) && res.error.name === "ValidationError") {
68
- helpers.setErrors(formatValidationErrors(res.error));
69
- } else {
70
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
71
- }
72
- return;
73
- }
74
- toggleNotification({
75
- type: "success",
76
- message: formatMessage({
77
- id: getTranslation("Settings.locales.modal.create.success"),
78
- defaultMessage: "Created locale"
79
- })
80
- });
81
- refetchPermissions();
82
- onClose();
83
- } catch (err) {
84
- toggleNotification({
85
- type: "danger",
86
- message: formatMessage({
87
- id: "notification.error",
88
- defaultMessage: "An error occurred, please try again"
89
- })
90
- });
91
- }
92
- };
93
- return /* @__PURE__ */ jsx(Modal.Content, { children: /* @__PURE__ */ jsxs(
94
- Form,
95
- {
96
- method: "POST",
97
- initialValues: initialFormValues,
98
- validationSchema: LOCALE_SCHEMA,
99
- onSubmit: handleSubmit,
100
- children: [
101
- /* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: formatMessage({
102
- id: getTranslation("Settings.list.actions.add"),
103
- defaultMessage: "Add new locale"
104
- }) }) }),
105
- /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsxs(Tabs.Root, { variant: "simple", defaultValue: "basic", children: [
106
- /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
107
- /* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "beta", id: titleId, children: formatMessage({
108
- id: getTranslation("Settings.locales.modal.title"),
109
- defaultMessage: "Configuration"
110
- }) }),
111
- /* @__PURE__ */ jsxs(Tabs.List, { "aria-labelledby": titleId, children: [
112
- /* @__PURE__ */ jsx(Tabs.Trigger, { value: "basic", children: formatMessage({
113
- id: getTranslation("Settings.locales.modal.base"),
114
- defaultMessage: "Basic settings"
115
- }) }),
116
- /* @__PURE__ */ jsx(Tabs.Trigger, { value: "advanced", children: formatMessage({
117
- id: getTranslation("Settings.locales.modal.advanced"),
118
- defaultMessage: "Advanced settings"
119
- }) })
120
- ] })
121
- ] }),
122
- /* @__PURE__ */ jsx(Divider, {}),
123
- /* @__PURE__ */ jsxs(Box, { paddingTop: 7, paddingBottom: 7, children: [
124
- /* @__PURE__ */ jsx(Tabs.Content, { value: "basic", children: /* @__PURE__ */ jsx(BaseForm, {}) }),
125
- /* @__PURE__ */ jsx(Tabs.Content, { value: "advanced", children: /* @__PURE__ */ jsx(AdvancedForm, {}) })
126
- ] })
127
- ] }) }),
128
- /* @__PURE__ */ jsxs(Modal.Footer, { children: [
129
- /* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }) }),
130
- /* @__PURE__ */ jsx(SubmitButton, {})
131
- ] })
132
- ]
133
- }
134
- ) });
135
- };
136
- const SubmitButton = () => {
137
- const { formatMessage } = useIntl();
138
- const isSubmitting = useForm("SubmitButton", (state) => state.isSubmitting);
139
- const modified = useForm("SubmitButton", (state) => state.modified);
140
- return /* @__PURE__ */ jsx(Button, { type: "submit", startIcon: /* @__PURE__ */ jsx(Check, {}), disabled: isSubmitting || !modified, children: formatMessage({ id: "global.save", defaultMessage: "Save" }) });
141
- };
142
- const BaseForm = ({ mode = "create" }) => {
143
- const { formatMessage } = useIntl();
144
- const { toggleNotification } = useNotification();
145
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
146
- const { data: defaultLocales, error } = useGetDefaultLocalesQuery();
147
- React.useEffect(() => {
148
- if (error) {
149
- toggleNotification({
150
- type: "danger",
151
- message: formatAPIError(error)
152
- });
153
- }
154
- }, [error, formatAPIError, toggleNotification]);
155
- if (!Array.isArray(defaultLocales)) {
156
- return null;
157
- }
158
- const options = defaultLocales.map((locale) => ({
159
- label: locale.name,
160
- value: locale.code
161
- }));
162
- const translatedForm = [
163
- {
164
- disabled: mode !== "create",
165
- label: {
166
- id: getTranslation("Settings.locales.modal.create.code.label"),
167
- defaultMessage: "Locales"
168
- },
169
- name: "code",
170
- options,
171
- placeholder: {
172
- id: "components.placeholder.select",
173
- defaultMessage: "Select"
174
- },
175
- required: true,
176
- size: 6,
177
- type: "enumeration"
178
- },
179
- {
180
- hint: {
181
- id: getTranslation("Settings.locales.modal.create.name.label.description"),
182
- defaultMessage: "Locale will be displayed under that name in the administration panel"
183
- },
184
- label: {
185
- id: getTranslation("Settings.locales.modal.create.name.label"),
186
- defaultMessage: "Locale display name"
187
- },
188
- name: "name",
189
- required: true,
190
- size: 6,
191
- type: "string"
192
- }
193
- ].map((field) => ({
194
- ...field,
195
- hint: field.hint ? formatMessage(field.hint) : void 0,
196
- label: formatMessage(field.label),
197
- placeholder: field.placeholder ? formatMessage(field.placeholder) : void 0
198
- }));
199
- return /* @__PURE__ */ jsx(Grid.Root, { gap: 4, children: translatedForm.map(({ size, ...field }) => /* @__PURE__ */ jsx(Grid.Item, { col: size, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsx(FormRenderer, { ...field }) }, field.name)) });
200
- };
201
- const AdvancedForm = ({ isDefaultLocale }) => {
202
- const { formatMessage } = useIntl();
203
- const form = [
204
- {
205
- disabled: isDefaultLocale,
206
- hint: {
207
- id: getTranslation("Settings.locales.modal.advanced.setAsDefault.hint"),
208
- defaultMessage: "One default locale is required, change it by selecting another one"
209
- },
210
- label: {
211
- id: getTranslation("Settings.locales.modal.advanced.setAsDefault"),
212
- defaultMessage: "Set as default locale"
213
- },
214
- name: "isDefault",
215
- size: 6,
216
- type: "boolean"
217
- }
218
- ].map((field) => ({
219
- ...field,
220
- hint: field.hint ? formatMessage(field.hint) : void 0,
221
- label: formatMessage(field.label)
222
- }));
223
- return /* @__PURE__ */ jsx(Grid.Root, { gap: 4, children: form.map(({ size, ...field }) => /* @__PURE__ */ jsx(Grid.Item, { col: size, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsx(FormRenderer, { ...field }) }, field.name)) });
224
- };
225
- const FormRenderer = (field) => {
226
- switch (field.type) {
227
- case "enumeration":
228
- return /* @__PURE__ */ jsx(EnumerationInput, { ...field });
229
- default:
230
- return /* @__PURE__ */ jsx(InputRenderer, { ...field });
231
- }
232
- };
233
- const EnumerationInput = ({
234
- disabled,
235
- hint,
236
- label,
237
- name,
238
- options,
239
- placeholder,
240
- required
241
- }) => {
242
- const { value, error, onChange } = useField(name);
243
- const { data: defaultLocales = [] } = useGetDefaultLocalesQuery();
244
- const handleChange = (value2) => {
245
- if (Array.isArray(defaultLocales)) {
246
- const locale = defaultLocales.find((locale2) => locale2.code === value2);
247
- onChange(name, value2);
248
- onChange("name", locale.name);
249
- } else {
250
- onChange(name, value2);
251
- }
252
- };
253
- return /* @__PURE__ */ jsxs(Field.Root, { error, hint, name, required, children: [
254
- /* @__PURE__ */ jsx(Field.Label, { children: label }),
255
- /* @__PURE__ */ jsx(
256
- SingleSelect,
257
- {
258
- disabled,
259
- onChange: handleChange,
260
- placeholder,
261
- value,
262
- children: options.map((option) => /* @__PURE__ */ jsx(SingleSelectOption, { value: option.value, children: option.label }, option.value))
263
- }
264
- ),
265
- /* @__PURE__ */ jsx(Field.Error, {}),
266
- /* @__PURE__ */ jsx(Field.Hint, {})
267
- ] });
268
- };
269
- const DeleteLocale = ({ id, name }) => {
270
- const { formatMessage } = useIntl();
271
- const { toggleNotification } = useNotification();
272
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
273
- const [visible, setVisible] = React.useState(false);
274
- const [deleteLocale] = useDeleteLocaleMutation();
275
- const handleConfirm = async () => {
276
- try {
277
- const res = await deleteLocale(id);
278
- if ("error" in res) {
279
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
280
- return;
281
- }
282
- toggleNotification({
283
- type: "success",
284
- message: formatMessage({
285
- id: getTranslation("Settings.locales.modal.delete.success"),
286
- defaultMessage: "Deleted locale"
287
- })
288
- });
289
- setVisible(false);
290
- } catch (err) {
291
- toggleNotification({
292
- type: "danger",
293
- message: formatMessage({
294
- id: "notification.error",
295
- defaultMessage: "An error occurred, please try again"
296
- })
297
- });
298
- }
299
- };
300
- return /* @__PURE__ */ jsxs(Dialog.Root, { open: visible, onOpenChange: setVisible, children: [
301
- /* @__PURE__ */ jsx(Dialog.Trigger, { children: /* @__PURE__ */ jsx(
302
- IconButton,
303
- {
304
- onClick: () => setVisible(true),
305
- label: formatMessage(
306
- {
307
- id: getTranslation("Settings.list.actions.delete"),
308
- defaultMessage: "Delete {name} locale"
309
- },
310
- {
311
- name
312
- }
313
- ),
314
- variant: "ghost",
315
- children: /* @__PURE__ */ jsx(Trash, {})
316
- }
317
- ) }),
318
- /* @__PURE__ */ jsx(ConfirmDialog, { onConfirm: handleConfirm })
319
- ] });
320
- };
321
- const EditLocale = (props) => {
322
- const { formatMessage } = useIntl();
323
- const [visible, setVisible] = React.useState(false);
324
- return /* @__PURE__ */ jsxs(Fragment, { children: [
325
- /* @__PURE__ */ jsx(
326
- IconButton,
327
- {
328
- onClick: () => setVisible(true),
329
- label: formatMessage(
330
- {
331
- id: getTranslation("Settings.list.actions.edit"),
332
- defaultMessage: "Edit {name} locale"
333
- },
334
- {
335
- name: props.name
336
- }
337
- ),
338
- variant: "ghost",
339
- children: /* @__PURE__ */ jsx(Pencil, {})
340
- }
341
- ),
342
- /* @__PURE__ */ jsx(EditModal, { ...props, open: visible, onOpenChange: setVisible })
343
- ] });
344
- };
345
- const EditModal = ({ id, code, isDefault, name, open, onOpenChange }) => {
346
- const { toggleNotification } = useNotification();
347
- const {
348
- _unstableFormatAPIError: formatAPIError,
349
- _unstableFormatValidationErrors: formatValidationErrors
350
- } = useAPIErrorHandler();
351
- const refetchPermissions = useAuth("EditModal", (state) => state.refetchPermissions);
352
- const { formatMessage } = useIntl();
353
- const titleId = useId();
354
- const [updateLocale] = useUpdateLocaleMutation();
355
- const handleSubmit = async ({ code: _code, ...data }, helpers) => {
356
- try {
357
- const res = await updateLocale({
358
- id,
359
- ...data
360
- });
361
- if ("error" in res) {
362
- if (isBaseQueryError(res.error) && res.error.name === "ValidationError") {
363
- helpers.setErrors(formatValidationErrors(res.error));
364
- } else {
365
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
366
- }
367
- return;
368
- }
369
- toggleNotification({
370
- type: "success",
371
- message: formatMessage({
372
- id: getTranslation("Settings.locales.modal.edit.success"),
373
- defaultMessage: "Updated locale"
374
- })
375
- });
376
- refetchPermissions();
377
- onOpenChange(false);
378
- } catch (err) {
379
- toggleNotification({
380
- type: "danger",
381
- message: formatMessage({
382
- id: "notification.error",
383
- defaultMessage: "An error occurred, please try again"
384
- })
385
- });
386
- }
387
- };
388
- return /* @__PURE__ */ jsx(Modal.Root, { open, onOpenChange, children: /* @__PURE__ */ jsx(Modal.Content, { children: /* @__PURE__ */ jsxs(
389
- Form,
390
- {
391
- method: "PUT",
392
- onSubmit: handleSubmit,
393
- initialValues: {
394
- code,
395
- name,
396
- isDefault
397
- },
398
- validationSchema: LOCALE_SCHEMA,
399
- children: [
400
- /* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: formatMessage(
401
- {
402
- id: getTranslation("Settings.list.actions.edit"),
403
- defaultMessage: "Edit a locale"
404
- },
405
- {
406
- name
407
- }
408
- ) }) }),
409
- /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsxs(Tabs.Root, { variant: "simple", defaultValue: "basic", children: [
410
- /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
411
- /* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "beta", id: titleId, children: formatMessage({
412
- id: getTranslation("Settings.locales.modal.title"),
413
- defaultMessage: "Configuration"
414
- }) }),
415
- /* @__PURE__ */ jsxs(Tabs.List, { "aria-labelledby": titleId, children: [
416
- /* @__PURE__ */ jsx(Tabs.Trigger, { value: "basic", children: formatMessage({
417
- id: getTranslation("Settings.locales.modal.base"),
418
- defaultMessage: "Basic settings"
419
- }) }),
420
- /* @__PURE__ */ jsx(Tabs.Trigger, { value: "advanced", children: formatMessage({
421
- id: getTranslation("Settings.locales.modal.advanced"),
422
- defaultMessage: "Advanced settings"
423
- }) })
424
- ] })
425
- ] }),
426
- /* @__PURE__ */ jsx(Divider, {}),
427
- /* @__PURE__ */ jsxs(Box, { paddingTop: 7, paddingBottom: 7, children: [
428
- /* @__PURE__ */ jsx(Tabs.Content, { value: "basic", children: /* @__PURE__ */ jsx(BaseForm, { mode: "edit" }) }),
429
- /* @__PURE__ */ jsx(Tabs.Content, { value: "advanced", children: /* @__PURE__ */ jsx(AdvancedForm, { isDefaultLocale: isDefault }) })
430
- ] })
431
- ] }) }),
432
- /* @__PURE__ */ jsxs(Modal.Footer, { children: [
433
- /* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }) }),
434
- /* @__PURE__ */ jsx(SubmitButton, {})
435
- ] })
436
- ]
437
- }
438
- ) }) });
439
- };
440
- const LocaleTable = ({ locales = [], canDelete, canUpdate }) => {
441
- const [editLocaleId, setEditLocaleId] = React.useState();
442
- const { formatMessage } = useIntl();
443
- const handleClick = (localeId) => () => {
444
- if (canUpdate) {
445
- setEditLocaleId(localeId);
446
- }
447
- };
448
- return /* @__PURE__ */ jsxs(Table, { colCount: 4, rowCount: locales.length + 1, children: [
449
- /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
450
- /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
451
- id: getTranslation("Settings.locales.row.id"),
452
- defaultMessage: "ID"
453
- }) }) }),
454
- /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
455
- id: getTranslation("Settings.locales.row.displayName"),
456
- defaultMessage: "Display name"
457
- }) }) }),
458
- /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
459
- id: getTranslation("Settings.locales.row.default-locale"),
460
- defaultMessage: "Default locale"
461
- }) }) }),
462
- /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: "Actions" }) })
463
- ] }) }),
464
- /* @__PURE__ */ jsx(Tbody, { children: locales.map((locale) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
465
- /* @__PURE__ */ jsxs(
466
- Tr,
467
- {
468
- onClick: handleClick(locale.id),
469
- style: { cursor: canUpdate ? "pointer" : "default" },
470
- children: [
471
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: locale.id }) }),
472
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: locale.name }) }),
473
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: locale.isDefault ? formatMessage({
474
- id: getTranslation("Settings.locales.default"),
475
- defaultMessage: "Default"
476
- }) : null }) }),
477
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { gap: 1, justifyContent: "flex-end", onClick: (e) => e.stopPropagation(), children: [
478
- canUpdate && /* @__PURE__ */ jsx(EditLocale, { ...locale }),
479
- canDelete && !locale.isDefault && /* @__PURE__ */ jsx(DeleteLocale, { ...locale })
480
- ] }) })
481
- ]
482
- }
483
- ),
484
- /* @__PURE__ */ jsx(
485
- EditModal,
486
- {
487
- ...locale,
488
- onOpenChange: () => setEditLocaleId(void 0),
489
- open: editLocaleId === locale.id
490
- }
491
- )
492
- ] }, locale.id)) })
493
- ] });
494
- };
495
- const SettingsPage = () => {
496
- const { formatMessage } = useIntl();
497
- const { toggleNotification } = useNotification();
498
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
499
- const { data: locales, isLoading: isLoadingLocales, error } = useGetLocalesQuery();
500
- const {
501
- isLoading: isLoadingRBAC,
502
- allowedActions: { canUpdate, canCreate, canDelete }
503
- } = useRBAC(PERMISSIONS);
504
- React.useEffect(() => {
505
- if (error) {
506
- toggleNotification({
507
- type: "danger",
508
- message: formatAPIError(error)
509
- });
510
- }
511
- }, [error, formatAPIError, toggleNotification]);
512
- const isLoading = isLoadingLocales || isLoadingRBAC;
513
- if (isLoading) {
514
- return /* @__PURE__ */ jsx(Page.Loading, {});
515
- }
516
- if (error || !Array.isArray(locales)) {
517
- return /* @__PURE__ */ jsx(Page.Error, {});
518
- }
519
- return /* @__PURE__ */ jsxs(Page.Main, { tabIndex: -1, children: [
520
- /* @__PURE__ */ jsx(
521
- Layouts.Header,
522
- {
523
- primaryAction: /* @__PURE__ */ jsx(CreateLocale, { disabled: !canCreate }),
524
- title: formatMessage({
525
- id: getTranslation("plugin.name"),
526
- defaultMessage: "Internationalization"
527
- }),
528
- subtitle: formatMessage({
529
- id: getTranslation("Settings.list.description"),
530
- defaultMessage: "Configure the settings"
531
- })
532
- }
533
- ),
534
- /* @__PURE__ */ jsx(Layouts.Content, { children: locales.length > 0 ? /* @__PURE__ */ jsx(LocaleTable, { locales, canDelete, canUpdate }) : /* @__PURE__ */ jsx(
535
- EmptyStateLayout,
536
- {
537
- icon: /* @__PURE__ */ jsx(EmptyDocuments, { width: void 0, height: void 0 }),
538
- content: formatMessage({
539
- id: getTranslation("Settings.list.empty.title"),
540
- defaultMessage: "There are no locales"
541
- }),
542
- action: /* @__PURE__ */ jsx(CreateLocale, { disabled: !canCreate, variant: "secondary" })
543
- }
544
- ) })
545
- ] });
546
- };
547
- const ProtectedSettingsPage = () => {
548
- return /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.read, children: /* @__PURE__ */ jsx(SettingsPage, {}) });
549
- };
550
- export {
551
- ProtectedSettingsPage,
552
- SettingsPage
553
- };
554
- //# sourceMappingURL=SettingsPage-D_53Ao8I.mjs.map