@autobusal/order-confirm 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this package are documented here. This project follows
4
4
  [Keep a Changelog](https://keepachangelog.com/) and [Semantic Versioning](https://semver.org/).
5
5
 
6
+ ## [1.1.0] - 2026-07-25
7
+
8
+ ### Added
9
+
10
+ - **Post-purchase Telegram addon binding.** When a purchased order has a
11
+ Telegram notification addon still awaiting binding, the "purchased"
12
+ confirmation page now shows a "Connect Telegram" deep link (polls obtapi's
13
+ `GET /api/orders/telegram/status?hash=...` every 4s until bound). Mirrors
14
+ magus's account-level `AccountTelegram` binding flow, but order-scoped
15
+ since a guest checkout has no account to bind against.
16
+
6
17
  ## [1.0.1] - 2026-07-19
7
18
 
8
19
  ### Security
package/OrderConfirm.tsx CHANGED
@@ -5,6 +5,7 @@ import { BiErrorAlt } from 'react-icons/bi';
5
5
  import { IoReturnUpBackOutline } from 'react-icons/io5';
6
6
  import { Meta, Button } from '@autobusal/common';
7
7
  import Reason from './Reason';
8
+ import Telegram from './Telegram/Telegram';
8
9
  import { Title, Actions } from './styles';
9
10
  import { useUserStore } from '@autobusal/providers/stores/user';
10
11
 
@@ -62,6 +63,7 @@ const OrderConfirm = ({ t }: Props): (JSX.Element | null) => {
62
63
 
63
64
  <>
64
65
  { (type === 'cancelled' && message !== '') && <Reason message={ message } t={ t } /> }
66
+ { (type === 'purchased' && hash) && <Telegram hash={ hash } t={ t } /> }
65
67
  </>
66
68
 
67
69
  <Actions>
@@ -0,0 +1,43 @@
1
+ import { TFunction } from 'i18next';
2
+ import { Button } from '@autobusal/common';
3
+ import { useGetOrderTelegramStatus } from '../services';
4
+ import { Container } from './styles';
5
+
6
+ interface Props {
7
+ hash: string
8
+ t: TFunction<'common'>
9
+ }
10
+
11
+ // Edited: Ferjolt Ozuni - Date: 2026-07-25
12
+ // Mirrors magus's account-level AccountTelegram.tsx, but order-scoped: a
13
+ // guest checkout has no account to bind against, so this reflects the
14
+ // order_addons row's own pending-token/chat_id state instead (see
15
+ // obtapi's Orders\AddonsController::telegram()). Renders nothing if the
16
+ // Telegram addon wasn't purchased on this order, or once bound - the
17
+ // binding is a one-time step, not something to keep displaying.
18
+ const Telegram = ({ hash, t }: Props): (JSX.Element | null) => {
19
+ const { data, isFetching } = useGetOrderTelegramStatus(hash);
20
+
21
+ if (isFetching || !data?.purchased || data.bound) {
22
+ return null;
23
+ }
24
+
25
+ if (!data.link) {
26
+ return null;
27
+ }
28
+
29
+ return (
30
+ <Container className="box">
31
+ <p>{ t('order_confirm.telegram.instructions') }</p>
32
+
33
+ <a href={ data.link } target="_blank" rel="noreferrer">
34
+ <Button
35
+ type="button"
36
+ text={ t('order_confirm.telegram.connect') }
37
+ />
38
+ </a>
39
+ </Container>
40
+ );
41
+ };
42
+
43
+ export default Telegram;
@@ -0,0 +1,10 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const Container = styled.div`
4
+ margin-top: 15px;
5
+ text-align: center;
6
+
7
+ p {
8
+ margin-bottom: 10px;
9
+ }
10
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/order-confirm",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts"
package/services.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { useQuery, UseQueryResult } from '@tanstack/react-query';
2
+ import { apiClient } from '@autobusal/providers';
3
+
4
+ export interface OrderTelegramStatus {
5
+ purchased: boolean
6
+ available?: boolean
7
+ bound?: boolean
8
+ link?: string
9
+ }
10
+
11
+ // Edited: Ferjolt Ozuni - Date: 2026-07-25
12
+ // Order-scoped equivalent of magus's Account/Telegram/services.ts
13
+ // useGetTelegramStatus - a guest checkout has no account to bind against,
14
+ // so the pending token/chat_id live on the order_addons row instead (see
15
+ // obtapi's Orders\AddonsController::telegram()).
16
+ export const useGetOrderTelegramStatus = (hash: string): UseQueryResult<OrderTelegramStatus> => (
17
+ useQuery({
18
+ queryKey: ['order-telegram-status', hash],
19
+ queryFn: async () => (
20
+ await apiClient
21
+ .get('/api/orders/telegram/status', {
22
+ params: { hash }
23
+ })
24
+ .then(response => (
25
+ response.data
26
+ ))
27
+ ),
28
+ // Poll while unbound, so "bound" flips true right after the buyer taps
29
+ // the deep link and messages the bot - no manual refresh needed.
30
+ // refetchIntervalInBackground is required: tapping the link backgrounds
31
+ // this tab (switching to the Telegram app/site), which is exactly when
32
+ // the poll needs to keep running - react-query pauses refetchInterval
33
+ // on a hidden tab by default.
34
+ refetchInterval: (query) => (query.state.data?.bound ? false : 4000),
35
+ refetchIntervalInBackground: true
36
+ })
37
+ );