@vtex/faststore-plugin-buyer-portal 1.3.19 → 1.3.21

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 CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.3.21] - 2025-11-05
11
+
12
+ ### Removed
13
+
14
+ - Remove cookie-based preference validation on Payment Methods remove Drawer.
15
+
16
+ ## [1.3.20] - 2025-11-05
17
+
18
+ ### Added
19
+
20
+ - Improves Navigation and User Experience Improvements on Address Management
21
+
10
22
  ## [1.3.19] - 2025-11-05
11
23
 
12
24
  ### Added
@@ -217,7 +229,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
217
229
  - Add CHANGELOG file
218
230
  - Add README file
219
231
 
220
- [unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.19...HEAD
232
+ [unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.21...HEAD
221
233
  [1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.2.2...1.2.3
222
234
  [1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.3
223
235
  [1.2.4]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.4
@@ -232,6 +244,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
232
244
 
233
245
  # <<<<<<< HEAD
234
246
 
247
+ [1.3.21]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.20...v1.3.21
248
+ [1.3.20]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.19...v1.3.20
235
249
  [1.3.19]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.18...v1.3.19
236
250
  [1.3.18]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.17...v1.3.18
237
251
  [1.3.17]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.16...v1.3.17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "1.3.19",
3
+ "version": "1.3.21",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -543,5 +543,21 @@
543
543
  d="M140,180a12,12,0,1,1-12-12A12,12,0,0,1,140,180ZM128,72c-22.06,0-40,16.15-40,36v4a8,8,0,0,0,16,0v-4c0-11,10.77-20,24-20s24,9,24,20-10.77,20-24,20a8,8,0,0,0-8,8v8a8,8,0,0,0,16,0v-.72c18.24-3.35,32-17.9,32-35.28C168,88.15,150.06,72,128,72Zm104,56A104,104,0,1,1,128,24,104.11,104.11,0,0,1,232,128Zm-16,0a88,88,0,1,0-88,88A88.1,88.1,0,0,0,216,128Z"
544
544
  fill="currentColor"/>
545
545
  </symbol>
546
+
547
+ <symbol id="OpenNewTab" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
548
+ <g clip-path="url(#clip0_401_516)">
549
+ <mask id="mask0_401_516" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="20" height="20">
550
+ <rect width="20" height="20" fill="#D9D9D9"/>
551
+ </mask>
552
+ <g mask="url(#mask0_401_516)">
553
+ <path d="M4.16667 17.5C3.70833 17.5 3.31597 17.3368 2.98958 17.0104C2.66319 16.684 2.5 16.2917 2.5 15.8333V4.16667C2.5 3.70833 2.66319 3.31597 2.98958 2.98958C3.31597 2.66319 3.70833 2.5 4.16667 2.5H10V4.16667H4.16667V15.8333H15.8333V10H17.5V15.8333C17.5 16.2917 17.3368 16.684 17.0104 17.0104C16.684 17.3368 16.2917 17.5 15.8333 17.5H4.16667ZM8.08333 13.0833L6.91667 11.9167L14.6667 4.16667H11.6667V2.5H17.5V8.33333H15.8333V5.33333L8.08333 13.0833Z" fill="#1F1F1F"/>
554
+ </g>
555
+ </g>
556
+ <defs>
557
+ <clipPath id="clip0_401_516">
558
+ <rect width="20" height="20" fill="white"/>
559
+ </clipPath>
560
+ </defs>
561
+ </symbol>
546
562
  </svg>
547
563
 
@@ -7,6 +7,7 @@ import { useUI } from "@faststore/ui";
7
7
  import { RecipientsForm } from "..";
8
8
  import { type BasicDrawerProps, BasicDrawer } from "../../../shared/components";
9
9
  import { useBuyerPortal } from "../../../shared/hooks";
10
+ import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
10
11
  import { useAddRecipientsToAddress } from "../../hooks/useAddRecipientsToAddress";
11
12
 
12
13
  import type { RecipientInput } from "../../types";
@@ -14,7 +15,7 @@ import type { RecipientInput } from "../../types";
14
15
  export type AddRecipientsDrawerProps = Omit<BasicDrawerProps, "children"> & {
15
16
  readonly?: boolean;
16
17
  addressId?: string;
17
- refetchRecipients: () => void;
18
+ refetchRecipients?: () => void;
18
19
  };
19
20
 
20
21
  export const AddRecipientsDrawer = ({
@@ -30,18 +31,38 @@ export const AddRecipientsDrawer = ({
30
31
  const { pushToast } = useUI();
31
32
  const { currentOrgUnit } = useBuyerPortal();
32
33
 
33
- const handleAddRecipientToAddressSuccess = () => {
34
- pushToast({
35
- message: "Recipients added successfully ",
36
- status: "INFO",
37
- });
38
- refetchRecipients();
39
- close();
40
- };
41
-
42
34
  const { addRecipientsToAddress, isAddRecipientToAddressLoading } =
43
35
  useAddRecipientsToAddress({
44
- onSuccess: handleAddRecipientToAddressSuccess,
36
+ onSuccess: () => {
37
+ const hasTabParam = router.query?.tab === "recipient-tab";
38
+
39
+ pushToast({
40
+ message: "Recipients added successfully ",
41
+ status: "INFO",
42
+ icon: (
43
+ <button
44
+ data-fs-bp-toast-view-button
45
+ type="button"
46
+ onClick={() => {
47
+ const url = buyerPortalRoutes.addressDetails({
48
+ orgUnitId: currentOrgUnit?.id ?? "",
49
+ contractId: router.query.contractId as string,
50
+ addressId: addressId ?? (router.query.addressId as string),
51
+ });
52
+
53
+ router.push(`${url}?tab=recipient-tab`);
54
+ }}
55
+ >
56
+ View
57
+ </button>
58
+ ),
59
+ });
60
+
61
+ close();
62
+ if (hasTabParam) {
63
+ refetchRecipients?.();
64
+ }
65
+ },
45
66
  onError: () => {
46
67
  pushToast({
47
68
  message: "An error occurred while adding recipients",
@@ -20,6 +20,7 @@ import type { AddressData } from "../../types";
20
20
  export type AddressDropdownMenuProps = {
21
21
  currentAddress: AddressData;
22
22
  onUpdate?: () => void;
23
+ onOpen?: () => void;
23
24
  onCreate?: () => void;
24
25
  isComplete?: boolean;
25
26
  };
@@ -27,6 +28,7 @@ export type AddressDropdownMenuProps = {
27
28
  export const AddressDropdownMenu = ({
28
29
  currentAddress,
29
30
  onUpdate,
31
+ onOpen,
30
32
  }: AddressDropdownMenuProps) => {
31
33
  const router = useRouter();
32
34
  const { pushToast } = useUI();
@@ -106,6 +108,10 @@ export const AddressDropdownMenu = ({
106
108
  });
107
109
  };
108
110
 
111
+ const handleOpenNewTab = () => {
112
+ onOpen?.();
113
+ };
114
+
109
115
  // const idsPath = currentOrgUnit?.path?.ids?.split("/") ?? [];
110
116
  // const isRootLevelOrgUnit = idsPath.length === 2;
111
117
 
@@ -144,6 +150,10 @@ export const AddressDropdownMenu = ({
144
150
  return (
145
151
  <>
146
152
  <BasicDropdownMenu data-fs-bp-dropdown-menu>
153
+ <DropdownItem onClick={handleOpenNewTab}>
154
+ <Icon name="OpenNewTab" {...sizeProps} />
155
+ Open
156
+ </DropdownItem>
147
157
  <DropdownItem onClick={openEditDrawerProps}>
148
158
  <Icon name="Edit" {...sizeProps} />
149
159
  Edit details
@@ -198,7 +208,6 @@ export const AddressDropdownMenu = ({
198
208
  {...locationDrawerProps}
199
209
  isOpen={isOpenLocationDrawer}
200
210
  addressId={currentAddress.id}
201
- onAddLocationSuccess={() => router.reload()}
202
211
  />
203
212
  )}
204
213
  {isOpenRecipientsDrawer && (
@@ -7,6 +7,7 @@ import { useUI } from "@faststore/ui";
7
7
  import { LocationForm } from "../";
8
8
  import { type BasicDrawerProps, BasicDrawer } from "../../../shared/components";
9
9
  import { useBuyerPortal } from "../../../shared/hooks";
10
+ import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
10
11
  import { useAddLocationsToAddress } from "../../hooks";
11
12
 
12
13
  import type { LocationInput } from "../../types/AddressData";
@@ -32,12 +33,34 @@ export const LocationDrawer = ({
32
33
 
33
34
  const { addLocationsMutate, addLocationsLoading } = useAddLocationsToAddress({
34
35
  onSuccess: () => {
36
+ const hasTabParam = router.query?.tab === "location-tab";
37
+
35
38
  pushToast({
36
39
  message: "Locations added successfully ",
37
40
  status: "INFO",
41
+ icon: (
42
+ <button
43
+ data-fs-bp-toast-view-button
44
+ type="button"
45
+ onClick={() => {
46
+ const url = buyerPortalRoutes.addressDetails({
47
+ orgUnitId: currentOrgUnit?.id ?? "",
48
+ contractId: router.query.contractId as string,
49
+ addressId: addressId ?? (router.query.addressId as string),
50
+ });
51
+
52
+ router.push(`${url}?tab=location-tab`);
53
+ }}
54
+ >
55
+ View
56
+ </button>
57
+ ),
38
58
  });
39
- onAddLocationSuccess?.();
59
+
40
60
  clearAndClose();
61
+ if (hasTabParam) {
62
+ onAddLocationSuccess?.();
63
+ }
41
64
  },
42
65
  onError: () => {
43
66
  pushToast({
@@ -1,4 +1,6 @@
1
- import { useRef, useState } from "react";
1
+ import { useEffect, useRef, useState } from "react";
2
+
3
+ import { useRouter } from "next/router";
2
4
 
3
5
  import { Dropdown } from "@faststore/ui";
4
6
 
@@ -38,11 +40,15 @@ export type AddressDetailsLayoutProps = {
38
40
  locationsData: LocationsPageData;
39
41
  };
40
42
 
43
+ type AddressDetailTabId = "address-tab" | "location-tab" | "recipient-tab";
44
+
41
45
  export const AddressDetailsLayout = ({
42
46
  addressDetails: data,
43
47
  recipientsData,
44
48
  locationsData,
45
49
  }: AddressDetailsLayoutProps) => {
50
+ const router = useRouter();
51
+
46
52
  // TODO: Implement the AddressDetailsLayout Fallback component
47
53
  if (!data) {
48
54
  return null;
@@ -56,11 +62,33 @@ export const AddressDetailsLayout = ({
56
62
 
57
63
  const { ...addressData } = data;
58
64
 
59
- const [activeTabId, setActiveTabId] = useState("address-tab");
65
+ const [activeTabId, setActiveTabId] = useState<AddressDetailTabId>(() => {
66
+ const tabFromQuery = router.query.tab as AddressDetailTabId;
67
+ const validTabs: AddressDetailTabId[] = [
68
+ "address-tab",
69
+ "location-tab",
70
+ "recipient-tab",
71
+ ];
72
+
73
+ return validTabs.includes(tabFromQuery) ? tabFromQuery : "address-tab";
74
+ });
60
75
  const { open: openEditDrawer, ...createDrawerProps } = useDrawerProps();
61
76
  const addressRecipientsListRef = useRef<AddressRecipientsListRef>(null);
62
77
  const addressLocationsListRef = useRef<AddressLocationsListRef>(null);
63
78
 
79
+ useEffect(() => {
80
+ const tabFromQuery = router.query.tab as AddressDetailTabId;
81
+ const validTabs: AddressDetailTabId[] = [
82
+ "address-tab",
83
+ "location-tab",
84
+ "recipient-tab",
85
+ ];
86
+
87
+ if (validTabs.includes(tabFromQuery) && tabFromQuery !== activeTabId) {
88
+ setActiveTabId(tabFromQuery);
89
+ }
90
+ }, [router.query.tab, activeTabId]);
91
+
64
92
  const {
65
93
  open: openLocationsDrawer,
66
94
  isOpen: isOpenLocationsDrawer,
@@ -77,6 +105,25 @@ export const AddressDetailsLayout = ({
77
105
  keyof typeof addressLabelToPropMapping
78
106
  >;
79
107
 
108
+ const handleTabChange = (id: string) => {
109
+ const newTabId = id as AddressDetailTabId;
110
+
111
+ // Update the URL query parameter without reloading the page
112
+ router.push(
113
+ {
114
+ pathname: router.pathname,
115
+ query: {
116
+ ...router.query,
117
+ tab: newTabId,
118
+ },
119
+ },
120
+ undefined,
121
+ { shallow: true }
122
+ );
123
+
124
+ setActiveTabId(newTabId);
125
+ };
126
+
80
127
  const handleRefetchRecipients = () => {
81
128
  addressRecipientsListRef.current?.refetchRecipients();
82
129
  };
@@ -140,7 +187,7 @@ export const AddressDetailsLayout = ({
140
187
  </Dropdown>
141
188
  </HeaderInside>
142
189
  <div data-fs-address-details-info-wrapper>
143
- <Tab defaultTabId={activeTabId} onChange={setActiveTabId}>
190
+ <Tab defaultTabId={activeTabId} onChange={handleTabChange}>
144
191
  <div data-fs-address-details-actions>
145
192
  <TabBar>
146
193
  <TabOption id="address-tab">Details</TabOption>
@@ -59,6 +59,13 @@ export const AddressLayout = ({
59
59
  { lazy: true }
60
60
  );
61
61
 
62
+ useEffect(() => {
63
+ if (addresses.length === 0) {
64
+ setIsLoading(true);
65
+ refetchSearchedAddresses();
66
+ }
67
+ }, []);
68
+
62
69
  useEffect(() => {
63
70
  if (addressesData?.data) {
64
71
  updateItemsFromRefetch(addressesData.data);
@@ -186,6 +193,15 @@ export const AddressLayout = ({
186
193
  ...address,
187
194
  }}
188
195
  onUpdate={handleRefetchAddresses}
196
+ onOpen={() => {
197
+ const url = buyerPortalRoutes.addressDetails({
198
+ orgUnitId: orgUnit?.id ?? "",
199
+ contractId: contract?.id ?? "",
200
+ addressId: id,
201
+ });
202
+
203
+ router.push(url);
204
+ }}
189
205
  />
190
206
  }
191
207
  />
@@ -195,9 +211,9 @@ export const AddressLayout = ({
195
211
  </Table>
196
212
 
197
213
  {!isLoading && (
198
- <p data-fs-bp-addresses-paginator-last>
199
- {`${addresses.length} of ${total}`}
200
- </p>
214
+ <p
215
+ data-fs-bp-addresses-paginator-last
216
+ >{`${addresses.length} of ${total}`}</p>
201
217
  )}
202
218
 
203
219
  <div data-fs-bp-addresses-paginator>
@@ -1,10 +1,5 @@
1
- import { useState } from "react";
2
-
3
- import { CheckboxField } from "@faststore/ui";
4
-
5
1
  import { type BasicDrawerProps, BasicDrawer } from "../../../shared/components";
6
2
  import { useBuyerPortal } from "../../../shared/hooks";
7
- import { useCookiePreferenceHideDrawer } from "../../hooks/useCookiePreferenceHideDrawer";
8
3
  import { useRemovePaymentMethod } from "../../hooks/useRemovePaymentMethodSubmit";
9
4
 
10
5
  import type { PaymentMethodData } from "../../types";
@@ -24,17 +19,9 @@ export const RemovePaymentMethodsDrawer = ({
24
19
  ...props
25
20
  }: RemovePaymentMethodsDrawerProps) => {
26
21
  const { currentOrgUnit: orgUnit } = useBuyerPortal();
27
- const { hideMessage, isMessageHidden } = useCookiePreferenceHideDrawer();
28
-
29
- const [dontShowAgain, setDontShowAgain] = useState<boolean>(
30
- isMessageHidden || false
31
- );
32
22
 
33
23
  const handleSuccess = () => {
34
24
  close();
35
- if (dontShowAgain) {
36
- hideMessage();
37
- }
38
25
  };
39
26
 
40
27
  const { remove, isRemovingPaymentMethod } =
@@ -44,7 +31,7 @@ export const RemovePaymentMethodsDrawer = ({
44
31
  remove(paymentMethodId);
45
32
  };
46
33
 
47
- if (!paymentMethod || isMessageHidden) {
34
+ if (!paymentMethod) {
48
35
  return null;
49
36
  }
50
37
 
@@ -68,14 +55,6 @@ export const RemovePaymentMethodsDrawer = ({
68
55
  This action will prevent users in this unit from acessing this
69
56
  payment method during checkout.
70
57
  </p>
71
- <CheckboxField
72
- data-fs-checkbox-field-content
73
- data-fs-bp-payment-methods-checkbox
74
- label="Don't show this message again"
75
- id="prevent-message"
76
- checked={dontShowAgain}
77
- onChange={(e) => setDontShowAgain(e.target.checked)}
78
- />
79
58
  </section>
80
59
  </BasicDrawer.Body>
81
60
 
@@ -16,7 +16,6 @@ import {
16
16
  RemovePaymentMethodsDrawer,
17
17
  SearchPaymentMethods,
18
18
  } from "../../components";
19
- import { useCookiePreferenceHideDrawer } from "../../hooks/useCookiePreferenceHideDrawer";
20
19
  import { useDebouncedSearchPaymentMethods } from "../../hooks/useDebouncedSearchPaymentMethods";
21
20
  import { useRemovePaymentMethod } from "../../hooks/useRemovePaymentMethodSubmit";
22
21
 
@@ -39,8 +38,7 @@ export const PaymentMethodsLayout = ({
39
38
  const [querySearch, setQuerySearch] = useState(search ?? "");
40
39
 
41
40
  const { setQueryString, removeQueryString } = useQueryParams();
42
- const { isMessageHidden } = useCookiePreferenceHideDrawer();
43
- const { remove, isRemovingPaymentMethod } = useRemovePaymentMethod(() => {
41
+ const { isRemovingPaymentMethod } = useRemovePaymentMethod(() => {
44
42
  setSelectedMethod(undefined);
45
43
  });
46
44
 
@@ -98,11 +96,7 @@ export const PaymentMethodsLayout = ({
98
96
 
99
97
  const onRemoveClick = (method: PaymentMethodData) => {
100
98
  setSelectedMethod(method);
101
- if (isMessageHidden) {
102
- remove(method);
103
- } else {
104
- openRemoveDrawer();
105
- }
99
+ openRemoveDrawer();
106
100
  };
107
101
 
108
102
  const columns = getTableColumns({ actionsLength: 1 });
@@ -13,4 +13,4 @@ export const LOCAL_STORAGE_LOCATION_EDIT_KEY = "bp_hide_edit_location_confirm";
13
13
  export const LOCAL_STORAGE_RECIPIENT_EDIT_KEY =
14
14
  "bp_hide_edit_recipient_confirm";
15
15
 
16
- export const CURRENT_VERSION = "1.3.19";
16
+ export const CURRENT_VERSION = "1.3.21";
@@ -1,34 +0,0 @@
1
- import { useEffect, useState } from "react";
2
-
3
- const COOKIE_NAME = "hideMessage";
4
- const MAX_AGE = 60 * 60 * 24 * 365; // a year
5
-
6
- type UseCookiePreferenceHideDrawerResult = {
7
- isMessageHidden: boolean;
8
- hideMessage: () => void;
9
- };
10
-
11
- export function useCookiePreferenceHideDrawer(): UseCookiePreferenceHideDrawerResult {
12
- const [isMessageHidden, setIsMessageHidden] = useState(false);
13
-
14
- useEffect(() => {
15
- const cookie = document.cookie
16
- .split("; ")
17
- .find((row) => row.startsWith(`${COOKIE_NAME}=`));
18
-
19
- if (cookie) {
20
- const value = cookie.split("=")[1];
21
- setIsMessageHidden(value === "true");
22
- }
23
- }, []);
24
-
25
- const hideMessage = () => {
26
- document.cookie = `${COOKIE_NAME}=true; path=/; max-age=${MAX_AGE}`;
27
- setIsMessageHidden(true);
28
- };
29
-
30
- return {
31
- isMessageHidden,
32
- hideMessage,
33
- };
34
- }