@cloud-ru/uikit-product-calculator 0.33.3

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 (205) hide show
  1. package/CHANGELOG.md +1508 -0
  2. package/LICENSE +201 -0
  3. package/README.md +85 -0
  4. package/package.json +75 -0
  5. package/src/components/Calculator/Calculator.tsx +79 -0
  6. package/src/components/Calculator/index.ts +1 -0
  7. package/src/components/CalculatorContent/CalculatorContent.tsx +38 -0
  8. package/src/components/CalculatorContent/index.ts +1 -0
  9. package/src/components/CalculatorContent/styles.module.scss +79 -0
  10. package/src/components/Catalog/Catalog.tsx +225 -0
  11. package/src/components/Catalog/components/PrivateCardHeader.tsx +63 -0
  12. package/src/components/Catalog/components/index.ts +1 -0
  13. package/src/components/Catalog/components/styles.module.scss +35 -0
  14. package/src/components/Catalog/index.ts +1 -0
  15. package/src/components/Catalog/styles.module.scss +104 -0
  16. package/src/components/Controls/AlertControl/AlertControl.tsx +44 -0
  17. package/src/components/Controls/AlertControl/index.ts +1 -0
  18. package/src/components/Controls/ArrayControl/ArrayControl.tsx +105 -0
  19. package/src/components/Controls/ArrayControl/index.ts +1 -0
  20. package/src/components/Controls/ArrayControl/styles.module.scss +33 -0
  21. package/src/components/Controls/CarouselControl/CarouselControl.tsx +173 -0
  22. package/src/components/Controls/CarouselControl/index.ts +1 -0
  23. package/src/components/Controls/CarouselControl/styles.module.scss +32 -0
  24. package/src/components/Controls/Control/Control.tsx +205 -0
  25. package/src/components/Controls/Control/index.ts +1 -0
  26. package/src/components/Controls/ObjectControl/ObjectControl.tsx +150 -0
  27. package/src/components/Controls/ObjectControl/index.ts +1 -0
  28. package/src/components/Controls/ObjectControl/styles.module.scss +18 -0
  29. package/src/components/Controls/ObjectDecorator/ObjectDecorator.tsx +23 -0
  30. package/src/components/Controls/ObjectDecorator/index.ts +1 -0
  31. package/src/components/Controls/ObjectDecorator/styles.module.scss +15 -0
  32. package/src/components/Controls/SegmentedControl/SegmentedControl.tsx +79 -0
  33. package/src/components/Controls/SegmentedControl/SegmentedControlCard.tsx +38 -0
  34. package/src/components/Controls/SegmentedControl/index.ts +1 -0
  35. package/src/components/Controls/SegmentedControl/styles.module.scss +8 -0
  36. package/src/components/Controls/SelectControl/SelectControl.tsx +172 -0
  37. package/src/components/Controls/SelectControl/index.ts +1 -0
  38. package/src/components/Controls/SelectControl/styles.module.scss +5 -0
  39. package/src/components/Controls/SliderControl/SliderControl.tsx +92 -0
  40. package/src/components/Controls/SliderControl/index.ts +1 -0
  41. package/src/components/Controls/StepperControl/StepperControl.tsx +160 -0
  42. package/src/components/Controls/StepperControl/index.ts +1 -0
  43. package/src/components/Controls/StepperControl/styles.module.scss +16 -0
  44. package/src/components/Controls/TableControl/TableControl.tsx +162 -0
  45. package/src/components/Controls/TableControl/helperComponents/StepperWithAllowedValues.tsx +50 -0
  46. package/src/components/Controls/TableControl/helperComponents/index.ts +1 -0
  47. package/src/components/Controls/TableControl/helperComponents/styles.module.scss +53 -0
  48. package/src/components/Controls/TableControl/index.ts +1 -0
  49. package/src/components/Controls/TableControl/styles.module.scss +104 -0
  50. package/src/components/Controls/ToggleCard/ToggleCard.tsx +46 -0
  51. package/src/components/Controls/ToggleCard/index.ts +1 -0
  52. package/src/components/Controls/ToggleCard/styles.module.scss +11 -0
  53. package/src/components/Controls/ToggleCardsControl/ToggleCardsControl.tsx +93 -0
  54. package/src/components/Controls/ToggleCardsControl/index.ts +1 -0
  55. package/src/components/Controls/ToggleCardsControl/styles.module.scss +40 -0
  56. package/src/components/Controls/ToggleControl/ToggleControl.tsx +59 -0
  57. package/src/components/Controls/ToggleControl/components/SwitchRow.tsx +98 -0
  58. package/src/components/Controls/ToggleControl/components/index.ts +1 -0
  59. package/src/components/Controls/ToggleControl/components/styles.module.scss +110 -0
  60. package/src/components/Controls/ToggleControl/index.ts +1 -0
  61. package/src/components/Controls/ToggleObjectControl/ToggleObjectControl.tsx +111 -0
  62. package/src/components/Controls/ToggleObjectControl/index.ts +1 -0
  63. package/src/components/Controls/ToggleObjectControl/styles.module.scss +13 -0
  64. package/src/components/Controls/constants.ts +16 -0
  65. package/src/components/Controls/index.tsx +26 -0
  66. package/src/components/Controls/types.ts +181 -0
  67. package/src/components/Controls/utils.ts +49 -0
  68. package/src/components/Disclaimer/Disclaimer.tsx +33 -0
  69. package/src/components/Disclaimer/index.ts +1 -0
  70. package/src/components/Disclaimer/styles.module.scss +14 -0
  71. package/src/components/HeaderContainer/index.tsx +32 -0
  72. package/src/components/HeaderContainer/styles.module.scss +24 -0
  73. package/src/components/PriceSummary/PriceSummary.tsx +158 -0
  74. package/src/components/PriceSummary/components/PricePeriodSelect/PricePeriodSelect.tsx +81 -0
  75. package/src/components/PriceSummary/components/PricePeriodSelect/index.ts +1 -0
  76. package/src/components/PriceSummary/components/ProductCard/ProductCard.tsx +85 -0
  77. package/src/components/PriceSummary/components/ProductCard/index.ts +1 -0
  78. package/src/components/PriceSummary/components/ProductCard/styles.module.scss +7 -0
  79. package/src/components/PriceSummary/components/ProductListActions/ProductListActions.tsx +118 -0
  80. package/src/components/PriceSummary/components/ProductListActions/index.ts +1 -0
  81. package/src/components/PriceSummary/components/ProductListActions/styles.module.scss +38 -0
  82. package/src/components/PriceSummary/components/index.ts +3 -0
  83. package/src/components/PriceSummary/hooks.ts +36 -0
  84. package/src/components/PriceSummary/index.ts +1 -0
  85. package/src/components/PriceSummary/styles.module.scss +110 -0
  86. package/src/components/PriceSummary/utils/getTotalPrice.ts +19 -0
  87. package/src/components/PriceSummary/utils/index.ts +2 -0
  88. package/src/components/PriceSummary/utils/transformToProductCardData.ts +36 -0
  89. package/src/components/ProductHeadline/ProductPageHeadline.tsx +134 -0
  90. package/src/components/ProductHeadline/components/PriceCount.tsx +93 -0
  91. package/src/components/ProductHeadline/components/index.ts +1 -0
  92. package/src/components/ProductHeadline/components/styles.module.scss +52 -0
  93. package/src/components/ProductHeadline/index.ts +1 -0
  94. package/src/components/ProductHeadline/styles.module.scss +32 -0
  95. package/src/components/ProductPage/ProductPage.tsx +105 -0
  96. package/src/components/ProductPage/index.ts +1 -0
  97. package/src/components/ProductPage/styles.module.scss +13 -0
  98. package/src/components/Welcome/Welcome.tsx +138 -0
  99. package/src/components/Welcome/index.ts +1 -0
  100. package/src/components/Welcome/styles.module.scss +155 -0
  101. package/src/components/index.ts +3 -0
  102. package/src/config/config.tsx +27 -0
  103. package/src/config/index.ts +2 -0
  104. package/src/config/platforms/advanced/catalog.ts +82 -0
  105. package/src/config/platforms/advanced/constants.ts +23 -0
  106. package/src/config/platforms/advanced/index.ts +5 -0
  107. package/src/config/platforms/advanced/platform.tsx +13 -0
  108. package/src/config/platforms/advanced/product-config/AdvancedCloudBackup.ts +76 -0
  109. package/src/config/platforms/advanced/product-config/AdvancedCloudContainerEngine.tsx +260 -0
  110. package/src/config/platforms/advanced/product-config/AdvancedCloudServer.tsx +526 -0
  111. package/src/config/platforms/advanced/product-config/AdvancedDataAsYouUse.ts +159 -0
  112. package/src/config/platforms/advanced/product-config/AdvancedDataLakeInsight.ts +134 -0
  113. package/src/config/platforms/advanced/product-config/AdvancedDataWarehouseService.ts +94 -0
  114. package/src/config/platforms/advanced/product-config/AdvancedDcsMemcached.ts +69 -0
  115. package/src/config/platforms/advanced/product-config/AdvancedDcsRedis.ts +220 -0
  116. package/src/config/platforms/advanced/product-config/AdvancedDmsKafka.tsx +186 -0
  117. package/src/config/platforms/advanced/product-config/AdvancedDmsRabbitMq.ts +202 -0
  118. package/src/config/platforms/advanced/product-config/AdvancedDocumentDatabase.tsx +323 -0
  119. package/src/config/platforms/advanced/product-config/AdvancedElasticLoadBalance.tsx +252 -0
  120. package/src/config/platforms/advanced/product-config/AdvancedElasticSearch.ts +365 -0
  121. package/src/config/platforms/advanced/product-config/AdvancedFunctionGraph.tsx +65 -0
  122. package/src/config/platforms/advanced/product-config/AdvancedMapReduce.tsx +394 -0
  123. package/src/config/platforms/advanced/product-config/AdvancedMySqlDataBase.ts +417 -0
  124. package/src/config/platforms/advanced/product-config/AdvancedNetwork.ts +146 -0
  125. package/src/config/platforms/advanced/product-config/AdvancedObjectStorage.ts +232 -0
  126. package/src/config/platforms/advanced/product-config/AdvancedPostgreSqlDatabase.ts +402 -0
  127. package/src/config/platforms/advanced/product-config/AdvancedScalableFile.tsx +161 -0
  128. package/src/config/platforms/advanced/product-config/AdvancedSqlDatabase.ts +380 -0
  129. package/src/config/platforms/advanced/product-config/index.ts +21 -0
  130. package/src/config/platforms/advanced/products.ts +267 -0
  131. package/src/config/platforms/evolution/catalog.tsx +107 -0
  132. package/src/config/platforms/evolution/constants.ts +80 -0
  133. package/src/config/platforms/evolution/index.ts +5 -0
  134. package/src/config/platforms/evolution/platform.tsx +13 -0
  135. package/src/config/platforms/evolution/product-config/EvolutionArenadataDb.ts +151 -0
  136. package/src/config/platforms/evolution/product-config/EvolutionArtifactRegistry.ts +57 -0
  137. package/src/config/platforms/evolution/product-config/EvolutionBareMetal.tsx +172 -0
  138. package/src/config/platforms/evolution/product-config/EvolutionCloudServer.tsx +407 -0
  139. package/src/config/platforms/evolution/product-config/EvolutionCloudServerFreeTier.tsx +185 -0
  140. package/src/config/platforms/evolution/product-config/EvolutionCloudServerGpu.tsx +301 -0
  141. package/src/config/platforms/evolution/product-config/EvolutionContainerApps.ts +84 -0
  142. package/src/config/platforms/evolution/product-config/EvolutionContainerAppsFreeTier.ts +29 -0
  143. package/src/config/platforms/evolution/product-config/EvolutionKubernetes.ts +388 -0
  144. package/src/config/platforms/evolution/product-config/EvolutionManagedMetastore.ts +38 -0
  145. package/src/config/platforms/evolution/product-config/EvolutionManagedRedis.ts +161 -0
  146. package/src/config/platforms/evolution/product-config/EvolutionManagedSpark.ts +360 -0
  147. package/src/config/platforms/evolution/product-config/EvolutionManagedTrino.ts +53 -0
  148. package/src/config/platforms/evolution/product-config/EvolutionMlInference.tsx +703 -0
  149. package/src/config/platforms/evolution/product-config/EvolutionPostgreSql.ts +217 -0
  150. package/src/config/platforms/evolution/product-config/EvolutionPublicIp.ts +39 -0
  151. package/src/config/platforms/evolution/product-config/EvolutionSnatGateway.ts +22 -0
  152. package/src/config/platforms/evolution/product-config/EvolutionStorageS3.ts +223 -0
  153. package/src/config/platforms/evolution/product-config/EvolutionStorageS3FreeTier.ts +97 -0
  154. package/src/config/platforms/evolution/product-config/index.ts +17 -0
  155. package/src/config/platforms/evolution/products.ts +260 -0
  156. package/src/config/platforms/index.ts +3 -0
  157. package/src/config/platforms/vmware/catalog.ts +19 -0
  158. package/src/config/platforms/vmware/constants.ts +6 -0
  159. package/src/config/platforms/vmware/index.ts +5 -0
  160. package/src/config/platforms/vmware/platform.tsx +13 -0
  161. package/src/config/platforms/vmware/product-config/VmWareCloudBackup.ts +56 -0
  162. package/src/config/platforms/vmware/product-config/VmWareVirtualDataCenter.ts +309 -0
  163. package/src/config/platforms/vmware/product-config/VmWareVirtualMachinesBackup.ts +58 -0
  164. package/src/config/platforms/vmware/product-config/VmWareVirtualWorkspaces.tsx +210 -0
  165. package/src/config/platforms/vmware/product-config/index.ts +4 -0
  166. package/src/config/platforms/vmware/products.ts +63 -0
  167. package/src/config/styles.module.scss +9 -0
  168. package/src/config/utils/disk.ts +94 -0
  169. package/src/config/utils/diskPostgreSqlMySQL.ts +94 -0
  170. package/src/config/utils/eip.ts +104 -0
  171. package/src/config/utils/index.ts +52 -0
  172. package/src/config/utils/obs.ts +100 -0
  173. package/src/constants.ts +56 -0
  174. package/src/contexts/CalculatorContext.tsx +193 -0
  175. package/src/contexts/ProductContext.ts +25 -0
  176. package/src/contexts/index.ts +2 -0
  177. package/src/hooks/index.ts +6 -0
  178. package/src/hooks/useAdaptive.ts +20 -0
  179. package/src/hooks/useCatalogCardClick.ts +37 -0
  180. package/src/hooks/useProductClick.ts +14 -0
  181. package/src/hooks/useProductDelete.ts +46 -0
  182. package/src/index.ts +6 -0
  183. package/src/services/constants.ts +5 -0
  184. package/src/services/getFetcherFn.ts +57 -0
  185. package/src/services/getInitPrice.ts +64 -0
  186. package/src/services/getOnDownloadFileClick.ts +37 -0
  187. package/src/services/getOnShareClick.ts +56 -0
  188. package/src/services/index.ts +4 -0
  189. package/src/types/CalculatorType.ts +16 -0
  190. package/src/types/CatalogConfig.ts +13 -0
  191. package/src/types/Category.ts +14 -0
  192. package/src/types/FetcherFn.ts +26 -0
  193. package/src/types/FormValues.ts +4 -0
  194. package/src/types/Platform.ts +24 -0
  195. package/src/types/Price.ts +18 -0
  196. package/src/types/Product.ts +39 -0
  197. package/src/types/ProductState.ts +11 -0
  198. package/src/types/State.ts +7 -0
  199. package/src/types/index.ts +10 -0
  200. package/src/utils/filterNonEmptyArrays.ts +13 -0
  201. package/src/utils/formatNumber.ts +5 -0
  202. package/src/utils/getPrice.ts +38 -0
  203. package/src/utils/index.ts +5 -0
  204. package/src/utils/parseKeyToDataTest.ts +14 -0
  205. package/src/utils/value.ts +11 -0
