Skip to content

Commit

Permalink
UIIN-2704: Disable the Share button after clicking on it once (#2364)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6854a23)
  • Loading branch information
OleksandrHladchenko1 committed Dec 6, 2023
1 parent 6a01323 commit e25b55c
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/ViewInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class ViewInstance extends React.Component {
isImportRecordModalOpened: false,
isCopyrightModalOpened: false,
isShareLocalInstanceModalOpen: false,
isShareButtonDisabled: false,
isUnlinkAuthoritiesModalOpen: false,
linkedAuthoritiesLength: 0,
isNewOrderModalOpen: false,
Expand Down Expand Up @@ -499,6 +500,7 @@ class ViewInstance extends React.Component {
isUnlinkAuthoritiesModalOpen: false,
isShareLocalInstanceModalOpen: false,
isInstanceSharing: true,
isShareButtonDisabled: false,
});

await this.waitForInstanceSharingComplete({ sourceTenantId, instanceIdentifier });
Expand All @@ -516,12 +518,15 @@ class ViewInstance extends React.Component {
isUnlinkAuthoritiesModalOpen: false,
isShareLocalInstanceModalOpen: false,
isInstanceSharing: false,
isShareButtonDisabled: false,
});
this.showUnsuccessfulShareInstanceCallout(instanceTitle);
});
}

checkIfHasLinkedAuthorities = () => {
this.setState({ isShareButtonDisabled: true });

const { selectedInstance } = this.props;
const authorityIds = getLinkedAuthorityIds(selectedInstance);

Expand All @@ -547,7 +552,10 @@ class ViewInstance extends React.Component {
this.handleShareLocalInstance(selectedInstance);
}
}).catch(() => {
this.setState({ isShareLocalInstanceModalOpen: false });
this.setState({
isShareLocalInstanceModalOpen: false,
isShareButtonDisabled: false,
});

this.calloutRef.current.sendCallout({
type: 'error',
Expand All @@ -556,6 +564,13 @@ class ViewInstance extends React.Component {
});
}

handleCloseUnlinkModal = () => {
this.setState({
isUnlinkAuthoritiesModalOpen: false,
isShareButtonDisabled: false,
});
}

toggleCopyrightModal = () => {
this.setState(prevState => ({ isCopyrightModalOpened: !prevState.isCopyrightModalOpened }));
};
Expand Down Expand Up @@ -960,7 +975,10 @@ class ViewInstance extends React.Component {
updateLocation,
canUseSingleRecordImport,
} = this.props;
const { linkedAuthoritiesLength } = this.state;
const {
linkedAuthoritiesLength,
isShareButtonDisabled,
} = this.state;

const ci = makeConnectedInstance(this.props, stripes.logger);
const instance = ci.instance();
Expand Down Expand Up @@ -1044,14 +1062,15 @@ class ViewInstance extends React.Component {
confirmLabel={<FormattedMessage id="ui-inventory.shareLocalInstance.modal.confirmButton" />}
onCancel={() => this.setState({ isShareLocalInstanceModalOpen: false })}
onConfirm={this.checkIfHasLinkedAuthorities}
isConfirmButtonDisabled={isShareButtonDisabled}
/>

<ConfirmationModal
open={this.state.isUnlinkAuthoritiesModalOpen}
heading={<FormattedMessage id="ui-inventory.unlinkLocalMarcAuthorities.modal.header" />}
message={<FormattedMessage id="ui-inventory.unlinkLocalMarcAuthorities.modal.message" values={{ linkedAuthoritiesLength }} />}
confirmLabel={<FormattedMessage id="ui-inventory.unlinkLocalMarcAuthorities.modal.proceed" />}
onCancel={() => this.setState({ isUnlinkAuthoritiesModalOpen: false })}
onCancel={this.handleCloseUnlinkModal}
onConfirm={() => this.handleShareLocalInstance(instance)}
/>

Expand Down

0 comments on commit e25b55c

Please sign in to comment.