mattermost-mobile-upstream/app/utils/integrations.ts
Elias Nahum b6fc85385e
Migrate from RNN to Expo router (#9402)
* Expo-Router partial migration

* Full migration to ExpoRouter

* i18n

* add tests

* Merge branch 'main' into expo-router

* align package-lock.json

* i18n

* feedback review

* feedback review

* android 16kb patch

* Refactored emoji picker keyboard using a state machine

* set android launch_screen in drawables instead of layout

* no conditional hooks

* remove duplicate call in test

* address feedback

* fix tests and address more feedback

* small corrections

* small corrections

* small corrections

* fix draft test

* fix draft test 2

* remove navigateToScreen in draff test

* fix nit in draft test

* remove doc file

* Feedback review

* fix snapshots

* improve test coverage

* fix i18n

* Upgrade t o RN 0.83, other dependencies and new architecture (#9737)

* library hardware-keyboard android new arch support fix

* library rnshare android new arch support fix

* library rnutils android new arch support fix

* library secure-pdf-viewer add new arch support

* Enable new arch on iOS and Android

* update emm and network client with new-arch

* update intune to use new-arch

* performance improvements

* fix tests

* fixes post input on new-arch

* fix android emoji picker

* remove doc

* run tests in parallel

* upgrade to React Native 0.83.9, Expo 55, React 19, and New Architecture

Bumps core dependencies to their latest versions:
- React Native 0.77.3 → 0.83.9 (New Architecture enabled)
- React 18.3.1 → 19.2.5
- Expo SDK 52 → 55
- TypeScript 5.8.3 → 6.0.3
- Node.js 22.16.0 → 24.15.0
- react-native-reanimated 3.17.3 → 4.3.0
- Various other dependency upgrades

Migrates iOS AppDelegate from Objective-C to Swift, updates Android
build tooling and Gradle wrapper, refreshes all patches and font
assets, and adapts app code, tests, and CI workflows throughout for
API changes introduced by these upgrades.

* remove unecessary dismissKeyboard in notifications

* feedback review

* update intune to use new-arch

* update @mattermost deps

* missing i18n string

* additional fixes

* update fastlane
2026-05-13 17:44:55 +08:00

156 lines
5.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {defineMessages, type IntlShape} from 'react-intl';
import {isAppSelectOption, DialogElementTypes, DialogTextSubtypes} from './dialog_utils';
import type {KeyboardTypeOptions} from 'react-native';
const messages = defineMessages({
required: {
id: 'interactive_dialog.error.required',
defaultMessage: 'This field is required.',
},
tooShort: {
id: 'interactive_dialog.error.too_short',
defaultMessage: 'Minimum input length is {minLength}.',
},
badEmail: {
id: 'interactive_dialog.error.bad_email',
defaultMessage: 'Must be a valid email address.',
},
badNumber: {
id: 'interactive_dialog.error.bad_number',
defaultMessage: 'Must be a number.',
},
badUrl: {
id: 'interactive_dialog.error.bad_url',
defaultMessage: 'URL must include http:// or https://.',
},
invalidOption: {
id: 'interactive_dialog.error.invalid_option',
defaultMessage: 'Must be a valid option',
},
});
export function checkDialogElementForError(elem: DialogElement, value: any, intl: IntlShape): string | undefined | null {
const fieldRequiredError = intl.formatMessage(messages.required);
if (typeof value === 'undefined' && !elem.optional) {
return fieldRequiredError;
}
const type = elem.type;
if (type === DialogElementTypes.TEXT || type === DialogElementTypes.TEXTAREA) {
if (value === '' && !elem.optional) {
return fieldRequiredError;
}
if (value && value.length < elem.min_length) {
return intl.formatMessage(messages.tooShort, {minLength: elem.min_length});
}
if (elem.subtype === DialogTextSubtypes.EMAIL) {
if (value && !value.includes('@')) {
return intl.formatMessage(messages.badEmail);
}
}
if (elem.subtype === DialogTextSubtypes.NUMBER) {
if (value && isNaN(value)) {
return intl.formatMessage(messages.badNumber);
}
}
if (elem.subtype === DialogTextSubtypes.URL) {
if (value && !value.startsWith('http://') && !value.startsWith('https://')) {
return intl.formatMessage(messages.badUrl);
}
}
} else if (type === DialogElementTypes.RADIO) {
if ((typeof value === 'undefined' || value === '') && !elem.optional) {
return fieldRequiredError;
}
const options = elem.options;
if (typeof value !== 'undefined' && value !== '' && Array.isArray(options)) {
// Extract value from AppSelectOption object if needed
const valueToCheck = isAppSelectOption(value) ? value.value : value;
if (!options.some((e) => e.value === valueToCheck)) {
return intl.formatMessage(messages.invalidOption);
}
}
} else if (type === DialogElementTypes.SELECT) {
// Handle empty values for both single and multiselect
if (!elem.optional) {
if (typeof value === 'undefined' || value === '') {
return fieldRequiredError;
}
// For multiselect, also check if array is empty
if (elem.multiselect && Array.isArray(value) && value.length === 0) {
return fieldRequiredError;
}
}
const options = elem.options;
if (typeof value !== 'undefined' && value !== '' && Array.isArray(options)) {
// Handle multiselect arrays
if (elem.multiselect && Array.isArray(value)) {
// For multiselect, check each value in the array
for (const singleValue of value) {
const valueToCheck = isAppSelectOption(singleValue) ? singleValue.value : singleValue;
if (!options.some((e) => e.value === valueToCheck)) {
return intl.formatMessage(messages.invalidOption);
}
}
} else {
// Single select validation
const valueToCheck = isAppSelectOption(value) ? value.value : value;
if (!options.some((e) => e.value === valueToCheck)) {
return intl.formatMessage(messages.invalidOption);
}
}
}
} else if (type === DialogElementTypes.BOOL) {
// Required boolean fields must be true
if (!elem.optional && (typeof value === 'undefined' || value !== true)) {
return fieldRequiredError;
}
}
return null;
}
// If we're returned errors that don't match any of the elements we have,
// ignore them and complete the dialog
export function checkIfErrorsMatchElements(errors: {
[x: string]: unknown;
} = {}, elements: DialogElement[] = []) {
const elemNames = new Set(elements.map((elem) => elem.name));
for (const name in errors) {
if (elemNames.has(name)) {
return true;
}
}
return false;
}
export function selectKeyboardType(subtype?: string): KeyboardTypeOptions {
switch (subtype) {
case 'email':
return 'email-address';
case 'number':
return 'numeric';
case 'tel':
return 'phone-pad';
case 'url':
return 'url';
default:
return 'default';
}
}