@vtex/faststore-plugin-buyer-portal 1.1.3 → 1.1.5

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.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/plugin.config.js +5 -5
  3. package/public/buyer-portal-icons.svg +9 -1
  4. package/src/features/payment-methods/clients/PaymentMethodsClient.ts +87 -0
  5. package/src/features/payment-methods/components/AddPaymentMethodsDrawer/AddPaymentMethodsDrawer.tsx +178 -0
  6. package/src/features/payment-methods/components/AddPaymentMethodsDrawer/add-payment-methods-drawer.scss +44 -0
  7. package/src/features/payment-methods/components/RemoveMethodButton/RemoveMethodButton.tsx +45 -0
  8. package/src/features/payment-methods/components/RemoveMethodButton/remove-method-button.scss +42 -0
  9. package/src/features/payment-methods/components/RemovePaymentMethodsDrawer/RemovePaymentMethodsDrawer.tsx +81 -0
  10. package/src/features/payment-methods/components/RemovePaymentMethodsDrawer/remove-payment-methods-drawer.scss +40 -0
  11. package/src/features/payment-methods/components/SearchPaymentMethods/SearchPaymentMethods.tsx +40 -0
  12. package/src/features/payment-methods/components/SearchPaymentMethods/search-payment-methods.scss +15 -0
  13. package/src/features/payment-methods/components/index.ts +4 -0
  14. package/src/features/payment-methods/hooks/index.ts +3 -0
  15. package/src/features/payment-methods/hooks/useAddPaymentMethodsToUnit.ts +27 -0
  16. package/src/features/payment-methods/hooks/useCookiePreferenceHideDrawer.ts +33 -0
  17. package/src/features/payment-methods/hooks/useDebouncedSearchPaymentMethods.ts +21 -0
  18. package/src/features/payment-methods/hooks/useGetPaymentMethodsByUnitId.ts +30 -0
  19. package/src/features/payment-methods/hooks/useRemovePaymentMethodSubmit.ts +40 -0
  20. package/src/features/payment-methods/hooks/useRemovePaymentMethodsFromUnit.ts +27 -0
  21. package/src/features/payment-methods/layouts/PaymentMethodsLayout/PaymentMethodsLayout.tsx +187 -0
  22. package/src/features/payment-methods/layouts/PaymentMethodsLayout/payment-methods-layout.scss +105 -0
  23. package/src/features/payment-methods/layouts/index.ts +1 -0
  24. package/src/features/payment-methods/services/add-payment-methods-to-unit.service.ts +32 -0
  25. package/src/features/payment-methods/services/get-payment-methods-by-unit-id.service.ts +31 -0
  26. package/src/features/payment-methods/services/index.ts +12 -0
  27. package/src/features/payment-methods/services/remove-payment-methods-from-unit.service.ts +27 -0
  28. package/src/features/payment-methods/types/PaymentMethod.ts +5 -0
  29. package/src/features/payment-methods/types/index.ts +1 -0
  30. package/src/features/shared/components/ConditionalTooltip/ConditionalTooltip.tsx +21 -0
  31. package/src/features/shared/components/HeaderInside/header-inside.scss +6 -0
  32. package/src/features/shared/components/InternalSearch/InternalSearch.tsx +1 -1
  33. package/src/features/shared/types/PaymentMethodsClientTypes.ts +12 -0
  34. package/src/features/shared/types/index.ts +5 -0
  35. package/src/pages/payment-methods.tsx +76 -0
  36. package/src/themes/layouts.scss +3 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "dependencies": {
package/plugin.config.js CHANGED
@@ -17,11 +17,10 @@ module.exports = {
17
17
  path: "/buyer-portal/addresses/[orgUnitId]/[contractId]",
18
18
  appLayout: false,
19
19
  },
20
- // Theses Routes will be added in the future
21
- // "payment-methods": {
22
- // path: "/buyer-portal/payment-methods/[orgUnitId]/[contractId]",
23
- // appLayout: false,
24
- // },
20
+ "payment-methods": {
21
+ path: "/buyer-portal/payment-methods/[orgUnitId]/[contractId]",
22
+ appLayout: false,
23
+ },
25
24
  "credit-cards": {
26
25
  path: "/buyer-portal/credit-cards/[orgUnitId]/[contractId]",
27
26
  appLayout: false,
@@ -30,6 +29,7 @@ module.exports = {
30
29
  path: "/buyer-portal/collections/[orgUnitId]/[contractId]",
31
30
  appLayout: false,
32
31
  },
32
+ // Theses Routes will be added in the future
33
33
  // "po-numbers": {
34
34
  // path: "/buyer-portal/po-numbers/[orgUnitId]/[contractId]",
35
35
  // appLayout: false,
@@ -363,10 +363,18 @@
363
363
  fill="currentColor" />
364
364
  </symbol>
365
365
 
366
+ <symbol
367
+ id="AccountBalanceWallet"
368
+ viewBox="0 0 19 18"
369
+ fill="none"
370
+ xmlns="http://www.w3.org/2000/svg">
371
+ <path d="M2 18C1.45 18 0.979167 17.8042 0.5875 17.4125C0.195833 17.0208 0 16.55 0 16V2C0 1.45 0.195833 0.979167 0.5875 0.5875C0.979167 0.195833 1.45 0 2 0H16C16.55 0 17.0208 0.195833 17.4125 0.5875C17.8042 0.979167 18 1.45 18 2V4.5H16V2H2V16H16V13.5H18V16C18 16.55 17.8042 17.0208 17.4125 17.4125C17.0208 17.8042 16.55 18 16 18H2ZM10 14C9.45 14 8.97917 13.8042 8.5875 13.4125C8.19583 13.0208 8 12.55 8 12V6C8 5.45 8.19583 4.97917 8.5875 4.5875C8.97917 4.19583 9.45 4 10 4H17C17.55 4 18.0208 4.19583 18.4125 4.5875C18.8042 4.97917 19 5.45 19 6V12C19 12.55 18.8042 13.0208 18.4125 13.4125C18.0208 13.8042 17.55 14 17 14H10ZM17 12V6H10V12H17ZM13 10.5C13.4167 10.5 13.7708 10.3542 14.0625 10.0625C14.3542 9.77083 14.5 9.41667 14.5 9C14.5 8.58333 14.3542 8.22917 14.0625 7.9375C13.7708 7.64583 13.4167 7.5 13 7.5C12.5833 7.5 12.2292 7.64583 11.9375 7.9375C11.6458 8.22917 11.5 8.58333 11.5 9C11.5 9.41667 11.6458 9.77083 11.9375 10.0625C12.2292 10.3542 12.5833 10.5 13 10.5Z" fill="currentColor"/>
372
+ </symbol>
373
+
366
374
  <symbol id="MinusCircle" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
367
375
  <path
368
376
  d="M7 13H17V11H7V13ZM12 22C10.6167 22 9.31667 21.7375 8.1 21.2125C6.88333 20.6875 5.825 19.975 4.925 19.075C4.025 18.175 3.3125 17.1167 2.7875 15.9C2.2625 14.6833 2 13.3833 2 12C2 10.6167 2.2625 9.31667 2.7875 8.1C3.3125 6.88333 4.025 5.825 4.925 4.925C5.825 4.025 6.88333 3.3125 8.1 2.7875C9.31667 2.2625 10.6167 2 12 2C13.3833 2 14.6833 2.2625 15.9 2.7875C17.1167 3.3125 18.175 4.025 19.075 4.925C19.975 5.825 20.6875 6.88333 21.2125 8.1C21.7375 9.31667 22 10.6167 22 12C22 13.3833 21.7375 14.6833 21.2125 15.9C20.6875 17.1167 19.975 18.175 19.075 19.075C18.175 19.975 17.1167 20.6875 15.9 21.2125C14.6833 21.7375 13.3833 22 12 22ZM12 20C14.2333 20 16.125 19.225 17.675 17.675C19.225 16.125 20 14.2333 20 12C20 9.76667 19.225 7.875 17.675 6.325C16.125 4.775 14.2333 4 12 4C9.76667 4 7.875 4.775 6.325 6.325C4.775 7.875 4 9.76667 4 12C4 14.2333 4.775 16.125 6.325 17.675C7.875 19.225 9.76667 20 12 20Z"
369
377
  fill="currentColor" />
370
378
  </symbol>
371
379
 
372
- </svg>
380
+ </svg>
@@ -0,0 +1,87 @@
1
+ import { Client } from "../../shared/clients/Client";
2
+ import type {
3
+ PaymentMethodResponse,
4
+ PaymentMethodsIdArray,
5
+ PaymentMethodsReqCommonParams,
6
+ } from "../../shared/types";
7
+ import { getApiUrl } from "../../shared/utils";
8
+ import type { PaymentMethodData } from "../types";
9
+
10
+ export default class PaymentMethodsClient extends Client {
11
+ constructor() {
12
+ super(getApiUrl());
13
+ }
14
+
15
+ async getPaymentMethodsByUnitId(
16
+ data: PaymentMethodsReqCommonParams & {
17
+ options?: {
18
+ filterByScope?: boolean;
19
+ name?: string;
20
+ };
21
+ }
22
+ ) {
23
+ const { customerId, unitId, cookie, options } = data;
24
+
25
+ const queryParams = new URLSearchParams();
26
+
27
+ if (options?.filterByScope) {
28
+ queryParams.append("filterByScope", options.filterByScope.toString());
29
+ }
30
+
31
+ if (options?.name) {
32
+ queryParams.append("name", options.name);
33
+ }
34
+
35
+ const queryString = queryParams.toString();
36
+ const url = `customers/${customerId}/units/${unitId}/payment-methods${
37
+ queryString ? `?${queryString}` : ""
38
+ }`;
39
+
40
+ return await this.get<PaymentMethodData[]>(url, {
41
+ headers: {
42
+ Cookie: cookie,
43
+ },
44
+ });
45
+ }
46
+
47
+ async addPaymentMethodsToUnit(
48
+ data: PaymentMethodsReqCommonParams & {
49
+ paymentMethodsIds: PaymentMethodsIdArray;
50
+ }
51
+ ) {
52
+ const { customerId, unitId, cookie, paymentMethodsIds } = data;
53
+
54
+ return await this.post<PaymentMethodResponse, PaymentMethodsIdArray>(
55
+ `customers/${customerId}/units/${unitId}/payment-methods`,
56
+ paymentMethodsIds,
57
+ {
58
+ headers: {
59
+ Cookie: cookie,
60
+ "Content-Type": "application/json",
61
+ },
62
+ }
63
+ );
64
+ }
65
+
66
+ async removePaymentMethodFromUnit(
67
+ data: PaymentMethodsReqCommonParams & {
68
+ paymentMethodId: number;
69
+ }
70
+ ) {
71
+ const { customerId, unitId, cookie, paymentMethodId } = data;
72
+
73
+ return await this.delete(
74
+ `customers/${customerId}/units/${unitId}/payment-methods/${paymentMethodId}`,
75
+ null,
76
+ {
77
+ headers: {
78
+ Cookie: cookie,
79
+ },
80
+ }
81
+ );
82
+ }
83
+ }
84
+
85
+ const paymentMethodsClient = new PaymentMethodsClient();
86
+
87
+ export { paymentMethodsClient };
@@ -0,0 +1,178 @@
1
+ import { useState, useRef, useEffect, useMemo, useCallback } from "react";
2
+ import { useUI, Checkbox, Skeleton } from "@faststore/ui";
3
+ import { useRouter } from "next/router";
4
+ import { type BasicDrawerProps, BasicDrawer, Icon, Table } from "../../../shared/components";
5
+ import { SearchPaymentMethods } from "../SearchPaymentMethods/SearchPaymentMethods";
6
+ import { useBuyerPortal } from "../../../shared/hooks";
7
+ import { useAddPaymentMethodsToUnit } from "../../hooks";
8
+ import { useDebouncedSearchPaymentMethods } from "../../hooks/useDebouncedSearchPaymentMethods";
9
+
10
+ export type AddPaymentMethodsDrawerProps = Omit<BasicDrawerProps, "children"> & {
11
+ readonly?: boolean;
12
+ };
13
+
14
+ export const AddPaymentMethodsDrawer = ({
15
+ close,
16
+ readonly,
17
+ ...props
18
+ }: AddPaymentMethodsDrawerProps) => {
19
+ const [querySearch, setQuerySearch] = useState("");
20
+ const [selectedMethods, setSelectedMethods] = useState<Set<number>>(new Set());
21
+
22
+ const { pushToast } = useUI();
23
+ const router = useRouter();
24
+ const selectAllRef = useRef<HTMLInputElement>(null);
25
+
26
+ const { currentOrgUnit: orgUnit, currentContract: contract } = useBuyerPortal();
27
+
28
+ const customerId = contract?.id ?? "";
29
+ const unitId = orgUnit?.id ?? "";
30
+
31
+ const { paymentMethods, isLoadingPaymentMethods } = useDebouncedSearchPaymentMethods({
32
+ customerId,
33
+ unitId,
34
+ filterByScope: false,
35
+ search: querySearch,
36
+ });
37
+
38
+ const availableMethods = paymentMethods?.filter((method) => !method?.isEnabled);
39
+
40
+ const handleSuccess = () => {
41
+ pushToast({ message: "Payment methods added successfully", status: "INFO" });
42
+ router.reload();
43
+ close();
44
+ };
45
+
46
+ const { addPaymentMethods, isAddPaymentMethodsLoading } = useAddPaymentMethodsToUnit({
47
+ onSuccess: handleSuccess,
48
+ onError: (err) => {
49
+ pushToast({
50
+ message: err?.message ?? "An error occurred while adding the payment methods",
51
+ status: "ERROR",
52
+ });
53
+ },
54
+ });
55
+
56
+ const allSelected = useMemo(
57
+ () => availableMethods.length > 0 && selectedMethods.size === availableMethods.length,
58
+ [availableMethods, selectedMethods]
59
+ );
60
+
61
+ const someSelected = useMemo(
62
+ () => selectedMethods.size > 0 && !allSelected,
63
+ [selectedMethods, allSelected]
64
+ );
65
+
66
+ useEffect(() => {
67
+ if (selectAllRef.current) {
68
+ selectAllRef.current.indeterminate = someSelected;
69
+ }
70
+ }, [someSelected]);
71
+
72
+ const toggleItem = useCallback((id: number) => {
73
+ setSelectedMethods((prev) => {
74
+ const newSet = new Set(prev);
75
+ newSet.has(id) ? newSet.delete(id) : newSet.add(id);
76
+ return newSet;
77
+ });
78
+ }, []);
79
+
80
+ const toggleAll = useCallback(() => {
81
+ setSelectedMethods(allSelected ? new Set() : new Set(availableMethods.map((m) => m.id)));
82
+ }, [allSelected, availableMethods]);
83
+
84
+ const handleSubmit = () => {
85
+ const paymentMethodsIds = Array.from(selectedMethods, (id) => ({ id }));
86
+ addPaymentMethods({ customerId, unitId, paymentMethodsIds });
87
+ };
88
+
89
+ return (
90
+ <BasicDrawer data-fs-bp-add-payment-methods-drawer close={close} {...props}>
91
+ <BasicDrawer.Heading title="Add payment methods" onClose={close} />
92
+
93
+ <BasicDrawer.Body>
94
+ <section data-fs-payment-methods-drawer>
95
+ <p data-fs-bp-add-payment-methods-drawer-description>
96
+ Add payment methods
97
+ {orgUnit?.name && <span>{` to ${orgUnit.name}`}</span>}
98
+ </p>
99
+
100
+ <SearchPaymentMethods
101
+ data={selectedMethods.size}
102
+ paymentMethodsData={availableMethods}
103
+ defaultValue={querySearch}
104
+ textSearch={setQuerySearch}
105
+ />
106
+
107
+ {isLoadingPaymentMethods ? (
108
+ <div data-fs-payment-methods-loading>
109
+ {Array.from({ length: 5 }).map((_, index) => (
110
+ <Skeleton key={index} size={{ width: "100%", height: "1.5rem" }} />
111
+ ))}
112
+ </div>
113
+ ) : (
114
+ <ul data-fs-payment-methods-list>
115
+ <div
116
+ data-fs-bp-payment-methods-list-title
117
+ data-fs-bp-payment-methods-list-title-drawer
118
+ >
119
+ <Checkbox
120
+ data-fs-bp-payment-methods-checkbox
121
+ ref={selectAllRef}
122
+ checked={allSelected}
123
+ onChange={toggleAll}
124
+ disabled={readonly}
125
+ aria-label="Select all payment methods"
126
+ />
127
+ Name
128
+ </div>
129
+
130
+ {availableMethods.map(({ id, name }) => (
131
+ <li key={id} data-fs-payment-methods-line>
132
+ <div
133
+ data-fs-payment-methods-row
134
+ data-fs-payment-methods-row-selected={selectedMethods.has(
135
+ id
136
+ )}
137
+ >
138
+ <div data-fs-payment-methods-row-information>
139
+ <Checkbox
140
+ data-fs-bp-payment-methods-checkbox
141
+ checked={selectedMethods.has(id)}
142
+ onChange={() => toggleItem(id)}
143
+ disabled={readonly}
144
+ aria-label={`Select ${name}`}
145
+ />
146
+ <span data-fs-payment-methods-row-icon-wrapper>
147
+ <Icon
148
+ name="AccountBalanceWallet"
149
+ width={20}
150
+ height={20}
151
+ />
152
+ </span>
153
+ <div data-fs-payment-methods-name>{name}</div>
154
+ </div>
155
+ </div>
156
+ </li>
157
+ ))}
158
+ </ul>
159
+ )}
160
+ </section>
161
+ </BasicDrawer.Body>
162
+
163
+ <BasicDrawer.Footer data-fs-bp-add-payment-methods-drawer-footer>
164
+ <BasicDrawer.Button variant="ghost" onClick={close}>
165
+ Cancel
166
+ </BasicDrawer.Button>
167
+ <BasicDrawer.Button
168
+ variant="confirm"
169
+ isLoading={isAddPaymentMethodsLoading}
170
+ onClick={handleSubmit}
171
+ disabled={!selectedMethods.size}
172
+ >
173
+ Add
174
+ </BasicDrawer.Button>
175
+ </BasicDrawer.Footer>
176
+ </BasicDrawer>
177
+ );
178
+ };
@@ -0,0 +1,44 @@
1
+ @import "../SearchPaymentMethods/search-payment-methods.scss";
2
+
3
+ [data-fs-bp-add-payment-methods-drawer] {
4
+ min-width: 66% !important;
5
+
6
+ [data-fs-payment-methods-drawer] {
7
+ @import "@faststore/ui/src/components/atoms/Checkbox/styles.scss";
8
+ @import "@faststore/ui/src/components/atoms/Skeleton/styles.scss";
9
+
10
+ [data-fs-bp-add-payment-methods-drawer-description] {
11
+ color: #1f1f1f;
12
+ margin-bottom: var(--fs-spacing-3);
13
+
14
+ span {
15
+ color: #0366dd;
16
+ }
17
+ }
18
+
19
+ [data-fs-bp-payment-methods-checkbox] {
20
+ border-color: #e5e5e5;
21
+ }
22
+
23
+ [data-fs-bp-payment-methods-checkbox]:checked {
24
+ background-color: #0366dd;
25
+ }
26
+
27
+ [data-fs-bp-basic-drawer-button-loading-indicator] {
28
+ position: relative;
29
+ }
30
+
31
+ [data-fs-payment-methods-loading] {
32
+ * {
33
+ margin-top: var(--fs-spacing-1);
34
+ padding: var(--fs-spacing-2) 0;
35
+ }
36
+ }
37
+ }
38
+
39
+ [data-fs-bp-add-payment-methods-drawer-footer] {
40
+ display: flex;
41
+ justify-content: flex-end;
42
+ gap: var(--fs-spacing-3);
43
+ }
44
+ }
@@ -0,0 +1,45 @@
1
+ import { Tooltip, Icon as UIIcon } from "@faststore/ui";
2
+ import type { ComponentProps } from "react";
3
+ import { Icon } from "../../../shared/components";
4
+
5
+ export type RemoveMethodButtonProps = {
6
+ isLoading: boolean;
7
+ disabled: boolean;
8
+ onClick?: () => void;
9
+ } & ComponentProps<"button">;
10
+
11
+ export const RemoveMethodButton = ({
12
+ isLoading,
13
+ disabled,
14
+ onClick,
15
+ ...props
16
+ }: RemoveMethodButtonProps) => {
17
+ return (
18
+ <Tooltip
19
+ data-fs-payment-methods-tooltip
20
+ placement={disabled ? "left-center" : "top-center"}
21
+ content={
22
+ disabled
23
+ ? "This payment method can't be removed. Each unit must have at least one active payment method. Add another one to proceed with the removal."
24
+ : "Remove from unit"
25
+ }
26
+ >
27
+ <button
28
+ {...props}
29
+ type="button"
30
+ data-fs-payment-methods-row-action-button
31
+ aria-label={"remove payment method action"}
32
+ disabled={disabled}
33
+ onClick={onClick}
34
+ >
35
+ <Icon
36
+ data-fs-icon
37
+ data-fs-icon-loading={isLoading}
38
+ name={isLoading ? "LoadingIndicator" : "MinusCircle"}
39
+ width={20}
40
+ height={20}
41
+ />
42
+ </button>
43
+ </Tooltip>
44
+ );
45
+ };
@@ -0,0 +1,42 @@
1
+ [data-fs-payment-methods-row-action-button] {
2
+ margin: 0 var(--fs-spacing-1);
3
+ border-radius: var(--fs-border-radius-pill);
4
+ width: var(--fs-spacing-5);
5
+ aspect-ratio: 1;
6
+ display: flex;
7
+ justify-content: center;
8
+ align-items: center;
9
+ cursor: pointer;
10
+
11
+ &:disabled {
12
+ cursor: not-allowed;
13
+
14
+ [data-fs-icon] {
15
+ color: #adadad;
16
+
17
+ &[data-fs-icon-loading="true"] {
18
+ @keyframes rotate {
19
+ from {
20
+ transform: rotate(0deg);
21
+ }
22
+ to {
23
+ transform: rotate(360deg);
24
+ }
25
+ }
26
+ animation: rotate 2s linear infinite;
27
+ }
28
+ }
29
+ }
30
+
31
+ &:hover {
32
+ background-color: #e0e0e0;
33
+ }
34
+
35
+ &:active {
36
+ opacity: 0.8;
37
+ }
38
+
39
+ [data-fs-icon] {
40
+ color: #000;
41
+ }
42
+ }
@@ -0,0 +1,81 @@
1
+ import { CheckboxField } from "@faststore/ui";
2
+ import { type BasicDrawerProps, BasicDrawer } from "../../../shared/components";
3
+ import type { PaymentMethodData } from "../../types";
4
+ import { useBuyerPortal } from "../../../shared/hooks";
5
+ import { useCookiePreferenceHideDrawer } from "../../hooks/useCookiePreferenceHideDrawer";
6
+ import { useState } from "react";
7
+ import { useRemovePaymentMethod } from "../../hooks/useRemovePaymentMethodSubmit";
8
+
9
+ export type RemovePaymentMethodsDrawerProps = Omit<BasicDrawerProps, "children"> & {
10
+ paymentMethod: PaymentMethodData;
11
+ readonly?: boolean;
12
+ };
13
+
14
+ export const RemovePaymentMethodsDrawer = ({
15
+ close,
16
+ paymentMethod,
17
+ readonly,
18
+ ...props
19
+ }: RemovePaymentMethodsDrawerProps) => {
20
+ const { currentOrgUnit: orgUnit } = useBuyerPortal();
21
+ const { hideMessage, isMessageHidden } = useCookiePreferenceHideDrawer();
22
+
23
+ const [dontShowAgain, setDontShowAgain] = useState<boolean>(isMessageHidden || false);
24
+
25
+ const handleSuccess = () => {
26
+ close();
27
+ if (dontShowAgain) {
28
+ hideMessage();
29
+ }
30
+ };
31
+
32
+ const { remove, isRemovingPaymentMethod } = useRemovePaymentMethod(handleSuccess);
33
+
34
+ const handleSubmit = (paymentMethodId: number) => {
35
+ remove(paymentMethodId);
36
+ };
37
+
38
+ if (!paymentMethod || isMessageHidden) {
39
+ return null;
40
+ }
41
+
42
+ return (
43
+ <BasicDrawer data-fs-bp-remove-payment-methods-drawer close={close} {...props}>
44
+ <BasicDrawer.Heading title="Remove payment method from unit" onClose={close} />
45
+ <BasicDrawer.Body>
46
+ <section data-fs-payment-methods-drawer>
47
+ <p data-fs-bp-remove-payment-methods-drawer-description>
48
+ Remove <span>{paymentMethod?.name}</span> contract from{" "}
49
+ <span>{orgUnit?.name}</span> organizational unit?
50
+ </p>
51
+ <p data-fs-bp-remove-payment-methods-drawer-description>
52
+ This action will prevent users in this unit from acessing this payment
53
+ method during checkout.
54
+ </p>
55
+ <CheckboxField
56
+ data-fs-checkbox-field-content
57
+ data-fs-bp-payment-methods-checkbox
58
+ label="Don't show this message again"
59
+ id="prevent-message"
60
+ checked={dontShowAgain}
61
+ onChange={(e) => setDontShowAgain(e.target.checked)}
62
+ />
63
+ </section>
64
+ </BasicDrawer.Body>
65
+
66
+ <BasicDrawer.Footer data-fs-bp-add-payment-methods-drawer-footer>
67
+ <BasicDrawer.Button variant="ghost" onClick={close}>
68
+ Cancel
69
+ </BasicDrawer.Button>
70
+ <BasicDrawer.Button
71
+ variant="confirm"
72
+ isLoading={isRemovingPaymentMethod}
73
+ onClick={() => handleSubmit(paymentMethod.id)}
74
+ disabled={readonly}
75
+ >
76
+ Remove
77
+ </BasicDrawer.Button>
78
+ </BasicDrawer.Footer>
79
+ </BasicDrawer>
80
+ );
81
+ };
@@ -0,0 +1,40 @@
1
+ [data-fs-bp-remove-payment-methods-drawer] {
2
+ [data-fs-payment-methods-drawer] {
3
+ @import "@faststore/ui/src/components/atoms/Checkbox/styles.scss";
4
+ @import "@faststore/ui/src/components/molecules/CheckboxField/styles.scss";
5
+
6
+ [data-fs-bp-remove-payment-methods-drawer-description] {
7
+ color: #1f1f1f;
8
+ margin-bottom: var(--fs-spacing-3);
9
+
10
+ span {
11
+ color: #0366dd;
12
+ }
13
+ }
14
+
15
+ [data-fs-bp-payment-methods-checkbox] {
16
+ border-color: #e5e5e5;
17
+ }
18
+
19
+ [data-fs-bp-payment-methods-checkbox]:checked {
20
+ background-color: #0366dd;
21
+ }
22
+
23
+ [data-fs-bp-basic-drawer-button-loading-indicator] {
24
+ position: relative;
25
+ }
26
+
27
+ [data-fs-checkbox-field-content] {
28
+ label {
29
+ color: #000;
30
+ font-size: var(--fs-text-size-1);
31
+ }
32
+ }
33
+ }
34
+
35
+ [data-fs-bp-add-payment-methods-drawer-footer] {
36
+ display: flex;
37
+ justify-content: flex-end;
38
+ gap: var(--fs-spacing-3);
39
+ }
40
+ }
@@ -0,0 +1,40 @@
1
+ import { InternalSearch } from "../../../shared/components";
2
+ import { InternalSearchProps } from "../../../shared/components/InternalSearch/InternalSearch";
3
+ import { useQueryParams } from "../../../shared/hooks";
4
+ import type { PaymentMethodData } from "../../types";
5
+
6
+ export type SearchPaymentMethodsProps = InternalSearchProps & {
7
+ data: PaymentMethodData[] | number;
8
+ paymentMethodsData: PaymentMethodData[] | number;
9
+ };
10
+
11
+ export const SearchPaymentMethods = ({
12
+ data,
13
+ paymentMethodsData,
14
+ ...props
15
+ }: SearchPaymentMethodsProps) => {
16
+ const { setQueryString, removeQueryString } = useQueryParams();
17
+
18
+ const getCount = (value: PaymentMethodData[] | number) =>
19
+ typeof value === "number" ? value : value?.length ?? 0;
20
+
21
+ return (
22
+ <div data-fs-bp-payment-methods-search-container>
23
+ <InternalSearch
24
+ // TODO: Corrigir warning do componente InternalSearch ( A component contains an input of type undefined with both value and defaultValue props. Input elements must be either controlled or uncontrolled )
25
+ textSearch={
26
+ props.textSearch
27
+ ? (searchTerm) => props.textSearch(searchTerm)
28
+ : (searchTerm) => {
29
+ searchTerm
30
+ ? setQueryString("search", searchTerm)
31
+ : removeQueryString("search");
32
+ }
33
+ }
34
+ />
35
+ <p data-fs-bp-payment-methods-search-container-counter>
36
+ {`${getCount(data)} of ${getCount(paymentMethodsData)}`}
37
+ </p>
38
+ </div>
39
+ );
40
+ };
@@ -0,0 +1,15 @@
1
+ @import "../../../shared/components/InternalSearch/internal-search.scss";
2
+
3
+ [data-fs-bp-payment-methods-search-container] {
4
+ display: flex;
5
+ justify-content: space-between;
6
+ align-items: center;
7
+ gap: var(--fs-spacing-1);
8
+ padding-bottom: var(--fs-spacing-5);
9
+ width: 100%;
10
+
11
+ [data-fs-bp-payment-methods-search-container-counter] {
12
+ font-size: var(--fs-text-size-1);
13
+ color: #5c5c5c;
14
+ }
15
+ }
@@ -0,0 +1,4 @@
1
+ export { AddPaymentMethodsDrawer } from "./AddPaymentMethodsDrawer/AddPaymentMethodsDrawer";
2
+ export { RemovePaymentMethodsDrawer } from "./RemovePaymentMethodsDrawer/RemovePaymentMethodsDrawer";
3
+ export { RemoveMethodButton } from "./RemoveMethodButton/RemoveMethodButton";
4
+ export { SearchPaymentMethods } from "./SearchPaymentMethods/SearchPaymentMethods";
@@ -0,0 +1,3 @@
1
+ export * from "./useAddPaymentMethodsToUnit";
2
+ export * from "./useGetPaymentMethodsByUnitId";
3
+ export * from "./useRemovePaymentMethodsFromUnit";
@@ -0,0 +1,27 @@
1
+ import { type MutationOptions, useMutation } from "../../shared/hooks";
2
+ import {
3
+ addPaymentMethodsToUnitService,
4
+ type AddPaymentMethodsToUnitServiceProps,
5
+ } from "../services";
6
+
7
+ export const useAddPaymentMethodsToUnit = (
8
+ options?: MutationOptions<AwaitedType<typeof addPaymentMethodsToUnitService>>
9
+ ) => {
10
+ const { mutate, isLoading, error } = useMutation<
11
+ AwaitedType<typeof addPaymentMethodsToUnitService>,
12
+ Omit<AddPaymentMethodsToUnitServiceProps, "cookie">
13
+ >(
14
+ (variables, clientContext) =>
15
+ addPaymentMethodsToUnitService({
16
+ ...variables,
17
+ cookie: clientContext.cookie,
18
+ }),
19
+ options
20
+ );
21
+
22
+ return {
23
+ addPaymentMethods: mutate,
24
+ isAddPaymentMethodsLoading: isLoading,
25
+ hasAddPaymentMethodsError: error,
26
+ };
27
+ };