@griddo/ax 11.14.2 → 11.14.3

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 (64) hide show
  1. package/config/jest/setup.js +13 -7
  2. package/package.json +2 -2
  3. package/src/__tests__/components/KeywordsPreviewModal/KeywordsPreviewModal.test.tsx +4 -3
  4. package/src/components/CategoryCell/index.tsx +3 -1
  5. package/src/components/ElementsTooltip/index.tsx +8 -4
  6. package/src/components/ErrorPage/index.tsx +3 -1
  7. package/src/components/FilterTagsBar/index.tsx +3 -3
  8. package/src/components/HeadingsPreviewModal/utils.tsx +2 -1
  9. package/src/components/KeywordsPreviewModal/atoms.tsx +2 -2
  10. package/src/components/KeywordsPreviewModal/index.tsx +6 -6
  11. package/src/components/KeywordsPreviewModal/utils.tsx +5 -3
  12. package/src/components/Modal/style.tsx +5 -5
  13. package/src/components/TableFilters/CheckGroupFilter/index.tsx +3 -2
  14. package/src/components/TableFilters/LiveFilter/index.tsx +4 -4
  15. package/src/components/TableFilters/SiteFilter/index.tsx +11 -12
  16. package/src/components/TableFilters/TranslationsFilter/index.tsx +2 -2
  17. package/src/components/TableFilters/TranslationsFilter/style.tsx +2 -2
  18. package/src/components/Tag/index.tsx +15 -7
  19. package/src/components/TruncatedTooltip/index.tsx +48 -0
  20. package/src/components/index.tsx +2 -0
  21. package/src/constants/index.ts +3 -0
  22. package/src/helpers/categoryColumns.tsx +55 -0
  23. package/src/helpers/images.tsx +3 -1
  24. package/src/helpers/index.tsx +2 -0
  25. package/src/modules/ActivityLog/ItemLog/EventItem/index.tsx +17 -10
  26. package/src/modules/ActivityLog/ItemLog/EventItem/style.tsx +18 -1
  27. package/src/modules/ActivityLog/ItemLogUser/UserItem/EventItem/index.tsx +10 -7
  28. package/src/modules/ActivityLog/ItemLogUser/UserItem/index.tsx +9 -3
  29. package/src/modules/ActivityLog/ItemLogUser/UserItem/style.tsx +17 -1
  30. package/src/modules/App/Routing/NavMenu/NavItem/style.tsx +1 -0
  31. package/src/modules/App/Routing/index.tsx +2 -2
  32. package/src/modules/App/Routing/style.tsx +8 -1
  33. package/src/modules/Categories/CategoriesList/BulkHeader/TableHeader/style.tsx +1 -0
  34. package/src/modules/Categories/CategoriesList/CategoryItem/index.tsx +7 -3
  35. package/src/modules/Categories/CategoriesList/CategoryItem/style.tsx +38 -5
  36. package/src/modules/Content/BulkHeader/TableHeader/style.tsx +1 -1
  37. package/src/modules/Content/PageItem/index.tsx +80 -204
  38. package/src/modules/Content/PageItem/style.tsx +18 -10
  39. package/src/modules/Content/atoms.tsx +147 -18
  40. package/src/modules/Content/index.tsx +2 -9
  41. package/src/modules/Forms/FormCategoriesList/CategoryItem/index.tsx +7 -3
  42. package/src/modules/Forms/FormCategoriesList/CategoryItem/style.tsx +34 -0
  43. package/src/modules/Forms/FormEditor/index.tsx +28 -50
  44. package/src/modules/Forms/FormList/FormItem/index.tsx +91 -120
  45. package/src/modules/Forms/FormList/FormItem/style.tsx +19 -0
  46. package/src/modules/Forms/FormList/index.tsx +27 -48
  47. package/src/modules/Forms/atoms.tsx +44 -32
  48. package/src/modules/StructuredData/StructuredDataList/BulkHeader/TableHeader/index.tsx +8 -8
  49. package/src/modules/StructuredData/StructuredDataList/BulkHeader/TableHeader/style.tsx +2 -2
  50. package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/index.tsx +83 -101
  51. package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/style.tsx +11 -5
  52. package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/index.tsx +31 -54
  53. package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/style.tsx +13 -7
  54. package/src/modules/Users/Roles/BulkHeader/TableHeader/style.tsx +6 -6
  55. package/src/modules/Users/Roles/RoleItem/index.tsx +3 -4
  56. package/src/modules/Users/Roles/RoleItem/style.tsx +12 -15
  57. package/src/modules/Users/Roles/index.tsx +1 -2
  58. package/src/modules/Users/UserCreate/SiteItem/index.tsx +10 -4
  59. package/src/modules/Users/UserCreate/SiteItem/style.tsx +33 -1
  60. package/src/modules/Users/UserForm/index.tsx +6 -4
  61. package/src/modules/Users/UserList/BulkHeader/TableHeader/index.tsx +2 -4
  62. package/src/modules/Users/UserList/BulkHeader/TableHeader/style.tsx +1 -1
  63. package/src/modules/Users/UserList/UserItem/index.tsx +18 -10
  64. package/src/modules/Users/UserList/UserItem/style.tsx +60 -4
