Skip to content

Commit

Permalink
refactor: remove unregister prop inline on inlineNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
usamaidrsk committed Mar 19, 2024
1 parent 3b4ef5a commit 329e58a
Showing 1 changed file with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const OrderBasket: React.FC<DefaultWorkspaceProps> = ({
error: errorFetchingEncounterUuid,
mutate: mutateEncounterUuid,
} = useOrderEncounter(patientUuid);
const [savingOrdersLoading, setSavingOrdersLoading] = useState(false);
const [isSavingOrders, setIsSavingOrders] = useState(false);
const [creatingEncounterError, setCreatingEncounterError] = useState('');
const { mutate: mutateOrders } = useMutatePatientOrders(patientUuid);

Expand All @@ -52,7 +52,7 @@ const OrderBasket: React.FC<DefaultWorkspaceProps> = ({
const abortController = new AbortController();
setCreatingEncounterError('');
let orderEncounterUuid = encounterUuid;
setSavingOrdersLoading(true);
setIsSavingOrders(true);
// If there's no encounter present, create an encounter along with the orders.
if (!orderEncounterUuid) {
try {
Expand All @@ -65,7 +65,7 @@ const OrderBasket: React.FC<DefaultWorkspaceProps> = ({
);
mutateEncounterUuid();
clearOrders();
mutateOrders().then();
await mutateOrders();
closeWorkspaceWithSavedChanges();
showOrderSuccessToast(t, orders);
} catch (e) {
Expand All @@ -78,15 +78,15 @@ const OrderBasket: React.FC<DefaultWorkspaceProps> = ({
} else {
const erroredItems = await postOrders(orderEncounterUuid, abortController);
clearOrders({ exceptThoseMatching: (item) => erroredItems.map((e) => e.display).includes(item.display) });
mutateOrders().then();
await mutateOrders();
if (erroredItems.length == 0) {
closeWorkspaceWithSavedChanges();
showOrderSuccessToast(t, orders);
} else {
showOrderFailureToast(t);
}
}
setSavingOrdersLoading(false);
setIsSavingOrders(false);
return () => abortController.abort();
}, [
activeVisit,
Expand Down Expand Up @@ -123,28 +123,22 @@ const OrderBasket: React.FC<DefaultWorkspaceProps> = ({
{(creatingEncounterError || errorFetchingEncounterUuid) && (
<InlineNotification
kind="error"
title={t('errorCreatingAnEncounter', 'Error when creating an encounter')}
title={t('errorCreatingAnEncounter', 'Error creating an encounter')}
subtitle={creatingEncounterError}
lowContrast={true}
className={styles.inlineNotification}
inline
/>
)}
<ButtonSet className={styles.buttonSet}>
<Button
className={styles.bottomButton}
disabled={savingOrdersLoading}
kind="secondary"
onClick={handleCancel}
>
<Button className={styles.bottomButton} disabled={isSavingOrders} kind="secondary" onClick={handleCancel}>
{t('cancel', 'Cancel')}
</Button>
<Button
className={styles.bottomButton}
kind="primary"
onClick={handleSave}
disabled={
savingOrdersLoading ||
isSavingOrders ||
!orders?.length ||
isLoadingEncounterUuid ||
(activeVisitRequired && !activeVisit) ||
Expand Down

0 comments on commit 329e58a

Please sign in to comment.