Chore: Migrate REST API - getUserPreferences to Typescript (#3830)

This commit is contained in:
Alex Junior 2022-03-09 21:16:20 -03:00 committed by GitHub
parent cd00366613
commit 4ea8d613a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 11 deletions

View File

@ -43,4 +43,10 @@ export type UsersEndpoints = {
user: IUser; user: IUser;
}; };
}; };
'users.getPreferences': {
GET: (params: { userId: IUser['_id'] }) => {
preferences: INotificationPreferences;
success: boolean;
};
};
}; };

View File

@ -290,10 +290,8 @@ export const getChannelInfo = (roomId: string) =>
// RC 0.48.0 // RC 0.48.0
sdk.get('channels.info', { roomId }); sdk.get('channels.info', { roomId });
export const getUserPreferences = (userId: string): any => export const getUserPreferences = (userId: string) =>
// RC 0.62.0 // RC 0.62.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('users.getPreferences', { userId }); sdk.get('users.getPreferences', { userId });
export const getRoomInfo = (roomId: string) => export const getRoomInfo = (roomId: string) =>

View File

@ -15,6 +15,7 @@ import { getUserSelector } from '../../selectors/login';
import sharedStyles from '../Styles'; import sharedStyles from '../Styles';
import { OPTIONS } from './options'; import { OPTIONS } from './options';
import { ProfileStackParamList } from '../../stacks/types'; import { ProfileStackParamList } from '../../stacks/types';
import { INotificationPreferences } from '../../definitions';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
pickerText: { pickerText: {
@ -26,11 +27,7 @@ const styles = StyleSheet.create({
type TKey = 'desktopNotifications' | 'pushNotifications' | 'emailNotificationMode'; type TKey = 'desktopNotifications' | 'pushNotifications' | 'emailNotificationMode';
interface IUserNotificationPreferencesViewState { interface IUserNotificationPreferencesViewState {
preferences: { preferences: INotificationPreferences;
desktopNotifications?: string;
pushNotifications?: string;
emailNotificationMode?: string;
};
loading: boolean; loading: boolean;
} }
@ -53,7 +50,7 @@ class UserNotificationPreferencesView extends React.Component<
constructor(props: IUserNotificationPreferencesViewProps) { constructor(props: IUserNotificationPreferencesViewProps) {
super(props); super(props);
this.state = { this.state = {
preferences: {}, preferences: {} as INotificationPreferences,
loading: false loading: false
}; };
} }
@ -62,8 +59,10 @@ class UserNotificationPreferencesView extends React.Component<
const { user } = this.props; const { user } = this.props;
const { id } = user; const { id } = user;
const result = await RocketChat.getUserPreferences(id); const result = await RocketChat.getUserPreferences(id);
const { preferences } = result; if (result.success) {
this.setState({ preferences, loading: true }); const { preferences } = result;
this.setState({ preferences, loading: true });
}
} }
findDefaultOption = (key: TKey) => { findDefaultOption = (key: TKey) => {