@akinon/pz-pay-on-delivery 2.0.0-beta.10 → 2.0.0-beta.12
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 +12 -0
- package/package.json +1 -1
- package/src/endpoints.ts +0 -1
- package/src/index.tsx +48 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @akinon/pz-pay-on-delivery
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.12
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1d79e32: ZERO-3540: Next.js Upgrade to 15.4.5
|
|
8
|
+
|
|
9
|
+
## 2.0.0-beta.11
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- ac783d6: ZERO-3482: Update tailwindcss to version 4.1.11 and enhance button cursor styles
|
|
14
|
+
|
|
3
15
|
## 2.0.0-beta.10
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/package.json
CHANGED
package/src/endpoints.ts
CHANGED
package/src/index.tsx
CHANGED
|
@@ -2,7 +2,14 @@ import { useAppSelector } from '@akinon/next/redux/hooks';
|
|
|
2
2
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
3
3
|
import { Button, Icon, Price, Radio } from '@akinon/next/components';
|
|
4
4
|
import React, { useEffect, useState } from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
SubmitHandler,
|
|
7
|
+
useForm,
|
|
8
|
+
UseFormHandleSubmit,
|
|
9
|
+
UseFormRegister,
|
|
10
|
+
Control,
|
|
11
|
+
FieldErrors
|
|
12
|
+
} from 'react-hook-form';
|
|
6
13
|
import { RootState } from 'redux/store';
|
|
7
14
|
import * as yup from 'yup';
|
|
8
15
|
import {
|
|
@@ -10,6 +17,11 @@ import {
|
|
|
10
17
|
useSetPayOnDeliveryChoiceMutation
|
|
11
18
|
} from './endpoints';
|
|
12
19
|
|
|
20
|
+
interface PayOnDeliveryForm {
|
|
21
|
+
agreement: boolean;
|
|
22
|
+
paymentType: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
13
25
|
interface PayOnDeliveryTranslationsProps {
|
|
14
26
|
paymentInformationTitle: string;
|
|
15
27
|
paymentInformationSubtitle: string;
|
|
@@ -43,29 +55,34 @@ const defaultTranslations = {
|
|
|
43
55
|
interface PayOnDeliveryProps {
|
|
44
56
|
translations: Record<string, PayOnDeliveryTranslationsProps>;
|
|
45
57
|
agreementCheckbox?: React.ReactElement;
|
|
58
|
+
customUIRender?: (props: {
|
|
59
|
+
handleSubmit: UseFormHandleSubmit<PayOnDeliveryForm>;
|
|
60
|
+
onSubmit: SubmitHandler<any>;
|
|
61
|
+
paymentChoices: any[];
|
|
62
|
+
preOrder: any;
|
|
63
|
+
formError: string | null;
|
|
64
|
+
isLoading: boolean;
|
|
65
|
+
register: UseFormRegister<PayOnDeliveryForm>;
|
|
66
|
+
control: Control<PayOnDeliveryForm>;
|
|
67
|
+
errors: FieldErrors<PayOnDeliveryForm>;
|
|
68
|
+
setPayOnDeliveryChoice: (value: string) => void;
|
|
69
|
+
}) => React.ReactNode;
|
|
46
70
|
}
|
|
47
71
|
|
|
48
72
|
export const PayOnDelivery = ({
|
|
49
73
|
translations,
|
|
50
|
-
agreementCheckbox
|
|
74
|
+
agreementCheckbox,
|
|
75
|
+
customUIRender
|
|
51
76
|
}: PayOnDeliveryProps) => {
|
|
52
77
|
const _translations = {
|
|
53
78
|
...defaultTranslations,
|
|
54
79
|
...translations
|
|
55
80
|
};
|
|
56
81
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
agreement: yup
|
|
62
|
-
.boolean()
|
|
63
|
-
.oneOf([true], _translations.requiredFieldMessage),
|
|
64
|
-
paymentType: yup.string()
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const payOnDeliveryFormSchema = createPayOnDeliveryFormSchema(_translations);
|
|
82
|
+
const payOnDeliveryFormSchema = yup.object().shape({
|
|
83
|
+
agreement: yup.boolean().oneOf([true], _translations.requiredFieldMessage),
|
|
84
|
+
paymentType: yup.string()
|
|
85
|
+
});
|
|
69
86
|
|
|
70
87
|
const {
|
|
71
88
|
handleSubmit,
|
|
@@ -73,12 +90,11 @@ export const PayOnDelivery = ({
|
|
|
73
90
|
register,
|
|
74
91
|
formState: { errors },
|
|
75
92
|
setValue
|
|
76
|
-
} = useForm({
|
|
93
|
+
} = useForm<PayOnDeliveryForm>({
|
|
77
94
|
resolver: yupResolver(payOnDeliveryFormSchema)
|
|
78
95
|
});
|
|
79
96
|
|
|
80
97
|
const [setCompletePayOnDelivery] = useSetCompletePayOnDeliveryMutation();
|
|
81
|
-
|
|
82
98
|
const [setPayOnDeliveryPaymentChoice, { isLoading }] =
|
|
83
99
|
useSetPayOnDeliveryChoiceMutation();
|
|
84
100
|
const [formError, setFormError] = useState(null);
|
|
@@ -87,15 +103,13 @@ export const PayOnDelivery = ({
|
|
|
87
103
|
(state: RootState) => state.checkout
|
|
88
104
|
);
|
|
89
105
|
|
|
90
|
-
const onSubmit: SubmitHandler<
|
|
106
|
+
const onSubmit: SubmitHandler<PayOnDeliveryForm> = async (data) => {
|
|
91
107
|
const response = await setCompletePayOnDelivery(data).unwrap();
|
|
92
|
-
|
|
93
108
|
setFormError(response?.errors?.non_field_errors);
|
|
94
109
|
};
|
|
95
110
|
|
|
96
111
|
const setPayOnDeliveryChoice = async (value: string) => {
|
|
97
112
|
if (isLoading) return;
|
|
98
|
-
|
|
99
113
|
const response = await setPayOnDeliveryPaymentChoice(value).unwrap();
|
|
100
114
|
setFormError(response?.errors?.non_field_errors);
|
|
101
115
|
};
|
|
@@ -108,6 +122,21 @@ export const PayOnDelivery = ({
|
|
|
108
122
|
}
|
|
109
123
|
}, [paymentChoices, preOrder?.payment_choice]);
|
|
110
124
|
|
|
125
|
+
if (customUIRender) {
|
|
126
|
+
return customUIRender({
|
|
127
|
+
handleSubmit,
|
|
128
|
+
onSubmit,
|
|
129
|
+
register,
|
|
130
|
+
control,
|
|
131
|
+
errors,
|
|
132
|
+
paymentChoices,
|
|
133
|
+
preOrder,
|
|
134
|
+
formError,
|
|
135
|
+
isLoading,
|
|
136
|
+
setPayOnDeliveryChoice
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
111
140
|
return (
|
|
112
141
|
<form
|
|
113
142
|
id="pay_on_delivery"
|