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
70 changes: 70 additions & 0 deletions src/actions/sponsor-pages-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getRequest,
postRequest,
putRequest,
deleteRequest,
startLoading,
stopLoading,
escapeFilterValue
Expand Down Expand Up @@ -47,6 +48,10 @@ export const RECEIVE_SPONSOR_CUSTOMIZED_PAGE =
export const SPONSOR_CUSTOMIZED_PAGE_ADDED = "SPONSOR_CUSTOMIZED_PAGE_ADDED";
export const SPONSOR_CUSTOMIZED_PAGE_UPDATED =
"SPONSOR_CUSTOMIZED_PAGE_UPDATED";
export const SPONSOR_CUSTOMIZED_PAGE_ARCHIVED =
"SPONSOR_CUSTOMIZED_PAGE_ARCHIVED";
export const SPONSOR_CUSTOMIZED_PAGE_UNARCHIVED =
"SPONSOR_CUSTOMIZED_PAGE_UNARCHIVED";

export const cloneGlobalPage =
(pagesIds, sponsorIds, allSponsors) => async (dispatch, getState) => {
Expand Down Expand Up @@ -353,6 +358,71 @@ export const saveSponsorCustomizedPage =
});
};

export const archiveCustomizedPage = (pageId) => async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const {
entity: { id: sponsorId }
} = currentSponsorState;
const accessToken = await getAccessTokenSafely();
const params = { access_token: accessToken };

dispatch(startLoading());

return putRequest(
null,
createAction(SPONSOR_CUSTOMIZED_PAGE_ARCHIVED)({ pageId }),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsor-pages/${pageId}/archive`,
null,
snackbarErrorHandler
)(params)(dispatch)
.then(() => {
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("edit_sponsor.pages_tab.customized_page_archived")
})
);
})
.finally(() => {
dispatch(stopLoading());
});
};

export const unarchiveCustomizedPage =
(pageId) => async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const {
entity: { id: sponsorId }
} = currentSponsorState;
const accessToken = await getAccessTokenSafely();
const params = { access_token: accessToken };

dispatch(startLoading());

return deleteRequest(
null,
createAction(SPONSOR_CUSTOMIZED_PAGE_UNARCHIVED)({ pageId }),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsor-pages/${pageId}/archive`,
null,
snackbarErrorHandler
)(params)(dispatch)
.then(() => {
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate(
"edit_sponsor.pages_tab.customized_page_unarchived"
)
})
);
})
.finally(() => {
dispatch(stopLoading());
});
};

const normalizeSponsorCustomPage = (entity, summitTZ) => {
const normalizedEntity = {
...entity,
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2489,7 +2489,9 @@
"add_selected_page_template": "Add Selected Page Template",
"managed_page_saved": "Managed Page updated successfully.",
"custom_page_saved": "Custom Sponsor Page saved",
"custom_page_created": "Custom Sponsor Page created"
"custom_page_created": "Custom Sponsor Page created",
"customized_page_archived": "Customized Sponsor Page successfully archived.",
"customized_page_unarchived": "Customized Sponsor Page successfully unarchived."
},
"cart_tab": {
"new_form": "New Form",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { act, screen, waitFor } from "@testing-library/react";
import SponsorPagesTab from "../index";
import { renderWithRedux } from "../../../../utils/test-utils";
import { DEFAULT_STATE as sponsorPagesDefaultState } from "../../../../reducers/sponsors/sponsor-page-pages-list-reducer";
import { getSponsorCustomizedPage } from "../../../../actions/sponsor-pages-actions";
import {
getSponsorCustomizedPage,
archiveCustomizedPage,
unarchiveCustomizedPage
} from "../../../../actions/sponsor-pages-actions";

// Mocks

Expand Down Expand Up @@ -46,7 +50,14 @@ jest.mock("../../../../actions/sponsor-pages-actions", () => ({
),
saveSponsorCustomizedPage: jest.fn(() => () => Promise.resolve()),
saveSponsorManagedPage: jest.fn(() => () => Promise.resolve()),
resetSponsorPage: jest.fn(() => ({ type: "MOCK_ACTION" }))
resetSponsorPage: jest.fn(() => ({ type: "MOCK_ACTION" })),
archiveCustomizedPage: jest.fn(() => () => Promise.resolve()),
unarchiveCustomizedPage: jest.fn(() => () => Promise.resolve())
}));

jest.mock("../../../../actions/sponsor-forms-actions", () => ({
...jest.requireActual("../../../../actions/sponsor-forms-actions"),
getSponsorships: jest.fn(() => () => Promise.resolve())
}));

// Helpers
Expand Down Expand Up @@ -86,6 +97,12 @@ const defaultState = {
},
hideArchived: false,
term: ""
},
currentSummitState: {
currentSummit: {
id: 1,
time_zone: { name: "UTC" }
}
}
};

Expand Down Expand Up @@ -219,4 +236,54 @@ describe("SponsorPagesTab", () => {
).not.toBeInTheDocument();
});
});

it("should call archiveCustomizedPage for non-archived item", async () => {
renderWithRedux(
<SponsorPagesTab sponsor={createSponsor()} summitId={1} summitTZ="UTC" />,
{
initialState: {
sponsorPagePagesListState: {
...defaultState.sponsorPagePagesListState,
customizedPages: {
...defaultState.sponsorPagePagesListState.customizedPages,
pages: [createCustomizedPage(1, { is_archived: false })],
totalItems: 1
}
}
}
}
);

const archiveButton = screen.getByText("general.archive");
await act(async () => {
await userEvent.click(archiveButton);
});

expect(archiveCustomizedPage).toHaveBeenCalledWith(1);
});

