Skip to content

Commit f0b0c60

Browse files
chrisbobbegnprice
authored andcommitted
ui [nfc]: Pull out some helpers for showErrorAlert
We'd like to use these for a new function, showConfirmationDialog, coming up.
1 parent eb7f11a commit f0b0c60

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/utils/info.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,33 @@ export const showToast = (message: string) => {
99
Toast.show(message);
1010
};
1111

12+
type LearnMoreButton = {|
13+
url: URL,
14+
text?: string,
15+
16+
// Needed by openLinkWithUserPreference
17+
globalSettings: GlobalSettingsState,
18+
|};
19+
20+
const makeLearnMoreButton = learnMoreButton => {
21+
const { url, text, globalSettings } = learnMoreButton;
22+
return {
23+
// TODO: Translate default text
24+
text: text ?? 'Learn more',
25+
onPress: () => {
26+
openLinkWithUserPreference(url.toString(), globalSettings);
27+
},
28+
};
29+
};
30+
1231
export const showErrorAlert = (
1332
title: string,
1433
message?: string,
15-
16-
learnMoreButton?: {|
17-
url: URL,
18-
text?: string,
19-
20-
// Needed by openLinkWithUserPreference
21-
globalSettings: GlobalSettingsState,
22-
|},
34+
learnMoreButton?: LearnMoreButton,
2335
): void => {
2436
const buttons = [];
2537
if (learnMoreButton) {
26-
const { url, text, globalSettings } = learnMoreButton;
27-
buttons.push({
28-
// TODO: Translate default text
29-
text: text ?? 'Learn more',
30-
onPress: () => {
31-
openLinkWithUserPreference(url.toString(), globalSettings);
32-
},
33-
});
38+
buttons.push(makeLearnMoreButton(learnMoreButton));
3439
}
3540
buttons.push({ text: 'OK', onPress: () => {} });
3641

0 commit comments

Comments
 (0)