@@ -1,13 +1,33 @@
1
- import React, { useState } from "react";
1
+ import type React from "react";
2
+ import { useState } from "react";
2
3
  import { connect } from "react-redux";
3
4
 
4
- import { CategoryCell, CheckField, Flag, FloatingMenu, Icon, LanguageMenu, Tooltip } from "@ax/components";
5
- import { FormContent, FormLanguage, FormState, ICheck, ILanguage, INotification, IRootState, ISite } from "@ax/types";
6
- import { formsActions } from "@ax/containers/Forms";
5
+ import {
6
+ CategoryCell,
7
+ CheckField,
8
+ Flag,
9
+ FloatingMenu,
10
+ Icon,
11
+ LanguageMenu,
12
+ Tooltip,
13
+ TruncatedTooltip,
14
+ } from "@ax/components";
7
15
  import { appActions } from "@ax/containers/App";
8
- import { useModal, usePermission } from "@ax/hooks";
9
- import { findObjectValue, getHumanLastModifiedDate } from "@ax/helpers";
16
+ import { formsActions } from "@ax/containers/Forms";
10
17
  import { findFieldsErrors } from "@ax/forms";
18
+ import { findObjectValue, getHumanLastModifiedDate } from "@ax/helpers";
19
+ import { useModals, usePermissions } from "@ax/hooks";
20
+ import type {
21
+ FormContent,
22
+ FormLanguage,
23
+ FormState,
24
+ ICheck,
25
+ ILanguage,
26
+ INotification,
27
+ IRootState,
28
+ ISite,
29
+ } from "@ax/types";
30
+
11
31
  import { CopyModal, DeleteModal, DuplicateModal, UnPublishModal } from "../../atoms";
12
32
  import FormUseModal from "../../FormUseModal";
13
33
 