it("should call unarchiveCustomizedPage for archived item", async () => {
renderWithRedux(
<SponsorPagesTab sponsor={createSponsor()} summitId={1} summitTZ="UTC" />,
{
initialState: {
sponsorPagePagesListState: {
...defaultState.sponsorPagePagesListState,
customizedPages: {
...defaultState.sponsorPagePagesListState.customizedPages,
pages: [createCustomizedPage(1, { is_archived: true })],
totalItems: 1
}
}
}
}
);

const unarchiveButton = screen.getByText("general.unarchive");
await act(async () => {
await userEvent.click(unarchiveButton);
});

expect(unarchiveCustomizedPage).toHaveBeenCalledWith(1);
});
});
23 changes: 17 additions & 6 deletions src/pages/sponsors/sponsor-pages-tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ import {
saveSponsorManagedPage,
saveSponsorCustomizedPage,
getSponsorCustomizedPage,
resetSponsorPage
resetSponsorPage,
unarchiveCustomizedPage,
archiveCustomizedPage
} from "../../../actions/sponsor-pages-actions";
import { getSponsorships } from "../../../actions/sponsor-forms-actions";
import CustomAlert from "../../../components/mui/custom-alert";
import SearchInput from "../../../components/mui/search-input";
import MuiTable from "../../../components/mui/table/mui-table";
import { DEFAULT_CURRENT_PAGE } from "../../../utils/constants";
import { DEFAULT_CURRENT_PAGE, MAX_PER_PAGE } from "../../../utils/constants";
import AddSponsorPageTemplatePopup from "./components/add-sponsor-page-template-popup";
import PageTemplatePopup from "../../sponsors-global/page-templates/page-template-popup";

Expand All @@ -53,6 +55,9 @@ const SponsorPagesTab = ({
getSponsorCustomizedPages,
saveSponsorCustomizedPage,
getSponsorCustomizedPage,
getSponsorships,
unarchiveCustomizedPage,
archiveCustomizedPage,
resetSponsorPage
}) => {
const [openPopup, setOpenPopup] = useState(null);
Expand Down Expand Up @@ -162,11 +167,13 @@ const SponsorPagesTab = ({
};

const handleAddPage = () => {
setOpenPopup("pagePopup");
getSponsorships(1, MAX_PER_PAGE).then(() => setOpenPopup("pagePopup"));
};

const handleArchiveCustomizedPage = (item) =>
console.log("ARCHIVE CUSTOMIZED ", item);
item.is_archived
? unarchiveCustomizedPage(item.id)
: archiveCustomizedPage(item.id);

const handleArchiveManagedPage = (item) =>
console.log("ARCHIVE MANAGED ", item);
Expand Down Expand Up @@ -217,7 +224,8 @@ const SponsorPagesTab = ({
order,
orderDir
);
}).finally(() => setOpenPopup(null));
})
.finally(() => setOpenPopup(null));
};

const handleSaveCustomizedPage = (entity) => {
Expand All @@ -231,7 +239,8 @@ const SponsorPagesTab = ({
order,
orderDir
);
}).finally(() => setOpenPopup(null));;
})
.finally(() => setOpenPopup(null));
};

const handleClosePagePopup = () => {
Expand Down Expand Up @@ -433,6 +442,8 @@ export default connect(mapStateToProps, {
getSponsorCustomizedPage,
getSponsorCustomizedPages,
saveSponsorCustomizedPage,
unarchiveCustomizedPage,
archiveCustomizedPage,
getSponsorships,
resetSponsorPage
})(SponsorPagesTab);
30 changes: 29 additions & 1 deletion src/reducers/sponsors/sponsor-page-pages-list-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import {
RECEIVE_SPONSOR_CUSTOMIZED_PAGES,
REQUEST_SPONSOR_CUSTOMIZED_PAGES,
RECEIVE_SPONSOR_CUSTOMIZED_PAGE,
RESET_EDIT_PAGE
RESET_EDIT_PAGE,
SPONSOR_CUSTOMIZED_PAGE_ARCHIVED,
SPONSOR_CUSTOMIZED_PAGE_UNARCHIVED
} from "../../actions/sponsor-pages-actions";
import { SET_CURRENT_SUMMIT } from "../../actions/summit-actions";
import { RECEIVE_GLOBAL_SPONSORSHIPS } from "../../actions/sponsor-forms-actions";
Expand Down Expand Up @@ -173,6 +175,32 @@ const sponsorPagePagesListReducer = (state = DEFAULT_STATE, action) => {
const customizedPage = payload.response;
return { ...state, currentEditPage: customizedPage };
}
case SPONSOR_CUSTOMIZED_PAGE_ARCHIVED: {
const { pageId } = payload;
const pages = state.customizedPages.pages.map((page) =>
page.id === pageId ? { ...page, is_archived: true } : page
);
return {
...state,
customizedPages: {
...state.customizedPages,
pages: [...pages]
}
};
}
case SPONSOR_CUSTOMIZED_PAGE_UNARCHIVED: {
const { pageId } = payload;
const pages = state.customizedPages.pages.map((page) =>
page.id === pageId ? { ...page, is_archived: false } : page
);
return {
...state,
customizedPages: {
...state.customizedPages,
pages: [...pages]
}
};
}
case RESET_EDIT_PAGE: {
return { ...state, currentEditPage: DEFAULT_PAGE };
}
Expand Down
Loading