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
32 changes: 2 additions & 30 deletions src/actions/sponsor-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
fetchErrorHandler,
postFile
} from "openstack-uicore-foundation/lib/utils/actions";
import debounce from "lodash/debounce"
import debounce from "lodash/debounce";
import URI from "urijs";
import { getAccessTokenSafely } from "../utils/methods";
import { normalizeLeadReportSettings } from "../models/lead-report-settings";
Expand Down Expand Up @@ -64,10 +64,6 @@ export const SPONSOR_TIER_DELETED = "SPONSOR_TIER_DELETED";
export const REQUEST_SPONSOR_SPONSORSHIPS = "REQUEST_SPONSOR_SPONSORSHIPS";
export const RECEIVE_SPONSOR_SPONSORSHIPS = "RECEIVE_SPONSOR_SPONSORSHIPS";
export const SET_SELECTED_SPONSORSHIP = "SET_SELECTED_SPONSORSHIP";
export const REQUEST_SPONSOR_SPONSORSHIPS_ADDONS =
"REQUEST_SPONSOR_SPONSORSHIPS_ADDONS";
export const RECEIVE_SPONSOR_SPONSORSHIPS_ADDONS =
"RECEIVE_SPONSOR_SPONSORSHIPS_ADDONS";
export const SPONSOR_SPONSORSHIPS_ADDON_ADDED =
"SPONSOR_SPONSORSHIPS_ADDON_ADDED";
export const SPONSOR_SPONSORSHIPS_ADDON_UPDATED =
Expand Down Expand Up @@ -356,7 +352,7 @@ export const addSponsorToSummit = (entity) => async (dispatch, getState) => {
.finally(() => dispatch(stopLoading()));
};

