@autobusal/routes-order 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/Found/Booking/Booking.tsx +2 -2
- package/Found/Dates/Dates.tsx +2 -2
- package/Step1/Step1.tsx +2 -2
- package/Step2.tsx +2 -2
- package/Step3.tsx +2 -2
- package/Step5/Coupons/Coupons.tsx +2 -2
- package/Step5/Payments/Payments.tsx +9 -2
- package/Step5/Step5.tsx +5 -5
- package/package.json +1 -1
- package/services.ts +6 -6
|
@@ -3,7 +3,7 @@ import { createDate } from '@autobusal/utilities';
|
|
|
3
3
|
import { Container, About, LinkBooking } from './styles';
|
|
4
4
|
import { RoutesSearchForm } from '@autobusal/routes-search/types';
|
|
5
5
|
import { FoundData } from '@autobusal/providers/types/routes';
|
|
6
|
-
import {
|
|
6
|
+
import { useGetSettings } from '@autobusal/providers/services';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
9
|
data?: FoundData[]
|
|
@@ -12,7 +12,7 @@ interface Props {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const Booking = ({ data, step1, t }: Props): (JSX.Element | null) => {
|
|
15
|
-
const { data: settings } =
|
|
15
|
+
const { data: settings } = useGetSettings();
|
|
16
16
|
|
|
17
17
|
if (data === undefined || data?.length === 0) {
|
|
18
18
|
return null;
|
package/Found/Dates/Dates.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import Loading from './Loading';
|
|
|
7
7
|
import { Container, Inner, ButtonDay } from './styles';
|
|
8
8
|
import { RoutesSearchForm } from '@autobusal/routes-search/types';
|
|
9
9
|
import { FoundDay } from '../../types';
|
|
10
|
-
import {
|
|
10
|
+
import { useGetDates } from '../../services';
|
|
11
11
|
|
|
12
12
|
interface Props {
|
|
13
13
|
type: 'departure' | '_return'
|
|
@@ -19,7 +19,7 @@ interface Props {
|
|
|
19
19
|
const Dates = ({ type, step1, t, onSearch }: Props): JSX.Element => {
|
|
20
20
|
const [number, setNumber] = useState<number>(0);
|
|
21
21
|
|
|
22
|
-
const { data, isLoading } =
|
|
22
|
+
const { data, isLoading } = useGetDates(step1, type, number);
|
|
23
23
|
|
|
24
24
|
if (isLoading) {
|
|
25
25
|
return <Loading t={ t } />;
|
package/Step1/Step1.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import prepare from './prepare';
|
|
|
7
7
|
import Steps from '../Steps/Steps';
|
|
8
8
|
import { Title } from '../styles';
|
|
9
9
|
import { RoutesSearchForm } from '@autobusal/routes-search/types';
|
|
10
|
-
import {
|
|
10
|
+
import { useGetSettings } from '@autobusal/providers/services';
|
|
11
11
|
|
|
12
12
|
interface Props {
|
|
13
13
|
value?: RoutesSearchForm
|
|
@@ -21,7 +21,7 @@ const Step1 = ({ value, redirected, t, onSave }: Props): JSX.Element => {
|
|
|
21
21
|
|
|
22
22
|
const [ searchParams ] = useSearchParams();
|
|
23
23
|
|
|
24
|
-
const { data } =
|
|
24
|
+
const { data } = useGetSettings();
|
|
25
25
|
|
|
26
26
|
const prepared = prepare(value, params, data.preferences.defaultLocations);
|
|
27
27
|
|
package/Step2.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import Found from './Found/Found';
|
|
|
7
7
|
import { Title, Actions } from './styles';
|
|
8
8
|
import { RoutesSearchForm } from '@autobusal/routes-search/types';
|
|
9
9
|
import { FoundData } from '@autobusal/providers/types/routes';
|
|
10
|
-
import {
|
|
10
|
+
import { useGetDepartures } from './services';
|
|
11
11
|
|
|
12
12
|
interface Props {
|
|
13
13
|
step1: RoutesSearchForm
|
|
@@ -18,7 +18,7 @@ interface Props {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const Step2 = ({ step1, t, onSearch, onSave, onBack }: Props): JSX.Element => {
|
|
21
|
-
const { data, isFetching } =
|
|
21
|
+
const { data, isFetching } = useGetDepartures(step1);
|
|
22
22
|
|
|
23
23
|
return (
|
|
24
24
|
<>
|
package/Step3.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import Found from './Found/Found';
|
|
|
7
7
|
import { Title, Actions } from './styles';
|
|
8
8
|
import { RoutesSearchForm } from '@autobusal/routes-search/types';
|
|
9
9
|
import { FoundData } from '@autobusal/providers/types/routes';
|
|
10
|
-
import {
|
|
10
|
+
import { useGetReturns } from './services';
|
|
11
11
|
|
|
12
12
|
interface Props {
|
|
13
13
|
step1: RoutesSearchForm
|
|
@@ -19,7 +19,7 @@ interface Props {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const Step3 = ({ step1, step2, t, onSearch, onSave, onBack }: Props): JSX.Element => {
|
|
22
|
-
const { data, isFetching } =
|
|
22
|
+
const { data, isFetching } = useGetReturns(step1, step2);
|
|
23
23
|
|
|
24
24
|
return (
|
|
25
25
|
<>
|
|
@@ -8,7 +8,7 @@ import { Container, ContainerForm, ContainerInput } from './styles';
|
|
|
8
8
|
import { CouponData } from '@autobusal/providers/types/orders';
|
|
9
9
|
import { FoundData } from '@autobusal/providers/types/routes';
|
|
10
10
|
import { TotalData, CouponForm } from '../../types';
|
|
11
|
-
import {
|
|
11
|
+
import { useGetCoupon } from '../../services';
|
|
12
12
|
|
|
13
13
|
interface Props {
|
|
14
14
|
current?: CouponData
|
|
@@ -21,7 +21,7 @@ interface Props {
|
|
|
21
21
|
const Coupons = ({ current, step2, t, total, onApplied }: Props): (JSX.Element | null) => {
|
|
22
22
|
const { register, handleSubmit, formState: { errors } } = useForm<CouponForm>();
|
|
23
23
|
|
|
24
|
-
const { mutate: SearchCoupons, isPending } =
|
|
24
|
+
const { mutate: SearchCoupons, isPending } = useGetCoupon(step2.id, total.value);
|
|
25
25
|
|
|
26
26
|
const onSubmit = (data: CouponForm): void => {
|
|
27
27
|
SearchCoupons(data, {
|
|
@@ -6,7 +6,7 @@ import { AiOutlineCreditCard } from 'react-icons/ai';
|
|
|
6
6
|
import { Inline } from '@autobusal/common';
|
|
7
7
|
import { SubTitle } from '../../styles';
|
|
8
8
|
import { Container, ContainerPayments, ButtonPayment } from './styles';
|
|
9
|
-
import {
|
|
9
|
+
import { useGetPayments } from '../../services';
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
12
|
selected: string
|
|
@@ -16,7 +16,7 @@ interface Props {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const Payments = ({ selected, isPartner, t, onChange }: Props): JSX.Element => {
|
|
19
|
-
const { data, isLoading, isSuccess } =
|
|
19
|
+
const { data, isLoading, isSuccess } = useGetPayments();
|
|
20
20
|
|
|
21
21
|
useEffect(() => {
|
|
22
22
|
if (isSuccess) {
|
|
@@ -73,6 +73,13 @@ const Payments = ({ selected, isPartner, t, onChange }: Props): JSX.Element => {
|
|
|
73
73
|
{ t('routes_order.step5.actions.card') }
|
|
74
74
|
</ButtonPayment>
|
|
75
75
|
) }
|
|
76
|
+
|
|
77
|
+
{ (data?.stripe || isPartner) && (
|
|
78
|
+
<ButtonPayment type="button" $selected={ selected === 'stripe' } onClick={ () => onChange('stripe') }>
|
|
79
|
+
<AiOutlineCreditCard />
|
|
80
|
+
{ t('routes_order.step5.actions.card') }
|
|
81
|
+
</ButtonPayment>
|
|
82
|
+
) }
|
|
76
83
|
</ContainerPayments>
|
|
77
84
|
</Container>
|
|
78
85
|
</>
|
package/Step5/Step5.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
2
|
import { TFunction } from 'i18next';
|
|
3
3
|
import { useForm } from 'react-hook-form';
|
|
4
4
|
import { useNavigate } from 'react-router-dom';
|
|
@@ -19,7 +19,7 @@ import { CouponData } from '@autobusal/providers/types/orders';
|
|
|
19
19
|
import { RoutesSearchForm } from '@autobusal/routes-search/types';
|
|
20
20
|
import { TotalData } from '../types';
|
|
21
21
|
import { useUserStore } from '@autobusal/providers/stores/user';
|
|
22
|
-
import {
|
|
22
|
+
import { usePostOrder } from '../services';
|
|
23
23
|
|
|
24
24
|
interface Props {
|
|
25
25
|
step1: RoutesSearchForm
|
|
@@ -44,7 +44,7 @@ const Step5 = ({ step1, step2, step3, step4, isPartner, t, onBack }: Props): JSX
|
|
|
44
44
|
|
|
45
45
|
const { register, handleSubmit, formState: { errors } } = useForm<BillingData>();
|
|
46
46
|
|
|
47
|
-
const { mutate: OrderSend, isPending } =
|
|
47
|
+
const { mutate: OrderSend, isPending } = usePostOrder(step1, step2, step3, step4, coupon, action);
|
|
48
48
|
|
|
49
49
|
const onApplyCoupon = (data: CouponData): void => {
|
|
50
50
|
setTotal(
|
|
@@ -54,9 +54,9 @@ const Step5 = ({ step1, step2, step3, step4, isPartner, t, onBack }: Props): JSX
|
|
|
54
54
|
setCoupon(data);
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
const onAction = (action: string): void => {
|
|
57
|
+
const onAction = useCallback((action: string): void => {
|
|
58
58
|
setAction(action);
|
|
59
|
-
};
|
|
59
|
+
}, []);
|
|
60
60
|
|
|
61
61
|
const onSendForm = async (): Promise<void> => {
|
|
62
62
|
await handleSubmit(onSubmit)();
|
package/package.json
CHANGED
package/services.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { CouponData } from '@autobusal/providers/types/orders';
|
|
|
6
6
|
import { BillingData, PersonData } from '@autobusal/providers/types/persons';
|
|
7
7
|
import { FoundDay, ActionData, SaveData, OrderedData, CouponForm } from './types';
|
|
8
8
|
|
|
9
|
-
export const
|
|
9
|
+
export const useGetDepartures = (data: RoutesSearchForm): UseQueryResult<FoundData[]> => (
|
|
10
10
|
useQuery({
|
|
11
11
|
queryKey: ['search-routes-step2', { data }],
|
|
12
12
|
queryFn: async () => (
|
|
@@ -21,7 +21,7 @@ export const GetDepartures = (data: RoutesSearchForm): UseQueryResult<FoundData[
|
|
|
21
21
|
})
|
|
22
22
|
);
|
|
23
23
|
|
|
24
|
-
export const
|
|
24
|
+
export const useGetReturns = (data: RoutesSearchForm, departure: FoundData): UseQueryResult<FoundData[]> => (
|
|
25
25
|
useQuery({
|
|
26
26
|
queryKey: ['search-routes-step3', { data }],
|
|
27
27
|
queryFn: async () => (
|
|
@@ -39,7 +39,7 @@ export const GetReturns = (data: RoutesSearchForm, departure: FoundData): UseQue
|
|
|
39
39
|
})
|
|
40
40
|
);
|
|
41
41
|
|
|
42
|
-
export const
|
|
42
|
+
export const useGetDates = (step1: RoutesSearchForm, type: ('departure' | '_return'), number: number): UseQueryResult<FoundDay[]> => {
|
|
43
43
|
const step = { ...step1 };
|
|
44
44
|
|
|
45
45
|
// we switch the locations and dates if a return trip
|
|
@@ -68,7 +68,7 @@ export const GetDates = (step1: RoutesSearchForm, type: ('departure' | '_return'
|
|
|
68
68
|
})
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
export const
|
|
71
|
+
export const usePostOrder = (
|
|
72
72
|
step1: RoutesSearchForm,
|
|
73
73
|
step2: FoundData,
|
|
74
74
|
step3: (FoundData | undefined),
|
|
@@ -118,7 +118,7 @@ export const PostOrder = (
|
|
|
118
118
|
})
|
|
119
119
|
);
|
|
120
120
|
|
|
121
|
-
export const
|
|
121
|
+
export const useGetCoupon = (routeId: number, total: number): UseMutationResult<CouponData, Error, CouponForm, unknown> => (
|
|
122
122
|
useMutation({
|
|
123
123
|
mutationKey: ['search-coupon'],
|
|
124
124
|
mutationFn: async (data: CouponForm) => (
|
|
@@ -135,7 +135,7 @@ export const GetCoupon = (routeId: number, total: number): UseMutationResult<Cou
|
|
|
135
135
|
})
|
|
136
136
|
);
|
|
137
137
|
|
|
138
|
-
export const
|
|
138
|
+
export const useGetPayments = (): UseQueryResult<ActionData> => (
|
|
139
139
|
useQuery({
|
|
140
140
|
queryKey: ['allowed-funds'],
|
|
141
141
|
queryFn: async () => (
|