@vtex/faststore-plugin-buyer-portal 1.0.28 → 1.0.30
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/package.json +1 -1
- package/plugin.config.js +4 -4
- package/public/buyer-portal-icons.svg +4 -10
- package/src/clients/BuyerPortalClient.ts +54 -12
- package/src/clients/Client.ts +41 -25
- package/src/features/contracts/components/ContractsCard/ContractsCard.tsx +18 -19
- package/src/features/contracts/hooks/index.ts +1 -0
- package/src/features/contracts/hooks/useUpdateContractStatus.ts +27 -0
- package/src/features/contracts/layouts/ContractsLayout/ContractsLayout.tsx +20 -2
- package/src/features/contracts/layouts/ContractsLayout/contracts-layout.scss +1 -0
- package/src/features/contracts/services/get-contract-details.service.ts +16 -0
- package/src/features/contracts/services/{get-contracts.service.ts → get-contracts-by-customer-id.service.ts} +5 -15
- package/src/features/contracts/services/get-contracts-org-by-unit-id.service.ts +40 -0
- package/src/features/contracts/services/index.ts +15 -3
- package/src/features/contracts/services/update-contract-status.service.ts +25 -0
- package/src/features/contracts/types/ContractData.ts +1 -1
- package/src/features/org-units/components/CreateOrgUnitDrawer/CreateOrgUnitDrawer.tsx +13 -1
- package/src/features/org-units/components/DeleteOrgUnitDrawer/DeleteOrgUnitDrawer.tsx +66 -67
- package/src/features/org-units/components/DeleteOrgUnitDrawer/delete-org-unit-drawer.scss +17 -1
- package/src/features/org-units/components/OrgUnitsDropdownMenu/OrgUnitsDropdownMenu.tsx +21 -21
- package/src/features/org-units/components/OrgUnitsHierarchyTree/OrgUnitsHierarchyTree.tsx +2 -9
- package/src/features/org-units/components/OrganizationalUnitsCard/OrganizationalUnitsCard.tsx +0 -1
- package/src/features/org-units/components/UpdateOrgUnitDrawer/UpdateOrgUnitDrawer.tsx +12 -32
- package/src/features/org-units/hooks/useCreateNewOrgUnit.ts +1 -1
- package/src/features/org-units/hooks/useUpdateOrgUnit.ts +1 -1
- package/src/features/org-units/layouts/OrgUnitDetailsLayout/OrgUnitDetailsLayout.tsx +19 -2
- package/src/features/org-units/layouts/OrgUnitsLayout/OrgUnitsLayout.tsx +17 -1
- package/src/features/org-units/layouts/OrgUnitsLayout/org-units-layout.scss +7 -1
- package/src/features/org-units/types/OrgUnitsData.ts +1 -1
- package/src/features/profile/components/ProfileCard/ProfileCard.tsx +2 -8
- package/src/features/profile/layouts/ProfileLayout/ProfileLayout.tsx +9 -5
- package/src/features/profile/layouts/ProfileLayout/profile-layout.scss +1 -1
- package/src/features/shared/components/BasicCard/BasicCard.tsx +3 -1
- package/src/features/shared/components/BasicDropdownMenu/BasicDropdownMenu.tsx +4 -0
- package/src/features/shared/components/BasicDropdownMenu/basic-dropdown-menu.scss +27 -12
- package/src/features/shared/components/InputText/InputText.tsx +2 -2
- package/src/features/shared/components/Toast/Toast.tsx +1 -3
- package/src/features/shared/components/Toast/toast.scss +8 -0
- package/src/features/shared/components/index.ts +2 -0
- package/src/features/shared/hooks/useBuyerPortal.ts +1 -4
- package/src/features/shared/layouts/GlobalLayout/GlobalLayout.tsx +1 -2
- package/src/features/shared/layouts/HomeLayout/HomeLayout.tsx +19 -2
- package/src/features/shared/layouts/HomeLayout/home-layout.scss +10 -4
- package/src/features/shared/utils/cookie.ts +31 -6
- package/src/features/shared/utils/getClientContext.ts +3 -2
- package/src/features/shared/utils/getTreeDepth.ts +1 -1
- package/src/pages/contracts.tsx +7 -2
- package/src/pages/org-units.tsx +2 -1
- package/src/pages/profile.tsx +20 -8
package/package.json
CHANGED
package/plugin.config.js
CHANGED
|
@@ -17,16 +17,16 @@ module.exports = {
|
|
|
17
17
|
path: "/user/[userId]",
|
|
18
18
|
appLayout: false,
|
|
19
19
|
},
|
|
20
|
+
profile: {
|
|
21
|
+
path: "/profile/[[...contractId]]",
|
|
22
|
+
appLayout: false,
|
|
23
|
+
},
|
|
20
24
|
|
|
21
25
|
// Shared pages
|
|
22
26
|
"org-units": {
|
|
23
27
|
path: "/org-units/[[...orgUnitId]]",
|
|
24
28
|
appLayout: false,
|
|
25
29
|
},
|
|
26
|
-
profile: {
|
|
27
|
-
path: "/profile/[[...orgUnitId]]",
|
|
28
|
-
appLayout: false,
|
|
29
|
-
},
|
|
30
30
|
contracts: {
|
|
31
31
|
path: "/contracts/[[...orgUnitId]]",
|
|
32
32
|
appLayout: false,
|
|
@@ -211,17 +211,11 @@
|
|
|
211
211
|
d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h560v-280h80v280q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L388-332Z" />
|
|
212
212
|
</symbol>
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
id="Profile"
|
|
217
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
218
|
-
viewBox="0 0 14 14"
|
|
219
|
-
fill="none"
|
|
220
|
-
>
|
|
214
|
+
<symbol id="Profile" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12"
|
|
215
|
+
fill="none">
|
|
221
216
|
<path
|
|
222
|
-
d="
|
|
223
|
-
fill="currentColor"
|
|
224
|
-
/>
|
|
217
|
+
d="M6 6C5.16667 6 4.45833 5.70833 3.875 5.125C3.29167 4.54167 3 3.83333 3 3C3 2.16667 3.29167 1.45833 3.875 0.875C4.45833 0.291667 5.16667 0 6 0C6.83333 0 7.54167 0.291667 8.125 0.875C8.70833 1.45833 9 2.16667 9 3C9 3.83333 8.70833 4.54167 8.125 5.125C7.54167 5.70833 6.83333 6 6 6ZM0 12V10C0 9.68056 0.0868056 9.37847 0.260417 9.09375C0.434028 8.80903 0.673611 8.56944 0.979167 8.375C1.74306 7.93056 2.55063 7.59028 3.40188 7.35417C4.25313 7.11806 5.11771 7 5.99563 7C6.87354 7 7.73958 7.11806 8.59375 7.35417C9.44792 7.59028 10.2569 7.93056 11.0208 8.375C11.3264 8.55556 11.566 8.79167 11.7396 9.08333C11.9132 9.375 12 9.68056 12 10V12H0ZM1.5 10.5H10.5V10C10.5 9.92806 10.479 9.86271 10.4369 9.80396C10.3949 9.74507 10.3396 9.69931 10.2708 9.66667C9.63194 9.27778 8.95139 8.98611 8.22917 8.79167C7.50694 8.59722 6.76389 8.5 6 8.5C5.23611 8.5 4.49306 8.59722 3.77083 8.79167C3.04861 8.98611 2.36806 9.27778 1.72917 9.66667C1.65972 9.72222 1.60417 9.77583 1.5625 9.8275C1.52083 9.87931 1.5 9.93681 1.5 10V10.5ZM6.00437 4.5C6.41813 4.5 6.77083 4.35271 7.0625 4.05812C7.35417 3.76354 7.5 3.40937 7.5 2.99562C7.5 2.58187 7.35271 2.22917 7.05812 1.9375C6.76354 1.64583 6.40938 1.5 5.99563 1.5C5.58188 1.5 5.22917 1.64729 4.9375 1.94188C4.64583 2.23646 4.5 2.59063 4.5 3.00438C4.5 3.41813 4.64729 3.77083 4.94187 4.0625C5.23646 4.35417 5.59062 4.5 6.00437 4.5Z"
|
|
218
|
+
fill="currentColor" />
|
|
225
219
|
</symbol>
|
|
226
220
|
|
|
227
221
|
<symbol
|
|
@@ -16,7 +16,7 @@ class BuyerPortalClient extends Client {
|
|
|
16
16
|
// Contracts
|
|
17
17
|
getContractsByCustomerId(customerId: string, cookie: string) {
|
|
18
18
|
return this.get<{ data: { contracts: ContractData[]; total: number } }>(
|
|
19
|
-
`contracts/${customerId}`,
|
|
19
|
+
`contracts/${customerId}/list`,
|
|
20
20
|
{
|
|
21
21
|
headers: {
|
|
22
22
|
Cookie: cookie,
|
|
@@ -25,6 +25,25 @@ class BuyerPortalClient extends Client {
|
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
getContractsByOrgUnitId(orgUnitId: string, cookie: string) {
|
|
29
|
+
return this.get<{ contracts: ContractData[]; total: number }>(
|
|
30
|
+
`contracts/${orgUnitId}`,
|
|
31
|
+
{
|
|
32
|
+
headers: {
|
|
33
|
+
Cookie: cookie,
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getContractDetails(contractId: string, cookie: string) {
|
|
40
|
+
return this.get<{ contract: ContractData }>(`contract/${contractId}`, {
|
|
41
|
+
headers: {
|
|
42
|
+
Cookie: cookie,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
28
47
|
getContracts(
|
|
29
48
|
cookie: string,
|
|
30
49
|
params?: {
|
|
@@ -42,6 +61,24 @@ class BuyerPortalClient extends Client {
|
|
|
42
61
|
});
|
|
43
62
|
}
|
|
44
63
|
|
|
64
|
+
updateContractStatus(
|
|
65
|
+
data: { contractId: string; isActive: boolean },
|
|
66
|
+
cookie: string
|
|
67
|
+
) {
|
|
68
|
+
const { contractId, isActive } = data;
|
|
69
|
+
|
|
70
|
+
return this.post<null, { isActive: boolean }>(
|
|
71
|
+
`contracts/status/${contractId}`,
|
|
72
|
+
{ isActive },
|
|
73
|
+
{
|
|
74
|
+
headers: {
|
|
75
|
+
Cookie: cookie,
|
|
76
|
+
},
|
|
77
|
+
data: { isActive },
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
45
82
|
//Addresses
|
|
46
83
|
getAddressesByCustomerId(customerId: string, cookie: string) {
|
|
47
84
|
return this.get<{ addresses: AddressData[] }>(`addresses/${customerId}`, {
|
|
@@ -89,15 +126,22 @@ class BuyerPortalClient extends Client {
|
|
|
89
126
|
}
|
|
90
127
|
|
|
91
128
|
createOrgUnit(
|
|
92
|
-
{
|
|
93
|
-
parentId,
|
|
94
|
-
...data
|
|
95
|
-
}: { name: string; parentId: string | null; customerId: string[] },
|
|
129
|
+
data: { name: string; parentId?: string | null; customerId: string[] },
|
|
96
130
|
cookie: string
|
|
97
131
|
) {
|
|
98
|
-
|
|
132
|
+
const { parentId, ...input } = data;
|
|
133
|
+
return this.post<
|
|
134
|
+
{
|
|
135
|
+
customerIds: string[];
|
|
136
|
+
id: string;
|
|
137
|
+
isActive: boolean;
|
|
138
|
+
name: string;
|
|
139
|
+
parentId: string;
|
|
140
|
+
},
|
|
141
|
+
typeof data
|
|
142
|
+
>(
|
|
99
143
|
"units",
|
|
100
|
-
{ ...
|
|
144
|
+
{ ...input, ...(parentId && { parentId }) },
|
|
101
145
|
{
|
|
102
146
|
headers: {
|
|
103
147
|
Cookie: cookie,
|
|
@@ -106,11 +150,9 @@ class BuyerPortalClient extends Client {
|
|
|
106
150
|
);
|
|
107
151
|
}
|
|
108
152
|
|
|
109
|
-
updateOrgUnit(
|
|
110
|
-
{ id, ...
|
|
111
|
-
|
|
112
|
-
) {
|
|
113
|
-
return this.patch(`units/${id}`, data, {
|
|
153
|
+
updateOrgUnit(data: { name?: string; id: string }, cookie: string) {
|
|
154
|
+
const { id, ...input } = data;
|
|
155
|
+
return this.patch<null, typeof input>(`units/${id}`, input, {
|
|
114
156
|
headers: {
|
|
115
157
|
Cookie: cookie,
|
|
116
158
|
},
|
package/src/clients/Client.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { toQueryParams } from "../features/shared/utils";
|
|
2
2
|
|
|
3
|
-
interface RequestConfig<
|
|
3
|
+
interface RequestConfig<Input = never> {
|
|
4
4
|
url: string;
|
|
5
5
|
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
6
|
-
data?:
|
|
6
|
+
data?: Input;
|
|
7
7
|
headers?: Record<string, string>;
|
|
8
8
|
params?: Record<string, string | number | boolean>;
|
|
9
9
|
}
|
|
@@ -15,13 +15,13 @@ class Client {
|
|
|
15
15
|
this.baseURL = baseURL;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
async request<
|
|
18
|
+
async request<Return, Input = never>({
|
|
19
19
|
url,
|
|
20
20
|
method,
|
|
21
21
|
data,
|
|
22
22
|
headers = {},
|
|
23
23
|
params = {},
|
|
24
|
-
}: RequestConfig<
|
|
24
|
+
}: RequestConfig<Input>): Promise<Return> {
|
|
25
25
|
const config: RequestInit = {
|
|
26
26
|
method,
|
|
27
27
|
headers: {
|
|
@@ -38,7 +38,7 @@ class Client {
|
|
|
38
38
|
|
|
39
39
|
try {
|
|
40
40
|
const response = await fetch(this.baseURL + url + paramsString, config);
|
|
41
|
-
let responseData:
|
|
41
|
+
let responseData: Return | null = null;
|
|
42
42
|
|
|
43
43
|
const contentType = response.headers.get("Content-Type");
|
|
44
44
|
if (contentType?.includes("application/json")) {
|
|
@@ -52,42 +52,58 @@ class Client {
|
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
return responseData as
|
|
55
|
+
return responseData as Return;
|
|
56
56
|
} catch (error) {
|
|
57
57
|
return Promise.reject(error);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
get<
|
|
62
|
-
|
|
61
|
+
get<Return>(
|
|
62
|
+
url: string,
|
|
63
|
+
config: Partial<RequestConfig> = {}
|
|
64
|
+
): Promise<Return> {
|
|
65
|
+
return this.request<Return>({ url, method: "GET", ...config });
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
post<
|
|
68
|
+
post<Return, Input>(
|
|
66
69
|
url: string,
|
|
67
|
-
data:
|
|
68
|
-
config: Partial<RequestConfig<
|
|
69
|
-
): Promise<
|
|
70
|
-
return this.request<
|
|
70
|
+
data: Input,
|
|
71
|
+
config: Partial<RequestConfig<Input>> = {}
|
|
72
|
+
): Promise<Return> {
|
|
73
|
+
return this.request<Return, Input>({
|
|
74
|
+
url,
|
|
75
|
+
method: "POST",
|
|
76
|
+
data,
|
|
77
|
+
...config,
|
|
78
|
+
});
|
|
71
79
|
}
|
|
72
80
|
|
|
73
|
-
put<
|
|
81
|
+
put<Return, Input>(
|
|
74
82
|
url: string,
|
|
75
|
-
data:
|
|
76
|
-
config: Partial<RequestConfig<
|
|
77
|
-
): Promise<
|
|
78
|
-
return this.request<
|
|
83
|
+
data: Input,
|
|
84
|
+
config: Partial<RequestConfig<Input>> = {}
|
|
85
|
+
): Promise<Return> {
|
|
86
|
+
return this.request<Return, Input>({ url, method: "PUT", data, ...config });
|
|
79
87
|
}
|
|
80
88
|
|
|
81
|
-
patch<
|
|
89
|
+
patch<Return, Input>(
|
|
82
90
|
url: string,
|
|
83
|
-
data:
|
|
84
|
-
config: Partial<RequestConfig<
|
|
85
|
-
): Promise<
|
|
86
|
-
return this.request<
|
|
91
|
+
data: Input,
|
|
92
|
+
config: Partial<RequestConfig<Input>> = {}
|
|
93
|
+
): Promise<Return> {
|
|
94
|
+
return this.request<Return, Input>({
|
|
95
|
+
url,
|
|
96
|
+
method: "PATCH",
|
|
97
|
+
data,
|
|
98
|
+
...config,
|
|
99
|
+
});
|
|
87
100
|
}
|
|
88
101
|
|
|
89
|
-
delete<
|
|
90
|
-
|
|
102
|
+
delete<Return>(
|
|
103
|
+
url: string,
|
|
104
|
+
config: Partial<RequestConfig<never>> = {}
|
|
105
|
+
): Promise<Return> {
|
|
106
|
+
return this.request<Return>({ url, method: "DELETE", ...config });
|
|
91
107
|
}
|
|
92
108
|
}
|
|
93
109
|
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
} from "@faststore/ui";
|
|
9
9
|
import type { ContractData } from "../../types";
|
|
10
10
|
import { BasicCard, Icon } from "../../../shared/components";
|
|
11
|
+
import { useRouter } from "next/router";
|
|
12
|
+
import { useUpdateContractStatus } from "../../hooks";
|
|
11
13
|
|
|
12
14
|
type ContractsCardProps = {
|
|
13
15
|
orgUnitData?: {
|
|
@@ -21,12 +23,17 @@ export default function ContractsCard({
|
|
|
21
23
|
contracts,
|
|
22
24
|
orgUnitData,
|
|
23
25
|
}: ContractsCardProps) {
|
|
26
|
+
const route = useRouter();
|
|
27
|
+
|
|
28
|
+
const { updateContractStatus } = useUpdateContractStatus();
|
|
29
|
+
|
|
24
30
|
return (
|
|
25
31
|
<BasicCard
|
|
26
32
|
footerLink={`/contracts${orgUnitData?.id ? `/${orgUnitData.id}` : ""}`}
|
|
27
33
|
footerMessage="View contracts"
|
|
28
34
|
title="Contracts"
|
|
29
35
|
subTitle={contracts.length ?? 0}
|
|
36
|
+
icon={<Icon name="Info" width={20} height={20} />}
|
|
30
37
|
onPlusIconClick={() => {}}
|
|
31
38
|
>
|
|
32
39
|
{contracts.length &&
|
|
@@ -48,6 +55,12 @@ export default function ContractsCard({
|
|
|
48
55
|
<Toggle
|
|
49
56
|
id="contractActive"
|
|
50
57
|
defaultChecked={contract.isActive}
|
|
58
|
+
onChange={(event) => {
|
|
59
|
+
updateContractStatus({
|
|
60
|
+
contractId: contract.id,
|
|
61
|
+
isActive: event.target.checked,
|
|
62
|
+
});
|
|
63
|
+
}}
|
|
51
64
|
/>
|
|
52
65
|
|
|
53
66
|
<Dropdown>
|
|
@@ -55,7 +68,11 @@ export default function ContractsCard({
|
|
|
55
68
|
<Icon name="MoreVert" data-fs-menu-action-button />
|
|
56
69
|
</DropdownButton>
|
|
57
70
|
<DropdownMenu align="right" data-fs-dropdown-menu>
|
|
58
|
-
<DropdownItem
|
|
71
|
+
<DropdownItem
|
|
72
|
+
onClick={() => {
|
|
73
|
+
route.push(`/contract/${contract.id}`);
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
59
76
|
<UIIcon name="ArrowSquareOut" data-fs-dropdown-icon />
|
|
60
77
|
Open
|
|
61
78
|
</DropdownItem>
|
|
@@ -77,24 +94,6 @@ export default function ContractsCard({
|
|
|
77
94
|
/>{" "}
|
|
78
95
|
Delete
|
|
79
96
|
</DropdownItem>
|
|
80
|
-
<DropdownItem dismissOnClick={false}>
|
|
81
|
-
<div data-fs-dropdown-active-item>
|
|
82
|
-
<div data-fs-dropdown-active-item-label>
|
|
83
|
-
<Icon
|
|
84
|
-
name="Active"
|
|
85
|
-
width={24}
|
|
86
|
-
height={24}
|
|
87
|
-
data-fs-dropdown-icon
|
|
88
|
-
/>{" "}
|
|
89
|
-
Active
|
|
90
|
-
</div>
|
|
91
|
-
<Toggle
|
|
92
|
-
id="contractActiveMenu"
|
|
93
|
-
defaultChecked={contract.isActive}
|
|
94
|
-
data-fs-internal-toggle
|
|
95
|
-
/>
|
|
96
|
-
</div>
|
|
97
|
-
</DropdownItem>
|
|
98
97
|
</DropdownMenu>
|
|
99
98
|
</Dropdown>
|
|
100
99
|
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useUpdateContractStatus } from "./useUpdateContractStatus";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type MutationOptions, useMutation } from "../../shared/hooks";
|
|
2
|
+
import {
|
|
3
|
+
updateContractStatusService,
|
|
4
|
+
type UpdateContractStatusServiceProps,
|
|
5
|
+
} from "../services";
|
|
6
|
+
|
|
7
|
+
export const useUpdateContractStatus = (
|
|
8
|
+
options?: MutationOptions<AwaitedType<typeof updateContractStatusService>>
|
|
9
|
+
) => {
|
|
10
|
+
const { mutate, isLoading, error } = useMutation<
|
|
11
|
+
AwaitedType<typeof updateContractStatusService>,
|
|
12
|
+
Omit<UpdateContractStatusServiceProps, "cookie">
|
|
13
|
+
>(
|
|
14
|
+
(variables, clientContext) =>
|
|
15
|
+
updateContractStatusService({
|
|
16
|
+
...variables,
|
|
17
|
+
cookie: clientContext.cookie,
|
|
18
|
+
}),
|
|
19
|
+
options
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
updateContractStatus: mutate,
|
|
24
|
+
isUpdateContractStatusLoading: isLoading,
|
|
25
|
+
hasUpdateContractStatusError: error,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -12,14 +12,20 @@ import {
|
|
|
12
12
|
import { useQueryParams } from "../../../shared/hooks";
|
|
13
13
|
import { GlobalLayout } from "../../../shared/layouts";
|
|
14
14
|
import { statusFilters } from "../../../shared/utils";
|
|
15
|
+
import { useUpdateContractStatus } from "../../hooks";
|
|
16
|
+
import { useRouter } from "next/router";
|
|
15
17
|
|
|
16
18
|
export type ContractsLayoutProps = {
|
|
17
19
|
data: ContractData[];
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
export const ContractsLayout = ({ data }: ContractsLayoutProps) => {
|
|
23
|
+
const route = useRouter();
|
|
24
|
+
|
|
21
25
|
const { setQueryString, removeQueryString } = useQueryParams();
|
|
22
26
|
|
|
27
|
+
const { updateContractStatus } = useUpdateContractStatus();
|
|
28
|
+
|
|
23
29
|
return (
|
|
24
30
|
<GlobalLayout>
|
|
25
31
|
<section data-fs-contracts-section>
|
|
@@ -58,15 +64,27 @@ export const ContractsLayout = ({ data }: ContractsLayoutProps) => {
|
|
|
58
64
|
{data.map((contract) => (
|
|
59
65
|
<div key={contract.id}>
|
|
60
66
|
<div data-fs-contract-row>
|
|
61
|
-
<div
|
|
67
|
+
<div
|
|
68
|
+
data-fs-contract-row-information
|
|
69
|
+
onClick={() => {
|
|
70
|
+
route.push(`/profile/${contract.id}`);
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
62
73
|
<Icon name="Address" width={32} height={32} />
|
|
63
|
-
{contract.name}
|
|
74
|
+
{contract.name ?? contract.email}
|
|
64
75
|
</div>
|
|
65
76
|
<div data-fs-contract-row-action>
|
|
66
77
|
<Toggle
|
|
67
78
|
id="isContractActive"
|
|
68
79
|
aria-label="is contract active"
|
|
69
80
|
defaultChecked={contract.isActive}
|
|
81
|
+
onChange={(event) => {
|
|
82
|
+
event.stopPropagation();
|
|
83
|
+
updateContractStatus({
|
|
84
|
+
contractId: contract.id,
|
|
85
|
+
isActive: event.target.checked,
|
|
86
|
+
});
|
|
87
|
+
}}
|
|
70
88
|
/>
|
|
71
89
|
</div>
|
|
72
90
|
</div>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { buyerPortalClient } from "../../../clients/BuyerPortalClient";
|
|
2
|
+
|
|
3
|
+
export const getContractDetailsService = async ({
|
|
4
|
+
contractId,
|
|
5
|
+
cookie,
|
|
6
|
+
}: {
|
|
7
|
+
contractId: string;
|
|
8
|
+
cookie: string;
|
|
9
|
+
}) => {
|
|
10
|
+
const { contract } = await buyerPortalClient.getContractDetails(
|
|
11
|
+
contractId,
|
|
12
|
+
cookie
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return contract;
|
|
16
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { buyerPortalClient } from "../../../clients/BuyerPortalClient";
|
|
2
|
-
import { compareItems, statusFilters } from "../../shared/utils";
|
|
3
2
|
import type { ContractData } from "../types";
|
|
4
3
|
|
|
5
|
-
export type
|
|
4
|
+
export type GetContractsByCustomerIdServiceProps = {
|
|
6
5
|
search?: string;
|
|
7
6
|
customerId?: string;
|
|
8
7
|
status?: string;
|
|
@@ -10,13 +9,13 @@ export type GetContractsServiceProps = {
|
|
|
10
9
|
cookie: string;
|
|
11
10
|
};
|
|
12
11
|
|
|
13
|
-
export const
|
|
12
|
+
export const getContractsByCustomerIdService = async ({
|
|
14
13
|
search = "",
|
|
15
14
|
customerId,
|
|
16
15
|
status,
|
|
17
16
|
sort,
|
|
18
17
|
cookie,
|
|
19
|
-
}:
|
|
18
|
+
}: GetContractsByCustomerIdServiceProps): Promise<ContractData[]> => {
|
|
20
19
|
const contractsData: ContractData[] = [];
|
|
21
20
|
|
|
22
21
|
if (!customerId) {
|
|
@@ -27,21 +26,12 @@ export const getContractsService = async ({
|
|
|
27
26
|
const {
|
|
28
27
|
data: { contracts },
|
|
29
28
|
} = await buyerPortalClient.getContractsByCustomerId(customerId, cookie);
|
|
29
|
+
|
|
30
30
|
contractsData.push(...contracts);
|
|
31
31
|
} catch (err) {
|
|
32
32
|
console.error("Failed to fetch contracts", err);
|
|
33
33
|
return contractsData;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
return contractsData
|
|
37
|
-
.filter((contract) => {
|
|
38
|
-
const matchesName = contract.name
|
|
39
|
-
.toLowerCase()
|
|
40
|
-
.includes(search.toLowerCase());
|
|
41
|
-
const matchesStatus =
|
|
42
|
-
!status || contract.isActive === statusFilters[status];
|
|
43
|
-
|
|
44
|
-
return matchesName && matchesStatus;
|
|
45
|
-
})
|
|
46
|
-
.sort((a, b) => compareItems(a, b, sort));
|
|
36
|
+
return contractsData;
|
|
47
37
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { buyerPortalClient } from "../../../clients/BuyerPortalClient";
|
|
2
|
+
import { compareItems, statusFilters } from "../../shared/utils";
|
|
3
|
+
import type { ContractData } from "../types";
|
|
4
|
+
|
|
5
|
+
export type GetContractsByOrgUnitIdServiceProps = {
|
|
6
|
+
search?: string;
|
|
7
|
+
orgUnitId?: string;
|
|
8
|
+
status?: string;
|
|
9
|
+
sort?: string;
|
|
10
|
+
cookie: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const getContractsByOrgUnitIdService = async ({
|
|
14
|
+
search = "",
|
|
15
|
+
orgUnitId,
|
|
16
|
+
status,
|
|
17
|
+
sort,
|
|
18
|
+
cookie,
|
|
19
|
+
}: GetContractsByOrgUnitIdServiceProps): Promise<ContractData[]> => {
|
|
20
|
+
const contractsData: ContractData[] = [];
|
|
21
|
+
|
|
22
|
+
if (!orgUnitId) {
|
|
23
|
+
return contractsData;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const { contracts } = await buyerPortalClient.getContractsByOrgUnitId(
|
|
28
|
+
orgUnitId,
|
|
29
|
+
cookie
|
|
30
|
+
);
|
|
31
|
+
contractsData.push(...contracts);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.error("Failed to fetch contracts", err);
|
|
34
|
+
return contractsData;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log("Contracts Data: ", contractsData);
|
|
38
|
+
|
|
39
|
+
return contractsData;
|
|
40
|
+
};
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
} from "./get-contracts.service";
|
|
2
|
+
getContractsByCustomerIdService,
|
|
3
|
+
type GetContractsByCustomerIdServiceProps,
|
|
4
|
+
} from "./get-contracts-by-customer-id.service";
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
getContractsByOrgUnitIdService,
|
|
8
|
+
type GetContractsByOrgUnitIdServiceProps,
|
|
9
|
+
} from "./get-contracts-org-by-unit-id.service";
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
updateContractStatusService,
|
|
13
|
+
UpdateContractStatusServiceProps,
|
|
14
|
+
} from "./update-contract-status.service";
|
|
15
|
+
|
|
16
|
+
export { getContractDetailsService } from "./get-contract-details.service";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { buyerPortalClient } from "../../../clients/BuyerPortalClient";
|
|
2
|
+
|
|
3
|
+
export type UpdateContractStatusServiceProps = {
|
|
4
|
+
contractId: string;
|
|
5
|
+
isActive: boolean;
|
|
6
|
+
cookie: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const updateContractStatusService = async ({
|
|
10
|
+
contractId,
|
|
11
|
+
isActive,
|
|
12
|
+
cookie,
|
|
13
|
+
}: UpdateContractStatusServiceProps): Promise<null> => {
|
|
14
|
+
try {
|
|
15
|
+
const data = await buyerPortalClient.updateContractStatus(
|
|
16
|
+
{ contractId, isActive },
|
|
17
|
+
cookie
|
|
18
|
+
);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
console.error("Failed to fetch contracts", err);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
Icon,
|
|
12
12
|
} from "../../../shared/components";
|
|
13
13
|
import { useCreateNewOrgUnit } from "../../hooks";
|
|
14
|
+
import type { createNewOrgUnitService } from "../../services";
|
|
14
15
|
|
|
15
16
|
export type CreateOrgUnitDrawerProps = Omit<BasicDrawerProps, "children"> & {
|
|
16
17
|
options?: { id: string; name: string }[];
|
|
@@ -35,10 +36,21 @@ export const CreateOrgUnitDrawer = ({
|
|
|
35
36
|
|
|
36
37
|
const [isTouched, setIsTouched] = useState(false);
|
|
37
38
|
|
|
38
|
-
const handleCreateNewOrgUnitSuccess = (
|
|
39
|
+
const handleCreateNewOrgUnitSuccess = (
|
|
40
|
+
data: AwaitedType<typeof createNewOrgUnitService>
|
|
41
|
+
) => {
|
|
39
42
|
pushToast({
|
|
40
43
|
message: "Organizational unit added successfully",
|
|
41
44
|
status: "INFO",
|
|
45
|
+
icon: (
|
|
46
|
+
<button
|
|
47
|
+
data-fs-bp-toast-view-button
|
|
48
|
+
type="button"
|
|
49
|
+
onClick={() => router.push(`/org-unit/${data.id}`)}
|
|
50
|
+
>
|
|
51
|
+
View
|
|
52
|
+
</button>
|
|
53
|
+
),
|
|
42
54
|
});
|
|
43
55
|
close();
|
|
44
56
|
router.replace(router.asPath);
|