-
Notifications
You must be signed in to change notification settings - Fork 4
Feat: sponsor pages CRUD #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
7c18260
bdad14a
315cbcd
7b9f1c1
e6ce3e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,242 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Copyright 2024 OpenStack Foundation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import T from "i18n-react/dist/i18n-react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| putRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| postRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deleteRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stopLoading, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| startLoading, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| authErrorHandler, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| escapeFilterValue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from "openstack-uicore-foundation/lib/utils/actions"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getAccessTokenSafely } from "../utils/methods"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DEFAULT_CURRENT_PAGE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DEFAULT_ORDER_DIR, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DEFAULT_PER_PAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from "../utils/constants"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const ADD_PAGE_TEMPLATE = "ADD_PAGE_TEMPLATE"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const PAGE_TEMPLATE_ADDED = "PAGE_TEMPLATE_ADDED"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const PAGE_TEMPLATE_DELETED = "PAGE_TEMPLATE_DELETED"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const PAGE_TEMPLATE_UPDATED = "PAGE_TEMPLATE_UPDATED"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const RECEIVE_PAGE_TEMPLATE = "RECEIVE_PAGE_TEMPLATE"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const RECEIVE_PAGE_TEMPLATES = "RECEIVE_PAGE_TEMPLATES"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const REQUEST_PAGE_TEMPLATES = "REQUEST_PAGE_TEMPLATES"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const RESET_PAGE_TEMPLATE_FORM = "RESET_PAGE_TEMPLATE_FORM"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const UPDATE_PAGE_TEMPLATE = "UPDATE_PAGE_TEMPLATE"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const PAGE_TEMPLATE_ARCHIVED = "PAGE_TEMPLATE_ARCHIVED"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const PAGE_TEMPLATE_UNARCHIVED = "PAGE_TEMPLATE_UNARCHIVED"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const getPageTemplates = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| term = null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| page = DEFAULT_CURRENT_PAGE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| perPage = DEFAULT_PER_PAGE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| order = "id", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| orderDir = DEFAULT_ORDER_DIR, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hideArchived = false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async (dispatch) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const accessToken = await getAccessTokenSafely(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const filter = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(startLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (term) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const escapedTerm = escapeFilterValue(term); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filter.push(`name=@${escapedTerm},code=@${escapedTerm}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const params = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| page, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expand: "modules", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fields: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "id,code,name,modules,is_archived,modules.kind,modules.id,modules.content", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| relations: "modules,modules.none", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| per_page: perPage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| access_token: accessToken | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hideArchived) filter.push("is_archived==0"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (filter.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params["filter[]"] = filter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (order != null && orderDir != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const orderDirSign = orderDir === 1 ? "" : "-"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params.order = `${orderDirSign}${order}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return getRequest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction(REQUEST_PAGE_TEMPLATES), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction(RECEIVE_PAGE_TEMPLATES), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/page-templates`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| authErrorHandler, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { order, orderDir, page, perPage, term, hideArchived } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )(params)(dispatch).then(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(stopLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const getPageTemplate = (formTemplateId) => async (dispatch) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const accessToken = await getAccessTokenSafely(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(startLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const params = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| access_token: accessToken, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expand: "materials,meta_fields,meta_fields.values" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return getRequest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction(RECEIVE_PAGE_TEMPLATE), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/page-templates/${formTemplateId}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| authErrorHandler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )(params)(dispatch).then(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(stopLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const deletePageTemplate = (formTemplateId) => async (dispatch) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const accessToken = await getAccessTokenSafely(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(startLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const params = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| access_token: accessToken | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return deleteRequest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction(PAGE_TEMPLATE_DELETED)({ formTemplateId }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/page-templates/${formTemplateId}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| authErrorHandler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )(params)(dispatch).then(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(stopLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const resetPageTemplateForm = () => (dispatch) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(createAction(RESET_PAGE_TEMPLATE_FORM)({})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const normalizeEntity = (entity) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const normalizedEntity = { ...entity }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| normalizedEntity.modules = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return normalizedEntity; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const savePageTemplate = (entity) => async (dispatch, getState) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const accessToken = await getAccessTokenSafely(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const params = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| access_token: accessToken | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(startLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const normalizedEntity = normalizeEntity(entity); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (entity.id) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return putRequest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction(UPDATE_PAGE_TEMPLATE), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction(PAGE_TEMPLATE_UPDATED), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/page-templates/${entity.id}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| normalizedEntity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| snackbarErrorHandler, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )(params)(dispatch) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .then(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| snackbarSuccessHandler({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: T.translate("general.success"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| html: T.translate("page_template_list.page_crud.page_saved") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getPageTemplates()(dispatch, getState); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .catch((err) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(err); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .finally(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(stopLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return postRequest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction(ADD_PAGE_TEMPLATE), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction(PAGE_TEMPLATE_ADDED), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/page-templates`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| normalizedEntity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| snackbarErrorHandler, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )(params)(dispatch) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .then(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| snackbarSuccessHandler({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: T.translate("general.success"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| html: T.translate("page_template_list.page_crud.page_created") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getPageTemplates()(dispatch, getState); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .catch((err) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(err); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .finally(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(stopLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* ************************************** ARCHIVE ************************************** */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const archivePageTemplate = (pageTemplateId) => async (dispatch) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const accessToken = await getAccessTokenSafely(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const params = { access_token: accessToken }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return putRequest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction(PAGE_TEMPLATE_ARCHIVED), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/page-templates/${pageTemplateId}/archive`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| snackbarErrorHandler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )(params)(dispatch); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+214
to
+225
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing loading state management in Unlike other async actions ( 🔧 Proposed fix export const archivePageTemplate = (pageTemplateId) => async (dispatch) => {
const accessToken = await getAccessTokenSafely();
const params = { access_token: accessToken };
+ dispatch(startLoading());
+
return putRequest(
null,
createAction(PAGE_TEMPLATE_ARCHIVED),
`${window.SPONSOR_PAGES_API_URL}/api/v1/page-templates/${pageTemplateId}/archive`,
null,
snackbarErrorHandler
- )(params)(dispatch);
+ )(params)(dispatch).then(() => {
+ dispatch(stopLoading());
+ });
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const unarchivePageTemplate = (pageTemplateId) => async (dispatch) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const accessToken = await getAccessTokenSafely(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const params = { access_token: accessToken }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(startLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return deleteRequest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createAction(PAGE_TEMPLATE_UNARCHIVED)({ pageTemplateId }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/page-templates/${pageTemplateId}/archive`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+233
to
+236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Payload structure mismatch with reducer for unarchive. The action dispatches This will cause the unarchive to fail silently (no template will match). Either fix the reducer (recommended - see reducer review) or change the action: - createAction(PAGE_TEMPLATE_UNARCHIVED)({ pageTemplateId }),
+ createAction(PAGE_TEMPLATE_UNARCHIVED)(pageTemplateId),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| snackbarErrorHandler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )(params)(dispatch).then(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dispatch(stopLoading()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -187,7 +187,8 @@ | |||||||||||||||||
| "submission_invitations": "Submission Invitations", | ||||||||||||||||||
| "sponsors_inventory": "Sponsors", | ||||||||||||||||||
| "form_templates": "Form Templates", | ||||||||||||||||||
| "inventory": "Inventory" | ||||||||||||||||||
| "inventory": "Inventory", | ||||||||||||||||||
| "page_templates": "Pages" | ||||||||||||||||||
| }, | ||||||||||||||||||
| "schedule": { | ||||||||||||||||||
| "schedule": "Schedule", | ||||||||||||||||||
|
|
@@ -3874,5 +3875,35 @@ | |||||||||||||||||
| "seat_type": "Select a Seat Type", | ||||||||||||||||||
| "status": "Select a Status" | ||||||||||||||||||
| } | ||||||||||||||||||
| }, | ||||||||||||||||||
| "page_template_list": { | ||||||||||||||||||
| "page_templates": "Page Templates", | ||||||||||||||||||
| "alert_info": "You can create or archive Pages from the list. To edit a Page click on the item's Edit botton.", | ||||||||||||||||||
| "code": "Code", | ||||||||||||||||||
|
Comment on lines
+3879
to
+3882
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo in "botton" should be "button". Proposed fix "page_template_list": {
"page_templates": "Page Templates",
- "alert_info": "You can create or archive Pages from the list. To edit a Page click on the item's Edit botton.",
+ "alert_info": "You can create or archive Pages from the list. To edit a Page click on the item's Edit button.",
"code": "Code",📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| "name": "Name", | ||||||||||||||||||
| "info_mod": "Info Mod", | ||||||||||||||||||
| "upload_mod": "Upload Mod", | ||||||||||||||||||
| "download_mod": "Download Mod", | ||||||||||||||||||
| "hide_archived": "Hide archived pages", | ||||||||||||||||||
| "no_pages": "No pages found.", | ||||||||||||||||||
| "add_new": "New Page", | ||||||||||||||||||
| "add_template": "Using Template", | ||||||||||||||||||
| "delete_form_template_warning": "Are you sure you want to delete form template ", | ||||||||||||||||||
| "using_duplicate": "Using Duplicate", | ||||||||||||||||||
| "add_form_template": "New Form", | ||||||||||||||||||
| "add_using_global_template": "Using Global Template", | ||||||||||||||||||
| "placeholders": { | ||||||||||||||||||
| "search": "Search" | ||||||||||||||||||
| }, | ||||||||||||||||||
| "page_crud": { | ||||||||||||||||||
| "title": "Create New Page", | ||||||||||||||||||
| "add_info": "Add Info", | ||||||||||||||||||
| "add_doc": "Add Document Download", | ||||||||||||||||||
| "add_media": "Add Media Request", | ||||||||||||||||||
| "no_modules": "No modules added yet.", | ||||||||||||||||||
| "save": "Save Page", | ||||||||||||||||||
| "page_saved": "Page saved successfully.", | ||||||||||||||||||
| "page_created": "Page created successfully." | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * Copyright 2024 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * */ | ||
|
|
||
| import React from "react"; | ||
| import { Switch, Route, withRouter } from "react-router-dom"; | ||
| import T from "i18n-react/dist/i18n-react"; | ||
| import { Breadcrumb } from "react-breadcrumbs"; | ||
| import Restrict from "../routes/restrict"; | ||
| import NoMatchPage from "../pages/no-match-page"; | ||
| import EditPageTemplatePage from "../pages/sponsors-global/page-templates/edit-page-template-page"; | ||
| import PageTemplateListPage from "../pages/sponsors-global/page-templates/page-template-list-page"; | ||
|
|
||
| const PageTemplateLayout = ({ match }) => ( | ||
| <div> | ||
| <Breadcrumb | ||
| data={{ | ||
| title: T.translate("page_template_list.page_templates"), | ||
| pathname: match.url | ||
| }} | ||
| /> | ||
| <Switch> | ||
| <Route | ||
| strict | ||
| exact | ||
| path={`${match.url}/new`} | ||
| component={EditPageTemplatePage} | ||
| /> | ||
| <Route | ||
| strict | ||
| exact | ||
| path={`${match.url}/:page_template_id(\\d+)`} | ||
| component={EditPageTemplatePage} | ||
| /> | ||
| <Route | ||
| strict | ||
| exact | ||
| path={`${match.url}`} | ||
| component={PageTemplateListPage} | ||
| /> | ||
| <Route component={NoMatchPage} /> | ||
| </Switch> | ||
| </div> | ||
| ); | ||
|
|
||
| export default Restrict(withRouter(PageTemplateLayout), "page-template"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add quotes around the scope value for consistency.
The value should be quoted to align with other scope variables (lines 5, 16, 17, 18) and to satisfy the linter.
📝 Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 dotenv-linter (4.0.0)
[warning] 21-21: [ValueWithoutQuotes] This value needs to be surrounded in quotes
(ValueWithoutQuotes)
🤖 Prompt for AI Agents