@@ -0,0 +1,32 @@
1
+ import { forwardRef, ReactNode } from 'react';
2
+
3
+ import { LAYOUT_TYPE } from '@cloud-ru/uikit-product-utils';
4
+
5
+ import { useCalculatorContext } from '../../contexts';
6
+ import styles from './styles.module.scss';
7
+
8
+ type HeaderContainerProps = {
9
+ children: ReactNode;
10
+ dataTestId?: string;
11
+ };
12
+
13
+ export const HeaderContainer = forwardRef<HTMLDivElement, HeaderContainerProps>(
14
+ ({ children, dataTestId }: HeaderContainerProps, ref) => {
15
+ const { layoutType } = useCalculatorContext();
16
+
17
+ const isTablet = layoutType !== LAYOUT_TYPE.Desktop && layoutType !== LAYOUT_TYPE.DesktopSmall;
18
+ const isMobile = layoutType === LAYOUT_TYPE.Mobile;
19
+
20
+ return (
21
+ <div
22
+ className={styles.header}
23
+ data-mobile={isMobile || undefined}
24
+ data-tablet={isTablet || undefined}
25
+ ref={ref}
26
+ data-test-id={dataTestId}
27
+ >
28
+ {children}
29
+ </div>
30
+ );
31
+ },
32
+ );
@@ -0,0 +1,24 @@
1
+ @use '@sbercloud/figma-tokens-cloud-platform/build/scss/styles-theme-variables' as stv;
2
+
3
+ .header {
4
+ border-bottom: solid 1px stv.$sys-neutral-decor-default;
5
+ display: flex;
6
+ gap: stv.$dimension-2m;
7
+ align-items: center;
8
+ justify-content: space-between;
9
+ box-sizing: border-box;
10
+ padding: stv.$dimension-4m;
11
+ height: 104px;
12
+
13
+ &[data-tablet] {
14
+ flex-direction: column;
15
+ height: auto;
16
+ align-items: inherit;
17
+ justify-content: inherit;
18
+ padding: stv.$dimension-3m;
19
+ }
20
+
21
+ &[data-mobile] {
22
+ padding: stv.$dimension-2m;
23
+ }
24
+ }
@@ -0,0 +1,158 @@
1
+ import cn from 'classnames';
2
+ import { useDeferredValue, useMemo, useRef } from 'react';
3
+
4
+ import { PlusSVG } from '@cloud-ru/uikit-product-icons';
5
+ import { LAYOUT_TYPE } from '@cloud-ru/uikit-product-utils';
6
+ import { ButtonFilled } from '@snack-uikit/button';
7
+ import { Scroll } from '@snack-uikit/scroll';
8
+ import { Tag } from '@snack-uikit/tag';
9
+ import { TruncateString } from '@snack-uikit/truncate-string';
10
+ import { Typography } from '@snack-uikit/typography';
11
+
12
+ import { PLATFORM } from '../../constants';
13
+ import { useCalculatorContext } from '../../contexts';
14
+ import { useProductClick, useProductDelete } from '../../hooks';
15
+ import { formatNumber, getPrice, parseKeyToDataTest } from '../../utils';
16
+ import { PricePeriodSelect, ProductCard, ProductListActions } from './components';
17
+ import { useScrollListToActiveProduct } from './hooks';
18
+ import styles from './styles.module.scss';
19
+ import { getTotalPrice, transformValueToProductCardData } from './utils';
20
+
21
+ export enum SummaryAppearance {
22
+ Welcome = 'welcome',
23
+ Default = 'default',
24
+ }
25
+
26
+ type PriceSummaryProps = {
27
+ className?: string;
28
+ appearance?: SummaryAppearance;
29
+ };
30
+
31
+ const PlatformSale = {
32
+ [PLATFORM.Evolution]: 25,
33
+ [PLATFORM.Advanced]: 25,
34
+ [PLATFORM.VmWare]: 20,
35
+ };
36
+
37
+ export function PriceSummary({ className, appearance = SummaryAppearance.Default }: PriceSummaryProps) {
38
+ const {
39
+ layoutType,
40
+ pricePeriod,
41
+ setCatalogOpen,
42
+ calculatorType,
43
+ selectedProduct,
44
+ products,
45
+ config: { products: productsProp, platforms },
46
+ actions: { onCatalogOpen, onStartClick },
47
+ } = useCalculatorContext();
48
+ const isMobile = layoutType !== LAYOUT_TYPE.Desktop && layoutType !== LAYOUT_TYPE.DesktopSmall;
49
+ const isPartners = calculatorType === 'partners';
50
+ const TitleComponent = isMobile ? Typography.SansTitleL : Typography.SansHeadlineS;
51
+
52
+ const total = getPrice({ price: getTotalPrice(products), pricePeriod, partners: isPartners });
53
+ const productCards = useMemo(() => transformValueToProductCardData(productsProp, products), [products, productsProp]);
54
+
55
+ const hasPayaGo = useMemo(() => {
56
+ const payaProducts = Object.values(productsProp).filter(product => product.hasPayaGo);
57
+
58
+ return Object.keys(products).some(productId => payaProducts.find(product => product.id === productId));
59
+ }, [products, productsProp]);
60
+
61
+ const scrollRef = useRef<HTMLDivElement>(null);
62
+ const activeRef = useRef<HTMLDivElement>(null);
63
+
64
+ useScrollListToActiveProduct({ scrollRef, activeRef });
65
+
66
+ const handleProductDelete = useProductDelete();
67
+ const handleProductClick = useProductClick();
68
+
69
+ const deferredTotal = useDeferredValue(total);
70
+
71
+ const handleCatalogOpen = () => {
72
+ onCatalogOpen?.();
73
+ setCatalogOpen(true);
74
+ };
75
+
76
+ const handleStartCatalog = () => {
77
+ onStartClick?.();
78
+ setCatalogOpen(true);
79
+ };
80
+
81
+ const serviceButtonProps = {
82
+ size: 'm',
83
+ icon: <PlusSVG />,
84
+ label: 'Добавить сервис',
85
+ 'data-test-id': parseKeyToDataTest('price', 'summary-button'),
86
+ } as const;
87
+
88
+ return (
89
+ <div
90
+ className={cn(styles.priceSummary, className)}
91
+ data-mobile={isMobile || undefined}
92
+ data-test-id={parseKeyToDataTest('price', 'summary')}
93
+ >
94
+ <div className={styles.headline}>
95
+ <TitleComponent data-test-id={parseKeyToDataTest('price', 'summary-title')}>Расчет</TitleComponent>
96
+ {appearance === SummaryAppearance.Welcome && (
97
+ <ButtonFilled appearance='primary' onClick={handleStartCatalog} {...serviceButtonProps} />
98
+ )}
99
+ {appearance === SummaryAppearance.Default && (
100
+ <ButtonFilled appearance='primary' fullWidth={isMobile} onClick={handleCatalogOpen} {...serviceButtonProps} />
101
+ )}
102
+ </div>
103
+
104
+ <Scroll className={styles.scroll} ref={scrollRef} data-test-id={parseKeyToDataTest('price', 'summary-products')}>
105
+ <div className={styles.content}>
106
+ {Object.entries(productCards)
107
+ .filter(([, products]) => products.length > 0)
108
+ .map(([platformId, cards]) => (
109
+ <div key={platformId} className={styles.platform}>
110
+ <Typography.SansTitleM data-test-id={parseKeyToDataTest('price', 'summary-platform')}>
111
+ Платформа {platforms.find(item => item.id === platformId)?.label}{' '}
112
+ {isPartners && <Tag label={`${PlatformSale[platformId]}% скидка`} appearance='red' size='xs' />}
113
+ </Typography.SansTitleM>
114
+
115
+ <div className={styles.body}>
116
+ {cards.map(({ id, idx, label }) => (
117
+ <div
118
+ key={id + idx}
119
+ ref={selectedProduct?.id === id && selectedProduct?.idx === idx ? activeRef : undefined}
120
+ >
121
+ <ProductCard
122
+ id={id}
123
+ idx={idx}
124
+ label={label}
125
+ selectedProduct={selectedProduct}
126
+ onProductClick={handleProductClick}
127
+ onProductDelete={handleProductDelete}
128
+ />
129
+ </div>
130
+ ))}
131
+ </div>
132
+ </div>
133
+ ))}
134
+ </div>
135
+ </Scroll>
136
+
137
+ <div className={styles.footer} data-test-id={parseKeyToDataTest('price', 'summary-footer')}>
138
+ <div>
139
+ <div className={styles.caption} data-test-id={parseKeyToDataTest('price', 'summary-title')}>
140
+ Общая стоимость с&nbsp;НДС
141
+ </div>
142
+ <div className={styles.footerHeadline}>
143
+ <div className={styles.total} data-test-id={parseKeyToDataTest('price', 'summary-footer-total')}>
144
+ <Typography.SansHeadlineS>
145
+ <TruncateString text={formatNumber(deferredTotal)} maxLines={1} />
146
+ </Typography.SansHeadlineS>
147
+ <Typography.SansTitleL>₽</Typography.SansTitleL>
148
+ </div>
149
+
150
+ <PricePeriodSelect hasPayaGo={hasPayaGo} />
151
+ </div>
152
+ </div>
153
+
154
+ <ProductListActions disabled={appearance === SummaryAppearance.Welcome} />
155
+ </div>
156
+ </div>
157
+ );
158
+ }
@@ -0,0 +1,81 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+
3
+ import { ChevronDownSVG, ChevronUpSVG } from '@cloud-ru/uikit-product-icons';
4
+ import { AdaptiveDroplist } from '@cloud-ru/uikit-product-mobile-dropdown';
5
+ import { ButtonFunction } from '@snack-uikit/button';
6
+ import { Tooltip } from '@snack-uikit/tooltip';
7
+
8
+ import { useCalculatorContext } from '../../../../contexts';
9
+ import { PRICE_PERIOD } from '../../../../types/Price';
10
+ import { parseKeyToDataTest } from '../../../../utils';
11
+
12
+ export const PRICE_NAME = {
13
+ [PRICE_PERIOD.Month]: 'В месяц',
14
+ [PRICE_PERIOD.Day]: 'В день',
15
+ [PRICE_PERIOD.Hour]: 'В час',
16
+ };
17
+
18
+ export const PRICE_PERIOD_ITEMS = [
19
+ {
20
+ id: PRICE_PERIOD.Month,
21
+ content: 'В месяц',
22
+ },
23
+ {
24
+ id: PRICE_PERIOD.Day,
25
+ content: 'В день',
26
+ },
27
+ {
28
+ id: PRICE_PERIOD.Hour,
29
+ content: 'В час',
30
+ },
31
+ ];
32
+
33
+ export function PricePeriodSelect({ hasPayaGo }: { hasPayaGo: boolean }) {
34
+ const { layoutType, pricePeriod, setPricePeriod } = useCalculatorContext();
35
+ const ref = useRef<HTMLButtonElement>(null);
36
+ const dataTestAttribute = parseKeyToDataTest('price', 'summary-footer-total');
37
+
38
+ const [open, setOpen] = useState<boolean>(false);
39
+
40
+ useEffect(() => {
41
+ if (hasPayaGo) {
42
+ setPricePeriod(PRICE_PERIOD.Month);
43
+ }
44
+
45
+ setOpen(false);
46
+ }, [hasPayaGo, setPricePeriod]);
47
+
48
+ return (
49
+ <AdaptiveDroplist
50
+ layoutType={layoutType}
51
+ size='m'
52
+ selection={{
53
+ mode: 'single',
54
+ value: pricePeriod,
55
+ onChange: v => {
56
+ v && setPricePeriod(v);
57
+ setOpen(false);
58
+ },
59
+ }}
60
+ open={hasPayaGo ? false : open}
61
+ onOpenChange={setOpen}
62
+ items={PRICE_PERIOD_ITEMS}
63
+ triggerElemRef={ref}
64
+ data-test-id={dataTestAttribute}
65
+ >
66
+ <Tooltip
67
+ tip='Доступен период только в месяц, т.к. в расчет добавлен сервис с методом тарификации PAYA (Pay As You Allocate). Чтобы изменить период расчета, удалите PAYA-сервис из расчета'
68
+ open={hasPayaGo ? undefined : false}
69
+ >
70
+ <ButtonFunction
71
+ ref={ref}
72
+ onClick={hasPayaGo ? e => e.stopPropagation() : () => setOpen(v => !v)}
73
+ label={PRICE_NAME[pricePeriod]}
74
+ size='m'
75
+ icon={open && !hasPayaGo ? <ChevronUpSVG /> : <ChevronDownSVG />}
76
+ disabled={hasPayaGo}
77
+ />
78
+ </Tooltip>
79
+ </AdaptiveDroplist>
80
+ );
81
+ }
@@ -0,0 +1 @@
1
+ export * from './PricePeriodSelect';
@@ -0,0 +1,85 @@
1
+ import { useDeferredValue } from 'react';
2
+
3
+ import { KebabSVG } from '@cloud-ru/uikit-product-icons';
4
+ import { AdaptiveDroplist } from '@cloud-ru/uikit-product-mobile-dropdown';
5
+ import { ButtonFunction } from '@snack-uikit/button';
6
+ import { Card } from '@snack-uikit/card';
7
+
8
+ import { useCalculatorContext } from '../../../../contexts';
9
+ import { formatNumber, getPrice, getValue, parseKeyToDataTest } from '../../../../utils';
10
+ import { PRICE_NAME } from '../PricePeriodSelect';
11
+ import styles from './styles.module.scss';
12
+
13
+ type ProductCardProps = {
14
+ id: string;
15
+ idx: number;
16
+ label: string;
17
+
18
+ selectedProduct: { id: string; idx: number } | null;
19
+
20
+ onProductClick(id: string, idx: number): void;
21
+ onProductDelete(productId: string, idx: number): void;
22
+ };
23
+
24
+ export function ProductCard({ id, idx, label, selectedProduct, onProductClick, onProductDelete }: ProductCardProps) {
25
+ const { layoutType, pricePeriod, calculatorType, products } = useCalculatorContext();
26
+ const isPartners = calculatorType === 'partners';
27
+ const isChecked = selectedProduct?.id === id && selectedProduct?.idx === idx;
28
+ const dataTestAttribute = parseKeyToDataTest('price', 'summary-product-card');
29
+
30
+ const price = useDeferredValue(getValue(products, `[${id}][${idx}].price`));
31
+
32
+ return (
33
+ <>
34
+ <Card
35
+ size='s'
36
+ onClick={() => {
37
+ onProductClick(id, idx);
38
+ }}
39
+ checked={isChecked}
40
+ outline
41
+ key={id + '_' + idx}
42
+ data-test-id={dataTestAttribute}
43
+ >
44
+ <>
45
+ <div className={styles.wrapper}>
46
+ <Card.Header
47
+ truncate={{
48
+ title: 10,
49
+ description: 20,
50
+ }}
51
+ title={label}
52
+ description={`${formatNumber(getPrice({ price, pricePeriod, partners: isPartners }))} ₽ ${PRICE_NAME[pricePeriod]}`}
53
+ />
54
+ <AdaptiveDroplist
55
+ layoutType={layoutType}
56
+ placement='bottom-end'
57
+ size='m'
58
+ closeDroplistOnItemClick
59
+ items={[
60
+ {
61
+ id: 'remove',
62
+ content: {
63
+ option: 'Удалить',
64
+ },
65
+ onClick: e => {
66
+ e.stopPropagation();
67
+ onProductDelete(id, idx);
68
+ },
69
+ },
70
+ ]}
71
+ >
72
+ <ButtonFunction
73
+ icon={<KebabSVG />}
74
+ size='m'
75
+ onClick={e => {
76
+ e.stopPropagation();
77
+ }}
78
+ />
79
+ </AdaptiveDroplist>
80
+ </div>
81
+ </>
82
+ </Card>
83
+ </>
84
+ );
85
+ }
@@ -0,0 +1 @@
1
+ export * from './ProductCard';
@@ -0,0 +1,7 @@
1
+ @use '@sbercloud/figma-tokens-cloud-platform/build/scss/styles-theme-variables' as stv;
2
+
3
+ .wrapper {
4
+ display: flex;
5
+ align-items: flex-start;
6
+ gap: stv.$dimension-1m;
7
+ }
@@ -0,0 +1,118 @@
1
+ import { MouseEventHandler, useEffect, useRef, useState } from 'react';
2
+
3
+ import { CheckFilledSVG, DownloadSVG, HeadphonesSVG, LinkSVG } from '@cloud-ru/uikit-product-icons';
4
+ import { ButtonTonal } from '@snack-uikit/button';
5
+ import { Tooltip } from '@snack-uikit/tooltip';
6
+
7
+ import { useCalculatorContext } from '../../../../contexts';
8
+ import { parseKeyToDataTest } from '../../../../utils';
9
+ import styles from './styles.module.scss';
10
+
11
+ type ProductListActionsProps = {
12
+ disabled?: boolean;
13
+ };
14
+
15
+ export function ProductListActions({ disabled }: ProductListActionsProps) {
16
+ const {
17
+ products,
18
+ calculatorType,
19
+ actions: { onShareClick, onDownloadFileClick, onRequestConsultationClick },
20
+ } = useCalculatorContext();
21
+
22
+ const [isChecked, setIsCheckedOpen] = useState(false);
23
+ const timerId = useRef<NodeJS.Timeout>();
24
+ const openChecked = () => setIsCheckedOpen(true);
25
+ const closeChecked = () => setIsCheckedOpen(false);
26
+
27
+ const handleShareClick: MouseEventHandler<HTMLButtonElement> = async event => {
28
+ event.stopPropagation();
29
+
30
+ onShareClick?.({
31
+ products,
32
+ calculatorType,
33
+ }).then(() => {
34
+ openChecked();
35
+ clearTimeout(timerId.current);
36
+ timerId.current = setTimeout(closeChecked, 1000);
37
+ });
38
+ };
39
+
40
+ useEffect(
41
+ () => () => {
42
+ closeChecked();
43
+ clearTimeout(timerId.current);
44
+ },
45
+ [],
46
+ );
47
+
48
+ const handleDownloadFileClick = () =>
49
+ onDownloadFileClick?.({
50
+ products,
51
+ calculatorType,
52
+ });
53
+
54
+ const handleRequestConsultationClick = () =>
55
+ onRequestConsultationClick?.({
56
+ products,
57
+ calculatorType,
58
+ });
59
+
60
+ return (
61
+ <div className={styles.footerLinks} data-test-id={parseKeyToDataTest('price', 'summary-footer')}>
62
+ {onShareClick && (
63
+ <Tooltip
64
+ tip={
65
+ isChecked ? (
66
+ <div className={styles.container}>
67
+ <span className={styles.icon}>
68
+ <CheckFilledSVG />
69
+ </span>
70
+ Ccылка скопирована
71
+ </div>
72
+ ) : (
73
+ <>Поделиться ссылкой</>
74
+ )
75
+ }
76
+ hoverDelayOpen={600}
77
+ open={isChecked || undefined}
78
+ >
79
+ <ButtonTonal
80
+ size='m'
81
+ icon={<LinkSVG />}
82
+ appearance='neutral'
83
+ fullWidth
84
+ onClick={handleShareClick}
85
+ data-test-id={parseKeyToDataTest('price', 'summary-footer-copy-link')}
86
+ disabled={disabled}
87
+ />
88
+ </Tooltip>
89
+ )}
90
+
91
+ <Tooltip tip='Скачать расчет' hoverDelayOpen={600}>
92
+ <ButtonTonal
93
+ size='m'
94
+ icon={<DownloadSVG />}
95
+ appearance='neutral'
96
+ data-test-id={parseKeyToDataTest('price', 'summary-footer-download')}
97
+ fullWidth
98
+ onClick={handleDownloadFileClick}
99
+ disabled={disabled}
100
+ />
101
+ </Tooltip>
102
+
103
+ {onRequestConsultationClick && (
104
+ <Tooltip tip='Запросить консультацию' hoverDelayOpen={600}>
105
+ <ButtonTonal
106
+ size='m'
107
+ icon={<HeadphonesSVG />}
108
+ appearance='neutral'
109
+ fullWidth
110
+ onClick={handleRequestConsultationClick}
111
+ data-test-id={parseKeyToDataTest('price', 'summary-footer-consultation')}
112
+ disabled={disabled}
113
+ />
114
+ </Tooltip>
115
+ )}
116
+ </div>
117
+ );
118
+ }
@@ -0,0 +1 @@
1
+ export * from './ProductListActions';
@@ -0,0 +1,38 @@
1
+ @use '@sbercloud/figma-tokens-cloud-platform/build/scss/components/styles-tokens-toaster-toasterUserAction';
2
+ @use '@sbercloud/figma-tokens-cloud-platform/build/scss/components/styles-tokens-element';
3
+ @use '@sbercloud/figma-tokens-cloud-platform/build/scss/styles-theme-variables';
4
+
5
+ .footerLinks {
6
+ display: flex;
7
+
8
+ gap: styles-theme-variables.$dimension-1m;
9
+ }
10
+
11
+ .icon {
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: center;
15
+
16
+ color: styles-theme-variables.$sys-green-accent-default;
17
+
18
+ svg {
19
+ width: styles-tokens-element.$icon-xs !important; /* stylelint-disable-line declaration-no-important */
20
+ height: styles-tokens-element.$icon-xs !important; /* stylelint-disable-line declaration-no-important */
21
+ }
22
+ }
23
+
24
+ .label {
25
+ @include styles-theme-variables.composite-var(styles-theme-variables.$sans-body-m);
26
+
27
+ color: styles-theme-variables.$sys-invert-neutral-text-main;
28
+ }
29
+
30
+ .container {
31
+ display: flex;
32
+ align-items: center;
33
+ justify-content: center;
34
+
35
+ box-sizing: border-box;
36
+
37
+ gap: 4px;
38
+ }
@@ -0,0 +1,3 @@
1
+ export * from './PricePeriodSelect';
2
+ export * from './ProductCard';
3
+ export * from './ProductListActions';
@@ -0,0 +1,36 @@
1
+ import { RefObject, useEffect } from 'react';
2
+
3
+ import { useCalculatorContext } from '../../contexts';
4
+
5
+ type UseScrollListToActiveProductProps = {
6
+ scrollRef: RefObject<HTMLDivElement>;
7
+ activeRef: RefObject<HTMLDivElement>;
8
+ };
9
+
10
+ export function useScrollListToActiveProduct({ scrollRef, activeRef }: UseScrollListToActiveProductProps) {
11
+ const { selectedProduct, products } = useCalculatorContext();
12
+
13
+ function scrollListToActiveProduct() {
14
+ if (!scrollRef.current) return;
15
+
16
+ const activeProduct = activeRef.current;
17
+ const container = scrollRef.current;
18
+
19
+ if (!activeProduct) return;
20
+
21
+ const activeProductRect = activeProduct.getBoundingClientRect();
22
+ const containerRefRect = container.getBoundingClientRect();
23
+ const currentScrollTop = container.scrollTop;
24
+ const scrollDistance = activeProductRect.top - containerRefRect.top + currentScrollTop - 320 / 2 + 50;
25
+
26
+ container.scroll({
27
+ top: scrollDistance,
28
+ behavior: 'smooth',
29
+ });
30
+ }
31
+
32
+ useEffect(() => {
33
+ scrollListToActiveProduct();
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }, [selectedProduct, Object.keys(products).length]);
36
+ }
@@ -0,0 +1 @@
1
+ export * from './PriceSummary';