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,25 @@ 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
);
});

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,17 @@ 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);
});

const handleShowArchivedForms = (value) => {
getFormTemplates(
Expand Down
13 changes: 11 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,17 @@ 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);
});

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,17 @@ 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);
});

const handleEdit = (row) => {
getPageTemplate(row.id).then(() => setOpenPageDialog(true));
Expand Down
9 changes: 8 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,13 @@ 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);
});

const handleShowArchivedForms = (ev) => {
getShowPages(
Expand Down
16 changes: 14 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,20 @@ 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
);
});

const handleRowDelete = (itemId) => {
deleteSponsorFormItem(formId, itemId).then(() => {
Expand Down
9 changes: 7 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,13 @@ 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);
});

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,21 @@ 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
);
});

const handleShowArchivedItems = (ev) => {
getSponsorCustomizedFormItems(
Expand Down
18 changes: 16 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,22 @@ 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
);
});

const handleCustomizedFormManageItems = (item) => {
history.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
DEFAULT_CURRENT_PAGE,
SPONSOR_MANAGED_PAGE_ASSIGNMENT
} from "../../../../../utils/constants";
import { getSafePageAfterRemove } from "../../../../../utils/methods";
import AddSponsorPageTemplatePopup from "./components/add-sponsor-page-template-popup";
import PageTemplatePopup from "../../../../sponsors-global/page-templates/page-template-popup";

Expand Down Expand Up @@ -183,10 +184,12 @@ const SponsorPagesTab = ({
? unarchiveCustomizedPage(item.id)
: archiveCustomizedPage(item.id)
).then(() => {
const { perPage, order, orderDir, currentPage } = customizedPages;
const { perPage, order, orderDir, currentPage, totalItems } =
customizedPages;
const safePage = getSafePageAfterRemove(totalItems, perPage, currentPage);
return getSponsorCustomizedPages(
term,
currentPage,
safePage,
perPage,
order,
orderDir,
Expand Down
7 changes: 7 additions & 0 deletions src/utils/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,3 +629,10 @@ export const formatDate = (date, timeZone, format = DATETIME_FORMAT) => {
.tz(timeZone)
.format(format);
};

export const getSafePageAfterRemove = (totalCount, perPage, currentPage) => {
const totalAfter = totalCount - 1;
const totalPages = Math.ceil(totalAfter / perPage);
const lastValidPage = Math.max(1, totalPages);
return Math.min(currentPage, lastValidPage);
};
Loading