@@ -52,23 +72,17 @@ const FormItem = (props: IFormItemProps): JSX.Element => {
52
72
  const [deleteAllVersions, setDeleteAllVersions] = useState(false);
53
73
  const [duplicateTitle, setDuplicateTitle] = useState("");
54
74
  const [site, setSite] = useState<number | null>(null);
55
- const { isOpen: isDeleteOpen, toggleModal: toggleDeleteModal } = useModal();
56
- const { isOpen: isUnpublishOpen, toggleModal: toggleUnpublishModal } = useModal();
57
- const { isOpen: isDuplicateOpen, toggleModal: toggleDuplicateModal } = useModal();
58
- const { isOpen: isCopyOpen, toggleModal: toggleCopyModal } = useModal();
59
- const { isOpen: isUseOpen, toggleModal: toggleUseModal } = useModal();
60
-
61
- const createFormPermission = isSiteView ? "forms.createForms" : "global.forms.createForms";
62
- const editFormPermission = isSiteView ? "forms.editForms" : "global.forms.editForms";
63
- const deleteFormPermission = isSiteView ? "forms.deleteForms" : "global.forms.deleteForms";
64
- const publishFormPermission = isSiteView ? "forms.publishUnpublishForms" : "global.forms.publishUnpublishForms";
65
- const isAllowedToCreateForm = usePermission(createFormPermission);
66
- const isAllowedToEditForm = usePermission(editFormPermission);
67
- const isAllowedToDeleteForm = usePermission(deleteFormPermission);
68
- const isAllowedToPublishForm = usePermission(publishFormPermission);
75
+ const { isOpen, toggleModal } = useModals(["delete", "unpublish", "duplicate", "copy", "use"]);
76
+
77
+ const isAllowedTo = usePermissions({
78
+ createForms: isSiteView ? "forms.createForms" : "global.forms.createForms",
79
+ editForms: isSiteView ? "forms.editForms" : "global.forms.editForms",
80
+ deleteForms: isSiteView ? "forms.deleteForms" : "global.forms.deleteForms",
81
+ publishUnpublishForms: isSiteView ? "forms.publishUnpublishForms" : "global.forms.publishUnpublishForms",
82
+ });
69
83
 
70
84
  const handleClick = () => {
71
- if (isAllowedToEditForm) {
85
+ if (isAllowedTo.editForms) {
72
86
  onClick(form.id);
73
87
  }
74
88
  };
@@ -83,7 +97,7 @@ const FormItem = (props: IFormItemProps): JSX.Element => {
83
97
  text: "This form is currently used on multiple pages. Please remove it from those pages before deleting.",
84
98
  type: "error",
85
99
  btnText: "Show pages",
86
- onClick: toggleUseModal,
100
+ onClick: () => toggleModal("use"),
87
101
  });
88
102
  } else {
89
103
  const formIds = deleteAllVersions ? dataLanguages.map((lang: FormLanguage) => lang.id) : id;
@@ -92,7 +106,7 @@ const FormItem = (props: IFormItemProps): JSX.Element => {
92
106
  toggleToast("1 form deleted");
93
107
  }
94
108
  }
95
- toggleDeleteModal();
109
+ toggleModal("delete");
96
110
  };
97
111
 
98
112
  const getSelectedFormLanguage = (language: ILanguage) =>
@@ -105,33 +119,20 @@ const FormItem = (props: IFormItemProps): JSX.Element => {
105
119
  const selectedFormLanguage = getSelectedFormLanguage(language);
106
120
 
107
121
  if (selectedFormLanguage) {
108
- if (isAllowedToEditForm) {
109
- onClick(selectedFormLanguage.id);
110
- }
122
+ isAllowedTo.editForms && onClick(selectedFormLanguage.id);
111
123
  } else {
112
124
  createNewTranslation(true);
113
125
  onClick(form.id);
114
126
  }
115
127
  };
116
128
 
