@redneckz/wildless-cms-uni-blocks 0.14.1026 → 0.14.1028

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.
Files changed (187) hide show
  1. package/bundle/blocks.schema.json +1 -1
  2. package/bundle/bundle.umd.js +353 -244
  3. package/bundle/bundle.umd.min.js +1 -1
  4. package/bundle/components/RatesTable/RatesTable.d.ts +6 -0
  5. package/bundle/components/RatesTable/RatesTableContent.d.ts +12 -0
  6. package/bundle/components/RatesTable/RatesTableItem.d.ts +9 -0
  7. package/bundle/components/RatesTable/renderDataPickForm.d.ts +1 -0
  8. package/bundle/components/RatesTable/renderDate.d.ts +6 -0
  9. package/bundle/components/RatesTable/renderLink.d.ts +1 -0
  10. package/bundle/hooks/useRates.d.ts +4 -0
  11. package/bundle/model/LinkProps.d.ts +2 -0
  12. package/bundle/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  13. package/bundle/ui-kit/Rate/Rate.d.ts +12 -0
  14. package/dist/components/Blocks.js +2 -0
  15. package/dist/components/Blocks.js.map +1 -1
  16. package/dist/components/Blocks.mobile.js +2 -0
  17. package/dist/components/Blocks.mobile.js.map +1 -1
  18. package/dist/components/RatesTable/RatesTable.d.ts +6 -0
  19. package/dist/components/RatesTable/RatesTable.js +17 -0
  20. package/dist/components/RatesTable/RatesTable.js.map +1 -0
  21. package/dist/components/RatesTable/RatesTableContent.d.ts +12 -0
  22. package/dist/components/RatesTable/RatesTableContent.js +2 -0
  23. package/dist/components/RatesTable/RatesTableContent.js.map +1 -0
  24. package/dist/components/RatesTable/RatesTableItem.d.ts +9 -0
  25. package/dist/components/RatesTable/RatesTableItem.js +16 -0
  26. package/dist/components/RatesTable/RatesTableItem.js.map +1 -0
  27. package/dist/components/RatesTable/renderDataPickForm.d.ts +1 -0
  28. package/dist/components/RatesTable/renderDataPickForm.js +8 -0
  29. package/dist/components/RatesTable/renderDataPickForm.js.map +1 -0
  30. package/dist/components/RatesTable/renderDate.d.ts +6 -0
  31. package/dist/components/RatesTable/renderDate.js +24 -0
  32. package/dist/components/RatesTable/renderDate.js.map +1 -0
  33. package/dist/components/RatesTable/renderLink.d.ts +1 -0
  34. package/dist/components/RatesTable/renderLink.js +8 -0
  35. package/dist/components/RatesTable/renderLink.js.map +1 -0
  36. package/dist/hooks/useRates.d.ts +4 -0
  37. package/dist/hooks/useRates.js +42 -0
  38. package/dist/hooks/useRates.js.map +1 -0
  39. package/dist/model/LinkProps.d.ts +2 -0
  40. package/dist/ui-kit/LinkButton/LinkButton.js +36 -2
  41. package/dist/ui-kit/LinkButton/LinkButton.js.map +1 -1
  42. package/dist/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  43. package/dist/ui-kit/Rate/Rate.d.ts +12 -0
  44. package/dist/ui-kit/Rate/Rate.js +11 -0
  45. package/dist/ui-kit/Rate/Rate.js.map +1 -0
  46. package/lib/common.css +1 -1
  47. package/lib/components/Blocks.js +2 -0
  48. package/lib/components/Blocks.js.map +1 -1
  49. package/lib/components/Blocks.mobile.js +2 -0
  50. package/lib/components/Blocks.mobile.js.map +1 -1
  51. package/lib/components/ButtonsBlock/ButtonsBlock.fixture.d.ts +1 -0
  52. package/lib/components/RatesTable/RatesTable.d.ts +6 -0
  53. package/lib/components/RatesTable/RatesTable.fixture.d.ts +6 -0
  54. package/lib/components/RatesTable/RatesTable.fixture.mobile.d.ts +6 -0
  55. package/lib/components/RatesTable/RatesTable.js +15 -0
  56. package/lib/components/RatesTable/RatesTable.js.map +1 -0
  57. package/lib/components/RatesTable/RatesTableContent.d.ts +12 -0
  58. package/lib/components/RatesTable/RatesTableContent.js +2 -0
  59. package/lib/components/RatesTable/RatesTableContent.js.map +1 -0
  60. package/lib/components/RatesTable/RatesTableItem.d.ts +9 -0
  61. package/lib/components/RatesTable/RatesTableItem.js +14 -0
  62. package/lib/components/RatesTable/RatesTableItem.js.map +1 -0
  63. package/lib/components/RatesTable/renderDataPickForm.d.ts +1 -0
  64. package/lib/components/RatesTable/renderDataPickForm.js +5 -0
  65. package/lib/components/RatesTable/renderDataPickForm.js.map +1 -0
  66. package/lib/components/RatesTable/renderDate.d.ts +6 -0
  67. package/lib/components/RatesTable/renderDate.js +21 -0
  68. package/lib/components/RatesTable/renderDate.js.map +1 -0
  69. package/lib/components/RatesTable/renderLink.d.ts +1 -0
  70. package/lib/components/RatesTable/renderLink.js +5 -0
  71. package/lib/components/RatesTable/renderLink.js.map +1 -0
  72. package/lib/hooks/useRates.d.ts +4 -0
  73. package/lib/hooks/useRates.js +39 -0
  74. package/lib/hooks/useRates.js.map +1 -0
  75. package/lib/model/LinkProps.d.ts +2 -0
  76. package/lib/ui-kit/LinkButton/LinkButton.js +36 -2
  77. package/lib/ui-kit/LinkButton/LinkButton.js.map +1 -1
  78. package/lib/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  79. package/lib/ui-kit/Rate/Rate.d.ts +12 -0
  80. package/lib/ui-kit/Rate/Rate.js +9 -0
  81. package/lib/ui-kit/Rate/Rate.js.map +1 -0
  82. package/mobile/bundle/bundle.umd.js +318 -209
  83. package/mobile/bundle/bundle.umd.min.js +1 -1
  84. package/mobile/bundle/components/RatesTable/RatesTable.d.ts +6 -0
  85. package/mobile/bundle/components/RatesTable/RatesTableContent.d.ts +12 -0
  86. package/mobile/bundle/components/RatesTable/RatesTableItem.d.ts +9 -0
  87. package/mobile/bundle/components/RatesTable/renderDataPickForm.d.ts +1 -0
  88. package/mobile/bundle/components/RatesTable/renderDate.d.ts +6 -0
  89. package/mobile/bundle/components/RatesTable/renderLink.d.ts +1 -0
  90. package/mobile/bundle/hooks/useRates.d.ts +4 -0
  91. package/mobile/bundle/model/LinkProps.d.ts +2 -0
  92. package/mobile/bundle/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  93. package/mobile/bundle/ui-kit/Rate/Rate.d.ts +12 -0
  94. package/mobile/dist/components/Blocks.js +2 -0
  95. package/mobile/dist/components/Blocks.js.map +1 -1
  96. package/mobile/dist/components/RatesTable/RatesTable.d.ts +6 -0
  97. package/mobile/dist/components/RatesTable/RatesTable.js +17 -0
  98. package/mobile/dist/components/RatesTable/RatesTable.js.map +1 -0
  99. package/mobile/dist/components/RatesTable/RatesTableContent.d.ts +12 -0
  100. package/mobile/dist/components/RatesTable/RatesTableContent.js +2 -0
  101. package/mobile/dist/components/RatesTable/RatesTableContent.js.map +1 -0
  102. package/mobile/dist/components/RatesTable/RatesTableItem.d.ts +9 -0
  103. package/mobile/dist/components/RatesTable/RatesTableItem.js +16 -0
  104. package/mobile/dist/components/RatesTable/RatesTableItem.js.map +1 -0
  105. package/mobile/dist/components/RatesTable/renderDataPickForm.d.ts +1 -0
  106. package/mobile/dist/components/RatesTable/renderDataPickForm.js +8 -0
  107. package/mobile/dist/components/RatesTable/renderDataPickForm.js.map +1 -0
  108. package/mobile/dist/components/RatesTable/renderDate.d.ts +6 -0
  109. package/mobile/dist/components/RatesTable/renderDate.js +24 -0
  110. package/mobile/dist/components/RatesTable/renderDate.js.map +1 -0
  111. package/mobile/dist/components/RatesTable/renderLink.d.ts +1 -0
  112. package/mobile/dist/components/RatesTable/renderLink.js +8 -0
  113. package/mobile/dist/components/RatesTable/renderLink.js.map +1 -0
  114. package/mobile/dist/hooks/useRates.d.ts +4 -0
  115. package/mobile/dist/hooks/useRates.js +42 -0
  116. package/mobile/dist/hooks/useRates.js.map +1 -0
  117. package/mobile/dist/model/LinkProps.d.ts +2 -0
  118. package/mobile/dist/ui-kit/LinkButton/LinkButton.js +36 -2
  119. package/mobile/dist/ui-kit/LinkButton/LinkButton.js.map +1 -1
  120. package/mobile/dist/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  121. package/mobile/dist/ui-kit/Rate/Rate.d.ts +12 -0
  122. package/mobile/dist/ui-kit/Rate/Rate.js +11 -0
  123. package/mobile/dist/ui-kit/Rate/Rate.js.map +1 -0
  124. package/mobile/lib/common.css +1 -1
  125. package/mobile/lib/components/Blocks.js +2 -0
  126. package/mobile/lib/components/Blocks.js.map +1 -1
  127. package/mobile/lib/components/RatesTable/RatesTable.d.ts +6 -0
  128. package/mobile/lib/components/RatesTable/RatesTable.js +15 -0
  129. package/mobile/lib/components/RatesTable/RatesTable.js.map +1 -0
  130. package/mobile/lib/components/RatesTable/RatesTableContent.d.ts +12 -0
  131. package/mobile/lib/components/RatesTable/RatesTableContent.js +2 -0
  132. package/mobile/lib/components/RatesTable/RatesTableContent.js.map +1 -0
  133. package/mobile/lib/components/RatesTable/RatesTableItem.d.ts +9 -0
  134. package/mobile/lib/components/RatesTable/RatesTableItem.js +14 -0
  135. package/mobile/lib/components/RatesTable/RatesTableItem.js.map +1 -0
  136. package/mobile/lib/components/RatesTable/renderDataPickForm.d.ts +1 -0
  137. package/mobile/lib/components/RatesTable/renderDataPickForm.js +5 -0
  138. package/mobile/lib/components/RatesTable/renderDataPickForm.js.map +1 -0
  139. package/mobile/lib/components/RatesTable/renderDate.d.ts +6 -0
  140. package/mobile/lib/components/RatesTable/renderDate.js +21 -0
  141. package/mobile/lib/components/RatesTable/renderDate.js.map +1 -0
  142. package/mobile/lib/components/RatesTable/renderLink.d.ts +1 -0
  143. package/mobile/lib/components/RatesTable/renderLink.js +5 -0
  144. package/mobile/lib/components/RatesTable/renderLink.js.map +1 -0
  145. package/mobile/lib/hooks/useRates.d.ts +4 -0
  146. package/mobile/lib/hooks/useRates.js +39 -0
  147. package/mobile/lib/hooks/useRates.js.map +1 -0
  148. package/mobile/lib/model/LinkProps.d.ts +2 -0
  149. package/mobile/lib/ui-kit/LinkButton/LinkButton.js +36 -2
  150. package/mobile/lib/ui-kit/LinkButton/LinkButton.js.map +1 -1
  151. package/mobile/lib/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  152. package/mobile/lib/ui-kit/Rate/Rate.d.ts +12 -0
  153. package/mobile/lib/ui-kit/Rate/Rate.js +9 -0
  154. package/mobile/lib/ui-kit/Rate/Rate.js.map +1 -0
  155. package/mobile/src/components/Blocks.ts +2 -0
  156. package/mobile/src/components/RatesTable/RatesTable.example.json +7 -0
  157. package/mobile/src/components/RatesTable/RatesTable.tsx +38 -0
  158. package/mobile/src/components/RatesTable/RatesTable.ui.json +7 -0
  159. package/mobile/src/components/RatesTable/RatesTableContent.ts +13 -0
  160. package/mobile/src/components/RatesTable/RatesTableItem.tsx +39 -0
  161. package/mobile/src/components/RatesTable/renderDataPickForm.tsx +9 -0
  162. package/mobile/src/components/RatesTable/renderDate.tsx +42 -0
  163. package/mobile/src/components/RatesTable/renderLink.tsx +8 -0
  164. package/mobile/src/hooks/useRates.ts +65 -0
  165. package/mobile/src/model/LinkProps.ts +2 -0
  166. package/mobile/src/ui-kit/LinkButton/LinkButton.tsx +54 -2
  167. package/mobile/src/ui-kit/LinkButton/LinkButtonContent.ts +12 -0
  168. package/mobile/src/ui-kit/Rate/Rate.tsx +27 -0
  169. package/package.json +1 -1
  170. package/src/components/Blocks.mobile.ts +2 -0
  171. package/src/components/Blocks.ts +2 -0
  172. package/src/components/ButtonsBlock/ButtonsBlock.fixture.tsx +21 -0
  173. package/src/components/RatesTable/RatesTable.example.json +7 -0
  174. package/src/components/RatesTable/RatesTable.fixture.mobile.tsx +26 -0
  175. package/src/components/RatesTable/RatesTable.fixture.tsx +26 -0
  176. package/src/components/RatesTable/RatesTable.tsx +38 -0
  177. package/src/components/RatesTable/RatesTable.ui.json +7 -0
  178. package/src/components/RatesTable/RatesTableContent.ts +13 -0
  179. package/src/components/RatesTable/RatesTableItem.tsx +39 -0
  180. package/src/components/RatesTable/renderDataPickForm.tsx +9 -0
  181. package/src/components/RatesTable/renderDate.tsx +42 -0
  182. package/src/components/RatesTable/renderLink.tsx +8 -0
  183. package/src/hooks/useRates.ts +65 -0
  184. package/src/model/LinkProps.ts +2 -0
  185. package/src/ui-kit/LinkButton/LinkButton.tsx +54 -2
  186. package/src/ui-kit/LinkButton/LinkButtonContent.ts +12 -0
  187. package/src/ui-kit/Rate/Rate.tsx +27 -0
