Skip to content

Commit 4a6102d

Browse files
authored
feat: telegram updated, invoices on partner page (#238)
* feat: telegram updated, invoices on partner page * chore: type * chore: logic
1 parent 7a9c357 commit 4a6102d

File tree

36 files changed

+1033
-869
lines changed

36 files changed

+1033
-869
lines changed

apps/atrium-telegram/app/app.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<script setup lang="ts">
1818
import * as locales from '@nuxt/ui/locale'
19-
import { retrieveLaunchParams, themeParams } from '@telegram-apps/sdk-vue'
19+
import { retrieveLaunchParams, themeParams } from '@tma.js/sdk-vue'
2020
2121
const { locale } = useI18n()
2222
@@ -35,11 +35,14 @@ useHead({
3535
})
3636
3737
// App
38-
const isDev = (retrieveLaunchParams().startParam === 'debug' || import.meta.env.DEV) ?? false
38+
const launchParams = retrieveLaunchParams()
39+
const { tgWebAppPlatform: platform } = launchParams
40+
const debug = (launchParams.tgWebAppStartParam || '').includes('debug') || import.meta.env.DEV
41+
3942
await init({
40-
debug: false,
41-
eruda: isDev,
42-
mockForMacOS: false,
43+
debug,
44+
eruda: debug && ['ios', 'android'].includes(platform),
45+
mockForMacOS: platform === 'macos',
4346
})
4447
4548
// Telegram

apps/atrium-telegram/app/components/PageContainer.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
</template>
1616

1717
<script setup lang="ts">
18-
import { hideBackButton } from '@telegram-apps/sdk-vue'
18+
import { backButton } from '@tma.js/sdk-vue'
1919
2020
const { back = true, class: className } = defineProps<{ back?: boolean, class?: string }>()
2121
22-
onMounted(() => !back && hideBackButton())
22+
onMounted(() => !back && backButton.hide())
2323
</script>

apps/atrium-telegram/app/components/PartnerCard.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
</div>
5656

5757
<div class="min-h-20 h-full px-4 pb-4 flex flex-col gap-2.5">
58+
<UBadge
59+
:color="partner.balance >= 0 ? 'neutral' : 'error'"
60+
variant="soft"
61+
size="md"
62+
class="rounded-lg justify-center font-semibold"
63+
:label="`Баланс ${new Intl.NumberFormat().format(partner.balance)} ₽`"
64+
/>
65+
5866
<h3 class="text-sm/4 font-bold">
5967
{{ partner.legalEntity?.name }}
6068
</h3>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<template>
2+
<ActiveCard>
3+
<Section>
4+
<div class="flex flex-row gap-2 items-center">
5+
<UIcon name="i-lucide-banknote-arrow-up" class="size-8 text-primary" />
6+
7+
<div v-if="invoice.status === 'paid'" class="flex flex-row items-center gap-1.5 text-primary">
8+
<UIcon
9+
name="i-lucide-bookmark-check"
10+
class="size-8"
11+
/>
12+
<p class="max-w-22 text-sm/4 font-bold">
13+
Оплачено
14+
</p>
15+
</div>
16+
<div v-else class="flex flex-row items-center gap-1.5 text-muted">
17+
<UIcon
18+
name="i-lucide-loader-circle"
19+
class="size-8 motion-preset-spin motion-duration-4000"
20+
/>
21+
</div>
22+
</div>
23+
24+
<div class="flex flex-col gap-1">
25+
<h3 class="text-xl/5 font-bold">
26+
{{ new Intl.NumberFormat().format(invoice.total) }} ₽
27+
</h3>
28+
29+
<div class="text-base/5 font-bold">
30+
{{ getInfoByType(invoice.type) }}
31+
</div>
32+
</div>
33+
34+
<div class="flex flex-col gap-1">
35+
<div class="text-base/5">
36+
{{ invoice.title }}
37+
</div>
38+
39+
<div class="text-base/5 text-muted">
40+
{{ invoice.description }}
41+
</div>
42+
</div>
43+
44+
<div class="text-sm/4 text-muted">
45+
Создан {{ format(new Date(invoice.createdAt), 'd MMMM в HH:mm', { locale: ru }) }}
46+
</div>
47+
</Section>
48+
</ActiveCard>
49+
</template>
50+
51+
<script setup lang="ts">
52+
import type { Invoice } from '@roll-stack/database'
53+
import { format } from 'date-fns'
54+
import { ru } from 'date-fns/locale/ru'
55+
56+
defineProps<{
57+
invoice: Invoice
58+
}>()
59+
60+
function getInfoByType(type: Invoice['type']) {
61+
switch (type) {
62+
case 'replenishment':
63+
return 'Пополнение'
64+
case 'royalties':
65+
return 'Роялти'
66+
case 'lump_sum_fee':
67+
return 'Паушальный взнос'
68+
case 'marketing_fee':
69+
return 'Маркетинговый сбор'
70+
case 'rospatent_fee':
71+
return 'Роспатент'
72+
case 'other':
73+
return 'Другое'
74+
default:
75+
return 'Другое'
76+
}
77+
}
78+
</script>

apps/atrium-telegram/app/components/StaffBlock.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</template>
4040

4141
<script setup lang="ts">
42-
import { openTelegramLink, showPopup } from '@telegram-apps/sdk-vue'
42+
import { openTelegramLink, popup } from '@tma.js/sdk-vue'
4343
4444
const { vibrate } = useFeedback()
4545
@@ -80,8 +80,8 @@ async function handleClick(userId: string) {
8080
return
8181
}
8282
83-
if (showPopup.isAvailable()) {
84-
const buttonId = await showPopup({
83+
if (popup.show.isAvailable()) {
84+
const buttonId = await popup.show({
8585
title: `${user.name} ${user.surname}`,
8686
message: user.caption,
8787
buttons: [

apps/atrium-telegram/app/composables/useBackButton.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { backButton } from '@telegram-apps/sdk-vue'
1+
import { backButton } from '@tma.js/sdk-vue'
22

33
function _useBackButton() {
44
let offClick: () => void = () => {}

apps/atrium-telegram/app/composables/useFeedback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hapticFeedback } from '@telegram-apps/sdk-vue'
1+
import { hapticFeedback } from '@tma.js/sdk-vue'
22

33
function _useFeedback() {
44
function vibrate(type: 'light' | 'success' | 'error' = 'light') {

apps/atrium-telegram/app/composables/useGyroscope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { EventListener } from '@telegram-apps/sdk-vue'
2-
import { off, on } from '@telegram-apps/sdk-vue'
1+
import type { EventListener } from '@tma.js/sdk-vue'
2+
import { off, on } from '@tma.js/sdk-vue'
33

44
function _useGyroscope() {
55
const x = ref(0)

apps/atrium-telegram/app/pages/partner/[partnerId]/index.vue

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<div class="flex flex-row gap-2 items-start text-base/5">
1919
<UIcon name="i-lucide-map" class="shrink-0 size-5" /> {{ partner?.city }}
2020
</div>
21+
22+
<div class="flex flex-row gap-2 items-start text-base/5">
23+
<UIcon name="i-lucide-banknote" class="shrink-0 size-5" /> Баланс {{ new Intl.NumberFormat().format(partner?.balance ?? 0) }} ₽
24+
</div>
2125
</div>
2226
</Section>
2327

@@ -85,6 +89,22 @@
8589
</div>
8690
</div>
8791
</div>
92+
93+
<div v-if="invoices?.length" class="flex flex-col gap-2.5">
94+
<div class="flex flex-row justify-between items-center">
95+
<SectionTitle title="Счета" />
96+
</div>
97+
98+
<div class="flex flex-col gap-4">
99+
<div
100+
v-for="invoice in invoices"
101+
:key="invoice.id"
102+
class="motion-preset-slide-left"
103+
>
104+
<PartnerInvoiceCard :invoice="invoice" />
105+
</div>
106+
</div>
107+
</div>
88108
</PageContainer>
89109
</template>
90110

@@ -99,4 +119,6 @@ const { params } = useRoute('partner-partnerId')
99119
const partnerStore = usePartnerStore()
100120
const partner = computed(() => partnerStore.partners.find((partner) => partner.id === params.partnerId))
101121
const partnerUser = computed(() => partner.value?.users.find((user) => user.type === 'partner'))
122+
123+
const invoices = computed(() => partner.value?.invoices.toSorted((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()))
102124
</script>

apps/atrium-telegram/app/pages/partner/index.vue

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22
<PageContainer>
33
<div class="flex flex-row gap-2.5 items-center">
44
<SectionTitle title="Партнеры" />
5-
<CounterBadge :value="partnerStore.partners.length" />
5+
<CounterBadge :value="filteredPartners.length" />
6+
</div>
7+
8+
<div class="grid grid-cols-1 gap-2.5 items-center">
9+
<UInput
10+
v-model="search"
11+
size="xl"
12+
trailing-icon="i-lucide-search"
13+
placeholder="Найти..."
14+
:ui="{
15+
base: 'rounded-lg text-lg/5 font-bold ring-0',
16+
}"
17+
class="motion-preset-slide-down"
18+
/>
619
</div>
720

821
<div class="grid grid-cols-2 gap-2.5 items-start">
922
<NuxtLink
10-
v-for="partner in partnerStore.partners"
23+
v-for="partner in filteredPartners"
1124
:key="partner.id"
1225
:to="`/partner/${partner.id}`"
1326
class="h-full motion-preset-slide-left"
@@ -20,4 +33,19 @@
2033

2134
<script setup lang="ts">
2235
const partnerStore = usePartnerStore()
36+
37+
const search = ref('')
38+
39+
const filteredPartners = computed(() => {
40+
if (!search.value) {
41+
// Show all
42+
return partnerStore.partners
43+
}
44+
45+
const filteredBySearch = partnerStore.partners.filter((partner) => {
46+
return partner.legalEntity?.name?.toLowerCase().includes(search.value.toLowerCase()) ?? false
47+
})
48+
49+
return filteredBySearch
50+
})
2351
</script>

0 commit comments

Comments
 (0)