@redneckz/wildless-cms-uni-blocks 0.14.745 → 0.14.747

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 (114) hide show
  1. package/bundle/api/apiBaseUrl.d.ts +1 -0
  2. package/bundle/blocks.schema.json +1 -1
  3. package/bundle/bundle.umd.js +84 -10
  4. package/bundle/bundle.umd.min.js +1 -1
  5. package/bundle/components/CardTransfer/CardTransferContent.d.ts +2 -1
  6. package/bundle/components/CardTransfer/SubmitFailedDialog.d.ts +6 -0
  7. package/bundle/components/CardTransfer/submitCardTransfer.d.ts +16 -0
  8. package/bundle/components/CardTransfer/useSubmitCardTransfer.d.ts +11 -0
  9. package/dist/api/RetailAPI/doRequest.js +1 -1
  10. package/dist/api/RetailAPI/doRequest.js.map +1 -1
  11. package/dist/api/apiBaseUrl.d.ts +1 -0
  12. package/dist/api/apiBaseUrl.js +2 -1
  13. package/dist/api/apiBaseUrl.js.map +1 -1
  14. package/dist/components/CardTransfer/CardTransfer.js +9 -7
  15. package/dist/components/CardTransfer/CardTransfer.js.map +1 -1
  16. package/dist/components/CardTransfer/CardTransferContent.d.ts +2 -1
  17. package/dist/components/CardTransfer/SubmitFailedDialog.d.ts +6 -0
  18. package/dist/components/CardTransfer/SubmitFailedDialog.js +13 -0
  19. package/dist/components/CardTransfer/SubmitFailedDialog.js.map +1 -0
  20. package/dist/components/CardTransfer/submitCardTransfer.d.ts +16 -0
  21. package/dist/components/CardTransfer/submitCardTransfer.js +44 -0
  22. package/dist/components/CardTransfer/submitCardTransfer.js.map +1 -0
  23. package/dist/components/CardTransfer/useSubmitCardTransfer.d.ts +11 -0
  24. package/dist/components/CardTransfer/useSubmitCardTransfer.js +33 -0
  25. package/dist/components/CardTransfer/useSubmitCardTransfer.js.map +1 -0
  26. package/dist/hooks/useLeadFormData.js +1 -1
  27. package/dist/hooks/useLeadFormData.js.map +1 -1
  28. package/lib/api/RetailAPI/doRequest.js +2 -2
  29. package/lib/api/RetailAPI/doRequest.js.map +1 -1
  30. package/lib/api/apiBaseUrl.d.ts +1 -0
  31. package/lib/api/apiBaseUrl.js +1 -0
  32. package/lib/api/apiBaseUrl.js.map +1 -1
  33. package/lib/common.css +1 -1
  34. package/lib/components/CardTransfer/CardTransfer.fixture.d.ts +2 -1
  35. package/lib/components/CardTransfer/CardTransfer.fixture.mobile.d.ts +2 -1
  36. package/lib/components/CardTransfer/CardTransfer.js +10 -8
  37. package/lib/components/CardTransfer/CardTransfer.js.map +1 -1
  38. package/lib/components/CardTransfer/CardTransferContent.d.ts +2 -1
  39. package/lib/components/CardTransfer/SubmitFailedDialog.d.ts +6 -0
  40. package/lib/components/CardTransfer/SubmitFailedDialog.js +10 -0
  41. package/lib/components/CardTransfer/SubmitFailedDialog.js.map +1 -0
  42. package/lib/components/CardTransfer/submitCardTransfer.d.ts +16 -0
  43. package/lib/components/CardTransfer/submitCardTransfer.js +39 -0
  44. package/lib/components/CardTransfer/submitCardTransfer.js.map +1 -0
  45. package/lib/components/CardTransfer/useSubmitCardTransfer.d.ts +11 -0
  46. package/lib/components/CardTransfer/useSubmitCardTransfer.js +30 -0
  47. package/lib/components/CardTransfer/useSubmitCardTransfer.js.map +1 -0
  48. package/lib/hooks/useLeadFormData.js +1 -1
  49. package/lib/hooks/useLeadFormData.js.map +1 -1
  50. package/mobile/bundle/api/apiBaseUrl.d.ts +1 -0
  51. package/mobile/bundle/bundle.umd.js +84 -10
  52. package/mobile/bundle/bundle.umd.min.js +1 -1
  53. package/mobile/bundle/components/CardTransfer/CardTransferContent.d.ts +2 -1
  54. package/mobile/bundle/components/CardTransfer/SubmitFailedDialog.d.ts +6 -0
  55. package/mobile/bundle/components/CardTransfer/submitCardTransfer.d.ts +16 -0
  56. package/mobile/bundle/components/CardTransfer/useSubmitCardTransfer.d.ts +11 -0
  57. package/mobile/dist/api/RetailAPI/doRequest.js +1 -1
  58. package/mobile/dist/api/RetailAPI/doRequest.js.map +1 -1
  59. package/mobile/dist/api/apiBaseUrl.d.ts +1 -0
  60. package/mobile/dist/api/apiBaseUrl.js +2 -1
  61. package/mobile/dist/api/apiBaseUrl.js.map +1 -1
  62. package/mobile/dist/components/CardTransfer/CardTransfer.js +9 -7
  63. package/mobile/dist/components/CardTransfer/CardTransfer.js.map +1 -1
  64. package/mobile/dist/components/CardTransfer/CardTransferContent.d.ts +2 -1
  65. package/mobile/dist/components/CardTransfer/SubmitFailedDialog.d.ts +6 -0
  66. package/mobile/dist/components/CardTransfer/SubmitFailedDialog.js +13 -0
  67. package/mobile/dist/components/CardTransfer/SubmitFailedDialog.js.map +1 -0
  68. package/mobile/dist/components/CardTransfer/submitCardTransfer.d.ts +16 -0
  69. package/mobile/dist/components/CardTransfer/submitCardTransfer.js +44 -0
  70. package/mobile/dist/components/CardTransfer/submitCardTransfer.js.map +1 -0
  71. package/mobile/dist/components/CardTransfer/useSubmitCardTransfer.d.ts +11 -0
  72. package/mobile/dist/components/CardTransfer/useSubmitCardTransfer.js +33 -0
  73. package/mobile/dist/components/CardTransfer/useSubmitCardTransfer.js.map +1 -0
  74. package/mobile/dist/hooks/useLeadFormData.js +1 -1
  75. package/mobile/dist/hooks/useLeadFormData.js.map +1 -1
  76. package/mobile/lib/api/RetailAPI/doRequest.js +2 -2
  77. package/mobile/lib/api/RetailAPI/doRequest.js.map +1 -1
  78. package/mobile/lib/api/apiBaseUrl.d.ts +1 -0
  79. package/mobile/lib/api/apiBaseUrl.js +1 -0
  80. package/mobile/lib/api/apiBaseUrl.js.map +1 -1
  81. package/mobile/lib/common.css +1 -1
  82. package/mobile/lib/components/CardTransfer/CardTransfer.js +10 -8
  83. package/mobile/lib/components/CardTransfer/CardTransfer.js.map +1 -1
  84. package/mobile/lib/components/CardTransfer/CardTransferContent.d.ts +2 -1
  85. package/mobile/lib/components/CardTransfer/SubmitFailedDialog.d.ts +6 -0
  86. package/mobile/lib/components/CardTransfer/SubmitFailedDialog.js +10 -0
  87. package/mobile/lib/components/CardTransfer/SubmitFailedDialog.js.map +1 -0
  88. package/mobile/lib/components/CardTransfer/submitCardTransfer.d.ts +16 -0
  89. package/mobile/lib/components/CardTransfer/submitCardTransfer.js +39 -0
  90. package/mobile/lib/components/CardTransfer/submitCardTransfer.js.map +1 -0
  91. package/mobile/lib/components/CardTransfer/useSubmitCardTransfer.d.ts +11 -0
  92. package/mobile/lib/components/CardTransfer/useSubmitCardTransfer.js +30 -0
  93. package/mobile/lib/components/CardTransfer/useSubmitCardTransfer.js.map +1 -0
  94. package/mobile/lib/hooks/useLeadFormData.js +1 -1
  95. package/mobile/lib/hooks/useLeadFormData.js.map +1 -1
  96. package/mobile/src/api/RetailAPI/doRequest.ts +2 -2
  97. package/mobile/src/api/apiBaseUrl.ts +1 -0
  98. package/mobile/src/components/CardTransfer/CardTransfer.tsx +12 -9
  99. package/mobile/src/components/CardTransfer/CardTransferContent.ts +3 -1
  100. package/mobile/src/components/CardTransfer/SubmitFailedDialog.tsx +42 -0
  101. package/mobile/src/components/CardTransfer/submitCardTransfer.ts +72 -0
  102. package/mobile/src/components/CardTransfer/useSubmitCardTransfer.tsx +47 -0
  103. package/mobile/src/hooks/useLeadFormData.ts +1 -1
  104. package/package.json +1 -1
  105. package/src/api/RetailAPI/doRequest.ts +2 -2
  106. package/src/api/apiBaseUrl.ts +1 -0
  107. package/src/components/CardTransfer/CardTransfer.fixture.mobile.tsx +11 -3
  108. package/src/components/CardTransfer/CardTransfer.fixture.tsx +13 -1
  109. package/src/components/CardTransfer/CardTransfer.tsx +12 -9
  110. package/src/components/CardTransfer/CardTransferContent.ts +3 -1
  111. package/src/components/CardTransfer/SubmitFailedDialog.tsx +42 -0
  112. package/src/components/CardTransfer/submitCardTransfer.ts +72 -0
  113. package/src/components/CardTransfer/useSubmitCardTransfer.tsx +47 -0
  114. package/src/hooks/useLeadFormData.ts +1 -1
