Snackbar: update (most) existing alerts to snackbars

This commit is contained in:
Alex Gleason 2020-09-29 19:10:57 -05:00
parent b782f6ab1a
commit 14a5d478f3
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
9 changed files with 29 additions and 29 deletions

View file

@ -1,5 +1,5 @@
import api from '../api';
import { showAlert } from 'soapbox/actions/alerts';
import snackbar from 'soapbox/actions/snackbar';
import { fetchMe } from 'soapbox/actions/me';
export const AUTH_APP_CREATED = 'AUTH_APP_CREATED';
@ -136,7 +136,7 @@ export function logIn(username, password) {
if (error.response.data.error === 'mfa_required') {
throw error;
} else {
dispatch(showAlert('Login failed.', 'Invalid username or password.'));
dispatch(snackbar.error('Invalid username or password.'));
}
throw error;
});
@ -156,7 +156,7 @@ export function logOut() {
token: state.getIn(['auth', 'user', 'access_token']),
});
dispatch(showAlert('Successfully logged out.', ''));
dispatch(snackbar.success('Logged out.'));
};
}
@ -172,9 +172,9 @@ export function register(params) {
dispatch({ type: AUTH_REGISTER_SUCCESS, token: response.data });
dispatch(authLoggedIn(response.data));
if (needsConfirmation) {
return dispatch(showAlert('', 'Check your email for further instructions.'));
return dispatch(snackbar.info('You must confirm your email.'));
} else if (needsApproval) {
return dispatch(showAlert('', 'Your account has been submitted for approval.'));
return dispatch(snackbar.info('Your account is being reviewed.'));
} else {
return dispatch(fetchMe());
}
@ -232,7 +232,7 @@ export function deleteAccount(password) {
if (response.data.error) throw response.data.error; // This endpoint returns HTTP 200 even on failure
dispatch({ type: DELETE_ACCOUNT_SUCCESS, response });
dispatch({ type: AUTH_LOGGED_OUT });
dispatch(showAlert('Successfully logged out.', ''));
dispatch(snackbar.success('Logged out.'));
}).catch(error => {
dispatch({ type: DELETE_ACCOUNT_FAIL, error, skipAlert: true });
throw error;

View file

@ -224,7 +224,7 @@ export function uploadCompose(files) {
let total = Array.from(files).reduce((a, v) => a + v.size, 0);
if (files.length + media.size > uploadLimit) {
dispatch(showAlert(undefined, messages.uploadErrorLimit));
dispatch(showAlert(undefined, messages.uploadErrorLimit, 'error'));
return;
}

View file

@ -1,5 +1,5 @@
import api from '../api';
import { showAlert } from 'soapbox/actions/alerts';
import snackbar from 'soapbox/actions/snackbar';
export const FILTERS_FETCH_REQUEST = 'FILTERS_FETCH_REQUEST';
export const FILTERS_FETCH_SUCCESS = 'FILTERS_FETCH_SUCCESS';
@ -47,7 +47,7 @@ export function createFilter(phrase, expires_at, context, whole_word, irreversib
expires_at,
}).then(response => {
dispatch({ type: FILTERS_CREATE_SUCCESS, filter: response.data });
dispatch(showAlert('', 'Filter added'));
dispatch(snackbar.success('Filter added.'));
}).catch(error => {
dispatch({ type: FILTERS_CREATE_FAIL, error });
});
@ -60,7 +60,7 @@ export function deleteFilter(id) {
dispatch({ type: FILTERS_DELETE_REQUEST });
return api(getState).delete('/api/v1/filters/'+id).then(response => {
dispatch({ type: FILTERS_DELETE_SUCCESS, filter: response.data });
dispatch(showAlert('', 'Filter deleted'));
dispatch(snackbar.success('Filter deleted.'));
}).catch(error => {
dispatch({ type: FILTERS_DELETE_FAIL, error });
});

View file

@ -1,5 +1,5 @@
import api from '../api';
import { showAlert } from 'soapbox/actions/alerts';
import snackbar from 'soapbox/actions/snackbar';
export const IMPORT_FOLLOWS_REQUEST = 'IMPORT_FOLLOWS_REQUEST';
export const IMPORT_FOLLOWS_SUCCESS = 'IMPORT_FOLLOWS_SUCCESS';
@ -19,7 +19,7 @@ export function importFollows(params) {
return api(getState)
.post('/api/pleroma/follow_import', params)
.then(response => {
dispatch(showAlert('', 'Followers imported successfully'));
dispatch(snackbar.success('Followers imported successfully'));
dispatch({ type: IMPORT_FOLLOWS_SUCCESS, config: response.data });
}).catch(error => {
dispatch({ type: IMPORT_FOLLOWS_FAIL, error });
@ -33,7 +33,7 @@ export function importBlocks(params) {
return api(getState)
.post('/api/pleroma/blocks_import', params)
.then(response => {
dispatch(showAlert('', 'Blocks imported successfully'));
dispatch(snackbar.success('Blocks imported successfully'));
dispatch({ type: IMPORT_BLOCKS_SUCCESS, config: response.data });
}).catch(error => {
dispatch({ type: IMPORT_BLOCKS_FAIL, error });
@ -47,7 +47,7 @@ export function importMutes(params) {
return api(getState)
.post('/api/pleroma/mutes_import', params)
.then(response => {
dispatch(showAlert('', 'Mutes imported successfully'));
dispatch(snackbar.success('Mutes imported successfully'));
dispatch({ type: IMPORT_MUTES_SUCCESS, config: response.data });
}).catch(error => {
dispatch({ type: IMPORT_MUTES_FAIL, error });

View file

@ -1,6 +1,6 @@
import api from '../api';
import { importFetchedAccounts, importFetchedStatus } from './importer';
import { showAlert } from 'soapbox/actions/alerts';
import snackbar from 'soapbox/actions/snackbar';
export const REBLOG_REQUEST = 'REBLOG_REQUEST';
export const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
@ -211,7 +211,7 @@ export function bookmark(status) {
api(getState).post(`/api/v1/statuses/${status.get('id')}/bookmark`).then(function(response) {
dispatch(importFetchedStatus(response.data));
dispatch(bookmarkSuccess(status, response.data));
dispatch(showAlert('', 'Bookmark added'));
dispatch(snackbar.success('Bookmark added'));
}).catch(function(error) {
dispatch(bookmarkFail(status, error));
});
@ -225,7 +225,7 @@ export function unbookmark(status) {
api(getState).post(`/api/v1/statuses/${status.get('id')}/unbookmark`).then(response => {
dispatch(importFetchedStatus(response.data));
dispatch(unbookmarkSuccess(status, response.data));
dispatch(showAlert('', 'Bookmark removed'));
dispatch(snackbar.success('Bookmark removed'));
}).catch(error => {
dispatch(unbookmarkFail(status, error));
});

View file

@ -4,7 +4,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
import { resetPassword } from 'soapbox/actions/auth';
import { SimpleForm, FieldsGroup, TextInput } from 'soapbox/features/forms';
import { Redirect } from 'react-router-dom';
import { showAlert } from 'soapbox/actions/alerts';
import snackbar from 'soapbox/actions/snackbar';
export default @connect()
class PasswordReset extends ImmutablePureComponent {
@ -20,7 +20,7 @@ class PasswordReset extends ImmutablePureComponent {
this.setState({ isLoading: true });
dispatch(resetPassword(nicknameOrEmail)).then(() => {
this.setState({ isLoading: false, success: true });
dispatch(showAlert('Password reset received. Check your email for further instructions.', ''));
dispatch(snackbar.info('Check your email for confirmation.'));
}).catch(error => {
this.setState({ isLoading: false });
});

View file

@ -4,7 +4,7 @@ import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { showAlert } from 'soapbox/actions/alerts';
import snackbar from 'soapbox/actions/snackbar';
import Column from '../ui/components/column';
import {
SimpleForm,
@ -124,7 +124,7 @@ class EditProfile extends ImmutablePureComponent {
const { dispatch } = this.props;
dispatch(patchMe(this.getFormdata())).then(() => {
this.setState({ isLoading: false });
dispatch(showAlert('', 'Profile saved!'));
dispatch(snackbar.success('Profile saved!'));
}).catch((error) => {
this.setState({ isLoading: false });
});

View file

@ -14,7 +14,7 @@ import {
SelectDropdown,
Checkbox,
} from 'soapbox/features/forms';
import { showAlert } from 'soapbox/actions/alerts';
import snackbar from 'soapbox/actions/snackbar';
import Icon from 'soapbox/components/icon';
import ColumnSubheading from '../ui/components/column_subheading';
@ -114,7 +114,7 @@ class Filters extends ImmutablePureComponent {
dispatch(createFilter(phrase, expires_at, context, whole_word, irreversible)).then(response => {
return dispatch(fetchFilters());
}).catch(error => {
dispatch(showAlert('', intl.formatMessage(messages.create_error)));
dispatch(snackbar.error(intl.formatMessage(messages.create_error)));
});
}
@ -123,7 +123,7 @@ class Filters extends ImmutablePureComponent {
dispatch(deleteFilter(e.currentTarget.dataset.value)).then(response => {
return dispatch(fetchFilters());
}).catch(error => {
dispatch(showAlert('', intl.formatMessage(messages.delete_error)));
dispatch(snackbar.error(intl.formatMessage(messages.delete_error)));
});
}

View file

@ -10,7 +10,7 @@ import ColumnSubheading from '../ui/components/column_subheading';
import LoadingIndicator from 'soapbox/components/loading_indicator';
import Button from 'soapbox/components/button';
import { changeSetting, getSettings } from 'soapbox/actions/settings';
import { showAlert } from 'soapbox/actions/alerts';
import snackbar from 'soapbox/actions/snackbar';
import {
SimpleForm,
SimpleInput,
@ -129,7 +129,7 @@ class DisableOtpForm extends ImmutablePureComponent {
this.context.router.history.push('../auth/edit');
dispatch(changeSetting(['otpEnabled'], false));
}).catch(error => {
dispatch(showAlert('', intl.formatMessage(messages.disableFail)));
dispatch(snackbar.error(intl.formatMessage(messages.disableFail)));
});
}
@ -180,7 +180,7 @@ class EnableOtpForm extends ImmutablePureComponent {
dispatch(fetchBackupCodes()).then(response => {
this.setState({ backupCodes: response.data.codes });
}).catch(error => {
dispatch(showAlert('', intl.formatMessage(messages.codesFail)));
dispatch(snackbar.error(intl.formatMessage(messages.codesFail)));
});
}
@ -261,7 +261,7 @@ class OtpConfirmForm extends ImmutablePureComponent {
dispatch(fetchToptSetup()).then(response => {
this.setState({ qrCodeURI: response.data.provisioning_uri, confirm_key: response.data.key });
}).catch(error => {
dispatch(showAlert('', intl.formatMessage(messages.qrFail)));
dispatch(snackbar.error(intl.formatMessage(messages.qrFail)));
});
}
@ -276,7 +276,7 @@ class OtpConfirmForm extends ImmutablePureComponent {
dispatch(confirmToptSetup(code, password)).then(response => {
dispatch(changeSetting(['otpEnabled'], true));
}).catch(error => {
dispatch(showAlert('', intl.formatMessage(messages.confirmFail)));
dispatch(snackbar.error(intl.formatMessage(messages.confirmFail)));
});
}