Skip to content

Commit 54d0158

Browse files
authored
feat: edit all users (#66)
* feat: edit all users * chore: filter
1 parent 988839c commit 54d0158

19 files changed

Lines changed: 147 additions & 87 deletions

File tree

apps/web-app/app/components/PartnerAgreementCard.vue

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,34 @@
55
!agreement.isActive && 'opacity-75 grayscale-100',
66
]"
77
>
8-
<div class="flex flex-col gap-3">
9-
<div class="flex flex-row items-start gap-2.5">
10-
<UIcon
11-
name="i-lucide-scroll-text"
12-
class="shrink-0 size-14 text-primary"
13-
@click="modalUpdatePartnerAgreement.open({ agreementId: agreement.id })"
14-
/>
8+
<div class="flex flex-col gap-3 group/list">
9+
<div class="flex flex-row justify-between">
10+
<div class="flex flex-row items-start gap-2.5">
11+
<UIcon name="i-lucide-scroll-text" class="shrink-0 size-14 text-primary" />
1512

16-
<UProgress
17-
v-model="agreementProgress"
18-
size="md"
19-
color="secondary"
20-
orientation="vertical"
21-
inverted
22-
class="h-14 py-1"
23-
:ui="{
24-
indicator: agreementProgress <= 15 && '!bg-error',
25-
}"
26-
/>
13+
<UProgress
14+
v-model="agreementProgress"
15+
size="md"
16+
color="secondary"
17+
orientation="vertical"
18+
inverted
19+
class="h-14 py-1"
20+
:ui="{
21+
indicator: agreementProgress <= 15 && '!bg-error',
22+
}"
23+
/>
24+
</div>
25+
26+
<UTooltip :text="`Редактировать «Договор №${agreement.internalId`">
27+
<UButton
28+
variant="outline"
29+
color="neutral"
30+
size="md"
31+
icon="i-lucide-pencil"
32+
class="size-10 justify-center opacity-0 group-hover/list:opacity-100"
33+
@click="modalUpdatePartnerAgreement.open({ agreementId: agreement.id })"
34+
/>
35+
</UTooltip>
2736
</div>
2837

2938
<h3 class="text-xl md:text-xl/6 font-semibold">

