From 60ecbe284ca6e18430f1b011c9eff78a342779e2 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Wed, 9 Mar 2022 15:10:36 -0300 Subject: [PATCH] Chore: Migrate REST API - saveUserProfile to Typescript (#3863) * Chore: Migrate REST API - saveUserProfile to Typescript * minor tweak --- .../IProfileViewInterfaces.ts} | 2 +- app/definitions/rest/v1/users.ts | 6 ++++++ app/lib/rocketchat/services/restApi.ts | 5 ++--- app/views/ProfileView/index.tsx | 10 +++++++++- app/views/RoomInfoEditView/index.tsx | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) rename app/{views/ProfileView/interfaces.ts => definitions/IProfileViewInterfaces.ts} (96%) diff --git a/app/views/ProfileView/interfaces.ts b/app/definitions/IProfileViewInterfaces.ts similarity index 96% rename from app/views/ProfileView/interfaces.ts rename to app/definitions/IProfileViewInterfaces.ts index 0fe592f32..491f7b201 100644 --- a/app/views/ProfileView/interfaces.ts +++ b/app/definitions/IProfileViewInterfaces.ts @@ -1,7 +1,7 @@ import { StackNavigationProp } from '@react-navigation/stack'; import React from 'react'; -import { ProfileStackParamList } from '../../stacks/types'; +import { ProfileStackParamList } from '../stacks/types'; export interface IUser { id: string; diff --git a/app/definitions/rest/v1/users.ts b/app/definitions/rest/v1/users.ts index b72f4821a..3b92eaef0 100644 --- a/app/definitions/rest/v1/users.ts +++ b/app/definitions/rest/v1/users.ts @@ -1,3 +1,4 @@ +import { IParams } from '../../IProfileViewInterfaces'; import type { ITeam } from '../../ITeam'; import type { IUser } from '../../IUser'; import { INotificationPreferences, IUserPreferences, IUserRegistered } from '../../IUser'; @@ -37,4 +38,9 @@ export type UsersEndpoints = { 'users.setStatus': { POST: (params: { status: string; message: string }) => {}; }; + 'users.updateOwnBasicInfo': { + POST: (params: { data: IParams | Pick; customFields?: { [key: string | number]: string } }) => { + user: IUser; + }; + }; }; diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 8eabe4566..99eea86f4 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -3,6 +3,7 @@ import { TEAM_TYPE } from '../../../definitions/ITeam'; import roomTypeToApiType, { RoomTypes } from '../methods/roomTypeToApiType'; import { SubscriptionType, INotificationPreferences, IRoomNotifications } from '../../../definitions'; import { ISpotlight } from '../../../definitions/ISpotlight'; +import { IParams } from '../../../definitions/IProfileViewInterfaces'; export const createChannel = ({ name, @@ -545,10 +546,8 @@ export const saveRoomSettings = ( // RC 0.55.0 sdk.methodCallWrapper('saveRoomSettings', rid, params); -export const saveUserProfile = (data: any, customFields?: any): any => +export const saveUserProfile = (data: IParams | Pick, customFields?: { [key: string | number]: string }) => // RC 0.62.2 - // TODO: missing definitions from server - // @ts-ignore sdk.post('users.updateOwnBasicInfo', { data, customFields }); export const saveUserPreferences = (data: Partial) => diff --git a/app/views/ProfileView/index.tsx b/app/views/ProfileView/index.tsx index fc409002d..d7ecbc399 100644 --- a/app/views/ProfileView/index.tsx +++ b/app/views/ProfileView/index.tsx @@ -31,7 +31,15 @@ import { withTheme } from '../../theme'; import { getUserSelector } from '../../selectors/login'; import SafeAreaView from '../../containers/SafeAreaView'; import styles from './styles'; -import { IAvatar, IAvatarButton, INavigationOptions, IParams, IProfileViewProps, IProfileViewState, IUser } from './interfaces'; +import { + IAvatar, + IAvatarButton, + INavigationOptions, + IParams, + IProfileViewProps, + IProfileViewState, + IUser +} from '../../definitions/IProfileViewInterfaces'; class ProfileView extends React.Component { private name: any; diff --git a/app/views/RoomInfoEditView/index.tsx b/app/views/RoomInfoEditView/index.tsx index d79af6d40..6f8b8a274 100644 --- a/app/views/RoomInfoEditView/index.tsx +++ b/app/views/RoomInfoEditView/index.tsx @@ -34,7 +34,7 @@ import log, { events, logEvent } from '../../utils/log'; import { MessageTypeValues } from '../../utils/messageTypes'; import random from '../../utils/random'; import scrollPersistTaps from '../../utils/scrollPersistTaps'; -import { IAvatar } from '../ProfileView/interfaces'; +import { IAvatar } from '../../definitions/IProfileViewInterfaces'; import sharedStyles from '../Styles'; import styles from './styles'; import SwitchContainer from './SwitchContainer';