117
- const getCurrentLanguages = () => {
118
- const available: ILanguage[] = [];
119
-
120
- dataLanguages.forEach(
121
- (dataLang) =>
122
- languages &&
123
- languages.forEach((language: ILanguage) => {
124
- if (language.id === dataLang.language) {
125
- available.push(language);
126
- }
127
- }),
128
- );
129
-
130
- return available;
129
+ const getCurrentLanguages = (): ILanguage[] => {
130
+ const dataLanguageIds = new Set(dataLanguages.map((lang) => lang.language));
131
+ return languages?.filter((lang) => dataLanguageIds.has(lang.id)) || [];
131
132
  };
132
133
 
133
134
  const currentLanguages = getCurrentLanguages();
134
- const availableLanguages = isAllowedToCreateForm ? languages : currentLanguages;
135
+ const availableLanguages = isAllowedTo.createForms ? languages : currentLanguages;
135
136
 
136
137
  const languageMenu = () => (
137
138
  <LanguageMenu
@@ -155,8 +156,8 @@ const FormItem = (props: IFormItemProps): JSX.Element => {
155
156
  const duplicated = await duplicateForm(form.id, duplicateTitle);
156
157
  if (duplicated) {
157
158
  goToEditor();
159
+ toggleModal("duplicate");
158
160
  }
159
- isDuplicateOpen && toggleDuplicateModal();
160
161
  };
161
162
 
162
163
  const handleCopyForm = async () => {
@@ -169,7 +170,7 @@ const FormItem = (props: IFormItemProps): JSX.Element => {
169
170
 
170
171
  const handleCloseCopyModal = () => {
171
172
  setSite(null);
172
- isCopyOpen && toggleCopyModal();
173
+ toggleModal("copy");
173
174
  };
174
175
 
175
176
  const unpublishForm = async () => {
@@ -178,15 +179,15 @@ const FormItem = (props: IFormItemProps): JSX.Element => {
178
179
  text: "This form is currently used on multiple pages. Please remove it from those pages before unpublishing.",
179
180
  type: "error",
180
181
  btnText: "Show pages",
181
- onClick: toggleUseModal,
182
+ onClick: () => toggleModal("use"),
182
183
  });
183
184
  } else {
184
185
  const isUpdated = await updateFormState(id, "inactive");
185
186
  if (isUpdated) {
186
187
  toggleToast("1 form unpublished");
188
+ toggleModal("unpublish");
187
189
  }
188
190
  }
189
- isUnpublishOpen && toggleUnpublishModal();
190
191
  };
191
192
 
192
193
  const publishForm = async () => {
@@ -202,18 +203,21 @@ const FormItem = (props: IFormItemProps): JSX.Element => {
202
203
  }
203
204
  };
204
205
 
205
- const publishButton =
206
- state && state === "active"
207
- ? {
208
- label: "unpublish",
209
- icon: "offline",
210
- action: toggleUnpublishModal,
211
- }
212
- : {
213
- label: "publish",
214
- icon: "upload-pending",
215
- action: publishForm,
216
- };
206
+ const isActive = state === "active";
207
+ const statusIcon = isActive ? "active" : "offline";
208
+ const statusTooltip = isActive ? "Live" : "Offline";
209
+
210
+ const publishButton = isActive
211
+ ? {
212
+ label: "unpublish",
213
+ icon: "offline",
214
+ action: () => toggleModal("unpublish"),
215
+ }
216
+ : {
217
+ label: "publish",
218
+ icon: "upload-pending",
219
+ action: publishForm,
220
+ };
217
221
 
218
222
  const menuOptions = [];
219
223
 
@@ -221,85 +225,56 @@ const FormItem = (props: IFormItemProps): JSX.Element => {
221
225
  menuOptions.push({
222
226
  label: "Show pages where it is used",
223
227
  icon: "view",
224
- action: () => toggleUseModal(),
228
+ action: () => toggleModal("use"),
225
229
  });
226
230
  }
227
231
 
228
- if (isAllowedToCreateForm) {
232
+ if (isAllowedTo.createForms) {
229
233
  menuOptions.push({
230
234
  label: "duplicate",
231
235
  icon: "duplicate",
232
- action: () => toggleDuplicateModal(),
236
+ action: () => toggleModal("duplicate"),
233
237
  });
234
238
  }
235
239
 
236
- if (isAllowedToCreateForm && isSiteView) {
240
+ if (isAllowedTo.createForms && isSiteView) {
237
241
  menuOptions.push({
238
242
  label: "Copy form in another site",
239
243
  icon: "copy",
240
- action: toggleCopyModal,
244
+ action: () => toggleModal("copy"),
241
245
  });
242
246
  }
243
247
 
244
- if (isAllowedToPublishForm) {
248
+ if (isAllowedTo.publishUnpublishForms) {
245
249
  menuOptions.push(publishButton);
246
250
  }
247
251
 
248
- if (isAllowedToDeleteForm) {
252
+ if (isAllowedTo.deleteForms) {
249
253
  menuOptions.push({
250
254
  label: "delete",
251
255
  icon: "delete",
252
- action: () => toggleDeleteModal(),
256
+ action: () => toggleModal("delete"),
253
257
  });
254
258
  }
255
259
 
256
- const mainDeleteModalAction = {
257
- title: "Delete form",
258
- onClick: removeItem,
259
- };
260
-
261
- const secondaryDeleteModalAction = { title: "Cancel", onClick: toggleDeleteModal };
262
-
263
- const mainUnpublishModalAction = {
264
- title: "Unpublish form",
265
- onClick: unpublishForm,
266
- };
267
-
268
- const secondaryUnpublishModalAction = { title: "Cancel", onClick: toggleUnpublishModal };
269
-
270
- const mainDuplicateModalAction = {
271
- title: "Duplicate form",
272
- onClick: handleDuplicateForm,
273
- disabled: !duplicateTitle.length,
274
- };
275
-
276
- const secondaryDuplicateModalAction = { title: "Cancel", onClick: toggleDuplicateModal };
277
-
278
- const mainCopyModalAction = {
279
- title: "Copy form",
280
- onClick: handleCopyForm,
281
- disabled: !site,
282
- };
283
-
284
- const secondaryCopyModalAction = { title: "Cancel", onClick: handleCloseCopyModal };
285
-
286
- const checkStatus = () => (state === "active" ? "active" : "offline");
287
- const getTooltip = () => (state === "active" ? "Live" : "Offline");
288
-
289
260
  return (
290
261
  <>
291
- <S.FormRow role="rowgroup" selected={isSelected} onClick={handleClick} clickable={isAllowedToEditForm}>
262
+ <S.FormRow role="rowgroup" selected={isSelected} onClick={handleClick} clickable={isAllowedTo.editForms}>
292
263
  <S.CheckCell role="cell" onClick={handleCheckClick}>
293
264
  <CheckField name={`form-${id}`} value={id} checked={isSelected || hoverCheck} onChange={handleOnChange} />
294
265
  </S.CheckCell>
295
- <S.NameCell role="cell">{title}</S.NameCell>
266
+ <S.NameCell role="cell">
267
+ <TruncatedTooltip content={title} expanded top={-5}>
268
+ <S.Title>{title}</S.Title>
269
+ </TruncatedTooltip>
270
+ </S.NameCell>
296
271
  {featuredCategory && (
297
272
  <CategoryCell categories={categories} categoryColors={categoryColors} addCategoryColors={addCategoryColors} />
298
273
  )}
299
274
  <S.UpdateCell role="cell">{getHumanLastModifiedDate(modified)}</S.UpdateCell>
300
275
  <S.StateCell role="cell">
301
- <Tooltip content={getTooltip()}>
302
- <Icon name={checkStatus()} />
276
+ <Tooltip content={statusTooltip}>
277
+ <Icon name={statusIcon} />
303
278
  </Tooltip>
304
279
  </S.StateCell>
305
280
  <S.LangCell role="cell">
@@ -310,41 +285,37 @@ const FormItem = (props: IFormItemProps): JSX.Element => {
310
285
  </S.ActionsCell>
311
286
  </S.FormRow>
312
287
  <DeleteModal
313
- isOpen={isDeleteOpen}
314
- toggleModal={toggleDeleteModal}
315
- mainModalAction={mainDeleteModalAction}
316
- secondaryModalAction={secondaryDeleteModalAction}
288
+ isOpen={isOpen("delete")}
289
+ toggleModal={() => toggleModal("delete")}
290
+ onDelete={removeItem}
317
291
  {...{ title, isTranslated, deleteAllVersions, setDeleteAllVersions }}
318
292
  />
319
293
  <UnPublishModal
320
- isOpen={isUnpublishOpen}
321
- toggleModal={toggleUnpublishModal}
322
- mainModalAction={mainUnpublishModalAction}
323
- secondaryModalAction={secondaryUnpublishModalAction}
294
+ isOpen={isOpen("unpublish")}
295
+ toggleModal={() => toggleModal("unpublish")}
296
+ onUnpublish={unpublishForm}
324
297
  title={title}
325
298
  />
326
299
  <DuplicateModal
327
- isOpen={isDuplicateOpen}
328
- toggleModal={toggleDuplicateModal}
329
- mainModalAction={mainDuplicateModalAction}
330
- secondaryModalAction={secondaryDuplicateModalAction}
300
+ isOpen={isOpen("duplicate")}
301
+ toggleModal={() => toggleModal("duplicate")}
302
+ onDuplicate={handleDuplicateForm}
331
303
  title={duplicateTitle}
332
304
  handleChange={setDuplicateTitle}
333
305
  />
334
306
  <CopyModal
335
- isOpen={isCopyOpen}
307
+ isOpen={isOpen("copy")}
336
308
  toggleModal={handleCloseCopyModal}
337
- mainModalAction={mainCopyModalAction}
338
- secondaryModalAction={secondaryCopyModalAction}
309
+ onCopy={handleCopyForm}
339
310
  site={site}
340
311
  setSite={setSite}
341
312
  lang={language}
342
313
  currentSite={currentSiteInfo?.id || null}
343
314
  />
344
- {isUseOpen && (
315
+ {isOpen("use") && (
345
316
  <FormUseModal
346
- isOpen={isUseOpen}
347
- toggleModal={toggleUseModal}
317
+ isOpen={isOpen("use")}
318
+ toggleModal={() => toggleModal("use")}
348
319
  isSiteView={!!currentSiteInfo?.id}
349
320
  formInUse={formInUse}
350
321
  />
@@ -16,6 +16,23 @@ const NameCell = styled(Cell)`
16
16
  ${(p) => p.theme.textStyle.uiS};
17
17
  color: ${(p) => p.theme.color.textHighEmphasis};
18
18
  flex-grow: 1;
19
+ min-width: 0;
20
+ position: relative;
21
+ > * {
22
+ min-width: 0;
23
+ max-width: 100%;
24
+ }
25
+ `;
26
+
27
+ const Title = styled.div`
28
+ width: 100%;
29
+ ${(p) => p.theme.textStyle.uiS};
30
+ color: ${(p) => p.theme.color.textHighEmphasis};
31
+ overflow: hidden;
32
+ text-overflow: ellipsis;
33
+ white-space: nowrap;
34
+ display: block;
35
+ min-width: 0;
19
36
  `;
20
37
 
21
38
  const TypeCell = styled(Cell)`
@@ -58,6 +75,7 @@ const StyledActionMenu = styled(ActionMenu)`
58
75
 
59
76
  const FormRow = styled(Row)<{ clickable: boolean }>`
60
77
  cursor: ${(p) => (p.clickable ? "pointer" : "default")};
78
+ overflow: hidden;
61
79
  &:hover {
62
80
  ${StyledActionMenu} {
63
81
  opacity: 1;
@@ -77,6 +95,7 @@ const FlagsWrapper = styled.div`
77
95
  export {
78
96
  CheckCell,
79
97
  NameCell,
98
+ Title,
80
99
  TypeCell,
81
100
  UpdateCell,
82
101
  StateCell,
@@ -15,7 +15,7 @@ import { appActions } from "@ax/containers/App";
15
15
  import { formsActions } from "@ax/containers/Forms";
16
16
  import { ITEMS_PER_PAGE } from "@ax/containers/Forms/constants";
17
17
  import { getFormTemplates, getSchemaFormCategories } from "@ax/helpers";
18
- import { useBulkSelection, useCategoryColors, useModal, usePermission, useToast } from "@ax/hooks";
18
+ import { useBulkSelection, useCategoryColors, useModals, usePermissions, useToast } from "@ax/hooks";
19
19
  import type {
20
20
  FormContent,
21
21
  FormState,
@@ -77,11 +77,9 @@ const FormList = (props: IUserListProps): JSX.Element => {
77
77
  const [arePagesTranslated, setArePagesTranslated] = useState(false);
78
78
  const [searchQuery, setSearchQuery] = useState<string>("");
79
79
  const [notification, setNotification] = useState<INotification | null>(errorTemplates);
80
- const { isOpen: isNewOpen, toggleModal: toggleNewModal } = useModal();
81
80
  const { isVisible, toggleToast, setIsVisible, state: toastState } = useToast();
82
81
  const { categoryColors, addCategoryColors } = useCategoryColors();
83
- const { isOpen: isDeleteOpen, toggleModal: toggleDeleteModal } = useModal();
84
- const { isOpen: isUnpublishOpen, toggleModal: toggleUnpublishModal } = useModal();
82
+ const { isOpen, toggleModal } = useModals(["new", "delete", "unpublish"]);
85
83
  const { sortedListStatus, setSortedListStatus } = useSortedListStatus();
86
84
  const { setFiltersSelection, resetFilterQuery, filterValues, query: currentFilterQuery } = useFilterQuery();
87
85
 
@@ -91,12 +89,11 @@ const FormList = (props: IUserListProps): JSX.Element => {
91
89
  const isSearching = searchQuery.length > 0;
92
90
  const isFiltering = currentFilterQuery.length > 0;
93
91
 
94
- const createFormPermission = isSiteView ? "forms.createForms" : "global.forms.createForms";
95
- const deleteFormPermission = isSiteView ? "forms.deleteForms" : "global.forms.deleteForms";
96
- const publishFormPermission = isSiteView ? "forms.publishUnpublishForms" : "global.forms.publishUnpublishForms";
97
- const isAllowedToCreateForm = usePermission(createFormPermission);
98
- const isAllowedToDeleteForm = usePermission(deleteFormPermission);
99
- const isAllowedToPublishForm = usePermission(publishFormPermission);
92
+ const isAllowedTo = usePermissions({
93
+ createForms: isSiteView ? "forms.createForms" : "global.forms.createForms",
94
+ deleteForms: isSiteView ? "forms.deleteForms" : "global.forms.deleteForms",
95
+ publishUnpublishForms: isSiteView ? "forms.publishUnpublishForms" : "global.forms.publishUnpublishForms",
96
+ });
100
97
 
101
98
  const {
102
99
  resetBulkSelection,
@@ -167,7 +164,7 @@ const FormList = (props: IUserListProps): JSX.Element => {
167
164
  goToEditor();
168
165
  };
169
166
 
170
- const addNewAction = () => (Object.keys(formTemplates).length > 1 ? toggleNewModal() : createNewForm());
167
+ const addNewAction = () => (Object.keys(formTemplates).length > 1 ? toggleModal("new") : createNewForm());
171
168
 
172
169
  const handleLanguage = (language: ILanguage) => {
173
170
  const { locale, id } = language;
@@ -201,7 +198,6 @@ const FormList = (props: IUserListProps): JSX.Element => {
201
198
  toggleToast(`${selectedItems.all.length} form${selectedItems.all.length > 1 ? "s" : ""} unpublished`);
202
199
  }
203
200
  }
204
- isUnpublishOpen && toggleUnpublishModal();
205
201
  setIsBulkLoading(false);
206
202
  };
207
203
 
@@ -218,9 +214,9 @@ const FormList = (props: IUserListProps): JSX.Element => {
218
214
  const isDeleted = await deleteForm(idsToBeDeleted);
219
215
  if (isDeleted) {
220
216
  toggleToast(`${selectedItems.all.length} form${selectedItems.all.length > 1 ? "s" : ""} deleted`);
217
+ toggleModal("delete");
221
218
  }
222
219
  }
223
- isDeleteOpen && toggleDeleteModal();
224
220
  setIsBulkLoading(false);
225
221
  };
226
222
 
@@ -229,7 +225,7 @@ const FormList = (props: IUserListProps): JSX.Element => {
229
225
  .filter((form) => selectedItems.all.includes(form.id))
230
226
  .some((form) => form.dataLanguages.length > 1);
231
227
  setArePagesTranslated(hasTranslations);
232
- toggleDeleteModal();
228
+ toggleModal("delete");
233
229
  };
234
230
 
235
231
  const handleSearch = (query: string) => {
@@ -237,7 +233,7 @@ const FormList = (props: IUserListProps): JSX.Element => {
237
233
  setPage(1);
238
234
  };
239
235
 
240
- const bulkActions = isAllowedToPublishForm
236
+ const bulkActions = isAllowedTo.publishUnpublishForms
241
237
  ? [
242
238
  {
243
239
  icon: "upload-pending",
@@ -247,12 +243,12 @@ const FormList = (props: IUserListProps): JSX.Element => {
247
243
  {
248
244
  icon: "offline",
249
245
  text: "unpublish",
250
- action: toggleUnpublishModal,
246
+ action: () => toggleModal("unpublish"),
251
247
  },
252
248
  ]
253
249
  : [];
254
250
 
255
- if (isAllowedToDeleteForm) {
251
+ if (isAllowedTo.deleteForms) {
256
252
  bulkActions.push({
257
253
  icon: "delete",
258
254
  text: "delete",
@@ -282,7 +278,7 @@ const FormList = (props: IUserListProps): JSX.Element => {
282
278
  );
283
279
 
284
280
  const handleCloseModal = () => {
285
- isNewOpen && toggleNewModal();
281
+ isOpen("new") && toggleModal("new");
286
282
  setSelectedTemplate(null);
287
283
  };
288
284
 
@@ -294,22 +290,7 @@ const FormList = (props: IUserListProps): JSX.Element => {
294
290
 
295
291
  const secondaryNewModalAction = { title: "Cancel", onClick: handleCloseModal };
296
292
 
297
- const mainUnpublishModalAction = {
298
- title: `Unpublish form${selectedItems.all.length > 1 ? "s" : ""}`,
299
- onClick: unpublishForm,
300
- };
301
-
302
- const secondaryUnpublishModalAction = { title: "Cancel", onClick: toggleUnpublishModal };
303
-
304
- const mainDeleteModalAction = {
305
- title: isBulkLoading ? "Deleting" : "Delete",
306
- onClick: handleDeleteForm,
307
- disabled: isBulkLoading,
308
- };
309
-
310
- const secondaryDeleteModalAction = { title: "Cancel", onClick: toggleDeleteModal };
311
-
312
- const rightButtonProps = isAllowedToCreateForm
293
+ const rightButtonProps = isAllowedTo.createForms
313
294
  ? {
314
295
  label: "New",
315
296
  action: addNewAction,
@@ -318,8 +299,8 @@ const FormList = (props: IUserListProps): JSX.Element => {
318
299
  : undefined;
319
300
 
320
301
  const emptyProps = {
321
- message: isAllowedToCreateForm ? "To start using forms in your site, create as many forms as you need" : "",
322
- button: isAllowedToCreateForm ? "New form" : undefined,
302
+ message: isAllowedTo.createForms ? "To start using forms in your site, create as many forms as you need" : "",
303
+ button: isAllowedTo.createForms ? "New form" : undefined,
323
304
  action: addNewAction,
324
305
  };
325
306
 
@@ -415,9 +396,9 @@ const FormList = (props: IUserListProps): JSX.Element => {
415
396
  }
416
397
  </S.TableListWrapper>
417
398
  </S.FormListWrapper>
418
- {isNewOpen && (
399
+ {isOpen("new") && (
419
400
  <TemplateModal
420
- isOpen={isNewOpen}
401
+ isOpen={isOpen("new")}
421
402
  toggleModal={handleCloseModal}
422
403
  templates={formTemplates}
423
404
  mainModalAction={mainNewModalAction}
@@ -426,21 +407,19 @@ const FormList = (props: IUserListProps): JSX.Element => {
426
407
  selectedTemplate={selectedTemplate}
427
408
  />
428
409
  )}
429
- {isUnpublishOpen && (
410
+ {isOpen("unpublish") && (
430
411
  <UnPublishModal
431
- isOpen={isUnpublishOpen}
432
- toggleModal={toggleUnpublishModal}
433
- mainModalAction={mainUnpublishModalAction}
434
- secondaryModalAction={secondaryUnpublishModalAction}
412
+ isOpen={isOpen("unpublish")}
413
+ toggleModal={() => toggleModal("unpublish")}
414
+ onUnpublish={unpublishForm}
435
415
  title={selectedItems.all.length > 1 ? "these forms" : "this form"}
436
416
  />
437
417
  )}
438
- {isDeleteOpen && (
418
+ {isOpen("delete") && (
439
419
  <DeleteModal
440
- isOpen={isDeleteOpen}
441
- toggleModal={toggleDeleteModal}
442
- mainModalAction={mainDeleteModalAction}
443
- secondaryModalAction={secondaryDeleteModalAction}
420
+ isOpen={isOpen("delete")}
421
+ toggleModal={() => toggleModal("delete")}
422
+ onDelete={handleDeleteForm}
444
423
  title={selectedItems.all.length > 1 ? "these forms" : "this form"}
445
424
  {...{ isTranslated: arePagesTranslated, deleteAllVersions, setDeleteAllVersions }}
446
425
  />