Skip to content

Commit 9fbb583

Browse files
committed
Merge branch 'custom-status' of https://github.com/RocketChat/Rocket.Chat.ReactNative into custom-status
2 parents 272b627 + 932a170 commit 9fbb583

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

app/definitions/ICustomUserStatus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export interface ICustomUserStatus {
55
name: string;
66
statusType: TUserStatus;
77
_updatedAt: {
8-
$date: number;
9-
};
8+
$date: number;
9+
};
1010
}

app/definitions/redux/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export interface IApplicationState {
7878
troubleshootingNotification: ITroubleshootingNotification;
7979
supportedVersions: ISupportedVersionsState;
8080
inAppFeedback: IInAppFeedbackState;
81-
customUserStatus: ICustomUserStatus[];
81+
customUserStatus: ICustomUserStatus[];
8282
}
8383

8484
export type TApplicationActions = TActionActiveUsers &
@@ -103,4 +103,4 @@ export type TApplicationActions = TActionActiveUsers &
103103
TActionTroubleshootingNotification &
104104
TActionSupportedVersions &
105105
TInAppFeedbackAction &
106-
TActionCustomUserStatus
106+
TActionCustomUserStatus;

app/lib/services/restApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
type IServerRoom,
1212
type RoomType,
1313
type SubscriptionType,
14-
type ICustomUserStatus
14+
type ICustomUserStatus
1515
} from '../../definitions';
1616
import { type TParams } from '../../definitions/ILivechatEditView';
1717
import { type ILivechatTag } from '../../definitions/ILivechatTag';
@@ -1124,4 +1124,4 @@ export const getUsersRoles = async (): Promise<boolean | IRoleUser[]> => {
11241124
export const getSupportedVersionsCloud = (uniqueId?: string, domain?: string) =>
11251125
fetch(`https://releases.rocket.chat/v2/server/supportedVersions?uniqueId=${uniqueId}&domain=${domain}&source=mobile`);
11261126

1127-
export const getCustomUserStatus = (): Promise<ICustomUserStatus[]> => sdk.methodCallWrapper('listCustomUserStatus');
1127+
export const getCustomUserStatus = (): Promise<ICustomUserStatus[]> => sdk.methodCallWrapper('listCustomUserStatus');

app/reducers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ export default combineReducers({
5555
troubleshootingNotification,
5656
supportedVersions,
5757
inAppFeedback,
58-
customUserStatus
58+
customUserStatus
5959
});

app/views/StatusView/index.tsx

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useNavigation } from '@react-navigation/native';
1+
import { useNavigation } from '@react-navigation/native';
22
import React, { useEffect, useMemo } from 'react';
33
import { FlatList, StyleSheet, View } from 'react-native';
44
import { useDispatch, useSelector } from 'react-redux';
@@ -30,29 +30,29 @@ interface IStatus {
3030
_id: string;
3131
name: string;
3232
statusType: TUserStatus;
33-
isCustom?: boolean;
33+
isCustom?: boolean;
3434
}
3535

3636
const STATUS: IStatus[] = [
3737
{
3838
_id: 'online',
3939
name: 'Online',
40-
statusType: 'online'
40+
statusType: 'online'
4141
},
4242
{
4343
_id: 'busy',
4444
name: 'Busy',
45-
statusType: 'busy'
45+
statusType: 'busy'
4646
},
4747
{
4848
_id: 'away',
4949
name: 'Away',
50-
statusType: 'away'
50+
statusType: 'away'
5151
},
5252
{
5353
_id: 'offline',
5454
name: 'Offline',
55-
statusType: 'offline'
55+
statusType: 'offline'
5656
}
5757
];
5858

@@ -79,14 +79,14 @@ const Status = ({
7979
statusText,
8080
setStatus,
8181
isCustom,
82-
isCustomSelected
82+
isCustomSelected
8383
}: {
8484
statusType: IStatus;
8585
status: TUserStatus;
8686
statusText: string;
8787
setStatus: (status: TUserStatus, statusText: string) => void;
8888
isCustom?: boolean;
89-
isCustomSelected: boolean;
89+
isCustomSelected: boolean;
9090
}) => {
9191
const { _id, name } = statusType;
9292
const acessibilityLabel = useMemo(() => {
@@ -103,11 +103,10 @@ const Status = ({
103103
if (isCustomSelected) {
104104
return statusText === name;
105105
}
106-
106+
107107
return status === statusType._id;
108108
}, [statusText, name, status, statusType]);
109109

110-
111110
return (
112111
<>
113112
<List.Item
@@ -130,7 +129,6 @@ const Status = ({
130129
);
131130
};
132131

133-
134132
const StatusView = (): React.ReactElement => {
135133
const validationSchema = yup.object().shape({
136134
statusText: yup
@@ -143,7 +141,7 @@ const StatusView = (): React.ReactElement => {
143141
const Accounts_AllowInvisibleStatusOption = useSelector(
144142
(state: IApplicationState) => state.settings.Accounts_AllowInvisibleStatusOption
145143
);
146-
const customUserStatus = useSelector((state: IApplicationState) => state.customUserStatus);
144+
const customUserStatus = useSelector((state: IApplicationState) => state.customUserStatus);
147145

148146
const {
149147
control,
@@ -186,9 +184,9 @@ const StatusView = (): React.ReactElement => {
186184

187185
const setStatus = (status: TUserStatus, statusText: string) => {
188186
setValue('status', status);
189-
if(statusText){
190-
setValue('statusText', statusText);
191-
}
187+
if (statusText) {
188+
setValue('statusText', statusText);
189+
}
192190
};
193191

194192
const setCustomStatus = async (status: TUserStatus, statusText: string) => {
@@ -210,12 +208,15 @@ const StatusView = (): React.ReactElement => {
210208
sendLoadingEvent({ visible: false });
211209
};
212210

213-
const AllStatus = [...STATUS, ...customUserStatus.map(s => ({ ...s, isCustom: true }))];
211+
const AllStatus = [...STATUS, ...customUserStatus.map(s => ({ ...s, isCustom: true }))];
214212
const statusType = Accounts_AllowInvisibleStatusOption ? AllStatus : AllStatus.filter(s => s._id !== 'offline');
215213

216-
const isCustomSelected = useMemo(() => !!customUserStatus.find(s => s.statusType === inputValues.status && s.name === inputValues.statusText), [inputValues.status, inputValues.statusText, statusType]);
217-
218-
const isStatusChanged = () => {
214+
const isCustomSelected = useMemo(
215+
() => !!customUserStatus.find(s => s.statusType === inputValues.status && s.name === inputValues.statusText),
216+
[inputValues.status, inputValues.statusText, statusType]
217+
);
218+
219+
const isStatusChanged = () => {
219220
const { status } = inputValues;
220221
if (!isValid) {
221222
return true;
@@ -236,7 +237,16 @@ const StatusView = (): React.ReactElement => {
236237
<FlatList
237238
data={statusType}
238239
keyExtractor={item => item._id}
239-
renderItem={({ item }) => <Status statusType={item} statusText={inputValues.statusText} status={inputValues.status} setStatus={setStatus} isCustom={item.isCustom} isCustomSelected={isCustomSelected} />}
240+
renderItem={({ item }) => (
241+
<Status
242+
statusType={item}
243+
statusText={inputValues.statusText}
244+
status={inputValues.status}
245+
setStatus={setStatus}
246+
isCustom={item.isCustom}
247+
isCustomSelected={isCustomSelected}
248+
/>
249+
)}
240250
ListHeaderComponent={
241251
<>
242252
<ControlledFormTextInput

0 commit comments

Comments
 (0)