Skip to content
Draft
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
39 changes: 37 additions & 2 deletions src/actions/sponsor-pages-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
createAction,
getRequest,
postRequest,
deleteRequest,
startLoading,
stopLoading,
authErrorHandler,
Expand All @@ -23,12 +24,17 @@ import {
import T from "i18n-react/dist/i18n-react";
import { getAccessTokenSafely } from "../utils/methods";
import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions";
import { DEFAULT_CURRENT_PAGE, DEFAULT_ORDER_DIR, DEFAULT_PER_PAGE } from "../utils/constants";
import {
DEFAULT_CURRENT_PAGE,
DEFAULT_ORDER_DIR,
DEFAULT_PER_PAGE
} from "../utils/constants";

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_DELETED = "SPONSOR_MANAGED_PAGE_DELETED";

export const REQUEST_SPONSOR_CUSTOMIZED_PAGES =
"REQUEST_SPONSOR_CUSTOMIZED_PAGES";
Expand Down Expand Up @@ -107,7 +113,7 @@ export const getSponsorManagedPages =

const params = {
page,
fields: "id,code,name,kind,modules_count,allowed_add_ons",
fields: "id,code,name,kind,modules_count,allowed_add_ons,assigned_type",
per_page: perPage,
access_token: accessToken
};
Expand Down Expand Up @@ -135,6 +141,35 @@ export const getSponsorManagedPages =
});
};

export const deleteSponsorManagedPage =
(pageId) => async (dispatch, getState) => {
const { currentSummitState } = getState();
const accessToken = await getAccessTokenSafely();
const { currentSummit } = currentSummitState;
const params = { access_token: accessToken };

dispatch(startLoading());

return deleteRequest(
null,
createAction(SPONSOR_MANAGED_PAGE_DELETED)({ pageId }),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/managed-pages/${pageId}`,
null,
snackbarErrorHandler
)(params)(dispatch)
.then(() => {
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("show_pages.page_delete_success")
})
);
})
.finally(() => {
dispatch(stopLoading());
});
};

/* ************************************************************************ */
/* CUSTOMIZED PAGES */
/* ************************************************************************ */
Expand Down
15 changes: 9 additions & 6 deletions src/components/mui/table/mui-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const MuiTable = ({
onEdit,
onArchive,
onDelete,
canDelete = () => true,
deleteDialogTitle = null,
deleteDialogBody = null
}) => {
Expand Down Expand Up @@ -244,12 +245,14 @@ const MuiTable = ({
: {})
}}
>
<IconButton
size="large"
onClick={() => handleDelete(row)}
>
<DeleteIcon fontSize="large" />
</IconButton>
{canDelete(row) && (
<IconButton
size="large"
onClick={() => handleDelete(row)}
>
<DeleteIcon fontSize="large" />
</IconButton>
)}
</TableCell>
)}
</TableRow>
Expand Down
28 changes: 24 additions & 4 deletions src/pages/sponsors/sponsor-pages-tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,25 @@ import {
import AddIcon from "@mui/icons-material/Add";
import {
getSponsorManagedPages,
getSponsorCustomizedPages
getSponsorCustomizedPages,
deleteSponsorManagedPage
} 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 {
DEFAULT_CURRENT_PAGE,
SPONSOR_MANAGED_PAGE_ASSIGNMENT
} from "../../../utils/constants";

const SponsorPagesTab = ({
term,
hideArchived,
managedPages,
customizedPages,
getSponsorManagedPages,
getSponsorCustomizedPages
getSponsorCustomizedPages,
deleteSponsorManagedPage
}) => {
useEffect(() => {
getSponsorManagedPages();
Expand Down Expand Up @@ -151,6 +156,17 @@ const SponsorPagesTab = ({
};

const handleManagedDelete = (itemId) => {
deleteSponsorManagedPage(itemId).then(() => {
const { perPage, order, orderDir } = managedPages;
getSponsorManagedPages(
term,
DEFAULT_CURRENT_PAGE,
perPage,
order,
orderDir,
hideArchived
);
});
console.log("DELETE MANAGED ", itemId);
};

Expand Down Expand Up @@ -333,6 +349,9 @@ const SponsorPagesTab = ({
onSort={handleManagedSort}
onEdit={handleManagedEdit}
onDelete={handleManagedDelete}
canDelete={(row) =>
row.assigned_type === SPONSOR_MANAGED_PAGE_ASSIGNMENT.EXPLICIT
}
onArchive={handleArchiveManagedPage}
/>
</div>
Expand All @@ -346,5 +365,6 @@ const mapStateToProps = ({ sponsorPagePagesListState }) => ({

export default connect(mapStateToProps, {
getSponsorManagedPages,
getSponsorCustomizedPages
getSponsorCustomizedPages,
deleteSponsorManagedPage
})(SponsorPagesTab);
5 changes: 5 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,8 @@ export const SPONSOR_USER_ASSIGNMENT_TYPE = {
EXISTING: "existing",
NEW: "new"
};

export const SPONSOR_MANAGED_PAGE_ASSIGNMENT = {
EXPLICIT: "Explicit",
IMPLICIT: "Implicit"
};