import { userSignOut } from '../userSignOut.js';
import { navigateAction } from 'fluxible-router';
import UserProfileStore from '../../../stores/UserProfileStore';
//import notFoundError from '../../error/notFoundError';
import methodNotAllowedError from '../../error/methodNotAllowedError';

export default function removeUser(context, payload, done) {
    payload.params = {};
    payload.params.id = context.getStore(UserProfileStore).userid;
    payload.params.jwt = context.getStore(UserProfileStore).jwt;
    context.service.delete('userProfile.remove', payload, { timeout: 20 * 1000 }, (err, res) => {
        if (err) {
            if (err.statusCode === 404) {
                context.dispatch('DELETE_USER_FAILURE', err);
            } else if (err.statusCode === 401) {
                context.executeAction(methodNotAllowedError, {}, done);
                return;
            } else
                context.dispatch('DELETE_USER_FAILURE', err);
        } else {
            //TODO logout user - context.executeAction(userSignOut, {}); throws an error
            context.executeAction(navigateAction, { url: '/' });
        }
        done();
    });
}

@@ -984,84 +984,88 @@
     
-//TODO logout user - context.executeAction(userSignOut, %7B%7D); throws an error
+context.deleteUser();%0A            context.dispatch('DELETE_USER_SUCCESS', null);
 %0A   
@@ -1126,16 +1126,47 @@
 '/' %7D);%0A
+            location.reload();%0A
         

Delete user context and doing refresh of page after user was deleted