Relax cart checks for managers

This commit is contained in:
Ruslan Bakiev
2026-04-04 08:52:30 +07:00
parent 60f8b863a2
commit e2fba1da4e

View File

@@ -1,6 +1,7 @@
<script setup lang="ts">
import { useMutation, useQuery } from '@vue/apollo-composable';
import {
MeDocument,
MyDeliveryAddressesDocument,
SubmitCalculationOrderDocument,
type MyDeliveryAddressesQuery,
@@ -11,6 +12,7 @@ import { useCounterpartyProfile } from '~/composables/useCounterpartyProfile';
type DeliveryAddressItem = MyDeliveryAddressesQuery['myDeliveryAddresses'][number];
const { isComplete: isCounterpartyComplete, loading: counterpartyLoading } = useCounterpartyProfile();
const meQuery = useQuery(MeDocument);
const submitMutation = useMutation(SubmitCalculationOrderDocument, { throws: 'never' });
const deliveryAddressesQuery = useQuery(MyDeliveryAddressesDocument);
@@ -30,6 +32,7 @@ const sending = ref(false);
const success = ref('');
const errorMessage = ref('');
const isManager = computed(() => meQuery.result.value?.me?.role === 'MANAGER');
const deliveryAddresses = computed<DeliveryAddressItem[]>(() => deliveryAddressesQuery.result.value?.myDeliveryAddresses ?? []);
const hasDeliveryAddresses = computed(() => deliveryAddresses.value.length > 0);
@@ -83,12 +86,12 @@ async function submitCart() {
success.value = '';
errorMessage.value = '';
if (!isCounterpartyComplete.value) {
if (!isManager.value && !isCounterpartyComplete.value) {
errorMessage.value = 'Сначала заполните карточку контрагента в профиле.';
return;
}
if (!selectedDeliveryAddressId.value) {
if (!isManager.value && !selectedDeliveryAddressId.value) {
errorMessage.value = 'Выберите адрес доставки в профиле.';
return;
}
@@ -111,7 +114,7 @@ async function submitCart() {
thickness: Number(item.parameters.thickness),
color: item.parameters.color,
},
deliveryAddressId: selectedDeliveryAddressId.value,
deliveryAddressId: selectedDeliveryAddressId.value || null,
},
});
@@ -138,7 +141,7 @@ async function submitCart() {
<div v-if="counterpartyLoading" class="alert surface-card">
Проверяем карточку контрагента...
</div>
<div v-else-if="!isCounterpartyComplete" class="alert alert-warning">
<div v-else-if="!isManager && !isCounterpartyComplete" class="alert alert-warning">
Для оформления заявки заполните карточку контрагента в
<NuxtLink to="/profile/counterparty" class="link link-hover font-semibold">профиле</NuxtLink>.
</div>
@@ -149,10 +152,13 @@ async function submitCart() {
<div v-if="deliveryAddressesQuery.loading.value" class="alert mt-3 surface-card">
Загружаем адреса...
</div>
<div v-else-if="!hasDeliveryAddresses" class="alert alert-warning mt-3">
<div v-else-if="!hasDeliveryAddresses && !isManager" class="alert alert-warning mt-3">
Адреса не добавлены.
<NuxtLink to="/profile/addresses" class="link link-hover font-semibold">Добавить адрес в профиле</NuxtLink>
</div>
<div v-else-if="!hasDeliveryAddresses" class="alert mt-3 surface-card">
Можно оформить заказ без адреса. Если нужно, адрес можно добавить позже в профиле.
</div>
<div v-else class="mt-3 space-y-2">
<label
v-for="address in deliveryAddresses"
@@ -227,7 +233,7 @@ async function submitCart() {
<button
class="btn w-full bg-[#139957] text-white hover:bg-[#0d854a]"
:disabled="sending || counterpartyLoading || !isCounterpartyComplete || !selectedDeliveryAddressId || cartItems.length === 0"
:disabled="sending || counterpartyLoading || (!isManager && !isCounterpartyComplete) || (!isManager && !selectedDeliveryAddressId) || cartItems.length === 0"
@click="submitCart"
>
{{ sending ? 'Отправляем…' : 'Оформить заявку' }}