@autobusal/order-process 1.0.0 → 1.1.0
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/BKT/Bkt.tsx +2 -2
- package/Content.tsx +4 -0
- package/Standard/Standard.tsx +2 -2
- package/Stripe/Stripe.tsx +28 -0
- package/package.json +1 -1
- package/services.ts +16 -3
- package/types.ts +4 -0
package/BKT/Bkt.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { useForm } from 'react-hook-form';
|
|
|
4
4
|
import { Inline } from '@autobusal/common';
|
|
5
5
|
import { Container } from '../styles';
|
|
6
6
|
import { BKTFormData } from '../types';
|
|
7
|
-
import {
|
|
7
|
+
import { useMakeBkt } from '../services';
|
|
8
8
|
|
|
9
9
|
interface Props {
|
|
10
10
|
hash?: string
|
|
@@ -16,7 +16,7 @@ const Bkt = ({ hash, t }: Props): JSX.Element => {
|
|
|
16
16
|
|
|
17
17
|
const ref = useRef<HTMLFormElement>(null);
|
|
18
18
|
|
|
19
|
-
const { data, isLoading, isSuccess } =
|
|
19
|
+
const { data, isLoading, isSuccess } = useMakeBkt(String(hash));
|
|
20
20
|
|
|
21
21
|
const onSubmit = (): void => {
|
|
22
22
|
ref.current?.submit();
|
package/Content.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TFunction } from 'i18next';
|
|
2
2
|
import Standard from './Standard/Standard';
|
|
3
3
|
import Bkt from './BKT/Bkt';
|
|
4
|
+
import Stripe from './Stripe/Stripe';
|
|
4
5
|
|
|
5
6
|
interface Props {
|
|
6
7
|
type?: string
|
|
@@ -13,6 +14,9 @@ const Content = ({ type, hash, t }: Props): JSX.Element => {
|
|
|
13
14
|
case 'bkt':
|
|
14
15
|
return <Bkt hash={ hash } t={ t } />;
|
|
15
16
|
|
|
17
|
+
case 'stripe':
|
|
18
|
+
return <Stripe hash={ hash } t={ t } />;
|
|
19
|
+
|
|
16
20
|
default:
|
|
17
21
|
return <Standard type={ type } hash={ hash } t={ t } />;
|
|
18
22
|
}
|
package/Standard/Standard.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { TFunction } from 'i18next';
|
|
|
2
2
|
import { Navigate } from 'react-router-dom';
|
|
3
3
|
import { Inline } from '@autobusal/common';
|
|
4
4
|
import { Container } from '../styles';
|
|
5
|
-
import {
|
|
5
|
+
import { useMakeStandard } from '../services';
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
8
8
|
type?: string
|
|
@@ -11,7 +11,7 @@ interface Props {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const Standard = ({ type, hash, t }: Props): JSX.Element => {
|
|
14
|
-
const { data, isSuccess } =
|
|
14
|
+
const { data, isSuccess } = useMakeStandard(String(type), String(hash));
|
|
15
15
|
|
|
16
16
|
if (isSuccess) {
|
|
17
17
|
return <Navigate to={ data } />;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { TFunction } from 'i18next';
|
|
3
|
+
import { Inline } from '@autobusal/common';
|
|
4
|
+
import { Container } from '../styles';
|
|
5
|
+
import { useMakeStripe } from '../services';
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
hash?: string
|
|
9
|
+
t: TFunction<'common'>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const Stripe = ({ hash, t }: Props): JSX.Element => {
|
|
13
|
+
const { data, isSuccess } = useMakeStripe(String(hash));
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (isSuccess) {
|
|
17
|
+
window.location.href = data.redirect;
|
|
18
|
+
}
|
|
19
|
+
}, [data, isSuccess]);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Container>
|
|
23
|
+
<Inline text={ t('order_process.stripe') } />
|
|
24
|
+
</Container>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default Stripe;
|
package/package.json
CHANGED
package/services.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useQuery, UseQueryResult } from '@tanstack/react-query';
|
|
2
2
|
import { apiClient } from '@autobusal/providers';
|
|
3
|
-
import { BKTData } from './types';
|
|
3
|
+
import { BKTData, StripeData } from './types';
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const useMakeStandard = (type: string, hash: string): UseQueryResult<string> => (
|
|
6
6
|
useQuery({
|
|
7
7
|
queryKey: ['process-payment-standard', { type, hash }],
|
|
8
8
|
queryFn: async () => (
|
|
@@ -18,7 +18,7 @@ export const MakeStandard = (type: string, hash: string): UseQueryResult<string>
|
|
|
18
18
|
})
|
|
19
19
|
);
|
|
20
20
|
|
|
21
|
-
export const
|
|
21
|
+
export const useMakeBkt = (hash: string): UseQueryResult<BKTData> => (
|
|
22
22
|
useQuery({
|
|
23
23
|
queryKey: ['process-payment-bkt', { hash }],
|
|
24
24
|
queryFn: async () => (
|
|
@@ -29,4 +29,17 @@ export const MakeBkt = (hash: string): UseQueryResult<BKTData> => (
|
|
|
29
29
|
))
|
|
30
30
|
)
|
|
31
31
|
})
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export const useMakeStripe = (hash: string): UseQueryResult<StripeData> => (
|
|
35
|
+
useQuery({
|
|
36
|
+
queryKey: ['process-payment-stripe', { hash }],
|
|
37
|
+
queryFn: async () => (
|
|
38
|
+
await apiClient
|
|
39
|
+
.post('/api/payment/stripe', { hash })
|
|
40
|
+
.then(response => (
|
|
41
|
+
response?.data ?? ''
|
|
42
|
+
))
|
|
43
|
+
)
|
|
44
|
+
})
|
|
32
45
|
);
|