Simplify manager cabinet flows

This commit is contained in:
Ruslan Bakiev
2026-04-03 19:23:08 +07:00
parent 1c19b06451
commit 1c2070b8d8
14 changed files with 1073 additions and 680 deletions

127
app/pages/clients/[id].vue Normal file
View File

@@ -0,0 +1,127 @@
<script setup lang="ts">
import { useMutation, useQuery } from '@vue/apollo-composable';
import {
RegistrationRequestsDocument,
ReviewRegistrationRequestDocument,
} from '~/composables/graphql/generated';
definePageMeta({
middleware: ['manager-only'],
});
const route = useRoute();
const requestId = computed(() => String(route.params.id || ''));
const clientQuery = useQuery(RegistrationRequestsDocument, {
status: null,
});
const reviewMutation = useMutation(ReviewRegistrationRequestDocument);
const currentClient = computed(() =>
(clientQuery.result.value?.registrationRequests ?? []).find((item) => item.id === requestId.value),
);
async function approveRequest() {
if (!currentClient.value) {
return;
}
await reviewMutation.mutate({
input: {
requestId: currentClient.value.id,
decision: 'APPROVE',
},
});
await clientQuery.refetch({ status: null });
}
async function rejectRequest() {
if (!currentClient.value) {
return;
}
await reviewMutation.mutate({
input: {
requestId: currentClient.value.id,
decision: 'REJECT',
rejectionReason: 'Не хватает данных для регистрации.',
},
});
await clientQuery.refetch({ status: null });
}
</script>
<template>
<section class="space-y-6">
<NuxtLink to="/clients" class="text-sm font-semibold text-[#0d854a]"> Назад к клиентам</NuxtLink>
<div v-if="clientQuery.loading.value" class="manager-empty-state">
Загружаем карточку клиента...
</div>
<div v-else-if="!currentClient" class="manager-empty-state">
Карточка клиента не найдена.
</div>
<template v-else>
<div class="flex flex-col gap-3 md:flex-row md:items-start md:justify-between">
<div class="manager-hero">
<p class="manager-eyebrow">Клиент</p>
<h1 class="manager-title">{{ currentClient.companyName }}</h1>
<p class="manager-copy">Контакт: {{ currentClient.contactName }} · {{ currentClient.email }}</p>
</div>
<div v-if="currentClient.status === 'PENDING'" class="flex flex-wrap gap-2">
<button class="btn btn-success border-0" @click="approveRequest">Одобрить</button>
<button class="btn btn-error border-0" @click="rejectRequest">Отклонить</button>
</div>
</div>
<div class="grid gap-4 lg:grid-cols-3">
<div class="manager-stat-card">
<p class="manager-stat-label">Статус</p>
<p class="manager-stat-value text-lg">
{{ currentClient.status === 'APPROVED' ? 'Активен' : currentClient.status === 'REJECTED' ? 'Отклонен' : 'На проверке' }}
</p>
</div>
<div class="manager-stat-card">
<p class="manager-stat-label">Дата заявки</p>
<p class="manager-stat-value text-lg">{{ new Date(currentClient.createdAt).toLocaleDateString() }}</p>
</div>
<div class="manager-stat-card">
<p class="manager-stat-label">ИНН</p>
<p class="manager-stat-value text-lg">{{ currentClient.inn || 'Не указан' }}</p>
</div>
</div>
<div class="surface-card rounded-3xl p-5">
<h2 class="text-xl font-bold text-[#123824]">Информация</h2>
<div class="mt-4 grid gap-3 md:grid-cols-2">
<div class="manager-mini-card">
<p class="text-xs font-semibold uppercase tracking-[0.12em] text-[#5c7b69]">Компания</p>
<p class="mt-2 text-sm text-[#123824]">{{ currentClient.companyName }}</p>
</div>
<div class="manager-mini-card">
<p class="text-xs font-semibold uppercase tracking-[0.12em] text-[#5c7b69]">Контакт</p>
<p class="mt-2 text-sm text-[#123824]">{{ currentClient.contactName }}</p>
</div>
<div class="manager-mini-card">
<p class="text-xs font-semibold uppercase tracking-[0.12em] text-[#5c7b69]">Email</p>
<p class="mt-2 text-sm text-[#123824]">{{ currentClient.email }}</p>
</div>
<div class="manager-mini-card">
<p class="text-xs font-semibold uppercase tracking-[0.12em] text-[#5c7b69]">Обновлено</p>
<p class="mt-2 text-sm text-[#123824]">{{ new Date(currentClient.updatedAt).toLocaleString() }}</p>
</div>
</div>
</div>
<div v-if="currentClient.rejectionReason" class="surface-card rounded-3xl p-5">
<h2 class="text-xl font-bold text-[#123824]">Причина отказа</h2>
<p class="mt-3 text-sm text-[#a34a34]">{{ currentClient.rejectionReason }}</p>
</div>
</template>
</section>
</template>

127
app/pages/clients/index.vue Normal file
View File

