@redneckz/wildless-cms-uni-blocks 0.14.1064 → 0.14.1066

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 (105) hide show
  1. package/bundle/blocks.schema.json +1 -1
  2. package/bundle/bundle.umd.js +58 -32
  3. package/bundle/bundle.umd.min.js +1 -1
  4. package/bundle/components/RatesTable/RatesTable.d.ts +3 -0
  5. package/bundle/components/RatesTable/RatesTableContent.d.ts +13 -3
  6. package/bundle/components/RatesTable/RatesTableItem.d.ts +2 -2
  7. package/bundle/hooks/useRates.d.ts +11 -2
  8. package/dist/components/CreditCardForm/getDeliveryCreditCardData.js +6 -0
  9. package/dist/components/CreditCardForm/getDeliveryCreditCardData.js.map +1 -1
  10. package/dist/components/CreditCardForm/useCreditCardFormAPI.js +2 -1
  11. package/dist/components/CreditCardForm/useCreditCardFormAPI.js.map +1 -1
  12. package/dist/components/RatesTable/RatesTable.d.ts +3 -0
  13. package/dist/components/RatesTable/RatesTable.js +23 -5
  14. package/dist/components/RatesTable/RatesTable.js.map +1 -1
  15. package/dist/components/RatesTable/RatesTableContent.d.ts +13 -3
  16. package/dist/components/RatesTable/RatesTableItem.d.ts +2 -2
  17. package/dist/components/RatesTable/RatesTableItem.js.map +1 -1
  18. package/dist/hooks/useRates.d.ts +11 -2
  19. package/dist/hooks/useRates.js +28 -20
  20. package/dist/hooks/useRates.js.map +1 -1
  21. package/dist/retail/components/Fields/DeliveryDateField.js +1 -5
  22. package/dist/retail/components/Fields/DeliveryDateField.js.map +1 -1
  23. package/dist/retail/components/Fields/DeliveryTimeField.js +1 -0
  24. package/dist/retail/components/Fields/DeliveryTimeField.js.map +1 -1
  25. package/lib/components/CreditCardForm/getDeliveryCreditCardData.js +6 -0
  26. package/lib/components/CreditCardForm/getDeliveryCreditCardData.js.map +1 -1
  27. package/lib/components/CreditCardForm/useCreditCardFormAPI.js +2 -1
  28. package/lib/components/CreditCardForm/useCreditCardFormAPI.js.map +1 -1
  29. package/lib/components/OfficesAtmsMap/OfficesAtmsMapLayout.d.ts +1 -1
  30. package/lib/components/RatesTable/RatesTable.d.ts +3 -0
  31. package/lib/components/RatesTable/RatesTable.fixture.d.ts +1 -1
  32. package/lib/components/RatesTable/RatesTable.fixture.mobile.d.ts +1 -1
  33. package/lib/components/RatesTable/RatesTable.js +23 -5
  34. package/lib/components/RatesTable/RatesTable.js.map +1 -1
  35. package/lib/components/RatesTable/RatesTableContent.d.ts +13 -3
  36. package/lib/components/RatesTable/RatesTableItem.d.ts +2 -2
  37. package/lib/components/RatesTable/RatesTableItem.js.map +1 -1
  38. package/lib/hooks/useRates.d.ts +11 -2
  39. package/lib/hooks/useRates.js +28 -20
  40. package/lib/hooks/useRates.js.map +1 -1
  41. package/lib/retail/components/Fields/DeliveryDateField.js +1 -5
  42. package/lib/retail/components/Fields/DeliveryDateField.js.map +1 -1
  43. package/lib/retail/components/Fields/DeliveryTimeField.js +1 -0
  44. package/lib/retail/components/Fields/DeliveryTimeField.js.map +1 -1
  45. package/mobile/bundle/bundle.umd.js +58 -32
  46. package/mobile/bundle/bundle.umd.min.js +1 -1
  47. package/mobile/bundle/components/RatesTable/RatesTable.d.ts +3 -0
  48. package/mobile/bundle/components/RatesTable/RatesTableContent.d.ts +13 -3
  49. package/mobile/bundle/components/RatesTable/RatesTableItem.d.ts +2 -2
  50. package/mobile/bundle/hooks/useRates.d.ts +11 -2
  51. package/mobile/dist/components/CreditCardForm/getDeliveryCreditCardData.js +6 -0
  52. package/mobile/dist/components/CreditCardForm/getDeliveryCreditCardData.js.map +1 -1
  53. package/mobile/dist/components/CreditCardForm/useCreditCardFormAPI.js +2 -1
  54. package/mobile/dist/components/CreditCardForm/useCreditCardFormAPI.js.map +1 -1
  55. package/mobile/dist/components/RatesTable/RatesTable.d.ts +3 -0
  56. package/mobile/dist/components/RatesTable/RatesTable.js +23 -5
  57. package/mobile/dist/components/RatesTable/RatesTable.js.map +1 -1
  58. package/mobile/dist/components/RatesTable/RatesTableContent.d.ts +13 -3
  59. package/mobile/dist/components/RatesTable/RatesTableItem.d.ts +2 -2
  60. package/mobile/dist/components/RatesTable/RatesTableItem.js.map +1 -1
  61. package/mobile/dist/hooks/useRates.d.ts +11 -2
  62. package/mobile/dist/hooks/useRates.js +28 -20
  63. package/mobile/dist/hooks/useRates.js.map +1 -1
  64. package/mobile/dist/retail/components/Fields/DeliveryDateField.js +1 -5
  65. package/mobile/dist/retail/components/Fields/DeliveryDateField.js.map +1 -1
  66. package/mobile/dist/retail/components/Fields/DeliveryTimeField.js +1 -0
  67. package/mobile/dist/retail/components/Fields/DeliveryTimeField.js.map +1 -1
  68. package/mobile/lib/components/CreditCardForm/getDeliveryCreditCardData.js +6 -0
  69. package/mobile/lib/components/CreditCardForm/getDeliveryCreditCardData.js.map +1 -1
  70. package/mobile/lib/components/CreditCardForm/useCreditCardFormAPI.js +2 -1
  71. package/mobile/lib/components/CreditCardForm/useCreditCardFormAPI.js.map +1 -1
  72. package/mobile/lib/components/RatesTable/RatesTable.d.ts +3 -0
  73. package/mobile/lib/components/RatesTable/RatesTable.js +23 -5
  74. package/mobile/lib/components/RatesTable/RatesTable.js.map +1 -1
  75. package/mobile/lib/components/RatesTable/RatesTableContent.d.ts +13 -3
  76. package/mobile/lib/components/RatesTable/RatesTableItem.d.ts +2 -2
  77. package/mobile/lib/components/RatesTable/RatesTableItem.js.map +1 -1
  78. package/mobile/lib/hooks/useRates.d.ts +11 -2
  79. package/mobile/lib/hooks/useRates.js +28 -20
  80. package/mobile/lib/hooks/useRates.js.map +1 -1
  81. package/mobile/lib/retail/components/Fields/DeliveryDateField.js +1 -5
  82. package/mobile/lib/retail/components/Fields/DeliveryDateField.js.map +1 -1
  83. package/mobile/lib/retail/components/Fields/DeliveryTimeField.js +1 -0
  84. package/mobile/lib/retail/components/Fields/DeliveryTimeField.js.map +1 -1
  85. package/mobile/src/components/CreditCardForm/getDeliveryCreditCardData.ts +6 -0
  86. package/mobile/src/components/CreditCardForm/useCreditCardFormAPI.tsx +2 -1
  87. package/mobile/src/components/RatesTable/RatesTable.example.json +5 -3
  88. package/mobile/src/components/RatesTable/RatesTable.tsx +71 -16
  89. package/mobile/src/components/RatesTable/RatesTableContent.ts +14 -3
  90. package/mobile/src/components/RatesTable/RatesTableItem.tsx +2 -1
  91. package/mobile/src/hooks/useRates.ts +46 -23
  92. package/mobile/src/retail/components/Fields/DeliveryDateField.tsx +2 -6
  93. package/mobile/src/retail/components/Fields/DeliveryTimeField.tsx +1 -0
  94. package/package.json +1 -1
  95. package/src/components/CreditCardForm/getDeliveryCreditCardData.ts +6 -0
  96. package/src/components/CreditCardForm/useCreditCardFormAPI.tsx +2 -1
  97. package/src/components/RatesTable/RatesTable.example.json +5 -3
  98. package/src/components/RatesTable/RatesTable.fixture.mobile.tsx +10 -5
  99. package/src/components/RatesTable/RatesTable.fixture.tsx +10 -5
  100. package/src/components/RatesTable/RatesTable.tsx +71 -16
  101. package/src/components/RatesTable/RatesTableContent.ts +14 -3
  102. package/src/components/RatesTable/RatesTableItem.tsx +2 -1
  103. package/src/hooks/useRates.ts +46 -23
  104. package/src/retail/components/Fields/DeliveryDateField.tsx +2 -6
  105. package/src/retail/components/Fields/DeliveryTimeField.tsx +1 -0
