@vtex/faststore-plugin-buyer-portal 1.3.25 → 1.3.26
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 +8 -1
- package/package.json +1 -1
- package/src/features/addresses/clients/DefaultValuesClient.ts +31 -1
- package/src/features/addresses/components/CreateAddressSettingsDrawer/CreateAddressSettingsDrawer.tsx +39 -5
- package/src/features/addresses/hooks/index.ts +3 -0
- package/src/features/addresses/hooks/useGetDefaultAddresses.ts +34 -0
- package/src/features/addresses/services/default-values/get-default-address.service.ts +58 -0
- package/src/features/addresses/services/index.ts +4 -0
- package/src/features/addresses/types/AddressData.ts +14 -0
- package/src/features/addresses/types/index.ts +1 -0
- package/src/features/shared/utils/constants.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.3.26] - 2025-11-25
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Pre-populate default addresses in Address Settings drawer
|
|
15
|
+
|
|
10
16
|
## [1.3.25] - 2025-11-25
|
|
11
17
|
|
|
12
18
|
### Added
|
|
@@ -256,7 +262,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
256
262
|
- Add CHANGELOG file
|
|
257
263
|
- Add README file
|
|
258
264
|
|
|
259
|
-
[unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.
|
|
265
|
+
[unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.26...HEAD
|
|
260
266
|
[1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.2.2...1.2.3
|
|
261
267
|
[1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.3
|
|
262
268
|
[1.2.4]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.4
|
|
@@ -271,6 +277,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
271
277
|
|
|
272
278
|
# <<<<<<< HEAD
|
|
273
279
|
|
|
280
|
+
[1.3.26]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.25...v1.3.26
|
|
274
281
|
[1.3.25]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.24...v1.3.25
|
|
275
282
|
[1.3.24]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.23...v1.3.24
|
|
276
283
|
[1.3.23]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.22...v1.3.23
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Client } from "../../shared/clients/Client";
|
|
2
2
|
import { getApiUrl } from "../../shared/utils";
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
DefaultAddressParams,
|
|
6
|
+
DefaultAddressResponse,
|
|
7
|
+
} from "../types/AddressData";
|
|
5
8
|
|
|
6
9
|
export default class DefaultValuesClient extends Client {
|
|
7
10
|
constructor() {
|
|
@@ -42,6 +45,33 @@ export default class DefaultValuesClient extends Client {
|
|
|
42
45
|
}
|
|
43
46
|
);
|
|
44
47
|
}
|
|
48
|
+
|
|
49
|
+
getDefaultAddress({
|
|
50
|
+
customerId,
|
|
51
|
+
orgUnitId,
|
|
52
|
+
addressType,
|
|
53
|
+
cookie,
|
|
54
|
+
}: {
|
|
55
|
+
customerId: string;
|
|
56
|
+
orgUnitId: string;
|
|
57
|
+
addressType: "shipping" | "billing";
|
|
58
|
+
cookie: string;
|
|
59
|
+
}) {
|
|
60
|
+
const entity =
|
|
61
|
+
addressType === "shipping" ? "address/shipping" : "address/billing";
|
|
62
|
+
|
|
63
|
+
return this.get<DefaultAddressResponse>(
|
|
64
|
+
`/customers/${customerId}/units/${orgUnitId}/default-values`,
|
|
65
|
+
{
|
|
66
|
+
headers: {
|
|
67
|
+
Cookie: cookie,
|
|
68
|
+
},
|
|
69
|
+
params: {
|
|
70
|
+
entity,
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
45
75
|
}
|
|
46
76
|
|
|
47
77
|
const defaultValuesClient = new DefaultValuesClient();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
2
|
|
|
3
3
|
import { useRouter } from "next/router";
|
|
4
4
|
|
|
5
|
-
import { useUI } from "@faststore/ui";
|
|
5
|
+
import { useUI, Skeleton } from "@faststore/ui";
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
type BasicDrawerProps,
|
|
@@ -14,6 +14,7 @@ import { OptionSelected } from "../../../shared/components/OptionSelected/Option
|
|
|
14
14
|
import { SearchHighlight } from "../../../shared/components/SearchHighlight/SearchHighlight";
|
|
15
15
|
import { ADDRESS_MESSAGES } from "../../constants/messages";
|
|
16
16
|
import { useDebouncedSearchAddressByUnitId } from "../../hooks/useDebouncedSearchAddressByUnitId";
|
|
17
|
+
import { useGetDefaultAddress } from "../../hooks/useGetDefaultAddresses";
|
|
17
18
|
import { useSetDefaultAddress } from "../../hooks/useSetDefaultAddress";
|
|
18
19
|
import AddressDisplay from "../AddressInfoDisplay/AddressInfoDisplay";
|
|
19
20
|
|
|
@@ -33,7 +34,6 @@ export const CreateAddressSettingsDrawer = ({
|
|
|
33
34
|
...props
|
|
34
35
|
}: CreateAddressSettingsDrawerProps) => {
|
|
35
36
|
const { pushToast } = useUI();
|
|
36
|
-
|
|
37
37
|
const router = useRouter();
|
|
38
38
|
|
|
39
39
|
const [searchValue, setSearchValue] = useState("");
|
|
@@ -47,6 +47,36 @@ export const CreateAddressSettingsDrawer = ({
|
|
|
47
47
|
{} as AddressData
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
+
const {
|
|
51
|
+
defaultAddress: defaultShippingAddress,
|
|
52
|
+
isDefaultAddressLoading: isLoadingShipping,
|
|
53
|
+
} = useGetDefaultAddress({
|
|
54
|
+
customerId: router.query.contractId as string,
|
|
55
|
+
orgUnitId: router.query.orgUnitId as string,
|
|
56
|
+
addressType: "shipping",
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const {
|
|
60
|
+
defaultAddress: defaultBillingAddress,
|
|
61
|
+
isDefaultAddressLoading: isLoadingBilling,
|
|
62
|
+
} = useGetDefaultAddress({
|
|
63
|
+
customerId: router.query.contractId as string,
|
|
64
|
+
orgUnitId: router.query.orgUnitId as string,
|
|
65
|
+
addressType: "billing",
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (defaultShippingAddress && !shippingAddress?.id) {
|
|
70
|
+
setShippingAddress(defaultShippingAddress);
|
|
71
|
+
}
|
|
72
|
+
}, [defaultShippingAddress]);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (defaultBillingAddress && !billingAddress?.id) {
|
|
76
|
+
setBillingAddress(defaultBillingAddress);
|
|
77
|
+
}
|
|
78
|
+
}, [defaultBillingAddress]);
|
|
79
|
+
|
|
50
80
|
const { searchedAddresses } = useDebouncedSearchAddressByUnitId({
|
|
51
81
|
orgUnitId: router.query.orgUnitId as string,
|
|
52
82
|
search: searchValue,
|
|
@@ -118,7 +148,9 @@ export const CreateAddressSettingsDrawer = ({
|
|
|
118
148
|
Default shipping address (optional)
|
|
119
149
|
</p>
|
|
120
150
|
|
|
121
|
-
{
|
|
151
|
+
{isLoadingShipping ? (
|
|
152
|
+
<Skeleton size={{ height: "3.5rem", width: "100%" }} />
|
|
153
|
+
) : shippingAddress?.id ? (
|
|
122
154
|
<OptionSelected
|
|
123
155
|
label={shippingAddress.name}
|
|
124
156
|
triggerIcon={<Icon name="MinusCircle" />}
|
|
@@ -169,7 +201,9 @@ export const CreateAddressSettingsDrawer = ({
|
|
|
169
201
|
Default billing address (optional)
|
|
170
202
|
</p>
|
|
171
203
|
|
|
172
|
-
{
|
|
204
|
+
{isLoadingBilling ? (
|
|
205
|
+
<Skeleton size={{ height: "3.5rem", width: "100%" }} />
|
|
206
|
+
) : billingAddress?.id ? (
|
|
173
207
|
<OptionSelected
|
|
174
208
|
label={billingAddress.name}
|
|
175
209
|
triggerIcon={<Icon name="MinusCircle" />}
|
|
@@ -5,3 +5,6 @@ export * from "./useAddLocationsToAddress";
|
|
|
5
5
|
export * from "./useAddressLocationList";
|
|
6
6
|
export * from "./useAddressLocationEdit";
|
|
7
7
|
export * from "./useAddressLocationDelete";
|
|
8
|
+
export * from "./useSetDefaultAddress";
|
|
9
|
+
export * from "./useUnsetDefaultAddress";
|
|
10
|
+
export * from "./useGetDefaultAddresses";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type QueryOptions, useQuery } from "../../shared/hooks";
|
|
2
|
+
import { getDefaultAddressService } from "../services";
|
|
3
|
+
|
|
4
|
+
import type { AddressData } from "../types";
|
|
5
|
+
|
|
6
|
+
interface GetDefaultAddressParams {
|
|
7
|
+
customerId: string;
|
|
8
|
+
orgUnitId: string;
|
|
9
|
+
addressType: "shipping" | "billing";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const useGetDefaultAddress = (
|
|
13
|
+
{ customerId, orgUnitId, addressType }: GetDefaultAddressParams,
|
|
14
|
+
options?: QueryOptions<AddressData | null>
|
|
15
|
+
) => {
|
|
16
|
+
const { data, error, isLoading, refetch } = useQuery(
|
|
17
|
+
`defaultAddress/${customerId}/${orgUnitId}/${addressType}`,
|
|
18
|
+
({ cookie }) =>
|
|
19
|
+
getDefaultAddressService({
|
|
20
|
+
customerId,
|
|
21
|
+
orgUnitId,
|
|
22
|
+
addressType,
|
|
23
|
+
cookie,
|
|
24
|
+
}),
|
|
25
|
+
options
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
defaultAddress: data,
|
|
30
|
+
hasDefaultAddressError: error,
|
|
31
|
+
isDefaultAddressLoading: isLoading,
|
|
32
|
+
refetchDefaultAddress: refetch,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { defaultValuesClient } from "../../clients/DefaultValuesClient";
|
|
2
|
+
|
|
3
|
+
import type { AddressData, DefaultAddressResponse } from "../../types";
|
|
4
|
+
|
|
5
|
+
export interface GetDefaultAddressServiceProps {
|
|
6
|
+
customerId: string;
|
|
7
|
+
orgUnitId: string;
|
|
8
|
+
addressType: "shipping" | "billing";
|
|
9
|
+
cookie: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const mapDefaultAddressToAddressData = (
|
|
13
|
+
response: DefaultAddressResponse
|
|
14
|
+
): AddressData => {
|
|
15
|
+
return {
|
|
16
|
+
id: response.userId || "",
|
|
17
|
+
name: response.addressLabel,
|
|
18
|
+
types: [response.addressType],
|
|
19
|
+
isActive: response.isActive,
|
|
20
|
+
isDefault: true,
|
|
21
|
+
streetAddress: response.street,
|
|
22
|
+
streetAddress2: response.complement,
|
|
23
|
+
streetNumber: response.number,
|
|
24
|
+
number: response.number,
|
|
25
|
+
unit: "",
|
|
26
|
+
neighborhood: response.neighborhood,
|
|
27
|
+
city: response.city,
|
|
28
|
+
state: response.state,
|
|
29
|
+
zip: response.postalCode,
|
|
30
|
+
country: response.country,
|
|
31
|
+
geoCoordinates: response.geoCoordinate || "",
|
|
32
|
+
locations: [],
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export async function getDefaultAddressService({
|
|
37
|
+
customerId,
|
|
38
|
+
orgUnitId,
|
|
39
|
+
addressType,
|
|
40
|
+
cookie,
|
|
41
|
+
}: GetDefaultAddressServiceProps): Promise<AddressData | null> {
|
|
42
|
+
try {
|
|
43
|
+
const data = await defaultValuesClient.getDefaultAddress({
|
|
44
|
+
customerId,
|
|
45
|
+
orgUnitId,
|
|
46
|
+
addressType,
|
|
47
|
+
cookie,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (!data) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return mapDefaultAddressToAddressData(data);
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -31,3 +31,7 @@ export {
|
|
|
31
31
|
getAddressRecipientsService,
|
|
32
32
|
type GetAddressRecipientsServiceProps,
|
|
33
33
|
} from "./recipients/get-address-recipients.service";
|
|
34
|
+
export {
|
|
35
|
+
getDefaultAddressService,
|
|
36
|
+
type GetDefaultAddressServiceProps,
|
|
37
|
+
} from "./default-values/get-default-address.service";
|
|
@@ -171,3 +171,17 @@ export type EditDeleteLocationParams = {
|
|
|
171
171
|
location: LocationData;
|
|
172
172
|
unitId: string;
|
|
173
173
|
};
|
|
174
|
+
|
|
175
|
+
export type DefaultAddressResponse = Pick<
|
|
176
|
+
CheckoutAddress,
|
|
177
|
+
"postalCode" | "city" | "state" | "street" | "number" | "complement"
|
|
178
|
+
> &
|
|
179
|
+
Pick<PaymentAddress, "addressType" | "receiverName"> & {
|
|
180
|
+
addressName: string;
|
|
181
|
+
addressLabel: string;
|
|
182
|
+
neighborhood: string;
|
|
183
|
+
country: string;
|
|
184
|
+
geoCoordinate: string | null;
|
|
185
|
+
isActive: boolean;
|
|
186
|
+
userId?: string;
|
|
187
|
+
};
|