Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 133 additions & 1 deletion src/actions/sponsor-pages-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,28 @@

import {
createAction,
getRequest,
postRequest,
startLoading,
stopLoading
stopLoading,
authErrorHandler,
escapeFilterValue
} from "openstack-uicore-foundation/lib/utils/actions";
import T from "i18n-react/dist/i18n-react";
import { getAccessTokenSafely } from "../utils/methods";
import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions";
import { DEFAULT_CURRENT_PAGE, DEFAULT_ORDER_DIR, DEFAULT_PER_PAGE } from "../utils/constants";

export const GLOBAL_PAGE_CLONED = "GLOBAL_PAGE_CLONED";

export const REQUEST_SPONSOR_MANAGED_PAGES = "REQUEST_SPONSOR_MANAGED_PAGES";
export const RECEIVE_SPONSOR_MANAGED_PAGES = "RECEIVE_SPONSOR_MANAGED_PAGES";

export const REQUEST_SPONSOR_CUSTOMIZED_PAGES =
"REQUEST_SPONSOR_CUSTOMIZED_PAGES";
export const RECEIVE_SPONSOR_CUSTOMIZED_PAGES =
"RECEIVE_SPONSOR_CUSTOMIZED_PAGES";

export const cloneGlobalPage =
(pagesIds, sponsorIds, allSponsors) => async (dispatch, getState) => {
const { currentSummitState } = getState();
Expand Down Expand Up @@ -62,3 +74,123 @@ export const cloneGlobalPage =
})
.finally(() => dispatch(stopLoading()));
};

/* ************************************************************************ */
/* MANAGED PAGES */
/* ************************************************************************ */

export const getSponsorManagedPages =
(
term = "",
page = DEFAULT_CURRENT_PAGE,
perPage = DEFAULT_PER_PAGE,
order = "id",
orderDir = DEFAULT_ORDER_DIR,
hideArchived = false
) =>
async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const {
entity: { id: sponsorId }
} = currentSponsorState;
const accessToken = await getAccessTokenSafely();
const summitTZ = currentSummit.time_zone.name;
const filter = [];

dispatch(startLoading());

if (term) {
const escapedTerm = escapeFilterValue(term);
filter.push(`name=@${escapedTerm},code=@${escapedTerm}`);
}

const params = {
page,
fields: "id,code,name,kind,modules_count,allowed_add_ons",
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_SPONSOR_MANAGED_PAGES),
createAction(RECEIVE_SPONSOR_MANAGED_PAGES),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/managed-pages`,
authErrorHandler,
{ order, orderDir, page, perPage, term, hideArchived, summitTZ }
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
Comment on lines +127 to +135
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Ensure loading state clears on failures.

stopLoading() only runs on success. If the request fails, loading can remain stuck. Mirror the cloneGlobalPage pattern and use finally.

🛠️ Suggested fix
-    return getRequest(
+    return getRequest(
       createAction(REQUEST_SPONSOR_MANAGED_PAGES),
       createAction(RECEIVE_SPONSOR_MANAGED_PAGES),
       `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/managed-pages`,
       authErrorHandler,
       { order, orderDir, page, perPage, term, hideArchived, summitTZ }
-    )(params)(dispatch).then(() => {
-      dispatch(stopLoading());
-    });
+    )(params)(dispatch)
+      .finally(() => dispatch(stopLoading()));

Apply to both managed and customized requests.

Also applies to: 187-195

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/actions/sponsor-pages-actions.js` around lines 127 - 135, The current
getRequest call that dispatches REQUEST_SPONSOR_MANAGED_PAGES and
RECEIVE_SPONSOR_MANAGED_PAGES only calls dispatch(stopLoading()) inside then(),
so stopLoading() is never dispatched on failures and the loading state can get
stuck; update the promise chain for the managed-pages request (the
getRequest(...) invocation that uses REQUEST_SPONSOR_MANAGED_PAGES /
RECEIVE_SPONSOR_MANAGED_PAGES) to call dispatch(stopLoading()) in a finally()
block (mirror the cloneGlobalPage pattern) so stopLoading() runs regardless of
success or error, and apply the same change to the analogous customized-pages
request (the getRequest using the customized action constants around the 187-195
area).

};

/* ************************************************************************ */
/* CUSTOMIZED PAGES */
/* ************************************************************************ */

export const getSponsorCustomizedPages =
(
term = "",
page = DEFAULT_CURRENT_PAGE,
perPage = DEFAULT_PER_PAGE,
order = "id",
orderDir = DEFAULT_ORDER_DIR,
hideArchived = false
) =>
async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const {
entity: { id: sponsorId }
} = currentSponsorState;
const accessToken = await getAccessTokenSafely();
const summitTZ = currentSummit.time_zone.name;
const filter = [];

dispatch(startLoading());

if (term) {
const escapedTerm = escapeFilterValue(term);
filter.push(`name=@${escapedTerm},code=@${escapedTerm}`);
}

