@vtex/faststore-plugin-buyer-portal 1.3.18 → 1.3.20
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 +15 -1
- package/package.json +1 -1
- package/public/buyer-portal-icons.svg +16 -0
- package/src/features/addresses/components/AddRecipientsDrawer/AddRecipientsDrawer.tsx +32 -11
- package/src/features/addresses/components/AddressDropdownMenu/AddressDropdownMenu.tsx +10 -1
- package/src/features/addresses/components/LocationsDrawer/LocationsDrawer.tsx +24 -1
- package/src/features/addresses/layouts/AddressDetailsLayout/AddressDetailsLayout.tsx +50 -3
- package/src/features/addresses/layouts/AddressesLayout/AddressesLayout.tsx +19 -3
- package/src/features/shared/components/OrgUnitInputSearch/OrgUnitInputSearch.tsx +17 -13
- package/src/features/shared/utils/constants.ts +1 -1
- package/src/features/users/hooks/useDebouncedSearchOrgUnit.ts +7 -11
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.20] - 2025-11-05
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Improves Navigation and User Experience Improvements on Address Management
|
|
15
|
+
|
|
16
|
+
## [1.3.19] - 2025-11-05
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- Add isLoading state to orgUnit search input
|
|
21
|
+
|
|
10
22
|
## [1.3.18] - 2025-11-05
|
|
11
23
|
|
|
12
24
|
### Added
|
|
@@ -211,7 +223,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
211
223
|
- Add CHANGELOG file
|
|
212
224
|
- Add README file
|
|
213
225
|
|
|
214
|
-
[unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.
|
|
226
|
+
[unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.20...HEAD
|
|
215
227
|
[1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.2.2...1.2.3
|
|
216
228
|
[1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.3
|
|
217
229
|
[1.2.4]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.4
|
|
@@ -226,6 +238,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
226
238
|
|
|
227
239
|
# <<<<<<< HEAD
|
|
228
240
|
|
|
241
|
+
[1.3.20]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.19...v1.3.20
|
|
242
|
+
[1.3.19]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.18...v1.3.19
|
|
229
243
|
[1.3.18]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.17...v1.3.18
|
|
230
244
|
[1.3.17]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.16...v1.3.17
|
|
231
245
|
[1.3.16]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.15...v1.3.16
|
package/package.json
CHANGED
|
@@ -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
|
|
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:
|
|
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
|
-
|
|
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(
|
|
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={
|
|
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
|
|
199
|
-
|
|
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>
|
|
@@ -4,6 +4,11 @@ import { AutocompleteDropdown } from "..";
|
|
|
4
4
|
import { useDebouncedSearchOrgUnit } from "../../../users/hooks";
|
|
5
5
|
import { OptionSelected } from "../OptionSelected/OptionSelected";
|
|
6
6
|
|
|
7
|
+
type Option = {
|
|
8
|
+
name: string;
|
|
9
|
+
id: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
7
12
|
export type OrgUnitInputSearchProps = Omit<
|
|
8
13
|
ComponentProps<typeof AutocompleteDropdown>,
|
|
9
14
|
"onSelect" | "label" | "onConfirmKeyPress"
|
|
@@ -25,9 +30,15 @@ export const OrgUnitInputSearch = ({
|
|
|
25
30
|
}: OrgUnitInputSearchProps) => {
|
|
26
31
|
const [autocompleteInputValue, setAutocompleteInputValue] = useState("");
|
|
27
32
|
|
|
28
|
-
const { searchedOrgUnits } =
|
|
29
|
-
autocompleteInputValue
|
|
30
|
-
|
|
33
|
+
const { searchedOrgUnits, isSearchedOrgUnitsLoading } =
|
|
34
|
+
useDebouncedSearchOrgUnit(autocompleteInputValue);
|
|
35
|
+
|
|
36
|
+
const loadingObject: Option = { id: "loading", name: "loading..." };
|
|
37
|
+
|
|
38
|
+
const handleSelect = (option: Option) => {
|
|
39
|
+
if (option.id === loadingObject.id) return;
|
|
40
|
+
onSelect?.(option);
|
|
41
|
+
};
|
|
31
42
|
|
|
32
43
|
return orgUnit.name ? (
|
|
33
44
|
<OptionSelected
|
|
@@ -47,15 +58,8 @@ export const OrgUnitInputSearch = ({
|
|
|
47
58
|
{...otherProps}
|
|
48
59
|
label="Search organizational units"
|
|
49
60
|
value={autocompleteInputValue}
|
|
50
|
-
options={searchedOrgUnits}
|
|
51
|
-
onConfirmKeyPress={
|
|
52
|
-
onSelect?.(
|
|
53
|
-
option as {
|
|
54
|
-
name: string;
|
|
55
|
-
id: string;
|
|
56
|
-
}
|
|
57
|
-
)
|
|
58
|
-
}
|
|
61
|
+
options={isSearchedOrgUnitsLoading ? [loadingObject] : searchedOrgUnits}
|
|
62
|
+
onConfirmKeyPress={handleSelect}
|
|
59
63
|
onChange={(event) => {
|
|
60
64
|
setAutocompleteInputValue(event.currentTarget.value);
|
|
61
65
|
}}
|
|
@@ -65,7 +69,7 @@ export const OrgUnitInputSearch = ({
|
|
|
65
69
|
closeOnClick
|
|
66
70
|
index={index}
|
|
67
71
|
isSelected={orgUnit?.id === option?.id}
|
|
68
|
-
onClick={() =>
|
|
72
|
+
onClick={() => handleSelect(option)}
|
|
69
73
|
>
|
|
70
74
|
{option?.name}
|
|
71
75
|
</AutocompleteDropdown.Item>
|
|
@@ -7,18 +7,14 @@ export const useDebouncedSearchOrgUnit = (searchTerm = "") => {
|
|
|
7
7
|
const { searchedOrgUnits, isSearchedOrgUnitsLoading } =
|
|
8
8
|
useSearchOrgUnits(debouncedSearchTerm);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
name: string;
|
|
14
|
-
id: string;
|
|
15
|
-
}[],
|
|
16
|
-
isLoading: false,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
10
|
+
const isDebouncing = searchTerm !== debouncedSearchTerm;
|
|
11
|
+
const isLoading =
|
|
12
|
+
searchTerm !== "" && (isDebouncing || isSearchedOrgUnitsLoading);
|
|
19
13
|
|
|
20
14
|
return {
|
|
21
|
-
searchedOrgUnits:
|
|
22
|
-
|
|
15
|
+
searchedOrgUnits: searchTerm
|
|
16
|
+
? searchedOrgUnits?.organizationalUnits ?? []
|
|
17
|
+
: [],
|
|
18
|
+
isSearchedOrgUnitsLoading: isLoading,
|
|
23
19
|
};
|
|
24
20
|
};
|