-
Notifications
You must be signed in to change notification settings - Fork 6
Brevo Mailing list integration #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
micsucmed
wants to merge
27
commits into
indico:master
Choose a base branch
from
micsucmed:brevo-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f4574ee
Add a simple view for mailing list preferences
micsucmed e33c321
Update mailing lists statesafter subscribing and unsubscribing
micsucmed bea215c
Improve button alignment
micsucmed 4ebc5f1
Fix submitting bugs
micsucmed 8b88342
Disable buttons after submission
micsucmed 1cf991b
remove unnecessary import
micsucmed bb33c00
Subscribe or unsubscribe on toggle
micsucmed 50aa120
Sent requests to brevo for single lists
micsucmed 42ce5c8
Improve appearance of list name and toggle
micsucmed 878817c
Solve small bug when retriving lists of a non contact
micsucmed 8fb8b82
Handle errors not expected to fail
micsucmed 44683f6
Remove unused error modal
micsucmed 0041961
Remove unnecessary try catch block
micsucmed ee1370b
Raise IndicoError on failed API requests to Brevo
micsucmed a3fd292
Add user loggers
micsucmed dd6dd15
Change className to styleName
micsucmed e8b5046
Solve linting
micsucmed fcbedc8
Add brevo python to dependencies
micsucmed 4b7d377
Fix formating and remove empty return statements
micsucmed c44745d
Rearrange imports
micsucmed 297e8ca
Remove plugin component registration
micsucmed ed071cd
Rename list title
micsucmed e2d15f7
Fix format
micsucmed 07b57e4
Update brevo_python dependency version
micsucmed d1fd29c
Move get_all_lists to the appropriate RH
micsucmed a8240e5
Get list name from brevo
micsucmed 628ce65
Disable toggle from frantic clicking
micsucmed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // This file is part of the JACoW plugin. | ||
| // Copyright (C) 2021 - 2025 CERN | ||
| // | ||
| // The CERN Indico plugins are free software; you can redistribute | ||
| // them and/or modify them under the terms of the MIT License; see | ||
| // the LICENSE file for more details. | ||
|
|
||
| // import getMailingListsURL from 'indico-url:plugin_jacow.mailing_lists'; | ||
| import mailingListSubscribeURL from 'indico-url:plugin_jacow.mailing_lists_subscribe'; | ||
| import mailingListUnsubscribeURL from 'indico-url:plugin_jacow.mailing_lists_unsubscribe'; | ||
|
|
||
| import PropTypes from 'prop-types'; | ||
| import {useState} from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import {ListItem, ListContent, List, Checkbox} from 'semantic-ui-react'; | ||
|
|
||
| import {Translate} from 'indico/react/i18n'; | ||
| import {indicoAxios, handleAxiosError} from 'indico/utils/axios'; | ||
|
|
||
| import './MailingList.module.scss'; | ||
|
|
||
| export function MailingList({mailingLists}) { | ||
| const [lists, setLists] = useState(mailingLists.lists); | ||
| const [listsLoadingRequests, setListsLoadingRequests] = useState(new Set()); | ||
|
|
||
| const subscribeList = async list => { | ||
| await indicoAxios.post(mailingListSubscribeURL(), list); | ||
| }; | ||
|
|
||
| const unsubscribeList = async list => { | ||
| await indicoAxios.post(mailingListUnsubscribeURL(), list); | ||
| }; | ||
|
|
||
| const handleToggle = async (ev, {value}) => { | ||
| if (listsLoadingRequests.has(value)) return; | ||
|
|
||
| setListsLoadingRequests(prev => new Set(prev).add(value)); | ||
|
|
||
| const targetList = lists.find(list => list.id === value); | ||
| const newSubscriptionStatus = !targetList.subscribed; | ||
|
|
||
| setLists(prevLists => | ||
| prevLists.map(list => | ||
| list.id === value ? { ...list, subscribed: newSubscriptionStatus } : list | ||
| ) | ||
| ); | ||
|
|
||
| try { | ||
| if (newSubscriptionStatus) { | ||
| await subscribeList({list_id: value}); | ||
| } else { | ||
| await unsubscribeList({list_id: value}); | ||
| } | ||
| } catch (e) { | ||
| handleAxiosError(e); | ||
| setLists(prevLists => | ||
| prevLists.map(list => | ||
| list.id === value ? { ...list, subscribed: !newSubscriptionStatus } : list | ||
| ) | ||
| ); | ||
| } finally { | ||
| setListsLoadingRequests(prev => { | ||
| const newSet = new Set(prev); | ||
| newSet.delete(value); | ||
| return newSet; | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div style={{marginTop: '15px'}}> | ||
| {/* Subscribed Lists Section */} | ||
| <div className="i-box"> | ||
| <div className="i-box-header"> | ||
| <div className="i-box-title"> | ||
| <Translate>Mailing Lists</Translate> | ||
| </div> | ||
| </div> | ||
| <div className="i-box-content"> | ||
| <List divided relaxed size="big"> | ||
| {lists.map(list => ( | ||
| <ListItem styleName="mailing" key={list.id}> | ||
| <ListContent>{list.name}</ListContent> | ||
| <ListContent> | ||
| <Checkbox | ||
| toggle | ||
| value={list.id} | ||
| onChange={handleToggle} | ||
| disabled={listsLoadingRequests.has(list.id)} | ||
| checked={list.subscribed} | ||
| /> | ||
| </ListContent> | ||
| </ListItem> | ||
| ))} | ||
| </List> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| MailingList.propTypes = { | ||
| mailingLists: PropTypes.shape({ | ||
| lists: PropTypes.arrayOf( | ||
| PropTypes.shape({ | ||
| id: PropTypes.number.isRequired, | ||
| name: PropTypes.string.isRequired, | ||
| subscribed: PropTypes.bool.isRequired, | ||
| }) | ||
| ).isRequired, | ||
| }).isRequired, | ||
| }; | ||
|
|
||
| window.setupMailingList = (elem, subMailingLists) => { | ||
| subMailingLists = JSON.parse(subMailingLists); | ||
| ReactDOM.render(<MailingList mailingLists={subMailingLists} />, elem); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // This file is part of the JACoW plugin. | ||
| // Copyright (C) 2021 - 2025 CERN | ||
| // | ||
| // The CERN Indico plugins are free software; you can redistribute | ||
| // them and/or modify them under the terms of the MIT License; see | ||
| // the LICENSE file for more details. | ||
|
|
||
| :global(.ui.list .item).mailing { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| width: 100%; | ||
|
|
||
| &::after { | ||
| content: none; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| {% extends 'users/base.html' %} | ||
|
|
||
| {% block user_content %} | ||
| <div id="mailing-lists"></div> | ||
| <script> | ||
| setupMailingList(document.querySelector('#mailing-lists'), {{ mailing_lists | tojson }}); | ||
| </script> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.