@akinon/pz-credit-payment 1.92.0-rc.9 → 1.92.0-snapshot-ZERO-3449-20250618101111

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,46 +1,8 @@
1
1
  # @akinon/pz-credit-payment
2
2
 
3
- ## 1.92.0-rc.9
3
+ ## 1.92.0-snapshot-ZERO-3449-20250618101111
4
4
 
5
- ## 1.92.0-rc.8
6
-
7
- ## 1.92.0-rc.7
8
-
9
- ## 1.91.0-rc.6
10
-
11
- ## 1.91.0-rc.5
12
-
13
- ## 1.91.0-rc.4
14
-
15
- ### Minor Changes
16
-
17
- - 7eb51ca: ZERO-3424 :Update package versions
18
-
19
- ## 1.91.0-rc.3
20
-
21
- ### Minor Changes
22
-
23
- - 310556ec: ZERO-3372 :Add README and enhance CreditPayment component with renderer support
24
- - 64699d3f: ZERO-2761: Fix invalid import for plugin module
25
- - e974d8e8: ZERO-3406: Fix rc build
26
- - 7727ae55: ZERO-3073: Refactor basket page to use server-side data fetching and simplify component structure
27
- - 33377cfd: ZERO-3267: Refactor import statement for ROUTES in error-page component
28
- - fec9638a: ZERO-3346 :Update data-testid for Credit Payment button
29
-
30
- ## 1.91.0-rc.2
31
-
32
- ## 1.91.0-rc.1
33
-
34
- ## 1.91.0-rc.0
35
-
36
- ### Minor Changes
37
-
38
- - 310556e: ZERO-3372 :Add README and enhance CreditPayment component with renderer support
39
- - 64699d3f: ZERO-2761: Fix invalid import for plugin module
40
- - e974d8e: ZERO-3406: Fix rc build
41
- - 7727ae55: ZERO-3073: Refactor basket page to use server-side data fetching and simplify component structure
42
- - 33377cfd: ZERO-3267: Refactor import statement for ROUTES in error-page component
43
- - fec9638a: ZERO-3346 :Update data-testid for Credit Payment button
5
+ ## 1.91.0
44
6
 
45
7
  ## 1.90.0
46
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/pz-credit-payment",
3
- "version": "1.92.0-rc.9",
3
+ "version": "1.92.0-snapshot-ZERO-3449-20250618101111",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
6
  "peerDependencies": {
package/src/index.tsx CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  import React from 'react';
2
3
  import { yupResolver } from '@hookform/resolvers/yup';
3
4
  import { useEffect, useState } from 'react';
@@ -26,23 +27,10 @@ const defaultTranslations = {
26
27
  };
27
28
 
28
29
  export interface CreditPaymentProps {
29
- translations?: Record<string, CreditPaymentTranslationsProps>;
30
+ translations: Record<string, CreditPaymentTranslationsProps>;
30
31
  agreementCheckbox: React.ReactElement;
31
32
  titleClassName?: string;
32
33
  buttonClassName?: string;
33
- renderer?: {
34
- Content?: (props: {
35
- control: any;
36
- errors: any;
37
- onSubmit: () => void;
38
- creditPaymentOptions: any[];
39
- selectedCreditPaymentPk: number | null;
40
- setCreditPaymentOption: (pk: number) => void;
41
- preOrder: RootState['checkout']['preOrder'];
42
- agreementCheckbox: React.ReactElement;
43
- formError: string | null;
44
- }) => JSX.Element;
45
- };
46
34
  }
47
35
 
48
36
  const creditPaymentFormSchema = (requiredFieldMessage) =>
@@ -50,13 +38,14 @@ const creditPaymentFormSchema = (requiredFieldMessage) =>
50
38
  agreement: yup.boolean().oneOf([true], requiredFieldMessage)
51
39
  });
52
40
 
