@akinon/pz-gpay 2.0.0-beta.13 → 2.0.0-beta.14
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 +6 -0
- package/package.json +1 -1
- package/src/views/gpay-option.tsx +32 -9
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from '../endpoints';
|
|
20
20
|
import { twMerge } from 'tailwind-merge';
|
|
21
21
|
import { Button } from '@akinon/next/components/button';
|
|
22
|
-
import { getPosError } from '@akinon/next/utils';
|
|
22
|
+
import { getPosError, checkPaymentWillRedirect } from '@akinon/next/utils';
|
|
23
23
|
|
|
24
24
|
type GPayForm = Record<string, never>;
|
|
25
25
|
|
|
@@ -61,6 +61,7 @@ const defaultTranslations: GPayTranslations = {
|
|
|
61
61
|
export function GPayOption(props: GPayOptionProps) {
|
|
62
62
|
const [formError, setFormError] = useState<string | null>(null);
|
|
63
63
|
const [errors, setErrors] = useState<string[]>([]);
|
|
64
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
64
65
|
|
|
65
66
|
const translations = { ...defaultTranslations, ...props.translations };
|
|
66
67
|
|
|
@@ -72,25 +73,46 @@ export function GPayOption(props: GPayOptionProps) {
|
|
|
72
73
|
const {
|
|
73
74
|
handleSubmit,
|
|
74
75
|
control,
|
|
75
|
-
formState: { errors: formErrors }
|
|
76
|
+
formState: { errors: formErrors, isSubmitting }
|
|
76
77
|
} = useForm<GPayForm>({
|
|
77
78
|
resolver: yupResolver(gpayFormSchema) as any
|
|
78
79
|
});
|
|
79
80
|
|
|
80
81
|
const [setPaymentOption] = useSetPaymentOptionMutation();
|
|
81
|
-
const [setGPayMethod] =
|
|
82
|
-
|
|
82
|
+
const [setGPayMethod, { isLoading: isSettingMethod }] =
|
|
83
|
+
useSetGPayMethodMutation();
|
|
84
|
+
const [setCompleteGPay, { isLoading: isCompleting }] =
|
|
85
|
+
useSetCompleteGPayMutation();
|
|
86
|
+
|
|
87
|
+
const isButtonDisabled =
|
|
88
|
+
isSubmitting ||
|
|
89
|
+
isPaymentStepBusy ||
|
|
90
|
+
isSettingMethod ||
|
|
91
|
+
isCompleting ||
|
|
92
|
+
isProcessing;
|
|
83
93
|
|
|
84
94
|
const onSubmit: SubmitHandler<GPayForm> = async () => {
|
|
85
|
-
if (
|
|
95
|
+
if (isButtonDisabled) return;
|
|
86
96
|
|
|
97
|
+
setIsProcessing(true);
|
|
87
98
|
setFormError(null);
|
|
88
|
-
await setGPayMethod();
|
|
89
99
|
|
|
90
|
-
|
|
100
|
+
try {
|
|
101
|
+
await setGPayMethod();
|
|
91
102
|
|
|
92
|
-
|
|
93
|
-
|
|
103
|
+
const response = await setCompleteGPay().unwrap();
|
|
104
|
+
|
|
105
|
+
if (response?.errors?.non_field_errors) {
|
|
106
|
+
setFormError(response.errors.non_field_errors);
|
|
107
|
+
setIsProcessing(false);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (response?.errors || !checkPaymentWillRedirect(response)) {
|
|
112
|
+
setIsProcessing(false);
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
setIsProcessing(false);
|
|
94
116
|
}
|
|
95
117
|
};
|
|
96
118
|
|
|
@@ -137,6 +159,7 @@ export function GPayOption(props: GPayOptionProps) {
|
|
|
137
159
|
data-testid="gpay-payment-button"
|
|
138
160
|
className={twMerge('w-full mt-3', props.buttonClassName)}
|
|
139
161
|
type="submit"
|
|
162
|
+
disabled={isButtonDisabled}
|
|
140
163
|
>
|
|
141
164
|
{translations.button}
|
|
142
165
|
</Button>
|