2020-02-04 04:41:12 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Modal from '/imports/ui/components/modal/simple/component';
|
|
|
|
import Button from '/imports/ui/components/button/component';
|
|
|
|
import { styles } from './styles';
|
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
closeModal: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
guestPolicy: PropTypes.string.isRequired,
|
|
|
|
changeGuestPolicy: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
class GuestPolicyComponent extends PureComponent {
|
2021-09-02 03:46:14 +08:00
|
|
|
componentWillUnmount() {
|
|
|
|
const { closeModal } = this.props;
|
|
|
|
|
|
|
|
closeModal();
|
|
|
|
}
|
|
|
|
|
2020-02-04 04:41:12 +08:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
closeModal,
|
|
|
|
intl,
|
|
|
|
guestPolicy,
|
|
|
|
changeGuestPolicy,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
overlayClassName={styles.overlay}
|
|
|
|
className={styles.modal}
|
|
|
|
onRequestClose={closeModal}
|
|
|
|
hideBorder
|
|
|
|
contentLabel={intl.formatMessage(intlMessages.ariaModalTitle)}
|
|
|
|
>
|
2021-04-15 00:16:41 +08:00
|
|
|
<div
|
|
|
|
className={styles.container}
|
|
|
|
data-test="guestPolicySettingsModal"
|
|
|
|
>
|
2020-02-04 04:41:12 +08:00
|
|
|
<div className={styles.header}>
|
|
|
|
<h2 className={styles.title}>
|
|
|
|
{intl.formatMessage(intlMessages.guestPolicyTitle)}
|
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
<div className={styles.description}>
|
|
|
|
{intl.formatMessage(intlMessages.guestPolicyDescription)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={styles.content}>
|
|
|
|
<Button
|
|
|
|
color="primary"
|
2021-09-03 11:50:54 +08:00
|
|
|
className={[styles.button, guestPolicy === ASK_MODERATOR && styles.active].join(' ')}
|
2020-02-04 04:41:12 +08:00
|
|
|
disabled={guestPolicy === ASK_MODERATOR}
|
|
|
|
label={intl.formatMessage(intlMessages.askModerator)}
|
2021-04-15 00:16:41 +08:00
|
|
|
data-test="askModerator"
|
2020-02-04 04:41:12 +08:00
|
|
|
onClick={() => {
|
|
|
|
changeGuestPolicy(ASK_MODERATOR);
|
|
|
|
closeModal();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
color="primary"
|
2021-09-03 11:50:54 +08:00
|
|
|
className={[styles.button, guestPolicy === ALWAYS_ACCEPT && styles.active].join(' ')}
|
2020-02-04 04:41:12 +08:00
|
|
|
disabled={guestPolicy === ALWAYS_ACCEPT}
|
|
|
|
label={intl.formatMessage(intlMessages.alwaysAccept)}
|
2021-04-15 00:16:41 +08:00
|
|
|
data-test="alwaysAccept"
|
2020-02-04 04:41:12 +08:00
|
|
|
onClick={() => {
|
|
|
|
changeGuestPolicy(ALWAYS_ACCEPT);
|
|
|
|
closeModal();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
color="primary"
|
2021-09-03 11:50:54 +08:00
|
|
|
className={[styles.button, guestPolicy === ALWAYS_DENY && styles.active].join(' ')}
|
2020-02-04 04:41:12 +08:00
|
|
|
disabled={guestPolicy === ALWAYS_DENY}
|
|
|
|
label={intl.formatMessage(intlMessages.alwaysDeny)}
|
2021-04-15 00:16:41 +08:00
|
|
|
data-test="alwaysDeny"
|
2020-02-04 04:41:12 +08:00
|
|
|
onClick={() => {
|
|
|
|
changeGuestPolicy(ALWAYS_DENY);
|
|
|
|
closeModal();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GuestPolicyComponent.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default injectIntl(GuestPolicyComponent);
|