53
- export const CreditPayment = ({
54
- translations,
55
- agreementCheckbox,
56
- titleClassName,
57
- buttonClassName,
58
- renderer
59
- }: CreditPaymentProps) => {
41
+ export const CreditPayment = (
42
+ {
43
+ translations,
44
+ agreementCheckbox,
45
+ titleClassName,
46
+ buttonClassName
47
+ }: CreditPaymentProps
48
+ ) => {
60
49
  const _translations = {
61
50
  ...defaultTranslations,
62
51
  ...translations
@@ -68,22 +57,21 @@ export const CreditPayment = ({
68
57
  register,
69
58
  formState: { errors }
70
59
  } = useForm({
71
- resolver: yupResolver(
72
- creditPaymentFormSchema(_translations.requiredFieldMessage)
73
- )
60
+ resolver: yupResolver(creditPaymentFormSchema(_translations.requiredFieldMessage))
74
61
  });
75
62
  const [formError, setFormError] = useState<string | null>(null);
76
63
 
77
64
  const [setCreditPaymentOption] = useSetCreditPaymentOptionMutation();
78
65
  const [confirmationCreditPayment] = useConfirmationCreditPaymentMutation();
79
66
 
80
- const { creditPaymentOptions, selectedCreditPaymentPk, preOrder } =
81
- useAppSelector((state: RootState) => state.checkout);
67
+ const { creditPaymentOptions, selectedCreditPaymentPk, preOrder } = useAppSelector(
68
+ (state: RootState) => state.checkout
69
+ );
82
70
 
83
71
  const onSubmit: SubmitHandler<any> = async () => {
84
72
  const response = await confirmationCreditPayment().unwrap();
85
73
 
86
- if (response?.errors?.non_field_errors) {
74
+ if(response?.errors?.non_field_errors) {
87
75
  setFormError(response?.errors?.non_field_errors);
88
76
  return;
89
77
  }
@@ -93,38 +81,17 @@ export const CreditPayment = ({
93
81
  if (creditPaymentOptions?.length && !preOrder.credit_payment_option) {
94
82
  setCreditPaymentOption(creditPaymentOptions[0].pk);
95
83
  }
96
- }, [
97
- creditPaymentOptions,
98
- selectedCreditPaymentPk,
99
- preOrder.credit_payment_option,
100
- setCreditPaymentOption
101
- ]);
102
-
103
- if (renderer?.Content) {
104
- return renderer.Content({
105
- control,
106
- errors,
107
- onSubmit: handleSubmit(onSubmit),
108
- creditPaymentOptions,
109
- selectedCreditPaymentPk,
110
- setCreditPaymentOption,
111
- preOrder,
112
- agreementCheckbox,
113
- formError
114
- });
115
- }
84
+ }, [creditPaymentOptions, selectedCreditPaymentPk, preOrder.credit_payment_option, setCreditPaymentOption]);
116
85
 
117
86
  return (
118
87
  <form className="flex flex-col w-full" onSubmit={handleSubmit(onSubmit)}>
119
- <div
120
- className={clsx(
121
- twMerge(
122
- 'flex justify-start items-center border-solid border-gray-400 px-4 py-2 sm:px-6 sm:py-3 sm:min-h-15',
123
- 'text-black-800 text-lg font-medium sm:text-2xl',
124
- titleClassName
88
+ <div className={clsx(
89
+ twMerge(
90
+ 'flex justify-start items-center border-solid border-gray-400 px-4 py-2 sm:px-6 sm:py-3 sm:min-h-15',
91
+ 'text-black-800 text-lg font-medium sm:text-2xl',
92
+ titleClassName
125
93
  )
126
- )}
127
- >
94
+ )}>
128
95
  {_translations.title}
129
96
  </div>
130
97
 
@@ -138,10 +105,7 @@ export const CreditPayment = ({
138
105
  <Radio
139
106
  type="radio"
140
107
  value={bank.pk}
141
- checked={
142
- bank.pk === selectedCreditPaymentPk ||
143
- preOrder.credit_payment_option?.pk === bank.pk
144
- }
108
+ checked={bank.pk === selectedCreditPaymentPk || preOrder.credit_payment_option?.pk === bank.pk}
145
109
  {...register('paymentType')}
146
110
  onChange={() => {
147
111
  setCreditPaymentOption(bank.pk);
@@ -159,12 +123,12 @@ export const CreditPayment = ({
159
123
 
160
124
  <div className="px-4 sm:px-6">
161
125
  <div className="flex items-start flex-col py-4 space-y-4">
162
- {agreementCheckbox &&
126
+ {agreementCheckbox &&
163
127
  React.cloneElement(agreementCheckbox, {
164
128
  control,
165
129
  error: errors.agreement,
166
130
  fieldId: 'agreement'
167
- })}
131
+ })}
168
132
 
169
133
  {formError && (
170
134
  <div className="w-full text-xs text-start px-1 mt-3 text-error">
@@ -174,12 +138,12 @@ export const CreditPayment = ({
174
138
 
175
139
  <Button
176
140
  type="submit"
177
- data-testid="checkout-credit-payment-button"
141
+ data-testid="checkout-bank-account-place-order"
178
142
  className={clsx(
179
143
  twMerge(
180
144
  'group uppercase mt-4 inline-flex items-center justify-center w-full',
181
145
  buttonClassName
182
- )
146
+ )
183
147
  )}
184
148
  >
185
149
  <span>{_translations.buttonName}</span>
@@ -195,3 +159,4 @@ export const CreditPayment = ({
195
159
  </form>
196
160
  );
197
161
  };
162
+
package/README.md DELETED
@@ -1,126 +0,0 @@
1
- # @akinon/pz-credit-payment
2
-
3
- ## Installation method
4
-
5
- You can use the following command to install the extension with the latest plugins:
6
-
7
- ```bash
8
-
9
- npx @akinon/projectzero@latest --plugins
10
-
11
- ```
12
-
13
- ## CreditPayment
14
-
15
- A customizable React component that enables customers to select a credit payment option during checkout and confirm their agreement to terms before placing the order.
16
-
17
- ### Props
18
-
19
- #### `CreditPaymentProps`
20
-
21
- | Prop | Type | Required | Description |
22
- | --- | --- | --- | --- |
23
- | `translations` | `Record<string, CreditPaymentTranslationsProps>` | Optional | Localization texts for title, button and validation message |
24
- | `agreementCheckbox` | `React.ReactElement` | Required | A controlled checkbox React element (e.g., terms agreement checkbox) |
25
- | `titleClassName` | `string` | Optional | Optional custom CSS class for the title area |
26
- | `buttonClassName` | `string` | Optional | Optional custom CSS class for the submit button |
27
- | `renderer` | `{ Content?: (props: RendererProps) => JSX.Element }` | Optional | Optional override to fully control the rendering of the component |
28
-
29
- #### `CreditPaymentTranslationsProps`
30
-
31
- | Key | Type | Description |
32
- | --- | --- | --- |
33
- | `title` | `string` | Title text shown at the top of the section |
34
- | `buttonName` | `string` | Submit button label |
35
- | `requiredFieldMessage` | `string` | Error message when checkbox is not checked |
36
-
37
- #### RendererProps (for `renderer.Content`)
38
-
39
- | Prop | Type | Description |
40
- | --- | --- | --- |
41
- | `control` | `any` | React Hook Form control instance |
42
- | `errors` | `any` | React Hook Form errors object |
43
- | `onSubmit` | `() => void` | Submit handler |
44
- | `creditPaymentOptions` | `any[]` | Available credit payment options |
45
- | `selectedCreditPaymentPk` | `number \| null` | Currently selected option's primary key |
46
- | `setCreditPaymentOption` | `(pk: number) => void` | Setter for selecting a payment option |
47
- | `preOrder` | `RootState['checkout']['preOrder']` | Pre-order object from Redux |
48
- | `agreementCheckbox` | `React.ReactElement` | Provided agreement checkbox component |
49
- | `formError` | `string \| null` | Any error returned from the confirmation API |
50
-
51
- ### Usage
52
-
53
- ```bash
54
- src/views/checkout/steps/payment/options/credit-payment/
55
- ```
56
-
57
- #### Default Usage
58
-
59
- ```javascript
60
- <PluginModule
61
- component={Component.CreditPayment}
62
- props={{
63
- agreementCheckbox: (
64
- <CheckoutAgreements control={null} error={null} fieldId="agreement" />
65
- )
66
- }}
67
- />
68
- ```
69
-
70
- #### Customized Usage with `renderer`
71
-
72
- ```javascript
73
- <PluginModule
74
- component={Component.CreditPayment}
75
- props={{
76
- agreementCheckbox: (
77
- <CheckoutAgreements control={null} error={null} fieldId="agreement" />
78
- ),
79
- renderer: {
80
- Content: ({
81
- control,
82
- errors,
83
- onSubmit,
84
- creditPaymentOptions,
85
- selectedCreditPaymentPk,
86
- setCreditPaymentOption,
87
- preOrder,
88
- agreementCheckbox,
89
- formError
90
- }) => (
91
- <form onSubmit={onSubmit} className="p-6 bg-white rounded-lg space-y-6">
92
- <h2 className="text-xl font-semibold">SHOPPING CREDIT</h2>
93
- <div className="space-y-4">
94
- {creditPaymentOptions.map((bank) => (
95
- <label
96
- key={bank.pk}
97
- className="p-4 flex items-center cursor-pointer rounded-lg border-gray-480 border space-x-5 pl-5 mb-6"
98
- >
99
- <Radio
100
- type="radio"
101
- value={bank.pk}
102
- checked={
103
- bank.pk === selectedCreditPaymentPk ||
104
- preOrder.credit_payment_option?.pk === bank.pk
105
- }
106
- onChange={() => setCreditPaymentOption(bank.pk)}
107
- />
108
- <span>{bank.name}</span>
109
- </label>
110
- ))}
111
- </div>
112
- {React.cloneElement(agreementCheckbox, {
113
- control,
114
- error: errors.agreement,
115
- fieldId: 'agreement'
116
- })}
117
- {formError && <p className="text-xs text-error mt-2">{formError}</p>}
118
- <Button type="submit" className="w-full bg-black text-white">
119
- Place Order
120
- </Button>
121
- </form>
122
- )
123
- }
124
- }}
125
- />
126
- ```