Skip to content

Commit

Permalink
fix transfer repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael18811380328 committed Dec 13, 2024
1 parent 3a11ace commit 3455c5b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
28 changes: 12 additions & 16 deletions frontend/src/components/dialog/transfer-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import '../../css/transfer-dialog.css';
const propTypes = {
itemName: PropTypes.string.isRequired,
toggleDialog: PropTypes.func.isRequired,
submit: PropTypes.func.isRequired,
onTransferRepo: PropTypes.func.isRequired,
canTransferToDept: PropTypes.bool,
isOrgAdmin: PropTypes.bool,
isSysAdmin: PropTypes.bool,
isDepAdminTransfer: PropTypes.bool,

};

const TRANS_USER = 'transUser';
Expand All @@ -47,17 +46,9 @@ class TransferDialog extends React.Component {
};

submit = () => {
const { activeTab, reshare } = this.state;
if (activeTab === TRANS_DEPART) {
let department = this.state.selectedOption;
this.props.submit(department, reshare);
} else if (activeTab === TRANS_USER) {
let selectedOption = this.state.selectedOption;
if (selectedOption && selectedOption[0]) {
let user = selectedOption[0];
this.props.submit(user, reshare);
}
}
const { activeTab, reshare, selectedOption } = this.state;
const email = activeTab === TRANS_DEPART ? selectedOption.email : selectedOption[0].email;
this.props.onTransferRepo(email, reshare);
};

componentDidMount() {
Expand Down Expand Up @@ -88,13 +79,13 @@ class TransferDialog extends React.Component {
}

updateOptions = (departmentsRes) => {
departmentsRes.data.forEach(item => {
this.options = departmentsRes.data.map(item => {
let option = {
value: item.name,
email: item.email,
label: item.name,
};
this.options.push(option);
return option;
});
};

Expand Down Expand Up @@ -211,9 +202,14 @@ class TransferDialog extends React.Component {
};

render() {
const { selectedOption } = this.state;
const { itemName: repoName } = this.props;
let title = gettext('Transfer Library {library_name}');
title = title.replace('{library_name}', '<span class="op-target text-truncate mx-1">' + Utils.HTMLescape(repoName) + '</span>');
let buttonDisabled = false;
if (selectedOption === null || (Array.isArray(selectedOption) && selectedOption.length === 0)) {
buttonDisabled = true;
}
return (
<Modal isOpen={true} style={{ maxWidth: '720px' }} toggle={this.props.toggleDialog} className="transfer-dialog">
<ModalHeader toggle={this.props.toggleDialog}>
Expand All @@ -224,7 +220,7 @@ class TransferDialog extends React.Component {
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggleDialog}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
<Button color="primary" onClick={this.submit} disabled={buttonDisabled}>{gettext('Submit')}</Button>
</ModalFooter>
</Modal>
);
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/my-libs/mylib-repo-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ class MylibRepoListItem extends React.Component {
this.setState({ isRenaming: !this.state.isRenaming });
};

onTransferRepo = (user, reshare) => {
onTransferRepo = (email, reshare) => {
let repoID = this.props.repo.repo_id;
userAPI.transferRepo(repoID, user.email, reshare).then(res => {
userAPI.transferRepo(repoID, email, reshare).then(res => {
this.props.onTransferRepo(repoID);
let message = gettext('Successfully transferred the library.');
toaster.success(message);
Expand Down Expand Up @@ -487,7 +487,7 @@ class MylibRepoListItem extends React.Component {
<ModalPortal>
<TransferDialog
itemName={repo.repo_name}
submit={this.onTransferRepo}
onTransferRepo={this.onTransferRepo}
toggleDialog={this.onTransferToggle}
/>
</ModalPortal>
Expand Down

0 comments on commit 3455c5b

Please sign in to comment.