Compare commits
65 Commits
hotfix/bot
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ecf72656b | ||
|
|
241effd3b8 | ||
|
|
64c9134cc2 | ||
|
|
19b53db5f3 | ||
|
|
a26c0eab8a | ||
|
|
3ac86cfeb0 | ||
|
|
d895433a65 | ||
|
|
3064887ecf | ||
|
|
02e9d5c529 | ||
|
|
f45140ef04 | ||
|
|
bdcd11d97e | ||
|
|
6a0d34d37b | ||
|
|
2df80c90f6 | ||
|
|
03145534a1 | ||
|
|
6a21f5911e | ||
|
|
b88ac07ba3 | ||
|
|
b517519e7e | ||
|
|
a1af00af69 | ||
|
|
311f6c183d | ||
|
|
67cf9a8e26 | ||
|
|
6080aadc93 | ||
|
|
ee4e70f43d | ||
|
|
4d40230864 | ||
|
|
92119baa5e | ||
|
|
1e9fd66e27 | ||
|
|
aa11ecfcec | ||
|
|
8e61fbbb40 | ||
|
|
d32a7dc54e | ||
|
|
0a43d63c2c | ||
|
|
01d8bb20d5 | ||
|
|
20b2b44572 | ||
|
|
7fe1b89f5b | ||
|
|
4a98ac5d3e | ||
|
|
f8d0b7619f | ||
|
|
0b64d8086c | ||
|
|
458a06a620 | ||
|
|
c7648e8bf9 | ||
|
|
9244eaec26 | ||
|
|
d109d50120 | ||
|
|
8aaae245a7 | ||
|
|
c4b76a4755 | ||
|
|
cb4763e32b | ||
|
|
2836153887 | ||
|
|
1c669f04dd | ||
|
|
047a9b1956 | ||
|
|
d9e67bf4ba | ||
|
|
80d29af1b4 | ||
|
|
d191be03e8 | ||
|
|
900cfe2cc2 | ||
|
|
1f168df095 | ||
|
|
3e0ac818f2 | ||
|
|
29ecc47822 | ||
|
|
86f0d87c31 | ||
|
|
a9fd9808ec | ||
|
|
31adf7e7b3 | ||
|
|
ec3c2869c1 | ||
|
|
24aabae434 | ||
|
|
81e0168e44 | ||
|
|
eb0ad25c3c | ||
|
|
7c7ddcf0d5 | ||
|
|
106fdc0da5 | ||
|
|
a669e1846e | ||
|
|
8092c7fecc | ||
|
|
363fce4499 | ||
|
|
3d0f74ef62 |
126
.github/workflows/deploy.yml
vendored
126
.github/workflows/deploy.yml
vendored
@ -1,9 +1,10 @@
|
||||
name: Build & Deploy Web & Bot
|
||||
name: Build & Deploy Web, Bot & Cache Proxy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
@ -12,11 +13,31 @@ jobs:
|
||||
outputs:
|
||||
web_tag: ${{ steps.vars.outputs.web_tag }}
|
||||
bot_tag: ${{ steps.vars.outputs.bot_tag }}
|
||||
cache_proxy_tag: ${{ steps.vars.outputs.cache_proxy_tag }}
|
||||
# Добавляем output-ы для отслеживания, какие проекты были собраны
|
||||
web_built: ${{ steps.filter.outputs.web }}
|
||||
bot_built: ${{ steps.filter.outputs.bot }}
|
||||
cache_proxy_built: ${{ steps.filter.outputs.cache_proxy }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Create fake .env file for build
|
||||
# --- НОВОЕ: Шаг 1: dorny/paths-filter для условной сборки ---
|
||||
- name: Filter changed paths
|
||||
uses: dorny/paths-filter@v2
|
||||
id: filter
|
||||
with:
|
||||
filters: |
|
||||
web:
|
||||
- 'apps/web/**'
|
||||
- 'packages/**'
|
||||
bot:
|
||||
- 'apps/bot/**'
|
||||
- 'packages/**'
|
||||
cache_proxy:
|
||||
- 'apps/cache-proxy/**'
|
||||
# -----------------------------------------------------------
|
||||
- name: Create .env file for build
|
||||
run: |
|
||||
echo "BOT_TOKEN=fake" > .env
|
||||
echo "LOGIN_GRAPHQL=fake" >> .env
|
||||
@ -26,32 +47,54 @@ jobs:
|
||||
echo "NEXTAUTH_SECRET=fakesecret" >> .env
|
||||
echo "BOT_URL=http://localhost:3000" >> .env
|
||||
echo "REDIS_PASSWORD=fake" >> .env
|
||||
echo "BOT_PROVIDER_TOKEN=fake" >> .env
|
||||
echo "SUPPORT_TELEGRAM_URL=${{ secrets.SUPPORT_TELEGRAM_URL }}" >> .env
|
||||
echo "URL_OFFER=${{ secrets.URL_OFFER }}" >> .env
|
||||
echo "URL_PRIVACY=${{ secrets.URL_PRIVACY }}" >> .env
|
||||
echo "URL_FAQ=${{ secrets.URL_FAQ }}" >> .env
|
||||
|
||||
- name: Set image tags
|
||||
id: vars
|
||||
run: |
|
||||
echo "web_tag=web-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
|
||||
echo "bot_tag=bot-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
|
||||
echo "cache_proxy_tag=cache-proxy-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Login to Docker Hub
|
||||
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
|
||||
|
||||
# --- ИЗМЕНЕНО: Условное выполнение Build/Push ---
|
||||
- name: Build web image
|
||||
if: steps.filter.outputs.web == 'true'
|
||||
run: |
|
||||
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-web:${{ steps.vars.outputs.web_tag }} -f ./apps/web/Dockerfile .
|
||||
|
||||
- name: Push web image to Docker Hub
|
||||
if: steps.filter.outputs.web == 'true'
|
||||
run: |
|
||||
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-web:${{ steps.vars.outputs.web_tag }}
|
||||
|
||||
- name: Build bot image
|
||||
if: steps.filter.outputs.bot == 'true'
|
||||
run: |
|
||||
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:${{ steps.vars.outputs.bot_tag }} -f ./apps/bot/Dockerfile .
|
||||
|
||||
- name: Push bot image to Docker Hub
|
||||
if: steps.filter.outputs.bot == 'true'
|
||||
run: |
|
||||
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:${{ steps.vars.outputs.bot_tag }}
|
||||
|
||||
- name: Build cache-proxy image
|
||||
if: steps.filter.outputs.cache_proxy == 'true'
|
||||
run: |
|
||||
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-cache-proxy:${{ steps.vars.outputs.cache_proxy_tag }} -f ./apps/cache-proxy/Dockerfile .
|
||||
|
||||
- name: Push cache-proxy image to Docker Hub
|
||||
if: steps.filter.outputs.cache_proxy == 'true'
|
||||
run: |
|
||||
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-cache-proxy:${{ steps.vars.outputs.cache_proxy_tag }}
|
||||
# -------------------------------------------------
|
||||
|
||||
deploy:
|
||||
name: Deploy to VPS
|
||||
needs: build-and-push
|
||||
@ -72,8 +115,10 @@ jobs:
|
||||
run: |
|
||||
ssh -i ~/.ssh/id_rsa -p ${{ secrets.VPS_PORT }} -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} "mkdir -p /home/${{ secrets.VPS_USER }}/zapishis"
|
||||
|
||||
- name: Create real .env file for production
|
||||
# --- НОВОЕ: Шаг 2: Создание основного .env БЕЗ ТЕГОВ ---
|
||||
- name: Create .env file for deploy
|
||||
run: |
|
||||
# Включаем все секреты, КРОМЕ тегов
|
||||
echo "BOT_TOKEN=${{ secrets.BOT_TOKEN }}" > .env
|
||||
echo "LOGIN_GRAPHQL=${{ secrets.LOGIN_GRAPHQL }}" >> .env
|
||||
echo "PASSWORD_GRAPHQL=${{ secrets.PASSWORD_GRAPHQL }}" >> .env
|
||||
@ -81,12 +126,26 @@ jobs:
|
||||
echo "EMAIL_GRAPHQL=${{ secrets.EMAIL_GRAPHQL }}" >> .env
|
||||
echo "NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}" >> .env
|
||||
echo "BOT_URL=${{ secrets.BOT_URL }}" >> .env
|
||||
echo "WEB_IMAGE_TAG=${{ needs.build-and-push.outputs.web_tag }}" >> .env
|
||||
echo "BOT_IMAGE_TAG=${{ needs.build-and-push.outputs.bot_tag }}" >> .env
|
||||
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" >> .env
|
||||
echo "REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}" >> .env
|
||||
echo "BOT_PROVIDER_TOKEN=${{ secrets.BOT_PROVIDER_TOKEN }}" >> .env
|
||||
echo "SUPPORT_TELEGRAM_URL=${{ secrets.SUPPORT_TELEGRAM_URL }}" >> .env
|
||||
echo "URL_OFFER=${{ secrets.URL_OFFER }}" >> .env
|
||||
echo "URL_PRIVACY=${{ secrets.URL_PRIVACY }}" >> .env
|
||||
echo "URL_FAQ=${{ secrets.URL_FAQ }}" >> .env
|
||||
|
||||
- name: Copy .env to VPS via SCP
|
||||
# --- НОВОЕ: Шаг 3: Создание файлов тегов (.project.env) ---
|
||||
- name: Create Project Tag Env Files
|
||||
run: |
|
||||
# Создаем файлы, которые будут содержать только одну переменную с тегом
|
||||
echo "WEB_IMAGE_TAG=${{ needs.build-and-push.outputs.web_tag }}" > .env.web
|
||||
echo "BOT_IMAGE_TAG=${{ needs.build-and-push.outputs.bot_tag }}" > .env.bot
|
||||
echo "CACHE_PROXY_IMAGE_TAG=${{ needs.build-and-push.outputs.cache_proxy_tag }}" > .env.cache-proxy
|
||||
|
||||
# --- Шаг 4: Копирование .env и УСЛОВНОЕ копирование тегов ---
|
||||
|
||||
# Копируем основной .env всегда
|
||||
- name: Copy .env to VPS via SCP (Always)
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: ${{ secrets.VPS_HOST }}
|
||||
@ -96,6 +155,42 @@ jobs:
|
||||
source: '.env'
|
||||
target: '/home/${{ secrets.VPS_USER }}/zapishis/'
|
||||
|
||||
# Копируем .env.web ТОЛЬКО, если web был собран (обновляем тег на VPS)
|
||||
- name: Copy .env.web to VPS
|
||||
if: ${{ needs.build-and-push.outputs.web_built == 'true' }}
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: ${{ secrets.VPS_HOST }}
|
||||
username: ${{ secrets.VPS_USER }}
|
||||
key: ${{ secrets.VPS_SSH_KEY }}
|
||||
port: ${{ secrets.VPS_PORT }}
|
||||
source: '.env.web'
|
||||
target: '/home/${{ secrets.VPS_USER }}/zapishis/'
|
||||
|
||||
# Копируем .env.bot ТОЛЬКО, если bot был собран
|
||||
- name: Copy .env.bot to VPS
|
||||
if: ${{ needs.build-and-push.outputs.bot_built == 'true' }}
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: ${{ secrets.VPS_HOST }}
|
||||
username: ${{ secrets.VPS_USER }}
|
||||
key: ${{ secrets.VPS_SSH_KEY }}
|
||||
port: ${{ secrets.VPS_PORT }}
|
||||
source: '.env.bot'
|
||||
target: '/home/${{ secrets.VPS_USER }}/zapishis/'
|
||||
|
||||
# Копируем .env.cache-proxy ТОЛЬКО, если cache-proxy был собран
|
||||
- name: Copy .env.cache-proxy to VPS
|
||||
if: ${{ needs.build-and-push.outputs.cache_proxy_built == 'true' }}
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: ${{ secrets.VPS_HOST }}
|
||||
username: ${{ secrets.VPS_USER }}
|
||||
key: ${{ secrets.VPS_SSH_KEY }}
|
||||
port: ${{ secrets.VPS_PORT }}
|
||||
source: '.env.cache-proxy'
|
||||
target: '/home/${{ secrets.VPS_USER }}/zapishis/'
|
||||
|
||||
- name: Copy docker-compose.yml to VPS via SCP
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
@ -106,12 +201,27 @@ jobs:
|
||||
source: 'docker-compose.yml'
|
||||
target: '/home/${{ secrets.VPS_USER }}/zapishis/'
|
||||
|
||||
# --- ФИНАЛЬНЫЙ ДЕПЛОЙ ---
|
||||
- name: Login and deploy on VPS
|
||||
run: |
|
||||
ssh -i ~/.ssh/id_rsa -p ${{ secrets.VPS_PORT }} -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} "
|
||||
cd /home/${{ secrets.VPS_USER }}/zapishis && \
|
||||
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} && \
|
||||
docker compose pull && \
|
||||
|
||||
# 1. Объединение ВСЕХ ENV-файлов в один основной .env
|
||||
# Теги из .env.web/.env.bot переопределят любые старые/пустые значения,
|
||||
# и .env станет полным и актуальным.
|
||||
echo \"Merging environment files into .env...\" && \
|
||||
cat .env .env.web .env.bot .env.cache-proxy > .temp_env && \
|
||||
mv .temp_env .env && \
|
||||
|
||||
# 2. Логин
|
||||
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
# 3. Pull ВСЕХ сервисов (Docker Compose автоматически использует обновленный .env)
|
||||
echo \"Pulling all services...\" && \
|
||||
docker compose pull
|
||||
|
||||
# 4. Перезапуск
|
||||
docker compose down && \
|
||||
docker compose up -d
|
||||
"
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
# Общие
|
||||
-support-contact = ℹ️ По всем вопросам и обратной связи: @v_dev_support
|
||||
|
||||
# Описание бота
|
||||
short-description =
|
||||
Запись к мастерам, тренерам и репетиторам на вашем смартфоне 📱📅
|
||||
|
||||
ℹ️ По всем вопросам и обратной связи: @vchikalkin
|
||||
|
||||
{ -support-contact }
|
||||
description =
|
||||
📲 Запишись.онлайн — это бесплатное Telegram-приложение для мастеров и тренеров в вашем смартфоне.
|
||||
📲 Запишись.онлайн — это встроенное в Telegram приложение + бот для мастеров и тренеров в вашем смартфоне.
|
||||
|
||||
Возможности:
|
||||
• 📅 Ведение графика и запись клиентов
|
||||
@ -17,89 +19,130 @@ description =
|
||||
✨ Всё, что нужно — ваш смартфон.
|
||||
|
||||
|
||||
ℹ️ По всем вопросам и обратной связи: @vchikalkin
|
||||
{ -support-contact }
|
||||
|
||||
# Команды
|
||||
start =
|
||||
.description = Запуск бота
|
||||
addcontact =
|
||||
.description = Добавить контакт клиента
|
||||
becomemaster =
|
||||
.description = Стать мастером
|
||||
.description = Добавить контакт
|
||||
sharebot =
|
||||
.description = Поделиться ботом
|
||||
subscribe =
|
||||
.description = Приобрести Pro доступ
|
||||
pro =
|
||||
.description = Информация о вашем Pro доступе
|
||||
help =
|
||||
.description = Список команд и поддержка
|
||||
|
||||
commands-list =
|
||||
📋 Доступные команды:
|
||||
• /addcontact — добавить контакт клиента
|
||||
• /becomemaster — стать мастером
|
||||
• /addcontact — добавить контакт
|
||||
• /sharebot — поделиться ботом
|
||||
• /subscribe — приобрести Pro доступ
|
||||
• /pro — информация о вашем Pro доступе
|
||||
• /help — список команд
|
||||
|
||||
Откройте приложение кнопкой "Открыть", чтобы отредактировать свой профиль или создать запись
|
||||
|
||||
support =
|
||||
ℹ️ По всем вопросам и обратной связи: @vchikalkin
|
||||
{ -support-contact }
|
||||
documents =
|
||||
.description = Документы
|
||||
|
||||
# Кнопки
|
||||
btn-add-contact = 👤 Добавить контакт
|
||||
btn-share-bot = 🤝 Поделиться ботом
|
||||
btn-pro = 👑 Pro доступ
|
||||
btn-subscribe = 👑 Приобрести Pro
|
||||
btn-pro-info = ℹ️ Мой Pro доступ
|
||||
btn-open-app = 📱 Открыть приложение
|
||||
btn-faq = 📖 Инструкция
|
||||
btn-documents = 📋 Документы
|
||||
btn-back = ◀️ Назад
|
||||
|
||||
|
||||
# Согласие
|
||||
share-phone-agreement =
|
||||
<i> Нажимая кнопку <b>«Отправить номер телефона»</b></i>,
|
||||
<i>вы:
|
||||
- соглашаетесь с <a href='{ $offerUrl }'>Публичной офертой</a>
|
||||
- подтверждаете согласие на обработку персональных данных согласно <a href='{ $privacyUrl }'>Политике конфиденциальности</a></i>
|
||||
share-contact-agreement =
|
||||
<i> Отправляя контакт, имя и номер телефона, вы подтверждаете, что имеете согласие этого человека на передачу его контактных данных и на их обработку в рамках нашего сервиса.
|
||||
(Пункт 4.5 <a href='{ $privacyUrl }'>Политики конфиденциальности</a>)</i>
|
||||
payment-agreement =
|
||||
Совершая оплату, вы соглашаетесь с <a href='{ $offerUrl }'>Публичной офертой</a>
|
||||
agreement-links =
|
||||
<a href='{ $offerUrl }'>Публичная оферта</a>
|
||||
<a href='{ $privacyUrl }'>Политика конфиденциальности</a>
|
||||
|
||||
|
||||
# Приветственные сообщения
|
||||
msg-welcome =
|
||||
👋 Добро пожаловать!
|
||||
Пожалуйста, поделитесь своим номером телефона для регистрации
|
||||
|
||||
msg-welcome-back = 👋 С возвращением, { $name }!
|
||||
|
||||
# Сообщения о статусе мастера
|
||||
msg-not-master =
|
||||
⛔️ Только мастер может добавлять контакты
|
||||
Стать мастером можно на странице профиля в приложении или с помощью команды /becomemaster
|
||||
|
||||
msg-already-master = 🎉 Вы уже являетесь мастером!
|
||||
|
||||
msg-become-master = 🥳 Поздравляем! Теперь вы мастер
|
||||
|
||||
# Сообщения о телефоне
|
||||
msg-need-phone = 📱 Чтобы добавить контакт, сначала поделитесь своим номером телефона
|
||||
|
||||
msg-need-phone = 📱 Чтобы добавить контакт, сначала поделитесь своим номером телефона.
|
||||
msg-phone-saved =
|
||||
✅ Спасибо! Мы сохранили ваш номер телефона
|
||||
Теперь вы можете открыть приложение или воспользоваться командами бота
|
||||
|
||||
msg-already-registered =
|
||||
✅ Вы уже зарегистрированы в системе
|
||||
|
||||
Для смены номера телефона обратитесь в поддержку (Контакты в профиле бота)
|
||||
|
||||
msg-invalid-phone = ❌ Некорректный номер телефона
|
||||
<i>Для смены номера телефона обратитесь в поддержку (Контакты в профиле бота)</i>
|
||||
msg-invalid-phone = ❌ Некорректный номер телефона. Пример: +79999999999
|
||||
|
||||
# Сообщения о контактах
|
||||
msg-send-client-contact =
|
||||
👤 Отправьте контакт клиента, которого вы хотите добавить.
|
||||
Для отмены операции используйте команду /cancel
|
||||
|
||||
msg-send-contact = Пожалуйста, отправьте контакт клиента через кнопку Telegram
|
||||
|
||||
msg-send-client-contact = 👤 Отправьте контакт пользователя, которого вы хотите добавить.
|
||||
msg-send-client-contact-or-phone = 👤 Отправьте контакт пользователя или введите его номер телефона в сообщении
|
||||
msg-send-contact = Пожалуйста, отправьте контакт пользователя через кнопку Telegram
|
||||
msg-send-client-name = ✍️ Введите имя пользователя одним сообщением
|
||||
msg-send-client-surname = ✍️ Введите фамилию пользователя одним сообщением
|
||||
msg-invalid-name = ❌ Некорректное имя. Попробуйте еще раз
|
||||
msg-contact-added =
|
||||
✅ Добавили { $name } в список ваших клиентов
|
||||
✅ Добавили { $fullname } в список ваших контактов
|
||||
|
||||
Пригласите клиента в приложение, чтобы вы могли добавлять с ним записи
|
||||
|
||||
msg-contact-forward = Перешлите пользователю следующее сообщение, чтобы он мог начать пользоваться ботом ⬇️
|
||||
Пригласите пользователя в приложение, чтобы вы могли добавлять с ним записи
|
||||
msg-contact-forward = <i>Перешлите пользователю следующее сообщение, чтобы он мог начать пользоваться ботом ⬇️</i>
|
||||
|
||||
# Сообщения для шаринга
|
||||
msg-share-bot =
|
||||
📅 Воспользуйтесь этим ботом для записи к вашему мастеру!
|
||||
Нажмите кнопку ниже, чтобы начать
|
||||
|
||||
|
||||
# Системные сообщения
|
||||
msg-cancel = ❌ Операция отменена
|
||||
msg-unhandled = ❓ Неизвестная команда. Попробуйте /start
|
||||
msg-cancel-operation = <i>Для отмены операции используйте команду /cancel</i>
|
||||
|
||||
# Ошибки
|
||||
err-generic = ⚠️ Что-то пошло не так. Попробуйте еще раз через несколько секунд
|
||||
err-banned = 🚫 Ваш аккаунт заблокирован
|
||||
err-with-details = ❌ Произошла ошибка
|
||||
{ $error }
|
||||
err-limit-exceeded = 🚫 Слишком много запросов! Подождите немного
|
||||
err-limit-exceeded = 🚫 Слишком много запросов! Подождите немного
|
||||
err-missing-telegram-id = ❌ Telegram ID не найден
|
||||
err-cannot-add-self = ❌ Нельзя добавить свой номер телефона как контакт
|
||||
|
||||
|
||||
# Сообщения о доступе
|
||||
msg-subscribe =
|
||||
👑 Pro доступ
|
||||
• Разблокирует неограниченное количество заказов
|
||||
msg-subscribe-success = ✅ Платеж успешно обработан!
|
||||
msg-subscribe-error = ❌ Произошла ошибка при обработке платежа
|
||||
msg-subscription-inactive = 🔴 Pro доступ неактивен
|
||||
msg-subscription-active = 🟢 Ваш Pro доступ активен
|
||||
msg-subscription-active-until = 👑 Ваш Pro доступ активен до { $date }
|
||||
msg-subscription-active-days = 👑 Осталось дней вашего Pro доступа: { $days }
|
||||
msg-subscription-active-days-short = Осталось дней: { $days }
|
||||
msg-subscription-expired =
|
||||
Ваш Pro доступ истек.
|
||||
Воспользуйтесь командой /subscribe, чтобы получить неограниченное количество заказов
|
||||
msg-subscribe-disabled = 🟢 Pro доступ отключен для всех. Ограничения сняты! Наслаждайтесь полным доступом! 🎉
|
||||
|
||||
# Информация о лимитах
|
||||
msg-remaining-orders-this-month = 🧾 Доступно заказов в этом месяце: { $count }
|
||||
@ -17,6 +17,7 @@
|
||||
"@grammyjs/conversations": "^2.1.0",
|
||||
"@grammyjs/hydrate": "^1.6.0",
|
||||
"@grammyjs/i18n": "^1.1.2",
|
||||
"@grammyjs/menu": "^1.3.1",
|
||||
"@grammyjs/parse-mode": "^2.2.0",
|
||||
"@grammyjs/ratelimiter": "^1.2.1",
|
||||
"@grammyjs/runner": "^2.0.3",
|
||||
@ -25,10 +26,13 @@
|
||||
"@repo/graphql": "workspace:*",
|
||||
"@repo/typescript-config": "workspace:*",
|
||||
"@types/node": "catalog:",
|
||||
"dayjs": "catalog:",
|
||||
"grammy": "^1.38.1",
|
||||
"ioredis": "^5.7.0",
|
||||
"libphonenumber-js": "^1.12.24",
|
||||
"pino": "^9.9.0",
|
||||
"pino-pretty": "^13.1.1",
|
||||
"radashi": "catalog:",
|
||||
"tsup": "^8.5.0",
|
||||
"typescript": "catalog:",
|
||||
"zod": "catalog:"
|
||||
|
||||
@ -1,82 +1,156 @@
|
||||
/* eslint-disable sonarjs/cognitive-complexity */
|
||||
/* eslint-disable id-length */
|
||||
import { type Context } from '@/bot/context';
|
||||
import { KEYBOARD_REMOVE, KEYBOARD_SHARE_BOT, KEYBOARD_SHARE_PHONE } from '@/config/keyboards';
|
||||
import { isCustomerMaster } from '@/utils/customer';
|
||||
import { isValidPhoneNumber, normalizePhoneNumber } from '@/utils/phone';
|
||||
import { env } from '@/config/env';
|
||||
import { KEYBOARD_SHARE_BOT, KEYBOARD_SHARE_PHONE } from '@/config/keyboards';
|
||||
import { parseContact } from '@/utils/contact';
|
||||
import { combine } from '@/utils/messages';
|
||||
import { type Conversation } from '@grammyjs/conversations';
|
||||
import { CustomersService } from '@repo/graphql/api/customers';
|
||||
import { RegistrationService } from '@repo/graphql/api/registration';
|
||||
import parsePhoneNumber from 'libphonenumber-js';
|
||||
|
||||
export async function addContact(conversation: Conversation<Context, Context>, ctx: Context) {
|
||||
// Проверяем, что пользователь является мастером
|
||||
// Все пользователи могут добавлять контакты
|
||||
const telegramId = ctx.from?.id;
|
||||
if (!telegramId) {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('err-generic')));
|
||||
}
|
||||
|
||||
const customerService = new CustomersService({ telegramId });
|
||||
const { customer } = await customerService.getCustomer({ telegramId });
|
||||
const registrationService = new RegistrationService();
|
||||
const { customer } = await registrationService._NOCACHE_GetCustomer({ telegramId });
|
||||
|
||||
if (!customer) {
|
||||
return ctx.reply(
|
||||
await conversation.external(({ t }) => t('msg-need-phone')),
|
||||
KEYBOARD_SHARE_PHONE,
|
||||
await conversation.external(({ t }) =>
|
||||
combine(
|
||||
t('msg-need-phone'),
|
||||
t('share-phone-agreement', {
|
||||
offerUrl: env.URL_OFFER,
|
||||
privacyUrl: env.URL_PRIVACY,
|
||||
}),
|
||||
),
|
||||
),
|
||||
{ ...KEYBOARD_SHARE_PHONE, parse_mode: 'HTML' },
|
||||
);
|
||||
}
|
||||
|
||||
if (!isCustomerMaster(customer)) {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('msg-not-master')));
|
||||
}
|
||||
// Просим отправить контакт или номер телефона
|
||||
await ctx.reply(
|
||||
await conversation.external(({ t }) =>
|
||||
combine(
|
||||
t('msg-send-client-contact-or-phone'),
|
||||
t('msg-cancel-operation'),
|
||||
t('share-contact-agreement', {
|
||||
offerUrl: env.URL_OFFER,
|
||||
privacyUrl: env.URL_PRIVACY,
|
||||
}),
|
||||
),
|
||||
),
|
||||
{
|
||||
parse_mode: 'HTML',
|
||||
},
|
||||
);
|
||||
|
||||
// Просим отправить контакт клиента
|
||||
await ctx.reply(await conversation.external(({ t }) => t('msg-send-client-contact')));
|
||||
// Ждём первое сообщение: контакт или текст с номером
|
||||
const firstCtx = await conversation.wait();
|
||||
|
||||
// Ждем любое сообщение от пользователя
|
||||
const waitCtx = await conversation.wait();
|
||||
let name = '';
|
||||
let surname = '';
|
||||
let phone = '';
|
||||
|
||||
// Проверяем, что отправлен контакт
|
||||
if (!waitCtx.message?.contact) {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('msg-send-contact')));
|
||||
}
|
||||
if (firstCtx.message?.contact) {
|
||||
/**
|
||||
* Отправлен контакт
|
||||
*/
|
||||
const { contact } = firstCtx.message;
|
||||
const parsedContact = parseContact(contact);
|
||||
const parsedPhone = parsePhoneNumber(contact.phone_number, 'RU');
|
||||
|
||||
const { contact } = waitCtx.message;
|
||||
const name = `${contact.first_name || ''} ${contact.last_name || ''}`.trim();
|
||||
const phone = normalizePhoneNumber(contact.phone_number);
|
||||
name = parsedContact.name;
|
||||
surname = parsedContact.surname;
|
||||
|
||||
// Проверяем валидность номера телефона
|
||||
if (!isValidPhoneNumber(phone)) {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('msg-invalid-phone')));
|
||||
if (!parsedPhone?.isValid() || !parsedPhone.number) {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('msg-invalid-phone')));
|
||||
}
|
||||
|
||||
phone = parsedPhone.number;
|
||||
} else if (firstCtx.message?.text) {
|
||||
/**
|
||||
* Номер в тексте сообщения
|
||||
*/
|
||||
const parsedPhone = parsePhoneNumber(firstCtx.message.text, 'RU');
|
||||
if (!parsedPhone?.isValid() || !parsedPhone.number) {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('msg-invalid-phone')));
|
||||
}
|
||||
|
||||
// Нельзя добавлять свой собственный номер телефона
|
||||
if (customer.phone && customer.phone === parsedPhone.number) {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('err-cannot-add-self')));
|
||||
}
|
||||
|
||||
phone = parsedPhone.number;
|
||||
|
||||
// Просим ввести имя клиента
|
||||
await ctx.reply(await conversation.external(({ t }) => t('msg-send-client-name')));
|
||||
const nameCtx = await conversation.wait();
|
||||
const typedName = nameCtx.message?.text?.trim() || '';
|
||||
if (!typedName) {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('msg-invalid-name')));
|
||||
}
|
||||
|
||||
name = typedName;
|
||||
|
||||
// Просим ввести фамилию клиента
|
||||
await ctx.reply(await conversation.external(({ t }) => t('msg-send-client-surname')));
|
||||
const surnameCtx = await conversation.wait();
|
||||
const typedSurname = surnameCtx.message?.text?.trim() || '';
|
||||
if (!typedSurname) {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('msg-invalid-surname')));
|
||||
}
|
||||
|
||||
surname = typedSurname;
|
||||
} else {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('msg-send-client-contact-or-phone')));
|
||||
}
|
||||
|
||||
try {
|
||||
// Проверяем, есть ли клиент с таким номером
|
||||
const { customer: existingCustomer } = await customerService.getCustomer({ phone });
|
||||
const { customer: existingCustomer } = await registrationService._NOCACHE_GetCustomer({
|
||||
phone,
|
||||
});
|
||||
let documentId = existingCustomer?.documentId;
|
||||
|
||||
// Если клиента нет, создаём нового
|
||||
if (!documentId) {
|
||||
const registrationService = new RegistrationService();
|
||||
const createCustomerResult = await registrationService.createCustomer({ name, phone });
|
||||
const createCustomerResult = await registrationService.createCustomer({
|
||||
data: { name, phone, surname },
|
||||
});
|
||||
|
||||
documentId = createCustomerResult?.createCustomer?.documentId;
|
||||
if (!documentId) throw new Error('Клиент не создан');
|
||||
}
|
||||
|
||||
// Добавляем текущего мастера к клиенту
|
||||
const masters = [customer.documentId];
|
||||
await customerService.addMasters({ data: { masters }, documentId });
|
||||
// Добавляем текущего пользователя к приглашенному
|
||||
const invitedBy = [customer.documentId];
|
||||
const customerService = new CustomersService({ telegramId });
|
||||
await customerService.addInvitedBy({ data: { invitedBy }, documentId });
|
||||
|
||||
// Отправляем подтверждения и инструкции
|
||||
await ctx.reply(await conversation.external(({ t }) => t('msg-contact-added', { name })));
|
||||
await ctx.reply(await conversation.external(({ t }) => t('msg-contact-forward')));
|
||||
await ctx.reply(
|
||||
await conversation.external(({ t }) =>
|
||||
t('msg-contact-added', { fullname: [name, surname].filter(Boolean).join(' ') }),
|
||||
),
|
||||
);
|
||||
await ctx.reply(await conversation.external(({ t }) => t('msg-contact-forward')), {
|
||||
parse_mode: 'HTML',
|
||||
});
|
||||
await ctx.reply(await conversation.external(({ t }) => t('msg-share-bot')), KEYBOARD_SHARE_BOT);
|
||||
} catch (error) {
|
||||
await ctx.reply(
|
||||
await conversation.external(({ t }) => t('err-with-details', { error: String(error) })),
|
||||
);
|
||||
} finally {
|
||||
await ctx.reply(await conversation.external(({ t }) => t('commands-list')), KEYBOARD_REMOVE);
|
||||
}
|
||||
|
||||
return ctx.reply(await conversation.external(({ t }) => t('err-generic')), KEYBOARD_REMOVE);
|
||||
return conversation.halt();
|
||||
}
|
||||
|
||||
@ -1 +1,2 @@
|
||||
export * from './add-contact';
|
||||
export * from './subscription';
|
||||
|
||||
193
apps/bot/src/bot/conversations/subscription.ts
Normal file
193
apps/bot/src/bot/conversations/subscription.ts
Normal file
@ -0,0 +1,193 @@
|
||||
/* eslint-disable id-length */
|
||||
import { type Context } from '@/bot/context';
|
||||
import { env } from '@/config/env';
|
||||
import { formatMoney } from '@/utils/format';
|
||||
import { combine } from '@/utils/messages';
|
||||
import { type Conversation } from '@grammyjs/conversations';
|
||||
import { fmt, i } from '@grammyjs/parse-mode';
|
||||
import { CustomersService } from '@repo/graphql/api/customers';
|
||||
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
|
||||
import * as GQL from '@repo/graphql/types';
|
||||
import { InlineKeyboard } from 'grammy';
|
||||
import { sift } from 'radashi';
|
||||
|
||||
export async function subscription(conversation: Conversation<Context, Context>, ctx: Context) {
|
||||
const telegramId = ctx.from?.id;
|
||||
if (!telegramId) {
|
||||
return replyError(ctx, conversation);
|
||||
}
|
||||
|
||||
const subscriptionsService = new SubscriptionsService({ telegramId });
|
||||
|
||||
const {
|
||||
hasActiveSubscription,
|
||||
remainingDays,
|
||||
subscription: currentSubscription,
|
||||
} = await subscriptionsService.getSubscription({
|
||||
telegramId,
|
||||
});
|
||||
|
||||
const { subscriptionPrices } = await subscriptionsService.getSubscriptionPrices({
|
||||
filters: {
|
||||
active: {
|
||||
eq: true,
|
||||
},
|
||||
period: {
|
||||
ne: GQL.Enum_Subscriptionprice_Period.Trial,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const prices = sift(subscriptionPrices);
|
||||
|
||||
// строим клавиатуру с указанием даты окончания после покупки
|
||||
const keyboard = buildPricesKeyboard(
|
||||
prices,
|
||||
currentSubscription?.expiresAt,
|
||||
hasActiveSubscription,
|
||||
);
|
||||
|
||||
// сообщение с выбором плана
|
||||
const messageWithPrices = await ctx.reply(
|
||||
combine(
|
||||
await conversation.external(({ t }) => {
|
||||
let statusLine = t('msg-subscribe');
|
||||
if (hasActiveSubscription && currentSubscription?.expiresAt) {
|
||||
statusLine = t('msg-subscription-active-until', {
|
||||
date: new Date(currentSubscription.expiresAt).toLocaleDateString('ru-RU', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
}),
|
||||
});
|
||||
} else if (remainingDays) {
|
||||
statusLine = t('msg-subscription-active-days', { days: remainingDays });
|
||||
}
|
||||
|
||||
return combine(statusLine, fmt`${i}${t('msg-cancel-operation')}${i}`.text);
|
||||
}),
|
||||
),
|
||||
{ parse_mode: 'HTML', reply_markup: keyboard },
|
||||
);
|
||||
|
||||
// ждём выбора
|
||||
const selectPlanWaitCtx = await conversation.wait();
|
||||
|
||||
// удаляем сообщение с выбором
|
||||
try {
|
||||
await ctx.api.deleteMessage(telegramId, messageWithPrices.message_id);
|
||||
} catch {
|
||||
/* игнорируем, если не удалось удалить */
|
||||
}
|
||||
|
||||
const selectedPeriod = selectPlanWaitCtx.callbackQuery?.data;
|
||||
if (!selectedPeriod) return replyError(ctx, conversation);
|
||||
|
||||
const selectedPrice = prices.find((price) => price?.period === selectedPeriod);
|
||||
if (!selectedPrice) return replyError(ctx, conversation);
|
||||
|
||||
// создаём invoice (с указанием даты, до которой будет доступ)
|
||||
const baseDate = currentSubscription?.expiresAt
|
||||
? new Date(Math.max(Date.now(), new Date(currentSubscription.expiresAt).getTime()))
|
||||
: new Date();
|
||||
const targetDate = addDays(baseDate, selectedPrice.days ?? 0);
|
||||
const targetDateRu = targetDate.toLocaleDateString('ru-RU', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
});
|
||||
|
||||
const agreementText = await conversation.external(({ t }) => {
|
||||
return t('payment-agreement', {
|
||||
offerUrl: env.URL_OFFER,
|
||||
privacyUrl: env.URL_PRIVACY,
|
||||
});
|
||||
});
|
||||
|
||||
await ctx.reply(agreementText, {
|
||||
parse_mode: 'HTML',
|
||||
});
|
||||
|
||||
const customerService = new CustomersService({ telegramId });
|
||||
const { customer } = await customerService.getCustomer({ telegramId });
|
||||
|
||||
return ctx.replyWithInvoice(
|
||||
'Оплата Pro доступа',
|
||||
combine(
|
||||
`${selectedPrice.description || 'Pro доступ'} — до ${targetDateRu}`,
|
||||
'(Автопродление отключено)',
|
||||
),
|
||||
JSON.stringify({ period: selectedPrice.period }),
|
||||
'RUB',
|
||||
[
|
||||
{
|
||||
amount: selectedPrice.amount * 100, // Telegram ждёт в копейках
|
||||
label: `${selectedPrice.description || 'К оплате'} — до ${targetDateRu}`,
|
||||
},
|
||||
],
|
||||
{
|
||||
protect_content: true,
|
||||
provider_data: JSON.stringify({
|
||||
receipt: {
|
||||
customer: {
|
||||
phone: customer?.phone.replaceAll(/\D/gu, ''),
|
||||
},
|
||||
items: [
|
||||
{
|
||||
amount: {
|
||||
currency: 'RUB',
|
||||
value: selectedPrice.amount,
|
||||
},
|
||||
description: selectedPrice.description || 'Pro доступ',
|
||||
payment_mode: 'full_payment',
|
||||
payment_subject: 'payment',
|
||||
quantity: 1,
|
||||
vat_code: 1,
|
||||
},
|
||||
],
|
||||
tax_system_code: 1,
|
||||
},
|
||||
}),
|
||||
provider_token: env.BOT_PROVIDER_TOKEN,
|
||||
start_parameter: 'get_access',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// --- helpers ---
|
||||
|
||||
function addDays(date: Date, days: number) {
|
||||
const d = new Date(date);
|
||||
d.setDate(d.getDate() + days);
|
||||
return d;
|
||||
}
|
||||
|
||||
function buildPricesKeyboard(
|
||||
prices: GQL.SubscriptionPriceFieldsFragment[],
|
||||
currentExpiresAt?: string,
|
||||
hasActiveSubscription = false,
|
||||
) {
|
||||
const keyboard = new InlineKeyboard();
|
||||
const baseTime = currentExpiresAt
|
||||
? Math.max(Date.now(), new Date(currentExpiresAt).getTime())
|
||||
: Date.now();
|
||||
for (const price of prices) {
|
||||
const targetDate = addDays(new Date(baseTime), price.days ?? 0);
|
||||
const targetDateRu = targetDate.toLocaleDateString('ru-RU', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
});
|
||||
keyboard.row({
|
||||
callback_data: price.period,
|
||||
pay: true,
|
||||
text: `${hasActiveSubscription ? 'Продлить' : 'Доступ'} до ${targetDateRu} (${formatMoney(price.amount)})`,
|
||||
});
|
||||
}
|
||||
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
async function replyError(ctx: Context, conversation: Conversation<Context, Context>) {
|
||||
return ctx.reply(await conversation.external(({ t }) => t('err-generic')));
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
import { handleAddContact } from '../handlers/add-contact';
|
||||
import { type Context } from '@/bot/context';
|
||||
import { logHandle } from '@/bot/helpers/logging';
|
||||
import { Composer } from 'grammy';
|
||||
@ -6,8 +7,6 @@ const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType('private');
|
||||
|
||||
feature.command('addcontact', logHandle('command-add-contact'), async (ctx) => {
|
||||
await ctx.conversation.enter('addContact');
|
||||
});
|
||||
feature.command('addcontact', logHandle('command-add-contact'), handleAddContact);
|
||||
|
||||
export { composer as addContact };
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
import { type Context } from '@/bot/context';
|
||||
import { logHandle } from '@/bot/helpers/logging';
|
||||
import { KEYBOARD_SHARE_PHONE } from '@/config/keyboards';
|
||||
import { isCustomerMaster } from '@/utils/customer';
|
||||
import { CustomersService } from '@repo/graphql/api/customers';
|
||||
import { Enum_Customer_Role } from '@repo/graphql/types';
|
||||
import { Composer } from 'grammy';
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType('private');
|
||||
|
||||
feature.command('becomemaster', logHandle('command-become-master'), async (ctx) => {
|
||||
const telegramId = ctx.from.id;
|
||||
const customerService = new CustomersService({ telegramId });
|
||||
const { customer } = await customerService.getCustomer({ telegramId });
|
||||
|
||||
if (!customer) {
|
||||
return ctx.reply(ctx.t('msg-need-phone'), { ...KEYBOARD_SHARE_PHONE, parse_mode: 'HTML' });
|
||||
}
|
||||
|
||||
if (isCustomerMaster(customer)) {
|
||||
return ctx.reply(ctx.t('msg-already-master'), { parse_mode: 'HTML' });
|
||||
}
|
||||
|
||||
// Обновляем роль клиента на мастер
|
||||
const response = await customerService
|
||||
.updateCustomer({
|
||||
data: { role: Enum_Customer_Role.Master },
|
||||
})
|
||||
.catch((error) => {
|
||||
ctx.reply(ctx.t('err-with-details', { error: String(error) }), { parse_mode: 'HTML' });
|
||||
});
|
||||
|
||||
if (response) {
|
||||
return ctx.reply(ctx.t('msg-become-master'), { parse_mode: 'HTML' });
|
||||
}
|
||||
|
||||
return ctx.reply(ctx.t('err-generic'), { parse_mode: 'HTML' });
|
||||
});
|
||||
|
||||
export { composer as becomeMaster };
|
||||
12
apps/bot/src/bot/features/documents.ts
Normal file
12
apps/bot/src/bot/features/documents.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { handleDocuments } from '../handlers/documents';
|
||||
import { type Context } from '@/bot/context';
|
||||
import { logHandle } from '@/bot/helpers/logging';
|
||||
import { Composer } from 'grammy';
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType('private');
|
||||
|
||||
feature.command('documents', logHandle('command-documents'), handleDocuments);
|
||||
|
||||
export { composer as documents };
|
||||
@ -1,7 +1,6 @@
|
||||
import { type Context } from '@/bot/context';
|
||||
import { logHandle } from '@/bot/helpers/logging';
|
||||
import { KEYBOARD_REMOVE } from '@/config/keyboards';
|
||||
import { combine } from '@/utils/messages';
|
||||
import { mainMenu } from '@/config/keyboards';
|
||||
import { Composer } from 'grammy';
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
@ -9,10 +8,7 @@ const composer = new Composer<Context>();
|
||||
const feature = composer.chatType('private');
|
||||
|
||||
feature.command('help', logHandle('command-help'), async (ctx) => {
|
||||
return ctx.reply(combine(ctx.t('commands-list'), ctx.t('support')), {
|
||||
...KEYBOARD_REMOVE,
|
||||
parse_mode: 'HTML',
|
||||
});
|
||||
return ctx.reply(ctx.t('support'), { reply_markup: mainMenu });
|
||||
});
|
||||
|
||||
export { composer as help };
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
export * from './add-contact';
|
||||
export * from './become-master';
|
||||
export * from './documents';
|
||||
export * from './help';
|
||||
export * from './pro';
|
||||
export * from './registration';
|
||||
export * from './share-bot';
|
||||
export * from './subscription';
|
||||
export * from './welcome';
|
||||
|
||||
11
apps/bot/src/bot/features/pro.ts
Normal file
11
apps/bot/src/bot/features/pro.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { handlePro } from '../handlers/pro';
|
||||
import { type Context } from '@/bot/context';
|
||||
import { logHandle } from '@/bot/helpers/logging';
|
||||
import { Composer } from 'grammy';
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
const feature = composer.chatType('private');
|
||||
|
||||
feature.command('pro', logHandle('command-pro'), handlePro);
|
||||
|
||||
export { composer as pro };
|
||||
@ -1,10 +1,10 @@
|
||||
import { type Context } from '@/bot/context';
|
||||
import { logHandle } from '@/bot/helpers/logging';
|
||||
import { KEYBOARD_REMOVE } from '@/config/keyboards';
|
||||
import { isValidPhoneNumber, normalizePhoneNumber } from '@/utils/phone';
|
||||
import { CustomersService } from '@repo/graphql/api/customers';
|
||||
import { KEYBOARD_REMOVE, mainMenu } from '@/config/keyboards';
|
||||
import { parseContact } from '@/utils/contact';
|
||||
import { RegistrationService } from '@repo/graphql/api/registration';
|
||||
import { Composer } from 'grammy';
|
||||
import parsePhoneNumber from 'libphonenumber-js';
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
@ -14,11 +14,13 @@ const feature = composer.chatType('private');
|
||||
feature.on(':contact', logHandle('contact-registration'), async (ctx) => {
|
||||
const telegramId = ctx.from.id;
|
||||
const { contact } = ctx.message;
|
||||
const name = `${contact.first_name || ''} ${contact.last_name || ''}`.trim();
|
||||
const { name, surname } = parseContact(contact);
|
||||
|
||||
// Проверяем, не зарегистрирован ли уже пользователь
|
||||
const customerService = new CustomersService({ telegramId });
|
||||
const { customer: existingCustomer } = await customerService.getCustomer({ telegramId });
|
||||
const registrationService = new RegistrationService();
|
||||
const { customer: existingCustomer } = await registrationService._NOCACHE_GetCustomer({
|
||||
telegramId,
|
||||
});
|
||||
|
||||
if (existingCustomer) {
|
||||
return ctx.reply(ctx.t('msg-already-registered'), {
|
||||
@ -33,31 +35,32 @@ feature.on(':contact', logHandle('contact-registration'), async (ctx) => {
|
||||
}
|
||||
|
||||
// Нормализация и валидация номера
|
||||
const phone = normalizePhoneNumber(contact.phone_number);
|
||||
if (!isValidPhoneNumber(phone)) {
|
||||
const parsedPhone = parsePhoneNumber(contact.phone_number, 'RU');
|
||||
if (!parsedPhone?.isValid() || !parsedPhone?.number) {
|
||||
return ctx.reply(ctx.t('msg-invalid-phone'));
|
||||
}
|
||||
|
||||
const registrationService = new RegistrationService();
|
||||
|
||||
try {
|
||||
const { customer } = await registrationService.getCustomer({ phone });
|
||||
const { customer } = await registrationService._NOCACHE_GetCustomer({
|
||||
phone: parsedPhone.number,
|
||||
});
|
||||
|
||||
if (customer && !customer.telegramId) {
|
||||
// Пользователь добавлен ранее мастером — обновляем данные
|
||||
await registrationService.updateCustomer({
|
||||
data: { active: true, name, telegramId },
|
||||
data: { active: true, name, surname, telegramId },
|
||||
documentId: customer.documentId,
|
||||
});
|
||||
|
||||
return ctx.reply(ctx.t('msg-phone-saved') + '\n\n' + ctx.t('commands-list'), {
|
||||
...KEYBOARD_REMOVE,
|
||||
parse_mode: 'HTML',
|
||||
});
|
||||
await ctx.reply(ctx.t('msg-phone-saved'), { ...KEYBOARD_REMOVE });
|
||||
|
||||
return ctx.reply(ctx.t('support'), { reply_markup: mainMenu });
|
||||
}
|
||||
|
||||
// Новый пользователь — создаём и активируем
|
||||
const response = await registrationService.createCustomer({ name, phone, telegramId });
|
||||
const response = await registrationService.createCustomer({
|
||||
data: { name, phone: parsedPhone.number, surname, telegramId },
|
||||
});
|
||||
|
||||
const documentId = response?.createCustomer?.documentId;
|
||||
if (!documentId) return ctx.reply(ctx.t('err-generic'));
|
||||
@ -67,10 +70,9 @@ feature.on(':contact', logHandle('contact-registration'), async (ctx) => {
|
||||
documentId,
|
||||
});
|
||||
|
||||
return ctx.reply(ctx.t('msg-phone-saved') + '\n\n' + ctx.t('commands-list'), {
|
||||
...KEYBOARD_REMOVE,
|
||||
parse_mode: 'HTML',
|
||||
});
|
||||
await ctx.reply(ctx.t('msg-phone-saved'), { ...KEYBOARD_REMOVE });
|
||||
|
||||
return ctx.reply(ctx.t('support'), { reply_markup: mainMenu });
|
||||
} catch (error) {
|
||||
return ctx.reply(ctx.t('err-with-details', { error: String(error) }));
|
||||
}
|
||||
|
||||
@ -1,15 +1,12 @@
|
||||
import { handleShareBot } from '../handlers/share-bot';
|
||||
import { type Context } from '@/bot/context';
|
||||
import { logHandle } from '@/bot/helpers/logging';
|
||||
import { KEYBOARD_SHARE_BOT } from '@/config/keyboards';
|
||||
import { Composer } from 'grammy';
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType('private');
|
||||
|
||||
feature.command('sharebot', logHandle('command-share-bot'), async (ctx) => {
|
||||
await ctx.reply(ctx.t('msg-contact-forward'), { parse_mode: 'HTML' });
|
||||
await ctx.reply(ctx.t('msg-share-bot'), { ...KEYBOARD_SHARE_BOT, parse_mode: 'HTML' });
|
||||
});
|
||||
feature.command('sharebot', logHandle('command-share-bot'), handleShareBot);
|
||||
|
||||
export { composer as shareBot };
|
||||
|
||||
48
apps/bot/src/bot/features/subscription.ts
Normal file
48
apps/bot/src/bot/features/subscription.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { handleSubscribe } from '../handlers/subscription';
|
||||
import { type Context } from '@/bot/context';
|
||||
import { logHandle } from '@/bot/helpers/logging';
|
||||
import { logger } from '@/utils/logger';
|
||||
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
|
||||
import { Composer } from 'grammy';
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
// Telegram требует отвечать на pre_checkout_query
|
||||
composer.on('pre_checkout_query', logHandle('pre-checkout-query'), async (ctx) => {
|
||||
await ctx.answerPreCheckoutQuery(true);
|
||||
});
|
||||
|
||||
const feature = composer.chatType('private');
|
||||
|
||||
// команда для входа в flow подписки
|
||||
feature.command('subscribe', logHandle('command-subscribe'), handleSubscribe);
|
||||
|
||||
// успешная оплата
|
||||
feature.on(':successful_payment', logHandle('successful-payment'), async (ctx) => {
|
||||
const telegramId = ctx.from.id;
|
||||
const subscriptionsService = new SubscriptionsService({ telegramId });
|
||||
|
||||
try {
|
||||
const rawPayload = ctx.message?.successful_payment.invoice_payload;
|
||||
if (!rawPayload) throw new Error('Missing invoice payload');
|
||||
|
||||
const payload = JSON.parse(rawPayload);
|
||||
|
||||
const provider_payment_charge_id = ctx.message?.successful_payment?.provider_payment_charge_id;
|
||||
|
||||
const { formattedDate } = await subscriptionsService.createOrUpdateSubscription(
|
||||
payload,
|
||||
provider_payment_charge_id,
|
||||
);
|
||||
|
||||
await ctx.reply(ctx.t('msg-subscribe-success'));
|
||||
await ctx.reply(ctx.t('msg-subscription-active-until', { date: formattedDate }));
|
||||
} catch (error) {
|
||||
await ctx.reply(ctx.t('msg-subscribe-error'));
|
||||
logger.error(
|
||||
'Failed to process subscription after successful payment\n' + (error as Error)?.message,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export { composer as subscription };
|
||||
@ -1,8 +1,9 @@
|
||||
import { type Context } from '@/bot/context';
|
||||
import { logHandle } from '@/bot/helpers/logging';
|
||||
import { KEYBOARD_REMOVE, KEYBOARD_SHARE_PHONE } from '@/config/keyboards';
|
||||
import { env } from '@/config/env';
|
||||
import { KEYBOARD_SHARE_PHONE, mainMenu } from '@/config/keyboards';
|
||||
import { combine } from '@/utils/messages';
|
||||
import { CustomersService } from '@repo/graphql/api/customers';
|
||||
import { RegistrationService } from '@repo/graphql/api/registration';
|
||||
import { Composer } from 'grammy';
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
@ -12,22 +13,30 @@ const feature = composer.chatType('private');
|
||||
feature.command('start', logHandle('command-start'), async (ctx) => {
|
||||
const telegramId = ctx.from.id;
|
||||
|
||||
const customerService = new CustomersService({ telegramId });
|
||||
const { customer } = await customerService.getCustomer({ telegramId });
|
||||
const registrationService = new RegistrationService();
|
||||
const { customer } = await registrationService._NOCACHE_GetCustomer({ telegramId });
|
||||
|
||||
if (customer) {
|
||||
// Пользователь уже зарегистрирован — приветствуем
|
||||
return ctx.reply(
|
||||
combine(ctx.t('msg-welcome-back', { name: customer.name }), ctx.t('commands-list')),
|
||||
{
|
||||
...KEYBOARD_REMOVE,
|
||||
parse_mode: 'HTML',
|
||||
},
|
||||
);
|
||||
return ctx.reply(ctx.t('msg-welcome-back', { name: customer.name }), {
|
||||
reply_markup: mainMenu,
|
||||
});
|
||||
}
|
||||
|
||||
// Новый пользователь — просим поделиться номером
|
||||
return ctx.reply(ctx.t('msg-welcome'), { ...KEYBOARD_SHARE_PHONE, parse_mode: 'HTML' });
|
||||
return ctx.reply(
|
||||
combine(
|
||||
ctx.t('msg-welcome'),
|
||||
ctx.t('share-phone-agreement', {
|
||||
offerUrl: env.URL_OFFER,
|
||||
privacyUrl: env.URL_PRIVACY,
|
||||
}),
|
||||
),
|
||||
{
|
||||
...KEYBOARD_SHARE_PHONE,
|
||||
parse_mode: 'HTML',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
export { composer as welcome };
|
||||
|
||||
7
apps/bot/src/bot/handlers/add-contact.ts
Normal file
7
apps/bot/src/bot/handlers/add-contact.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { type Context } from '@/bot/context';
|
||||
|
||||
async function handler(ctx: Context) {
|
||||
await ctx.conversation.enter('addContact');
|
||||
}
|
||||
|
||||
export { handler as handleAddContact };
|
||||
18
apps/bot/src/bot/handlers/documents.ts
Normal file
18
apps/bot/src/bot/handlers/documents.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { type Context } from '@/bot/context';
|
||||
import { env } from '@/config/env';
|
||||
import { KEYBOARD_REMOVE } from '@/config/keyboards';
|
||||
|
||||
async function handler(ctx: Context) {
|
||||
await ctx.reply(
|
||||
ctx.t('agreement-links', {
|
||||
offerUrl: env.URL_OFFER,
|
||||
privacyUrl: env.URL_PRIVACY,
|
||||
}),
|
||||
{
|
||||
...KEYBOARD_REMOVE,
|
||||
parse_mode: 'HTML',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export { handler as handleDocuments };
|
||||
5
apps/bot/src/bot/handlers/index.ts
Normal file
5
apps/bot/src/bot/handlers/index.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export * from './add-contact';
|
||||
export * from './documents';
|
||||
export * from './pro';
|
||||
export * from './share-bot';
|
||||
export * from './subscription';
|
||||
41
apps/bot/src/bot/handlers/pro.ts
Normal file
41
apps/bot/src/bot/handlers/pro.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { type Context } from '@/bot/context';
|
||||
import { combine } from '@/utils/messages';
|
||||
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
|
||||
|
||||
async function handler(ctx: Context) {
|
||||
const telegramId = ctx?.from?.id;
|
||||
|
||||
if (!telegramId) throw new Error(ctx.t('err-missing-telegram-id'));
|
||||
|
||||
const subscriptionsService = new SubscriptionsService({ telegramId });
|
||||
|
||||
const { subscriptionSetting } = await subscriptionsService.getSubscriptionSettings();
|
||||
const proEnabled = subscriptionSetting?.proEnabled;
|
||||
|
||||
if (!proEnabled) {
|
||||
await ctx.reply(ctx.t('msg-subscribe-disabled'));
|
||||
}
|
||||
|
||||
const { hasActiveSubscription, remainingDays, remainingOrdersCount } =
|
||||
await subscriptionsService.getSubscription({ telegramId });
|
||||
|
||||
if (hasActiveSubscription && remainingDays > 0) {
|
||||
await ctx.reply(
|
||||
combine(
|
||||
ctx.t('msg-subscription-active'),
|
||||
ctx.t('msg-subscription-active-days-short', { days: remainingDays }),
|
||||
remainingDays === 0 ? ctx.t('msg-subscription-expired') : '',
|
||||
),
|
||||
);
|
||||
} else {
|
||||
await ctx.reply(
|
||||
combine(
|
||||
ctx.t('msg-subscription-inactive'),
|
||||
ctx.t('msg-remaining-orders-this-month', { count: remainingOrdersCount }),
|
||||
remainingOrdersCount === 0 ? ctx.t('msg-subscription-expired') : '',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export { handler as handlePro };
|
||||
9
apps/bot/src/bot/handlers/share-bot.ts
Normal file
9
apps/bot/src/bot/handlers/share-bot.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { type Context } from '@/bot/context';
|
||||
import { KEYBOARD_SHARE_BOT } from '@/config/keyboards';
|
||||
|
||||
async function handler(ctx: Context) {
|
||||
await ctx.reply(ctx.t('msg-contact-forward'), { parse_mode: 'HTML' });
|
||||
await ctx.reply(ctx.t('msg-share-bot'), { ...KEYBOARD_SHARE_BOT, parse_mode: 'HTML' });
|
||||
}
|
||||
|
||||
export { handler as handleShareBot };
|
||||
22
apps/bot/src/bot/handlers/subscription.ts
Normal file
22
apps/bot/src/bot/handlers/subscription.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { type Context } from '@/bot/context';
|
||||
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
|
||||
|
||||
async function handler(ctx: Context) {
|
||||
const telegramId = ctx?.from?.id;
|
||||
|
||||
if (!telegramId) throw new Error(ctx.t('err-missing-telegram-id'));
|
||||
|
||||
const subscriptionsService = new SubscriptionsService({ telegramId });
|
||||
|
||||
const { subscriptionSetting } = await subscriptionsService.getSubscriptionSettings();
|
||||
|
||||
const proEnabled = subscriptionSetting?.proEnabled;
|
||||
|
||||
if (proEnabled) {
|
||||
await ctx.conversation.enter('subscription');
|
||||
} else {
|
||||
await ctx.reply(ctx.t('msg-subscribe-disabled'));
|
||||
}
|
||||
}
|
||||
|
||||
export { handler as handleSubscribe };
|
||||
@ -3,7 +3,7 @@ import { I18n } from '@grammyjs/i18n';
|
||||
import path from 'node:path';
|
||||
|
||||
export const i18n = new I18n<Context>({
|
||||
defaultLocale: 'en',
|
||||
defaultLocale: 'ru',
|
||||
directory: path.resolve(process.cwd(), 'locales'),
|
||||
fluentBundleOptions: {
|
||||
useIsolating: false,
|
||||
|
||||
@ -5,11 +5,11 @@ import { unhandledFeature } from './features/unhandled';
|
||||
import { errorHandler } from './handlers/errors';
|
||||
import { i18n } from './i18n';
|
||||
import * as middlewares from './middlewares';
|
||||
import { setCommands } from './settings/commands';
|
||||
import { setInfo } from './settings/info';
|
||||
import { setCommands, setInfo } from './settings';
|
||||
import { env } from '@/config/env';
|
||||
import { mainMenu } from '@/config/keyboards';
|
||||
import { getRedisInstance } from '@/utils/redis';
|
||||
import { autoChatAction } from '@grammyjs/auto-chat-action';
|
||||
import { autoChatAction, chatAction } from '@grammyjs/auto-chat-action';
|
||||
import { createConversation, conversations as grammyConversations } from '@grammyjs/conversations';
|
||||
import { hydrate } from '@grammyjs/hydrate';
|
||||
import { limit } from '@grammyjs/ratelimiter';
|
||||
@ -38,6 +38,10 @@ export function createBot({ token }: Parameters_) {
|
||||
}),
|
||||
);
|
||||
|
||||
bot.use(autoChatAction(bot.api));
|
||||
|
||||
bot.use(chatAction('typing'));
|
||||
|
||||
bot.use(grammyConversations()).command('cancel', async (ctx) => {
|
||||
await ctx.conversation.exitAll();
|
||||
await ctx.reply(ctx.t('msg-cancel'));
|
||||
@ -47,13 +51,14 @@ export function createBot({ token }: Parameters_) {
|
||||
bot.use(createConversation(conversation));
|
||||
}
|
||||
|
||||
bot.use(mainMenu);
|
||||
|
||||
setInfo(bot);
|
||||
setCommands(bot);
|
||||
|
||||
const protectedBot = bot.errorBoundary(errorHandler);
|
||||
|
||||
protectedBot.use(middlewares.updateLogger());
|
||||
protectedBot.use(autoChatAction(bot.api));
|
||||
protectedBot.use(hydrate());
|
||||
|
||||
for (const feature of Object.values(features)) {
|
||||
|
||||
@ -5,7 +5,15 @@ import { type LanguageCode } from '@grammyjs/types';
|
||||
import { type Api, type Bot, type RawApi } from 'grammy';
|
||||
|
||||
export async function setCommands({ api }: Bot<Context, Api<RawApi>>) {
|
||||
const commands = createCommands(['start', 'addcontact', 'becomemaster', 'sharebot', 'help']);
|
||||
const commands = createCommands([
|
||||
'start',
|
||||
'addcontact',
|
||||
'sharebot',
|
||||
'help',
|
||||
'subscribe',
|
||||
'pro',
|
||||
'documents',
|
||||
]);
|
||||
|
||||
for (const command of commands) {
|
||||
addLocalizations(command);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const envSchema = z.object({
|
||||
BOT_PROVIDER_TOKEN: z.string(),
|
||||
BOT_TOKEN: z.string(),
|
||||
BOT_URL: z.string(),
|
||||
RATE_LIMIT: z
|
||||
@ -17,6 +18,9 @@ export const envSchema = z.object({
|
||||
.string()
|
||||
.transform((value) => Number.parseInt(value, 10))
|
||||
.default('6379'),
|
||||
URL_FAQ: z.string(),
|
||||
URL_OFFER: z.string(),
|
||||
URL_PRIVACY: z.string(),
|
||||
});
|
||||
|
||||
export const env = envSchema.parse(process.env);
|
||||
|
||||
@ -1,3 +1,13 @@
|
||||
import { env } from './env';
|
||||
import { type Context } from '@/bot/context';
|
||||
import {
|
||||
handleAddContact,
|
||||
handleDocuments,
|
||||
handlePro,
|
||||
handleShareBot,
|
||||
handleSubscribe,
|
||||
} from '@/bot/handlers';
|
||||
import { Menu } from '@grammyjs/menu';
|
||||
import {
|
||||
type InlineKeyboardMarkup,
|
||||
type ReplyKeyboardMarkup,
|
||||
@ -30,9 +40,34 @@ export const KEYBOARD_SHARE_BOT = {
|
||||
[
|
||||
{
|
||||
text: ' Воспользоваться ботом',
|
||||
url: process.env.BOT_URL as string,
|
||||
url: env.BOT_URL + '?start=new',
|
||||
},
|
||||
],
|
||||
],
|
||||
} as InlineKeyboardMarkup,
|
||||
};
|
||||
|
||||
// Главное меню
|
||||
export const mainMenu = new Menu<Context>('main-menu', { autoAnswer: true })
|
||||
.text((ctx) => ctx.t('btn-add-contact'), handleAddContact)
|
||||
.row()
|
||||
.text((ctx) => ctx.t('btn-subscribe'), handleSubscribe)
|
||||
.text((ctx) => ctx.t('btn-pro-info'), handlePro)
|
||||
.row()
|
||||
.text((ctx) => ctx.t('btn-share-bot'), handleShareBot)
|
||||
.row()
|
||||
.text((ctx) => ctx.t('btn-documents'), handleDocuments)
|
||||
.row()
|
||||
.url(
|
||||
(ctx) => ctx.t('btn-faq'),
|
||||
() => env.URL_FAQ,
|
||||
)
|
||||
.row()
|
||||
.url(
|
||||
(ctx) => ctx.t('btn-open-app'),
|
||||
() => {
|
||||
const botUrl = new URL(env.BOT_URL);
|
||||
botUrl.searchParams.set('startapp', '');
|
||||
return botUrl.toString();
|
||||
},
|
||||
);
|
||||
|
||||
9
apps/bot/src/utils/contact.ts
Normal file
9
apps/bot/src/utils/contact.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { type Contact } from '@grammyjs/types';
|
||||
|
||||
export function parseContact(contact: Contact) {
|
||||
return {
|
||||
name: contact?.first_name?.trim() || '',
|
||||
phone: contact?.phone_number?.trim() || '',
|
||||
surname: contact?.last_name?.trim() || '',
|
||||
};
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
import * as GQL from '@repo/graphql/types';
|
||||
|
||||
export function isCustomerMaster(customer: GQL.CustomerFieldsFragment) {
|
||||
return customer?.role === GQL.Enum_Customer_Role.Master;
|
||||
}
|
||||
4
apps/bot/src/utils/format.ts
Normal file
4
apps/bot/src/utils/format.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export const formatMoney = Intl.NumberFormat('ru-RU', {
|
||||
currency: 'RUB',
|
||||
style: 'currency',
|
||||
}).format;
|
||||
@ -1,3 +1,3 @@
|
||||
export function combine(...messages: string[]) {
|
||||
return messages.join('\n\n');
|
||||
export function combine(...messages: Array<string | undefined>) {
|
||||
return messages.filter(Boolean).join('\n\n');
|
||||
}
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
export function isValidPhoneNumber(phone: string) {
|
||||
return /^\+7\d{10}$/u.test(phone);
|
||||
}
|
||||
|
||||
export function normalizePhoneNumber(phone: string): string {
|
||||
const digitsOnly = phone.replaceAll(/\D/gu, '');
|
||||
|
||||
return `+${digitsOnly}`;
|
||||
}
|
||||
7
apps/cache-proxy/.dockerignore
Normal file
7
apps/cache-proxy/.dockerignore
Normal file
@ -0,0 +1,7 @@
|
||||
.git
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
node_modules
|
||||
*.log
|
||||
dist
|
||||
README.md
|
||||
13
apps/cache-proxy/.eslintrc.js
Normal file
13
apps/cache-proxy/.eslintrc.js
Normal file
@ -0,0 +1,13 @@
|
||||
import { typescript } from '@repo/eslint-config/typescript';
|
||||
|
||||
/** @type {import("eslint").Linter.Config} */
|
||||
export default [
|
||||
...typescript,
|
||||
{
|
||||
ignores: ['**/types/**', '*.config.*', '*.config.js', '.eslintrc.js'],
|
||||
rules: {
|
||||
'import/no-duplicates': 'off',
|
||||
'import/consistent-type-specifier-style': 'off',
|
||||
},
|
||||
},
|
||||
];
|
||||
56
apps/cache-proxy/.gitignore
vendored
Normal file
56
apps/cache-proxy/.gitignore
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
/build
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# temp directory
|
||||
.temp
|
||||
.tmp
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
51
apps/cache-proxy/Dockerfile
Normal file
51
apps/cache-proxy/Dockerfile
Normal file
@ -0,0 +1,51 @@
|
||||
ARG NODE_VERSION=22
|
||||
ARG PROJECT=cache-proxy
|
||||
|
||||
# Alpine image
|
||||
FROM node:${NODE_VERSION}-alpine AS alpine
|
||||
RUN apk update
|
||||
RUN apk add --no-cache libc6-compat
|
||||
|
||||
FROM alpine as base
|
||||
ENV PNPM_HOME="/pnpm"
|
||||
ENV PATH="$PNPM_HOME:$PATH"
|
||||
RUN apk add --no-cache libc6-compat && \
|
||||
corepack enable && \
|
||||
pnpm install turbo@2.3.2 dotenv-cli --global
|
||||
|
||||
FROM base AS pruner
|
||||
ARG PROJECT
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN turbo prune --scope=${PROJECT} --docker
|
||||
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=pruner /app/out/json/ .
|
||||
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
|
||||
|
||||
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm install --prod --frozen-lockfile
|
||||
|
||||
COPY --from=pruner /app/out/full/ .
|
||||
|
||||
COPY turbo.json turbo.json
|
||||
COPY .env .env
|
||||
|
||||
RUN dotenv -e .env turbo run build --filter=${PROJECT}...
|
||||
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm prune --prod --no-optional
|
||||
RUN rm -rf ./**/*/src
|
||||
|
||||
FROM alpine AS runner
|
||||
ARG PROJECT
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 appuser
|
||||
USER appuser
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder --chown=nodejs:nodejs /app .
|
||||
WORKDIR /app/apps/${PROJECT}
|
||||
|
||||
CMD ["node", "dist/main.js"]
|
||||
73
apps/cache-proxy/README.md
Normal file
73
apps/cache-proxy/README.md
Normal file
@ -0,0 +1,73 @@
|
||||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
|
||||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ pnpm install
|
||||
```
|
||||
|
||||
## Running the app
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ pnpm run start
|
||||
|
||||
# watch mode
|
||||
$ pnpm run start:dev
|
||||
|
||||
# production mode
|
||||
$ pnpm run start:prod
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ pnpm run test
|
||||
|
||||
# e2e tests
|
||||
$ pnpm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ pnpm run test:cov
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](LICENSE).
|
||||
9
apps/cache-proxy/nest-cli.json
Normal file
9
apps/cache-proxy/nest-cli.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"monorepo": true,
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
75
apps/cache-proxy/package.json
Normal file
75
apps/cache-proxy/package.json
Normal file
@ -0,0 +1,75 @@
|
||||
{
|
||||
"name": "cache-proxy",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"dev": "dotenv -e ../../.env.local nest start -- --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/cli": "^10.0.0",
|
||||
"@nestjs/schematics": "^10.0.0",
|
||||
"@nestjs/cache-manager": "^2.2.1",
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/config": "^3.2.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@nestjs/platform-fastify": "^10.3.3",
|
||||
"@types/node": "catalog:",
|
||||
"fastify": "^4.26.1",
|
||||
"dotenv-cli": "catalog:",
|
||||
"cache-manager": "^5.4.0",
|
||||
"cache-manager-ioredis": "^2.1.0",
|
||||
"ioredis": "^5.3.2",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.8.1",
|
||||
"source-map-support": "^0.5.21",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "catalog:",
|
||||
"zod": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/testing": "^10.0.0",
|
||||
"@repo/eslint-config": "workspace:*",
|
||||
"@repo/typescript-config": "workspace:*",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/supertest": "^6.0.0",
|
||||
"eslint": "catalog:",
|
||||
"jest": "^29.5.0",
|
||||
"prettier": "catalog:",
|
||||
"supertest": "^6.3.3",
|
||||
"ts-jest": "29.1.1",
|
||||
"ts-loader": "^9.4.3",
|
||||
"ts-node": "^10.9.1"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
18
apps/cache-proxy/src/app.module.ts
Normal file
18
apps/cache-proxy/src/app.module.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { ProxyModule } from './proxy/proxy.module';
|
||||
import { HealthController } from './health/health.controller';
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
}),
|
||||
ProxyModule,
|
||||
],
|
||||
controllers: [HealthController],
|
||||
providers: [],
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
||||
export class AppModule {}
|
||||
3
apps/cache-proxy/src/config/constants.ts
Normal file
3
apps/cache-proxy/src/config/constants.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { seconds } from 'src/utils/time';
|
||||
|
||||
export const DEFAULT_CACHE_TTL = seconds().fromMinutes(5);
|
||||
3
apps/cache-proxy/src/config/env.ts
Normal file
3
apps/cache-proxy/src/config/env.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import envSchema from './schema/env';
|
||||
|
||||
export const env = envSchema.parse(process.env);
|
||||
22
apps/cache-proxy/src/config/schema/env.ts
Normal file
22
apps/cache-proxy/src/config/schema/env.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { DEFAULT_CACHE_TTL } from '../constants';
|
||||
import { z } from 'zod';
|
||||
|
||||
const envSchema = z.object({
|
||||
CACHE_TTL: z
|
||||
.string()
|
||||
.transform((val) => Number.parseInt(val, 10))
|
||||
.default(DEFAULT_CACHE_TTL.toString()),
|
||||
PORT: z
|
||||
.string()
|
||||
.transform((val) => Number.parseInt(val, 10))
|
||||
.default('5000'),
|
||||
REDIS_HOST: z.string().default('redis'),
|
||||
REDIS_PASSWORD: z.string(),
|
||||
REDIS_PORT: z
|
||||
.string()
|
||||
.transform((value) => Number.parseInt(value, 10))
|
||||
.default('6379'),
|
||||
URL_GRAPHQL: z.string(),
|
||||
});
|
||||
|
||||
export default envSchema;
|
||||
11
apps/cache-proxy/src/health/health.controller.ts
Normal file
11
apps/cache-proxy/src/health/health.controller.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
|
||||
@Controller('api')
|
||||
export class HealthController {
|
||||
@Get('health')
|
||||
public health() {
|
||||
return { status: 'ok' };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
15
apps/cache-proxy/src/main.ts
Normal file
15
apps/cache-proxy/src/main.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { AppModule } from './app.module';
|
||||
import { env } from './config/env';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import type { NestFastifyApplication } from '@nestjs/platform-fastify';
|
||||
import { FastifyAdapter } from '@nestjs/platform-fastify';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestFastifyApplication>(
|
||||
AppModule,
|
||||
new FastifyAdapter(),
|
||||
);
|
||||
|
||||
await app.listen(env.PORT, '0.0.0.0');
|
||||
}
|
||||
bootstrap();
|
||||
16
apps/cache-proxy/src/proxy/lib/config.ts
Normal file
16
apps/cache-proxy/src/proxy/lib/config.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { seconds } from 'src/utils/time';
|
||||
|
||||
export const queryTTL: Record<string, number | false> = {
|
||||
GetCustomer: seconds().fromHours(12),
|
||||
GetCustomers: false,
|
||||
GetInvited: false,
|
||||
GetInvitedBy: false,
|
||||
GetOrders: false,
|
||||
GetServices: false,
|
||||
GetSlots: false,
|
||||
GetSlotsOrders: false,
|
||||
GetSubscriptionHistory: false,
|
||||
GetSubscriptions: false,
|
||||
GetSubscriptionSettings: seconds().fromHours(12),
|
||||
Login: false,
|
||||
};
|
||||
8
apps/cache-proxy/src/proxy/lib/utils.ts
Normal file
8
apps/cache-proxy/src/proxy/lib/utils.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { env } from 'src/config/env';
|
||||
import { queryTTL } from './config';
|
||||
|
||||
export function getQueryTTL(operationName: string) {
|
||||
if (operationName.includes('NOCACHE')) return false;
|
||||
|
||||
return queryTTL[operationName] ?? env.CACHE_TTL;
|
||||
}
|
||||
138
apps/cache-proxy/src/proxy/proxy.controller.ts
Normal file
138
apps/cache-proxy/src/proxy/proxy.controller.ts
Normal file
@ -0,0 +1,138 @@
|
||||
import type { GQLRequest, GQLResponse } from './types';
|
||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import {
|
||||
All,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Inject,
|
||||
Query,
|
||||
Req,
|
||||
Res,
|
||||
} from '@nestjs/common';
|
||||
import type { Cache } from 'cache-manager';
|
||||
import { FastifyReply, FastifyRequest } from 'fastify';
|
||||
import { env } from 'src/config/env';
|
||||
import { extractDocumentId, getQueryType } from 'src/utils/query';
|
||||
import { getQueryTTL } from './lib/utils';
|
||||
|
||||
type RedisStore = Omit<Cache, 'set'> & {
|
||||
set: (key: string, value: unknown, { ttl }: { ttl: number }) => Promise<void>;
|
||||
};
|
||||
|
||||
@Controller('api')
|
||||
export class ProxyController {
|
||||
constructor(@Inject(CACHE_MANAGER) private readonly cacheManager: RedisStore) {}
|
||||
|
||||
@All('/graphql')
|
||||
public async graphql(@Req() req: FastifyRequest, @Res() reply: FastifyReply) {
|
||||
const { operationName, query, variables } = req.body as GQLRequest;
|
||||
|
||||
const queryType = getQueryType(query);
|
||||
|
||||
const key = `${operationName} ${JSON.stringify(variables)}`;
|
||||
|
||||
if (queryType.action === 'query') {
|
||||
const cached = await this.cacheManager.get(key);
|
||||
if (cached) return reply.send(cached);
|
||||
}
|
||||
|
||||
const response = await fetch(env.URL_GRAPHQL, {
|
||||
body: JSON.stringify({ operationName, query, variables }),
|
||||
headers: {
|
||||
Authorization: req.headers.authorization,
|
||||
'Content-Type': 'application/json',
|
||||
Cookie: req.headers.cookie,
|
||||
},
|
||||
method: req.method,
|
||||
});
|
||||
|
||||
const data = (await response.json()) as GQLResponse;
|
||||
|
||||
if (!response.ok || data?.error || data?.errors?.length)
|
||||
throw new HttpException(
|
||||
response.statusText,
|
||||
response.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
|
||||
if (queryType.action === 'mutation' && queryType.entity) {
|
||||
const documentId = extractDocumentId(data);
|
||||
const keys = await this.cacheManager.store.keys(`*${queryType.entity}*`);
|
||||
for (const key of keys) {
|
||||
if (key.includes(documentId)) {
|
||||
await this.cacheManager.del(key);
|
||||
|
||||
// console.log(`🗑 Cache invalidated (by key): ${key}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const value = await this.cacheManager.get(key);
|
||||
const serialized = typeof value === 'string' ? value : JSON.stringify(value);
|
||||
if (serialized?.includes(documentId)) {
|
||||
await this.cacheManager.del(key);
|
||||
|
||||
// console.log(`🗑 Cache invalidated (by value): ${key}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const ttl = getQueryTTL(operationName);
|
||||
if (queryType.action === 'query' && data && ttl !== false)
|
||||
await this.cacheManager.set(key, data, { ttl });
|
||||
|
||||
return reply.send(data);
|
||||
}
|
||||
|
||||
@Get('/get-queries')
|
||||
public async getQueriesList(@Res() reply: FastifyReply) {
|
||||
const keys: string[] = await this.cacheManager.store.keys('*');
|
||||
|
||||
const entries = await Promise.all(
|
||||
keys.map(async (key) => {
|
||||
try {
|
||||
const value = await this.cacheManager.get(key);
|
||||
return { key, value };
|
||||
} catch (e) {
|
||||
return { key, error: e.message };
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
return reply.send(entries);
|
||||
}
|
||||
|
||||
@Delete('/delete-query')
|
||||
public async deleteQuery(@Query('queryKey') queryKey: string, @Res() reply: FastifyReply) {
|
||||
try {
|
||||
await this.cacheManager.del(queryKey);
|
||||
|
||||
return reply.send('ok');
|
||||
} catch (error) {
|
||||
throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Delete('/reset')
|
||||
public async reset(@Res() reply: FastifyReply) {
|
||||
try {
|
||||
await this.cacheManager.reset();
|
||||
|
||||
return reply.send('ok');
|
||||
} catch (error) {
|
||||
throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('/get-query')
|
||||
public async getQueryValue(@Query('queryKey') queryKey: string, @Res() reply: FastifyReply) {
|
||||
try {
|
||||
const value = await this.cacheManager.get(queryKey);
|
||||
|
||||
return reply.send(value);
|
||||
} catch (error) {
|
||||
throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
apps/cache-proxy/src/proxy/proxy.module.ts
Normal file
22
apps/cache-proxy/src/proxy/proxy.module.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { ProxyController } from './proxy.controller';
|
||||
import { CacheModule } from '@nestjs/cache-manager';
|
||||
import { Module } from '@nestjs/common';
|
||||
import * as redisStore from 'cache-manager-ioredis';
|
||||
import type { RedisOptions } from 'ioredis';
|
||||
import { env } from 'src/config/env';
|
||||
|
||||
@Module({
|
||||
controllers: [ProxyController],
|
||||
imports: [
|
||||
CacheModule.register<RedisOptions>({
|
||||
host: env.REDIS_HOST,
|
||||
port: env.REDIS_PORT,
|
||||
store: redisStore,
|
||||
ttl: env.CACHE_TTL,
|
||||
password: env.REDIS_PASSWORD,
|
||||
db: 1,
|
||||
}),
|
||||
],
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
||||
export class ProxyModule {}
|
||||
16
apps/cache-proxy/src/proxy/types.ts
Normal file
16
apps/cache-proxy/src/proxy/types.ts
Normal file
@ -0,0 +1,16 @@
|
||||
export type GQLRequest = {
|
||||
operationName: string;
|
||||
query: string;
|
||||
variables: string;
|
||||
};
|
||||
|
||||
export type GQLResponse = {
|
||||
data: unknown;
|
||||
error?: unknown;
|
||||
errors?: unknown[];
|
||||
};
|
||||
|
||||
export type QueryItem = {
|
||||
queries: string[];
|
||||
ttl: number | false;
|
||||
};
|
||||
22
apps/cache-proxy/src/utils/query.ts
Normal file
22
apps/cache-proxy/src/utils/query.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { GQLResponse } from 'src/proxy/types';
|
||||
|
||||
export function getQueryType(query: string) {
|
||||
const actionMatch = query.match(/\b(query|mutation)\b/u);
|
||||
const action = actionMatch ? (actionMatch[1] as 'query' | 'mutation') : null;
|
||||
|
||||
const entityMatch = query.match(
|
||||
/\b(mutation|query)\s+\w*([A-Z][A-Za-z0-9_]+)/u,
|
||||
);
|
||||
const entity = entityMatch ? entityMatch[2] : null;
|
||||
|
||||
return { action, entity };
|
||||
}
|
||||
|
||||
export function extractDocumentId(data: GQLResponse) {
|
||||
if (!data?.data) return null;
|
||||
|
||||
const firstKey = Object.keys(data.data)[0];
|
||||
if (!firstKey) return null;
|
||||
|
||||
return data.data[firstKey]?.documentId || null;
|
||||
}
|
||||
13
apps/cache-proxy/src/utils/time.ts
Normal file
13
apps/cache-proxy/src/utils/time.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export function seconds() {
|
||||
return {
|
||||
fromDays(days: number) {
|
||||
return days * 24 * 60 * 60;
|
||||
},
|
||||
fromHours(hours: number) {
|
||||
return hours * 60 * 60;
|
||||
},
|
||||
fromMinutes(minutes: number) {
|
||||
return minutes * 60;
|
||||
},
|
||||
};
|
||||
}
|
||||
4
apps/cache-proxy/tsconfig.build.json
Normal file
4
apps/cache-proxy/tsconfig.build.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
||||
23
apps/cache-proxy/tsconfig.json
Normal file
23
apps/cache-proxy/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2022",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": false,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"noFallthroughCasesInSwitch": false
|
||||
},
|
||||
"include": ["."],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
}
|
||||
@ -1,8 +1,9 @@
|
||||
import * as customers from './server/customers';
|
||||
import { wrapClientAction } from '@/utils/actions';
|
||||
|
||||
export const addMasters = wrapClientAction(customers.addMasters);
|
||||
export const getClients = wrapClientAction(customers.getClients);
|
||||
export const addInvitedBy = wrapClientAction(customers.addInvitedBy);
|
||||
export const getInvited = wrapClientAction(customers.getInvited);
|
||||
export const getCustomer = wrapClientAction(customers.getCustomer);
|
||||
export const getMasters = wrapClientAction(customers.getMasters);
|
||||
export const getCustomers = wrapClientAction(customers.getCustomers);
|
||||
export const getInvitedBy = wrapClientAction(customers.getInvitedBy);
|
||||
export const updateCustomer = wrapClientAction(customers.updateCustomer);
|
||||
|
||||
@ -6,16 +6,10 @@ import { CustomersService } from '@repo/graphql/api/customers';
|
||||
|
||||
const getService = useService(CustomersService);
|
||||
|
||||
export async function addMasters(...variables: Parameters<CustomersService['addMasters']>) {
|
||||
export async function addInvitedBy(...variables: Parameters<CustomersService['addInvitedBy']>) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.addMasters(...variables));
|
||||
}
|
||||
|
||||
export async function getClients(...variables: Parameters<CustomersService['getClients']>) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.getClients(...variables));
|
||||
return wrapServerAction(() => service.addInvitedBy(...variables));
|
||||
}
|
||||
|
||||
export async function getCustomer(...variables: Parameters<CustomersService['getCustomer']>) {
|
||||
@ -24,10 +18,22 @@ export async function getCustomer(...variables: Parameters<CustomersService['get
|
||||
return wrapServerAction(() => service.getCustomer(...variables));
|
||||
}
|
||||
|
||||
export async function getMasters(...variables: Parameters<CustomersService['getMasters']>) {
|
||||
export async function getCustomers(...variables: Parameters<CustomersService['getCustomers']>) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.getMasters(...variables));
|
||||
return wrapServerAction(() => service.getCustomers(...variables));
|
||||
}
|
||||
|
||||
export async function getInvited(...variables: Parameters<CustomersService['getInvited']>) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.getInvited(...variables));
|
||||
}
|
||||
|
||||
export async function getInvitedBy(...variables: Parameters<CustomersService['getInvitedBy']>) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.getInvitedBy(...variables));
|
||||
}
|
||||
|
||||
export async function updateCustomer(...variables: Parameters<CustomersService['updateCustomer']>) {
|
||||
|
||||
84
apps/web/actions/api/server/subscriptions.ts
Normal file
84
apps/web/actions/api/server/subscriptions.ts
Normal file
@ -0,0 +1,84 @@
|
||||
'use server';
|
||||
import { useService } from '../lib/service';
|
||||
import { wrapServerAction } from '@/utils/actions';
|
||||
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
|
||||
|
||||
const getService = useService(SubscriptionsService);
|
||||
|
||||
export async function createSubscription(
|
||||
...variables: Parameters<SubscriptionsService['createSubscription']>
|
||||
) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.createSubscription(...variables));
|
||||
}
|
||||
|
||||
export async function createSubscriptionHistory(
|
||||
...variables: Parameters<SubscriptionsService['createSubscriptionHistory']>
|
||||
) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.createSubscriptionHistory(...variables));
|
||||
}
|
||||
|
||||
export async function createTrialSubscription() {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.createTrialSubscription());
|
||||
}
|
||||
|
||||
export async function getSubscription(
|
||||
...variables: Parameters<SubscriptionsService['getSubscription']>
|
||||
) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.getSubscription(...variables));
|
||||
}
|
||||
|
||||
export async function getSubscriptionHistory(
|
||||
...variables: Parameters<SubscriptionsService['getSubscriptionHistory']>
|
||||
) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.getSubscriptionHistory(...variables));
|
||||
}
|
||||
|
||||
export async function getSubscriptionPrices(
|
||||
...variables: Parameters<SubscriptionsService['getSubscriptionPrices']>
|
||||
) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.getSubscriptionPrices(...variables));
|
||||
}
|
||||
|
||||
export async function getSubscriptions(
|
||||
...variables: Parameters<SubscriptionsService['getSubscriptions']>
|
||||
) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.getSubscriptions(...variables));
|
||||
}
|
||||
|
||||
export async function getSubscriptionSettings(
|
||||
...variables: Parameters<SubscriptionsService['getSubscriptionSettings']>
|
||||
) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.getSubscriptionSettings(...variables));
|
||||
}
|
||||
|
||||
export async function updateSubscription(
|
||||
...variables: Parameters<SubscriptionsService['updateSubscription']>
|
||||
) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.updateSubscription(...variables));
|
||||
}
|
||||
|
||||
export async function updateSubscriptionHistory(
|
||||
...variables: Parameters<SubscriptionsService['updateSubscriptionHistory']>
|
||||
) {
|
||||
const service = await getService();
|
||||
|
||||
return wrapServerAction(() => service.updateSubscriptionHistory(...variables));
|
||||
}
|
||||
13
apps/web/actions/api/subscriptions.ts
Normal file
13
apps/web/actions/api/subscriptions.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import * as subscriptions from './server/subscriptions';
|
||||
import { wrapClientAction } from '@/utils/actions';
|
||||
|
||||
export const getSubscription = wrapClientAction(subscriptions.getSubscription);
|
||||
export const getSubscriptions = wrapClientAction(subscriptions.getSubscriptions);
|
||||
export const getSubscriptionSettings = wrapClientAction(subscriptions.getSubscriptionSettings);
|
||||
export const getSubscriptionPrices = wrapClientAction(subscriptions.getSubscriptionPrices);
|
||||
export const getSubscriptionHistory = wrapClientAction(subscriptions.getSubscriptionHistory);
|
||||
export const createSubscription = wrapClientAction(subscriptions.createSubscription);
|
||||
export const updateSubscription = wrapClientAction(subscriptions.updateSubscription);
|
||||
export const createSubscriptionHistory = wrapClientAction(subscriptions.createSubscriptionHistory);
|
||||
export const updateSubscriptionHistory = wrapClientAction(subscriptions.updateSubscriptionHistory);
|
||||
export const createTrialSubscription = wrapClientAction(subscriptions.createTrialSubscription);
|
||||
@ -2,12 +2,15 @@
|
||||
|
||||
import { authOptions } from '@/config/auth';
|
||||
import { getServerSession } from 'next-auth/next';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
export async function getSessionUser() {
|
||||
const session = await getServerSession(authOptions);
|
||||
const user = session?.user;
|
||||
|
||||
if (!user?.telegramId) throw new Error('Missing session');
|
||||
if (!user?.telegramId) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@ -22,7 +22,18 @@ export default function Auth() {
|
||||
signIn('telegram', {
|
||||
callbackUrl: '/profile',
|
||||
redirect: false,
|
||||
telegramId: user?.id,
|
||||
telegramId: user?.id?.toString(),
|
||||
}).then((result) => {
|
||||
if (
|
||||
result?.error &&
|
||||
(result?.error?.includes('CredentialsSignin') ||
|
||||
result?.error?.includes('UNREGISTERED'))
|
||||
) {
|
||||
// Пользователь не зарегистрирован
|
||||
redirect('/unregistered');
|
||||
} else if (result?.ok) {
|
||||
redirect('/profile');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -10,4 +10,6 @@ export default function Page() {
|
||||
|
||||
redirect(isTG ? '/telegram' : '/browser');
|
||||
});
|
||||
|
||||
return 'Redirecting...';
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { TelegramProvider } from '@/providers/telegram';
|
||||
import { type PropsWithChildren } from 'react';
|
||||
|
||||
export default async function Layout({ children }: Readonly<PropsWithChildren>) {
|
||||
export default function Layout({ children }: Readonly<PropsWithChildren>) {
|
||||
return <TelegramProvider>{children}</TelegramProvider>;
|
||||
}
|
||||
|
||||
@ -1,40 +1,79 @@
|
||||
/* eslint-disable promise/prefer-await-to-then */
|
||||
'use client';
|
||||
|
||||
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
|
||||
import { initData, isMiniAppDark, useSignal } from '@telegram-apps/sdk-react';
|
||||
import { signIn, useSession } from 'next-auth/react';
|
||||
import { signIn, type SignInResponse, useSession } from 'next-auth/react';
|
||||
import { useTheme } from 'next-themes';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
|
||||
export default function Auth() {
|
||||
useTelegramTheme();
|
||||
useAuth();
|
||||
|
||||
return null;
|
||||
useTelegramAuth();
|
||||
|
||||
return <LoadingSpinner />;
|
||||
}
|
||||
|
||||
function useAuth() {
|
||||
/**
|
||||
* Хук для авторизации пользователя через NextAuth
|
||||
*/
|
||||
function useTelegramAuth() {
|
||||
const initDataUser = useSignal(initData.user);
|
||||
const { status } = useSession();
|
||||
|
||||
const { data: session, status } = useSession();
|
||||
const router = useRouter();
|
||||
|
||||
const handleSignInResult = useCallback(
|
||||
(result: SignInResponse | undefined) => {
|
||||
if (!result) return;
|
||||
|
||||
if (
|
||||
result.error &&
|
||||
(result.error.includes('CredentialsSignin') || result.error.includes('UNREGISTERED'))
|
||||
) {
|
||||
router.replace('/unregistered');
|
||||
} else if (result.ok) {
|
||||
router.replace('/profile');
|
||||
}
|
||||
},
|
||||
[router],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!initDataUser?.id) return;
|
||||
const telegramId = initDataUser?.id;
|
||||
if (!telegramId) return;
|
||||
|
||||
if (status === 'authenticated') {
|
||||
redirect('/profile');
|
||||
// Если telegramId есть в сессии — редирект
|
||||
if (session?.user?.telegramId) {
|
||||
router.replace('/profile');
|
||||
} else {
|
||||
// Если telegramId отсутствует — пробуем заново signIn
|
||||
void signIn('telegram', {
|
||||
callbackUrl: '/profile',
|
||||
redirect: false,
|
||||
telegramId: telegramId.toString(),
|
||||
}).then(handleSignInResult);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (status === 'unauthenticated') {
|
||||
signIn('telegram', {
|
||||
void signIn('telegram', {
|
||||
callbackUrl: '/profile',
|
||||
redirect: false,
|
||||
telegramId: initDataUser.id,
|
||||
}).then(() => redirect('/profile'));
|
||||
telegramId: telegramId.toString(),
|
||||
}).then(handleSignInResult);
|
||||
}
|
||||
}, [initDataUser?.id, status]);
|
||||
}, [initDataUser?.id, status, session?.user?.telegramId, router, handleSignInResult]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Хук для установки темы из Telegram Mini App
|
||||
*/
|
||||
function useTelegramTheme() {
|
||||
const isDark = isMiniAppDark();
|
||||
const { setTheme } = useTheme();
|
||||
|
||||
54
apps/web/app/(auth)/unregistered/page.tsx
Normal file
54
apps/web/app/(auth)/unregistered/page.tsx
Normal file
@ -0,0 +1,54 @@
|
||||
import { UnregisteredClient } from './unregistered-client';
|
||||
import { Container } from '@/components/layout';
|
||||
import { env } from '@/config/env';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@repo/ui/components/ui/card';
|
||||
import { Bot, MessageCircle } from 'lucide-react';
|
||||
|
||||
export default function UnregisteredPage() {
|
||||
return (
|
||||
<Container>
|
||||
<div className="flex min-h-screen items-center justify-center">
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto mb-4 flex size-16 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-900/20">
|
||||
<Bot className="size-8 text-blue-600 dark:text-blue-400" />
|
||||
</div>
|
||||
<CardTitle className="text-xl">Давайте познакомимся</CardTitle>
|
||||
<CardDescription>
|
||||
Для использования приложения необходимо поделиться своим номером телефона с ботом
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="rounded-lg bg-muted p-4">
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-start gap-3">
|
||||
<MessageCircle className="mt-0.5 size-5 text-blue-500" />
|
||||
<div className="text-sm">
|
||||
<p className="mb-1 font-medium text-foreground">Как поделиться:</p>
|
||||
<ol className="list-inside list-decimal space-y-1 text-muted-foreground">
|
||||
<li>Вернитесь к Telegram боту</li>
|
||||
<li>
|
||||
Отправьте команду{' '}
|
||||
<code className="rounded bg-muted px-1 py-0.5 text-xs">/start</code>
|
||||
</li>
|
||||
<li>Нажмите на появившуюся кнопку "Отправить номер телефона"</li>
|
||||
<li>Закройте и откройте это приложение еще раз</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<UnregisteredClient botUrl={env.BOT_URL} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
37
apps/web/app/(auth)/unregistered/unregistered-client.tsx
Normal file
37
apps/web/app/(auth)/unregistered/unregistered-client.tsx
Normal file
@ -0,0 +1,37 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from '@repo/ui/components/ui/button';
|
||||
import { Bot, ExternalLink } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { signOut } from 'next-auth/react';
|
||||
|
||||
type UnregisteredClientProps = {
|
||||
readonly botUrl: string;
|
||||
};
|
||||
|
||||
export function UnregisteredClient({ botUrl }: UnregisteredClientProps) {
|
||||
const handleSignOut = () => {
|
||||
signOut({ callbackUrl: '/' });
|
||||
};
|
||||
const handleRefresh = () => {
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<Button asChild className="w-full">
|
||||
<Link href={botUrl} rel="noopener noreferrer" target="_blank">
|
||||
<Bot className="mr-2 size-4" />
|
||||
Перейти к боту
|
||||
<ExternalLink className="ml-2 size-4" />
|
||||
</Link>
|
||||
</Button>
|
||||
<Button className="w-full" onClick={handleRefresh} variant="outline">
|
||||
Обновить страницу
|
||||
</Button>
|
||||
<Button className="w-full" onClick={handleSignOut} variant="outline">
|
||||
Выйти из аккаунта
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
6
apps/web/app/(documents)/offer/layout.tsx
Normal file
6
apps/web/app/(documents)/offer/layout.tsx
Normal file
@ -0,0 +1,6 @@
|
||||
import { DocumentsLayout } from '@/components/documents/layout';
|
||||
import { type PropsWithChildren } from 'react';
|
||||
|
||||
export default function Layout({ children }: Readonly<PropsWithChildren>) {
|
||||
return <DocumentsLayout title="Публичная оферта">{children}</DocumentsLayout>;
|
||||
}
|
||||
99
apps/web/app/(documents)/offer/page.mdx
Normal file
99
apps/web/app/(documents)/offer/page.mdx
Normal file
@ -0,0 +1,99 @@
|
||||
import { env } from '@/config/env';
|
||||
|
||||
export const metadata = {
|
||||
title: 'Публичная оферта',
|
||||
description: 'Публичная оферта бота / мини-приложения «Запишись.онлайн» (@zapishis_online_bot)',
|
||||
};
|
||||
|
||||
### Договор-оферта на использование сервиса «Запишись.онлайн» (@zapishis_online_bot)
|
||||
|
||||
Настоящий документ является публичной офертой в соответствии с пунктом 2 статьи 437 Гражданского кодекса Российской Федерации и представляет собой предложение индивидуального предпринимателя (самозанятого) — далее именуемого «Администрация», заключить Договор на использование Сервиса (далее – «Договор», «Оферта») с любым физическим лицом, принявшим условия настоящей Оферты (далее – «Пользователь»).
|
||||
|
||||
#### 1. Термины и определения
|
||||
|
||||
1.1. Оферта — настоящий документ, постоянно размещенный в сети Интернет по адресу <a href={env.URL_OFFER}>{env.URL_OFFER}</a>.
|
||||
|
||||
1.2. Акцепт — полное и безоговорочное принятие условий Оферты Пользователем путем оплаты доступа через встроенный платежный бот ЮKassa в Telegram.
|
||||
|
||||
1.3. Сервис — Telegram-бот и мини-приложение, позволяющее пользователям создавать и принимать заказы, управлять расписанием и взаимодействовать друг с другом без необходимости регистрации.
|
||||
|
||||
1.4. Администрация — самозанятое лицо, являющееся разработчиком и правообладателем Сервиса.
|
||||
|
||||
1.5. Пользователь — любое физическое лицо, использующее Сервис в личных или профессиональных целях.
|
||||
|
||||
1.6. Доступ — право использования функционала Сервиса на определённый оплаченный период (например, неделя, месяц, год).
|
||||
|
||||
1.7. Оплата — денежные средства, перечисленные Пользователем через платёжный бот ЮKassa в Telegram.
|
||||
|
||||
#### 2. Акцепт оферты и заключение договора
|
||||
|
||||
2.1. Акцептом настоящей Оферты считается оплата Пользователем доступа к Сервису любым доступным способом.
|
||||
|
||||
2.2. С момента совершения оплаты Пользователь считается заключившим Договор с Администрацией на условиях, изложенных в настоящей Оферте.
|
||||
|
||||
2.3. Пользователь подтверждает, что ему понятны все условия настоящей Оферты и он принимает их без ограничений.
|
||||
|
||||
#### 3. Предмет договора
|
||||
|
||||
3.1. Администрация предоставляет Пользователю неисключительное право (доступ) на использование функционала Сервиса в пределах оплаченного периода времени.
|
||||
|
||||
3.2. Сервис предоставляется в онлайн-формате через Telegram-бота без установки дополнительного программного обеспечения.
|
||||
|
||||
3.3. Пользователь получает право использовать функционал Сервиса в личных целях, в том числе для организации и планирования заказов, встреч и тренировок.
|
||||
|
||||
#### 4. Порядок оплаты и использование
|
||||
|
||||
4.1. Оплата производится через встроенные инструменты Telegram-бота с использованием платёжной системы ЮKassa.
|
||||
|
||||
4.2. Комиссия платёжной системы включена в итоговую стоимость. Администрация не взимает дополнительных платежей.
|
||||
|
||||
4.3. Доступ активируется автоматически после успешного подтверждения оплаты.
|
||||
|
||||
4.4. Пользователь может продлить доступ путём повторной оплаты. Автоматическое продление не применяется.
|
||||
|
||||
4.5. Возврат денежных средств возможен только в случае технических ошибок, по письменному обращению на адрес поддержки.
|
||||
|
||||
#### 5. Права и обязанности сторон
|
||||
|
||||
5.1. Пользователь обязуется:
|
||||
|
||||
- не использовать Сервис в противоправных целях;
|
||||
- не вмешиваться в работу Сервиса и не предпринимать действий, направленных на нарушение его функционирования;
|
||||
- предоставлять достоверную информацию при оплате и использовании Сервиса;
|
||||
- при добавлении контактов других лиц (например, клиентов, мастеров) гарантировать, что у него есть согласие этих лиц на передачу и обработку их персональных данных в рамках Сервиса;
|
||||
|
||||
5.2. Администрация обязуется:
|
||||
|
||||
- обеспечивать бесперебойную работу Сервиса, за исключением периодов технического обслуживания;
|
||||
- обрабатывать персональные данные Пользователей в соответствии с Политикой конфиденциальности;
|
||||
- принимать обращения и запросы Пользователей по вопросам работы Сервиса. 6. Ответственность сторон;
|
||||
|
||||
6.1. Сервис предоставляется «как есть». Администрация не несёт ответственности за временные сбои, потерю данных или недоступность Сервиса, возникшие по причинам, не зависящим от неё.
|
||||
|
||||
6.2. Пользователь несёт полную ответственность за корректность совершаемых платежей и действий, совершаемых через свой Telegram-аккаунт.
|
||||
|
||||
#### 7. Обработка персональных данных
|
||||
|
||||
7.1. Администрация обрабатывает персональные данные Пользователя в соответствии с Федеральным законом №152-ФЗ «О персональных данных» и Политикой конфиденциальности.
|
||||
|
||||
7.2. Использование Сервиса означает согласие Пользователя на обработку его персональных данных.
|
||||
|
||||
#### 8. Срок действия и расторжение договора
|
||||
|
||||
8.1. Договор вступает в силу с момента оплаты доступа и действует в течение оплаченного периода.
|
||||
|
||||
8.2. Пользователь может прекратить использование Сервиса в любое время без возврата оплаченных средств.
|
||||
|
||||
8.3. Администрация вправе приостановить доступ в случае нарушения Пользователем условий настоящей Оферты.
|
||||
|
||||
#### 9. Заключительные положения
|
||||
|
||||
9.1. Настоящий Договор регулируется законодательством Российской Федерации.
|
||||
|
||||
9.2. Все споры и разногласия решаются путём переговоров, а при недостижении соглашения — в судебном порядке по месту нахождения Администрации.
|
||||
|
||||
9.3. Администрация оставляет за собой право изменять условия Оферты с размещением новой редакции на сайте.
|
||||
|
||||
#### 10. Контакты
|
||||
|
||||
Если у Вас есть вопросы по настоящему договору публичной оферты персональных данных, пожалуйста, свяжитесь с Разработчиком. Контакты указаны в описании бота.
|
||||
6
apps/web/app/(documents)/privacy/layout.tsx
Normal file
6
apps/web/app/(documents)/privacy/layout.tsx
Normal file
@ -0,0 +1,6 @@
|
||||
import { DocumentsLayout } from '@/components/documents/layout';
|
||||
import { type PropsWithChildren } from 'react';
|
||||
|
||||
export default function Layout({ children }: Readonly<PropsWithChildren>) {
|
||||
return <DocumentsLayout title="Политика конфиденциальности">{children}</DocumentsLayout>;
|
||||
}
|
||||
131
apps/web/app/(documents)/privacy/page.mdx
Normal file
131
apps/web/app/(documents)/privacy/page.mdx
Normal file
@ -0,0 +1,131 @@
|
||||
export const metadata = {
|
||||
title: 'Политика конфиденциальности',
|
||||
description:
|
||||
'Политика конфиденциальности бота / мини-приложения «Запишись.онлайн» (@zapishis_online_bot)',
|
||||
};
|
||||
|
||||
### Политика конфиденциальности бота / мини-приложения «Запишись.онлайн» (@zapishis_online_bot)
|
||||
|
||||
#### 1. Термины и определения
|
||||
|
||||
- **Telegram** – Telegram Messenger Inc. (платформа, на которой работает бот и мини-приложение).
|
||||
- **Платформа** – экосистема ботов и мини-приложений Telegram.
|
||||
- **Разработчик** – физическое лицо, самозанятый, владелец и оператор сервиса «Запишись.онлайн» (@zapishis_online_bot) - (далее — «Разработчик»).
|
||||
- **Сторонний сервис** – бот/мини-приложение Разработчика, предоставляемое в Платформе.
|
||||
- **Пользователь** – лицо, использующее Сторонний сервис через свою учетную запись Telegram (далее — «Вы»).
|
||||
- **Политика** – настоящий документ, регулирующий отношения между Разработчиком и Пользователем в части сбора и - обработки персональных данных.
|
||||
|
||||
#### 2. Общие положения
|
||||
|
||||
2.1. Настоящая Политика регулирует исключительно отношения между Разработчиком и Пользователем. Она не заменяет и не изменяет Политику конфиденциальности Telegram: [https://telegram.org/privacy](https://telegram.org/privacy).
|
||||
|
||||
2.2. Разработчик соблюдает применимые требования платформы Telegram к конфиденциальности и защите данных.
|
||||
|
||||
2.3. Использование Сервиса Пользователем и/или активация платного доступа означает согласие Пользователя с условиями настоящей Политики.
|
||||
|
||||
2.4. Если Вы не согласны с условиями Политики — прекратите использование Сервиса.
|
||||
|
||||
#### 3. Отказ от ответственности
|
||||
|
||||
3.1. Сторонний сервис является независимым приложением и не поддерживается, не одобряется и не аффилирован с Telegram (за исключением использования API и инфраструктуры Telegram).
|
||||
|
||||
3.2. Разработчик вправе изменять настоящую Политику — изменения вступают в силу с момента их публикации. Вы обязаны самостоятельно отслеживать обновления.
|
||||
|
||||
3.3. Используя Сервис, Вы подтверждаете, что ознакомлены и согласны с условиями использования Telegram для ботов и мини-приложений: [https://telegram.org/tos/bots](https://telegram.org/tos/bots), [https://telegram.org/tos/mini-apps](https://telegram.org/tos/mini-apps).
|
||||
|
||||
3.4. Вы гарантируете, что используете Сервис в соответствии с действующим законодательством и обладаете правом взаимодействовать с ним (например, достигли возраста, необходимого для использования услуг).
|
||||
|
||||
3.5. Вы обязуетесь предоставлять точную и актуальную информацию, если Сервис запрашивает её.
|
||||
|
||||
3.6. Любая информация, которую Вы делаете общедоступной самостоятельно (через профиль Telegram, публичные сообщения и т.п.), может стать доступна другим пользователям и не подпадает под защиту настоящей Политики в части конфиденциальности этой общедоступной информации.
|
||||
|
||||
#### 4. Сбор персональных данных
|
||||
|
||||
4.1. Telegram по умолчанию предоставляет сторонним сервисам ограниченный набор данных о Пользователе — подробнее: [https://telegram.org/privacy#6-bot-messages](https://telegram.org/privacy#6-bot-messages).
|
||||
|
||||
4.2. Сторонний сервис может дополнительно получать данные, которые Вы передаёте в чате бота или в мини-приложении (например, контакт, телефон), если Вы явно их отправляете.
|
||||
|
||||
4.3. В случае мини-приложения дополнительно могут передаваться данные в соответствии с правилами мини-приложений Telegram: [https://telegram.org/tos/mini-apps#4-privacy](https://telegram.org/tos/mini-apps#4-privacy).
|
||||
|
||||
4.4. Сторонний сервис может собирать также анонимную статистику использования (диагностика, события взаимодействия), не связываемую напрямую с персоной.
|
||||
|
||||
4.5. Пользователь может передавать данные третьих лиц (например, контактные данные клиентов или мастеров) для использования в Сервисе. При этом пользователь гарантирует, что эти лица дали согласие на обработку их персональных данных в рамках Сервиса.
|
||||
|
||||
#### 5. Какие данные мы собираем и как используем
|
||||
|
||||
5.1. Разработчик запрашивает, собирает и обрабатывает только те данные, которые необходимы для корректной работы функций Сервиса, в частности:
|
||||
|
||||
- Telegram ID и (опционально) отображаемое имя пользователя;
|
||||
- телефон, только если Вы предоставили его добровольно (например, при регистрации);
|
||||
- данные о заказах: дата/время, описание заказа, статус;
|
||||
- информация о факте покупки Pro-доступа: период доступа, тип покупки (детали платёжной транзакции обрабатывает платёжный оператор — ЮKassa);
|
||||
|
||||
5.2. Цели обработки:
|
||||
|
||||
- предоставление и поддержка работы Сервиса (создание заказов, напоминания, управление доступом);
|
||||
- подтверждение и учет оплат (взаимодействие с платёжным оператором для актуализации статуса доступа);
|
||||
- реализация реферальной программы (хранение связей «кто пригласил/кого пригласили»);
|
||||
- анализ использования и улучшение сервиса;
|
||||
- выполнение юридических обязательств (хранение информации о транзакциях и др.);
|
||||
|
||||
> **Важно:** детальные платёжные данные (реквизиты карт и т.д.) не хранятся у Разработчика — их обрабатывает платёжный оператор (ЮKassa) и Telegram-платежный бот.
|
||||
|
||||
#### 6. Передача данных третьим лицам
|
||||
|
||||
6.1. Разработчик не передаёт персональные данные третьим лицам, за исключением следующих случаев:
|
||||
|
||||
- платёжному оператору (ЮKassa) и связанным службам для обработки платежей;
|
||||
- Telegram как платформе для функционирования бота и мини-приложения;
|
||||
- в случае необходимости — исполнителям, оказывающим техническую поддержку, при условии подписания ими обязательств о конфиденциальности;
|
||||
- если передача требуется по закону (запросы уполномоченных органов и т.п.);
|
||||
|
||||
6.2. Разработчик не продаёт и не передаёт персональные данные для рекламных целей третьим лицам без Вашего отдельного согласия.
|
||||
|
||||
#### 7. Защита и хранение данных
|
||||
|
||||
7.1. Разработчик применяет разумные технические и организационные меры для защиты персональных данных (использование надежного VPS, ограничения доступа, резервное копирование и т.п.).
|
||||
|
||||
7.2. Доступ к персональным данным имеет только Разработчик (и/или доверенные исполнители технической поддержки при необходимости).
|
||||
|
||||
7.3. Данные хранятся на серверах, указанных Разработчиком. Если используются внешние сервисы/облачные хранилища — это будет указано в соответствующих местах Политики или сообщения при сборе данных.
|
||||
|
||||
#### 8. Права и обязанности сторон
|
||||
|
||||
8.1. Права Разработчика:
|
||||
|
||||
- вносить изменения в Политику с публикацией новой версии;
|
||||
- ограничивать доступ к API/сервису при подозрении в злоупотреблениях;
|
||||
- запросить подтверждение личности при необходимости обработки привилегированных запросов;
|
||||
|
||||
8.2. Обязанности Разработчика:
|
||||
|
||||
- обеспечивать доступность Политики и исполнять её условия;
|
||||
- обрабатывать законные запросы пользователей о доступе, изменении или удалении данных в разумные сроки (не позднее 30 дней, если иное не установлено законом);
|
||||
- соблюдать применимое законодательство о защите персональных данных;
|
||||
|
||||
8.3. Права Пользователя:
|
||||
|
||||
- запросить копию своих персональных данных, хранящихся у Разработчика;
|
||||
- потребовать исправления неточных данных;
|
||||
- потребовать удаления персональных данных в пределах, допустимых законом (с сохранением данных, необходимых для выполнения юридических обязательств, например, по учёту платежей);
|
||||
- отозвать согласие на обработку персональных данных, если такое согласие предоставлялось добровольно;
|
||||
- подать жалобу в уполномоченные органы по защите персональных данных, если считает, что его права нарушены;
|
||||
|
||||
8.4. Обязанности Пользователя:
|
||||
|
||||
- предоставлять точную и актуальную информацию;
|
||||
- не использовать Сервис в нарушении законодательства и условий Telegram.
|
||||
|
||||
#### 9. Реклама и использование данных для аналитики
|
||||
|
||||
9.1. На текущем этапе Разработчик не использует персональные данные для демонстрации таргетированной рекламы третьих лиц без явного согласия Пользователя.
|
||||
|
||||
9.2. Разработчик может собирать агрегированную (анонимную) статистику использования Сервиса для улучшения функционала.
|
||||
|
||||
#### 10. Изменения Политики
|
||||
|
||||
10.1. Разработчик вправе вносить изменения в настоящую Политику. Все изменения публикуются на этой странице и вступают в силу с момента публикации.
|
||||
|
||||
#### 11. Контакты
|
||||
|
||||
Если у Вас есть вопросы по Политике конфиденциальности или запросы в отношении персональных данных, пожалуйста, свяжитесь с Разработчиком. Контакты указаны в описании бота.
|
||||
@ -1,4 +1,4 @@
|
||||
import { ContactsFilter, ContactsList } from '@/components/contacts';
|
||||
import { ContactsList } from '@/components/contacts';
|
||||
import { ContactsContextProvider } from '@/context/contacts';
|
||||
import { Card } from '@repo/ui/components/ui/card';
|
||||
|
||||
@ -8,7 +8,7 @@ export default function ContactsPage() {
|
||||
<Card>
|
||||
<div className="flex flex-row items-center justify-between space-x-4 p-4">
|
||||
<h1 className="font-bold">Контакты</h1>
|
||||
<ContactsFilter />
|
||||
{/* <ContactsFilter /> */}
|
||||
</div>
|
||||
<div className="p-4 pt-0">
|
||||
<ContactsList />
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { getOrder } from '@/actions/api/orders';
|
||||
import { Container } from '@/components/layout';
|
||||
import { PageHeader } from '@/components/navigation';
|
||||
import {
|
||||
@ -9,23 +8,14 @@ import {
|
||||
OrderStatus,
|
||||
} from '@/components/orders';
|
||||
import { type OrderPageParameters } from '@/components/orders/types';
|
||||
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';
|
||||
|
||||
type Props = { params: Promise<OrderPageParameters> };
|
||||
|
||||
export default async function ProfilePage(props: Readonly<Props>) {
|
||||
const parameters = await props.params;
|
||||
const documentId = parameters.documentId;
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
await queryClient.prefetchQuery({
|
||||
queryFn: () => getOrder({ documentId }),
|
||||
queryKey: ['order', documentId],
|
||||
});
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<>
|
||||
<PageHeader title="Запись" />
|
||||
<Container>
|
||||
<OrderDateTime {...parameters} />
|
||||
@ -35,6 +25,6 @@ export default async function ProfilePage(props: Readonly<Props>) {
|
||||
<div className="pb-24" />
|
||||
<OrderButtons {...parameters} />
|
||||
</Container>
|
||||
</HydrationBoundary>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ import { Container } from '@/components/layout';
|
||||
import { PageHeader } from '@/components/navigation';
|
||||
import { OrderForm } from '@/components/orders';
|
||||
|
||||
export default async function AddOrdersPage() {
|
||||
export default function AddOrdersPage() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader title="Новая запись" />
|
||||
|
||||
156
apps/web/app/(main)/pro/page.tsx
Normal file
156
apps/web/app/(main)/pro/page.tsx
Normal file
@ -0,0 +1,156 @@
|
||||
import {
|
||||
getSubscription,
|
||||
getSubscriptionPrices,
|
||||
getSubscriptions,
|
||||
} from '@/actions/api/subscriptions';
|
||||
import { getSessionUser } from '@/actions/session';
|
||||
import { TryFreeButton } from '@/components/subscription';
|
||||
import { env } from '@/config/env';
|
||||
import { Enum_Subscriptionprice_Period as SubscriptionPricePeriod } from '@repo/graphql/types';
|
||||
import { Button } from '@repo/ui/components/ui/button';
|
||||
import { formatMoney } from '@repo/utils/money';
|
||||
import { ArrowRight, Crown, Infinity as InfinityIcon } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
|
||||
export default async function ProPage() {
|
||||
const { telegramId } = await getSessionUser();
|
||||
|
||||
const { subscriptions } = await getSubscriptions({
|
||||
filters: { customer: { telegramId: { eq: telegramId } } },
|
||||
});
|
||||
|
||||
const hasActiveSubscription = subscriptions?.length
|
||||
? ((await getSubscription({ telegramId }))?.hasActiveSubscription ?? false)
|
||||
: false;
|
||||
|
||||
const canUseTrial = !subscriptions?.length;
|
||||
|
||||
const { subscriptionPrices = [] } = await getSubscriptionPrices({
|
||||
filters: {
|
||||
active: { eq: true },
|
||||
period: { ne: SubscriptionPricePeriod.Trial },
|
||||
},
|
||||
});
|
||||
|
||||
const botUrl = new URL(env.BOT_URL);
|
||||
botUrl.searchParams.set('start', 'pro');
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-blue-50 to-indigo-100 dark:from-slate-900 dark:via-slate-800 dark:to-slate-900">
|
||||
{/* Hero Section */}
|
||||
<div className="px-4 py-8 sm:px-6 lg:px-8">
|
||||
<div className="mx-auto max-w-4xl text-center">
|
||||
<div className="mb-2 flex justify-center">
|
||||
<div className="relative">
|
||||
<div className="absolute inset-0 rounded-full bg-gradient-to-r from-purple-600 to-blue-600 opacity-30 blur-xl dark:from-purple-700 dark:to-blue-700" />
|
||||
<div className="relative rounded-full bg-gradient-to-r from-purple-600 to-blue-600 p-4 dark:from-purple-700 dark:to-blue-700">
|
||||
<Crown className="size-8 text-white" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1 className="mb-4 text-4xl font-bold tracking-tight text-gray-900 dark:text-white sm:text-6xl">
|
||||
<span className="bg-gradient-to-r from-purple-600 to-blue-600 bg-clip-text text-transparent dark:from-purple-700 dark:to-blue-700">
|
||||
Pro
|
||||
</span>{' '}
|
||||
Доступ
|
||||
</h1>
|
||||
|
||||
<p className="mx-auto mb-6 max-w-2xl text-xl text-gray-600 dark:text-gray-300">
|
||||
{hasActiveSubscription
|
||||
? 'Ваш Pro доступ активен!'
|
||||
: 'Разблокируйте больше возможностей'}
|
||||
</p>
|
||||
|
||||
{!hasActiveSubscription && (
|
||||
<div className="flex flex-col items-center justify-center gap-4 sm:flex-row">
|
||||
{canUseTrial && <TryFreeButton />}
|
||||
|
||||
<Button
|
||||
asChild
|
||||
className={`w-full border-2 text-base font-semibold sm:w-auto ${
|
||||
canUseTrial
|
||||
? 'border-gray-300 text-gray-700 hover:bg-gray-100 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700'
|
||||
: 'border-0 bg-gradient-to-r from-purple-600 to-blue-600 text-white hover:from-purple-700 hover:to-blue-700 dark:from-purple-700 dark:to-blue-700 dark:hover:from-purple-800 dark:hover:to-blue-800'
|
||||
}`}
|
||||
size="lg"
|
||||
variant={canUseTrial ? 'outline' : 'default'}
|
||||
>
|
||||
<Link href={botUrl.toString()} rel="noopener noreferrer" target="_blank">
|
||||
Приобрести Pro доступ через бота
|
||||
<ArrowRight className="ml-2 size-5" />
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mx-auto mt-12 max-w-2xl">
|
||||
<h2 className="mb-4 text-center text-2xl font-bold text-gray-900 dark:text-white">
|
||||
Преимущества
|
||||
</h2>
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-start gap-3 rounded-lg border border-gray-200 bg-white/50 p-4 dark:border-gray-700 dark:bg-slate-800/50">
|
||||
<div className="mt-1 shrink-0">
|
||||
<InfinityIcon className="size-5 text-purple-600 dark:text-purple-400" />
|
||||
</div>
|
||||
<p className="text-left text-base leading-relaxed text-gray-700 dark:text-gray-300">
|
||||
Доступно неограниченное количество записей в месяц
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* <div className="flex items-start gap-3 rounded-lg border border-gray-200 bg-white/50 p-4 dark:border-gray-700 dark:bg-slate-800/50">
|
||||
<div className="mt-1 shrink-0">
|
||||
<Star className="size-5 text-purple-600 dark:text-purple-400" />
|
||||
</div>
|
||||
<p className="text-left text-base leading-relaxed text-gray-700 dark:text-gray-300">
|
||||
Профиль и аватар выделяются цветом
|
||||
</p>
|
||||
</div> */}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{subscriptionPrices?.length > 0 && (
|
||||
<div className="mx-auto mt-12 max-w-2xl">
|
||||
<h2 className="mb-4 text-center text-2xl font-bold text-gray-900 dark:text-white">
|
||||
Цены
|
||||
</h2>
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
{subscriptionPrices.map((price) => (
|
||||
<div
|
||||
className={`relative rounded-xl border bg-white/60 p-4 text-left dark:bg-slate-800/60 ${
|
||||
price?.period === SubscriptionPricePeriod.Month
|
||||
? 'border-2 border-purple-400'
|
||||
: 'border-gray-200 dark:border-gray-700'
|
||||
}`}
|
||||
key={price?.documentId}
|
||||
>
|
||||
{price?.period === SubscriptionPricePeriod.Month && (
|
||||
<div className="absolute -top-2 right-3 rounded-full bg-purple-600 px-2 py-0.5 text-xs font-semibold text-white dark:bg-purple-500">
|
||||
Популярный
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-baseline justify-between">
|
||||
<div className="text-xl font-bold text-gray-900 dark:text-white">
|
||||
{formatMoney(price?.amount ?? 0)}
|
||||
</div>
|
||||
{typeof price?.days === 'number' && (
|
||||
<div className="text-sm text-gray-600 dark:text-gray-300">
|
||||
{price.days} дн.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{price?.description && (
|
||||
<div className="mt-2 text-sm text-gray-600 dark:text-gray-300">
|
||||
{price.description}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -1,11 +1,8 @@
|
||||
import { getCustomer } from '@/actions/api/customers';
|
||||
import { getSessionUser } from '@/actions/session';
|
||||
import { Container } from '@/components/layout';
|
||||
import { PageHeader } from '@/components/navigation';
|
||||
import { ContactDataCard, PersonCard, ProfileOrdersList } from '@/components/profile';
|
||||
import { BookButton } from '@/components/shared/book-button';
|
||||
import { isCustomerMaster } from '@repo/utils/customer';
|
||||
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';
|
||||
import { ProfileButtons } from '@/components/profile/profile-buttons';
|
||||
import { ReadonlyServicesList } from '@/components/profile/services';
|
||||
|
||||
// Тип параметров страницы
|
||||
type Props = { params: Promise<{ telegramId: string }> };
|
||||
@ -13,44 +10,18 @@ type Props = { params: Promise<{ telegramId: string }> };
|
||||
export default async function ProfilePage(props: Readonly<Props>) {
|
||||
const { telegramId } = await props.params;
|
||||
const contactTelegramId = Number(telegramId);
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
// Получаем профиль контакта
|
||||
const { customer: profile } = await queryClient.fetchQuery({
|
||||
queryFn: () => getCustomer({ telegramId: contactTelegramId }),
|
||||
queryKey: ['customer', contactTelegramId],
|
||||
});
|
||||
|
||||
// Получаем текущего пользователя
|
||||
const sessionUser = await getSessionUser();
|
||||
const { customer: currentUser } = await queryClient.fetchQuery({
|
||||
queryFn: () => getCustomer({ telegramId: sessionUser.telegramId }),
|
||||
queryKey: ['customer', sessionUser.telegramId],
|
||||
});
|
||||
|
||||
// Проверка наличия данных
|
||||
if (!profile || !currentUser) return null;
|
||||
|
||||
// Определяем роли и id
|
||||
const isMaster = isCustomerMaster(currentUser);
|
||||
const masterId = isMaster ? currentUser.documentId : profile.documentId;
|
||||
const clientId = isMaster ? profile.documentId : currentUser.documentId;
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<>
|
||||
<PageHeader title="Профиль контакта" />
|
||||
<Container className="px-0">
|
||||
<PersonCard telegramId={contactTelegramId} />
|
||||
<ContactDataCard telegramId={contactTelegramId} />
|
||||
<ReadonlyServicesList telegramId={contactTelegramId} />
|
||||
<ProfileOrdersList telegramId={contactTelegramId} />
|
||||
{masterId && clientId && (
|
||||
<BookButton
|
||||
clientId={clientId}
|
||||
label={isMaster ? 'Записать' : 'Записаться'}
|
||||
masterId={masterId}
|
||||
/>
|
||||
)}
|
||||
<div className="pb-24" />
|
||||
<ProfileButtons telegramId={contactTelegramId} />
|
||||
</Container>
|
||||
</HydrationBoundary>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,26 +1,13 @@
|
||||
import { getCustomer } from '@/actions/api/customers';
|
||||
import { getSessionUser } from '@/actions/session';
|
||||
import { Container } from '@/components/layout';
|
||||
import { LinksCard, PersonCard, ProfileDataCard } from '@/components/profile';
|
||||
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';
|
||||
|
||||
export default async function ProfilePage() {
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
const { telegramId } = await getSessionUser();
|
||||
|
||||
await queryClient.prefetchQuery({
|
||||
queryFn: () => getCustomer({ telegramId }),
|
||||
queryKey: ['customer', telegramId],
|
||||
});
|
||||
import { LinksCard, PersonCard, ProfileDataCard, SubscriptionInfoBar } from '@/components/profile';
|
||||
|
||||
export default function ProfilePage() {
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<Container className="px-0">
|
||||
<PersonCard />
|
||||
<ProfileDataCard />
|
||||
<LinksCard />
|
||||
</Container>
|
||||
</HydrationBoundary>
|
||||
<Container className="px-0">
|
||||
<PersonCard />
|
||||
<SubscriptionInfoBar />
|
||||
<ProfileDataCard />
|
||||
<LinksCard />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,45 +1,24 @@
|
||||
import { getCustomer } from '@/actions/api/customers';
|
||||
import { getSlot } from '@/actions/api/slots';
|
||||
import { getSessionUser } from '@/actions/session';
|
||||
import { Container } from '@/components/layout';
|
||||
import { PageHeader } from '@/components/navigation';
|
||||
import { SlotButtons, SlotDateTime, SlotOrdersList } from '@/components/schedule';
|
||||
import { type SlotPageParameters } from '@/components/schedule/types';
|
||||
import { BookButton } from '@/components/shared/book-button';
|
||||
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';
|
||||
|
||||
type Props = { params: Promise<SlotPageParameters> };
|
||||
|
||||
export default async function SlotPage(props: Readonly<Props>) {
|
||||
const parameters = await props.params;
|
||||
const documentId = parameters.documentId;
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
await queryClient.prefetchQuery({
|
||||
queryFn: () => getSlot({ documentId }),
|
||||
queryKey: ['slot', documentId],
|
||||
});
|
||||
|
||||
// Получаем текущего пользователя
|
||||
const sessionUser = await getSessionUser();
|
||||
const { customer: currentUser } = await queryClient.fetchQuery({
|
||||
queryFn: () => getCustomer({ telegramId: sessionUser.telegramId }),
|
||||
queryKey: ['customer', sessionUser.telegramId],
|
||||
});
|
||||
|
||||
const masterId = currentUser?.documentId;
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<>
|
||||
<PageHeader title="Слот" />
|
||||
<Container>
|
||||
<SlotDateTime {...parameters} />
|
||||
<SlotOrdersList {...parameters} />
|
||||
{masterId && <BookButton label="Создать запись" masterId={masterId} />}
|
||||
<BookButton label="Создать запись" />
|
||||
<div className="pb-24" />
|
||||
<SlotButtons {...parameters} />
|
||||
</Container>
|
||||
</HydrationBoundary>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,28 +1,20 @@
|
||||
import { getService } from '@/actions/api/services';
|
||||
import { Container } from '@/components/layout';
|
||||
import { PageHeader } from '@/components/navigation';
|
||||
import { ServiceButtons, ServiceDataCard } from '@/components/profile/services';
|
||||
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';
|
||||
|
||||
// Тип параметров страницы
|
||||
type Props = { params: Promise<{ serviceId: string }> };
|
||||
|
||||
export default async function ProfilePage(props: Readonly<Props>) {
|
||||
const { serviceId } = await props.params;
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
await queryClient.prefetchQuery({
|
||||
queryFn: () => getService({ documentId: serviceId }),
|
||||
queryKey: ['service', serviceId],
|
||||
});
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<>
|
||||
<PageHeader title="Услуга" />
|
||||
<Container className="px-0">
|
||||
<ServiceDataCard serviceId={serviceId} />
|
||||
<ServiceButtons serviceId={serviceId} />
|
||||
</Container>
|
||||
</HydrationBoundary>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
5
apps/web/app/api/health/route.ts
Normal file
5
apps/web/app/api/health/route.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export function GET() {
|
||||
return new NextResponse('OK');
|
||||
}
|
||||
@ -2,11 +2,9 @@ import { AuthProvider } from '@/providers/auth';
|
||||
import { ErrorProvider } from '@/providers/error';
|
||||
import { QueryProvider } from '@/providers/query';
|
||||
import { ThemeProvider } from '@/providers/theme-provider';
|
||||
import { I18nProvider } from '@/utils/i18n/provider';
|
||||
import '@repo/ui/globals.css';
|
||||
import { cn } from '@repo/ui/lib/utils';
|
||||
import { type Metadata } from 'next';
|
||||
import { getLocale } from 'next-intl/server';
|
||||
import { Inter } from 'next/font/google';
|
||||
import { type PropsWithChildren } from 'react';
|
||||
|
||||
@ -17,19 +15,15 @@ export const metadata: Metadata = {
|
||||
};
|
||||
|
||||
export default async function RootLayout({ children }: Readonly<PropsWithChildren>) {
|
||||
const locale = await getLocale();
|
||||
|
||||
return (
|
||||
<html lang={locale}>
|
||||
<html lang="ru">
|
||||
<body className={cn(inter.className, 'flex min-h-screen flex-col bg-app-background')}>
|
||||
<ErrorProvider>
|
||||
<I18nProvider>
|
||||
<ThemeProvider>
|
||||
<AuthProvider>
|
||||
<QueryProvider>{children}</QueryProvider>
|
||||
</AuthProvider>
|
||||
</ThemeProvider>
|
||||
</I18nProvider>
|
||||
<ThemeProvider>
|
||||
<AuthProvider>
|
||||
<QueryProvider>{children}</QueryProvider>
|
||||
</AuthProvider>
|
||||
</ThemeProvider>
|
||||
</ErrorProvider>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,25 +1,27 @@
|
||||
'use client';
|
||||
|
||||
import { useCustomerMutation } from '@/hooks/api/customers';
|
||||
import { useClientOnce } from '@/hooks/telegram';
|
||||
import { initData, useSignal } from '@telegram-apps/sdk-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export function UpdateProfile() {
|
||||
const initDataUser = useSignal(initData.user);
|
||||
const { mutate: updateProfile } = useCustomerMutation();
|
||||
const [hasUpdated, setHasUpdated] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasUpdated) {
|
||||
useClientOnce(() => {
|
||||
if (
|
||||
localStorage.getItem('firstLogin') === null ||
|
||||
localStorage.getItem('firstLogin') === 'true'
|
||||
) {
|
||||
updateProfile({
|
||||
data: {
|
||||
active: true,
|
||||
photoUrl: initDataUser?.photoUrl || undefined,
|
||||
},
|
||||
});
|
||||
setHasUpdated(true);
|
||||
localStorage.setItem('firstLogin', 'false');
|
||||
}
|
||||
}, [hasUpdated, initDataUser?.photoUrl, updateProfile]);
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -2,21 +2,39 @@
|
||||
|
||||
import { DataNotFound } from '../shared/alert';
|
||||
import { ContactRow } from '../shared/contact-row';
|
||||
import { useCustomerContacts } from '@/hooks/api/contacts';
|
||||
import { useContactsInfiniteQuery } from '@/hooks/api/customers';
|
||||
import { Button } from '@repo/ui/components/ui/button';
|
||||
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
|
||||
|
||||
export function ContactsList() {
|
||||
const { contacts, isLoading } = useCustomerContacts();
|
||||
const {
|
||||
data: { pages } = {},
|
||||
fetchNextPage,
|
||||
hasNextPage,
|
||||
isLoading,
|
||||
} = useContactsInfiniteQuery();
|
||||
|
||||
if (isLoading) return <LoadingSpinner />;
|
||||
|
||||
if (!contacts.length) return <DataNotFound title="Контакты не найдены" />;
|
||||
const contacts = pages?.flatMap((page) => page.customers);
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{contacts.map((contact) => (
|
||||
<ContactRow key={contact.documentId} {...contact} />
|
||||
))}
|
||||
<div className="flex flex-col space-y-2">
|
||||
{isLoading && <LoadingSpinner />}
|
||||
{!isLoading && !contacts?.length ? <DataNotFound title="Контакты не найдены" /> : null}
|
||||
{contacts?.map(
|
||||
(contact) =>
|
||||
contact && (
|
||||
<ContactRow
|
||||
description={contact.services.map((service) => service?.name).join(', ')}
|
||||
key={contact.documentId}
|
||||
{...contact}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
{hasNextPage && (
|
||||
<Button onClick={() => fetchNextPage()} variant="ghost">
|
||||
Загрузить еще
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -13,8 +13,8 @@ import { use } from 'react';
|
||||
|
||||
const filterLabels: Record<FilterType, string> = {
|
||||
all: 'Все',
|
||||
clients: 'Клиенты',
|
||||
masters: 'Мастера',
|
||||
invited: 'Приглашенные',
|
||||
invitedBy: 'Пригласили вас',
|
||||
};
|
||||
|
||||
export function ContactsFilter() {
|
||||
@ -29,9 +29,13 @@ export function ContactsFilter() {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => setFilter('all')}>Все</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setFilter('clients')}>Клиенты</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setFilter('masters')}>Мастера</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setFilter('all')}>{filterLabels['all']}</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setFilter('invited')}>
|
||||
{filterLabels['invited']}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setFilter('invitedBy')}>
|
||||
{filterLabels['invitedBy']}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
|
||||
18
apps/web/components/documents/layout.tsx
Normal file
18
apps/web/components/documents/layout.tsx
Normal file
@ -0,0 +1,18 @@
|
||||
import { Container } from '@/components/layout';
|
||||
import { PageHeader } from '@/components/navigation';
|
||||
import { type PropsWithChildren } from 'react';
|
||||
|
||||
export function DocumentsLayout({
|
||||
children,
|
||||
title,
|
||||
}: Readonly<PropsWithChildren> & { readonly title: string }) {
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={title} />
|
||||
<Container className="prose prose-neutral md:prose-lg dark:prose-invert max-w-none">
|
||||
{children}
|
||||
</Container>
|
||||
<div className="h-10" />
|
||||
</>
|
||||
);
|
||||
}
|
||||
17
apps/web/components/documents/links.tsx
Normal file
17
apps/web/components/documents/links.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import { env } from '@/config/env';
|
||||
|
||||
export function OfferLink() {
|
||||
return (
|
||||
<a href={env.URL_OFFER} rel="noreferrer" target="_blank">
|
||||
{env.URL_OFFER}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
export function SupportLink() {
|
||||
return (
|
||||
<a href={env.SUPPORT_TELEGRAM_URL} rel="noreferrer" target="_blank">
|
||||
{env.SUPPORT_TELEGRAM_URL}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@ -4,12 +4,16 @@ import { NavButton } from './nav-button';
|
||||
import { BookOpen, Newspaper, PlusCircle, User, Users } from 'lucide-react';
|
||||
import { usePathname } from 'next/navigation';
|
||||
|
||||
const hideOn = ['/pro'];
|
||||
|
||||
export function BottomNav() {
|
||||
const pathname = usePathname();
|
||||
|
||||
const isFirstLevel = pathname.split('/').length <= 2;
|
||||
if (!isFirstLevel) return null;
|
||||
|
||||
if (hideOn.includes(pathname)) return null;
|
||||
|
||||
return (
|
||||
<nav className="sticky inset-x-0 bottom-0 border-t border-border bg-background">
|
||||
<div className="grid grid-cols-5">
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
'use client';
|
||||
|
||||
import { BackButton } from './back-button';
|
||||
import { cn } from '@repo/ui/lib/utils';
|
||||
import { isTMA } from '@telegram-apps/sdk-react';
|
||||
@ -6,16 +7,16 @@ import { isTMA } from '@telegram-apps/sdk-react';
|
||||
type Props = { title: string | undefined };
|
||||
|
||||
export function PageHeader(props: Readonly<Props>) {
|
||||
const isTG = isTMA('simple');
|
||||
const hideBackButton = process.env.NODE_ENV === 'production' || isTMA('simple');
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'sticky top-0 z-50 flex h-12 items-center rounded-b-lg bg-transparent font-bold tracking-wide backdrop-blur-md',
|
||||
isTG ? 'px-4' : 'px-2',
|
||||
hideBackButton ? 'px-4' : 'px-2',
|
||||
)}
|
||||
>
|
||||
{!isTG && <BackButton />}
|
||||
{!hideBackButton && <BackButton />}
|
||||
{props.title}
|
||||
</div>
|
||||
);
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
/* eslint-disable complexity */
|
||||
/* eslint-disable canonical/id-match */
|
||||
'use client';
|
||||
|
||||
import FloatingActionPanel from '../shared/action-panel';
|
||||
import { type OrderComponentProps } from './types';
|
||||
import { useIsMaster } from '@/hooks/api/customers';
|
||||
import { useCustomerQuery } from '@/hooks/api/customers';
|
||||
import { useOrderMutation, useOrderQuery } from '@/hooks/api/orders';
|
||||
import { usePushWithData } from '@/hooks/url';
|
||||
import { Enum_Order_State } from '@repo/graphql/types';
|
||||
@ -12,13 +13,16 @@ import { isBeforeNow } from '@repo/utils/datetime-format';
|
||||
export function OrderButtons({ documentId }: Readonly<OrderComponentProps>) {
|
||||
const push = usePushWithData();
|
||||
|
||||
const isMaster = useIsMaster();
|
||||
|
||||
const { data: { customer } = {} } = useCustomerQuery();
|
||||
const { data: { order } = {} } = useOrderQuery({ documentId });
|
||||
|
||||
const { isPending, mutate: updateSlot } = useOrderMutation({ documentId });
|
||||
const { isPending, mutate: updateOrder } = useOrderMutation({ documentId });
|
||||
|
||||
if (!order) return null;
|
||||
if (!order || !customer) return null;
|
||||
|
||||
// Проверяем роль относительно конкретного заказа
|
||||
const isOrderMaster = order.slot?.master?.documentId === customer.documentId;
|
||||
const isOrderClient = order.client?.documentId === customer.documentId;
|
||||
|
||||
const isCreated = order?.state === Enum_Order_State.Created;
|
||||
const isApproved = order?.state === Enum_Order_State.Approved;
|
||||
@ -27,22 +31,22 @@ export function OrderButtons({ documentId }: Readonly<OrderComponentProps>) {
|
||||
const isCancelled = order?.state === Enum_Order_State.Cancelled;
|
||||
|
||||
function handleApprove() {
|
||||
if (isMaster) {
|
||||
updateSlot({ data: { state: Enum_Order_State.Approved } });
|
||||
if (isOrderMaster) {
|
||||
updateOrder({ data: { state: Enum_Order_State.Approved } });
|
||||
}
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
if (isMaster) {
|
||||
updateSlot({ data: { state: Enum_Order_State.Cancelled } });
|
||||
} else {
|
||||
updateSlot({ data: { state: Enum_Order_State.Cancelling } });
|
||||
if (isOrderMaster) {
|
||||
updateOrder({ data: { state: Enum_Order_State.Cancelled } });
|
||||
} else if (isOrderClient) {
|
||||
updateOrder({ data: { state: Enum_Order_State.Cancelling } });
|
||||
}
|
||||
}
|
||||
|
||||
function handleOnComplete() {
|
||||
if (isMaster) {
|
||||
updateSlot({ data: { state: Enum_Order_State.Completed } });
|
||||
if (isOrderMaster) {
|
||||
updateOrder({ data: { state: Enum_Order_State.Completed } });
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,11 +56,11 @@ export function OrderButtons({ documentId }: Readonly<OrderComponentProps>) {
|
||||
|
||||
const isOrderStale = order?.datetime_start && isBeforeNow(order?.datetime_start);
|
||||
|
||||
const canCancel = !isOrderStale && (isCreated || (isMaster && isCancelling) || isApproved);
|
||||
const canComplete = isMaster && isApproved;
|
||||
const canConfirm = !isOrderStale && isMaster && isCreated;
|
||||
const canCancel = !isOrderStale && (isCreated || (isOrderMaster && isCancelling) || isApproved);
|
||||
const canComplete = isOrderMaster && isApproved;
|
||||
const canConfirm = !isOrderStale && isOrderMaster && isCreated;
|
||||
const canRepeat = isCancelled || isCompleted;
|
||||
const canReturn = !isOrderStale && isMaster && isCancelled;
|
||||
const canReturn = !isOrderStale && isOrderMaster && isCancelled;
|
||||
|
||||
return (
|
||||
<FloatingActionPanel
|
||||
|
||||
@ -1,26 +1,32 @@
|
||||
'use client';
|
||||
import { DataNotFound } from '../shared/alert';
|
||||
import { ContactRow } from '../shared/contact-row';
|
||||
import { type OrderComponentProps } from './types';
|
||||
import { useOrderQuery } from '@/hooks/api/orders';
|
||||
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
|
||||
|
||||
export function OrderContacts({ documentId }: Readonly<OrderComponentProps>) {
|
||||
const { data: { order } = {} } = useOrderQuery({ documentId });
|
||||
const { data: { order } = {}, isLoading } = useOrderQuery({ documentId });
|
||||
|
||||
if (!order) return null;
|
||||
const noContacts = !order?.slot?.master && !order?.client;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-2">
|
||||
<h1 className="font-bold">Контакты</h1>
|
||||
<h1 className="font-bold">Участники</h1>
|
||||
<div className="space-y-2">
|
||||
{order.slot?.master && (
|
||||
{isLoading && <LoadingSpinner />}
|
||||
{!isLoading && noContacts ? <DataNotFound title="Пользователи не найдены" /> : null}
|
||||
{order?.slot?.master && (
|
||||
<ContactRow
|
||||
className="rounded-2xl bg-background p-2 px-4 dark:bg-primary/5"
|
||||
description="Мастер"
|
||||
{...order.slot?.master}
|
||||
/>
|
||||
)}
|
||||
{order.client && (
|
||||
{order?.client && (
|
||||
<ContactRow
|
||||
className="rounded-2xl bg-background p-2 px-4 dark:bg-primary/5"
|
||||
description="Клиент"
|
||||
{...order.client}
|
||||
/>
|
||||
)}
|
||||
|
||||
@ -6,7 +6,16 @@ import { useOrderQuery } from '@/hooks/api/orders';
|
||||
import { formatDate } from '@repo/utils/datetime-format';
|
||||
|
||||
export function OrderDateTime({ documentId }: Readonly<OrderComponentProps>) {
|
||||
const { data: { order } = {} } = useOrderQuery({ documentId });
|
||||
const { data: { order } = {}, isLoading } = useOrderQuery({ documentId });
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex animate-pulse flex-col space-y-1">
|
||||
<div className="h-5 w-28 rounded bg-muted" />
|
||||
<div className="h-9 w-48 rounded bg-muted" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!order) return null;
|
||||
|
||||
|
||||
@ -1,129 +1,172 @@
|
||||
/* eslint-disable canonical/id-match */
|
||||
'use client';
|
||||
|
||||
import { DataNotFound } from '@/components/shared/alert';
|
||||
import { UserAvatar } from '@/components/shared/user-avatar';
|
||||
import { CardSectionHeader } from '@/components/ui';
|
||||
import { ContactsContextProvider } from '@/context/contacts';
|
||||
import { useCustomerContacts } from '@/hooks/api/contacts';
|
||||
// eslint-disable-next-line import/extensions
|
||||
import AvatarPlaceholder from '@/public/avatar/avatar_placeholder.png';
|
||||
import { useContactsInfiniteQuery, useCustomerQuery } from '@/hooks/api/customers';
|
||||
import { useOrderStore } from '@/stores/order';
|
||||
import { withContext } from '@/utils/context';
|
||||
import { type CustomerFieldsFragment } from '@repo/graphql/types';
|
||||
import { type CustomerFieldsFragment, Enum_Customer_Role } from '@repo/graphql/types';
|
||||
import { Button } from '@repo/ui/components/ui/button';
|
||||
import { Card } from '@repo/ui/components/ui/card';
|
||||
import { Label } from '@repo/ui/components/ui/label';
|
||||
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
|
||||
import { cn } from '@repo/ui/lib/utils';
|
||||
import Image from 'next/image';
|
||||
import { useEffect } from 'react';
|
||||
import { getCustomerFullName } from '@repo/utils/customer';
|
||||
import { sift } from 'radashi';
|
||||
|
||||
type ContactsGridProps = {
|
||||
readonly contacts: CustomerFieldsFragment[];
|
||||
readonly hasNextPage?: boolean;
|
||||
readonly isLoading?: boolean;
|
||||
readonly onClick: () => void;
|
||||
readonly onFetchNextPage?: () => void;
|
||||
readonly onSelect: (contactId: null | string) => void;
|
||||
readonly selected?: null | string;
|
||||
readonly title: string;
|
||||
};
|
||||
|
||||
export function ContactsGridBase({ contacts, onSelect, selected, title }: ContactsGridProps) {
|
||||
type UseContactsProps = Partial<{
|
||||
showInactive: boolean;
|
||||
}>;
|
||||
|
||||
export function ClientsGrid() {
|
||||
const { contacts, fetchNextPage, hasNextPage, isLoading } = useContacts({ showInactive: true });
|
||||
|
||||
const clientId = useOrderStore((store) => store.clientId);
|
||||
const setClientId = useOrderStore((store) => store.setClientId);
|
||||
const masterId = useOrderStore((store) => store.masterId);
|
||||
|
||||
return (
|
||||
<ContactsGridBase
|
||||
contacts={contacts.filter((contact) => contact.documentId !== masterId)}
|
||||
hasNextPage={Boolean(hasNextPage)}
|
||||
isLoading={isLoading}
|
||||
onClick={() => {
|
||||
if (clientId) setClientId(null);
|
||||
}}
|
||||
onFetchNextPage={fetchNextPage}
|
||||
onSelect={(contactId) => setClientId(contactId)}
|
||||
selected={clientId}
|
||||
title="Выбор клиента"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function ContactsGridBase({
|
||||
contacts,
|
||||
hasNextPage,
|
||||
isLoading,
|
||||
onClick,
|
||||
onFetchNextPage,
|
||||
onSelect,
|
||||
selected,
|
||||
title,
|
||||
}: ContactsGridProps) {
|
||||
const { data: { customer } = {} } = useCustomerQuery();
|
||||
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<div className="flex flex-col gap-4">
|
||||
<CardSectionHeader title={title} />
|
||||
{isLoading && <LoadingSpinner />}
|
||||
{!isLoading && (!contacts || contacts.length === 0) ? (
|
||||
<DataNotFound title="Контакты не найдены" />
|
||||
) : null}
|
||||
<div className="grid max-h-screen grid-cols-4 gap-2 overflow-y-auto">
|
||||
{contacts.map((contact) => {
|
||||
if (!contact) return null;
|
||||
{!isLoading &&
|
||||
contacts?.map((contact) => {
|
||||
if (!contact) return null;
|
||||
|
||||
const isCurrentUser = contact?.name === 'Я';
|
||||
const isCurrentUser = contact.documentId === customer?.documentId;
|
||||
|
||||
return (
|
||||
<Label
|
||||
className="flex cursor-pointer flex-col items-center"
|
||||
key={contact?.documentId}
|
||||
>
|
||||
<input
|
||||
checked={selected === contact?.documentId}
|
||||
className="hidden"
|
||||
name="user"
|
||||
onChange={() => onSelect(contact?.documentId)}
|
||||
type="radio"
|
||||
value={contact?.documentId}
|
||||
/>
|
||||
<div
|
||||
className={cn(
|
||||
'w-20 h-20 rounded-full border-2 transition-all duration-75',
|
||||
selected === contact?.documentId ? 'border-primary' : 'border-transparent',
|
||||
)}
|
||||
return (
|
||||
<Label
|
||||
className="flex cursor-pointer flex-col items-center"
|
||||
key={contact.documentId}
|
||||
>
|
||||
<input
|
||||
checked={selected === contact.documentId}
|
||||
className="hidden"
|
||||
name="user"
|
||||
onChange={() => onSelect(contact.documentId)}
|
||||
onClick={onClick}
|
||||
type="radio"
|
||||
value={contact.documentId}
|
||||
/>
|
||||
<div
|
||||
className={cn(
|
||||
'size-full rounded-full p-1',
|
||||
isCurrentUser
|
||||
? 'bg-gradient-to-r from-purple-500 to-pink-500'
|
||||
: 'bg-transparent',
|
||||
'rounded-full border-2 transition-all duration-75',
|
||||
selected === contact.documentId ? 'border-primary' : 'border-transparent',
|
||||
)}
|
||||
>
|
||||
<Image
|
||||
alt={contact?.name}
|
||||
className="size-full rounded-full object-cover"
|
||||
height={80}
|
||||
src={contact?.photoUrl || AvatarPlaceholder}
|
||||
width={80}
|
||||
/>
|
||||
<UserAvatar {...contact} size="md" />
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
className={cn(
|
||||
'mt-2 max-w-20 break-words text-center text-sm font-medium',
|
||||
isCurrentUser && 'font-bold',
|
||||
)}
|
||||
>
|
||||
{contact?.name}
|
||||
</span>
|
||||
</Label>
|
||||
);
|
||||
})}
|
||||
<span
|
||||
className={cn(
|
||||
'mt-2 max-w-20 break-words text-center text-sm font-medium',
|
||||
isCurrentUser && 'font-bold',
|
||||
)}
|
||||
>
|
||||
{getCustomerFullName(contact)}
|
||||
</span>
|
||||
</Label>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{hasNextPage && onFetchNextPage && (
|
||||
<Button onClick={onFetchNextPage} variant="ghost">
|
||||
Загрузить еще
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export const MastersGrid = withContext(ContactsContextProvider)(function () {
|
||||
const { contacts, isLoading, setFilter } = useCustomerContacts();
|
||||
export function MastersGrid() {
|
||||
const { contacts, fetchNextPage, hasNextPage, isLoading } = useContacts();
|
||||
|
||||
const masterId = useOrderStore((store) => store.masterId);
|
||||
const setMasterId = useOrderStore((store) => store.setMasterId);
|
||||
|
||||
useEffect(() => {
|
||||
setFilter('masters');
|
||||
}, [setFilter]);
|
||||
|
||||
if (isLoading) return <LoadingSpinner />;
|
||||
const clientId = useOrderStore((store) => store.clientId);
|
||||
|
||||
return (
|
||||
<ContactsGridBase
|
||||
contacts={contacts}
|
||||
contacts={contacts.filter(
|
||||
(contact) => contact.documentId !== clientId && contact.role !== Enum_Customer_Role.Client,
|
||||
)}
|
||||
hasNextPage={Boolean(hasNextPage)}
|
||||
isLoading={isLoading}
|
||||
onClick={() => {
|
||||
if (masterId) setMasterId(null);
|
||||
}}
|
||||
onFetchNextPage={fetchNextPage}
|
||||
onSelect={(contactId) => setMasterId(contactId)}
|
||||
selected={masterId}
|
||||
title="Мастера"
|
||||
title="Выбор мастера"
|
||||
/>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export const ClientsGrid = withContext(ContactsContextProvider)(function () {
|
||||
const { contacts, isLoading, setFilter } = useCustomerContacts();
|
||||
const clientId = useOrderStore((store) => store.clientId);
|
||||
const setClientId = useOrderStore((store) => store.setClientId);
|
||||
function useContacts({ showInactive = false }: UseContactsProps = {}) {
|
||||
const { data: { customer } = {}, isLoading: isLoadingCustomer } = useCustomerQuery();
|
||||
|
||||
useEffect(() => {
|
||||
setFilter('clients');
|
||||
}, [setFilter]);
|
||||
const {
|
||||
data: { pages } = { pages: [] },
|
||||
isLoading: isLoadingContacts,
|
||||
...query
|
||||
} = useContactsInfiniteQuery();
|
||||
|
||||
if (isLoading) return <LoadingSpinner />;
|
||||
const isLoading = isLoadingContacts || isLoadingCustomer;
|
||||
|
||||
return (
|
||||
<ContactsGridBase
|
||||
contacts={contacts}
|
||||
onSelect={(contactId) => setClientId(contactId)}
|
||||
selected={clientId}
|
||||
title="Клиенты"
|
||||
/>
|
||||
);
|
||||
});
|
||||
const contacts = sift(pages.flatMap((page) => page.customers));
|
||||
|
||||
return {
|
||||
isLoading,
|
||||
...query,
|
||||
contacts: [{ ...customer, name: 'Я', surname: undefined } as CustomerFieldsFragment].concat(
|
||||
showInactive ? contacts : contacts.filter((contact) => contact.active),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@ -6,12 +6,13 @@ import { ServiceCard } from '@/components/shared/service-card';
|
||||
import { useServicesQuery } from '@/hooks/api/services';
|
||||
import { useOrderStore } from '@/stores/order';
|
||||
import { type ServiceFieldsFragment } from '@repo/graphql/types';
|
||||
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
|
||||
import { cn } from '@repo/ui/lib/utils';
|
||||
|
||||
export function ServicesSelect() {
|
||||
const masterId = useOrderStore((store) => store.masterId);
|
||||
|
||||
const { data: { services } = {} } = useServicesQuery({
|
||||
const { data: { services } = {}, isLoading } = useServicesQuery({
|
||||
filters: {
|
||||
active: {
|
||||
eq: true,
|
||||
@ -24,6 +25,8 @@ export function ServicesSelect() {
|
||||
},
|
||||
});
|
||||
|
||||
if (isLoading) return <LoadingSpinner />;
|
||||
|
||||
if (!services?.length) return <DataNotFound title="Услуги не найдены" />;
|
||||
|
||||
return (
|
||||
|
||||
@ -1,18 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import { DataNotFound } from '../shared/alert';
|
||||
import { ServiceCard } from '../shared/service-card';
|
||||
import { type OrderComponentProps } from './types';
|
||||
import { useOrderQuery } from '@/hooks/api/orders';
|
||||
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
|
||||
|
||||
export function OrderServices({ documentId }: Readonly<OrderComponentProps>) {
|
||||
const { data: { order } = {} } = useOrderQuery({ documentId });
|
||||
|
||||
if (!order) return null;
|
||||
const { data: { order } = {}, isLoading } = useOrderQuery({ documentId });
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-2">
|
||||
<h1 className="font-bold">Услуги</h1>
|
||||
{order.services?.map(
|
||||
{isLoading && <LoadingSpinner />}
|
||||
{!isLoading && !order?.services?.length ? <DataNotFound title="Услуги не найдены" /> : null}
|
||||
{order?.services?.map(
|
||||
(service) => service && <ServiceCard key={service.documentId} {...service} />,
|
||||
)}
|
||||
</div>
|
||||
|
||||
@ -5,7 +5,14 @@ import { getAlert } from '@/components/shared/status';
|
||||
import { useOrderQuery } from '@/hooks/api/orders';
|
||||
|
||||
export function OrderStatus({ documentId }: Readonly<OrderComponentProps>) {
|
||||
const { data: { order } = {} } = useOrderQuery({ documentId });
|
||||
const { data: { order } = {}, isLoading } = useOrderQuery({ documentId });
|
||||
|
||||
if (isLoading)
|
||||
return (
|
||||
<div className="flex animate-pulse flex-col space-y-1">
|
||||
<div className="h-10 w-full rounded bg-muted" />
|
||||
</div>
|
||||
);
|
||||
|
||||
return order?.state && getAlert(order.state);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useCustomerQuery, useIsMaster } from '@/hooks/api/customers';
|
||||
import { useCustomerQuery } from '@/hooks/api/customers';
|
||||
import { useOrdersQuery } from '@/hooks/api/orders';
|
||||
import { useDateTimeStore } from '@/stores/datetime';
|
||||
import { Calendar } from '@repo/ui/components/ui/calendar';
|
||||
@ -11,35 +11,25 @@ import { useMemo, useState } from 'react';
|
||||
export function DateSelect() {
|
||||
const { data: { customer } = {} } = useCustomerQuery();
|
||||
|
||||
const isMaster = useIsMaster();
|
||||
|
||||
const [currentMonthDate, setCurrentMonthDate] = useState(new Date());
|
||||
|
||||
const clientId = isMaster ? undefined : customer?.documentId;
|
||||
const masterId = isMaster ? customer?.documentId : undefined;
|
||||
|
||||
const { data: { orders } = { orders: [] } } = useOrdersQuery(
|
||||
{
|
||||
filters: {
|
||||
client: {
|
||||
documentId: {
|
||||
eq: clientId,
|
||||
},
|
||||
},
|
||||
// Показываем все записи где пользователь является клиентом или мастером
|
||||
or: [
|
||||
{ client: { documentId: { eq: customer?.documentId } } },
|
||||
{ slot: { master: { documentId: { eq: customer?.documentId } } } },
|
||||
],
|
||||
slot: {
|
||||
datetime_start: {
|
||||
gte: dayjs(currentMonthDate).startOf('month').toISOString(),
|
||||
lte: dayjs(currentMonthDate).endOf('month').toISOString(),
|
||||
},
|
||||
master: {
|
||||
documentId: {
|
||||
eq: masterId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Boolean(clientId) || Boolean(masterId),
|
||||
Boolean(customer?.documentId),
|
||||
);
|
||||
|
||||
const daysWithOrders = useMemo(() => {
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import { OrdersList as OrdersListComponent } from './orders-list';
|
||||
import { useCurrentAndNext } from './utils';
|
||||
import { useCustomerQuery, useIsMaster } from '@/hooks/api/customers';
|
||||
import { useCustomerQuery } from '@/hooks/api/customers';
|
||||
import { useOrdersInfiniteQuery } from '@/hooks/api/orders';
|
||||
import { useDateTimeStore } from '@/stores/datetime';
|
||||
import type * as GQL from '@repo/graphql/types';
|
||||
@ -10,7 +10,6 @@ import { getDateUTCRange } from '@repo/utils/datetime-format';
|
||||
|
||||
export function OrdersList() {
|
||||
const { data: { customer } = {} } = useCustomerQuery();
|
||||
const isMaster = useIsMaster();
|
||||
const selectedDate = useDateTimeStore((store) => store.date);
|
||||
const { endOfDay, startOfDay } = getDateUTCRange(selectedDate).day();
|
||||
|
||||
@ -22,10 +21,13 @@ export function OrdersList() {
|
||||
} = useOrdersInfiniteQuery(
|
||||
{
|
||||
filters: {
|
||||
client: isMaster ? undefined : { documentId: { eq: customer?.documentId } },
|
||||
// Показываем все записи где пользователь является клиентом или мастером
|
||||
or: [
|
||||
{ client: { documentId: { eq: customer?.documentId } } },
|
||||
{ slot: { master: { documentId: { eq: customer?.documentId } } } },
|
||||
],
|
||||
slot: {
|
||||
datetime_start: selectedDate ? { gte: startOfDay, lt: endOfDay } : undefined,
|
||||
master: isMaster ? { documentId: { eq: customer?.documentId } } : undefined,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -37,17 +39,15 @@ export function OrdersList() {
|
||||
|
||||
const { current, next } = useCurrentAndNext(orders);
|
||||
|
||||
if (!orders?.length || isLoading) return null;
|
||||
|
||||
return (
|
||||
<OrdersListComponent
|
||||
avatarSource={isMaster ? 'client' : 'master'}
|
||||
current={current}
|
||||
hasNextPage={hasNextPage}
|
||||
isLoading={isLoading}
|
||||
next={next}
|
||||
onLoadMore={() => fetchNextPage()}
|
||||
onLoadMore={fetchNextPage}
|
||||
orders={orders}
|
||||
title={isMaster ? 'Записи клиентов' : 'Ваши записи'}
|
||||
title={selectedDate ? `Записи на ${selectedDate.toLocaleDateString()}` : 'Все записи'}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
import { getOrderStatus, getStatusText, type OrderStatus } from './utils';
|
||||
import { DataNotFound } from '@/components/shared/alert';
|
||||
import { OrderCard } from '@/components/shared/order-card';
|
||||
import type * as GQL from '@repo/graphql/types';
|
||||
import { Button } from '@repo/ui/components/ui/button';
|
||||
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
|
||||
import { cn } from '@repo/ui/lib/utils';
|
||||
|
||||
type Order = GQL.OrderFieldsFragment;
|
||||
|
||||
type OrdersListProps = Pick<Parameters<typeof OrderCard>[0], 'avatarSource'> & {
|
||||
type OrdersListProps = {
|
||||
readonly current: null | Order;
|
||||
readonly hasNextPage?: boolean;
|
||||
readonly isLoading?: boolean;
|
||||
readonly next: null | Order;
|
||||
readonly onLoadMore?: () => void;
|
||||
readonly orders: Order[];
|
||||
@ -16,9 +19,9 @@ type OrdersListProps = Pick<Parameters<typeof OrderCard>[0], 'avatarSource'> & {
|
||||
};
|
||||
|
||||
export function OrdersList({
|
||||
avatarSource,
|
||||
current,
|
||||
hasNextPage = false,
|
||||
isLoading,
|
||||
next,
|
||||
onLoadMore,
|
||||
orders,
|
||||
@ -27,6 +30,8 @@ export function OrdersList({
|
||||
return (
|
||||
<div className="flex flex-col space-y-2">
|
||||
<h1 className="font-bold">{title}</h1>
|
||||
{isLoading && <LoadingSpinner />}
|
||||
{!isLoading && !orders.length ? <DataNotFound title="Заказы не найдены" /> : null}
|
||||
{orders?.map((order) => {
|
||||
if (!order) return null;
|
||||
|
||||
@ -34,7 +39,7 @@ export function OrdersList({
|
||||
|
||||
return (
|
||||
<DateStatusWrapper key={order.documentId} status={status}>
|
||||
<OrderCard avatarSource={avatarSource} showDate {...order} />
|
||||
<OrderCard showDate {...order} />
|
||||
</DateStatusWrapper>
|
||||
);
|
||||
})}
|
||||
|
||||
@ -1,16 +1,29 @@
|
||||
/* eslint-disable canonical/id-match */
|
||||
'use client';
|
||||
|
||||
import { type ProfileProps } from '../types';
|
||||
import { TextField } from '@/components/shared/data-fields';
|
||||
import { CheckboxWithText, TextField } from '@/components/shared/data-fields';
|
||||
import { CardSectionHeader } from '@/components/ui';
|
||||
import { useCustomerMutation, useCustomerQuery } from '@/hooks/api/customers';
|
||||
import { Enum_Customer_Role } from '@repo/graphql/types';
|
||||
import { Button } from '@repo/ui/components/ui/button';
|
||||
import { Card } from '@repo/ui/components/ui/card';
|
||||
import Link from 'next/link';
|
||||
import { useState } from 'react';
|
||||
|
||||
export function ContactDataCard({ telegramId }: Readonly<ProfileProps>) {
|
||||
const { data: { customer } = {} } = useCustomerQuery({ telegramId });
|
||||
const { data: { customer } = {}, isLoading } = useCustomerQuery({ telegramId });
|
||||
|
||||
if (isLoading)
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<div className="flex animate-pulse flex-col gap-4">
|
||||
<div className="h-4 w-16 rounded bg-muted" />
|
||||
<div className="h-6 w-32 rounded bg-muted" />
|
||||
<div className="h-10 w-full rounded bg-muted" />
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
|
||||
if (!customer) return null;
|
||||
|
||||
@ -31,10 +44,26 @@ export function ContactDataCard({ telegramId }: Readonly<ProfileProps>) {
|
||||
}
|
||||
|
||||
export function ProfileDataCard() {
|
||||
const { data: { customer } = {} } = useCustomerQuery();
|
||||
const { data: { customer } = {}, isLoading } = useCustomerQuery();
|
||||
const { cancelChanges, hasChanges, isPending, resetTrigger, saveChanges, updateField } =
|
||||
useProfileEdit();
|
||||
|
||||
if (isLoading)
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<div className="flex animate-pulse flex-col gap-4">
|
||||
<div className="h-6 w-32 rounded bg-muted" />
|
||||
<div className="h-4 w-16 rounded bg-muted" />
|
||||
<div className="h-10 w-full rounded bg-muted" />
|
||||
<div className="h-4 w-16 rounded bg-muted" />
|
||||
<div className="h-10 w-full rounded bg-muted" />
|
||||
<div className="h-4 w-16 rounded bg-muted" />
|
||||
<div className="h-10 w-full rounded bg-muted" />
|
||||
<div className="h-5 w-60 rounded bg-muted" />
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
|
||||
if (!customer) return null;
|
||||
|
||||
return (
|
||||
@ -48,15 +77,22 @@ export function ProfileDataCard() {
|
||||
onChange={(value) => updateField('name', value)}
|
||||
value={customer?.name ?? ''}
|
||||
/>
|
||||
<TextField
|
||||
id="surname"
|
||||
key={`surname-${resetTrigger}`}
|
||||
label="Фамилия"
|
||||
onChange={(value) => updateField('surname', value)}
|
||||
value={customer?.surname ?? ''}
|
||||
/>
|
||||
<TextField disabled id="phone" label="Телефон" readOnly value={customer?.phone ?? ''} />
|
||||
{/* <CheckboxWithText
|
||||
<CheckboxWithText
|
||||
checked={customer.role !== 'client'}
|
||||
description="Разрешить другим пользователям записываться к вам"
|
||||
onChange={(checked) =>
|
||||
updateField('role', checked ? Role.Master : Role.Client)
|
||||
updateField('role', checked ? Enum_Customer_Role.Master : Enum_Customer_Role.Client)
|
||||
}
|
||||
text="Быть мастером"
|
||||
/> */}
|
||||
/>
|
||||
{hasChanges && (
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button disabled={isPending} onClick={cancelChanges} variant="outline">
|
||||
|
||||
@ -2,3 +2,4 @@ export * from './data-card';
|
||||
export * from './links-card';
|
||||
export * from './orders-list';
|
||||
export * from './person-card';
|
||||
export * from './subscription-bar';
|
||||
|
||||
@ -1,24 +1,26 @@
|
||||
/* eslint-disable canonical/id-match */
|
||||
'use client';
|
||||
|
||||
import { LinkButton } from './link-button';
|
||||
import { useIsMaster } from '@/hooks/api/customers';
|
||||
import { useCustomerQuery } from '@/hooks/api/customers';
|
||||
import { Enum_Customer_Role } from '@repo/graphql/types';
|
||||
|
||||
export function LinksCard() {
|
||||
const isMaster = useIsMaster();
|
||||
const { data: { customer } = {} } = useCustomerQuery();
|
||||
|
||||
if (customer?.role === Enum_Customer_Role.Client) return null;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 p-4 py-0">
|
||||
<LinkButton
|
||||
description="Указать доступные дни и время для записи клиентов"
|
||||
description="Указать доступные дни и время для записи"
|
||||
href="/profile/schedule"
|
||||
text="График работы"
|
||||
visible={isMaster}
|
||||
/>
|
||||
<LinkButton
|
||||
description="Добавить и редактировать ваши услуги мастера"
|
||||
description="Добавить и редактировать ваши услуги"
|
||||
href="/profile/services"
|
||||
text="Услуги"
|
||||
visible={isMaster}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@ -4,12 +4,9 @@ type Props = {
|
||||
readonly description?: string;
|
||||
readonly href: string;
|
||||
readonly text: string;
|
||||
readonly visible?: boolean;
|
||||
};
|
||||
|
||||
export function LinkButton({ description, href, text, visible }: Props) {
|
||||
if (!visible) return null;
|
||||
|
||||
export function LinkButton({ description, href, text }: Props) {
|
||||
return (
|
||||
<Link href={href} rel="noopener noreferrer">
|
||||
<div className="flex min-h-24 w-full flex-col rounded-2xl bg-background p-4 px-6 shadow-lg backdrop-blur-2xl dark:bg-primary/5">
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user