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