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