apps/web-app/app/components/UserMenu.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<template>
22
<UDropdownMenu
3-
v-if="user.id"
3+
v-if="userStore.id"
44
size="lg"
55
:items="userMenuItems"
66
:search-input="false"
77
:content="{ side: 'top', align: 'center' }"
88
:ui="{ content: 'w-64' }"
99
>
1010
<UButton
11-
:avatar="{ src: user.avatarUrl ?? undefined }"
11+
:avatar="{ src: userStore.avatarUrl ?? undefined }"
1212
:ui="{ trailingIcon: 'text-dimmed' }"
13-
:label="user.fullName ?? t('common.colleague')"
13+
:label="userStore.fullName ?? t('common.colleague')"
1414
block
1515
color="neutral"
1616
variant="ghost"
@@ -28,7 +28,7 @@ const { t } = useI18n()
2828
const colorMode = useColorMode()
2929
const app = useApp()
3030
31-
const user = useUserStore()
31+
const userStore = useUserStore()
3232
3333
async function signOut() {
3434
await clear()
@@ -41,10 +41,10 @@ const modalUpdateUser = overlay.create(ModalUpdateUser)
4141
4242
const userMenuItems = computed(() => [
4343
{
44-
label: user.fullName ?? t('common.colleague'),
44+
label: userStore.fullName ?? t('common.colleague'),
4545
type: 'label' as const,
4646
avatar: {
47-
src: user.avatarUrl ?? undefined,
47+
src: userStore.avatarUrl ?? undefined,
4848
},
4949
},
5050
{
@@ -55,7 +55,7 @@ const userMenuItems = computed(() => [
5555
type: 'link' as const,
5656
icon: 'lucide:edit',
5757
onClick() {
58-
modalUpdateUser.open()
58+
modalUpdateUser.open({ userId: userStore.id })
5959
},
6060
},
6161
{

apps/web-app/app/components/form/AttachProduct.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ async function onSubmit(event: FormSubmitEvent<AttachProductToMenuCategory>) {
8787
body: event.data,
8888
})
8989
90-
await productStore.update()
91-
await menuStore.update()
90+
await Promise.all([
91+
productStore.update(),
92+
menuStore.update(),
93+
])
9294
9395
actionToast.success(toastId, t('toast.category-updated'))
9496
emit('success')

apps/web-app/app/components/form/CompleteTask.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ async function onSubmit(event: FormSubmitEvent<CompleteTask>) {
9090
body: event.data,
9191
})
9292
93-
await taskStore.update()
94-
await userStore.update()
93+
await Promise.all([
94+
taskStore.update(),
95+
userStore.update(),
96+
])
9597
9698
actionToast.success(toastId, t('toast.task-completed'))
9799
emit('success')

apps/web-app/app/components/form/UpdateActivityScheduleItem.vue

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,6 @@
6060
block
6161
:label="$t('common.update')"
6262
/>
63-
64-
<!-- <UButton
65-
variant="soft"
66-
color="error"
67-
size="xl"
68-
icon="i-lucide-trash-2"
69-
class="aspect-square justify-center"
70-
@click="onDelete"
71-
/> -->
7263
</div>
7364
</UForm>
7465
</template>
@@ -119,25 +110,4 @@ async function onSubmit(event: FormSubmitEvent<UpdateActivityScheduleItem>) {
119110
actionToast.error(toastId)
120111
}
121112
}
122-
123-
// async function onDelete() {
124-
// const toastId = actionToast.start()
125-
// emit('submitted')
126-
127-
// try {
128-
// await $fetch(`/api/menu/category/id/${categoryId}`, {
129-
// method: 'DELETE',
130-
// })
131-
132-
// await menuStore.update()
133-
134-
// actionToast.success(toastId, t('toast.category-deleted'))
135-
// emit('success')
136-
137-
// router.push(redirectTo)
138-
// } catch (error) {
139-
// console.error(error)
140-
// actionToast.error(toastId)
141-
// }
142-
// }
143113
</script>

apps/web-app/app/components/form/UpdateProduct.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ async function onSubmit(event: FormSubmitEvent<UpdateProduct>) {
109109
body: event.data,
110110
})
111111
112-
await productStore.update()
113-
await menuStore.update()
112+
await Promise.all([
113+
productStore.update(),
114+
menuStore.update(),
115+
])
114116
115117
actionToast.success(toastId, t('toast.product-updated'))
116118
emit('success')
@@ -129,8 +131,10 @@ async function onDelete() {
129131
method: 'DELETE',
130132
})
131133
132-
await productStore.update()
133-
await menuStore.update()
134+
await Promise.all([
135+
productStore.update(),
136+
menuStore.update(),
137+
])
134138
135139
actionToast.success(toastId, t('toast.product-deleted'))
136140
emit('success')

apps/web-app/app/components/form/UpdateProductVariant.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,10 @@ async function onSubmit(event: FormSubmitEvent<UpdateProductVariant>) {
235235
body: event.data,
236236
})
237237
238-
await productStore.update()
239-
await menuStore.update()
238+
await Promise.all([
239+
productStore.update(),
240+
menuStore.update(),
241+
])
240242
241243
actionToast.success(toastId, t('toast.variant-updated'))
242244
emit('success')
@@ -255,8 +257,10 @@ async function onDelete() {
255257
method: 'DELETE',
256258
})
257259
258-
await productStore.update()
259-
await menuStore.update()
260+
await Promise.all([
261+
productStore.update(),
262+
menuStore.update(),
263+
])
260264
261265
actionToast.success(toastId, t('toast.variant-deleted'))
262266
emit('success')

apps/web-app/app/components/form/UpdateUser.vue

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
/>
3232
</UFormField>
3333

34+
<UFormField :label="$t('common.phone')" name="phone">
35+
<UInput
36+
v-model="state.phone"
37+
size="xl"
38+
class="w-full items-center justify-center"
39+
/>
40+
</UFormField>
41+
3442
<UFormField :label="$t('common.caption')" name="caption">
3543
<UInput
3644
v-model="state.caption"
@@ -39,6 +47,16 @@
3947
/>
4048
</UFormField>
4149

