diff --git a/src/actions/sponsor-pages-actions.js b/src/actions/sponsor-pages-actions.js index 6692048c5..af7cdde1c 100644 --- a/src/actions/sponsor-pages-actions.js +++ b/src/actions/sponsor-pages-actions.js @@ -15,21 +15,24 @@ import { createAction, getRequest, postRequest, + putRequest, startLoading, stopLoading, - authErrorHandler, escapeFilterValue } from "openstack-uicore-foundation/lib/utils/actions"; import T from "i18n-react/dist/i18n-react"; +import moment from "moment-timezone"; import { getAccessTokenSafely } from "../utils/methods"; import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions"; import { DEFAULT_CURRENT_PAGE, DEFAULT_ORDER_DIR, - DEFAULT_PER_PAGE + DEFAULT_PER_PAGE, + PAGES_MODULE_KINDS } from "../utils/constants"; export const GLOBAL_PAGE_CLONED = "GLOBAL_PAGE_CLONED"; +export const RESET_EDIT_PAGE = "RESET_EDIT_PAGE"; export const REQUEST_SPONSOR_MANAGED_PAGES = "REQUEST_SPONSOR_MANAGED_PAGES"; export const RECEIVE_SPONSOR_MANAGED_PAGES = "RECEIVE_SPONSOR_MANAGED_PAGES"; @@ -39,6 +42,11 @@ export const REQUEST_SPONSOR_CUSTOMIZED_PAGES = "REQUEST_SPONSOR_CUSTOMIZED_PAGES"; export const RECEIVE_SPONSOR_CUSTOMIZED_PAGES = "RECEIVE_SPONSOR_CUSTOMIZED_PAGES"; +export const RECEIVE_SPONSOR_CUSTOMIZED_PAGE = + "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 cloneGlobalPage = (pagesIds, sponsorIds, allSponsors) => async (dispatch, getState) => { @@ -80,6 +88,10 @@ export const cloneGlobalPage = .finally(() => dispatch(stopLoading())); }; +export const resetSponsorPage = () => (dispatch) => { + dispatch(createAction(RESET_EDIT_PAGE)({})); +}; + /* ************************************************************************ */ /* MANAGED PAGES */ /* ************************************************************************ */ @@ -133,9 +145,9 @@ export const getSponsorManagedPages = 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, + snackbarErrorHandler, { order, orderDir, page, perPage, term, hideArchived, summitTZ } - )(params)(dispatch).then(() => { + )(params)(dispatch).finally(() => { dispatch(stopLoading()); }); }; @@ -225,7 +237,9 @@ export const getSponsorCustomizedPages = const params = { page, - fields: "id,code,name,kind,modules_count,allowed_add_ons", + fields: + "id,code,name,allowed_add_ons,is_archived,modules,allowed_add_ons.type,allowed_add_ons.name,allowed_add_ons.id", + expand: "allowed_add_ons", per_page: perPage, access_token: accessToken }; @@ -246,9 +260,137 @@ export const getSponsorCustomizedPages = 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, + snackbarErrorHandler, { order, orderDir, page, perPage, term, hideArchived, summitTZ } - )(params)(dispatch).then(() => { + )(params)(dispatch).finally(() => { + dispatch(stopLoading()); + }); + }; + +export const getSponsorCustomizedPage = + (pageId) => async (dispatch, getState) => { + const { currentSummitState, currentSponsorState } = getState(); + const { currentSummit } = currentSummitState; + const { + entity: { id: sponsorId } + } = currentSponsorState; + const accessToken = await getAccessTokenSafely(); + + dispatch(startLoading()); + + const params = { + fields: + "id,code,name,allowed_add_ons,is_archived,modules,allowed_add_ons.name,allowed_add_ons.id", + expand: "allowed_add_ons", + access_token: accessToken + }; + + return getRequest( + null, + createAction(RECEIVE_SPONSOR_CUSTOMIZED_PAGE), + `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsor-pages/${pageId}`, + snackbarErrorHandler + )(params)(dispatch).finally(() => { dispatch(stopLoading()); }); }; + +export const saveSponsorCustomizedPage = + (entity) => async (dispatch, getState) => { + const { currentSummitState, currentSponsorState } = getState(); + const { currentSummit } = currentSummitState; + const { + entity: { id: sponsorId } + } = currentSponsorState; + const summitTZ = currentSummit.time_zone.name; + const accessToken = await getAccessTokenSafely(); + + dispatch(startLoading()); + + const normalizedEntity = normalizeSponsorCustomPage(entity, summitTZ); + + const params = { + access_token: accessToken, + fields: "id,code,name,kind,modules_count,allowed_add_ons" + }; + + if (entity.id) { + return putRequest( + null, + createAction(SPONSOR_CUSTOMIZED_PAGE_UPDATED), + `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsor-pages/${entity.id}`, + normalizedEntity, + snackbarErrorHandler, + entity + )(params)(dispatch) + .then(() => { + dispatch( + snackbarSuccessHandler({ + title: T.translate("general.success"), + html: T.translate("edit_sponsor.pages_tab.custom_page_saved") + }) + ); + }) + .finally(() => { + dispatch(stopLoading()); + }); + } + + return postRequest( + null, + createAction(SPONSOR_CUSTOMIZED_PAGE_ADDED), + `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsor-pages`, + normalizedEntity, + snackbarErrorHandler + )(params)(dispatch) + .then(() => { + dispatch( + snackbarSuccessHandler({ + title: T.translate("general.success"), + html: T.translate("edit_sponsor.pages_tab.custom_page_created") + }) + ); + }) + .finally(() => { + dispatch(stopLoading()); + }); + }; + +const normalizeSponsorCustomPage = (entity, summitTZ) => { + const normalizedEntity = { + ...entity, + apply_to_all_add_ons: false + }; + + if (entity.allowed_add_ons.includes("all")) { + normalizedEntity.apply_to_all_add_ons = true; + normalizedEntity.allowed_add_ons = []; + } else { + normalizedEntity.allowed_add_ons = entity.allowed_add_ons.map((e) => e.id); + } + + normalizedEntity.modules = entity.modules.map((module) => { + const normalizedModule = { ...module }; + + if (module.kind === PAGES_MODULE_KINDS.MEDIA && module.upload_deadline) { + normalizedModule.upload_deadline = moment + .tz(module.upload_deadline, summitTZ) + .unix(); + } + + if (module.kind === PAGES_MODULE_KINDS.MEDIA && module.file_type_id) { + normalizedModule.file_type_id = + module.file_type_id?.value || module.file_type_id; + } + + if (module.kind === PAGES_MODULE_KINDS.DOCUMENT && module.file) { + normalizedModule.file = module.file[0] || null; + } + + delete normalizedModule._tempId; + + return normalizedModule; + }); + + return normalizedEntity; +}; diff --git a/src/i18n/en.json b/src/i18n/en.json index 35546d87d..c9f25a6c8 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -3,7 +3,7 @@ "user_not_authz": "Hold on. Your user is not authorized!.", "user_not_set": "Hold on. Can not get any valid user.", "session_expired": "Hold on. Your session expired!.", - "empty_list": "there not are any item that match your criteria.", + "empty_list": "there not are any {item} that match your criteria.", "server_error": "There was a problem with our server, please contact admin.", "empty_list_schedule_events": "Please select a Day and a Location ...", "not_allowed": "You are not allowed here, please login with another user to access this page.", @@ -2487,7 +2487,9 @@ "no_pages": "There are no pages that match the criteria", "add_page_using_template": "Add Page Template", "add_selected_page_template": "Add Selected Page Template", - "managed_page_saved": "Managed Page updated successfully." + "managed_page_saved": "Managed Page updated successfully.", + "custom_page_saved": "Custom Sponsor Page saved", + "custom_page_created": "Custom Sponsor Page created" }, "cart_tab": { "new_form": "New Form", diff --git a/src/pages/sponsors-global/page-templates/page-template-popup/index.js b/src/pages/sponsors-global/page-templates/page-template-popup/index.js index 06930e6e9..6b75729f4 100644 --- a/src/pages/sponsors-global/page-templates/page-template-popup/index.js +++ b/src/pages/sponsors-global/page-templates/page-template-popup/index.js @@ -28,11 +28,15 @@ import { PAGE_MODULES_DOWNLOAD } from "../../../../utils/constants"; import DropdownCheckbox from "../../../../components/mui/dropdown-checkbox"; +import MuiFormikSelectGroup from "../../../../components/mui/formik-inputs/mui-formik-select-group"; +import { querySponsorAddons } from "../../../../actions/sponsor-actions"; -const PageTemplatePopup = ({ pageTemplate, onClose, onSave, sponsorships }) => { +const PageTemplatePopup = ({ pageTemplate, onClose, onSave, sponsorships, summitId, sponsorId, sponsorshipIds }) => { const showSponsorships = Array.isArray(sponsorships) && sponsorships.length > 0; + const showAllowedAddons = summitId && sponsorId && sponsorshipIds?.length > 0; + const infoModuleSchema = yup.object().shape({ kind: yup.string().equals([PAGES_MODULE_KINDS.INFO]), content: yup.string().required(T.translate("validation.required")) @@ -177,7 +181,12 @@ const PageTemplatePopup = ({ pageTemplate, onClose, onSave, sponsorships }) => { fullWidth /> - + { /> )} + {showAllowedAddons && ( + + addon.sponsorship.type.id} + getGroupLabel={(addon) => addon.sponsorship.type.type.name} + placeholder={T.translate( + "edit_sponsor.placeholders.select_add_ons" + )} + /> + + )} @@ -250,7 +275,10 @@ const PageTemplatePopup = ({ pageTemplate, onClose, onSave, sponsorships }) => { PageTemplatePopup.propTypes = { onClose: PropTypes.func.isRequired, onSave: PropTypes.func.isRequired, - sponsorships: PropTypes.array + sponsorships: PropTypes.array, + sponsorshipIds: PropTypes.array, + summitId: PropTypes.number, + sponsorId: PropTypes.number }; export default PageTemplatePopup; diff --git a/src/pages/sponsors/sponsor-forms-tab/components/add-sponsor-form-template-popup/index.js b/src/pages/sponsors/sponsor-forms-tab/components/add-sponsor-form-template-popup/index.js index 77d604d3e..dce024f88 100644 --- a/src/pages/sponsors/sponsor-forms-tab/components/add-sponsor-form-template-popup/index.js +++ b/src/pages/sponsors/sponsor-forms-tab/components/add-sponsor-form-template-popup/index.js @@ -75,18 +75,16 @@ const AddSponsorFormTemplatePopup = ({ }); useEffect(() => { - if (open) { - getSponsorForms( - term, - currentPage, - FIVE_PER_PAGE, - order, - orderDir, - false, - sponsorshipTypeIds - ); - } - }, [open]); + getSponsorForms( + term, + currentPage, + FIVE_PER_PAGE, + order, + orderDir, + false, + sponsorshipTypeIds + ); + }, []); const handlePageChange = (page) => { getSponsorForms( diff --git a/src/pages/sponsors/sponsor-pages-tab/__tests__/sponsor-pages-tab.test.js b/src/pages/sponsors/sponsor-pages-tab/__tests__/sponsor-pages-tab.test.js new file mode 100644 index 000000000..10d610185 --- /dev/null +++ b/src/pages/sponsors/sponsor-pages-tab/__tests__/sponsor-pages-tab.test.js @@ -0,0 +1,222 @@ +import React from "react"; +import userEvent from "@testing-library/user-event"; +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"; + +// Mocks + +jest.mock( + "../components/add-sponsor-page-template-popup", + () => + function MockAddSponsorPageTemplatePopup({ onClose, onSubmit }) { + return ( +
+ + +
+ ); + } +); + +jest.mock( + "../../../sponsors-global/page-templates/page-template-popup", + () => + function MockPageTemplatePopup({ onClose, onSave, pageTemplate }) { + return ( +
+ {pageTemplate?.id} + + +
+ ); + } +); + +jest.mock("../../../../actions/sponsor-pages-actions", () => ({ + ...jest.requireActual("../../../../actions/sponsor-pages-actions"), + getSponsorManagedPages: jest.fn(() => ({ type: "MOCK_ACTION" })), + getSponsorCustomizedPages: jest.fn(() => ({ type: "MOCK_ACTION" })), + getSponsorCustomizedPage: jest.fn( + () => () => Promise.resolve({ id: 1, name: "Test Page" }) + ), + saveSponsorCustomizedPage: jest.fn(() => () => Promise.resolve()), + saveSponsorManagedPage: jest.fn(() => () => Promise.resolve()), + resetSponsorPage: jest.fn(() => ({ type: "MOCK_ACTION" })) +})); + +// Helpers + +const createSponsor = (overrides = {}) => ({ + id: 1, + sponsorships_collection: { sponsorships: [] }, + ...overrides +}); + +const createCustomizedPage = (id, overrides = {}) => ({ + id, + code: `CODE-${id}`, + name: `Page ${id}`, + is_archived: false, + ...overrides +}); + +const defaultState = { + sponsorPagePagesListState: { + ...sponsorPagesDefaultState, + managedPages: { + pages: [], + totalItems: 0, + currentPage: 1, + perPage: 10, + order: "id", + orderDir: 1 + }, + customizedPages: { + pages: [], + totalItems: 0, + currentPage: 1, + perPage: 10, + order: "id", + orderDir: 1 + }, + hideArchived: false, + term: "" + } +}; + +describe("SponsorPagesTab", () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + describe("Component", () => { + it("should open page popup when new page button is clicked", async () => { + renderWithRedux( + , + { initialState: defaultState } + ); + + const newPageButton = screen.getByText("edit_sponsor.pages_tab.new_page"); + await act(async () => { + await userEvent.click(newPageButton); + }); + + expect(screen.getByTestId("page-template-popup")).toBeInTheDocument(); + }); + + it("should close page popup and reset form when close is clicked", async () => { + renderWithRedux( + , + { initialState: defaultState } + ); + + const newPageButton = screen.getByText("edit_sponsor.pages_tab.new_page"); + await act(async () => { + await userEvent.click(newPageButton); + }); + + expect(screen.getByTestId("page-template-popup")).toBeInTheDocument(); + + const closeButton = screen.getByText("Close"); + await act(async () => { + await userEvent.click(closeButton); + }); + + expect( + screen.queryByTestId("page-template-popup") + ).not.toBeInTheDocument(); + }); + + it("should call getSponsorCustomizedPage and open popup when edit is clicked", async () => { + renderWithRedux( + , + { + initialState: { + sponsorPagePagesListState: { + ...defaultState.sponsorPagePagesListState, + customizedPages: { + ...defaultState.sponsorPagePagesListState.customizedPages, + pages: [createCustomizedPage(1)], + totalItems: 1 + } + } + } + } + ); + + const editButton = screen.getByTestId("EditIcon").closest("button"); + await act(async () => { + await userEvent.click(editButton); + }); + + expect(getSponsorCustomizedPage).toHaveBeenCalledWith(1); + await waitFor(() => { + expect(screen.getByTestId("page-template-popup")).toBeInTheDocument(); + }); + }); + + it("should refresh customized pages list after save", async () => { + const { + getSponsorCustomizedPages + } = require("../../../../actions/sponsor-pages-actions"); + + renderWithRedux( + , + { + initialState: { + sponsorPagePagesListState: { + ...defaultState.sponsorPagePagesListState, + customizedPages: { + ...defaultState.sponsorPagePagesListState.customizedPages, + pages: [createCustomizedPage(1)], + totalItems: 1 + } + } + } + } + ); + + const editButton = screen.getByTestId("EditIcon").closest("button"); + await act(async () => { + await userEvent.click(editButton); + }); + + await waitFor(() => { + expect(screen.getByTestId("page-template-popup")).toBeInTheDocument(); + }); + + const saveButton = screen.getByText("Save"); + await act(async () => { + await userEvent.click(saveButton); + }); + + await waitFor(() => { + expect(getSponsorCustomizedPages).toHaveBeenCalledTimes(2); + }); + expect( + screen.queryByTestId("page-template-popup") + ).not.toBeInTheDocument(); + }); + }); +}); diff --git a/src/pages/sponsors/sponsor-pages-tab/index.js b/src/pages/sponsors/sponsor-pages-tab/index.js index 5ca762e97..9365f6cc2 100644 --- a/src/pages/sponsors/sponsor-pages-tab/index.js +++ b/src/pages/sponsors/sponsor-pages-tab/index.js @@ -26,13 +26,17 @@ import AddIcon from "@mui/icons-material/Add"; import { getSponsorManagedPages, getSponsorCustomizedPages, - saveSponsorManagedPage + saveSponsorManagedPage, + saveSponsorCustomizedPage, + getSponsorCustomizedPage, + resetSponsorPage } from "../../../actions/sponsor-pages-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 AddSponsorPageTemplatePopup from "./components/add-sponsor-page-template-popup"; +import PageTemplatePopup from "../../sponsors-global/page-templates/page-template-popup"; const SponsorPagesTab = ({ sponsor, @@ -41,9 +45,14 @@ const SponsorPagesTab = ({ hideArchived, managedPages, customizedPages, + summitTZ, + currentEditPage, getSponsorManagedPages, + saveSponsorManagedPage, getSponsorCustomizedPages, - saveSponsorManagedPage + saveSponsorCustomizedPage, + getSponsorCustomizedPage, + resetSponsorPage }) => { const [openPopup, setOpenPopup] = useState(null); @@ -148,7 +157,11 @@ const SponsorPagesTab = ({ }; const handleUsingTemplate = () => { - setOpenPopup("template"); + setOpenPopup("usingTemplate"); + }; + + const handleAddPage = () => { + setOpenPopup("pagePopup"); }; const handleArchiveCustomizedPage = (item) => @@ -166,7 +179,7 @@ const SponsorPagesTab = ({ }; const handleCustomizedEdit = (item) => { - console.log("EDIT CUSTOMIZED ", item); + getSponsorCustomizedPage(item.id).then(() => setOpenPopup("pagePopup")); }; const handleCustomizedDelete = (itemId) => { @@ -194,10 +207,39 @@ const SponsorPagesTab = ({ const handleSaveManagedPageFromTemplate = (entity) => { saveSponsorManagedPage(entity) - .then(() => getSponsorManagedPages()) + .then(() => { + const { perPage, order, orderDir } = managedPages; + getSponsorManagedPages( + term, + DEFAULT_CURRENT_PAGE, + perPage, + order, + orderDir + ); + }) .finally(() => setOpenPopup(null)); }; + const handleSaveCustomizedPage = (entity) => { + saveSponsorCustomizedPage(entity) + .then(() => { + const { perPage, order, orderDir } = customizedPages; + getSponsorCustomizedPages( + term, + DEFAULT_CURRENT_PAGE, + perPage, + order, + orderDir + ); + }) + .finally(() => setOpenPopup(null)); + }; + + const handleClosePagePopup = () => { + resetSponsorPage(); + setOpenPopup(null); + }; + const baseColumns = (name) => [ { columnKey: "name", @@ -242,6 +284,10 @@ const SponsorPagesTab = ({ ) ]; + const sponsorshipIds = sponsor.sponsorships_collection.sponsorships.map( + (e) => e.id + ); + return ( console.log("open popup new")} + onClick={handleAddPage} startIcon={} sx={{ height: "36px" }} > @@ -354,7 +400,7 @@ const SponsorPagesTab = ({ /> - {openPopup === "template" && ( + {openPopup === "usingTemplate" && ( setOpenPopup(null)} /> )} + + {openPopup === "pagePopup" && ( + + )} ); }; @@ -373,5 +431,8 @@ const mapStateToProps = ({ sponsorPagePagesListState }) => ({ export default connect(mapStateToProps, { getSponsorManagedPages, saveSponsorManagedPage, - getSponsorCustomizedPages + getSponsorCustomizedPage, + getSponsorCustomizedPages, + saveSponsorCustomizedPage, + resetSponsorPage })(SponsorPagesTab); diff --git a/src/reducers/sponsors/sponsor-page-pages-list-reducer.js b/src/reducers/sponsors/sponsor-page-pages-list-reducer.js index d66631d71..9c7f4eb03 100644 --- a/src/reducers/sponsors/sponsor-page-pages-list-reducer.js +++ b/src/reducers/sponsors/sponsor-page-pages-list-reducer.js @@ -16,11 +16,22 @@ import { REQUEST_SPONSOR_MANAGED_PAGES, RECEIVE_SPONSOR_MANAGED_PAGES, RECEIVE_SPONSOR_CUSTOMIZED_PAGES, - REQUEST_SPONSOR_CUSTOMIZED_PAGES + REQUEST_SPONSOR_CUSTOMIZED_PAGES, + RECEIVE_SPONSOR_CUSTOMIZED_PAGE, + RESET_EDIT_PAGE } from "../../actions/sponsor-pages-actions"; import { SET_CURRENT_SUMMIT } from "../../actions/summit-actions"; +import { RECEIVE_GLOBAL_SPONSORSHIPS } from "../../actions/sponsor-forms-actions"; +import { PAGES_MODULE_KINDS } from "../../utils/constants"; -const DEFAULT_STATE = { +const DEFAULT_PAGE = { + code: "", + name: "", + allowed_add_ons: [], + modules: [] +}; + +export const DEFAULT_STATE = { managedPages: { pages: [], order: "name", @@ -39,6 +50,13 @@ const DEFAULT_STATE = { perPage: 10, totalItems: 0 }, + currentEditPage: DEFAULT_PAGE, + sponsorships: { + items: [], + currentPage: 0, + lastPage: 0, + total: 0 + }, term: "", hideArchived: false, summitTZ: "" @@ -130,9 +148,14 @@ const sponsorPagePagesListReducer = (state = DEFAULT_STATE, action) => { code: a.code, name: a.name, allowed_add_ons: a.allowed_add_ons, - info_mod: a.modules_count.info_modules_count, - upload_mod: a.modules_count.media_request_modules_count, - download_mod: a.modules_count.document_download_modules_count + is_archived: a.is_archived, + info_mod: a.modules.filter((m) => m.kind === PAGES_MODULE_KINDS.INFO) + .length, + upload_mod: a.modules.filter((m) => m.kind === PAGES_MODULE_KINDS.MEDIA) + .length, + download_mod: a.modules.filter( + (m) => m.kind === PAGES_MODULE_KINDS.DOCUMENT + ).length })); return { @@ -146,6 +169,41 @@ const sponsorPagePagesListReducer = (state = DEFAULT_STATE, action) => { } }; } + case RECEIVE_SPONSOR_CUSTOMIZED_PAGE: { + const customizedPage = payload.response; + return { ...state, currentEditPage: customizedPage }; + } + case RESET_EDIT_PAGE: { + return { ...state, currentEditPage: DEFAULT_PAGE }; + } + case RECEIVE_GLOBAL_SPONSORSHIPS: { + const { + current_page: currentPage, + last_page: lastPage, + total, + data + } = payload.response; + + const newSponsorships = data.map((s) => ({ + id: s.id, + name: s.type.name + })); + + const items = + currentPage === 1 + ? newSponsorships + : [...state.sponsorships.items, ...newSponsorships]; + + return { + ...state, + sponsorships: { + items, + currentPage, + lastPage, + total + } + }; + } default: return state; }