@@ -1,38 +1,93 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useRates } from '../../hooks/useRates';
2
+ import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
3
+ import { useRates, type RateItemList } from '../../hooks/useRates';
3
4
  import { BlockWrapper } from '../../ui-kit/BlockWrapper';
4
5
  import { Heading } from '../../ui-kit/Heading/Heading';
6
+ import { Loader } from '../../ui-kit/Loader/Loader';
7
+ import { NotFound } from '../../ui-kit/NotFound/NotFound';
5
8
  import { type UniBlockProps } from '../../UniBlock/UniBlockProps';
6
9
  import { style } from '../../utils/style';
7
10
  import { type RatesTableContent } from './RatesTableContent';
8
11
  import { RatesTableItem } from './RatesTableItem';
9
- import { renderDataPickForm } from './renderDataPickForm';
10
12
  import { renderLink } from './renderLink';
11
13
 
12
14
  interface RatesTableProps extends RatesTableContent, UniBlockProps {}
13
15
 
16
+ interface RenderRatesContent extends RatesTableContent, ArchiveRates {
17
+ isRatesValid?: boolean;
18
+ ratesList?: RateItemList[];
19
+ }
20
+
21
+ export type ArchiveRates = {
22
+ isArchive?: boolean;
23
+ };
24
+
14
25
  export const RatesTable = JSX<RatesTableProps>(
15
- ({ href, className = '', infoMessage, title, isArchive = false, ...rest }) => {
16
- const ratesList = useRates(isArchive);
26
+ ({
27
+ href,
28
+ ratesType = 'natural',
29
+ className = '',
30
+ infoMessage,
31
+ notFoundMessage,
32
+ title,
33
+ ...rest
34
+ }) => {
35
+ // const [date, setDate] = useState<Date>();
36
+ const [fetchArchive, setFetchArchive] = useState<boolean>(true);
37
+
38
+ //const isArchive = ratesType === 'archive';
39
+
40
+ const { ratesList, isLoad } = useRates({
41
+ ratesType,
42
+ fetchArchive,
43
+ });
17
44
 
18
- const isRatesValid = ratesList[0].length > 0;
45
+ useEffect(() => {
46
+ setFetchArchive(false);
47
+ }, []);
48
+
49
+ const isRatesValid = ratesList?.length > 0;
19
50
 
20
51
  return (
21
52
  <BlockWrapper className={style('p-6xl space-y-xl', className)} defaultPadding="p-0" {...rest}>
22
53
  <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
-
54
+ {/*{isArchive
55
+ ? renderDataPickForm({ value: date, onChange: setDate, handleClick: setFetchArchive })
56
+ : null}*/}
57
+ {isLoad ? (
58
+ renderRatesContent({
59
+ ratesList,
60
+ isArchive: false,
61
+ infoMessage,
62
+ isRatesValid,
63
+ notFoundMessage,
64
+ })
65
+ ) : (
66
+ <Loader position="static" />
67
+ )}
34
68
  {href ? renderLink(href) : null}
35
69
  </BlockWrapper>
36
70
  );
37
71
  },
38
72
  );
73
+
74
+ const renderRatesContent = ({
75
+ ratesList = [],
76
+ isArchive = false,
77
+ infoMessage,
78
+ isRatesValid,
79
+ notFoundMessage,
80
+ }: RenderRatesContent) =>
81
+ ratesList.length > 0 ? (
82
+ ratesList.map((list, i) => (
83
+ <RatesTableItem
84
+ list={list}
85
+ isRatesValid={isRatesValid}
86
+ isArchive={isArchive}
87
+ key={String(i)}
88
+ infoMessage={infoMessage}
89
+ />
90
+ ))
91
+ ) : (
92
+ <NotFound description={notFoundMessage} />
93
+ );
@@ -1,13 +1,24 @@
1
1
  import { type HrefProps } from '../../model/LinkProps';
2
2
 
3
3
  /**
4
- * @title Таблица курсов
4
+ * @title Тип курсов
5
+ * @default "Курсы для физ.лиц"
6
+ * @enumNames [
7
+ * "Курсы для физ.лиц",
8
+ * "Курсы для держателей карт"
9
+ * ]
10
+ */
11
+ export type RatesType = 'natural' | 'cards';
12
+
13
+ /**
14
+ * @title Кросс-курсы
5
15
  */
6
16
  export interface RatesTableContent extends HrefProps {
7
17
  /** @title Информационное сообщение */
8
18
  infoMessage?: string;
9
19
  /** @title Заголовок */
10
20
  title?: string;
11
- /** @hidden */
12
- isArchive?: boolean;
21
+ ratesType?: RatesType;
22
+ /** @title Сообщение при отсутствии ставок */
23
+ notFoundMessage?: string;
13
24
  }
@@ -3,10 +3,11 @@ import { Paragraph } from '../../ui-kit/Paragraph/Paragraph';
3
3
  import { Rate, RATES_COLUMN_STYLE, type RateItem } from '../../ui-kit/Rate/Rate';
4
4
  import { Text } from '../../ui-kit/Text/Text';
5
5
  import { style } from '../../utils/style';
6
+ import { type ArchiveRates } from './RatesTable';
6
7
  import { type RatesTableContent } from './RatesTableContent';
7
8
  import { renderDate } from './renderDate';
8
9
 
9
- interface RatesTableItemProps extends RatesTableContent {
10
+ export interface RatesTableItemProps extends RatesTableContent, ArchiveRates {
10
11
  maxDate?: string;
11
12
  isRatesValid?: boolean;
12
13
  list: RateItem[];
@@ -1,6 +1,7 @@
1
1
  import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
2
2
  import { useLocalStore } from '@redneckz/uni-jsx/lib/Store/useLocalStore';
3
3
  import { API_BASE_URI } from '../api/apiBaseUrl';
4
+ import { type RatesType } from '../components/RatesTable/RatesTableContent';
4
5
  import { type RateItem } from '../ui-kit/Rate/Rate';
5
6
  import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
6
7
 
@@ -9,33 +10,43 @@ type RatesStoreItem = {
9
10
  nextUpdate: number;
10
11
  };
11
12
 
12
- type RateItemList = RateItem[];
13
+ export type RateItemList = RateItem[];
13
14
 
14
15
  type RatesStoreSlice = {
15
16
  rates: RatesStoreItem;
16
17
  archiveRates: RatesStoreItem;
17
18
  };
18
19
 
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';
20
+ type FetchRatesProps = {
21
+ ratesType?: RatesType;
22
+ date?: Date;
23
+ fetchArchive?: boolean;
24
+ };
25
+
26
+ const EMPTY_RATES: RateItemList[] = [];
27
+
28
+ const RATES_URL: Record<RatesType, string> = {
29
+ natural: `${API_BASE_URI}/rates`,
30
+ cards: `${API_BASE_URI}/ratescards`,
31
+ //archive: `${API_BASE_URI}/historyrates`,
32
+ };
33
+
34
+ const RATES_KEY: Record<RatesType, string> = {
35
+ natural: 'rates',
36
+ cards: 'ratescards',
37
+ //archive: 'historyrates',
38
+ };
39
+
40
+ // TODO: для архива прокинуть date
41
+ export function useRates({ ratesType = 'natural', fetchArchive = true }: FetchRatesProps) {
42
+ //const url = ratesType === 'archive' ? getArchiveRatesURL(date) : RATES_URL[ratesType];
43
+ const url = RATES_URL[ratesType];
44
+ const rateKey = RATES_KEY[ratesType];
34
45
 
35
46
  const ratesStore = useLocalStore<RatesStoreSlice>();
36
47
 
37
48
  // проверяем, надо ли обновлять значения ставок
38
- const shouldUpdate = getShouldUpdate(isArchive, ratesStore as RatesStoreSlice);
49
+ const shouldUpdate = getShouldUpdate(rateKey, ratesStore as RatesStoreSlice, fetchArchive);
39
50
 
40
51
  // костыль, не отправлять запрос на бэк, если уже был запрос менее 15 мин назад
41
52
  const { data } = useAsyncData(
@@ -46,20 +57,32 @@ export function useRates(isArchive: boolean): RateItemList[] {
46
57
  // если есть data и значение надо обновить, то обновляем локалсторадж
47
58
  if (shouldUpdate && data) {
48
59
  const nextUpdate = getTimeAfter15Minutes();
49
- ratesStore[rateKey] = { rate: data, nextUpdate };
60
+ ratesStore[rateKey] = { rate: data ?? [], nextUpdate };
50
61
  }
51
62
 
52
63
  // берем данные из локалсторадж
53
64
  const rates = ratesStore[rateKey]?.rate;
54
65
 
66
+ const isLoad = Array.isArray(rates);
67
+
55
68
  // возвращаем данные из локалсторадж или заглушку
56
- return Array.isArray(rates) ? rates : EMPTY_RATES;
69
+ return { ratesList: rates ?? EMPTY_RATES, isLoad };
57
70
  }
58
71
 
59
72
  // Отсчитываем 15 минут с текущего момента
60
73
  const getTimeAfter15Minutes = () => Date.now() + 15 * 60 * 1000;
61
74
 
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();
75
+ const getShouldUpdate = (
76
+ rateKey: string,
77
+ ratesStore: RatesStoreSlice | null,
78
+ fetchArchive: boolean,
79
+ ) =>
80
+ rateKey === 'archive'
81
+ ? (!ratesStore?.[rateKey] || ratesStore?.[rateKey].nextUpdate <= Date.now()) && fetchArchive
82
+ : !ratesStore?.[rateKey] || ratesStore?.[rateKey].nextUpdate <= Date.now();
83
+
84
+ /*const getArchiveRatesURL = (date?: Date) => {
85
+ const formattedDate = date && formatDate(date, true);
86
+
87
+ return formattedDate ? `${RATES_URL['archive']}?date=${formattedDate}` : RATES_URL['archive'];
88
+ };*/
@@ -3,14 +3,10 @@ import { useMemo } from '@redneckz/uni-jsx/lib/hooks';
3
3
  import { DatePickerControl } from '../../../ui-kit/DatePicker/DatePickerControl';
4
4
  import { type CustomFieldProps } from '../../../ui-kit/FormField/CustomFieldProps';
5
5
  import { useLeadFormData } from '../../hooks/useLeadFormData';
6
- import { useRetailFormStore } from '../../hooks/useRetailFormStore';
7
6
 
8
7
  const MIN_DATE = new Date(Date.now() + 1 * 24 * 60 * 60 * 1000);
9
8
 
10
9
  export const DeliveryDateField = JSX<CustomFieldProps>(({ field, input }) => {
11
- const { productType } = useRetailFormStore();
12
- const isDebit = productType === 'debitCard';
13
- const minDate = isDebit ? MIN_DATE : new Date();
14
10
  const { data } = useLeadFormData('DAYS_DELIVERY_SETTINGS');
15
11
 
16
12
  const weekends: number[] = useMemo(() => {
@@ -27,8 +23,8 @@ export const DeliveryDateField = JSX<CustomFieldProps>(({ field, input }) => {
27
23
  label="Дата доставки"
28
24
  {...field(input?.name ?? '')}
29
25
  {...input}
30
- minDate={minDate}
31
- weekends={isDebit ? weekends : []}
26
+ minDate={MIN_DATE}
27
+ weekends={weekends}
32
28
  />
33
29
  );
34
30
  });
@@ -18,6 +18,7 @@ export const DeliveryTimeField = JSX<CustomFieldProps>(({ field, input }) => {
18
18
 
19
19
  return (data || [])
20
20
  .filter((item) => item.key && allowedTimes.includes(item.key))
21
+ .sort((a, b) => (a.displayOrder || 0) - (b.displayOrder || 0))
21
22
  .map((item) => ({
22
23
  id: item.key as string,
23
24
  text: item.value,