@@ -1010,6 +1010,7 @@
1010
1010
  const formatPhone = (phone) => phone?.replace(/[^+\d]/g, '');
1011
1011
 
1012
1012
  const API_BASE_URI = '/api/v1';
1013
+ const RETAIL_API_BASE_URI = '/light-api-cash/v1';
1013
1014
 
1014
1015
  function LeadServiceAPI() {
1015
1016
  async function send(body, isIndividualType = false) {
@@ -3280,7 +3281,7 @@
3280
3281
  }
3281
3282
  };
3282
3283
  async function doRequest(url, method, body) {
3283
- return globalThis?.fetch?.(`${API_BASE_URI}${url}`, {
3284
+ return globalThis?.fetch?.(`${RETAIL_API_BASE_URI}${url}`, {
3284
3285
  method,
3285
3286
  headers: {
3286
3287
  'Content-Type': 'application/json',
@@ -3596,7 +3597,7 @@
3596
3597
  };
3597
3598
 
3598
3599
  const useLeadFormData = (typeField) => {
3599
- const { data, error } = useAsyncData(`/api/v1/dictionary?dictionaryType=${encodeURIComponent(typeField)}`, fetchData);
3600
+ const { data, error } = useAsyncData(`/light-api-cash/v1/dictionary?dictionaryType=${encodeURIComponent(typeField)}`, fetchData);
3600
3601
  if (data && 'errorMessage' in data) {
3601
3602
  return { error };
3602
3603
  }
@@ -6496,24 +6497,97 @@
6496
6497
 
6497
6498
  const CurrencyInput = JSX((props) => (jsx(NumberInput, { ...props, fractionDigits: 2, children: jsx("div", { className: "absolute right-4 bottom-4", children: jsx(Text, { size: "text-xl", font: "font-light", children: "\u20BD" }) }) })));
6498
6499
 
6500
+ const sessionStore = new Store(); // sessionStorage cache
6501
+ replicate(sessionStore, new StorageAdapter(globalThis?.sessionStorage));
6502
+ function useSessionStore() {
6503
+ return useStore(sessionStore);
6504
+ }
6505
+
6506
+ const paymentURLMap = {
6507
+ private: 'p2p/registerP2P',
6508
+ business: 'b2c/registerB2C',
6509
+ };
6510
+ const SUCCESS_URL = '/p2p/success';
6511
+ const FAIL_URL = '/p2p/success';
6512
+ const CURRENCY_CODE = '643';
6513
+ const LANGUAGE = 'ru';
6514
+ const submitCardTransfer = async (typeForm, amount) => {
6515
+ const navigator = locationNavigator();
6516
+ const submitBody = {
6517
+ amount: String(amount),
6518
+ currency: CURRENCY_CODE,
6519
+ returnUrl: `${navigator.origin}${SUCCESS_URL}`,
6520
+ failUrl: `${navigator.origin}${FAIL_URL}`,
6521
+ language: LANGUAGE,
6522
+ };
6523
+ const url = `${API_BASE_URI}/payment/${paymentURLMap[typeForm]}`;
6524
+ try {
6525
+ const res = await fetch(url, {
6526
+ method: 'POST',
6527
+ headers: { 'Content-Type': 'application/json' },
6528
+ mode: 'cors',
6529
+ body: JSON.stringify(submitBody),
6530
+ });
6531
+ if (!res.ok) {
6532
+ return null;
6533
+ }
6534
+ return await res.json();
6535
+ }
6536
+ catch (ex) {
6537
+ return null;
6538
+ }
6539
+ };
6540
+ const isSuccessResponse = (response) => Boolean(response?.formUrl) && Boolean(response?.orderId);
6541
+ const isErrorInResponse = (response) => Boolean(response?.errorMessage) && response?.errorCode !== 0;
6542
+
6543
+ const FAILED_TITLE = 'Ошибка перевода';
6544
+ const SubmitFailedDialog = ({ onClose, errorCode, errorMessage, }) => {
6545
+ const description = errorCode ? `Код ошибки - ${errorCode}` : 'Пожалуйста, повторите позднее';
6546
+ return (jsx(Dialog, { className: "my-6xl max-w-lg w-full min-h-fit mx-auto", onClose: onClose, children: jsxs("div", { className: "flex flex-col gap-lg items-center rounded-md space-x-m", children: [jsx(Img, { image: { icon: 'ResponseFailIcon', iconVersion: 'normal' }, width: "136", height: "136" }), jsx(Headline, { className: "w-full", title: FAILED_TITLE, description: description, headlineVersion: "XS", isEmbedded: true }), errorMessage ? (jsxs("div", { className: "bg-secondary-dark rounded-xl px-4 pt-4 pb-8 grid gap-4 grid-cols-12", children: [jsxs("div", { className: "col-span-8", children: [" ", errorMessage] }), jsx("div", { className: "col-span-4", children: jsx(Img, { image: { icon: 'ResponseFailIcon', iconVersion: 'normal' } }) })] })) : null] }) }));
6547
+ };
6548
+
6549
+ const useSubmitCardTransfer = (formType) => {
6550
+ const responseTypeDialog = useDialog(SubmitFailedDialog);
6551
+ const sessionStore = useSessionStore();
6552
+ const navigator = locationNavigator();
6553
+ const adjustedTypeForm = formType === 'private' ? 'p2p' : 'b2c';
6554
+ return useCallback(async ({ amount }) => {
6555
+ const response = await submitCardTransfer(formType, amount);
6556
+ if (isSuccessResponse(response)) {
6557
+ sessionStore.transaction = {
6558
+ orderId: response.orderId,
6559
+ type: adjustedTypeForm,
6560
+ url: navigator.href,
6561
+ };
6562
+ navigator.assign(`${adjustedTypeForm}/?formUrl=${encodeURIComponent(response.formUrl)}`);
6563
+ }
6564
+ if (isErrorInResponse(response)) {
6565
+ responseTypeDialog.open({
6566
+ errorCode: response.errorCode,
6567
+ errorMessage: response.errorMessage,
6568
+ });
6569
+ }
6570
+ }, [formType]);
6571
+ };
6572
+
6499
6573
  const DEFAULT_TITLE = 'Укажите сумму перевода';
6500
6574
  const DEFAULT_LABEL = 'Сумма перевода';
6501
6575
  const MAX_AMOUNT = 300000;
6502
6576
  const MIN_AMOUNT = 1;
6503
- const FORM_URL_MAP = {
6504
- private: 'https://old.rshb.ru/p2p/',
6505
- business: 'https://old.rshb.ru/smallbusiness/p2p/',
6506
- };
6507
6577
  const INITIAL_FORM_STATE = {
6508
6578
  amount: 1500,
6509
6579
  };
6510
6580
  const CardTransfer = JSX(({ className = '', title = DEFAULT_TITLE, label = DEFAULT_LABEL, button, formType = 'private', ...rest }) => {
6511
- const [{ amount }, { field }] = useForm(INITIAL_FORM_STATE);
6512
- const [isDisabled, setDisabled] = useState(false);
6581
+ const [isDisabled, { setValue: setDisabled }] = useBool(false);
6582
+ const handleSubmit = useSubmitCardTransfer(formType);
6583
+ const [{ amount }, { field, onSubmit }] = useForm(INITIAL_FORM_STATE, {
6584
+ onSubmit: handleSubmit,
6585
+ });
6586
+ // TODO: dont set state in useEffect
6513
6587
  useEffect(() => {
6514
6588
  setDisabled(amount <= 0);
6515
6589
  }, [amount]);
6516
- return (jsxs(BlockWrapper, { className: style('flex flex-col items-center', className), defaultPadding: "p-6xl", ...rest, children: [title ? (jsx(Heading, { className: "pb-lg xl:pb-4xl self-start xl:self-center", headingType: "h3", title: title })) : null, jsxs("form", { className: "w-full xl:max-w-[468px]", method: "POST", action: FORM_URL_MAP[formType], children: [jsx(CurrencyInput, { valid: !isDisabled, label: label, max: MAX_AMOUNT, min: MIN_AMOUNT, ...field('amount', { parse: Number, format: String }) }), jsx("input", { type: "hidden", name: "amount", value: amount }), button?.text ? (jsx(Button, { className: "w-full mt-lg", type: "submit", disabled: isDisabled, children: button.text })) : null] })] }));
6590
+ return (jsxs(BlockWrapper, { className: style('flex flex-col items-center', className), defaultPadding: "p-6xl", ...rest, children: [title ? (jsx(Heading, { className: "pb-lg xl:pb-4xl self-start xl:self-center", headingType: "h3", title: title })) : null, jsxs("form", { className: "w-full xl:max-w-[468px]", method: "POST", onSubmit: onSubmit, children: [jsx(CurrencyInput, { valid: !isDisabled, label: label, max: MAX_AMOUNT, min: MIN_AMOUNT, ...field('amount', { parse: Number, format: String }) }), jsx("input", { type: "hidden", name: "amount", value: amount }), button?.text ? (jsx(Button, { className: "w-full mt-lg", type: "submit", disabled: isDisabled, children: button.text })) : null] })] }));
6517
6591
  });
6518
6592
 
6519
6593
  const ITEMS_GAP = 16;
@@ -10394,7 +10468,7 @@
10394
10468
  slots: () => [HEADER_SLOT, FOOTER_SLOT, STICKY_FOOTER_SLOT],
10395
10469
  });
10396
10470
 
10397
- const packageVersion = "0.14.744";
10471
+ const packageVersion = "0.14.746";
10398
10472
 
10399
10473
  exports.Blocks = Blocks;
10400
10474
  exports.ContentPage = ContentPage;