Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix#997/projects users followup #1008

Merged
merged 5 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/data/pages/users-db.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"notes": "voluptatibus et soluta"
},
{
"id": 21,
"id": 22,
"active": true,
"fullname": "Raymond Simonis",
"email": "[email protected]",
Expand All @@ -220,7 +220,7 @@
"notes": "aut id molestiae"
},
{
"id": 22,
"id": 23,
"active": true,
"fullname": "Janice Sporer",
"email": "[email protected]",
Expand All @@ -230,7 +230,7 @@
"notes": "magnam eum aliquam"
},
{
"id": 23,
"id": 24,
"active": true,
"fullname": "Francis Schowalter",
"email": "[email protected]",
Expand All @@ -240,7 +240,7 @@
"notes": "similique architecto in"
},
{
"id": 24,
"id": 25,
"active": true,
"fullname": "Emilio Hoppe",
"email": "[email protected]",
Expand All @@ -250,7 +250,7 @@
"notes": "rerum quae dolorem"
},
{
"id": 25,
"id": 26,
"active": true,
"fullname": "Janice Harber",
"email": "[email protected]",
Expand All @@ -260,7 +260,7 @@
"notes": "iure dolor provident"
},
{
"id": 26,
"id": 27,
"fullname": "Evelyn Morar",
"email": "[email protected]",
"role": "user",
Expand All @@ -270,7 +270,7 @@
"notes": "quae eos placeat"
},
{
"id": 27,
"id": 28,
"fullname": "Antoinette Schneider",
"email": "[email protected]",
"role": "user",
Expand All @@ -280,7 +280,7 @@
"notes": "qui cumque unde"
},
{
"id": 28,
"id": 29,
"fullname": "Ebony Daniel",
"email": "[email protected]",
"role": "user",
Expand Down
4 changes: 2 additions & 2 deletions src/data/pages/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export const getUsers = async (filters: Partial<Filters & Pagination & Sorting>)
const { isActive, search, sortBy, sortingOrder } = filters
let filteredUsers = users

filteredUsers = users.filter((user) => user.active === isActive)
filteredUsers = filteredUsers.filter((user) => user.active === isActive)

if (search) {
filteredUsers = users.filter((user) => user.fullname.toLowerCase().includes(search.toLowerCase()))
filteredUsers = filteredUsers.filter((user) => user.fullname.toLowerCase().includes(search.toLowerCase()))
}

if (sortBy && sortingOrder) {
Expand Down
6 changes: 2 additions & 4 deletions src/pages/projects/ProjectsPage.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<script setup lang="ts">
import { ref } from 'vue'
import { useLocalStorage } from '@vueuse/core'
import { useProjects } from './composables/useProjects'
import ProjectCards from './widgets/ProjectCards.vue'
import ProjectTable from './widgets/ProjectsTable.vue'
import EditProjectForm from './widgets/EditProjectForm.vue'
import { Project } from './types'
import { useModal, useToast } from 'vuestic-ui'

const doShowAsCards = ref(true)
const doShowAsCards = useLocalStorage('projects-view', true)

const { projects, update, add, isLoading, remove, pagination, sorting } = useProjects()

Expand All @@ -27,7 +28,6 @@ const createNewProject = () => {
const { init: notify } = useToast()

const onProjectSaved = async (project: Project) => {
isLoading.value = true
doShowProjectFormModal.value = false
if ('id' in project) {
await update(project as Project)
Expand All @@ -42,8 +42,6 @@ const onProjectSaved = async (project: Project) => {
color: 'success',
})
}

isLoading.value = false
}

const { confirm } = useModal()
Expand Down
8 changes: 4 additions & 4 deletions src/pages/projects/composables/useProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export const useProjects = (options?: { sorting: Ref<Sorting>; pagination: Ref<P

async add(project: Omit<Project, 'id' | 'creation_date'>) {
isLoading.value = true
const createdProject = await addProject({
await addProject({
...project,
project_owner: project.project_owner.id,
team: project.team.map((user) => user.id),
})
projects.value.unshift(createdProject as Project)
await fetch()
isLoading.value = false
},

Expand All @@ -63,7 +63,7 @@ export const useProjects = (options?: { sorting: Ref<Sorting>; pagination: Ref<P
project_owner: project.project_owner.id,
team: project.team.map((user) => user.id),
})
projects.value = projects.value.map((u) => (u.id === project.id ? project : u))
await fetch()
isLoading.value = false
},

Expand All @@ -74,7 +74,7 @@ export const useProjects = (options?: { sorting: Ref<Sorting>; pagination: Ref<P
project_owner: project.project_owner.id,
team: project.team.map((user) => user.id),
})
projects.value = projects.value.filter((u) => u.id !== project.id)
await fetch()
isLoading.value = false
},

Expand Down
7 changes: 3 additions & 4 deletions src/pages/projects/widgets/ProjectsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const totalPages = computed(() => Math.ceil(props.pagination.total / props.pagin
</script>

<template>
<div v-if="projects.length > 0">
<div>
<VaDataTable
v-model:sort-by="sortByVModel"
v-model:sorting-order="sortingOrderVModel"
Expand Down Expand Up @@ -96,8 +96,8 @@ const totalPages = computed(() => Math.ceil(props.pagination.total / props.pagin

<template #cell(actions)="{ rowData: project }">
<div class="flex gap-2 justify-end">
<VaButton preset="primary" icon="mso-edit" color="primary" @click="$emit('edit', project)" />
<VaButton preset="primary" icon="mso-delete" color="danger" @click="$emit('delete', project)" />
<VaButton preset="primary" size="small" color="primary" @click="$emit('edit', project)">Edit</VaButton>
<VaButton preset="primary" size="small" icon="mso-delete" color="danger" @click="$emit('delete', project)" />
</div>
</template>
</VaDataTable>
Expand Down Expand Up @@ -133,5 +133,4 @@ const totalPages = computed(() => Math.ceil(props.pagination.total / props.pagin
</div>
</div>
</div>
<div v-else class="p-4 flex justify-center items-center text-[var(--va-secondary)]">No projects</div>
</template>
13 changes: 3 additions & 10 deletions src/pages/users/composables/useUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,21 @@ export const useUsers = (options?: {
async add(user: User) {
isLoading.value = true
await addUser(user)
users.value.unshift(user)
await fetch()
isLoading.value = false
},

async update(user: User) {
isLoading.value = true
await updateUser(user)
users.value = users.value
.map((u) => (u.id === user.id ? user : u))
.filter((u) => u.active === filters.value.isActive)
.filter((u) => {
if (!filters.value.search) return true

return u.fullname.toLowerCase().includes(filters.value.search.toLowerCase())
})
await fetch()
isLoading.value = false
},

async remove(user: User) {
isLoading.value = true
await removeUser(user)
users.value = users.value.filter((u) => u.id !== user.id)
await fetch()
isLoading.value = false
},
}
Expand Down
10 changes: 8 additions & 2 deletions src/pages/users/widgets/UsersTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ const formatProjectNames = (projects: Project[]) => {

<template #cell(actions)="{ rowData }">
<div class="flex gap-2 justify-end">
<VaButton preset="primary" icon="mso-edit" @click="$emit('edit-user', rowData as User)" />
<VaButton preset="primary" icon="mso-delete" color="danger" @click="onUserDelete(rowData as User)" />
<VaButton preset="primary" size="small" @click="$emit('edit-user', rowData as User)">Edit</VaButton>
<VaButton
preset="primary"
size="small"
icon="mso-delete"
color="danger"
@click="onUserDelete(rowData as User)"
/>
</div>
</template>
</VaDataTable>
Expand Down