Skip to content

Commit

Permalink
UIREQ-840: Cannot save item request from On Order item, because need …
Browse files Browse the repository at this point in the history
…a barcode (#978)
  • Loading branch information
artem-blazhko committed Nov 21, 2022
1 parent 8dc54a5 commit 9603db9
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/RequestForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class RequestForm extends React.Component {
shouldValidateInstanceId: false,
isInstanceIdBlur: false,
validatedInstanceId: null,
isItemIdRequest: Boolean(this.props.query?.itemId),
};

this.connectedCancelRequestDialog = props.stripes.connect(CancelRequestDialog);
Expand Down Expand Up @@ -669,13 +670,16 @@ class RequestForm extends React.Component {
});
}

findItem(key, value, isValidation = false) {
findItem(key, value, isValidation = false, isBarcodeRequired = false) {
const {
findResource,
form,
onSetSelectedItem,
onShowErrorModal,
} = this.props;
const {
isItemIdRequest,
} = this.state;

this.setState({
isItemOrInstanceLoading: true,
Expand All @@ -696,6 +700,16 @@ class RequestForm extends React.Component {

return findResource(RESOURCE_TYPES.ITEM, value, key)
.then((result) => {
if (key === 'id' && !isBarcodeRequired) {
this.setState({
isItemIdRequest: true,
});
} else if (key === 'barcode' && isItemIdRequest) {
this.setState({
isItemIdRequest: false,
});
}

if (!result || result.totalRecords === 0) {
this.setState({
isItemOrInstanceLoading: false,
Expand Down Expand Up @@ -945,8 +959,13 @@ class RequestForm extends React.Component {
} = this.props;
const {
shouldValidateItemBarcode,
isItemIdRequest,
} = this.state;

if (isItemIdRequest && !barcode) {
return undefined;
}

if (!barcode || (!barcode && !selectedItem?.id)) {
return <FormattedMessage id="ui-requests.errors.selectItemRequired" />;
}
Expand Down Expand Up @@ -1217,21 +1236,30 @@ class RequestForm extends React.Component {
this.setState({
isItemsDialogOpen: false,
requestTypeOptions: [],
});
isItemIdRequest: false,
}, this.triggerItemBarcodeValidation);
}

handleInstanceItemClick = (event, item) => {
const {
onSetSelectedInstance,
} = this.props;
let isBarcodeRequired = false;

onSetSelectedInstance(undefined);
this.setState({
isItemsDialogOpen: false,
requestTypeOptions: [],
});

this.findItem('id', item.id);
if (item?.barcode) {
isBarcodeRequired = true;
this.setState({
isItemIdRequest: false,
});
}

this.findItem('id', item.id, false, isBarcodeRequired);
}

handleCloseProxy = () => {
Expand Down

0 comments on commit 9603db9

Please sign in to comment.