Skip to content

Commit

Permalink
feat!: address and paymentMethod (#236)
Browse files Browse the repository at this point in the history
* fix: limit on increment

* feat: country code

* feat!: address and paymentMethod
  • Loading branch information
hmbanan666 authored Oct 9, 2024
1 parent 105122a commit 25b0b4e
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 122 deletions.
179 changes: 115 additions & 64 deletions apps/food/app/components/Checkout/DeliveryForm.vue
Original file line number Diff line number Diff line change
@@ -1,96 +1,147 @@
<template>
<div class="mb-6 px-4 py-5 md:px-6 md:py-6 bg-white rounded-3xl">
<!-- <h2 class="mb-2 text-xl md:text-2xl font-medium">
Условия доставки
</h2> -->

<div class="mb-6 px-4 py-5 md:px-6 md:py-6 bg-white rounded-3xl space-y-5">
<CartDeliveryMethodSwitch />

<div class="w-full mt-4">
<div class="w-full">
<h3 class="mb-2 text-lg md:text-xl font-medium">
Контакты
</h3>

<div class="grid grid-cols-1 md:grid-cols-2 md:gap-2">
<input
type="text"
<UiInput
v-model="phoneNumber"
type="tel"
name="phone"
value=""
placeholder="Ваш телефон"
class="px-4 py-3 mb-2 w-full border border-neutral-200 rounded-2xl outline-2 outline-offset-1 outline-neutral-500 placeholder:text-neutral-400 data-[valid=true]:outline-teal-400"
data-valid="{isValidPhone}"
>
maxlength="17"
:class="{ '!outline-emerald-500': isValidPhone }"
@change="formatPhone"
/>

<input
type="text"
<UiInput
name="name"
placeholder="Ваше имя"
class="px-4 py-3 mb-2 w-full border border-neutral-200 rounded-2xl"
>
/>
</div>
</div>

<div class="w-full mt-4">
<div v-if="checkout?.deliveryMethod === 'DELIVERY'" class="w-full">
<h3 class="mb-2 text-lg md:text-xl font-medium">
Укажите свой адрес
</h3>
<input
type="text"
<UiLabel for="street">
Улица и дом
</UiLabel>
<UiInput
id="street"
name="street"
placeholder="Улица и дом"
class="px-4 py-3 mb-2 w-full border border-neutral-200 rounded-2xl"
>

<div class="mb-2 grid grid-cols-2 md:grid-cols-4 gap-2">
<input
type="text"
name="apartment"
placeholder="Кв./офис"
class="px-4 py-3 border border-neutral-200 rounded-2xl"
>

<input
type="text"
name="doorphone"
placeholder="Домофон"
class="px-4 py-3 border border-neutral-200 rounded-2xl"
>

<input
type="text"
name="entrance"
placeholder="Подъезд"
class="px-4 py-3 border border-neutral-200 rounded-2xl"
>

<input
type="text"
name="floor"
placeholder="Этаж"
class="px-4 py-3 border border-neutral-200 rounded-2xl"
>
/>

<div class="mt-2 mb-2 grid grid-cols-2 md:grid-cols-4 gap-2">
<div>
<UiLabel for="apartment">
Кв./офис
</UiLabel>
<UiInput
id="apartment"
name="apartment"
/>
</div>

<div>
<UiLabel for="doorphone">
Домофон
</UiLabel>
<UiInput
id="doorphone"
name="doorphone"
/>
</div>

<div>
<UiLabel for="entrance">
Подъезд
</UiLabel>
<UiInput
id="entrance"
name="entrance"
/>
</div>

<div>
<UiLabel for="floor">
Этаж
</UiLabel>
<UiInput
id="floor"
name="floor"
/>
</div>
</div>

<div>
<UiLabel for="address-note">
Комментарий
</UiLabel>
<UiTextarea
id="address-note"
name="address-note"
placeholder="Чтобы курьер быстрее вас нашел, укажите дополнительную информацию"
/>
</div>
</div>
<div v-if="checkout?.deliveryMethod === 'WAREHOUSE'">
<h3 class="mb-2 text-lg md:text-xl font-medium">
Выберите адрес
</h3>

<input
type="text"
name="comment"
placeholder="Комментарий"
class="px-4 py-3 mb-2 w-full border border-neutral-200 rounded-2xl"
>
<UiTextarea>123</UiTextarea>
<div class="grid grid-cols-1 md:grid-cols-1 gap-2">
<UiButton v-for="warehouse in channel?.warehouses" :key="warehouse.id" variant="secondary" class="w-full min-h-14 flex flex-row flex-wrap gap-2 justify-start items-center" @click="selectedWarehouseId = warehouse.id">
<Icon :name="warehouse.id === selectedWarehouseId ? icons.bookmarkCheck : icons.bookmark" class="w-6 h-6 text-neutral-300" :class="{ 'w-7 h-7 !text-emerald-500': warehouse.id === selectedWarehouseId }" />
<p class="font-medium text-lg leading-tight break-all">
{{ warehouse.address }}
</p>
</UiButton>
</div>
</div>
<h2 class="mt-4 mb-2 text-xl md:text-2xl font-medium">
Время доставки
</h2>
<div class="w-full">
<h2 class="mb-2 text-xl md:text-2xl font-medium">
Время
</h2>

<div class="flex flex-row gap-2 items-center">
<Icon :name="icons.clock" />
Сейчас: 45-60 мин
<div class="flex flex-row gap-2 items-center">
<Icon :name="icons.clock" />
Ближайшее: 45-60 мин
</div>
</div>
</div>
</template>

<script setup lang="ts">
const { icons } = useAppConfig()
const { channel } = await useChannel()
const { checkout } = useCheckout()
const selectedWarehouseId = ref('')
const phoneNumber = ref('')
const countryCode = computed(() => channel.value?.countryCode as CountryCode)
const isValidPhone = ref(false)
watch(
() => phoneNumber.value,
() => {
if (phoneNumber.value.length > 17) {
return
}
getPhoneNumberFormatter(countryCode.value).input(phoneNumber.value)
isValidPhone.value = checkPhoneNumberValidity(phoneNumber.value, countryCode.value)
},
)
function formatPhone() {
getPhoneNumberFormatter(countryCode.value).input(phoneNumber.value)
phoneNumber.value = formatPhoneNumber(phoneNumber.value, countryCode.value)
}
</script>
2 changes: 1 addition & 1 deletion apps/food/app/components/ui/input/Input.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<input v-model="modelValue" :class="cn('flex h-12 w-full rounded-2xl border border-neutral-200 bg-white px-4 py-2 ring-offset-white file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-neutral-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-950 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-neutral-800 dark:bg-neutral-950 dark:ring-offset-neutral-950 dark:placeholder:text-neutral-400 dark:focus-visible:ring-neutral-300', props.class)">
<input v-model="modelValue" :class="cn('flex h-12 w-full rounded-2xl border border-neutral-200 bg-white px-4 py-2 ring-offset-white file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-neutral-400 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-950 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-neutral-800 dark:bg-neutral-950 dark:ring-offset-neutral-950 dark:placeholder:text-neutral-400 dark:focus-visible:ring-neutral-300', props.class)">
</template>

<script setup lang="ts">
Expand Down
2 changes: 1 addition & 1 deletion apps/food/app/components/ui/textarea/Textarea.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<textarea v-model="modelValue" :class="cn('flex min-h-20 w-full rounded-2xl border border-neutral-200 bg-white leading-tight px-4 py-3 ring-offset-white placeholder:text-neutral-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-950 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-neutral-800 dark:bg-neutral-950 dark:ring-offset-neutral-950 dark:placeholder:text-neutral-400 dark:focus-visible:ring-neutral-300', props.class)" />
<textarea v-model="modelValue" :class="cn('flex min-h-20 w-full rounded-2xl border border-neutral-200 bg-white leading-tight px-4 py-3 ring-offset-white placeholder:text-neutral-400 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-950 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-neutral-800 dark:bg-neutral-950 dark:ring-offset-neutral-950 dark:placeholder:text-neutral-400 dark:focus-visible:ring-neutral-300', props.class)" />
</template>

<script setup lang="ts">
Expand Down
78 changes: 57 additions & 21 deletions apps/food/app/pages/checkout/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,60 @@
</h2>

<CheckoutLine v-for="line in checkout?.lines" :key="line.id" :line-id="line.id" />
<div class="mt-4">
<UiLabel for="note">
Комментарий для кухни
</UiLabel>
<UiTextarea
id="note"
name="note"
placeholder="Пожелания к заказу"
/>
</div>
</div>
</div>
<div class="col-span-full md:col-span-5 h-fit sticky top-20">
<div class="mb-6 px-4 py-5 md:px-6 md:py-6 bg-white rounded-3xl">
<h3 class="mb-16 text-lg md:text-xl font-medium">
Метод оплаты
</h3>
<div class="mb-6 px-4 py-5 md:px-6 md:py-6 bg-white rounded-3xl space-y-5">
<div>
<h3 class="mb-2 text-lg md:text-xl font-medium">
Метод оплаты
</h3>

<h3 class="mb-2 text-lg md:text-xl font-medium">
Итого
</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
<UiButton v-for="payment in availablePayments" :key="payment.type" variant="secondary" class="w-full min-h-14 flex flex-row flex-wrap gap-2 justify-start items-center" @click="selectedPayment = payment.type">
<Icon :name="payment.type === selectedPayment ? icons.bookmarkCheck : icons.bookmark" class="w-6 h-6 text-neutral-300" :class="{ 'w-7 h-7 !text-emerald-500': payment.type === selectedPayment }" />
<p class="font-medium text-lg leading-tight break-all">
{{ payment.type }}
</p>
</UiButton>
</div>
</div>

<div class="mb-4">
<div class="mb-2 flex flex-row justify-between text-lg">
<div>Стоимость товаров</div>
<div class="tracking-tight">
{{ checkout?.totalPrice }} <span class="text-sm">{{ getCurrencySign(channel?.currencyCode) }}</span>
<div>
<h3 class="mb-2 text-lg md:text-xl font-medium">
Итого
</h3>

<div>
<div class="mb-2 flex flex-row justify-between text-lg">
<div>Стоимость товаров</div>
<div class="tracking-tight">
{{ checkout?.totalPrice }} <span class="text-sm">{{ getCurrencySign(channel?.currencyCode) }}</span>
</div>
</div>
</div>
<div class="mb-2 flex flex-row justify-between text-lg">
<div>Стоимость доставки</div>
<div class="tracking-tight">
{{ checkout?.shippingPrice }} <span class="text-sm">{{ getCurrencySign(channel?.currencyCode) }}</span>
<div class="mb-2 flex flex-row justify-between text-lg">
<div>Стоимость доставки</div>
<div class="tracking-tight">
{{ checkout?.shippingPrice }} <span class="text-sm">{{ getCurrencySign(channel?.currencyCode) }}</span>
</div>
</div>
</div>

<div class="mt-4 mb-6">
<div class="text-base text-neutral-500">
Есть промо код?
<div class="mt-4">
<div class="text-base text-neutral-500">
Есть промо код?
</div>
</div>
</div>
</div>
Expand All @@ -68,6 +92,18 @@ definePageMeta({
layout: 'checkout',
})

const { icons } = useAppConfig()
const { channel } = await useChannel()
const { checkout } = useCheckout()

const selectedPayment = ref('')

const availablePayments = [
{
type: 'CASH',
},
{
type: 'CARD',
},
]
</script>
5 changes: 1 addition & 4 deletions apps/food/app/utils/phoneHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type {
CountryCode } from 'libphonenumber-js'
import {
AsYouType,
formatIncompletePhoneNumber,
Expand Down Expand Up @@ -33,7 +31,6 @@ export function formatPhoneNumber(value: string, countryCode: CountryCode) {
return value
}

export function checkPhoneNumberValidity(value: string,
countryCode: CountryCode) {
export function checkPhoneNumberValidity(value: string, countryCode: CountryCode) {
return isValidPhoneNumber(value, countryCode)
}
Loading

0 comments on commit 25b0b4e

Please sign in to comment.