Skip to content
Closed
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
172 changes: 172 additions & 0 deletions src/actions/sponsor-pages-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export const RECEIVE_SPONSOR_PAGES = "RECEIVE_SPONSOR_PAGES";

export const GLOBAL_PAGE_CLONED = "GLOBAL_PAGE_CLONED";

export const REQUEST_SPONSOR_MANAGED_PAGES = "REQUEST_SPONSOR_MANAGED_PAGES";
export const RECEIVE_SPONSOR_MANAGED_PAGES = "RECEIVE_SPONSOR_MANAGED_PAGES";
export const SPONSOR_MANAGED_PAGE_ADDED = "SPONSOR_MANAGED_PAGE_ADDED";

export const REQUEST_SPONSOR_CUSTOMIZED_PAGES =
"REQUEST_SPONSOR_CUSTOMIZED_PAGES";
export const RECEIVE_SPONSOR_CUSTOMIZED_PAGES =
"RECEIVE_SPONSOR_CUSTOMIZED_PAGES";

export const getSponsorPages =
(
term = "",
Expand Down Expand Up @@ -133,3 +142,166 @@ export const cloneGlobalPage =
})
.finally(() => dispatch(stopLoading()));
};

/* ************************************************************************ */
/* MANAGED PAGES */
/* ************************************************************************ */

export const getSponsorManagedPages =
(
term = "",
page = DEFAULT_CURRENT_PAGE,
perPage = DEFAULT_PER_PAGE,
order = "id",
orderDir = DEFAULT_ORDER_DIR,
hideArchived = false
) =>
async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const {
entity: { id: sponsorId }
} = currentSponsorState;
const accessToken = await getAccessTokenSafely();
const summitTZ = currentSummit.time_zone.name;
const filter = [];

dispatch(startLoading());

if (term) {
const escapedTerm = escapeFilterValue(term);
filter.push(`name=@${escapedTerm},code=@${escapedTerm}`);
}

const params = {
page,
fields: "id,code,name,kind,modules_count,allowed_add_ons",
per_page: perPage,
access_token: accessToken
};

if (hideArchived) filter.push("is_archived==0");

if (filter.length > 0) {
params["filter[]"] = filter;
}

// order
if (order != null && orderDir != null) {
const orderDirSign = orderDir === 1 ? "" : "-";
params.order = `${orderDirSign}${order}`;
}

return getRequest(
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,
{ order, orderDir, page, perPage, term, hideArchived, summitTZ }
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};

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

dispatch(startLoading());

const normalizedEntity = normalizeSponsorManagedPage(entity);

const params = {
access_token: accessToken,
fields: "id,code,name,kind,modules_count,allowed_add_ons"
};

