@strapi/i18n 5.9.0 → 5.10.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.
Files changed (126) 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 +1 -1
  58. package/dist/admin/src/components/tests/CreateLocale.test.d.ts +1 -0
  59. package/dist/admin/src/components/tests/DeleteLocale.test.d.ts +1 -0
  60. package/dist/admin/src/components/tests/EditLocale.test.d.ts +1 -0
  61. package/dist/admin/src/components/tests/LocaleListCell.test.d.ts +1 -0
  62. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +1 -1
  63. package/dist/admin/src/pages/tests/SettingsPage.test.d.ts +1 -0
  64. package/dist/admin/tests/server.d.ts +1 -0
  65. package/dist/admin/tests/utils.d.ts +6 -0
  66. package/dist/server/index.js +3650 -3390
  67. package/dist/server/index.js.map +1 -1
  68. package/dist/server/index.mjs +3632 -3374
  69. package/dist/server/index.mjs.map +1 -1
  70. package/dist/server/src/services/localizations.d.ts +1 -1
  71. package/dist/server/src/services/localizations.d.ts.map +1 -1
  72. package/dist/shared/contracts/content-manager.d.ts +1 -1
  73. package/dist/shared/contracts/shared.d.ts +1 -1
  74. package/package.json +14 -11
  75. package/dist/_chunks/SettingsPage-B-KzAqT3.mjs +0 -554
  76. package/dist/_chunks/SettingsPage-B-KzAqT3.mjs.map +0 -1
  77. package/dist/_chunks/SettingsPage-hyOi94O9.js +0 -573
  78. package/dist/_chunks/SettingsPage-hyOi94O9.js.map +0 -1
  79. package/dist/_chunks/de-BOhNX_-5.js +0 -65
  80. package/dist/_chunks/de-BOhNX_-5.js.map +0 -1
  81. package/dist/_chunks/de-D80IRBP9.mjs +0 -65
  82. package/dist/_chunks/de-D80IRBP9.mjs.map +0 -1
  83. package/dist/_chunks/dk-CJ6Zzz78.mjs +0 -65
  84. package/dist/_chunks/dk-CJ6Zzz78.mjs.map +0 -1
  85. package/dist/_chunks/dk-cjXm0p3m.js +0 -65
  86. package/dist/_chunks/dk-cjXm0p3m.js.map +0 -1
  87. package/dist/_chunks/en-BTyF7WVW.mjs +0 -80
  88. package/dist/_chunks/en-BTyF7WVW.mjs.map +0 -1
  89. package/dist/_chunks/en-UlC0jh2t.js +0 -80
  90. package/dist/_chunks/en-UlC0jh2t.js.map +0 -1
  91. package/dist/_chunks/es-V8WnPN7w.mjs +0 -65
  92. package/dist/_chunks/es-V8WnPN7w.mjs.map +0 -1
  93. package/dist/_chunks/es-hr9b_HLp.js +0 -65
  94. package/dist/_chunks/es-hr9b_HLp.js.map +0 -1
  95. package/dist/_chunks/fr-BFmBbE0H.js +0 -65
  96. package/dist/_chunks/fr-BFmBbE0H.js.map +0 -1
  97. package/dist/_chunks/fr-F94noFiV.mjs +0 -65
  98. package/dist/_chunks/fr-F94noFiV.mjs.map +0 -1
  99. package/dist/_chunks/index-BcYj5jo9.mjs +0 -1589
  100. package/dist/_chunks/index-BcYj5jo9.mjs.map +0 -1
  101. package/dist/_chunks/index-C8NzsAKp.js +0 -1610
  102. package/dist/_chunks/index-C8NzsAKp.js.map +0 -1
  103. package/dist/_chunks/ko-C40pNQ9b.js +0 -64
  104. package/dist/_chunks/ko-C40pNQ9b.js.map +0 -1
  105. package/dist/_chunks/ko-CF-P3Car.mjs +0 -64
  106. package/dist/_chunks/ko-CF-P3Car.mjs.map +0 -1
  107. package/dist/_chunks/pl-Dxr9RUmD.mjs +0 -65
  108. package/dist/_chunks/pl-Dxr9RUmD.mjs.map +0 -1
  109. package/dist/_chunks/pl-JtWBy-JQ.js +0 -65
  110. package/dist/_chunks/pl-JtWBy-JQ.js.map +0 -1
  111. package/dist/_chunks/ru-B-4sVwXN.mjs +0 -67
  112. package/dist/_chunks/ru-B-4sVwXN.mjs.map +0 -1
  113. package/dist/_chunks/ru-COSWt3Nu.js +0 -67
  114. package/dist/_chunks/ru-COSWt3Nu.js.map +0 -1
  115. package/dist/_chunks/tr-BVj1O5ch.js +0 -65
  116. package/dist/_chunks/tr-BVj1O5ch.js.map +0 -1
  117. package/dist/_chunks/tr-Ccu6Yj11.mjs +0 -65
  118. package/dist/_chunks/tr-Ccu6Yj11.mjs.map +0 -1
  119. package/dist/_chunks/zh-BIz395Ms.mjs +0 -65
  120. package/dist/_chunks/zh-BIz395Ms.mjs.map +0 -1
  121. package/dist/_chunks/zh-Hans-Bfo6_TCM.mjs +0 -56
  122. package/dist/_chunks/zh-Hans-Bfo6_TCM.mjs.map +0 -1
  123. package/dist/_chunks/zh-Hans-DIEm_EMC.js +0 -56
  124. package/dist/_chunks/zh-Hans-DIEm_EMC.js.map +0 -1
  125. package/dist/_chunks/zh-wkBPBkhc.js +0 -65
  126. package/dist/_chunks/zh-wkBPBkhc.js.map +0 -1
