Skip to content

Commit 68dcf3c

Browse files
committed
feat: WIP sponsor managed pages delete only for explicits ones
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
1 parent f0fbe8c commit 68dcf3c

File tree

4 files changed

+75
-12
lines changed

4 files changed

+75
-12
lines changed

src/actions/sponsor-pages-actions.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
createAction,
1616
getRequest,
1717
postRequest,
18+
deleteRequest,
1819
startLoading,
1920
stopLoading,
2021
authErrorHandler,
@@ -23,12 +24,17 @@ import {
2324
import T from "i18n-react/dist/i18n-react";
2425
import { getAccessTokenSafely } from "../utils/methods";
2526
import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions";
26-
import { DEFAULT_CURRENT_PAGE, DEFAULT_ORDER_DIR, DEFAULT_PER_PAGE } from "../utils/constants";
27+
import {
28+
DEFAULT_CURRENT_PAGE,
29+
DEFAULT_ORDER_DIR,
30+
DEFAULT_PER_PAGE
31+
} from "../utils/constants";
2732

2833
export const GLOBAL_PAGE_CLONED = "GLOBAL_PAGE_CLONED";
2934

3035
export const REQUEST_SPONSOR_MANAGED_PAGES = "REQUEST_SPONSOR_MANAGED_PAGES";
3136
export const RECEIVE_SPONSOR_MANAGED_PAGES = "RECEIVE_SPONSOR_MANAGED_PAGES";
37+
export const SPONSOR_MANAGED_PAGE_DELETED = "SPONSOR_MANAGED_PAGE_DELETED";
3238

3339
export const REQUEST_SPONSOR_CUSTOMIZED_PAGES =
3440
"REQUEST_SPONSOR_CUSTOMIZED_PAGES";
@@ -107,7 +113,7 @@ export const getSponsorManagedPages =
107113

108114
const params = {
109115
page,
110-
fields: "id,code,name,kind,modules_count,allowed_add_ons",
116+
fields: "id,code,name,kind,modules_count,allowed_add_ons,assigned_type",
111117
per_page: perPage,
112118
access_token: accessToken
113119
};
@@ -135,6 +141,35 @@ export const getSponsorManagedPages =
135141
});
136142
};
137143

144+
export const deleteSponsorManagedPage =
145+
(pageId) => async (dispatch, getState) => {
146+
const { currentSummitState } = getState();
147+
const accessToken = await getAccessTokenSafely();
148+
const { currentSummit } = currentSummitState;
149+
const params = { access_token: accessToken };
150+
151+
dispatch(startLoading());
152+
153+
return deleteRequest(
154+
null,
155+
createAction(SPONSOR_MANAGED_PAGE_DELETED)({ pageId }),
156+
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/managed-pages/${pageId}`,
157+
null,
158+
snackbarErrorHandler
159+
)(params)(dispatch)
160+
.then(() => {
161+
dispatch(
162+
snackbarSuccessHandler({
163+
title: T.translate("general.success"),
164+
html: T.translate("show_pages.page_delete_success")
165+
})
166+
);
167+
})
168+
.finally(() => {
169+
dispatch(stopLoading());
170+
});
171+
};
172+
138173
/* ************************************************************************ */
139174
/* CUSTOMIZED PAGES */
140175
/* ************************************************************************ */

src/components/mui/table/mui-table.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const MuiTable = ({
4343
onEdit,
4444
onArchive,
4545
onDelete,
46+
canDelete = () => true,
4647
deleteDialogTitle = null,
4748
deleteDialogBody = null
4849
}) => {
@@ -244,12 +245,14 @@ const MuiTable = ({
244245
: {})
245246
}}
246247
>
247-
<IconButton
248-
size="large"
249-
onClick={() => handleDelete(row)}
250-
>
251-
<DeleteIcon fontSize="large" />
252-
</IconButton>
248+
{canDelete(row) && (
249+
<IconButton
250+
size="large"
251+
onClick={() => handleDelete(row)}
252+
>
253+
<DeleteIcon fontSize="large" />
254+
</IconButton>
255+
)}
253256
</TableCell>
254257
)}
255258
</TableRow>

src/pages/sponsors/sponsor-pages-tab/index.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,25 @@ import {
2525
import AddIcon from "@mui/icons-material/Add";
2626
import {
2727
getSponsorManagedPages,
28-
getSponsorCustomizedPages
28+
getSponsorCustomizedPages,
29+
deleteSponsorManagedPage
2930
} from "../../../actions/sponsor-pages-actions";
3031
import CustomAlert from "../../../components/mui/custom-alert";
3132
import SearchInput from "../../../components/mui/search-input";
3233
import MuiTable from "../../../components/mui/table/mui-table";
33-
import { DEFAULT_CURRENT_PAGE } from "../../../utils/constants";
34+
import {
35+
DEFAULT_CURRENT_PAGE,
36+
SPONSOR_MANAGED_PAGE_ASSIGNMENT
37+
} from "../../../utils/constants";
3438

3539
const SponsorPagesTab = ({
3640
term,
3741
hideArchived,
3842
managedPages,
3943
customizedPages,
4044
getSponsorManagedPages,
41-
getSponsorCustomizedPages
45+
getSponsorCustomizedPages,
46+
deleteSponsorManagedPage
4247
}) => {
4348
useEffect(() => {
4449
getSponsorManagedPages();
@@ -151,6 +156,17 @@ const SponsorPagesTab = ({
151156
};
152157

153158
const handleManagedDelete = (itemId) => {
159+
deleteSponsorManagedPage(itemId).then(() => {
160+
const { perPage, order, orderDir } = managedPages;
161+
getSponsorManagedPages(
162+
term,
163+
DEFAULT_CURRENT_PAGE,
164+
perPage,
165+
order,
166+
orderDir,
167+
hideArchived
168+
);
169+
});
154170
console.log("DELETE MANAGED ", itemId);
155171
};
156172

@@ -333,6 +349,9 @@ const SponsorPagesTab = ({
333349
onSort={handleManagedSort}
334350
onEdit={handleManagedEdit}
335351
onDelete={handleManagedDelete}
352+
canDelete={(row) =>
353+
row.assigned_type === SPONSOR_MANAGED_PAGE_ASSIGNMENT.EXPLICIT
354+
}
336355
onArchive={handleArchiveManagedPage}
337356
/>
338357
</div>
@@ -346,5 +365,6 @@ const mapStateToProps = ({ sponsorPagePagesListState }) => ({
346365

347366
export default connect(mapStateToProps, {
348367
getSponsorManagedPages,
349-
getSponsorCustomizedPages
368+
getSponsorCustomizedPages,
369+
deleteSponsorManagedPage
350370
})(SponsorPagesTab);

src/utils/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,8 @@ export const SPONSOR_USER_ASSIGNMENT_TYPE = {
264264
EXISTING: "existing",
265265
NEW: "new"
266266
};
267+
268+
export const SPONSOR_MANAGED_PAGE_ASSIGNMENT = {
269+
EXPLICIT: "Explicit",
270+
IMPLICIT: "Implicit"
271+
};

0 commit comments

Comments
 (0)