50+
<UFormField :label="$t('common.gender.title')" name="gender">
51+
<USelect
52+
v-model="state.gender"
53+
:items="getLocalizedGenderForSelect()"
54+
:placeholder="$t('common.select')"
55+
size="xl"
56+
class="w-full"
57+
/>
58+
</UFormField>
59+
4260
<UButton
4361
type="submit"
4462
variant="solid"
@@ -56,31 +74,40 @@ import type { FormSubmitEvent } from '@nuxt/ui'
5674
import type { UpdateUser } from '~~/shared/services/user'
5775
import { updateUserSchema } from '~~/shared/services/user'
5876
77+
const { userId } = defineProps<{ userId: string }>()
78+
5979
const emit = defineEmits(['success', 'submitted'])
6080
6181
const { t } = useI18n()
6282
const actionToast = useActionToast()
6383
84+
const partnerStore = usePartnerStore()
6485
const userStore = useUserStore()
86+
const user = userStore.find(userId)
6587
6688
const state = ref<Partial<UpdateUser>>({
67-
name: userStore.name,
68-
surname: userStore.surname,
69-
email: userStore.email ?? undefined,
70-
caption: userStore.caption,
89+
name: user?.name,
90+
surname: user?.surname,
91+
email: user?.email ?? undefined,
92+
phone: user?.phone ?? undefined,
93+
caption: user?.caption,
94+
gender: user?.gender,
7195
})
7296
7397
async function onSubmit(event: FormSubmitEvent<UpdateUser>) {
7498
const toastId = actionToast.start()
7599
emit('submitted')
76100
77101
try {
78-
await $fetch(`/api/user/id/${userStore.id}`, {
102+
await $fetch(`/api/user/id/${user?.id}`, {
79103
method: 'PATCH',
80104
body: event.data,
81105
})
82106
83-
await userStore.update()
107+
await Promise.all([
108+
userStore.update(),
109+
partnerStore.update(),
110+
])
84111
85112
actionToast.success(toastId, t('toast.user-updated'))
86113
emit('success')

apps/web-app/app/components/modal/UpdateUser.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<UModal :title="$t('app.update.user.title')">
33
<template #body>
44
<FormUpdateUser
5+
:user-id="userId ?? ''"
56
@submitted="overlay.closeAll"
67
@success="overlay.closeAll"
78
/>
@@ -10,5 +11,9 @@
1011
</template>
1112

1213
<script setup lang="ts">
14+
defineProps<{
15+
userId?: string
16+
}>()
17+
1318
const overlay = useOverlay()
1419
</script>

apps/web-app/app/pages/partner/[id]/index.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
</div>
3636
</UCard>
3737

38-
<UserCard v-if="partnerUser" :user="partnerUser" />
38+
<UserCard
39+
v-if="partnerUser"
40+
:user="partnerUser"
41+
@click="modalUpdateUser.open({ userId: partnerUser.id })"
42+
/>
3943

4044
<div class="lg:col-span-2">
4145
<PartnerLegalEntityCard :partner-id="partner?.id ?? ''" :entity="partner?.legalEntity" />
@@ -53,16 +57,21 @@
5357
</template>
5458

5559
<script setup lang="ts">
60+
import { ModalUpdateUser } from '#components'
61+
5662
const { t } = useI18n()
5763
const { params } = useRoute('partner-id')
5864
5965
const partnerStore = usePartnerStore()
6066
const partner = computed(() => partnerStore.partners.find((partner) => partner.id === params.id))
6167
62-
const partnerUser = computed(() => partner.value?.users.filter((user) => user.type === 'partner')[0])
68+
const partnerUser = computed(() => partner.value?.users.find((user) => user.type === 'partner'))
6369
6470
const activeAgreements = computed(() => partner.value?.legalEntity?.agreements.filter((agreement) => agreement.isActive))
6571
72+
const overlay = useOverlay()
73+
const modalUpdateUser = overlay.create(ModalUpdateUser)
74+
6675
useHead({
6776
title: t('common.partner'),
6877
})

0 commit comments

Comments
 (0)