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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import AddFormTemplateItemDialog from "./add-form-template-item-popup";
import SponsorInventoryDialog from "./sponsor-inventory-popup";
import { getInventoryItems } from "../../../actions/inventory-item-actions";
import { DEFAULT_CURRENT_PAGE } from "../../../utils/constants";
import { getSafePageAfterRemove } from "../../../utils/methods";

const FormTemplateItemListPage = ({
formTemplateId,
Expand Down Expand Up @@ -161,9 +162,37 @@ const FormTemplateItemListPage = ({
};

const handleArchiveItem = (item) =>
item.is_archived
(item.is_archived
? unarchiveFormTemplateItem(formTemplateId, item)
: archiveFormTemplateItem(formTemplateId, item);
: archiveFormTemplateItem(formTemplateId, item)
)
.then(() => {
const safePage = getSafePageAfterRemove(
totalFormTemplateItems,
perPage,
currentPage
);
getFormTemplateItems(
formTemplateId,
term,
safePage,
perPage,
order,
orderDir,
showArchived
);
})
.catch(() =>
getFormTemplateItems(
formTemplateId,
term,
currentPage,
perPage,
order,
orderDir,
showArchived
)
);

const handleShowArchivedForms = (ev) => {
getFormTemplateItems(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import FormTemplateDialog from "./form-template-popup";
import history from "../../../history";
import FormTemplateFromDuplicateDialog from "./form-template-from-duplicate-popup";
import { DEFAULT_CURRENT_PAGE } from "../../../utils/constants";
import { getSafePageAfterRemove } from "../../../utils/methods";

const FormTemplateListPage = ({
formTemplates,
Expand Down Expand Up @@ -153,7 +154,32 @@ const FormTemplateListPage = ({
};

const handleArchiveItem = (item) =>
item.is_archived ? unarchiveFormTemplate(item) : archiveFormTemplate(item);
(item.is_archived ? unarchiveFormTemplate(item) : archiveFormTemplate(item))
.then(() => {
const safePage = getSafePageAfterRemove(
totalFormTemplates,
perPage,
currentPage
);
getFormTemplates(
term,
safePage,
perPage,
order,
orderDir,
showArchived
);
})
.catch(() =>
getFormTemplates(
term,
currentPage,
perPage,
order,
orderDir,
showArchived
)
);

const handleShowArchivedForms = (value) => {
getFormTemplates(
Expand Down
31 changes: 29 additions & 2 deletions src/pages/sponsors-global/inventory/inventory-list-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
} from "../../../actions/inventory-item-actions";
import SponsorInventoryDialog from "../form-templates/sponsor-inventory-popup";
import { DEFAULT_CURRENT_PAGE } from "../../../utils/constants";
import { getSafePageAfterRemove } from "../../../utils/methods";

const PREVIEW_BOX_SIZE = 220;
const PREVIEW_MARGIN_BOTTOM = 1;
Expand Down Expand Up @@ -262,9 +263,35 @@ const InventoryListPage = ({
};

const handleArchiveItem = (item) =>
item.is_archived
(item.is_archived
? unarchiveInventoryItem(item)
: archiveInventoryItem(item);
: archiveInventoryItem(item)
)
.then(() => {
const safePage = getSafePageAfterRemove(
totalInventoryItems,
perPage,
currentPage
);
getInventoryItems(
term,
safePage,
perPage,
order,
orderDir,
showArchived
);
})
.catch(() =>
getInventoryItems(
term,
currentPage,
perPage,
order,
orderDir,
showArchived
)
);

const columns = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
import { DEFAULT_CURRENT_PAGE } from "../../../utils/constants";
import PageTemplatePopup from "./page-template-popup";
import PageTemplateClonePopup from "./page-template-clone-popup";
import { getSafePageAfterRemove } from "../../../utils/methods";

const PageTemplateListPage = ({
pageTemplates,
Expand Down Expand Up @@ -119,9 +120,35 @@ const PageTemplateListPage = ({
};

const handleArchive = (item) =>
item.is_archived
(item.is_archived
? unarchivePageTemplate(item.id)
: archivePageTemplate(item.id);
: archivePageTemplate(item.id)
)
.then(() => {
const safePage = getSafePageAfterRemove(
totalPageTemplates,
perPage,
currentPage
);
getPageTemplates(
term,
safePage,
perPage,
order,
orderDir,
showArchived
);
})
.catch(() =>
getPageTemplates(
term,
currentPage,
perPage,
order,
orderDir,
showArchived
)
);

const handleEdit = (row) => {
getPageTemplate(row.id).then(() => setOpenPageDialog(true));
Expand Down
14 changes: 13 additions & 1 deletion src/pages/sponsors/show-pages-list-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import CustomAlert from "../../../components/mui/custom-alert";
import GlobalPagePopup from "./components/global-page/global-page-popup";
import PageTemplatePopup from "../../sponsors-global/page-templates/page-template-popup";
import { DEFAULT_CURRENT_PAGE, MAX_PER_PAGE } from "../../../utils/constants";
import { getSafePageAfterRemove } from "../../../utils/methods";

const ShowPagesListPage = ({
showPages,
Expand Down Expand Up @@ -92,7 +93,18 @@ const ShowPagesListPage = ({
};

const handleArchiveItem = (item) =>
item.is_archived ? unarchiveShowPage(item.id) : archiveShowPage(item.id);
(item.is_archived ? unarchiveShowPage(item.id) : archiveShowPage(item.id))
.then(() => {
const safePage = getSafePageAfterRemove(
totalCount,
perPage,
currentPage
);
getShowPages(term, safePage, perPage, order, orderDir, showArchived);
})
.catch(() =>
getShowPages(term, currentPage, perPage, order, orderDir, showArchived)
);

const handleShowArchivedForms = (ev) => {
getShowPages(
Expand Down
31 changes: 29 additions & 2 deletions src/pages/sponsors/sponsor-form-item-list-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import SponsorFormAddItemFromInventoryPopup from "./components/sponsor-form-add-
import { DEFAULT_CURRENT_PAGE } from "../../../utils/constants";
import { rateCellValidation } from "../../../utils/yup";
import { rateToCents } from "../../../utils/rate-helpers";
import { getSafePageAfterRemove } from "../../../utils/methods";

const SponsorFormItemListPage = ({
match,
Expand Down Expand Up @@ -110,9 +111,35 @@ const SponsorFormItemListPage = ({
};

const handleArchiveItem = (item) =>
item.is_archived
(item.is_archived
? unarchiveSponsorFormItem(formId, item.id)
: archiveSponsorFormItem(formId, item.id);
: archiveSponsorFormItem(formId, item.id)
)
.then(() => {
const safePage = getSafePageAfterRemove(
totalCount,
perPage,
currentPage
);
getSponsorFormItems(
formId,
safePage,
perPage,
order,
orderDir,
showArchived
);
})
.catch(() =>
getSponsorFormItems(
formId,
currentPage,
perPage,
order,
orderDir,
showArchived
)
);

const handleRowDelete = (itemId) => {
deleteSponsorFormItem(formId, itemId).then(() => {
Expand Down
24 changes: 22 additions & 2 deletions src/pages/sponsors/sponsor-forms-list-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import GlobalTemplatePopup from "./components/global-template/global-template-po
import FormTemplatePopup from "./components/form-template/form-template-popup";
import { DEFAULT_CURRENT_PAGE, MAX_PER_PAGE } from "../../../utils/constants";
import { normalizeTiers, sameTierSet } from "./utils";
import { getSafePageAfterRemove } from "../../../utils/methods";

const SponsorFormsListPage = ({
sponsorForms,
Expand Down Expand Up @@ -118,9 +119,28 @@ const SponsorFormsListPage = ({
};

const handleArchiveItem = (item) =>
item.is_archived
(item.is_archived
? unarchiveSponsorForm(item.id)
: archiveSponsorForm(item.id);
: archiveSponsorForm(item.id)
)
.then(() => {
const safePage = getSafePageAfterRemove(
totalCount,
perPage,
currentPage
);
getSponsorForms(term, safePage, perPage, order, orderDir, showArchived);
})
.catch(() =>
getSponsorForms(
term,
currentPage,
perPage,
order,
orderDir,
showArchived
)
);

const handleShowArchivedForms = (ev) => {
getSponsorForms(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
import { rateCellValidation } from "../../../../../../../utils/yup";
import { rateToCents } from "../../../../../../../utils/rate-helpers";
import Restrict from "../../../../../../../routes/restrict";
import { getSafePageAfterRemove } from "../../../../../../../utils/methods";

const SponsorFormsManageItems = ({
term,
Expand Down Expand Up @@ -151,9 +152,37 @@ const SponsorFormsManageItems = ({
};

const handleArchiveItem = (item) =>
item.is_archived
(item.is_archived
? unarchiveSponsorCustomizedFormItem(formId, item.id)
: archiveSponsorCustomizedFormItem(formId, item.id);
: archiveSponsorCustomizedFormItem(formId, item.id)
)
.then(() => {
const safePage = getSafePageAfterRemove(
totalCount,
perPage,
currentPage
);
getSponsorCustomizedFormItems(
formId,
term,
safePage,
perPage,
order,
orderDir,
showArchived
);
})
.catch(() =>
getSponsorCustomizedFormItems(
formId,
term,
currentPage,
perPage,
order,
orderDir,
showArchived
)
);
Comment on lines 154 to +185
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Safe-page logic is applied to both directions, but removal is filter-dependent.

getSafePageAfterRemove is remove-specific, yet this handler uses it for both archive and unarchive paths unconditionally. That can still produce wrong page selection for one direction depending on showArchived filtering (the direction×filter case called out in the PR discussion).

Suggested adjustment
 const handleArchiveItem = (item) =>
   (item.is_archived
     ? unarchiveSponsorCustomizedFormItem(formId, item.id)
     : archiveSponsorCustomizedFormItem(formId, item.id)
   )
     .then(() => {
-      const safePage = getSafePageAfterRemove(
-        totalCount,
-        perPage,
-        currentPage
-      );
+      const isRemoveLikeMutation = !showArchived; // adjust based on actual filter semantics
+      const safePage = isRemoveLikeMutation
+        ? getSafePageAfterRemove(totalCount, perPage, currentPage)
+        : currentPage;
       getSponsorCustomizedFormItems(
         formId,
         term,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items.js`
around lines 154 - 185, The handler handleArchiveItem currently uses
getSafePageAfterRemove for both archive and unarchive flows; change it so
getSafePageAfterRemove(...) is used only when performing a removal
(archiveSponsorCustomizedFormItem) and for the unarchive path call
getSponsorCustomizedFormItems with the existing currentPage (no safe-page
adjustment), keeping the catch behavior consistent by reloading the appropriate
page for the attempted action; update calls around
archiveSponsorCustomizedFormItem(formId, item.id) and
unarchiveSponsorCustomizedFormItem(formId, item.id) to branch the then() logic
so the page argument passed to getSponsorCustomizedFormItems is safePage only
for archive and currentPage for unarchive.


const handleShowArchivedItems = (ev) => {
getSponsorCustomizedFormItems(
Expand Down
34 changes: 32 additions & 2 deletions src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import CustomAlert from "../../../../../components/mui/custom-alert";
import AddSponsorFormTemplatePopup from "./components/add-sponsor-form-template-popup";
import CustomizedFormPopup from "./components/customized-form/customized-form-popup";
import { DEFAULT_CURRENT_PAGE } from "../../../../../utils/constants";
import { getSafePageAfterRemove } from "../../../../../utils/methods";

const SponsorFormsTab = ({
term,
Expand Down Expand Up @@ -146,9 +147,38 @@ const SponsorFormsTab = ({
};

const handleArchiveForm = (item) =>
item.is_archived
(item.is_archived
? unarchiveSponsorCustomizedForm(item.id)
: archiveSponsorCustomizedForm(item.id);
: archiveSponsorCustomizedForm(item.id)
)
.then(() => {
const { perPage, order, orderDir, currentPage, totalCount } =
customizedForms;
const safePage = getSafePageAfterRemove(
totalCount,
perPage,
currentPage
);
getSponsorCustomizedForms(
term,
safePage,
perPage,
order,
orderDir,
showArchived
);
})
.catch(() => {
const { perPage, order, orderDir, currentPage } = customizedForms;
getSponsorCustomizedForms(
term,
currentPage,
perPage,
order,
orderDir,
showArchived
);
});

const handleCustomizedFormManageItems = (item) => {
history.push(
Expand Down
Loading
Loading