export const getSponsorTiers =
export const getSponsorSponsorships =
(
sponsorId,
currentPage = DEFAULT_CURRENT_PAGE,
Expand Down Expand Up @@ -483,30 +479,6 @@ const normalizeTiersForSponsor = (entity) => {
return normalizedEntity;
};

export const getSponsorshipAddons = (sponsorshipId) => async (dispatch) => {
const { currentSummitState } = getState();
const accessToken = await getAccessTokenSafely();
const { currentSummit } = currentSummitState;
const {
entity: { id: sponsorId }
} = currentSponsorState;

const params = {
access_token: accessToken
};

dispatch(startLoading());

return getRequest(
createAction(REQUEST_SPONSOR_SPONSORSHIPS_ADDONS),
createAction(RECEIVE_SPONSOR_SPONSORSHIPS_ADDONS),
`${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsorships/${sponsorshipId}/addons`,
authErrorHandler
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};

export const setSelectedSponsorship = (sponsorship) => (dispatch) => {
dispatch(createAction(SET_SELECTED_SPONSORSHIP)({ sponsorship }));
};
Expand Down
7 changes: 5 additions & 2 deletions src/actions/sponsor-forms-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,11 @@ const normalizeSponsorManagedForm = (entity) => {
};

export const getSponsorManagedForm = (formId) => async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const {
entity: { id: sponsorId }
} = currentSponsorState;
const accessToken = await getAccessTokenSafely();

dispatch(startLoading());
Expand All @@ -654,7 +657,7 @@ export const getSponsorManagedForm = (formId) => async (dispatch, getState) => {
return getRequest(
null,
createAction(RECEIVE_SPONSOR_CUSTOMIZED_FORM),
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/show-forms/${formId}`,
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/managed-forms/${formId}`,
snackbarErrorHandler
)(params)(dispatch).then(() => {
dispatch(stopLoading());
Expand Down
2 changes: 1 addition & 1 deletion src/pages/sponsors/__tests__/edit-sponsor-page.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jest.mock("../../../actions/sponsor-actions", () => ({
getSponsorMaterials: jest.fn(() => ({ type: "MOCK_ACTION" })),
getSponsorSocialNetworks: jest.fn(() => ({ type: "MOCK_ACTION" })),
getSponsorLeadReportSettingsMeta: jest.fn(() => ({ type: "MOCK_ACTION" })),
getSponsorTiers: jest.fn(() => ({ type: "MOCK_ACTION" })),
getSponsorSponsorships: jest.fn(() => ({ type: "MOCK_ACTION" })),
getExtraQuestionMeta: jest.fn(() => ({ type: "MOCK_ACTION" })),
resetSponsorForm: jest.fn(() => ({ type: "MOCK_ACTION" }))
}));
Expand Down
8 changes: 4 additions & 4 deletions src/pages/sponsors/sponsor-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
getSponsorLeadReportSettingsMeta,
getSponsorMaterials,
getSponsorSocialNetworks,
getSponsorTiers,
getSponsorSponsorships,
resetSponsorForm
} from "../../../actions/sponsor-actions";
import { getSponsorPurchasesMeta } from "../../../actions/sponsor-settings-actions";
Expand All @@ -39,7 +39,7 @@ const SponsorPage = ({
getSponsorMaterials,
getSponsorSocialNetworks,
getSponsorLeadReportSettingsMeta,
getSponsorTiers,
getSponsorSponsorships,
getExtraQuestionMeta,
getSponsorPurchasesMeta
}) => {
Expand All @@ -49,7 +49,7 @@ const SponsorPage = ({
getSponsorMaterials(entity.id);
getSponsorSocialNetworks(entity.id);
getSponsorLeadReportSettingsMeta(entity.id);
getSponsorTiers(entity.id);
getSponsorSponsorships(entity.id);
getExtraQuestionMeta();
getSponsorPurchasesMeta();
} else {
Expand Down Expand Up @@ -103,7 +103,7 @@ export default connect(mapStateToProps, {
getSponsorMaterials,
getSponsorSocialNetworks,
getSponsorLeadReportSettingsMeta,
getSponsorTiers,
getSponsorSponsorships,
getExtraQuestionMeta,
getSponsorPurchasesMeta
})(SponsorPage);
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@ jest.mock("actions/sponsor-forms-actions", () => ({

jest.mock("../customized-form", () => ({
__esModule: true,
default: ({ onSubmit, isSaving }) => (
<button
type="button"
disabled={isSaving}
onClick={() => onSubmit({ code: "111" })}
>
submit-customized-form
</button>
)
default: ({ onSubmit, isSaving, sponsor, summitId }) => {
const sponsorshipIds = (sponsor?.sponsorships || []).map((s) => s.id);
return (
<>
<button
type="button"
disabled={isSaving}
onClick={() => onSubmit({ code: "111" })}
>
submit-customized-form
</button>
<span
data-testid="addon-query-params"
data-params={JSON.stringify([summitId, sponsor?.id, sponsorshipIds])}
/>
</>
);
}
}));

describe("CustomizedFormPopup", () => {
Expand All @@ -41,17 +50,34 @@ describe("CustomizedFormPopup", () => {
}
};

const sponsor = {
const createSponsor = (overrides = {}) => ({
id: 1,
sponsorships_collection: {
sponsorships: []
}
};
sponsorships: [{ id: 42 }],
...overrides
});

const sponsor = createSponsor();

beforeEach(() => {
jest.clearAllMocks();
});

it("passes sponsorship ids and summitId to the form as queryParams", () => {
renderWithRedux(
<CustomizedFormPopup
formId={null}
open
onClose={jest.fn()}
sponsor={createSponsor({ sponsorships: [{ id: 42 }, { id: 99 }] })}
summitId={69}
/>,
{ initialState }
);

const el = screen.getByTestId("addon-query-params");
expect(JSON.parse(el.dataset.params)).toEqual([69, 1, [42, 99]]);
});

it("keeps modal open when save fails", async () => {
const onClose = jest.fn();
const onSaved = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ const CustomizedForm = ({
isSaving = false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The entity mock in customized-form-popup.test.js still uses the old shape (sponsorships_collection: { sponsorships: [] }), so sponsor.sponsorships is undefined in every test and sponsorshipIds is always []. The non-empty filtering path is never exercised.

Consider updating the mock to the new shape and adding an assertion that the sponsorship ID reaches the queryParams prop on the MuiFormikSelectGroup that loads add-ons:

// customized-form-popup.test.js
const createSponsor = (overrides = {}) => ({
  id: 1,
  sponsorships: [{ id: 42 }],
  ...overrides
});

onSubmit
}) => {
const sponsorships = sponsor.sponsorships_collection.sponsorships.map(
(e) => e.id
);
const sponsorshipIds = sponsor.sponsorships?.map((e) => e.id) || [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tomrndom define sponsorships: [] at DEFAULT_ENTITY in sponsor-reducer.js


const formik = useFormik(
{
Expand Down Expand Up @@ -126,7 +124,7 @@ const CustomizedForm = ({
name="allowed_add_ons"
queryFunction={querySponsorAddons}
// params for function, except input
queryParams={[summitId, sponsor.id, sponsorships]}
queryParams={[summitId, sponsor.id, sponsorshipIds]}
showSelectAll
getGroupId={(addon) => addon.sponsorship.type.id}
getGroupLabel={(addon) => addon.sponsorship.type.type.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import {
deleteExtraQuestion,
getSponsorExtraQuestion,
getSponsorLeadReportSettingsMeta,
getSponsorshipAddons,
getSponsorTiers,
getSponsorSponsorships,
removeAddonToSponsorship,
removeTierFromSponsor,
resetSponsorExtraQuestionForm,
Expand All @@ -40,10 +39,9 @@ const SponsorGeneralForm = ({
sponsor,
member,
currentSummit,
getSponsorTiers,
getSponsorSponsorships,
addTierToSponsor,
removeTierFromSponsor,
getSponsorshipAddons,
setSelectedSponsorship,
saveAddonsToSponsorship,
removeAddonToSponsorship,
Expand All @@ -57,7 +55,7 @@ const SponsorGeneralForm = ({
updateExtraQuestionOrder
}) => {
const handleSponsorshipPaginate = (page, perPage, order, orderDir) => {
getSponsorTiers(sponsor.id, page, perPage, order, orderDir);
getSponsorSponsorships(sponsor.id, page, perPage, order, orderDir);
};

return (
Expand All @@ -70,7 +68,6 @@ const SponsorGeneralForm = ({
onSponsorshipPaginate={handleSponsorshipPaginate}
onSponsorshipAdd={addTierToSponsor}
onSponsorshipDelete={removeTierFromSponsor}
getSponsorshipAddons={getSponsorshipAddons}
onSponsorshipSelect={setSelectedSponsorship}
onSponsorshipAddonSave={saveAddonsToSponsorship}
onSponsorshipAddonRemove={removeAddonToSponsorship}
Expand Down Expand Up @@ -108,10 +105,9 @@ const mapStateToProps = ({

export default connect(mapStateToProps, {
getSponsorLeadReportSettingsMeta,
getSponsorTiers,
getSponsorSponsorships,
addTierToSponsor,
removeTierFromSponsor,
getSponsorshipAddons,
saveAddonsToSponsorship,
removeAddonToSponsorship,
setSelectedSponsorship,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const Sponsorship = ({
onSponsorshipPaginate,
onSponsorshipAdd,
onSponsorshipDelete,
getSponsorshipAddons,
onSponsorshipSelect,
onSponsorshipAddonSave,
onSponsorshipAddonRemove
Expand Down Expand Up @@ -186,7 +185,6 @@ const Sponsorship = ({
sponsorship={selectedSponsorship}
summitId={summitId}
open={showManageTierAddonsPopup}
getSponsorshipAddons={getSponsorshipAddons}
onSponsorshipAddonRemove={onSponsorshipAddonRemove}
onClose={handleCloseManageAddonsPopup}
onSubmit={handleAddSponsorshipAddon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jest.mock("../../../../../../actions/summit-actions", () => ({

const createSponsor = (overrides = {}) => ({
id: 1,
sponsorships_collection: { sponsorships: [] },
sponsorships: [],
...overrides
});

Expand Down Expand Up @@ -125,7 +125,7 @@ const defaultState = {
}
},
currentSponsorState: {
entity: { id: 1, sponsorships_collection: { sponsorships: [] } },
entity: { id: 1, sponsorships: [] },
errors: {}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,7 @@ const SponsorPagesTab = ({
)
];

const sponsorshipIds = sponsor.sponsorships_collection.sponsorships.map(
(e) => e.id
);
const sponsorshipIds = sponsor.sponsorships?.map((e) => e.id) || [];

return (
<Box sx={{ mt: 2 }}>
Expand Down
5 changes: 5 additions & 0 deletions src/reducers/sponsors/sponsor-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const DEFAULT_ENTITY = {
extra_questions: [],
lead_report_setting: {},
available_lead_report_columns: [],
sponsorships: [],
sponsorships_collection: DEFAULT_SPONSORHIPS_STATE
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};

Expand Down Expand Up @@ -163,6 +164,10 @@ const sponsorReducer = (state = DEFAULT_STATE, action) => {
}
}

if (!Array.isArray(entity.sponsorships)) {
entity.sponsorships = [];
}

if (!entity.lead_report_setting) entity.lead_report_setting = {};

return {
Expand Down
Loading