@@ -0,0 +1,127 @@
<script setup lang="ts">
import { useQuery } from '@vue/apollo-composable';
import {
RegistrationRequestsDocument,
type RegistrationRequestsQuery,
} from '~/composables/graphql/generated';
definePageMeta({
middleware: ['manager-only'],
});
type ClientCard = RegistrationRequestsQuery['registrationRequests'][number];
const clientsQuery = useQuery(RegistrationRequestsDocument, {
status: null,
});
const search = ref('');
function statusLabel(status: ClientCard['status']) {
if (status === 'APPROVED') {
return 'Активен';
}
if (status === 'REJECTED') {
return 'Отклонен';
}
return 'На проверке';
}
function statusClass(status: ClientCard['status']) {
if (status === 'APPROVED') {
return 'badge badge-success border-0';
}
if (status === 'REJECTED') {
return 'badge badge-error border-0';
}
return 'badge badge-warning border-0';
}
const filteredClients = computed(() => {
const items = clientsQuery.result.value?.registrationRequests ?? [];
const query = search.value.trim().toLowerCase();
return items.filter((item) => {
if (!query) {
return true;
}
return [
item.companyName,
item.contactName,
item.email,
item.inn || '',
]
.join(' ')
.toLowerCase()
.includes(query);
});
});
</script>
<template>
<section class="space-y-6">
<div class="flex flex-col gap-3 md:flex-row md:items-end md:justify-between">
<div class="manager-hero">
<p class="manager-eyebrow">Клиенты</p>
<h1 class="manager-title">Карточки клиентов без лишней нагрузки</h1>
<p class="manager-copy">Список заявок и клиентов, с которыми менеджер уже работает.</p>
</div>
<NuxtLink to="/clients/invite" class="btn btn-primary border-0">
Пригласить клиента
</NuxtLink>
</div>
<div class="surface-card rounded-3xl p-4 md:p-5">
<div class="grid gap-3 md:grid-cols-[1fr_auto] md:items-end">
<label class="form-control">
<span class="label-text">Search</span>
<input
v-model="search"
type="text"
class="input manager-field w-full"
placeholder="Компания, контакт, email или ИНН"
>
</label>
<div class="manager-mini-card text-sm text-[#123824] md:w-56">
Всего карточек: <span class="font-semibold">{{ filteredClients.length }}</span>
</div>
</div>
</div>
<div v-if="clientsQuery.loading.value" class="manager-empty-state">
Загружаем клиентов...
</div>
<div v-else-if="filteredClients.length === 0" class="manager-empty-state">
По текущему запросу карточки клиентов не найдены.
</div>
<div v-else class="grid gap-4 lg:grid-cols-2 xl:grid-cols-3">
<NuxtLink
v-for="client in filteredClients"
:key="client.id"
:to="`/clients/${client.id}`"
class="surface-card rounded-3xl p-5"
>
<div class="flex items-start justify-between gap-3">
<div class="space-y-1">
<h2 class="text-lg font-bold text-[#123824]">{{ client.companyName }}</h2>
<p class="text-sm text-[#466653]">{{ client.contactName }}</p>
</div>
<span :class="statusClass(client.status)">{{ statusLabel(client.status) }}</span>
</div>
<div class="mt-4 space-y-2 text-sm text-[#355947]">
<p>{{ client.email }}</p>
<p v-if="client.inn">ИНН: {{ client.inn }}</p>
<p>{{ new Date(client.createdAt).toLocaleDateString() }}</p>
</div>
<p v-if="client.rejectionReason" class="mt-4 text-sm text-[#a34a34]">
{{ client.rejectionReason }}
</p>
</NuxtLink>
</div>
</section>
</template>

View File

@@ -0,0 +1,78 @@
<script setup lang="ts">
import { useMutation } from '@vue/apollo-composable';
import { CreateInvitationDocument } from '~/composables/graphql/generated';
definePageMeta({
middleware: ['manager-only'],
});
const email = ref('');
const companyName = ref('');
const invitationResult = ref<null | { token: string; expiresAt: string }>(null);
const createInvitationMutation = useMutation(CreateInvitationDocument);
async function createInvitation() {
invitationResult.value = null;
const response = await createInvitationMutation.mutate({
input: {
email: email.value,
companyName: companyName.value,
expiresInDays: 7,
},
});
const invitation = response?.data?.createInvitation;
if (!invitation) {
return;
}
invitationResult.value = {
token: invitation.token,
expiresAt: invitation.expiresAt,
};
}
</script>
<template>
<section class="space-y-6 max-w-3xl">
<NuxtLink to="/clients" class="text-sm font-semibold text-[#0d854a]"> Назад к клиентам</NuxtLink>
<div class="manager-hero">
<p class="manager-eyebrow">Приглашение</p>
<h1 class="manager-title">Пригласить нового клиента</h1>
<p class="manager-copy">Форма вынесена отдельно, чтобы список клиентов оставался чистым и спокойным.</p>
</div>
<div class="surface-card rounded-3xl p-5">
<div class="grid gap-3">
<label class="form-control">
<span class="label-text">Email</span>
<input v-model="email" type="email" class="input manager-field w-full" placeholder="client@example.com">
</label>
<label class="form-control">
<span class="label-text">Компания</span>
<input v-model="companyName" type="text" class="input manager-field w-full" placeholder="Название компании">
</label>
<div>
<button class="btn btn-primary border-0" @click="createInvitation">Создать инвайт</button>
</div>
</div>
</div>
<div v-if="invitationResult" class="surface-card rounded-3xl p-5">
<h2 class="text-xl font-bold text-[#123824]">Инвайт создан</h2>
<div class="mt-4 space-y-3 text-sm text-[#123824]">
<div class="manager-mini-card">
Токен: <span class="font-semibold">{{ invitationResult.token }}</span>
</div>
<div class="manager-mini-card">
Действует до: <span class="font-semibold">{{ new Date(invitationResult.expiresAt).toLocaleString() }}</span>
</div>
</div>
</div>
</section>
</template>