* feature edit profile screen * minor refactoring * Apply suggestions from code review Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * ts fixes * revert floatingTextInput label This reverts commit a778e1f76191aea7c1a18d60a23ffbd6d3dec0eb. * code clean up * Apply suggestions from code review Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * code fix * code fix * Adding preventDoubleTap * rename id to fieldKey * Update edit_profile.tsx * wip * navigating through fields; partly done * navigating through fields - partly done * navigating through fields; partly done * completed field navigation * added theme into dependency array * code clean up * revert conditions for disabling fields * Added colorFilters prop to Loading component * Completed loading feature on Edit Profile screen * code clean up * Add profile_error * renamed valid_mime_types to valid_image_mime_types * added props isDisabled to email field * refactored next field logic * fix * fix * code clean up * code clean up * Updated ESLINT hook rules to warning instead of disabled * code fix * code fix * new line within your_profile component * added memo for Field component * added canSave to dependency array * update loading component - color filter * Update app/screens/edit_profile/edit_profile.tsx Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * dependency fix * fix to fetch my latest status * fix to remove unnecessary user id for local action updateLocalUser * prevents bouncing for iOS * code revert * Adding textInputStyle and animatedTextStyle to FloatingTextInput component * correction after dev session * adding changes as per new ux * Update edit_profile.tsx * corrections after ux review * ux review * ux review * code clean up * Adding userProfileFields into useMemo * Add enableSaveButton to dependency of submitUser * Revert fetching status on userProfile * EditProfile enable extraScrollHeight on iOS only Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {getTimeZone} from 'react-native-localize';
|
|
|
|
import {updateMe} from '@actions/remote/user';
|
|
import DatabaseManager from '@database/manager';
|
|
import {queryUserById} from '@queries/servers/user';
|
|
|
|
import type UserModel from '@typings/database/models/servers/user';
|
|
|
|
export const isTimezoneEnabled = (config: Partial<ClientConfig>) => {
|
|
return config?.ExperimentalTimezone === 'true';
|
|
};
|
|
|
|
export function getDeviceTimezone() {
|
|
return getTimeZone();
|
|
}
|
|
|
|
export const autoUpdateTimezone = async (serverUrl: string, {deviceTimezone, userId}: {deviceTimezone: string; userId: string}) => {
|
|
const database = DatabaseManager.serverDatabases[serverUrl].database;
|
|
if (!database) {
|
|
return {error: `No database present for ${serverUrl}`};
|
|
}
|
|
|
|
const currentUser = await queryUserById(database, userId) ?? null;
|
|
|
|
if (!currentUser) {
|
|
return null;
|
|
}
|
|
|
|
const currentTimezone = getUserTimezone(currentUser);
|
|
const newTimezoneExists = currentTimezone.automaticTimezone !== deviceTimezone;
|
|
|
|
if (currentTimezone.useAutomaticTimezone && newTimezoneExists) {
|
|
const timezone = {useAutomaticTimezone: 'true', automaticTimezone: deviceTimezone, manualTimezone: currentTimezone.manualTimezone};
|
|
await updateMe(serverUrl, {timezone});
|
|
}
|
|
return null;
|
|
};
|
|
|
|
export const getUserTimezone = (currentUser: UserModel) => {
|
|
if (currentUser?.timezone) {
|
|
return {
|
|
...currentUser?.timezone,
|
|
useAutomaticTimezone: currentUser?.timezone?.useAutomaticTimezone === 'true',
|
|
};
|
|
}
|
|
|
|
return {
|
|
useAutomaticTimezone: true,
|
|
automaticTimezone: '',
|
|
manualTimezone: '',
|
|
};
|
|
};
|