[FIX] User status update (#4333)
This commit is contained in:
parent
30d3b0b9f9
commit
e39919094e
|
@ -36,7 +36,7 @@ export type UsersEndpoints = {
|
|||
POST: (params: { name: string; email: string; username: string; pass: string }) => { user: IUserRegistered };
|
||||
};
|
||||
'users.setStatus': {
|
||||
POST: (params: { status: string; message: string }) => {};
|
||||
POST: (params: { status?: string; message?: string }) => {};
|
||||
};
|
||||
'users.updateOwnBasicInfo': {
|
||||
POST: (params: {
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Alert } from 'react-native';
|
|||
import I18n from '../../../i18n';
|
||||
|
||||
export const showErrorAlert = (message: string, title?: string, onPress = () => {}): void =>
|
||||
Alert.alert(title!, message, [{ text: 'OK', onPress }], { cancelable: true });
|
||||
Alert.alert(title || '', message, [{ text: 'OK', onPress }], { cancelable: true });
|
||||
|
||||
interface IShowConfirmationAlert {
|
||||
title?: string;
|
||||
|
|
|
@ -280,7 +280,7 @@ export const setUserPreferences = (userId: string, data: Partial<INotificationPr
|
|||
|
||||
export const setUserStatus = (status: string, message: string) =>
|
||||
// RC 1.2.0
|
||||
sdk.post('users.setStatus', { status, message });
|
||||
sdk.methodCall('setUserStatus', status, message);
|
||||
|
||||
export const setReaction = (emoji: string, messageId: string) =>
|
||||
// RC 0.62.2
|
||||
|
|
|
@ -57,7 +57,7 @@ const styles = StyleSheet.create({
|
|||
}
|
||||
});
|
||||
|
||||
const Status = ({ status, statusText }: { status: IStatus; statusText: string }) => {
|
||||
const Status = ({ status }: { status: IStatus }) => {
|
||||
const user = useSelector((state: IApplicationState) => getUserSelector(state));
|
||||
const dispatch = useDispatch();
|
||||
|
||||
|
@ -70,15 +70,13 @@ const Status = ({ status, statusText }: { status: IStatus; statusText: string })
|
|||
logEvent(events[key]);
|
||||
if (user.status !== status.id) {
|
||||
try {
|
||||
const result = await Services.setUserStatus(status.id, statusText);
|
||||
if (result.success) {
|
||||
dispatch(setUser({ status: status.id }));
|
||||
}
|
||||
await Services.setUserStatus(status.id, user.statusText || '');
|
||||
dispatch(setUser({ status: status.id }));
|
||||
} catch (e: any) {
|
||||
const messageError =
|
||||
e.data && e.data.error.includes('[error-too-many-requests]')
|
||||
? I18n.t('error-too-many-requests', { seconds: e.data.error.replace(/\D/g, '') })
|
||||
: e.data.errorType;
|
||||
e.error && e.error.includes('[error-too-many-requests]')
|
||||
? I18n.t('error-too-many-requests', { seconds: e.reason.replace(/\D/g, '') })
|
||||
: e.reason;
|
||||
showErrorAlert(messageError);
|
||||
logEvent(events.SET_STATUS_FAIL);
|
||||
log(e);
|
||||
|
@ -108,7 +106,7 @@ const StatusView = (): React.ReactElement => {
|
|||
const submit = async () => {
|
||||
logEvent(events.STATUS_DONE);
|
||||
if (statusText !== user.statusText) {
|
||||
await setCustomStatus(statusText);
|
||||
await setCustomStatus(user.status, statusText);
|
||||
}
|
||||
goBack();
|
||||
};
|
||||
|
@ -126,23 +124,18 @@ const StatusView = (): React.ReactElement => {
|
|||
setHeader();
|
||||
}, [statusText, user.status]);
|
||||
|
||||
const setCustomStatus = async (statusText: string) => {
|
||||
const setCustomStatus = async (status: string, statusText: string) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const result = await Services.setUserStatus(user.status, statusText);
|
||||
if (result.success) {
|
||||
dispatch(setUser({ statusText }));
|
||||
logEvent(events.STATUS_CUSTOM);
|
||||
showToast(I18n.t('Status_saved_successfully'));
|
||||
} else {
|
||||
logEvent(events.STATUS_CUSTOM_F);
|
||||
showToast(I18n.t('error-could-not-change-status'));
|
||||
}
|
||||
await Services.setUserStatus(status, statusText);
|
||||
dispatch(setUser({ statusText }));
|
||||
logEvent(events.STATUS_CUSTOM);
|
||||
showToast(I18n.t('Status_saved_successfully'));
|
||||
} catch (e: any) {
|
||||
const messageError =
|
||||
e.data && e.data.error.includes('[error-too-many-requests]')
|
||||
? I18n.t('error-too-many-requests', { seconds: e.data.error.replace(/\D/g, '') })
|
||||
: e.data.errorType;
|
||||
e.error && e.error.includes('[error-too-many-requests]')
|
||||
? I18n.t('error-too-many-requests', { seconds: e.reason.replace(/\D/g, '') })
|
||||
: e.reason;
|
||||
logEvent(events.STATUS_CUSTOM_F);
|
||||
showErrorAlert(messageError);
|
||||
}
|
||||
|
@ -156,7 +149,7 @@ const StatusView = (): React.ReactElement => {
|
|||
<FlatList
|
||||
data={status}
|
||||
keyExtractor={item => item.id}
|
||||
renderItem={({ item }) => <Status status={item} statusText={statusText} />}
|
||||
renderItem={({ item }) => <Status status={item} />}
|
||||
ListHeaderComponent={
|
||||
<>
|
||||
<FormTextInput
|
||||
|
|
Loading…
Reference in New Issue