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 Apr 15, 2024
1 parent 8b7cbc6 commit 856641d
Showing 1 changed file with 8 additions and 13 deletions.
Expand Up @@ -34,7 +34,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 @@ -53,7 +53,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 @@ -66,7 +66,7 @@ const OrderBasket: React.FC<DefaultWorkspaceProps> = ({
);
mutateEncounterUuid();
clearOrders();
mutateOrders().then();
await mutateOrders();
closeWorkspaceWithSavedChanges();
showOrderSuccessToast(t, orders);
} catch (e) {
Expand All @@ -79,15 +79,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 {
setOrdersWithErrors(erroredItems);
}
}
setSavingOrdersLoading(false);
setIsSavingOrders(false);
return () => abortController.abort();
}, [
activeVisit,
Expand Down Expand Up @@ -124,7 +124,7 @@ 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}
Expand All @@ -140,20 +140,15 @@ const OrderBasket: React.FC<DefaultWorkspaceProps> = ({
/>
))}
<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 856641d

Please sign in to comment.