forked from openedx/frontend-app-account
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented notification preference UI for cadence (openedx#1033)
* feat: implented notification preference UI for cadence * refactor: refactored code * refactor: refactored code * refactor: clean code after adding email cadence * refactor: refactored and restructured notificationPreferences page * refactor: refactored and implemented mobile view * fix: fixed disabled for email cadence * refactor: resolved spaces and changed font size class * refactor: resolved conflicts --------- Co-authored-by: Awais Ansari <[email protected]>
- Loading branch information
1 parent
fc329fe
commit e314de2
Showing
12 changed files
with
361 additions
and
156 deletions.
There are no files selected for viewing
This file contains 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 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 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,70 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { | ||
Dropdown, ModalPopup, Button, useToggle, | ||
} from '@openedx/paragon'; | ||
import { ExpandLess, ExpandMore } from '@openedx/paragon/icons'; | ||
import messages from './messages'; | ||
import { EMAIL_CADENCE } from './data/constants'; | ||
|
||
const EmailCadences = ({ | ||
email, onToggle, emailCadence, notificationType, | ||
}) => { | ||
const intl = useIntl(); | ||
const [isOpen, open, close] = useToggle(false); | ||
const [target, setTarget] = useState(null); | ||
|
||
return ( | ||
<> | ||
<Button | ||
ref={setTarget} | ||
variant="outline-primary" | ||
onClick={open} | ||
disabled={!email} | ||
size="sm" | ||
iconAfter={isOpen ? ExpandLess : ExpandMore} | ||
className="border-light-300 text-primary-500 justify-content-between ml-3.5 cadence-button" | ||
> | ||
{intl.formatMessage(messages.emailCadence, { text: emailCadence })} | ||
</Button> | ||
<ModalPopup | ||
onClose={close} | ||
positionRef={target} | ||
isOpen={isOpen} | ||
> | ||
<div | ||
className="bg-white shadow d-flex flex-column margin-left-2" | ||
data-testid="email-cadence-dropdown" | ||
> | ||
{Object.values(EMAIL_CADENCE).map((cadence) => ( | ||
<Dropdown.Item | ||
key={cadence} | ||
name="email_cadence" | ||
className="d-flex justify-content-start py-1.5" | ||
as={Button} | ||
variant="primary" | ||
size="inline" | ||
autoFocus={cadence === emailCadence} | ||
onClick={(event) => { | ||
onToggle(event, notificationType); | ||
close(); | ||
}} | ||
> | ||
{intl.formatMessage(messages.emailCadence, { text: cadence })} | ||
</Dropdown.Item> | ||
))} | ||
</div> | ||
</ModalPopup> | ||
</> | ||
); | ||
}; | ||
|
||
EmailCadences.propTypes = { | ||
email: PropTypes.bool.isRequired, | ||
onToggle: PropTypes.func.isRequired, | ||
emailCadence: PropTypes.oneOf(Object.values(EMAIL_CADENCE)).isRequired, | ||
notificationType: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default React.memo(EmailCadences); |
This file contains 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.