Skip to content
Merged
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
69 changes: 69 additions & 0 deletions src/actions/sponsor-pages-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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 @@ -390,6 +394,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 @@ -2495,7 +2495,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);
});
});
21 changes: 20 additions & 1 deletion src/pages/sponsors/sponsor-pages-tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
saveSponsorCustomizedPage,
getSponsorCustomizedPage,
deleteSponsorManagedPage,
unarchiveCustomizedPage,
archiveCustomizedPage,
resetSponsorPage
} from "../../../actions/sponsor-pages-actions";
import CustomAlert from "../../../components/mui/custom-alert";
Expand Down Expand Up @@ -57,6 +59,8 @@ const SponsorPagesTab = ({
saveSponsorCustomizedPage,
getSponsorCustomizedPage,
deleteSponsorManagedPage,
unarchiveCustomizedPage,
archiveCustomizedPage,
resetSponsorPage
}) => {
const [openPopup, setOpenPopup] = useState(null);
Expand Down Expand Up @@ -170,7 +174,20 @@ const SponsorPagesTab = ({
};

const handleArchiveCustomizedPage = (item) =>
console.log("ARCHIVE CUSTOMIZED ", item);
(item.is_archived
? unarchiveCustomizedPage(item.id)
: archiveCustomizedPage(item.id)
).then(() => {
const { perPage, order, orderDir, currentPage } = customizedPages;
return getSponsorCustomizedPages(
term,
currentPage,
perPage,
order,
orderDir,
hideArchived
);
});

const handleArchiveManagedPage = (item) =>
console.log("ARCHIVE MANAGED ", item);
Expand Down Expand Up @@ -453,5 +470,7 @@ export default connect(mapStateToProps, {
getSponsorCustomizedPages,
saveSponsorCustomizedPage,
deleteSponsorManagedPage,
unarchiveCustomizedPage,
archiveCustomizedPage,
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,
Copy link

Choose a reason for hiding this comment

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

@tomrndom
is_archived not mapped from API response in RECEIVE_SPONSOR_CUSTOMIZED_PAGES

Copy link
Author

Choose a reason for hiding this comment

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

@smarcet this is mapped at

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 @@ -174,6 +176,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