Skip to content

Commit

Permalink
Merge 7d63dc3 into b20314c
Browse files Browse the repository at this point in the history
  • Loading branch information
mogoodrich committed Apr 7, 2023
2 parents b20314c + 7d63dc3 commit 82e210e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 28 deletions.
80 changes: 55 additions & 25 deletions app/js/components/Draft.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,63 @@ export class Draft extends PureComponent {
</li>);
});
}
render() {

renderAddResultsButton = () => {
const {
draftOrders, handleDraftDiscard, handleSubmit, intl, isLoading, showAddResultsButton,
draftOrders, handleSubmit, intl, isLoading,
} = this.props;
const isDisabled = draftOrders.length === 0 || isLoading;
const save = intl.formatMessage({ id: "app.orders.save", defaultMessage: "Sign and Save" });
const addResults = intl.formatMessage({ id: "app.orders.addResults", defaultMessage: "Add Results" });
return (
<input
type="submit"
onClick={() => handleSubmit({ redirectToAddResults: true })}
className="button confirm right modified-btn"
value={addResults}
disabled={isDisabled}
/>)
}


renderCancelButton = () => {
const {
draftOrders, handleDraftDiscard, intl, isLoading, showAddResultsButton,
} = this.props;
const isDisabled = draftOrders.length === 0 || isLoading;
const discard = intl.formatMessage({ id: "app.orders.discard", defaultMessage: "Discard" });
const discardAll = intl.formatMessage({ id: "app.orders.discardall", defaultMessage: "Discard All" });
return (
<input
type="button"
id="draft-discard-all"
onClick={() => handleDraftDiscard()}
className={`button ${showAddResultsButton ? 'right' : ''} cancel modified-btn`}
value={draftOrders.length > 1 ? discardAll : discard}
disabled={isDisabled}
/>)
}
renderSubmitButton = () => {
const {
draftOrders, handleSubmit, intl, showAddResultsButton, isLoading,
} = this.props;
const isDisabled = draftOrders.length === 0 || isLoading;
const save = intl.formatMessage({ id: "app.orders.save", defaultMessage: "Save" });

return (
<input
type="submit"
onClick={() => handleSubmit()}
className={`button confirm ${!showAddResultsButton ? 'right' : ''} modified-btn`}
value={save}
disabled={isDisabled}
/>)
}

render() {
const {
draftOrders, showAddResultsButton,
} = this.props;

return (
<div>
<h5 className="h5-draft-header">
Expand All @@ -93,30 +141,12 @@ export class Draft extends PureComponent {
</ul>
</div>
<br />
<input
type="button"
id="draft-discard-all"
onClick={() => handleDraftDiscard()}
className="button cancel modified-btn"
value={draftOrders.length > 1 ? discardAll : discard}
disabled={isDisabled}
/>
<input
type="submit"
onClick={() => handleSubmit()}
className="button confirm right modified-btn"
value={save}
disabled={isDisabled}
/>
{ !showAddResultsButton && this.renderCancelButton() }
{ this.renderSubmitButton() }
{ showAddResultsButton && this.renderAddResultsButton()}
<br />
<br />
{ showAddResultsButton && <input
type="submit"
onClick={() => handleSubmit({ redirectToAddResults: true })}
className="button confirm right modified-btn"
value={addResults}
disabled={isDisabled}
/> }
{ showAddResultsButton && this.renderCancelButton()}
</div>
);
}
Expand Down
5 changes: 4 additions & 1 deletion app/js/components/orderEntry/OrderEntryPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class OrderEntryPage extends PureComponent {
state = {
page: new URLSearchParams(this.props.location.search).get('page'),
returnUrl: new URLSearchParams(this.props.location.search).get('returnUrl'),
afterSaveUrl: new URLSearchParams(this.props.location.search).get('afterSaveUrl'),
addResultsUrl: new URLSearchParams(this.props.location.search).get('addResultsUrl'),
};

Expand Down Expand Up @@ -70,7 +71,7 @@ export class OrderEntryPage extends PureComponent {
} = this.props.addResultsReducer

const { intl } = this.props;
const { addResultsUrl } = this.state;
const { addResultsUrl, afterSaveUrl } = this.state;
const orderCreatedMsg = intl.formatMessage({ id: "app.orders.create.success", defaultMessage: "Order Successfully Created" });
if (added && orderData !== prevProps.createOrderReducer.orderData) {
successToast(orderCreatedMsg);
Expand All @@ -83,6 +84,8 @@ export class OrderEntryPage extends PureComponent {
orders: orderData.orders.map(o => o.uuid).join(","),
});
window.location.assign(url);
} else if (afterSaveUrl) { // otherwise, if there's an after save url, redirect there
window.location.assign(afterSaveUrl)
}
}
if (error) {
Expand Down
4 changes: 2 additions & 2 deletions tests/components/__snapshots__/Draft.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ exports[`Component: Draft should render on initial setup 1`] = `
</div>
<br />
<input
className="button cancel modified-btn"
className="button cancel modified-btn"
id="draft-discard-all"
onClick={[Function]}
type="button"
Expand All @@ -231,7 +231,7 @@ exports[`Component: Draft should render on initial setup 1`] = `
className="button confirm right modified-btn"
onClick={[Function]}
type="submit"
value="Sign and Save"
value="Save"
/>
<br />
<br />
Expand Down

0 comments on commit 82e210e

Please sign in to comment.