@akinon/pz-bkm 1.89.0-rc.2 → 1.89.0-rc.20

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,57 @@
1
1
  # @akinon/pz-bkm
2
2
 
3
+ ## 1.89.0-rc.20
4
+
5
+ ## 1.89.0-rc.19
6
+
7
+ ## 1.89.0-rc.18
8
+
9
+ ## 1.89.0-rc.17
10
+
11
+ ## 1.89.0-rc.16
12
+
13
+ ## 1.89.0-rc.15
14
+
15
+ ## 1.89.0-rc.14
16
+
17
+ ## 1.89.0-rc.13
18
+
19
+ ### Minor Changes
20
+
21
+ - 1044bce: ZERO-3379: Add custom UI rendering support
22
+
23
+ ## 1.89.0-rc.12
24
+
25
+ ## 1.89.0-rc.11
26
+
27
+ ## 1.89.0-rc.10
28
+
29
+ ### Minor Changes
30
+
31
+ - 64699d3f: ZERO-2761: Fix invalid import for plugin module
32
+ - 7727ae55: ZERO-3073: Refactor basket page to use server-side data fetching and simplify component structure
33
+ - 33377cfd: ZERO-3267: Refactor import statement for ROUTES in error-page component
34
+
35
+ ## 1.89.0-rc.9
36
+
37
+ ### Minor Changes
38
+
39
+ - 64699d3f: ZERO-2761: Fix invalid import for plugin module
40
+ - 7727ae55: ZERO-3073: Refactor basket page to use server-side data fetching and simplify component structure
41
+ - 33377cfd: ZERO-3267: Refactor import statement for ROUTES in error-page component
42
+
43
+ ## 1.89.0-rc.8
44
+
45
+ ## 1.89.0-rc.7
46
+
47
+ ## 1.89.0-rc.6
48
+
49
+ ## 1.89.0-rc.5
50
+
51
+ ## 1.89.0-rc.4
52
+
53
+ ## 1.89.0-rc.3
54
+
3
55
  ## 1.89.0-rc.2
4
56
 
5
57
  ## 1.89.0-rc.1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/pz-bkm",
