Keep cart rules identical for all users
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { useMutation, useQuery } from '@vue/apollo-composable';
|
||||
import {
|
||||
MeDocument,
|
||||
MyDeliveryAddressesDocument,
|
||||
SubmitCalculationOrderDocument,
|
||||
type MyDeliveryAddressesQuery,
|
||||
@@ -12,7 +11,6 @@ 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);
|
||||
|
||||
@@ -32,7 +30,6 @@ 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);
|
||||
|
||||
@@ -86,12 +83,12 @@ async function submitCart() {
|
||||
success.value = '';
|
||||
errorMessage.value = '';
|
||||
|
||||
if (!isManager.value && !isCounterpartyComplete.value) {
|
||||
if (!isCounterpartyComplete.value) {
|
||||
errorMessage.value = 'Сначала заполните карточку контрагента в профиле.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isManager.value && !selectedDeliveryAddressId.value) {
|
||||
if (!selectedDeliveryAddressId.value) {
|
||||
errorMessage.value = 'Выберите адрес доставки в профиле.';
|
||||
return;
|
||||
}
|
||||
@@ -114,7 +111,7 @@ async function submitCart() {
|
||||
thickness: Number(item.parameters.thickness),
|
||||
color: item.parameters.color,
|
||||
},
|
||||
deliveryAddressId: selectedDeliveryAddressId.value || null,
|
||||
deliveryAddressId: selectedDeliveryAddressId.value,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -141,7 +138,7 @@ async function submitCart() {
|
||||
<div v-if="counterpartyLoading" class="alert surface-card">
|
||||
Проверяем карточку контрагента...
|
||||
</div>
|
||||
<div v-else-if="!isManager && !isCounterpartyComplete" class="alert alert-warning">
|
||||
<div v-else-if="!isCounterpartyComplete" class="alert alert-warning">
|
||||
Для оформления заявки заполните карточку контрагента в
|
||||
<NuxtLink to="/profile/counterparty" class="link link-hover font-semibold">профиле</NuxtLink>.
|
||||
</div>
|
||||
@@ -152,13 +149,10 @@ async function submitCart() {
|
||||
<div v-if="deliveryAddressesQuery.loading.value" class="alert mt-3 surface-card">
|
||||
Загружаем адреса...
|
||||
</div>
|
||||
<div v-else-if="!hasDeliveryAddresses && !isManager" class="alert alert-warning mt-3">
|
||||
<div v-else-if="!hasDeliveryAddresses" 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"
|
||||
@@ -233,7 +227,7 @@ async function submitCart() {
|
||||
|
||||
<button
|
||||
class="btn w-full bg-[#139957] text-white hover:bg-[#0d854a]"
|
||||
:disabled="sending || counterpartyLoading || (!isManager && !isCounterpartyComplete) || (!isManager && !selectedDeliveryAddressId) || cartItems.length === 0"
|
||||
:disabled="sending || counterpartyLoading || !isCounterpartyComplete || !selectedDeliveryAddressId || cartItems.length === 0"
|
||||
@click="submitCart"
|
||||
>
|
||||
{{ sending ? 'Отправляем…' : 'Оформить заявку' }}
|
||||
|
||||
Reference in New Issue
Block a user