Skip to content

Commit 25b7db2

Browse files
authored
(fix) Replace showToast with showSnackbar (#690)
showToast is deprecated in favor of showSnackbar. This migrates the remaining usages in error-utils, form-factory-provider, and encounter-form-processor to use showSnackbar with the corresponding SnackbarDescriptor properties (subtitle instead of description, isLowContrast instead of critical).
1 parent 63fe602 commit 25b7db2

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

src/processors/encounter/encounter-form-processor.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ export class EncounterFormProcessor extends FormProcessor {
140140
const errorMessages = extractErrorMessagesFromResponse(error);
141141
return Promise.reject({
142142
title: t('errorSavingPatientIdentifiers', 'Error saving patient identifiers'),
143-
description: errorMessages.join(', '),
143+
subtitle: errorMessages.join(', '),
144144
kind: 'error',
145-
critical: true,
145+
isLowContrast: false,
146146
});
147147
}
148148

@@ -165,9 +165,9 @@ export class EncounterFormProcessor extends FormProcessor {
165165
const errorMessages = extractErrorMessagesFromResponse(error);
166166
return Promise.reject({
167167
title: t('errorSavingPatientPrograms', 'Error saving patient program(s)'),
168-
description: errorMessages.join(', '),
168+
subtitle: errorMessages.join(', '),
169169
kind: 'error',
170-
critical: true,
170+
isLowContrast: false,
171171
});
172172
}
173173

@@ -209,9 +209,9 @@ export class EncounterFormProcessor extends FormProcessor {
209209
const errorMessages = extractErrorMessagesFromResponse(error);
210210
return Promise.reject({
211211
title: t('errorSavingAttachments', 'Error saving attachment(s)'),
212-
description: errorMessages.join(', '),
212+
subtitle: errorMessages.join(', '),
213213
kind: 'error',
214-
critical: true,
214+
isLowContrast: false,
215215
});
216216
}
217217
return savedEncounter;
@@ -220,9 +220,9 @@ export class EncounterFormProcessor extends FormProcessor {
220220
const errorMessages = extractErrorMessagesFromResponse(error);
221221
return Promise.reject({
222222
title: t('errorSavingEncounter', 'Error saving encounter'),
223-
description: errorMessages.join(', '),
223+
subtitle: errorMessages.join(', '),
224224
kind: 'error',
225-
critical: true,
225+
isLowContrast: false,
226226
});
227227
}
228228
}

src/provider/form-factory-provider.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
2-
import { type FormField, type FormSchema, type SessionMode } from '../types';
3-
import { EncounterFormProcessor } from '../processors/encounter/encounter-form-processor';
2+
import { useTranslation } from 'react-i18next';
43
import {
4+
showSnackbar,
55
type LayoutType,
6-
useLayoutType,
76
type OpenmrsResource,
8-
showSnackbar,
9-
showToast,
10-
type ToastDescriptor,
7+
type SnackbarDescriptor,
118
type Visit,
9+
useLayoutType,
1210
} from '@openmrs/esm-framework';
13-
import { type FormProcessorConstructor } from '../processors/form-processor';
14-
import { type FormContextProps } from './form-provider';
11+
12+
import { EncounterFormProcessor } from '../processors/encounter/encounter-form-processor';
1513
import { processPostSubmissionActions, validateForm } from './form-factory-helper';
16-
import { useTranslation } from 'react-i18next';
17-
import { usePostSubmissionActions } from '../hooks/usePostSubmissionActions';
14+
import { type FormContextProps } from './form-provider';
15+
import { type FormField, type FormSchema, type SessionMode } from '../types';
16+
import { type FormProcessorConstructor } from '../processors/form-processor';
1817
import { useExternalFormAction } from '../hooks/useExternalFormAction';
18+
import { usePostSubmissionActions } from '../hooks/usePostSubmissionActions';
1919

2020
interface FormFactoryProviderContextProps {
2121
patient: fhir.Patient;
@@ -157,17 +157,17 @@ export const FormFactoryProvider: React.FC<FormFactoryProviderProps> = ({
157157
handleClose();
158158
}
159159
})
160-
.catch((errorObject: Error | ToastDescriptor) => {
160+
.catch((errorObject: Error | SnackbarDescriptor) => {
161161
setIsSubmitting(false);
162162
if (errorObject instanceof Error) {
163-
showToast({
163+
showSnackbar({
164164
title: t('errorProcessingFormSubmission', 'Error processing form submission'),
165165
kind: 'error',
166-
description: errorObject.message,
167-
critical: true,
166+
subtitle: errorObject.message,
167+
isLowContrast: false,
168168
});
169169
} else {
170-
showToast(errorObject);
170+
showSnackbar(errorObject);
171171
}
172172
});
173173
} else {

src/utils/error-utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { showToast } from '@openmrs/esm-framework';
1+
import { showSnackbar } from '@openmrs/esm-framework';
22

33
export function reportError(error: Error, title: string): void {
44
if (error) {
55
const errorMessage = extractErrorMessagesFromResponse(error).join(', ');
66
console.error(error);
7-
showToast({
8-
description: errorMessage,
7+
showSnackbar({
8+
subtitle: errorMessage,
99
title: title,
1010
kind: 'error',
11-
critical: true,
11+
isLowContrast: false,
1212
});
1313
}
1414
}

0 commit comments

Comments
 (0)