const params = {
page,
fields: "id,code,name,kind,modules_count,allowed_add_ons",
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_SPONSOR_CUSTOMIZED_PAGES),
createAction(RECEIVE_SPONSOR_CUSTOMIZED_PAGES),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsor-pages`,
authErrorHandler,
{ order, orderDir, page, perPage, term, hideArchived, summitTZ }
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};
17 changes: 17 additions & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2461,6 +2461,23 @@
}
}
},
"pages_tab": {
"alert_info": "To add a Sponsor Specific Page for this show's sponsor, click Add Page button. Note: this Page will be visible only to this sponsor for this show. The General Pages can only be managed on the Show's Pages section.",
"hide_archived": "Hide archived Pages",
"using_template": "Using Template",
"new_page": "New Page",
"pages": "pages",
"managed_pages": "Managed Pages",
"sponsor_customized_pages": "Customized Sponsor Pages",
"code": "Code",
"name": "Name",
"add_ons": "Add-ons",
"info_mod": "Info Mod",
"upload_mod": "Upload Mod",
"download_mod": "Download Mod",
"archive": "Archive",
"unarchive": "Unarchive"
},
Comment on lines 2464 to 2480
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add a managed-pages label to match the new table header.

The UI renders a managed pages header, but there’s no dedicated label here. Add a key (and update the component to use it) to avoid falling back to the raw i18n key.

📝 Suggested addition
     "pages_tab": {
       "alert_info": "To add a Sponsor Specific Page for this show's sponsor, click Add Page button. Note: this Page will be visible only to this sponsor for this show. The General Pages can only be managed on the Show's Pages section.",
       "hide_archived": "Hide archived Pages",
       "using_template": "Using Template",
       "new_page": "New Page",
       "pages": "pages",
+      "managed_pages": "Managed Pages",
       "sponsor_customized_pages": "Customized Sponsor Pages",
       "code": "Code",
       "name": "Name",
       "add_ons": "Add-ons",
       "info_mod": "Info Mod",
       "upload_mod": "Upload Mod",
       "download_mod": "Download Mod",
       "archive": "Archive",
       "unarchive": "Unarchive"
     },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"pages_tab": {
"alert_info": "To add a Sponsor Specific Page for this show's sponsor, click Add Page button. Note: this Page will be visible only to this sponsor for this show. The General Pages can only be managed on the Show's Pages section.",
"hide_archived": "Hide archived Pages",
"using_template": "Using Template",
"new_page": "New Page",
"pages": "pages",
"sponsor_customized_pages": "Customized Sponsor Pages",
"code": "Code",
"name": "Name",
"add_ons": "Add-ons",
"info_mod": "Info Mod",
"upload_mod": "Upload Mod",
"download_mod": "Download Mod",
"archive": "Archive",
"unarchive": "Unarchive"
},
"pages_tab": {
"alert_info": "To add a Sponsor Specific Page for this show's sponsor, click Add Page button. Note: this Page will be visible only to this sponsor for this show. The General Pages can only be managed on the Show's Pages section.",
"hide_archived": "Hide archived Pages",
"using_template": "Using Template",
"new_page": "New Page",
"pages": "pages",
"managed_pages": "Managed Pages",
"sponsor_customized_pages": "Customized Sponsor Pages",
"code": "Code",
"name": "Name",
"add_ons": "Add-ons",
"info_mod": "Info Mod",
"upload_mod": "Upload Mod",
"download_mod": "Download Mod",
"archive": "Archive",
"unarchive": "Unarchive"
},
🤖 Prompt for AI Agents
In `@src/i18n/en.json` around lines 2463 - 2478, Add a new i18n key
"managed_pages" under the existing "pages_tab" object in src/i18n/en.json (e.g.,
"pages_tab.managed_pages": "Managed Pages") and update the component that
renders the managed pages header to consume pages_tab.managed_pages instead of
displaying the raw i18n key; ensure the component uses the same i18n path
("pages_tab.managed_pages") so the header no longer falls back to the key
string.

"cart_tab": {
"new_form": "New Form",
"forms": "forms",
Expand Down
8 changes: 8 additions & 0 deletions src/pages/sponsors/edit-sponsor-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import SponsorUsersListPerSponsorPage from "./sponsor-users-list-per-sponsor";
import SponsorFormsTab from "./sponsor-forms-tab";
import SponsorBadgeScans from "./sponsor-badge-scans";
import SponsorCartTab from "./sponsor-cart-tab";
import SponsorPagesTab from "./sponsor-pages-tab";
import SponsorFormsManageItems from "./sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items";
import { SPONSOR_TABS } from "../../utils/constants";
import SponsorPurchasesTab from "./sponsor-purchases-tab";
Expand Down Expand Up @@ -248,6 +249,13 @@ const EditSponsorPage = (props) => {
<CustomTabPanel value={selectedTab} index={1}>
<SponsorUsersListPerSponsorPage sponsor={entity} />
</CustomTabPanel>
<CustomTabPanel value={selectedTab} index={2}>
<SponsorPagesTab
sponsor={entity}
summitId={currentSummit.id}
history={history}
/>
</CustomTabPanel>
<CustomTabPanel value={selectedTab} index={4}>
{isNestedFormItemRoute ? (
<SponsorFormsManageItems match={match} />
Expand Down
Loading