2019-10-19 16:38:07 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import RepositoryRoleForm from './RepositoryRoleForm';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { translate } from 'react-i18next';
|
|
|
|
|
import { ErrorNotification, Subtitle, Title } from '@scm-manager/ui-components';
|
2019-05-15 14:48:12 +02:00
|
|
|
import {
|
|
|
|
|
createRole,
|
2019-05-16 12:17:18 +02:00
|
|
|
getCreateRoleFailure,
|
2019-05-15 14:48:12 +02:00
|
|
|
getFetchVerbsFailure,
|
2019-10-19 16:38:07 +02:00
|
|
|
isFetchVerbsPending,
|
|
|
|
|
} from '../modules/roles';
|
|
|
|
|
import { RepositoryRole } from '@scm-manager/ui-types';
|
2019-05-15 14:48:12 +02:00
|
|
|
import {
|
|
|
|
|
getRepositoryRolesLink,
|
2019-10-19 16:38:07 +02:00
|
|
|
getRepositoryVerbsLink,
|
|
|
|
|
} from '../../../modules/indexResource';
|
|
|
|
|
import { History } from 'history';
|
2019-05-15 14:48:12 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
repositoryRolesLink: string;
|
|
|
|
|
error?: Error;
|
|
|
|
|
history: History;
|
2019-05-15 14:48:12 +02:00
|
|
|
|
|
|
|
|
//dispatch function
|
2019-10-19 16:38:07 +02:00
|
|
|
addRole: (link: string, role: RepositoryRole, callback?: () => void) => void;
|
2019-05-16 10:10:10 +02:00
|
|
|
|
|
|
|
|
// context objects
|
2019-10-19 16:38:07 +02:00
|
|
|
t: (p: string) => string;
|
2019-05-15 14:48:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CreateRepositoryRole extends React.Component<Props> {
|
2019-05-16 13:36:11 +02:00
|
|
|
repositoryRoleCreated = (role: RepositoryRole) => {
|
2019-05-15 14:48:12 +02:00
|
|
|
const { history } = this.props;
|
2019-10-19 16:38:07 +02:00
|
|
|
history.push('/admin/role/' + role.name + '/info');
|
2019-05-15 14:48:12 +02:00
|
|
|
};
|
|
|
|
|
|
2019-05-16 13:36:11 +02:00
|
|
|
createRepositoryRole = (role: RepositoryRole) => {
|
2019-05-15 14:48:12 +02:00
|
|
|
this.props.addRole(this.props.repositoryRolesLink, role, () =>
|
2019-10-19 16:38:07 +02:00
|
|
|
this.repositoryRoleCreated(role),
|
2019-05-15 14:48:12 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-05-16 12:17:18 +02:00
|
|
|
const { t, error } = this.props;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return <ErrorNotification error={error} />;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 14:48:12 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
2019-10-19 16:38:07 +02:00
|
|
|
<Title title={t('repositoryRole.title')} />
|
|
|
|
|
<Subtitle subtitle={t('repositoryRole.createSubtitle')} />
|
2019-05-15 14:48:12 +02:00
|
|
|
<RepositoryRoleForm
|
|
|
|
|
submitForm={role => this.createRepositoryRole(role)}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
const loading = isFetchVerbsPending(state);
|
2019-05-16 12:17:18 +02:00
|
|
|
const error = getFetchVerbsFailure(state) || getCreateRoleFailure(state);
|
2019-05-15 14:48:12 +02:00
|
|
|
const verbsLink = getRepositoryVerbsLink(state);
|
|
|
|
|
const repositoryRolesLink = getRepositoryRolesLink(state);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
loading,
|
|
|
|
|
error,
|
|
|
|
|
verbsLink,
|
2019-10-19 16:38:07 +02:00
|
|
|
repositoryRolesLink,
|
2019-05-15 14:48:12 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
2019-05-16 13:36:11 +02:00
|
|
|
addRole: (link: string, role: RepositoryRole, callback?: () => void) => {
|
2019-05-15 16:57:28 +02:00
|
|
|
dispatch(createRole(link, role, callback));
|
2019-10-19 16:38:07 +02:00
|
|
|
},
|
2019-05-15 14:48:12 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
2019-10-19 16:38:07 +02:00
|
|
|
mapDispatchToProps,
|
|
|
|
|
)(translate('admin')(CreateRepositoryRole));
|