@@ -36,6 +36,7 @@ import { LinkDocs } from './LinkDocs/LinkDocs';
36
36
  import { MobileAppTile } from './MobileAppTile/MobileAppTile';
37
37
  import { OfficesAtmsMap } from './OfficesAtmsMap/OfficesAtmsMap';
38
38
  import { ProductBlock } from './ProductBlock/ProductBlock';
39
+ import { RatesTable } from './RatesTable/RatesTable';
39
40
  import { RichTextBlock } from './RichTextBlock/RichTextBlock';
40
41
  import { RkoTariffCardsTable } from './RkoTariffCardsTable/RkoTariffCardsTable';
41
42
  import { RollupItem } from './RollupItem/RollupItem';
@@ -92,4 +93,5 @@ export const Blocks: BlocksRegistry = {
92
93
  CashbackCalculator,
93
94
  CalculatorRko,
94
95
  RkoTariffCardsTable,
96
+ RatesTable,
95
97
  };
@@ -0,0 +1,7 @@
1
+ {
2
+ "content": {
3
+ "infoMessage": "",
4
+ "title": "Курс покупки/продажи для операций с использованием платежных карт в сети Банка",
5
+ "href": ""
6
+ }
7
+ }
@@ -0,0 +1,38 @@
1
+ import { JSX } from '@redneckz/uni-jsx';
2
+ import { useRates } from '../../hooks/useRates';
3
+ import { BlockWrapper } from '../../ui-kit/BlockWrapper';
4
+ import { Heading } from '../../ui-kit/Heading/Heading';
5
+ import { type UniBlockProps } from '../../UniBlock/UniBlockProps';
6
+ import { style } from '../../utils/style';
7
+ import { type RatesTableContent } from './RatesTableContent';
8
+ import { RatesTableItem } from './RatesTableItem';
9
+ import { renderDataPickForm } from './renderDataPickForm';
10
+ import { renderLink } from './renderLink';
11
+
12
+ interface RatesTableProps extends RatesTableContent, UniBlockProps {}
13
+
14
+ export const RatesTable = JSX<RatesTableProps>(
15
+ ({ href, className = '', infoMessage, title, isArchive = false, ...rest }) => {
16
+ const ratesList = useRates(isArchive);
17
+
18
+ const isRatesValid = ratesList[0].length > 0;
19
+
20
+ return (
21
+ <BlockWrapper className={style('p-6xl space-y-xl', className)} defaultPadding="p-0" {...rest}>
22
+ <Heading className="mb-xl">{title}</Heading>
23
+ {isArchive ? renderDataPickForm() : null}
24
+ {ratesList.map((list, i) => (
25
+ <RatesTableItem
26
+ list={list}
27
+ isRatesValid={isRatesValid}
28
+ isArchive={isArchive}
29
+ key={String(i)}
30
+ infoMessage={infoMessage}
31
+ />
32
+ ))}
33
+
34
+ {href ? renderLink(href) : null}
35
+ </BlockWrapper>
36
+ );
37
+ },
38
+ );
@@ -0,0 +1,7 @@
1
+ {
2
+ "content": {
3
+ "href": {
4
+ "ui:field": "attachmentHref"
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,13 @@
1
+ import { type HrefProps } from '../../model/LinkProps';
2
+
3
+ /**
4
+ * @title Таблица курсов
5
+ */
6
+ export interface RatesTableContent extends HrefProps {
7
+ /** @title Информационное сообщение */
8
+ infoMessage?: string;
9
+ /** @title Заголовок */
10
+ title?: string;
11
+ /** @hidden */
12
+ isArchive?: boolean;
13
+ }
@@ -0,0 +1,39 @@
1
+ import { JSX } from '@redneckz/uni-jsx';
2
+ import { Paragraph } from '../../ui-kit/Paragraph/Paragraph';
3
+ import { Rate, RATES_COLUMN_STYLE, type RateItem } from '../../ui-kit/Rate/Rate';
4
+ import { Text } from '../../ui-kit/Text/Text';
5
+ import { style } from '../../utils/style';
6
+ import { type RatesTableContent } from './RatesTableContent';
7
+ import { renderDate } from './renderDate';
8
+
9
+ interface RatesTableItemProps extends RatesTableContent {
10
+ maxDate?: string;
11
+ isRatesValid?: boolean;
12
+ list: RateItem[];
13
+ }
14
+
15
+ export const RatesTableItem = JSX<RatesTableItemProps>(
16
+ ({ isArchive = false, isRatesValid, list = [], infoMessage }) => {
17
+ const maxDate = isRatesValid
18
+ ? list.map((item) => item.lastUpdatedAt).reduce((a, b) => (String(a) > String(b) ? a : b))
19
+ : '';
20
+
21
+ return (
22
+ <div className="space-y-xl mb-3xl">
23
+ {maxDate && renderDate({ dateString: maxDate, isArchive })}
24
+ <div className={style(RATES_COLUMN_STYLE)}>
25
+ <Text font="font-medium">Валюта</Text>
26
+ <Text font="font-medium">Покупка</Text>
27
+ <Text font="font-medium">Продажа</Text>
28
+ </div>
29
+ {list.length > 0 ? (
30
+ list.map((rate, i) => <Rate key={String(i)} {...rate} />)
31
+ ) : (
32
+ <Paragraph>Ошибка получения данных</Paragraph>
33
+ )}
34
+
35
+ <Paragraph color="text-secondary-text">{infoMessage}</Paragraph>
36
+ </div>
37
+ );
38
+ },
39
+ );
@@ -0,0 +1,9 @@
1
+ import { SubmitButton } from '../../ui-kit/Button/SubmitButton';
2
+ import { DatePicker } from '../../ui-kit/DatePicker/DatePicker';
3
+
4
+ export const renderDataPickForm = () => (
5
+ <div className="flex justify-start items-end space-x-xl">
6
+ <DatePicker label="Выберите день" maxDate={new Date()} />
7
+ <SubmitButton className="h-fit">Показать</SubmitButton>
8
+ </div>
9
+ );
@@ -0,0 +1,42 @@
1
+ import { Paragraph } from '../../ui-kit/Paragraph/Paragraph';
2
+ import { Text } from '../../ui-kit/Text/Text';
3
+
4
+ type RenderDateProps = {
5
+ dateString: string;
6
+ isArchive?: boolean;
7
+ };
8
+
9
+ const TIMEZONE = 'МСК';
10
+
11
+ export const renderDate = ({ dateString, isArchive = false }: RenderDateProps) => {
12
+ const date = new Date(String(dateString));
13
+
14
+ const formatTime = date.toLocaleTimeString('ru-RU', {
15
+ timeZone: 'Europe/Moscow',
16
+ hour: '2-digit',
17
+ minute: '2-digit',
18
+ hour12: false,
19
+ });
20
+
21
+ const formatDate = date.toLocaleDateString('ru-RU', {
22
+ timeZone: 'Europe/Moscow',
23
+ day: 'numeric',
24
+ month: 'long',
25
+ year: 'numeric',
26
+ });
27
+
28
+ return isArchive ? (
29
+ <div>
30
+ <Paragraph color="text-secondary-text" font="font-medium">
31
+ {formatDate}
32
+ </Paragraph>
33
+ <Paragraph color="text-secondary-text">
34
+ {formatTime} ({TIMEZONE})
35
+ </Paragraph>
36
+ </div>
37
+ ) : (
38
+ <Text color="text-secondary-text">
39
+ Курсы действительны на {formatTime} ({TIMEZONE}), {formatDate}
40
+ </Text>
41
+ );
42
+ };
@@ -0,0 +1,8 @@
1
+ import { Link } from '../../ui-kit/Link/Link';
2
+ import { Paragraph } from '../../ui-kit/Paragraph/Paragraph';
3
+
4
+ export const renderLink = (href: string) => (
5
+ <Paragraph>
6
+ Полный архив вы можете посмотреть <Link href={href}>здесь</Link>
7
+ </Paragraph>
8
+ );
@@ -0,0 +1,65 @@
1
+ import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
2
+ import { useLocalStore } from '@redneckz/uni-jsx/lib/Store/useLocalStore';
3
+ import { API_BASE_URI } from '../api/apiBaseUrl';
4
+ import { type RateItem } from '../ui-kit/Rate/Rate';
5
+ import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
6
+
7
+ type RatesStoreItem = {
8
+ rate: RateItemList[];
9
+ nextUpdate: number;
10
+ };
11
+
12
+ type RateItemList = RateItem[];
13
+
14
+ type RatesStoreSlice = {
15
+ rates: RatesStoreItem;
16
+ archiveRates: RatesStoreItem;
17
+ };
18
+
19
+ const RATES_URL = `${API_BASE_URI}/rates`;
20
+ const ARCHIVE_RATES_URL = `${API_BASE_URI}/historyrates`;
21
+ const EMPTY_RATES: RateItemList[] = [
22
+ [
23
+ {
24
+ currencyPair: 'Валютная пара',
25
+ buyRate: 0,
26
+ sellRate: 0,
27
+ },
28
+ ],
29
+ ];
30
+
31
+ export function useRates(isArchive: boolean): RateItemList[] {
32
+ const url = isArchive ? ARCHIVE_RATES_URL : RATES_URL;
33
+ const rateKey = isArchive ? 'archiveRates' : 'rates';
34
+
35
+ const ratesStore = useLocalStore<RatesStoreSlice>();
36
+
37
+ // проверяем, надо ли обновлять значения ставок
38
+ const shouldUpdate = getShouldUpdate(isArchive, ratesStore as RatesStoreSlice);
39
+
40
+ // костыль, не отправлять запрос на бэк, если уже был запрос менее 15 мин назад
41
+ const { data } = useAsyncData(
42
+ shouldUpdate ? url : '',
43
+ fetchJSONUnsafe as FetchJSONUnsafeType<RateItemList[]>,
44
+ );
45
+
46
+ // если есть data и значение надо обновить, то обновляем локалсторадж
47
+ if (shouldUpdate && data) {
48
+ const nextUpdate = getTimeAfter15Minutes();
49
+ ratesStore[rateKey] = { rate: data, nextUpdate };
50
+ }
51
+
52
+ // берем данные из локалсторадж
53
+ const rates = ratesStore[rateKey]?.rate;
54
+
55
+ // возвращаем данные из локалсторадж или заглушку
56
+ return Array.isArray(rates) ? rates : EMPTY_RATES;
57
+ }
58
+
59
+ // Отсчитываем 15 минут с текущего момента
60
+ const getTimeAfter15Minutes = () => Date.now() + 15 * 60 * 1000;
61
+
62
+ const getShouldUpdate = (isArchive: boolean, ratesStore: RatesStoreSlice | null) =>
63
+ isArchive
64
+ ? !ratesStore?.archiveRates || ratesStore?.archiveRates.nextUpdate <= Date.now()
65
+ : !ratesStore?.rates || ratesStore?.rates.nextUpdate <= Date.now();
@@ -16,6 +16,8 @@ export type Target = '' | '_self' | '_blank' | '_parent' | '_top';
16
16
  export type HrefProps = {
17
17
  /** @title URL (href) */
18
18
  href?: string;
19
+ /** @title Дополнительные ссылки для A/B-тестирования */
20
+ additionalHrefs?: string[];
19
21
  };
20
22
 
21
23
  export type LinkCommonProps = HrefProps & {
@@ -1,19 +1,35 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
+ import { useLocalStore } from '@redneckz/uni-jsx/lib/Store/useLocalStore';
2
3
  import { useLink } from '../../hooks/useLink';
3
4
  import { getAspectsAttributes } from '../../utils/dataAttributes';
4
5
  import { ButtonInner } from './ButtonInner';
5
6
  import { getDisabledButtonClasses } from './getDisabledButtonClasses';
6
7
  import { getRegularButtonClasses } from './getRegularButtonClasses';
8
+ import { type LinkStoreSlice } from './LinkButtonContent';
7
9
  import { type LinkButtonProps } from './LinkButtonProps';
8
10
  import { useFormSubmit } from './useFormSubmit';
9
11
 
12
+ type SaveLinksProps = {
13
+ linksStore: LinkStoreSlice;
14
+ id?: string;
15
+ href?: string;
16
+ additionalHrefs?: string[];
17
+ };
18
+
10
19
  /** @deprecated */
11
20
  export const LinkButton = JSX<LinkButtonProps>(
12
- ({ disabled, children, method = 'LINK', href, ...rest }) => {
21
+ ({ disabled, children, method = 'LINK', href, id, additionalHrefs, ...rest }) => {
13
22
  const handleFormSubmit = useFormSubmit({ method, href });
23
+ const linksStore = useLocalStore<LinkStoreSlice>();
24
+
25
+ saveLinksToStore({ linksStore, href, id, additionalHrefs });
26
+
27
+ const adjustedHref = additionalHrefs
28
+ ? (linksStore.links || []).find((store) => store.id === id)?.lastLink
29
+ : href;
14
30
 
15
31
  const link = useLink();
16
- const adjustedProps = link({ onClick: handleFormSubmit, href, ...rest });
32
+ const adjustedProps = link({ onClick: handleFormSubmit, href: adjustedHref, ...rest });
17
33
  const buttonInner = children ?? <ButtonInner {...adjustedProps} />;
18
34
 
19
35
  return disabled ? (
@@ -69,3 +85,39 @@ const DisabledButton = JSX<LinkButtonProps>(
69
85
  </button>
70
86
  ),
71
87
  );
88
+
89
+ const getRandomHref = (href = '', additionalHrefs: string[] = []) => {
90
+ const hrefs = [href, ...additionalHrefs];
91
+
92
+ return hrefs[Math.floor(Math.random() * hrefs.length)];
93
+ };
94
+
95
+ // Отсчитываем 7 длей с текущей даты
96
+ const getTimeAfter7days = () => Date.now() + 7 * 24 * 60 * 60 * 1000;
97
+
98
+ // Сохраняем или заменяем рандомную ссылку в localStorage
99
+ const saveLinksToStore = ({ linksStore, id, href, additionalHrefs }: SaveLinksProps) => {
100
+ const buttonLinkStore = (linksStore.links || []).find((store) => store.id === id);
101
+
102
+ // Если хранилища вообще нет
103
+ if (!linksStore.links) {
104
+ linksStore.links = [];
105
+ }
106
+
107
+ if ((!buttonLinkStore || buttonLinkStore.nextDueAt <= Date.now()) && additionalHrefs) {
108
+ // Получаем рандомную ссылку
109
+ const randomHref = getRandomHref(href, additionalHrefs);
110
+
111
+ // При наличии ссылки для этой кнопки в хранилище удаляем этот элемент из массива ссылок
112
+ const updatedLinks = linksStore.links?.filter((item) => item.id !== id);
113
+
114
+ // Добавляем новый элемент
115
+ updatedLinks.push({
116
+ id: id ?? '',
117
+ lastLink: randomHref,
118
+ nextDueAt: getTimeAfter7days(),
119
+ });
120
+ // Добавляем это все в хранилище
121
+ linksStore.links = updatedLinks;
122
+ }
123
+ };
@@ -22,4 +22,16 @@ export interface LinkButtonContent extends ButtonCommonContent {
22
22
  iconRight?: Picture;
23
23
  /** @title Верхний текст */
24
24
  aboveText?: string;
25
+ /** @title Уникальный идентификатор кнопки */
26
+ id?: string;
25
27
  }
28
+
29
+ type LinkStoreItem = {
30
+ id: string;
31
+ lastLink: string;
32
+ nextDueAt: number;
33
+ };
34
+
35
+ export type LinkStoreSlice = {
36
+ links: LinkStoreItem[] | null;
37
+ };
@@ -0,0 +1,27 @@
1
+ import { DIVIDER_STYLE } from '../../components/TariffsTable/TariffsTableRowContainer';
2
+ import { UniBlock } from '../../UniBlock/UniBlock';
3
+ import { type UniBlockProps } from '../../UniBlock/UniBlockProps';
4
+ import { style } from '../../utils/style';
5
+
6
+ export type RateItem = {
7
+ currencyPair?: string;
8
+ buyRate?: number;
9
+ sellRate?: number;
10
+ lastUpdatedAt?: string;
11
+ };
12
+
13
+ interface RateProps extends RateItem, UniBlockProps {}
14
+
15
+ export const RATES_COLUMN_STYLE = `grid grid-cols-3 gap-s`;
16
+
17
+ export const Rate = UniBlock<RateProps>(({ currencyPair = '', buyRate = 0, sellRate = 0 }) => (
18
+ <div className={style('mb-s', RATES_COLUMN_STYLE, DIVIDER_STYLE)}>
19
+ <div>{formatCurrencyPair(currencyPair)}</div>
20
+ <div>{formatRate(buyRate)}</div>
21
+ <div>{formatRate(sellRate)}</div>
22
+ </div>
23
+ ));
24
+
25
+ const formatCurrencyPair = (currency: string) => currency.replace('_TOD', '');
26
+
27
+ const formatRate = (rate: number) => rate.toFixed(4);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redneckz/wildless-cms-uni-blocks",
3
- "version": "0.14.1026",
3
+ "version": "0.14.1028",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "ЦК",
@@ -36,6 +36,7 @@ import { LinkDocs } from './LinkDocs/LinkDocs';
36
36
  import { MobileAppTile } from './MobileAppTile/MobileAppTile';
37
37
  import { OfficesAtmsMap } from './OfficesAtmsMap/OfficesAtmsMap';
38
38
  import { ProductBlock } from './ProductBlock/ProductBlock';
39
+ import { RatesTable } from './RatesTable/RatesTable';
39
40
  import { RichTextBlock } from './RichTextBlock/RichTextBlock';
40
41
  import { RkoTariffCardsTable } from './RkoTariffCardsTable/RkoTariffCardsTable';
41
42
  import { RollupItem } from './RollupItem/RollupItem';
@@ -92,4 +93,5 @@ export const Blocks: BlocksRegistry = {
92
93
  CashbackCalculator,
93
94
  CalculatorRko,
94
95
  RkoTariffCardsTable,
96
+ RatesTable,
95
97
  };
@@ -37,6 +37,7 @@ import { LinkDocs } from './LinkDocs/LinkDocs';
37
37
  import { MobileAppTile } from './MobileAppTile/MobileAppTile';
38
38
  import { OfficesAtmsMap } from './OfficesAtmsMap/OfficesAtmsMap';
39
39
  import { ProductBlock } from './ProductBlock/ProductBlock';
40
+ import { RatesTable } from './RatesTable/RatesTable';
40
41
  import { RichTextBlock } from './RichTextBlock/RichTextBlock';
41
42
  import { RkoTariffCardsTable } from './RkoTariffCardsTable/RkoTariffCardsTable';
42
43
  import { RollupItem } from './RollupItem/RollupItem';
@@ -96,4 +97,5 @@ export const Blocks: BlocksRegistry = {
96
97
  CashbackCalculator,
97
98
  CalculatorRko,
98
99
  RkoTariffCardsTable,
100
+ RatesTable,
99
101
  };
@@ -18,10 +18,31 @@ const buttons: LinkButtonContent[] = [
18
18
  },
19
19
  ];
20
20
 
21
+ const buttonsForABTesting: LinkButtonContent[] = [
22
+ {
23
+ href: '/premium-cards',
24
+ additionalHrefs: ['/debit-cards', '/deposits'],
25
+ text: 'Оформить',
26
+ target: '_blank',
27
+ version: 'primary',
28
+ id: 'oformite',
29
+ },
30
+ {
31
+ href: '/details',
32
+ text: 'Подробнее',
33
+ target: '_blank',
34
+ version: 'secondary',
35
+ },
36
+ ];
21
37
  export default {
22
38
  default: (
23
39
  <div className="container grid grid-cols-12">
24
40
  <ButtonsBlock className="col-span-12" buttons={buttons} />
25
41
  </div>
26
42
  ),
43
+ abTesting: (
44
+ <div className="container grid grid-cols-12">
45
+ <ButtonsBlock className="col-span-12" buttons={buttonsForABTesting} />
46
+ </div>
47
+ ),
27
48
  };
@@ -0,0 +1,7 @@
1
+ {
2
+ "content": {
3
+ "infoMessage": "",
4
+ "title": "Курс покупки/продажи для операций с использованием платежных карт в сети Банка",
5
+ "href": ""
6
+ }
7
+ }
@@ -0,0 +1,26 @@
1
+ import '../../setup-fixture';
2
+ import { RatesTable } from './RatesTable';
3
+
4
+ const ratesTableContent = {
5
+ infoMessage: 'Информация может содержать неточности, актуальный курс уточняйте в отделении Банка',
6
+ title: 'Курс покупки/продажи для операций с использованием платежных карт в сети Банка',
7
+ href: 'rshb.ru',
8
+ };
9
+
10
+ const archiveRatesTableContent = {
11
+ title: 'Архив курсов покупки/продажи для операций с использованием платежных карт в сети Банка',
12
+ isArchive: true,
13
+ };
14
+
15
+ export default {
16
+ default: (
17
+ <div className="container grid grid-cols-12">
18
+ <RatesTable className="col-span-12" {...ratesTableContent} />
19
+ </div>
20
+ ),
21
+ archive: (
22
+ <div className="container grid grid-cols-12">
23
+ <RatesTable className="col-span-12" {...archiveRatesTableContent} />
24
+ </div>
25
+ ),
26
+ };
@@ -0,0 +1,26 @@
1
+ import '../../setup-fixture';
2
+ import { RatesTable } from './RatesTable';
3
+
4
+ const ratesTableContent = {
5
+ infoMessage: 'Информация может содержать неточности, актуальный курс уточняйте в отделении Банка',
6
+ title: 'Курс покупки/продажи для операций с использованием платежных карт в сети Банка',
7
+ href: 'rshb.ru',
8
+ };
9
+
10
+ const archiveRatesTableContent = {
11
+ title: 'Архив курсов покупки/продажи для операций с использованием платежных карт в сети Банка',
12
+ isArchive: true,
13
+ };
14
+
15
+ export default {
16
+ default: (
17
+ <div className="container grid grid-cols-12">
18
+ <RatesTable className="col-span-12" {...ratesTableContent} />
19
+ </div>
20
+ ),
21
+ archive: (
22
+ <div className="container grid grid-cols-12">
23
+ <RatesTable className="col-span-12" {...archiveRatesTableContent} />
24
+ </div>
25
+ ),
26
+ };
@@ -0,0 +1,38 @@
1
+ import { JSX } from '@redneckz/uni-jsx';
2
+ import { useRates } from '../../hooks/useRates';
3
+ import { BlockWrapper } from '../../ui-kit/BlockWrapper';
4
+ import { Heading } from '../../ui-kit/Heading/Heading';
5
+ import { type UniBlockProps } from '../../UniBlock/UniBlockProps';
6
+ import { style } from '../../utils/style';
7
+ import { type RatesTableContent } from './RatesTableContent';
8
+ import { RatesTableItem } from './RatesTableItem';
9
+ import { renderDataPickForm } from './renderDataPickForm';
10
+ import { renderLink } from './renderLink';
11
+
12
+ interface RatesTableProps extends RatesTableContent, UniBlockProps {}
13
+
14
+ export const RatesTable = JSX<RatesTableProps>(
15
+ ({ href, className = '', infoMessage, title, isArchive = false, ...rest }) => {
16
+ const ratesList = useRates(isArchive);
17
+
18
+ const isRatesValid = ratesList[0].length > 0;
19
+
20
+ return (
21
+ <BlockWrapper className={style('p-6xl space-y-xl', className)} defaultPadding="p-0" {...rest}>
22
+ <Heading className="mb-xl">{title}</Heading>
23
+ {isArchive ? renderDataPickForm() : null}
24
+ {ratesList.map((list, i) => (
25
+ <RatesTableItem
26
+ list={list}
27
+ isRatesValid={isRatesValid}
28
+ isArchive={isArchive}
29
+ key={String(i)}
30
+ infoMessage={infoMessage}
31
+ />
32
+ ))}
33
+
34
+ {href ? renderLink(href) : null}
35
+ </BlockWrapper>
36
+ );
37
+ },
38
+ );
@@ -0,0 +1,7 @@
1
+ {
2
+ "content": {
3
+ "href": {
4
+ "ui:field": "attachmentHref"
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,13 @@
1
+ import { type HrefProps } from '../../model/LinkProps';
2
+
3
+ /**
4
+ * @title Таблица курсов
5
+ */
6
+ export interface RatesTableContent extends HrefProps {
7
+ /** @title Информационное сообщение */
8
+ infoMessage?: string;
9
+ /** @title Заголовок */
10
+ title?: string;
11
+ /** @hidden */
12
+ isArchive?: boolean;
13
+ }
@@ -0,0 +1,39 @@
1
+ import { JSX } from '@redneckz/uni-jsx';
2
+ import { Paragraph } from '../../ui-kit/Paragraph/Paragraph';
3
+ import { Rate, RATES_COLUMN_STYLE, type RateItem } from '../../ui-kit/Rate/Rate';
4
+ import { Text } from '../../ui-kit/Text/Text';
5
+ import { style } from '../../utils/style';
6
+ import { type RatesTableContent } from './RatesTableContent';
7
+ import { renderDate } from './renderDate';
8
+
9
+ interface RatesTableItemProps extends RatesTableContent {
10
+ maxDate?: string;
11
+ isRatesValid?: boolean;
12
+ list: RateItem[];
13
+ }
14
+
15
+ export const RatesTableItem = JSX<RatesTableItemProps>(
16
+ ({ isArchive = false, isRatesValid, list = [], infoMessage }) => {
17
+ const maxDate = isRatesValid
18
+ ? list.map((item) => item.lastUpdatedAt).reduce((a, b) => (String(a) > String(b) ? a : b))
19
+ : '';
20
+
21
+ return (
22
+ <div className="space-y-xl mb-3xl">
23
+ {maxDate && renderDate({ dateString: maxDate, isArchive })}
24
+ <div className={style(RATES_COLUMN_STYLE)}>
25
+ <Text font="font-medium">Валюта</Text>
26
+ <Text font="font-medium">Покупка</Text>
27
+ <Text font="font-medium">Продажа</Text>
28
+ </div>
29
+ {list.length > 0 ? (
30
+ list.map((rate, i) => <Rate key={String(i)} {...rate} />)
31
+ ) : (
32
+ <Paragraph>Ошибка получения данных</Paragraph>
33
+ )}
34
+
35
+ <Paragraph color="text-secondary-text">{infoMessage}</Paragraph>
36
+ </div>
37
+ );
38
+ },
39
+ );
@@ -0,0 +1,9 @@
1
+ import { SubmitButton } from '../../ui-kit/Button/SubmitButton';
2
+ import { DatePicker } from '../../ui-kit/DatePicker/DatePicker';
3
+
4
+ export const renderDataPickForm = () => (
5
+ <div className="flex justify-start items-end space-x-xl">
6
+ <DatePicker label="Выберите день" maxDate={new Date()} />
7
+ <SubmitButton className="h-fit">Показать</SubmitButton>
8
+ </div>
9
+ );