Admin: add registration mode picker
This commit is contained in:
@@ -37,18 +37,18 @@ class AdminNav extends React.PureComponent {
|
||||
<IconWithCounter icon='gavel' count={reportsCount} fixedWidth />
|
||||
<FormattedMessage id='admin_nav.reports' defaultMessage='Reports' />
|
||||
</a>
|
||||
{(instance.get('approval_required') || approvalCount > 0) && (
|
||||
{((instance.get('registrations') && instance.get('approval_required')) || approvalCount > 0) && (
|
||||
<NavLink className='promo-panel-item' to='/admin/approval'>
|
||||
<IconWithCounter icon='user' count={approvalCount} fixedWidth />
|
||||
<FormattedMessage id='admin_nav.awaiting_approval' defaultMessage='Awaiting Approval' />
|
||||
</NavLink>
|
||||
)}
|
||||
{!instance.get('registrations') && (
|
||||
{/* <NavLink className='promo-panel-item' to='#'>
|
||||
{/* !instance.get('registrations') && (
|
||||
<NavLink className='promo-panel-item' to='#'>
|
||||
<Icon id='envelope' className='promo-panel-item__icon' fixedWidth />
|
||||
<FormattedMessage id='admin_nav.invites' defaultMessage='Invites' />
|
||||
</NavLink> */}
|
||||
)}
|
||||
</NavLink>
|
||||
) */}
|
||||
{/* <NavLink className='promo-panel-item' to='#'>
|
||||
<Icon id='group' className='promo-panel-item__icon' fixedWidth />
|
||||
<FormattedMessage id='admin_nav.registration' defaultMessage='Registration' />
|
||||
|
||||
@@ -8,37 +8,67 @@ import {
|
||||
RadioGroup,
|
||||
RadioItem,
|
||||
} from 'soapbox/features/forms';
|
||||
import { updateConfig } from 'soapbox/actions/admin';
|
||||
|
||||
const mapStateToProps = (state, props) => ({
|
||||
instance: state.get('instance'),
|
||||
mode: modeFromInstance(state.get('instance')),
|
||||
openReportCount: state.getIn(['admin', 'open_report_count']),
|
||||
});
|
||||
|
||||
const generateConfig = mode => {
|
||||
const configMap = {
|
||||
open: [{ tuple: [':registrations_open', true] }, { tuple: [':account_approval_required', false] }],
|
||||
approval: [{ tuple: [':registrations_open', true] }, { tuple: [':account_approval_required', true] }],
|
||||
closed: [{ tuple: [':registrations_open', false] }],
|
||||
};
|
||||
|
||||
return [{
|
||||
group: ':pleroma',
|
||||
key: ':instance',
|
||||
value: configMap[mode],
|
||||
}];
|
||||
};
|
||||
|
||||
const modeFromInstance = instance => {
|
||||
if (instance.get('approval_required') && instance.get('registrations')) return 'approval';
|
||||
return instance.get('registrations') ? 'open' : 'closed';
|
||||
};
|
||||
|
||||
export default @connect(mapStateToProps)
|
||||
class RegistrationModePicker extends ImmutablePureComponent {
|
||||
|
||||
onChange = e => {
|
||||
const { dispatch } = this.props;
|
||||
const config = generateConfig(e.target.value);
|
||||
dispatch(updateConfig(config));
|
||||
}
|
||||
|
||||
render() {
|
||||
const { mode } = this.props;
|
||||
|
||||
return (
|
||||
<SimpleForm>
|
||||
<FieldsGroup>
|
||||
<RadioGroup
|
||||
label={<FormattedMessage id='admin.dashboard.registration_mode_label' defaultMessage='Registrations' />}
|
||||
checked
|
||||
onChange={this.onChange}
|
||||
>
|
||||
<RadioItem
|
||||
label={<FormattedMessage id='admin.dashboard.registration_mode.open_label' defaultMessage='Open' />}
|
||||
hint={<FormattedMessage id='admin.dashboard.registration_mode.open_hint' defaultMessage='Anyone can join.' />}
|
||||
checked={mode === 'open'}
|
||||
value='open'
|
||||
/>
|
||||
<RadioItem
|
||||
label={<FormattedMessage id='admin.dashboard.registration_mode.approval_label' defaultMessage='Approval Required' />}
|
||||
hint={<FormattedMessage id='admin.dashboard.registration_mode.approval_hint' defaultMessage='Users can sign up, but their account only gets activated when an admin approves it.' />}
|
||||
checked={mode === 'approval'}
|
||||
value='approval'
|
||||
/>
|
||||
<RadioItem
|
||||
label={<FormattedMessage id='admin.dashboard.registration_mode.closed_label' defaultMessage='Closed' />}
|
||||
hint={<FormattedMessage id='admin.dashboard.registration_mode.closed_hint' defaultMessage='Nobody can sign up. You can still invite people.' />}
|
||||
checked={mode === 'closed'}
|
||||
value='closed'
|
||||
/>
|
||||
</RadioGroup>
|
||||
|
||||
Reference in New Issue
Block a user