@@ -0,0 +1,797 @@
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-k3BHSNs0.mjs';
10
+ import 'lodash/get';
11
+ import 'styled-components';
12
+ import '@reduxjs/toolkit/query';
13
+ import '@strapi/content-manager/strapi-admin';
14
+ import 'react-router-dom';
15
+ import 'qs';
16
+ import 'lodash/omit';
17
+
18
+ const isBaseQueryError = (error)=>{
19
+ return error.name !== undefined;
20
+ };
21
+
22
+ const CreateLocale = ({ disabled, variant = 'default' })=>{
23
+ const { formatMessage } = useIntl();
24
+ const [visible, setVisible] = React.useState(false);
25
+ return /*#__PURE__*/ jsxs(Modal.Root, {
26
+ open: visible,
27
+ onOpenChange: setVisible,
28
+ children: [
29
+ /*#__PURE__*/ jsx(Modal.Trigger, {
30
+ children: /*#__PURE__*/ jsx(Button, {
31
+ variant: variant,
32
+ disabled: disabled,
33
+ startIcon: /*#__PURE__*/ jsx(Plus, {}),
34
+ onClick: ()=>setVisible(true),
35
+ size: "S",
36
+ children: formatMessage({
37
+ id: getTranslation('Settings.list.actions.add'),
38
+ defaultMessage: 'Add new locale'
39
+ })
40
+ })
41
+ }),
42
+ /*#__PURE__*/ jsx(CreateModal, {
43
+ onClose: ()=>setVisible(false)
44
+ })
45
+ ]
46
+ });
47
+ };
48
+ /* -------------------------------------------------------------------------------------------------
49
+ * CreateModal
50
+ * -----------------------------------------------------------------------------------------------*/ const LOCALE_SCHEMA = yup.object().shape({
51
+ code: yup.string().nullable().required({
52
+ id: 'Settings.locales.modal.create.code.error',
53
+ defaultMessage: 'Please select a locale'
54
+ }),
55
+ name: yup.string().nullable().max(50, {
56
+ id: 'Settings.locales.modal.create.name.error.min',
57
+ defaultMessage: 'The locale display name can only be less than 50 characters.'
58
+ }).required({
59
+ id: 'Settings.locales.modal.create.name.error.required',
60
+ defaultMessage: 'Please give the locale a display name'
61
+ }),
62
+ isDefault: yup.boolean()
63
+ });
64
+ const initialFormValues = {
65
+ code: '',
66
+ name: '',
67
+ isDefault: false
68
+ };
69
+ const CreateModal = ({ onClose })=>{
70
+ const titleId = useId();
71
+ const { toggleNotification } = useNotification();
72
+ const { _unstableFormatAPIError: formatAPIError, _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
73
+ const [createLocale] = useCreateLocaleMutation();
74
+ const { formatMessage } = useIntl();
75
+ const refetchPermissions = useAuth('CreateModal', (state)=>state.refetchPermissions);
76
+ const handleSubmit = async (values, helpers)=>{
77
+ try {
78
+ const res = await createLocale(values);
79
+ if ('error' in res) {
80
+ if (isBaseQueryError(res.error) && res.error.name === 'ValidationError') {
81
+ helpers.setErrors(formatValidationErrors(res.error));
82
+ } else {
83
+ toggleNotification({
84
+ type: 'danger',
85
+ message: formatAPIError(res.error)
86
+ });
87
+ }
88
+ return;
89
+ }
90
+ toggleNotification({
91
+ type: 'success',
92
+ message: formatMessage({
93
+ id: getTranslation('Settings.locales.modal.create.success'),
94
+ defaultMessage: 'Created locale'
95
+ })
96
+ });
97
+ refetchPermissions();
98
+ onClose();
99
+ } catch (err) {
100
+ toggleNotification({
101
+ type: 'danger',
102
+ message: formatMessage({
103
+ id: 'notification.error',
104
+ defaultMessage: 'An error occurred, please try again'
105
+ })
106
+ });
107
+ }
108
+ };
109
+ return /*#__PURE__*/ jsx(Modal.Content, {
110
+ children: /*#__PURE__*/ jsxs(Form, {
111
+ method: "POST",
112
+ initialValues: initialFormValues,
113
+ validationSchema: LOCALE_SCHEMA,
114
+ onSubmit: handleSubmit,
115
+ children: [
116
+ /*#__PURE__*/ jsx(Modal.Header, {
117
+ children: /*#__PURE__*/ jsx(Modal.Title, {
118
+ children: formatMessage({
119
+ id: getTranslation('Settings.list.actions.add'),
120
+ defaultMessage: 'Add new locale'
121
+ })
122
+ })
123
+ }),
124
+ /*#__PURE__*/ jsx(Modal.Body, {
125
+ children: /*#__PURE__*/ jsxs(Tabs.Root, {
126
+ variant: "simple",
127
+ defaultValue: "basic",
128
+ children: [
129
+ /*#__PURE__*/ jsxs(Flex, {
130
+ justifyContent: "space-between",
131
+ children: [
132
+ /*#__PURE__*/ jsx(Typography, {
133
+ tag: "h2",
134
+ variant: "beta",
135
+ id: titleId,
136
+ children: formatMessage({
137
+ id: getTranslation('Settings.locales.modal.title'),
138
+ defaultMessage: 'Configuration'
139
+ })
140
+ }),
141
+ /*#__PURE__*/ jsxs(Tabs.List, {
142
+ "aria-labelledby": titleId,
143
+ children: [
144
+ /*#__PURE__*/ jsx(Tabs.Trigger, {
145
+ value: "basic",
146
+ children: formatMessage({
147
+ id: getTranslation('Settings.locales.modal.base'),
148
+ defaultMessage: 'Basic settings'
149
+ })
150
+ }),
151
+ /*#__PURE__*/ jsx(Tabs.Trigger, {
152
+ value: "advanced",
153
+ children: formatMessage({
154
+ id: getTranslation('Settings.locales.modal.advanced'),
155
+ defaultMessage: 'Advanced settings'
156
+ })
157
+ })
158
+ ]
159
+ })
160
+ ]
161
+ }),
162
+ /*#__PURE__*/ jsx(Divider, {}),
163
+ /*#__PURE__*/ jsxs(Box, {
164
+ paddingTop: 7,
165
+ paddingBottom: 7,
166
+ children: [
167
+ /*#__PURE__*/ jsx(Tabs.Content, {
168
+ value: "basic",
169
+ children: /*#__PURE__*/ jsx(BaseForm, {})
170
+ }),
171
+ /*#__PURE__*/ jsx(Tabs.Content, {
172
+ value: "advanced",
173
+ children: /*#__PURE__*/ jsx(AdvancedForm, {})
174
+ })
175
+ ]
176
+ })
177
+ ]
178
+ })
179
+ }),
180
+ /*#__PURE__*/ jsxs(Modal.Footer, {
181
+ children: [
182
+ /*#__PURE__*/ jsx(Modal.Close, {
183
+ children: /*#__PURE__*/ jsx(Button, {
184
+ variant: "tertiary",
185
+ children: formatMessage({
186
+ id: 'app.components.Button.cancel',
187
+ defaultMessage: 'Cancel'
188
+ })
189
+ })
190
+ }),
191
+ /*#__PURE__*/ jsx(SubmitButton, {})
192
+ ]
193
+ })
194
+ ]
195
+ })
196
+ });
197
+ };
198
+ /* -------------------------------------------------------------------------------------------------
199
+ * SubmitButton
200
+ * -----------------------------------------------------------------------------------------------*/ const SubmitButton = ()=>{
201
+ const { formatMessage } = useIntl();
202
+ const isSubmitting = useForm('SubmitButton', (state)=>state.isSubmitting);
203
+ const modified = useForm('SubmitButton', (state)=>state.modified);
204
+ return /*#__PURE__*/ jsx(Button, {
205
+ type: "submit",
206
+ startIcon: /*#__PURE__*/ jsx(Check, {}),
207
+ disabled: isSubmitting || !modified,
208
+ children: formatMessage({
209
+ id: 'global.save',
210
+ defaultMessage: 'Save'
211
+ })
212
+ });
213
+ };
214
+ const BaseForm = ({ mode = 'create' })=>{
215
+ const { formatMessage } = useIntl();
216
+ const { toggleNotification } = useNotification();
217
+ const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
218
+ const { data: defaultLocales, error } = useGetDefaultLocalesQuery();
219
+ React.useEffect(()=>{
220
+ if (error) {
221
+ toggleNotification({
222
+ type: 'danger',
223
+ message: formatAPIError(error)
224
+ });
225
+ }
226
+ }, [
227
+ error,
228
+ formatAPIError,
229
+ toggleNotification
230
+ ]);
231
+ if (!Array.isArray(defaultLocales)) {
232
+ return null;
233
+ }
234
+ const options = defaultLocales.map((locale)=>({
235
+ label: locale.name,
236
+ value: locale.code
237
+ }));
238
+ const translatedForm = [
239
+ {
240
+ disabled: mode !== 'create',
241
+ label: {
242
+ id: getTranslation('Settings.locales.modal.create.code.label'),
243
+ defaultMessage: 'Locales'
244
+ },
245
+ name: 'code',
246
+ options,
247
+ placeholder: {
248
+ id: 'components.placeholder.select',
249
+ defaultMessage: 'Select'
250
+ },
251
+ required: true,
252
+ size: 6,
253
+ type: 'enumeration'
254
+ },
255
+ {
256
+ hint: {
257
+ id: getTranslation('Settings.locales.modal.create.name.label.description'),
258
+ defaultMessage: 'Locale will be displayed under that name in the administration panel'
259
+ },
260
+ label: {
261
+ id: getTranslation('Settings.locales.modal.create.name.label'),
262
+ defaultMessage: 'Locale display name'
263
+ },
264
+ name: 'name',
265
+ required: true,
266
+ size: 6,
267
+ type: 'string'
268
+ }
269
+ ].map((field)=>({
270
+ ...field,
271
+ hint: field.hint ? formatMessage(field.hint) : undefined,
272
+ label: formatMessage(field.label),
273
+ placeholder: field.placeholder ? formatMessage(field.placeholder) : undefined
274
+ }));
275
+ return /*#__PURE__*/ jsx(Grid.Root, {
276
+ gap: 4,
277
+ children: translatedForm.map(({ size, ...field })=>/*#__PURE__*/ jsx(Grid.Item, {
278
+ col: size,
279
+ direction: "column",
280
+ alignItems: "stretch",
281
+ children: /*#__PURE__*/ jsx(FormRenderer, {
282
+ ...field
283
+ })
284
+ }, field.name))
285
+ });
286
+ };
287
+ const AdvancedForm = ({ isDefaultLocale })=>{
288
+ const { formatMessage } = useIntl();
289
+ const form = [
290
+ {
291
+ disabled: isDefaultLocale,
292
+ hint: {
293
+ id: getTranslation('Settings.locales.modal.advanced.setAsDefault.hint'),
294
+ defaultMessage: 'One default locale is required, change it by selecting another one'
295
+ },
296
+ label: {
297
+ id: getTranslation('Settings.locales.modal.advanced.setAsDefault'),
298
+ defaultMessage: 'Set as default locale'
299
+ },
300
+ name: 'isDefault',
301
+ size: 6,
302
+ type: 'boolean'
303
+ }
304
+ ].map((field)=>({
305
+ ...field,
306
+ hint: field.hint ? formatMessage(field.hint) : undefined,
307
+ label: formatMessage(field.label)
308
+ }));
309
+ return /*#__PURE__*/ jsx(Grid.Root, {
310
+ gap: 4,
311
+ children: form.map(({ size, ...field })=>/*#__PURE__*/ jsx(Grid.Item, {
312
+ col: size,
313
+ direction: "column",
314
+ alignItems: "stretch",
315
+ children: /*#__PURE__*/ jsx(FormRenderer, {
316
+ ...field
317
+ })
318
+ }, field.name))
319
+ });
320
+ };
321
+ /* -------------------------------------------------------------------------------------------------
322
+ * FormRenderer
323
+ * -----------------------------------------------------------------------------------------------*/ const FormRenderer = (field)=>{
324
+ switch(field.type){
325
+ /**
326
+ * This will override the default input renderer
327
+ * choice for `enumeration`.
328
+ */ case 'enumeration':
329
+ return /*#__PURE__*/ jsx(EnumerationInput, {
330
+ ...field
331
+ });
332
+ default:
333
+ return /*#__PURE__*/ jsx(InputRenderer, {
334
+ ...field
335
+ });
336
+ }
337
+ };
338
+ const EnumerationInput = ({ disabled, hint, label, name, options, placeholder, required })=>{
339
+ const { value, error, onChange } = useField(name);
340
+ const { data: defaultLocales = [] } = useGetDefaultLocalesQuery();
341
+ const handleChange = (value)=>{
342
+ if (Array.isArray(defaultLocales)) {
343
+ // We know it exists because the options are created from the list of default locales
344
+ const locale = defaultLocales.find((locale)=>locale.code === value);
345
+ onChange(name, value);
346
+ // This lets us automatically fill the name field with the locale name
347
+ onChange('name', locale.name);
348
+ } else {
349
+ onChange(name, value);
350
+ }
351
+ };
352
+ return /*#__PURE__*/ jsxs(Field.Root, {
353
+ error: error,
354
+ hint: hint,
355
+ name: name,
356
+ required: required,
357
+ children: [
358
+ /*#__PURE__*/ jsx(Field.Label, {
359
+ children: label
360
+ }),
361
+ /*#__PURE__*/ jsx(SingleSelect, {
362
+ disabled: disabled,
363
+ // @ts-expect-error – This will dissapear when the DS removes support for numbers to be returned by SingleSelect.
364
+ onChange: handleChange,
365
+ placeholder: placeholder,
366
+ value: value,
367
+ children: options.map((option)=>/*#__PURE__*/ jsx(SingleSelectOption, {
368
+ value: option.value,
369
+ children: option.label
370
+ }, option.value))
371
+ }),
372
+ /*#__PURE__*/ jsx(Field.Error, {}),
373
+ /*#__PURE__*/ jsx(Field.Hint, {})
374
+ ]
375
+ });
376
+ };
377
+
378
+ const DeleteLocale = ({ id, name })=>{
379
+ const { formatMessage } = useIntl();
380
+ const { toggleNotification } = useNotification();
381
+ const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
382
+ const [visible, setVisible] = React.useState(false);
383
+ const [deleteLocale] = useDeleteLocaleMutation();
384
+ const handleConfirm = async ()=>{
385
+ try {
386
+ const res = await deleteLocale(id);
387
+ if ('error' in res) {
388
+ toggleNotification({
389
+ type: 'danger',
390
+ message: formatAPIError(res.error)
391
+ });
392
+ return;
393
+ }
394
+ toggleNotification({
395
+ type: 'success',
396
+ message: formatMessage({
397
+ id: getTranslation('Settings.locales.modal.delete.success'),
398
+ defaultMessage: 'Deleted locale'
399
+ })
400
+ });
401
+ setVisible(false);
402
+ } catch (err) {
403
+ toggleNotification({
404
+ type: 'danger',
405
+ message: formatMessage({
406
+ id: 'notification.error',
407
+ defaultMessage: 'An error occurred, please try again'
408
+ })
409
+ });
410
+ }
411
+ };
412
+ return /*#__PURE__*/ jsxs(Dialog.Root, {
413
+ open: visible,
414
+ onOpenChange: setVisible,
415
+ children: [
416
+ /*#__PURE__*/ jsx(Dialog.Trigger, {
417
+ children: /*#__PURE__*/ jsx(IconButton, {
418
+ onClick: ()=>setVisible(true),
419
+ label: formatMessage({
420
+ id: getTranslation('Settings.list.actions.delete'),
421
+ defaultMessage: 'Delete {name} locale'
422
+ }, {
423
+ name
424
+ }),
425
+ variant: "ghost",
426
+ children: /*#__PURE__*/ jsx(Trash, {})
427
+ })
428
+ }),
429
+ /*#__PURE__*/ jsx(ConfirmDialog, {
430
+ onConfirm: handleConfirm
431
+ })
432
+ ]
433
+ });
434
+ };
435
+
436
+ const EditLocale = (props)=>{
437
+ const { formatMessage } = useIntl();
438
+ const [visible, setVisible] = React.useState(false);
439
+ return /*#__PURE__*/ jsxs(Fragment, {
440
+ children: [
441
+ /*#__PURE__*/ jsx(IconButton, {
442
+ onClick: ()=>setVisible(true),
443
+ label: formatMessage({
444
+ id: getTranslation('Settings.list.actions.edit'),
445
+ defaultMessage: 'Edit {name} locale'
446
+ }, {
447
+ name: props.name
448
+ }),
449
+ variant: "ghost",
450
+ children: /*#__PURE__*/ jsx(Pencil, {})
451
+ }),
452
+ /*#__PURE__*/ jsx(EditModal, {
453
+ ...props,
454
+ open: visible,
455
+ onOpenChange: setVisible
456
+ })
457
+ ]
458
+ });
459
+ };
460
+ /**
461
+ * @internal
462
+ * @description Exported to be used when someone clicks on a table row.
463
+ */ const EditModal = ({ id, code, isDefault, name, open, onOpenChange })=>{
464
+ const { toggleNotification } = useNotification();
465
+ const { _unstableFormatAPIError: formatAPIError, _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
466
+ const refetchPermissions = useAuth('EditModal', (state)=>state.refetchPermissions);
467
+ const { formatMessage } = useIntl();
468
+ const titleId = useId();
469
+ const [updateLocale] = useUpdateLocaleMutation();
470
+ const handleSubmit = async ({ code: _code, ...data }, helpers)=>{
471
+ try {
472
+ /**
473
+ * We don't need to send the code, because the
474
+ * code can never be changed.
475
+ */ const res = await updateLocale({
476
+ id,
477
+ ...data
478
+ });
479
+ if ('error' in res) {
480
+ if (isBaseQueryError(res.error) && res.error.name === 'ValidationError') {
481
+ helpers.setErrors(formatValidationErrors(res.error));
482
+ } else {
483
+ toggleNotification({
484
+ type: 'danger',
485
+ message: formatAPIError(res.error)
486
+ });
487
+ }
488
+ return;
489
+ }
490
+ toggleNotification({
491
+ type: 'success',
492
+ message: formatMessage({
493
+ id: getTranslation('Settings.locales.modal.edit.success'),
494
+ defaultMessage: 'Updated locale'
495
+ })
496
+ });
497
+ refetchPermissions();
498
+ onOpenChange(false);
499
+ } catch (err) {
500
+ toggleNotification({
501
+ type: 'danger',
502
+ message: formatMessage({
503
+ id: 'notification.error',
504
+ defaultMessage: 'An error occurred, please try again'
505
+ })
506
+ });
507
+ }
508
+ };
509
+ return /*#__PURE__*/ jsx(Modal.Root, {
510
+ open: open,
511
+ onOpenChange: onOpenChange,
512
+ children: /*#__PURE__*/ jsx(Modal.Content, {
513
+ children: /*#__PURE__*/ jsxs(Form, {
514
+ method: "PUT",
515
+ onSubmit: handleSubmit,
516
+ initialValues: {
517
+ code,
518
+ name,
519
+ isDefault
520
+ },
521
+ validationSchema: LOCALE_SCHEMA,
522
+ children: [
523
+ /*#__PURE__*/ jsx(Modal.Header, {
524
+ children: /*#__PURE__*/ jsx(Modal.Title, {
525
+ children: formatMessage({
526
+ id: getTranslation('Settings.list.actions.edit'),
527
+ defaultMessage: 'Edit a locale'
528
+ }, {
529
+ name
530
+ })
531
+ })
532
+ }),
533
+ /*#__PURE__*/ jsx(Modal.Body, {
534
+ children: /*#__PURE__*/ jsxs(Tabs.Root, {
535
+ variant: "simple",
536
+ defaultValue: "basic",
537
+ children: [
538
+ /*#__PURE__*/ jsxs(Flex, {
539
+ justifyContent: "space-between",
540
+ children: [
541
+ /*#__PURE__*/ jsx(Typography, {
542
+ tag: "h2",
543
+ variant: "beta",
544
+ id: titleId,
545
+ children: formatMessage({
546
+ id: getTranslation('Settings.locales.modal.title'),
547
+ defaultMessage: 'Configuration'
548
+ })
549
+ }),
550
+ /*#__PURE__*/ jsxs(Tabs.List, {
551
+ "aria-labelledby": titleId,
552
+ children: [
553
+ /*#__PURE__*/ jsx(Tabs.Trigger, {
554
+ value: "basic",
555
+ children: formatMessage({
556
+ id: getTranslation('Settings.locales.modal.base'),
557
+ defaultMessage: 'Basic settings'
558
+ })
559
+ }),
560
+ /*#__PURE__*/ jsx(Tabs.Trigger, {
561
+ value: "advanced",
562
+ children: formatMessage({
563
+ id: getTranslation('Settings.locales.modal.advanced'),
564
+ defaultMessage: 'Advanced settings'
565
+ })
566
+ })
567
+ ]
568
+ })
569
+ ]
570
+ }),
571
+ /*#__PURE__*/ jsx(Divider, {}),
572
+ /*#__PURE__*/ jsxs(Box, {
573
+ paddingTop: 7,
574
+ paddingBottom: 7,
575
+ children: [
576
+ /*#__PURE__*/ jsx(Tabs.Content, {
577
+ value: "basic",
578
+ children: /*#__PURE__*/ jsx(BaseForm, {
579
+ mode: "edit"
580
+ })
581
+ }),
582
+ /*#__PURE__*/ jsx(Tabs.Content, {
583
+ value: "advanced",
584
+ children: /*#__PURE__*/ jsx(AdvancedForm, {
585
+ isDefaultLocale: isDefault
586
+ })
587
+ })
588
+ ]
589
+ })
590
+ ]
591
+ })
592
+ }),
593
+ /*#__PURE__*/ jsxs(Modal.Footer, {
594
+ children: [
595
+ /*#__PURE__*/ jsx(Modal.Close, {
596
+ children: /*#__PURE__*/ jsx(Button, {
597
+ variant: "tertiary",
598
+ children: formatMessage({
599
+ id: 'app.components.Button.cancel',
600
+ defaultMessage: 'Cancel'
601
+ })
602
+ })
603
+ }),
604
+ /*#__PURE__*/ jsx(SubmitButton, {})
605
+ ]
606
+ })
607
+ ]
608
+ })
609
+ })
610
+ });
611
+ };
612
+
613
+ const LocaleTable = ({ locales = [], canDelete, canUpdate })=>{
614
+ const [editLocaleId, setEditLocaleId] = React.useState();
615
+ const { formatMessage } = useIntl();
616
+ const handleClick = (localeId)=>()=>{
617
+ if (canUpdate) {
618
+ setEditLocaleId(localeId);
619
+ }
620
+ };
621
+ return /*#__PURE__*/ jsxs(Table, {
622
+ colCount: 4,
623
+ rowCount: locales.length + 1,
624
+ children: [
625
+ /*#__PURE__*/ jsx(Thead, {
626
+ children: /*#__PURE__*/ jsxs(Tr, {
627
+ children: [
628
+ /*#__PURE__*/ jsx(Th, {
629
+ children: /*#__PURE__*/ jsx(Typography, {
630
+ variant: "sigma",
631
+ textColor: "neutral600",
632
+ children: formatMessage({
633
+ id: getTranslation('Settings.locales.row.id'),
634
+ defaultMessage: 'ID'
635
+ })
636
+ })
637
+ }),
638
+ /*#__PURE__*/ jsx(Th, {
639
+ children: /*#__PURE__*/ jsx(Typography, {
640
+ variant: "sigma",
641
+ textColor: "neutral600",
642
+ children: formatMessage({
643
+ id: getTranslation('Settings.locales.row.displayName'),
644
+ defaultMessage: 'Display name'
645
+ })
646
+ })
647
+ }),
648
+ /*#__PURE__*/ jsx(Th, {
649
+ children: /*#__PURE__*/ jsx(Typography, {
650
+ variant: "sigma",
651
+ textColor: "neutral600",
652
+ children: formatMessage({
653
+ id: getTranslation('Settings.locales.row.default-locale'),
654
+ defaultMessage: 'Default locale'
655
+ })
656
+ })
657
+ }),
658
+ /*#__PURE__*/ jsx(Th, {
659
+ children: /*#__PURE__*/ jsx(VisuallyHidden, {
660
+ children: "Actions"
661
+ })
662
+ })
663
+ ]
664
+ })
665
+ }),
666
+ /*#__PURE__*/ jsx(Tbody, {
667
+ children: locales.map((locale)=>/*#__PURE__*/ jsxs(React.Fragment, {
668
+ children: [
669
+ /*#__PURE__*/ jsxs(Tr, {
670
+ onClick: handleClick(locale.id),
671
+ style: {
672
+ cursor: canUpdate ? 'pointer' : 'default'
673
+ },
674
+ children: [
675
+ /*#__PURE__*/ jsx(Td, {
676
+ children: /*#__PURE__*/ jsx(Typography, {
677
+ textColor: "neutral800",
678
+ children: locale.id
679
+ })
680
+ }),
681
+ /*#__PURE__*/ jsx(Td, {
682
+ children: /*#__PURE__*/ jsx(Typography, {
683
+ textColor: "neutral800",
684
+ children: locale.name
685
+ })
686
+ }),
687
+ /*#__PURE__*/ jsx(Td, {
688
+ children: /*#__PURE__*/ jsx(Typography, {
689
+ textColor: "neutral800",
690
+ children: locale.isDefault ? formatMessage({
691
+ id: getTranslation('Settings.locales.default'),
692
+ defaultMessage: 'Default'
693
+ }) : null
694
+ })
695
+ }),
696
+ /*#__PURE__*/ jsx(Td, {
697
+ children: /*#__PURE__*/ jsxs(Flex, {
698
+ gap: 1,
699
+ justifyContent: "flex-end",
700
+ onClick: (e)=>e.stopPropagation(),
701
+ children: [
702
+ canUpdate && /*#__PURE__*/ jsx(EditLocale, {
703
+ ...locale
704
+ }),
705
+ canDelete && !locale.isDefault && /*#__PURE__*/ jsx(DeleteLocale, {
706
+ ...locale
707
+ })
708
+ ]
709
+ })
710
+ })
711
+ ]
712
+ }),
713
+ /*#__PURE__*/ jsx(EditModal, {
714
+ ...locale,
715
+ onOpenChange: ()=>setEditLocaleId(undefined),
716
+ open: editLocaleId === locale.id
717
+ })
718
+ ]
719
+ }, locale.id))
720
+ })
721
+ ]
722
+ });
723
+ };
724
+
725
+ const SettingsPage = ()=>{
726
+ const { formatMessage } = useIntl();
727
+ const { toggleNotification } = useNotification();
728
+ const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
729
+ const { data: locales, isLoading: isLoadingLocales, error } = useGetLocalesQuery();
730
+ const { isLoading: isLoadingRBAC, allowedActions: { canUpdate, canCreate, canDelete } } = useRBAC(PERMISSIONS);
731
+ React.useEffect(()=>{
732
+ if (error) {
733
+ toggleNotification({
734
+ type: 'danger',
735
+ message: formatAPIError(error)
736
+ });
737
+ }
738
+ }, [
739
+ error,
740
+ formatAPIError,
741
+ toggleNotification
742
+ ]);
743
+ const isLoading = isLoadingLocales || isLoadingRBAC;
744
+ if (isLoading) {
745
+ return /*#__PURE__*/ jsx(Page.Loading, {});
746
+ }
747
+ if (error || !Array.isArray(locales)) {
748
+ return /*#__PURE__*/ jsx(Page.Error, {});
749
+ }
750
+ return /*#__PURE__*/ jsxs(Page.Main, {
751
+ tabIndex: -1,
752
+ children: [
753
+ /*#__PURE__*/ jsx(Layouts.Header, {
754
+ primaryAction: /*#__PURE__*/ jsx(CreateLocale, {
755
+ disabled: !canCreate
756
+ }),
757
+ title: formatMessage({
758
+ id: getTranslation('plugin.name'),
759
+ defaultMessage: 'Internationalization'
760
+ }),
761
+ subtitle: formatMessage({
762
+ id: getTranslation('Settings.list.description'),
763
+ defaultMessage: 'Configure the settings'
764
+ })
765
+ }),
766
+ /*#__PURE__*/ jsx(Layouts.Content, {
767
+ children: locales.length > 0 ? /*#__PURE__*/ jsx(LocaleTable, {
768
+ locales: locales,
769
+ canDelete: canDelete,
770
+ canUpdate: canUpdate
771
+ }) : /*#__PURE__*/ jsx(EmptyStateLayout, {
772
+ icon: /*#__PURE__*/ jsx(EmptyDocuments, {
773
+ width: undefined,
774
+ height: undefined
775
+ }),
776
+ content: formatMessage({
777
+ id: getTranslation('Settings.list.empty.title'),
778
+ defaultMessage: 'There are no locales'
779
+ }),
780
+ action: /*#__PURE__*/ jsx(CreateLocale, {
781
+ disabled: !canCreate,
782
+ variant: "secondary"
783
+ })
784
+ })
785
+ })
786
+ ]
787
+ });
788
+ };
789
+ const ProtectedSettingsPage = ()=>{
790
+ return /*#__PURE__*/ jsx(Page.Protect, {
791
+ permissions: PERMISSIONS.read,
792
+ children: /*#__PURE__*/ jsx(SettingsPage, {})
793
+ });
794
+ };
795
+
796
+ export { ProtectedSettingsPage, SettingsPage };
797
+ //# sourceMappingURL=SettingsPage-DydtYvMJ.mjs.map