@autobusal/routes-order 1.9.0 → 1.11.1
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 +176 -0
- package/Checkout/Checkout.tsx +280 -0
- package/Checkout/Sidebar/Sidebar.tsx +110 -0
- package/Checkout/Sidebar/styles.ts +44 -0
- package/Found/Empty/Empty.tsx +109 -0
- package/Found/Empty/styles.ts +99 -0
- package/Found/Filters/Filters.tsx +10 -7
- package/Found/Filters/styles.ts +79 -8
- package/Found/Found.tsx +47 -26
- package/Found/Header/styles.ts +20 -4
- package/Found/Orders/Orders.tsx +13 -4
- package/Found/Route/Route.tsx +46 -18
- package/Found/Route/styles.ts +109 -31
- package/Found/Summary/Summary.tsx +1 -1
- package/Found/Summary/styles.ts +12 -0
- package/Found/refine.ts +69 -0
- package/RoutesOrder.tsx +45 -23
- package/Step2.tsx +34 -1
- package/Step4/Passenger/Passenger.tsx +10 -10
- package/Step5/Billing/Billing.tsx +8 -7
- package/Step5/Coupons/styles.ts +16 -9
- package/Step5/Payments/styles.ts +7 -4
- package/Step5/Summary/About/About.tsx +66 -16
- package/Step5/Summary/About/styles.ts +81 -0
- package/Steps/Steps.tsx +3 -1
- package/package.json +1 -1
- package/services.ts +46 -4
- package/styles.ts +49 -0
- package/types.ts +24 -0
- package/Step4/Step4.tsx +0 -114
- package/Step5/Step5.tsx +0 -185
package/Step5/Step5.tsx
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from 'react';
|
|
2
|
-
import { TFunction } from 'i18next';
|
|
3
|
-
import { useForm } from 'react-hook-form';
|
|
4
|
-
import { useNavigate } from 'react-router-dom';
|
|
5
|
-
import { RiShoppingCartLine } from 'react-icons/ri';
|
|
6
|
-
import { AiOutlineCaretLeft } from 'react-icons/ai';
|
|
7
|
-
import { MdDone } from 'react-icons/md';
|
|
8
|
-
import { Button } from '@autobusal/common';
|
|
9
|
-
import Steps from '../Steps/Steps';
|
|
10
|
-
import Summary from './Summary/Summary';
|
|
11
|
-
import Coupons from './Coupons/Coupons';
|
|
12
|
-
import Addons from './Addons/Addons';
|
|
13
|
-
import Billing from './Billing/Billing';
|
|
14
|
-
import Payments from './Payments/Payments';
|
|
15
|
-
import { getTotal, convertCoupon } from './utilities';
|
|
16
|
-
import { Title, Actions } from '../styles';
|
|
17
|
-
import { PersonData, BillingData } from '@autobusal/providers/types/persons';
|
|
18
|
-
import { FoundData } from '@autobusal/providers/types/routes';
|
|
19
|
-
import { CouponData } from '@autobusal/providers/types/orders';
|
|
20
|
-
import { RoutesSearchForm } from '@autobusal/routes-search/types';
|
|
21
|
-
import { TotalData } from '../types';
|
|
22
|
-
import { useUserStore } from '@autobusal/providers/stores/user';
|
|
23
|
-
import { useGetSettings } from '@autobusal/providers/services';
|
|
24
|
-
import { usePostOrder } from '../services';
|
|
25
|
-
|
|
26
|
-
interface Props {
|
|
27
|
-
step1: RoutesSearchForm
|
|
28
|
-
step2: FoundData
|
|
29
|
-
step3?: FoundData
|
|
30
|
-
step4: PersonData
|
|
31
|
-
isPartner?: boolean
|
|
32
|
-
t: TFunction<'common'>
|
|
33
|
-
onBack: (step: number) => void
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const Step5 = ({ step1, step2, step3, step4, isPartner, t, onBack }: Props): JSX.Element => {
|
|
37
|
-
const [ coupon, setCoupon ] = useState<CouponData | undefined>(undefined);
|
|
38
|
-
const [ total, setTotal ] = useState<TotalData>(
|
|
39
|
-
getTotal(step2, step3)
|
|
40
|
-
);
|
|
41
|
-
const [ action, setAction ] = useState<string | undefined>(undefined);
|
|
42
|
-
|
|
43
|
-
const [ addonWhatsapp, setAddonWhatsapp ] = useState<boolean>(false);
|
|
44
|
-
const [ addonWhatsappNumber, setAddonWhatsappNumber ] = useState<string>('');
|
|
45
|
-
const [ addonTelegram, setAddonTelegram ] = useState<boolean>(false);
|
|
46
|
-
|
|
47
|
-
const { data: UserData } = useUserStore();
|
|
48
|
-
const { data: SettingsData } = useGetSettings();
|
|
49
|
-
|
|
50
|
-
const navigate = useNavigate();
|
|
51
|
-
|
|
52
|
-
const { register, handleSubmit, formState: { errors } } = useForm<BillingData>();
|
|
53
|
-
|
|
54
|
-
// Edited: Ferjolt Ozuni - Date: 2026-07-25
|
|
55
|
-
// Paid addons are priced/verified server-side (see obtapi's
|
|
56
|
-
// App\Libraries\Orders\Make\Addons) - this is only for the checkout
|
|
57
|
-
// summary display and the grand total shown before payment.
|
|
58
|
-
const currency = total.display.split(' ')[1] ?? '';
|
|
59
|
-
|
|
60
|
-
const addonItems = [
|
|
61
|
-
addonWhatsapp && SettingsData?.addons?.whatsapp.available ? {
|
|
62
|
-
label: t('routes_order.step5.addons.whatsapp.label'),
|
|
63
|
-
price: SettingsData.addons.whatsapp.price
|
|
64
|
-
} : null,
|
|
65
|
-
addonTelegram && SettingsData?.addons?.telegram.available ? {
|
|
66
|
-
label: t('routes_order.step5.addons.telegram.label'),
|
|
67
|
-
price: SettingsData.addons.telegram.price
|
|
68
|
-
} : null
|
|
69
|
-
].filter((item): item is { label: string, price: number } => item !== null);
|
|
70
|
-
|
|
71
|
-
const addonsValue = addonItems.reduce((sum, item) => sum + item.price, 0);
|
|
72
|
-
|
|
73
|
-
const grandTotal: TotalData = {
|
|
74
|
-
display: `${ total.value + addonsValue } ${ currency }`,
|
|
75
|
-
value: total.value + addonsValue
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const { mutate: OrderSend, isPending } = usePostOrder(step1, step2, step3, step4, coupon, action, {
|
|
79
|
-
whatsapp: addonWhatsapp,
|
|
80
|
-
whatsappNumber: addonWhatsappNumber,
|
|
81
|
-
telegram: addonTelegram
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const onApplyCoupon = (data: CouponData): void => {
|
|
85
|
-
setTotal(
|
|
86
|
-
convertCoupon(data)
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
setCoupon(data);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const onAction = useCallback((action: string): void => {
|
|
93
|
-
setAction(action);
|
|
94
|
-
}, []);
|
|
95
|
-
|
|
96
|
-
const onSendForm = async (): Promise<void> => {
|
|
97
|
-
if (addonWhatsapp && addonWhatsappNumber.trim().length < 5) {
|
|
98
|
-
alert(t('routes_order.step5.addons.whatsapp.phone_error'));
|
|
99
|
-
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
await handleSubmit(onSubmit)();
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const onSubmit = (data: BillingData): void => {
|
|
107
|
-
OrderSend(data, {
|
|
108
|
-
onSuccess: (data) => {
|
|
109
|
-
if (data === undefined) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const hash = step1.type === 'return' ? data.return : data.departure;
|
|
114
|
-
|
|
115
|
-
navigate(`/orders/process/${ action }/${ hash }`);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<>
|
|
122
|
-
<Title>
|
|
123
|
-
<RiShoppingCartLine />
|
|
124
|
-
{ t('routes_order.step5.title') }
|
|
125
|
-
</Title>
|
|
126
|
-
|
|
127
|
-
<Steps value={ 5 } />
|
|
128
|
-
|
|
129
|
-
<Summary
|
|
130
|
-
step1={ step1 }
|
|
131
|
-
step2={ step2 }
|
|
132
|
-
step3={ step3 }
|
|
133
|
-
step4={ step4 }
|
|
134
|
-
coupon={ coupon }
|
|
135
|
-
addons={ addonItems.map(item => ({ label: item.label, value: `${ item.price } ${ currency }` })) }
|
|
136
|
-
total={ grandTotal }
|
|
137
|
-
t={ t }
|
|
138
|
-
/>
|
|
139
|
-
|
|
140
|
-
<Coupons current={ coupon } step2={ step2 } total={ total } t={ t } onApplied={ onApplyCoupon } />
|
|
141
|
-
|
|
142
|
-
<Addons
|
|
143
|
-
data={ SettingsData?.addons }
|
|
144
|
-
currency={ currency }
|
|
145
|
-
whatsapp={ addonWhatsapp }
|
|
146
|
-
whatsappNumber={ addonWhatsappNumber }
|
|
147
|
-
telegram={ addonTelegram }
|
|
148
|
-
t={ t }
|
|
149
|
-
onChangeWhatsapp={ setAddonWhatsapp }
|
|
150
|
-
onChangeWhatsappNumber={ setAddonWhatsappNumber }
|
|
151
|
-
onChangeTelegram={ setAddonTelegram }
|
|
152
|
-
/>
|
|
153
|
-
|
|
154
|
-
{ UserData === undefined && <Billing t={ t } errors={ errors } refs={ register } /> }
|
|
155
|
-
|
|
156
|
-
<Payments
|
|
157
|
-
selected={ action ?? '' }
|
|
158
|
-
isPartner={ isPartner ?? false }
|
|
159
|
-
t={ t }
|
|
160
|
-
onChange={ onAction }
|
|
161
|
-
/>
|
|
162
|
-
|
|
163
|
-
<Actions>
|
|
164
|
-
<Button
|
|
165
|
-
type="button"
|
|
166
|
-
subtype="secondary"
|
|
167
|
-
text={ <><AiOutlineCaretLeft /> { t('routes_order.step5.back') }</> }
|
|
168
|
-
noMargin
|
|
169
|
-
onClick={ () => onBack(4) }
|
|
170
|
-
/>
|
|
171
|
-
|
|
172
|
-
<Button
|
|
173
|
-
loading={isPending}
|
|
174
|
-
noMargin
|
|
175
|
-
text={ (
|
|
176
|
-
<><MdDone />{ t('routes_order.step5.next') }</>
|
|
177
|
-
) }
|
|
178
|
-
onClick={ onSendForm }
|
|
179
|
-
/>
|
|
180
|
-
</Actions>
|
|
181
|
-
</>
|
|
182
|
-
);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
export default Step5;
|