2020-02-04 04:41:12 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-11-03 20:12:32 +08:00
|
|
|
import Styled from './styles';
|
2023-08-05 03:47:23 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2020-02-04 04:41:12 +08:00
|
|
|
|
|
|
|
const ASK_MODERATOR = 'ASK_MODERATOR';
|
|
|
|
const ALWAYS_ACCEPT = 'ALWAYS_ACCEPT';
|
|
|
|
const ALWAYS_DENY = 'ALWAYS_DENY';
|
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
ariaModalTitle: {
|
|
|
|
id: 'app.guest-policy.ariaTitle',
|
|
|
|
description: 'Guest policy aria title',
|
|
|
|
},
|
|
|
|
guestPolicyTitle: {
|
|
|
|
id: 'app.guest-policy.title',
|
|
|
|
description: 'Guest policy title',
|
|
|
|
},
|
|
|
|
guestPolicyDescription: {
|
|
|
|
id: 'app.guest-policy.description',
|
|
|
|
description: 'Guest policy description',
|
|
|
|
},
|
2021-09-03 20:44:38 +08:00
|
|
|
policyBtnDesc: {
|
|
|
|
id: 'app.guest-policy.policyBtnDesc',
|
|
|
|
description: 'aria description for guest policy button',
|
|
|
|
},
|
2020-02-04 04:41:12 +08:00
|
|
|
askModerator: {
|
|
|
|
id: 'app.guest-policy.button.askModerator',
|
|
|
|
description: 'Ask moderator button label',
|
|
|
|
},
|
|
|
|
alwaysAccept: {
|
|
|
|
id: 'app.guest-policy.button.alwaysAccept',
|
|
|
|
description: 'Always accept button label',
|
|
|
|
},
|
|
|
|
alwaysDeny: {
|
|
|
|
id: 'app.guest-policy.button.alwaysDeny',
|
|
|
|
description: 'Always deny button label',
|
|
|
|
},
|
2023-08-05 03:47:23 +08:00
|
|
|
feedbackMessage: {
|
|
|
|
id: 'app.guest-policy.feedbackMessage',
|
|
|
|
description: 'Feedback message for guest policy change',
|
|
|
|
},
|
2020-02-04 04:41:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
guestPolicy: PropTypes.string.isRequired,
|
|
|
|
changeGuestPolicy: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
class GuestPolicyComponent extends PureComponent {
|
2023-08-05 03:47:23 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.handleChangePolicy = this.handleChangePolicy.bind(this);
|
|
|
|
}
|
|
|
|
|
2021-09-02 03:46:14 +08:00
|
|
|
componentWillUnmount() {
|
2023-03-22 04:45:20 +08:00
|
|
|
const { setIsOpen } = this.props;
|
2021-09-02 03:46:14 +08:00
|
|
|
|
2023-03-22 04:45:20 +08:00
|
|
|
setIsOpen(false);
|
2021-09-02 03:46:14 +08:00
|
|
|
}
|
|
|
|
|
2023-08-05 03:47:23 +08:00
|
|
|
handleChangePolicy(policyRule, messageId) {
|
|
|
|
const { intl, changeGuestPolicy } = this.props;
|
|
|
|
|
|
|
|
changeGuestPolicy(policyRule);
|
|
|
|
|
|
|
|
notify(intl.formatMessage(intlMessages.feedbackMessage) + intl.formatMessage(messageId), 'success');
|
|
|
|
}
|
|
|
|
|
2020-02-04 04:41:12 +08:00
|
|
|
render() {
|
|
|
|
const {
|
2023-03-22 04:45:20 +08:00
|
|
|
setIsOpen,
|
2020-02-04 04:41:12 +08:00
|
|
|
intl,
|
|
|
|
guestPolicy,
|
2023-04-12 23:51:23 +08:00
|
|
|
isOpen,
|
|
|
|
onRequestClose,
|
|
|
|
priority,
|
2020-02-04 04:41:12 +08:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
2021-11-03 20:12:32 +08:00
|
|
|
<Styled.GuestPolicyModal
|
2023-03-22 04:45:20 +08:00
|
|
|
onRequestClose={() => setIsOpen(false)}
|
2020-02-04 04:41:12 +08:00
|
|
|
contentLabel={intl.formatMessage(intlMessages.ariaModalTitle)}
|
2022-11-11 02:09:21 +08:00
|
|
|
title={intl.formatMessage(intlMessages.guestPolicyTitle)}
|
2023-04-12 23:51:23 +08:00
|
|
|
{...{
|
|
|
|
isOpen,
|
|
|
|
onRequestClose,
|
|
|
|
priority,
|
|
|
|
}}
|
2020-02-04 04:41:12 +08:00
|
|
|
>
|
2021-11-03 20:12:32 +08:00
|
|
|
<Styled.Container
|
2021-04-15 00:16:41 +08:00
|
|
|
data-test="guestPolicySettingsModal"
|
|
|
|
>
|
2021-11-03 20:12:32 +08:00
|
|
|
<Styled.Description>
|
2020-02-04 04:41:12 +08:00
|
|
|
{intl.formatMessage(intlMessages.guestPolicyDescription)}
|
2021-11-03 20:12:32 +08:00
|
|
|
</Styled.Description>
|
2020-02-04 04:41:12 +08:00
|
|
|
|
2021-11-03 20:12:32 +08:00
|
|
|
<Styled.Content>
|
|
|
|
<Styled.GuestPolicyButton
|
2020-02-04 04:41:12 +08:00
|
|
|
color="primary"
|
|
|
|
disabled={guestPolicy === ASK_MODERATOR}
|
|
|
|
label={intl.formatMessage(intlMessages.askModerator)}
|
2021-09-03 20:44:38 +08:00
|
|
|
aria-describedby={guestPolicy === ASK_MODERATOR ? 'selected-btn-desc' : 'policy-btn-desc'}
|
|
|
|
aria-pressed={guestPolicy === ASK_MODERATOR}
|
2021-04-15 00:16:41 +08:00
|
|
|
data-test="askModerator"
|
2020-02-04 04:41:12 +08:00
|
|
|
onClick={() => {
|
2023-08-05 03:47:23 +08:00
|
|
|
this.handleChangePolicy(ASK_MODERATOR, intlMessages.askModerator);
|
2023-03-22 04:45:20 +08:00
|
|
|
setIsOpen(false);
|
2020-02-04 04:41:12 +08:00
|
|
|
}}
|
|
|
|
/>
|
2021-11-03 20:12:32 +08:00
|
|
|
<Styled.GuestPolicyButton
|
2020-02-04 04:41:12 +08:00
|
|
|
color="primary"
|
|
|
|
disabled={guestPolicy === ALWAYS_ACCEPT}
|
|
|
|
label={intl.formatMessage(intlMessages.alwaysAccept)}
|
2021-09-03 20:44:38 +08:00
|
|
|
aria-describedby={guestPolicy === ALWAYS_ACCEPT ? 'selected-btn-desc' : 'policy-btn-desc'}
|
|
|
|
aria-pressed={guestPolicy === ALWAYS_ACCEPT}
|
2021-04-15 00:16:41 +08:00
|
|
|
data-test="alwaysAccept"
|
2020-02-04 04:41:12 +08:00
|
|
|
onClick={() => {
|
2023-08-05 03:47:23 +08:00
|
|
|
this.handleChangePolicy(ALWAYS_ACCEPT, intlMessages.alwaysAccept);
|
2023-03-22 04:45:20 +08:00
|
|
|
setIsOpen(false);
|
2020-02-04 04:41:12 +08:00
|
|
|
}}
|
|
|
|
/>
|
2021-11-03 20:12:32 +08:00
|
|
|
<Styled.GuestPolicyButton
|
2020-02-04 04:41:12 +08:00
|
|
|
color="primary"
|
|
|
|
disabled={guestPolicy === ALWAYS_DENY}
|
|
|
|
label={intl.formatMessage(intlMessages.alwaysDeny)}
|
2021-09-03 20:44:38 +08:00
|
|
|
aria-describedby={guestPolicy === ALWAYS_DENY ? 'selected-btn-desc' : 'policy-btn-desc'}
|
|
|
|
aria-pressed={guestPolicy === ALWAYS_DENY}
|
2021-04-15 00:16:41 +08:00
|
|
|
data-test="alwaysDeny"
|
2020-02-04 04:41:12 +08:00
|
|
|
onClick={() => {
|
2023-08-05 03:47:23 +08:00
|
|
|
this.handleChangePolicy(ALWAYS_DENY, intlMessages.alwaysDeny);
|
2023-03-22 04:45:20 +08:00
|
|
|
setIsOpen(false);
|
2020-02-04 04:41:12 +08:00
|
|
|
}}
|
|
|
|
/>
|
2021-11-03 20:12:32 +08:00
|
|
|
</Styled.Content>
|
2021-09-03 20:44:38 +08:00
|
|
|
<div id="policy-btn-desc" aria-hidden className="sr-only">
|
|
|
|
{intl.formatMessage(intlMessages.policyBtnDesc)}
|
|
|
|
</div>
|
2021-11-03 20:12:32 +08:00
|
|
|
</Styled.Container>
|
|
|
|
</Styled.GuestPolicyModal>
|
2020-02-04 04:41:12 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GuestPolicyComponent.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default injectIntl(GuestPolicyComponent);
|