From 179c470ff9c91f8206b9e0d53d5b6563656e28b1 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 25 Sep 2022 16:16:31 +0200 Subject: Edit user --- components/VHeader.vue | 2 +- pages/settings.vue | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ store/users.js | 26 +++++++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 pages/settings.vue diff --git a/components/VHeader.vue b/components/VHeader.vue index 0886f08..3ab2ca7 100644 --- a/components/VHeader.vue +++ b/components/VHeader.vue @@ -48,7 +48,7 @@ | Your Profile - a.flex.leanding-6.block.px-4.py-2.text-sm.text-gray-700(href="#" role="menuitem" tabindex="-1") + a.flex.leanding-6.block.px-4.py-2.text-sm.text-gray-700(href="/settings" role="menuitem" tabindex="-1") diff --git a/pages/settings.vue b/pages/settings.vue new file mode 100644 index 0000000..e9a02fb --- /dev/null +++ b/pages/settings.vue @@ -0,0 +1,90 @@ + + + diff --git a/store/users.js b/store/users.js index cb9b4b4..e1f6767 100644 --- a/store/users.js +++ b/store/users.js @@ -59,6 +59,32 @@ export const actions = { commit("loadingStatus", false, { root: true }); + return res; + }, + // Edit an user + async editUser({ commit, rootGetters }, payload) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/users/${payload.id}`, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${rootGetters["auth/accessToken"]}`, + }, + body: JSON.stringify(payload), + }) + .then(async (response) => { + res.data = await response.json(); + res.status = response.status; + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + return res; }, }; -- cgit v1.2.3-18-g5258