mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	invite: Clean error handling and use ui_report.
This also fixes few unusual UI issues like an invitation got failed when certain emails can't be invited then the error box is left with "warning" even when next request got succeed and another case when invitation got succeed after failing it's still reported with "alert-error" class alert banner.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							93ddf2ca37
						
					
				
				
					commit
					9e3423129b
				
			@@ -7,7 +7,7 @@ var common = (function () {
 | 
			
		||||
 | 
			
		||||
var exports = {};
 | 
			
		||||
 | 
			
		||||
exports.status_classes = 'alert-error alert-success alert-info';
 | 
			
		||||
exports.status_classes = 'alert-error alert-success alert-info alert-warning';
 | 
			
		||||
 | 
			
		||||
exports.autofocus = function (selector) {
 | 
			
		||||
    $(function () {
 | 
			
		||||
 
 | 
			
		||||
@@ -46,9 +46,8 @@ function submit_invitation_form() {
 | 
			
		||||
        },
 | 
			
		||||
        success: function () {
 | 
			
		||||
            $('#submit-invitation').button('reset');
 | 
			
		||||
            invite_status.text(i18n.t('User(s) invited successfully.'))
 | 
			
		||||
                .addClass('alert-success')
 | 
			
		||||
                .show();
 | 
			
		||||
            ui_report.success(i18n.t('User(s) invited successfully.'), invite_status);
 | 
			
		||||
            invitee_emails_group.removeClass('warning');
 | 
			
		||||
            invitee_emails.val('');
 | 
			
		||||
 | 
			
		||||
            if (page_params.development_environment) {
 | 
			
		||||
@@ -62,23 +61,21 @@ function submit_invitation_form() {
 | 
			
		||||
            var arr = JSON.parse(xhr.responseText);
 | 
			
		||||
            if (arr.errors === undefined) {
 | 
			
		||||
                // There was a fatal error, no partial processing occurred.
 | 
			
		||||
                invite_status.text(arr.msg)
 | 
			
		||||
                    .addClass('alert-error')
 | 
			
		||||
                    .show();
 | 
			
		||||
                ui_report.error("", xhr, invite_status);
 | 
			
		||||
            } else {
 | 
			
		||||
                // Some users were not invited.
 | 
			
		||||
                var invitee_emails_errored = [];
 | 
			
		||||
                var error_list = $('<ul>');
 | 
			
		||||
                _.each(arr.errors, function (value) {
 | 
			
		||||
                    error_list.append($('<li>').text(value.join(': ')));
 | 
			
		||||
                var error_list = [];
 | 
			
		||||
                arr.errors.forEach(function (value) {
 | 
			
		||||
                    error_list.push(value.join(': '));
 | 
			
		||||
                    invitee_emails_errored.push(value[0]);
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                invite_status.addClass('alert-warning')
 | 
			
		||||
                    .empty()
 | 
			
		||||
                    .append($('<p>').text(arr.msg))
 | 
			
		||||
                    .append(error_list)
 | 
			
		||||
                    .show();
 | 
			
		||||
                var error_response = templates.render("invitation_failed_error", {
 | 
			
		||||
                    error_message: arr.msg,
 | 
			
		||||
                    error_list: error_list,
 | 
			
		||||
                });
 | 
			
		||||
                ui_report.message(error_response, invite_status, "alert-warning");
 | 
			
		||||
                invitee_emails_group.addClass('warning');
 | 
			
		||||
 | 
			
		||||
                if (arr.sent_invitations) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								static/templates/invitation_failed_error.handlebars
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								static/templates/invitation_failed_error.handlebars
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
<p>{{ error_message }}</p>
 | 
			
		||||
<ul>
 | 
			
		||||
    {{#each error_list}}
 | 
			
		||||
    <li>{{this}}</li>
 | 
			
		||||
    {{/each}}
 | 
			
		||||
</ul>
 | 
			
		||||
		Reference in New Issue
	
	Block a user