{"size": 1894, "ext": "js", "max_stars_repo_path": "resources/js/admin/store/modules/users.js", "max_stars_repo_name": "srvrchik/portfolio.site", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "resources/js/admin/store/modules/users.js", "max_issues_repo_name": "srvrchik/portfolio.site", "max_issues_repo_issues_event_min_datetime": "2021-03-10T09:37:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T00:30:05.000Z", "max_forks_repo_path": "resources/js/admin/store/modules/users.js", "max_forks_repo_name": "srvrchik/portfolio.site", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 26.676056338, "max_line_length": 77, "alphanum_fraction": 0.3579725449}
export default {
    namespaced: true,
    state: {
        users: [],
        user: {
            name: ''
        }
    },
    getters: {
        users: (state) => {
            return state.users;
        },
        user: (state) => {
            return state.user;
        },
    },
    actions: {
        getUsers(context){
            axios
                .get('/api/users/list')
                .then((res) => {
                    context.commit('updateUsers', res.data);
                })
                .catch((res) => {
                    console.log(res.response.data);
                    throw "Something went wrong.";
                });
        },
        getUser(context, user_id)
        {
            axios
                .post('/api/users/' + user_id)
                .then((res) => {
                    context.commit('updateUser', res.data.user);
                })
                .catch((res) => {
                    console.log(res.response.data);
                    throw "Something went wrong.";
                });
        },
        deleteUser(context, id)
        {
            var res = confirm('Are you sure?');
            if(res)
            {
                axios
                    .post('/api/users/'+id+'/delete')
                    .then((res) => {
                        context.dispatch('snackbar/showSnackbar', 'Deleted');
                        context.dispatch('getUsers');
                    })
                    .catch((res) => {
                        console.log(res.response.data);
                        throw "Something went wrong.";
                    });
                return true;
            }

            return false;
        }
    },
    mutations: {
        updateUsers(state, users){
            state.users = users;
        },
        updateUser(state, user){
            state.user = user;
        },
    },
}
