@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
@@ -1018,6 +1018,7 @@
1018
1018
  const formatPhone = (phone) => phone?.replace(/[^+\d]/g, '');
1019
1019
 
1020
1020
  const API_BASE_URI = '/api/v1';
1021
+ const RETAIL_API_BASE_URI = '/light-api-cash/v1';
1021
1022
 
1022
1023
  function LeadServiceAPI() {
1023
1024
  async function send(body, isIndividualType = false) {
@@ -3288,7 +3289,7 @@
3288
3289
  }
3289
3290
  };
3290
3291
  async function doRequest(url, method, body) {
3291
- return globalThis?.fetch?.(`${API_BASE_URI}${url}`, {
3292
+ return globalThis?.fetch?.(`${RETAIL_API_BASE_URI}${url}`, {
3292
3293
  method,
3293
3294
  headers: {
3294
3295
  'Content-Type': 'application/json',
@@ -3604,7 +3605,7 @@
3604
3605
  };
3605
3606
 
3606
3607
  const useLeadFormData = (typeField) => {
3607
- const { data, error } = useAsyncData(`/api/v1/dictionary?dictionaryType=${encodeURIComponent(typeField)}`, fetchData);
3608
+ const { data, error } = useAsyncData(`/light-api-cash/v1/dictionary?dictionaryType=${encodeURIComponent(typeField)}`, fetchData);
3608
3609
  if (data && 'errorMessage' in data) {
3609
3610
  return { error };
3610
3611
  }
@@ -6492,24 +6493,97 @@
6492
6493
 
6493
6494
  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" }) }) })));
6494
6495
 
6496
+ const sessionStore = new Store(); // sessionStorage cache
6497
+ replicate(sessionStore, new StorageAdapter(globalThis?.sessionStorage));
6498
+ function useSessionStore() {
6499
+ return useStore(sessionStore);
6500
+ }
6501
+
6502
+ const paymentURLMap = {
6503
+ private: 'p2p/registerP2P',
6504
+ business: 'b2c/registerB2C',
6505
+ };
6506
+ const SUCCESS_URL = '/p2p/success';
6507
+ const FAIL_URL = '/p2p/success';
6508
+ const CURRENCY_CODE = '643';
6509
+ const LANGUAGE = 'ru';
6510
+ const submitCardTransfer = async (typeForm, amount) => {
6511
+ const navigator = locationNavigator();
6512
+ const submitBody = {
6513
+ amount: String(amount),
6514
+ currency: CURRENCY_CODE,
6515
+ returnUrl: `${navigator.origin}${SUCCESS_URL}`,
6516
+ failUrl: `${navigator.origin}${FAIL_URL}`,
6517
+ language: LANGUAGE,
6518
+ };
6519
+ const url = `${API_BASE_URI}/payment/${paymentURLMap[typeForm]}`;
6520
+ try {
6521
+ const res = await fetch(url, {
6522
+ method: 'POST',
6523
+ headers: { 'Content-Type': 'application/json' },
6524
+ mode: 'cors',
6525
+ body: JSON.stringify(submitBody),
6526
+ });
6527
+ if (!res.ok) {
6528
+ return null;
6529
+ }
6530
+ return await res.json();
6531
+ }
6532
+ catch (ex) {
6533
+ return null;
6534
+ }
6535
+ };
6536
+ const isSuccessResponse = (response) => Boolean(response?.formUrl) && Boolean(response?.orderId);
6537
+ const isErrorInResponse = (response) => Boolean(response?.errorMessage) && response?.errorCode !== 0;
6538
+
6539
+ const FAILED_TITLE = 'Ошибка перевода';
6540
+ const SubmitFailedDialog = ({ onClose, errorCode, errorMessage, }) => {
6541
+ const description = errorCode ? `Код ошибки - ${errorCode}` : 'Пожалуйста, повторите позднее';
6542
+ 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] }) }));
6543
+ };
6544
+
6545
+ const useSubmitCardTransfer = (formType) => {
6546
+ const responseTypeDialog = useDialog(SubmitFailedDialog);
6547
+ const sessionStore = useSessionStore();
6548
+ const navigator = locationNavigator();
6549
+ const adjustedTypeForm = formType === 'private' ? 'p2p' : 'b2c';
6550
+ return useCallback(async ({ amount }) => {
6551
+ const response = await submitCardTransfer(formType, amount);
6552
+ if (isSuccessResponse(response)) {
6553
+ sessionStore.transaction = {
6554
+ orderId: response.orderId,
6555
+ type: adjustedTypeForm,
6556
+ url: navigator.href,
6557
+ };
6558
+ navigator.assign(`${adjustedTypeForm}/?formUrl=${encodeURIComponent(response.formUrl)}`);
6559
+ }
6560
+ if (isErrorInResponse(response)) {
6561
+ responseTypeDialog.open({
6562
+ errorCode: response.errorCode,
6563
+ errorMessage: response.errorMessage,
6564
+ });
6565
+ }
6566
+ }, [formType]);
6567
+ };
6568
+
6495
6569
  const DEFAULT_TITLE = 'Укажите сумму перевода';
6496
6570
  const DEFAULT_LABEL = 'Сумма перевода';
6497
6571
  const MAX_AMOUNT = 300000;
6498
6572
  const MIN_AMOUNT = 1;
6499
- const FORM_URL_MAP = {
6500
- private: 'https://old.rshb.ru/p2p/',
6501
- business: 'https://old.rshb.ru/smallbusiness/p2p/',
6502
- };
6503
6573
  const INITIAL_FORM_STATE = {
6504
6574
  amount: 1500,
6505
6575
  };
6506
6576
  const CardTransfer = JSX(({ className = '', title = DEFAULT_TITLE, label = DEFAULT_LABEL, button, formType = 'private', ...rest }) => {
6507
- const [{ amount }, { field }] = useForm(INITIAL_FORM_STATE);
6508
- const [isDisabled, setDisabled] = useState(false);
6577
+ const [isDisabled, { setValue: setDisabled }] = useBool(false);
6578
+ const handleSubmit = useSubmitCardTransfer(formType);
6579
+ const [{ amount }, { field, onSubmit }] = useForm(INITIAL_FORM_STATE, {
6580
+ onSubmit: handleSubmit,
6581
+ });
6582
+ // TODO: dont set state in useEffect
6509
6583
  useEffect(() => {
6510
6584
  setDisabled(amount <= 0);
6511
6585
  }, [amount]);
6512
- 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] })] }));
6586
+ 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] })] }));
6513
6587
  });
6514
6588
 
6515
6589
  const ITEMS_GAP = 16;
@@ -10017,7 +10091,7 @@
10017
10091
  slots: () => [HEADER_SLOT, FOOTER_SLOT, STICKY_FOOTER_SLOT],
10018
10092
  });
10019
10093
 
10020
- const packageVersion = "0.14.744";
10094
+ const packageVersion = "0.14.746";
10021
10095
 
10022
10096
  exports.Blocks = Blocks;
10023
10097
  exports.ContentPage = ContentPage;