@vtex/faststore-plugin-buyer-portal 1.3.20 → 1.3.22
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 -2
- package/package.json +1 -1
- package/src/features/org-units/components/DeleteOrgUnitDrawer/DeleteOrgUnitDrawer.tsx +8 -4
- package/src/features/payment-methods/components/RemovePaymentMethodsDrawer/RemovePaymentMethodsDrawer.tsx +1 -22
- package/src/features/payment-methods/layouts/PaymentMethodsLayout/PaymentMethodsLayout.tsx +2 -8
- package/src/features/shared/utils/constants.ts +1 -1
- package/src/features/users/hooks/useGetUserByOrgUnitId.ts +20 -0
- package/src/features/payment-methods/hooks/useCookiePreferenceHideDrawer.ts +0 -34
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.22] - 2025-11-21
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add validation to prevent Org Unit deletion if it has users
|
|
15
|
+
|
|
16
|
+
## [1.3.21] - 2025-11-05
|
|
17
|
+
|
|
18
|
+
### Removed
|
|
19
|
+
|
|
20
|
+
- Remove cookie-based preference validation on Payment Methods remove Drawer.
|
|
21
|
+
|
|
10
22
|
## [1.3.20] - 2025-11-05
|
|
11
23
|
|
|
12
24
|
### Added
|
|
@@ -132,8 +144,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
132
144
|
## [1.2.4] - 2025-10-16
|
|
133
145
|
|
|
134
146
|
### Added
|
|
135
|
-
- Responsiviness adjustment to to Buying policies page
|
|
136
147
|
|
|
148
|
+
- Responsiviness adjustment to to Buying policies page
|
|
137
149
|
|
|
138
150
|
### Added
|
|
139
151
|
|
|
@@ -223,7 +235,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
223
235
|
- Add CHANGELOG file
|
|
224
236
|
- Add README file
|
|
225
237
|
|
|
226
|
-
[unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.
|
|
238
|
+
[unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.22...HEAD
|
|
227
239
|
[1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.2.2...1.2.3
|
|
228
240
|
[1.2.3]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.3
|
|
229
241
|
[1.2.4]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.2.4
|
|
@@ -238,6 +250,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
238
250
|
|
|
239
251
|
# <<<<<<< HEAD
|
|
240
252
|
|
|
253
|
+
[1.3.22]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.21...v1.3.22
|
|
254
|
+
[1.3.21]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.20...v1.3.21
|
|
241
255
|
[1.3.20]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.19...v1.3.20
|
|
242
256
|
[1.3.19]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.18...v1.3.19
|
|
243
257
|
[1.3.18]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.17...v1.3.18
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
InputText,
|
|
12
12
|
type BasicDrawerProps,
|
|
13
13
|
} from "../../../shared/components";
|
|
14
|
+
import { useGetUserByOrgUnitId } from "../../../users/hooks/useGetUserByOrgUnitId";
|
|
14
15
|
import { useChildrenOrgUnits } from "../../hooks";
|
|
15
16
|
import { useDeleteOrgUnit } from "../../hooks/useDeleteOrgUnit";
|
|
16
17
|
|
|
@@ -28,12 +29,14 @@ export const DeleteOrgUnitDrawer = ({
|
|
|
28
29
|
}: DeleteOrgUnitDrawerProps) => {
|
|
29
30
|
const router = useRouter();
|
|
30
31
|
const { childrenOrgUnits } = useChildrenOrgUnits(id, name);
|
|
32
|
+
const { users } = useGetUserByOrgUnitId(id);
|
|
31
33
|
const { pushToast } = useUI();
|
|
32
34
|
|
|
33
35
|
const [confirmName, setConfirmName] = useState("");
|
|
34
36
|
const [isTouched, setIsTouched] = useState(false);
|
|
35
37
|
|
|
36
|
-
const hasChildren =
|
|
38
|
+
const hasChildren =
|
|
39
|
+
Boolean(childrenOrgUnits?.nodes?.length) || Boolean(users?.length);
|
|
37
40
|
|
|
38
41
|
const handleDeleteOrgUnitSuccess = () => {
|
|
39
42
|
pushToast({
|
|
@@ -111,13 +114,14 @@ export const DeleteOrgUnitDrawer = ({
|
|
|
111
114
|
<span data-fs-bp-delete-org-unit-drawer-message-name>
|
|
112
115
|
{` ${name} `}
|
|
113
116
|
</span>
|
|
114
|
-
, you must first remove all child organizational units
|
|
117
|
+
, you must first remove all child organizational units{" "}
|
|
118
|
+
{users?.length ? "and users" : ""}.
|
|
115
119
|
<br />
|
|
116
120
|
Please delete them individually, starting from the lowest level.
|
|
117
121
|
<br />
|
|
118
122
|
<br />
|
|
119
|
-
Once all child units
|
|
120
|
-
{name}.
|
|
123
|
+
Once all child units {users?.length ? "and users" : ""} bellow are
|
|
124
|
+
removed, you’ll be able to delete {name}.
|
|
121
125
|
</p>
|
|
122
126
|
|
|
123
127
|
<span data-fs-bp-delete-org-unit-drawer-subtitle>
|
|
@@ -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
|
|
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 {
|
|
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
|
-
|
|
102
|
-
remove(method);
|
|
103
|
-
} else {
|
|
104
|
-
openRemoveDrawer();
|
|
105
|
-
}
|
|
99
|
+
openRemoveDrawer();
|
|
106
100
|
};
|
|
107
101
|
|
|
108
102
|
const columns = getTableColumns({ actionsLength: 1 });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type QueryOptions, useQuery } from "../../shared/hooks";
|
|
2
|
+
import { getUsersByOrgUnitIdService } from "../services";
|
|
3
|
+
|
|
4
|
+
export const useGetUserByOrgUnitId = (
|
|
5
|
+
orgUnitId: string,
|
|
6
|
+
options?: QueryOptions<AwaitedType<typeof getUsersByOrgUnitIdService>>
|
|
7
|
+
) => {
|
|
8
|
+
const { data, error, isLoading, refetch } = useQuery(
|
|
9
|
+
`org-unit/user/${orgUnitId}`,
|
|
10
|
+
({ cookie }) => getUsersByOrgUnitIdService({ orgUnitId, cookie }),
|
|
11
|
+
options
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
users: data?.users,
|
|
16
|
+
hasUserError: error,
|
|
17
|
+
isUserLoading: isLoading,
|
|
18
|
+
refetchUser: refetch,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -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
|
-
}
|