3
- "version": "1.89.0-rc.2",
3
+ "version": "1.89.0-rc.20",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
6
  "peerDependencies": {
package/readme.md CHANGED
@@ -35,7 +35,59 @@ export default Bkm;
35
35
 
36
36
  ### Props
37
37
 
38
- | Property | Type | Description |
39
- | -------------- | -------- | ----------------------------------------- |
40
- | `translations` | `object` | Object containing translation strings. |
41
- | `classes` | `object` | Object containing custom CSS class names. |
38
+ | Property | Type | Description |
39
+ | --- | --- | --- |
40
+ | `translations` | `object` | Object containing translation strings. |
41
+ | `classes` | `object` | Object containing custom CSS class names. |
42
+ | `customUIRender` | `React.ReactNode` | Optional function to fully customize the bkm express. Receives control, errors, translations, bkmFrameId and handleSubmit props. |
43
+
44
+ ### Customizing BKM Express
45
+
46
+ ```javascript
47
+ import PluginModule, { Component } from '@akinon/next/components/plugin-module';
48
+
49
+ <PluginModule
50
+ component={Component.BKMExpress}
51
+ props={{
52
+ customUIRender: ({
53
+ handleSubmit,
54
+ onSubmit,
55
+ control,
56
+ errors,
57
+ translations,
58
+ bkmFrameId
59
+ }) => (
60
+ <div className="px-4 py-6">
61
+ <form onSubmit={handleSubmit(onSubmit)}>
62
+ <h2 className="font-semibold text-2xl mb-4">{translations?.title}</h2>
63
+ <p className="text-sm">
64
+ When paying with BKM Express, you will be redirected to
65
+ www.bkmexpress.com.tr. <br />
66
+ You need to log in to the application with the username and password
67
+ you used when signing up to BKM Express. You can easily pay by selecting
68
+ the card you want to make a transaction and the payment method from the
69
+ payment screen that appears. After completing your shopping, you will
70
+ automatically return to site.
71
+ </p>
72
+ <div className="py-4">
73
+ <CheckoutAgreements
74
+ control={control}
75
+ error={errors?.agreement}
76
+ fieldId="agreement"
77
+ />
78
+ </div>
79
+
80
+ <button className="w-full bg-primary text-white h-9" type="submit">
81
+ Pay with BKM Express
82
+ </button>
83
+ </form>
84
+
85
+ <div
86
+ id={bkmFrameId}
87
+ className="bkm-frame !flex justify-center items-center !pt-0"
88
+ ></div>
89
+ </div>
90
+ )
91
+ }}
92
+ />;
93
+ ```
@@ -2,11 +2,21 @@ import React, { ReactElement, useId } from 'react';
2
2
  import Script from 'next/script';
3
3
  import * as yup from 'yup';
4
4
  import { yupResolver } from '@hookform/resolvers/yup';
5
- import { SubmitHandler, useForm } from 'react-hook-form';
5
+ import {
6
+ SubmitHandler,
7
+ useForm,
8
+ UseFormHandleSubmit,
9
+ Control,
10
+ FieldErrors
11
+ } from 'react-hook-form';
6
12
  import { Button } from '@akinon/next/components';
7
13
  import { useCompleteBkmMutation, useSetBkmMutation } from '../endpoints';
8
14
  import { twMerge } from 'tailwind-merge';
9
15
 
16
+ interface BKMOptionForm {
17
+ agreement: boolean;
18
+ }
19
+
10
20
  type BKMOptionProps = {
11
21
  translations?: {
12
22
  title?: string;
@@ -18,6 +28,14 @@ type BKMOptionProps = {
18
28
  description?: string;
19
29
  button?: string;
20
30
  };
31
+ customUIRender?: (params: {
32
+ handleSubmit: UseFormHandleSubmit<BKMOptionForm>;
33
+ onSubmit: SubmitHandler<BKMOptionForm>;
34
+ control: Control<BKMOptionForm>;
35
+ errors: FieldErrors<BKMOptionForm>;
36
+ translations?: BKMOptionProps['translations'];
37
+ bkmFrameId: string;
38
+ }) => ReactElement;
21
39
  agreementCheckbox?: ReactElement;
22
40
  };
23
41
 
@@ -31,7 +49,8 @@ const formSchema = (requiredText?: string) =>
31
49
  const BKMOption = ({
32
50
  translations,
33
51
  classes,
34
- agreementCheckbox
52
+ agreementCheckbox,
53
+ customUIRender
35
54
  }: BKMOptionProps) => {
36
55
  const id = useId();
37
56
  const {
@@ -39,13 +58,13 @@ const BKMOption = ({
39
58
  control,
40
59
  formState: { errors },
41
60
  getValues
42
- } = useForm({
61
+ } = useForm<BKMOptionForm>({
43
62
  resolver: yupResolver(formSchema(translations?.required))
44
63
  });
45
64
  const [setBkm] = useSetBkmMutation();
46
65
  const [completeBkm] = useCompleteBkmMutation();
47
66
 
48
- const onSubmit: SubmitHandler<null> = async () => {
67
+ const onSubmit: SubmitHandler<BKMOptionForm> = async () => {
49
68
  const response = await setBkm(getValues('agreement')).unwrap();
50
69
 
51
70
  const bexContext = response.context_list.find(
@@ -86,6 +105,25 @@ const BKMOption = ({
86
105
  );
87
106
  };
88
107
 
108
+ if (customUIRender) {
109
+ return (
110
+ <>
111
+ {customUIRender({
112
+ handleSubmit,
113
+ onSubmit,
114
+ control,
115
+ errors,
116
+ translations,
117
+ bkmFrameId: `js-bkm-frame-${id}`
118
+ })}
119
+ <Script
120
+ src="https://js.bkmexpress.com.tr/v1/javascripts/bex.js"
121
+ defer
122
+ />
123
+ </>
124
+ );
125
+ }
126
+
89
127
  return (
90
128
  <>
91
129
  <form className="flex flex-col w-full" onSubmit={handleSubmit(onSubmit)}>