return postRequest(
null,
createAction(SPONSOR_MANAGED_PAGE_ADDED),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/managed-pages`,
normalizedEntity,
snackbarErrorHandler
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};

const normalizeSponsorManagedPage = (entity) => {
const normalizedEntity = {
show_page_ids: entity.pages,
allowed_add_ons: entity.add_ons.map((a) => a.id),
apply_to_all_add_ons: false
};

if (entity.add_ons.includes("all")) {
normalizedEntity.apply_to_all_add_ons = true;
normalizedEntity.allowed_add_ons = [];
}

return normalizedEntity;
};
/* ************************************************************************ */
/* CUSTOMIZED PAGES */
/* ************************************************************************ */

export const getSponsorCustomizedPages =
(
term = "",
page = DEFAULT_CURRENT_PAGE,
perPage = DEFAULT_PER_PAGE,
order = "id",
orderDir = DEFAULT_ORDER_DIR,
hideArchived = false
) =>
async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const {
entity: { id: sponsorId }
} = currentSponsorState;
const accessToken = await getAccessTokenSafely();
const summitTZ = currentSummit.time_zone.name;
const filter = [];

dispatch(startLoading());

if (term) {
const escapedTerm = escapeFilterValue(term);
filter.push(`name=@${escapedTerm},code=@${escapedTerm}`);
}

const params = {
page,
fields: "id,code,name,kind,modules_count,allowed_add_ons",
per_page: perPage,
access_token: accessToken
};

if (hideArchived) filter.push("is_archived==0");

if (filter.length > 0) {
params["filter[]"] = filter;
}

// order
if (order != null && orderDir != null) {
const orderDirSign = orderDir === 1 ? "" : "-";
params.order = `${orderDirSign}${order}`;
}

return getRequest(
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,
{ order, orderDir, page, perPage, term, hideArchived, summitTZ }
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};
124 changes: 76 additions & 48 deletions src/components/mui/formik-inputs/mui-formik-select-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const MuiFormikSelectGroup = ({
selectAllLabel = "Select All",
getOptionLabel = (item) => item.name,
getOptionValue = (item) => item.id,
noOptionsLabel = "No items",
getGroupId = null,
getGroupLabel = null,
disabled = false
Expand Down Expand Up @@ -213,6 +214,79 @@ const MuiFormikSelectGroup = ({
.flat()
.filter(Boolean);

const renderMenuContent = () => {
if (loading) {
return (
<MenuItem disabled>
<CircularProgress size={20} />
</MenuItem>
);
}

if (options.length === 0) {
return (
<MenuItem disabled>
<ListItemText
primary={noOptionsLabel}
slotProps={{
primary: {
sx: {
fontSize: "16px",
color: "#00000061"
}
}
}}
/>
</MenuItem>
);
}

return (
<>
{showSelectAll && (
<>
<MenuItem
value="selectAll"
sx={{
backgroundColor: "#fafafa",
"&:hover": {
backgroundColor: "#f0f0f0"
}
}}
onClick={() => {
// custom event value to select all
handleChange({ target: { value: ["selectAll"] } });
}}
>
<Checkbox
checked={isAllSelected}
indeterminate={selectedValues.length > 0 && !isAllSelected}
sx={{
p: 1,
"& svg": {
fontSize: 24
}
}}
/>
<ListItemText
primary={selectAllLabel}
slotProps={{
primary: {
sx: {
fontSize: "16px"
}
}
}}
/>
</MenuItem>
<Divider />
</>
)}
{renderGroupedOptions()}
</>
);
};

const IconWithLoading = useMemo(() => getCustomIcon(loading), [loading]);

return (
Expand Down Expand Up @@ -243,54 +317,7 @@ const MuiFormikSelectGroup = ({
error={Boolean(error)}
IconComponent={IconWithLoading}
>
{loading ? (
<MenuItem disabled>
<CircularProgress size={20} />
</MenuItem>
) : (
<>
{showSelectAll && options.length > 0 && (
<>
<MenuItem
value="selectAll"
sx={{
backgroundColor: "#fafafa",
"&:hover": {
backgroundColor: "#f0f0f0"
}
}}
onClick={() => {
// custom event value to select all
handleChange({ target: { value: ["selectAll"] } });
}}
>
<Checkbox
checked={isAllSelected}
indeterminate={selectedValues.length > 0 && !isAllSelected}
sx={{
p: 1,
"& svg": {
fontSize: 24
}
}}
/>
<ListItemText
primary={selectAllLabel}
slotProps={{
primary: {
sx: {
fontSize: "16px"
}
}
}}
/>
</MenuItem>
<Divider />
</>
)}
{renderGroupedOptions()}
</>
)}
{renderMenuContent()}
</Select>
{error && (
<div
Expand Down Expand Up @@ -318,6 +345,7 @@ MuiFormikSelectGroup.propTypes = {
getOptionValue: PropTypes.func,
getGroupId: PropTypes.func,
getGroupLabel: PropTypes.func,
noOptionsLabel: PropTypes.string,
disabled: PropTypes.bool
};

Expand Down
20 changes: 20 additions & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,26 @@
}
}
},
"pages_tab": {
"alert_info": "To add a Sponsor Specific Page for this show's sponsor, click Add Page button. Note: this Page will be visible only to this sponsor for this show. The General Pages can only be managed on the Show's Pages section.",
"hide_archived": "Hide archived Pages",
"using_template": "Using Template",
"new_page": "New Page",
"pages": "pages",
"managed_pages": "Managed Pages",
"sponsor_customized_pages": "Customized Sponsor Pages",
"code": "Code",
"name": "Name",
"add_ons": "Add-ons",
"info_mod": "Info Mod",
"upload_mod": "Upload Mod",
"download_mod": "Download Mod",
"archive": "Archive",
"unarchive": "Unarchive",
"no_add_ons": "No Add-ons Available",
"add_page_using_template": "Add Page Template",
"add_selected_page_template": "Add Selected Page Template"
},
"cart_tab": {
"new_form": "New Form",
"forms": "forms",
Expand Down
8 changes: 8 additions & 0 deletions src/pages/sponsors/edit-sponsor-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import SponsorUsersListPerSponsorPage from "./sponsor-users-list-per-sponsor";
import SponsorFormsTab from "./sponsor-forms-tab";
import SponsorBadgeScans from "./sponsor-badge-scans";
import SponsorCartTab from "./sponsor-cart-tab";
import SponsorPagesTab from "./sponsor-pages-tab";
import SponsorFormsManageItems from "./sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items";
import { SPONSOR_TABS } from "../../utils/constants";

Expand Down Expand Up @@ -235,6 +236,13 @@ const EditSponsorPage = (props) => {
<CustomTabPanel value={selectedTab} index={1}>
<SponsorUsersListPerSponsorPage sponsor={entity} />
</CustomTabPanel>
<CustomTabPanel value={selectedTab} index={2}>
<SponsorPagesTab
sponsor={entity}
summitId={currentSummit.id}
history={history}
/>
</CustomTabPanel>
<CustomTabPanel value={selectedTab} index={4}>
{sponsorFormItemRoute ? (
<SponsorFormsManageItems match={match} />
Expand Down
Loading