@vtex/faststore-plugin-buyer-portal 1.3.25 → 1.3.27
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 +16 -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/buying-policies/components/BasicBuyingPolicyDrawer/basic-buying-policy-drawer.scss +25 -18
- package/src/features/shared/utils/constants.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.3.27] - 2025-11-25
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Style improvements and consistency updates to the `basic-buying-policy-drawer.scss` file.
|
|
16
|
+
|
|
17
|
+
## [1.3.26] - 2025-11-25
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- Pre-populate default addresses in Address Settings drawer
|
|
22
|
+
|
|
10
23
|
## [1.3.25] - 2025-11-25
|
|
11
24
|
|
|
12
25
|
### Added
|
|
@@ -256,7 +269,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
256
269
|
- Add CHANGELOG file
|
|
257
270
|
- Add README file
|
|
258
271
|
|
|
259
|
-
[unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.
|
|
272
|
+
[unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.27...HEAD
|
|
260
273
|
[1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.2.2...1.2.3
|
|
261
274
|
[1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.3
|
|
262
275
|
[1.2.4]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.4
|
|
@@ -271,6 +284,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
271
284
|
|
|
272
285
|
# <<<<<<< HEAD
|
|
273
286
|
|
|
287
|
+
[1.3.27]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.26...v1.3.27
|
|
288
|
+
[1.3.26]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.25...v1.3.26
|
|
274
289
|
[1.3.25]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.24...v1.3.25
|
|
275
290
|
[1.3.24]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.23...v1.3.24
|
|
276
291
|
[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
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
@import
|
|
2
|
-
@import
|
|
3
|
-
@import
|
|
4
|
-
@import
|
|
1
|
+
@import '../../../shared/components/BasicDrawer/basic-drawer.scss';
|
|
2
|
+
@import '../../../shared/components/OrgUnitInputSearch/org-unit-input-search.scss';
|
|
3
|
+
@import '../../../shared/components/CustomDropdown/custom-dropdown.scss';
|
|
4
|
+
@import '../BudgetCriteriaSelector/budget-criteria-selector.scss';
|
|
5
5
|
|
|
6
6
|
[data-fs-bp-basic-buying-policy-drawer] {
|
|
7
|
-
@import
|
|
8
|
-
@import
|
|
9
|
-
@import
|
|
10
|
-
@import
|
|
11
|
-
@import
|
|
7
|
+
@import '../../../shared/components/InputText/input-text.scss';
|
|
8
|
+
@import '../../../shared/components/ErrorMessage/error-message.scss';
|
|
9
|
+
@import '../../../shared/components/LevelDivider/level-divider.scss';
|
|
10
|
+
@import '@faststore/ui/src/components/molecules/Tooltip/styles.scss';
|
|
11
|
+
@import '@faststore/ui/src/components/molecules/Dropdown/styles.scss';
|
|
12
12
|
|
|
13
13
|
[data-fs-bp-autocomplete-dropdown] {
|
|
14
14
|
[data-fs-bp-input-text-input] {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
gap: var(--fs-spacing-2);
|
|
66
66
|
margin-top: calc(var(--fs-spacing-0) + var(--fs-spacing-3));
|
|
67
67
|
|
|
68
|
-
@include media(
|
|
68
|
+
@include media('<=tablet') {
|
|
69
69
|
justify-content: center;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -94,15 +94,16 @@
|
|
|
94
94
|
height: 100%;
|
|
95
95
|
margin: 0;
|
|
96
96
|
background-color: #f5f5f5;
|
|
97
|
-
font-family:
|
|
97
|
+
font-family: 'Roboto', monospace;
|
|
98
98
|
font-size: var(--fs-text-size-1);
|
|
99
99
|
border: var(--fs-border-width) solid #d6d6d6;
|
|
100
|
-
padding: calc(var(--fs-spacing-3) + var(--fs-spacing-0))
|
|
101
|
-
var(--fs-spacing-3);
|
|
100
|
+
padding: calc(var(--fs-spacing-3) + var(--fs-spacing-0)) var(--fs-spacing-3);
|
|
102
101
|
border-radius: calc(var(--fs-border-radius) * 2);
|
|
103
102
|
text-wrap: nowrap;
|
|
104
103
|
text-overflow: ellipsis;
|
|
105
104
|
white-space: nowrap;
|
|
105
|
+
overflow: hidden;
|
|
106
|
+
max-width: 840px;
|
|
106
107
|
cursor: pointer;
|
|
107
108
|
|
|
108
109
|
[data-fs-bp-label] {
|
|
@@ -119,18 +120,17 @@
|
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
|
|
123
123
|
[data-fs-bp-input-text-criteria] {
|
|
124
124
|
color: #5c5c5c;
|
|
125
125
|
|
|
126
126
|
label {
|
|
127
|
-
font-family:
|
|
127
|
+
font-family: 'Roboto', monospace;
|
|
128
128
|
font-size: var(--fs-text-size-1);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
&[data-fs-bp-input-text-code] {
|
|
132
132
|
background-color: #f5f5f5;
|
|
133
|
-
font-family:
|
|
133
|
+
font-family: 'Roboto', monospace;
|
|
134
134
|
font-size: var(--fs-text-size-1);
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -142,8 +142,7 @@
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
[data-fs-bp-buying-policy-add-level-button] {
|
|
145
|
-
padding: var(--fs-spacing-2)
|
|
146
|
-
calc(var(--fs-spacing-0) + var(--fs-spacing-3));
|
|
145
|
+
padding: var(--fs-spacing-2) calc(var(--fs-spacing-0) + var(--fs-spacing-3));
|
|
147
146
|
margin: calc(var(--fs-spacing-0) + var(--fs-spacing-3)) 0;
|
|
148
147
|
border-radius: var(--fs-border-radius-pill);
|
|
149
148
|
border: var(--fs-border-width) solid #d6d6d6;
|
|
@@ -160,4 +159,12 @@
|
|
|
160
159
|
[data-fs-bp-basic-buying-policy-drawer-skeleton] {
|
|
161
160
|
margin-bottom: var(--fs-spacing-3);
|
|
162
161
|
}
|
|
162
|
+
|
|
163
|
+
@include media('<=tablet') {
|
|
164
|
+
[data-fs-bp-basic-drawer-body],
|
|
165
|
+
[data-fs-bp-basic-drawer-heading],
|
|
166
|
+
[data-fs-bp-basic-drawer-footer] {
|
|
167
|
+
max-width: 430px;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
163
170
|
}
|