generated from moevm/nsql-clean-tempate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from moevm/users-actions
Users actions
- Loading branch information
Showing
20 changed files
with
639 additions
and
174 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<template> | ||
<Modal ref="modal" backdrop="static" @opened="onOpened"> | ||
<template #header="{ close }"> | ||
<h4 class="modal-title">Редактировать данные</h4> | ||
<button type="button" class="btn-close" @click="close"></button> | ||
</template> | ||
|
||
<template v-if="user" #body> | ||
<FormKit v-model="user" type="form" :actions="false"> | ||
<FormKit name="login" type="text" label="Логин" /> | ||
<FormKit name="name" type="text" label="Имя" /> | ||
<FormKit name="password" type="text" label="Пароль" /> | ||
</FormKit> | ||
</template> | ||
|
||
<template #footer="{ close }"> | ||
<button type="button" class="btn btn-secondary" @click="close"> | ||
Отмена | ||
</button> | ||
<button type="button" class="btn btn-danger" @click="submit"> | ||
Подтвердить | ||
</button> | ||
</template> | ||
</Modal> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import Modal from "@/components/common/Modal.vue"; | ||
import { ref } from "vue"; | ||
import { User } from "@/types/users"; | ||
import _ from "lodash"; | ||
const props = defineProps<{ user: User }>(); | ||
const emit = defineEmits<{ (e: "submit", u: User): void }>(); | ||
const modal = ref<InstanceType<typeof Modal> | null>(null); | ||
const user = ref<User | null>(null); | ||
function onOpened() { | ||
user.value = _.cloneDeep(props.user); | ||
} | ||
function submit() { | ||
if (user.value) { | ||
emit("submit", user.value); | ||
} | ||
modal.value?.close(); | ||
} | ||
defineExpose({ modal }); | ||
</script> | ||
|
||
<style scoped lang="scss"></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<template> | ||
<div class="container-lg mt-3"> | ||
<div class="row justify-content-center"> | ||
<i | ||
class="col-auto text-primary bi bi-person-circle" | ||
style="font-size: 256px" | ||
/> | ||
<div class="col-auto"> | ||
<div class="fs-4 d-flex align-items-center"> | ||
<span class="fs-3">{{ userStore.user?.login }}</span> | ||
<span class="badge bg-secondary ms-3"> | ||
#{{ userStore.user?._id.$oid }} | ||
</span> | ||
<i | ||
class="bi bi-person-gear fs-1 text-primary ms-5" | ||
role="button" | ||
@click="edit" | ||
/> | ||
</div> | ||
<div class="fs-4 mt-2"> | ||
<div>Имя: {{ userStore.user?.name }}</div> | ||
<div class="mt-1"> | ||
Роль: | ||
{{ UserRoleTranslations[userStore.user?.role ?? UserRole.user] }} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<EditProfileModal | ||
v-if="userStore.user" | ||
ref="editUserModal" | ||
:user="userStore.user" | ||
@submit="onEdit" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref } from "vue"; | ||
import { useUserStore } from "@/store/user"; | ||
import { useToaster } from "@/store/toaster"; | ||
import { UserRole, UserRoleTranslations } from "@/config/users"; | ||
import EditProfileModal from "@/components/routes/profile/EditProfileModal.vue"; | ||
import { User } from "@/types/users"; | ||
import _ from "lodash"; | ||
import { ProfileAPI } from "@/components/routes/profile/api"; | ||
import { ToastTypes } from "@/config/toast"; | ||
|
||
const editUserModal = ref<InstanceType<typeof EditProfileModal> | null>(null); | ||
|
||
const userStore = useUserStore(), | ||
toaster = useToaster(); | ||
|
||
function edit() { | ||
editUserModal.value?.modal?.open(); | ||
} | ||
|
||
async function onEdit(data: User) { | ||
await ProfileAPI.updateSelf(_.pick(data, ["login", "name", "password"])); | ||
await userStore.fetchUser(); | ||
toaster.addToast({ | ||
title: "Обновлено", | ||
body: "Профиль успешно обновлён", | ||
type: ToastTypes.success, | ||
}); | ||
} | ||
</script> | ||
|
||
<style scoped lang="scss"></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { api } from "@/api"; | ||
import { UserSelfUpdate } from "@/components/routes/profile/types"; | ||
|
||
function updateSelf(data: UserSelfUpdate) { | ||
return api.put("/users/user/self", { ...data }); | ||
} | ||
|
||
export const ProfileAPI = { updateSelf }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { User } from "@/types/users"; | ||
|
||
export type UserSelfUpdate = Omit<User, "_id" | "role">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<template> | ||
<Modal ref="modal" backdrop="static" @opened="onOpened"> | ||
<template #header="{ close }"> | ||
<h4 class="modal-title">Редактировать данные</h4> | ||
<button type="button" class="btn-close" @click="close"></button> | ||
</template> | ||
|
||
<template v-if="user" #body> | ||
<FormKit v-model="user" type="form" :actions="false"> | ||
<FormKit name="login" type="text" label="Логин" /> | ||
<FormKit name="password" type="text" label="Пароль" /> | ||
<FormKit name="name" type="text" label="Имя" /> | ||
<FormKit | ||
name="role" | ||
type="select" | ||
label="Роль" | ||
placeholder="Выберите роль" | ||
:options="UserRoleTranslations" | ||
/> | ||
</FormKit> | ||
</template> | ||
|
||
<template #footer="{ close }"> | ||
<button type="button" class="btn btn-secondary" @click="close"> | ||
Отмена | ||
</button> | ||
<button type="button" class="btn btn-danger" @click="submit"> | ||
Подтвердить | ||
</button> | ||
</template> | ||
</Modal> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import Modal from "@/components/common/Modal.vue"; | ||
import { ref } from "vue"; | ||
import { User } from "@/types/users"; | ||
import { UserRoleTranslations } from "@/config/users"; | ||
import _ from "lodash"; | ||
const props = defineProps<{ user: User }>(); | ||
const emit = defineEmits<{ (e: "submit", u: User): void }>(); | ||
const modal = ref<InstanceType<typeof Modal> | null>(null); | ||
const user = ref<User | null>(null); | ||
function onOpened() { | ||
user.value = _.cloneDeep(props.user); | ||
} | ||
function submit() { | ||
if (user.value) { | ||
emit("submit", user.value); | ||
} | ||
modal.value?.close(); | ||
} | ||
defineExpose({ modal }); | ||
</script> | ||
|
||
<style scoped lang="scss"></style> |
Oops, something went wrong.