@vtex/faststore-plugin-buyer-portal 2.0.46 → 2.0.48
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/src/features/accounting-fields/components/AccountingFieldDropdown/AccountingFieldDropdown.tsx +5 -2
- package/src/features/contracts/layouts/ContractListingLayout/ContractListingLayout.tsx +117 -109
- package/src/features/contracts/layouts/ContractListingLayout/contract-listing-layout.scss +79 -61
- package/src/features/shared/components/VerticalNav/VerticalNavLink.tsx +3 -10
- package/src/features/shared/components/VerticalNav/VerticalNavTree.tsx +5 -30
- package/src/features/shared/components/VerticalNav/vertical-nav.scss +42 -29
- package/src/features/shared/hooks/index.ts +1 -0
- package/src/features/shared/hooks/useDropdownAlign.ts +27 -0
- package/src/features/shared/layouts/ContractTabsLayout/ContractTabsLayout.tsx +2 -2
- package/src/features/shared/layouts/SumaPageLayout/FullSidebarNav.tsx +0 -1
- package/src/features/shared/layouts/SumaPageLayout/SumaPageLayout.tsx +2 -2
- package/src/features/shared/layouts/SumaPageLayout/SumaSidebar.tsx +15 -39
- package/src/features/shared/types/VerticalNav.ts +0 -1
- package/src/features/shared/utils/__tests__/getDropdownAlign.test.ts +17 -0
- package/src/features/shared/utils/__tests__/isNavLinkActive.test.ts +117 -0
- package/src/features/shared/utils/constants.ts +1 -1
- package/src/features/shared/utils/getDropdownAlign.ts +11 -0
- package/src/features/shared/utils/isNavLinkActive.ts +40 -0
- package/src/features/users/components/CreateUserDrawerWithUsername/CreateUserDrawerWithUsername.tsx +8 -9
- package/src/features/users/utils/__tests__/resolveAccessCodeRecipient.test.ts +38 -0
- package/src/features/users/utils/resolveAccessCodeRecipient.ts +26 -0
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "@faststore/ui";
|
|
9
9
|
|
|
10
10
|
import { BasicDropdownMenu, Icon } from "../../../shared/components";
|
|
11
|
-
import { useDrawerProps } from "../../../shared/hooks";
|
|
11
|
+
import { useDrawerProps, useDropdownAlign } from "../../../shared/hooks";
|
|
12
12
|
import { useLocalization } from "../../../shared/localization/LocalizationContext";
|
|
13
13
|
import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
|
|
14
14
|
import { CreateAccountingValueDrawer } from "../CreateAccountingValueDrawer/CreateAccountingValueDrawer";
|
|
@@ -34,6 +34,7 @@ export const AccountingFieldDropdown = ({
|
|
|
34
34
|
}: AccountingFieldDropdownProps) => {
|
|
35
35
|
const { t } = useLocalization();
|
|
36
36
|
const router = useRouter();
|
|
37
|
+
const { align, updateAlign } = useDropdownAlign();
|
|
37
38
|
const route = buyerPortalRoutes.accountingFields({
|
|
38
39
|
orgUnitId,
|
|
39
40
|
contractId,
|
|
@@ -76,10 +77,12 @@ export const AccountingFieldDropdown = ({
|
|
|
76
77
|
<DropdownButton asChild>
|
|
77
78
|
<IconButton
|
|
78
79
|
aria-label="toggle accounting dropdown"
|
|
80
|
+
onPointerDown={updateAlign}
|
|
81
|
+
onKeyDown={updateAlign}
|
|
79
82
|
icon={<Icon name="MoreVert" width={ICON_SIZE} height={ICON_SIZE} />}
|
|
80
83
|
/>
|
|
81
84
|
</DropdownButton>
|
|
82
|
-
<BasicDropdownMenu>
|
|
85
|
+
<BasicDropdownMenu align={align}>
|
|
83
86
|
<DropdownItem onClick={openCreateAccountingValueDrawer}>
|
|
84
87
|
<Icon name="Add" width={ICON_SIZE} height={ICON_SIZE} />
|
|
85
88
|
{t("accountingFields.dropdown.addValues")}
|
|
@@ -358,121 +358,129 @@ export const ContractListingLayout = ({
|
|
|
358
358
|
|
|
359
359
|
return (
|
|
360
360
|
<GlobalLayout>
|
|
361
|
-
<
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
<div data-fs-bp-contract-listing-body>
|
|
372
|
-
<SumaSidebar
|
|
373
|
-
orgUnitId={orgUnit.id}
|
|
374
|
-
contractId={defaultContractId}
|
|
375
|
-
variant="unit"
|
|
361
|
+
<div data-fs-bp-contract-listing-page>
|
|
362
|
+
<OrgUnitDetailsNavbar
|
|
363
|
+
orgId={orgUnit.id}
|
|
364
|
+
contractId=""
|
|
365
|
+
person={{
|
|
366
|
+
name: user?.name ?? "",
|
|
367
|
+
email: user?.email ?? "",
|
|
368
|
+
}}
|
|
369
|
+
loading={loading}
|
|
370
|
+
sidebarVariant="unit"
|
|
376
371
|
/>
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
)}
|
|
390
|
-
</HeaderInside>
|
|
391
|
-
|
|
392
|
-
{loading ? (
|
|
393
|
-
// Route-transition skeleton (LoadingTabsLayout): the destination
|
|
394
|
-
// is the multi-contract listing, so mirror its rows.
|
|
395
|
-
<ContractSelectionListSkeleton />
|
|
396
|
-
) : isSingleContract ? (
|
|
397
|
-
<BasicCard
|
|
398
|
-
data-fs-bp-contracts-settings-card
|
|
399
|
-
footerMessage={t("orgUnitDetails.links.manageContractSettings")}
|
|
400
|
-
footerLink={contractScopedLink(buyerPortalRoutes.profileDetails, {
|
|
401
|
-
orgUnitId: orgUnit.id,
|
|
402
|
-
contractId: defaultContractId,
|
|
403
|
-
})}
|
|
404
|
-
enableFooter
|
|
372
|
+
<div data-fs-bp-contract-listing-body>
|
|
373
|
+
<SumaSidebar
|
|
374
|
+
orgUnitId={orgUnit.id}
|
|
375
|
+
contractId={defaultContractId}
|
|
376
|
+
variant="unit"
|
|
377
|
+
/>
|
|
378
|
+
|
|
379
|
+
<section data-fs-bp-contract-listing-section aria-busy={isBusy}>
|
|
380
|
+
<HeaderInside
|
|
381
|
+
title={loading ? undefined : t("contracts.titles.contracts")}
|
|
382
|
+
info={loading ? undefined : headerInfo}
|
|
383
|
+
data-fs-bp-contract-listing-header
|
|
405
384
|
>
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
385
|
+
{featureFlags?.suma && !loading && (
|
|
386
|
+
<HeaderInside.Button
|
|
387
|
+
onClick={openAddContractsDrawer}
|
|
388
|
+
aria-label="Add contracts"
|
|
389
|
+
/>
|
|
390
|
+
)}
|
|
391
|
+
</HeaderInside>
|
|
392
|
+
|
|
393
|
+
{loading ? (
|
|
394
|
+
// Route-transition skeleton (LoadingTabsLayout): the destination
|
|
395
|
+
// is the multi-contract listing, so mirror its rows.
|
|
396
|
+
<ContractSelectionListSkeleton />
|
|
397
|
+
) : isSingleContract ? (
|
|
398
|
+
<BasicCard
|
|
399
|
+
data-fs-bp-contracts-settings-card
|
|
400
|
+
footerMessage={t("orgUnitDetails.links.manageContractSettings")}
|
|
401
|
+
footerLink={contractScopedLink(
|
|
402
|
+
buyerPortalRoutes.profileDetails,
|
|
403
|
+
{
|
|
404
|
+
orgUnitId: orgUnit.id,
|
|
405
|
+
contractId: defaultContractId,
|
|
406
|
+
}
|
|
407
|
+
)}
|
|
408
|
+
enableFooter
|
|
409
|
+
>
|
|
410
|
+
<LetterHighlight letter={displayName} />
|
|
411
|
+
<VerticalNav.Menu title={displayName} loading={isBusy}>
|
|
412
|
+
{isBusy ? (
|
|
413
|
+
[...new Array(8)].map((_, index) => (
|
|
414
|
+
<li
|
|
415
|
+
style={{ padding: "8px 0" }}
|
|
416
|
+
key={`skeleton-${index}`}
|
|
417
|
+
>
|
|
418
|
+
<Skeleton
|
|
419
|
+
size={{
|
|
420
|
+
width: "100%",
|
|
421
|
+
height: "2.5rem",
|
|
422
|
+
}}
|
|
423
|
+
/>
|
|
424
|
+
</li>
|
|
425
|
+
))
|
|
426
|
+
) : (
|
|
427
|
+
<VerticalNav.Tree
|
|
428
|
+
items={buildContractSettingsNavItems({
|
|
429
|
+
orgUnitId: orgUnit.id,
|
|
430
|
+
contractId: defaultContractId,
|
|
431
|
+
accountingFields: listAccountingFieldData ?? [],
|
|
432
|
+
accountingFieldsLoading: listAccountingFieldLoading,
|
|
433
|
+
onAddAccountingField: openAccountingFieldDrawer,
|
|
434
|
+
onAccountingFieldChange: listAccountingFieldRefresh,
|
|
435
|
+
t,
|
|
436
|
+
featureFlags,
|
|
437
|
+
})}
|
|
438
|
+
/>
|
|
439
|
+
)}
|
|
440
|
+
</VerticalNav.Menu>
|
|
441
|
+
</BasicCard>
|
|
442
|
+
) : (
|
|
443
|
+
<>
|
|
444
|
+
<ContractsListHeader
|
|
445
|
+
searchTerm={searchTerm}
|
|
446
|
+
onSearch={setSearch}
|
|
447
|
+
from={from}
|
|
448
|
+
to={to}
|
|
449
|
+
total={total}
|
|
450
|
+
hasPrev={hasPrev}
|
|
451
|
+
hasNext={hasNext}
|
|
452
|
+
onPrev={prevPage}
|
|
453
|
+
onNext={nextPage}
|
|
454
|
+
/>
|
|
455
|
+
<ContractSelectAllRow
|
|
456
|
+
total={total}
|
|
457
|
+
selectedCount={selectedInFiltered}
|
|
458
|
+
onToggle={handleToggleSelectAll}
|
|
459
|
+
/>
|
|
460
|
+
{isRefreshing ? (
|
|
461
|
+
<ContractSelectionListSkeleton
|
|
462
|
+
rows={Math.max(pageItems.length, 3)}
|
|
463
|
+
/>
|
|
419
464
|
) : (
|
|
420
|
-
<
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
t,
|
|
429
|
-
featureFlags,
|
|
430
|
-
})}
|
|
465
|
+
<ContractSelectionList
|
|
466
|
+
contracts={pageItems}
|
|
467
|
+
orgUnitId={orgUnit.id}
|
|
468
|
+
selectedIds={selectedIds}
|
|
469
|
+
onKeyDown={handleKeyDown}
|
|
470
|
+
onSelect={handleSelect}
|
|
471
|
+
onItemRemove={handleItemRemove}
|
|
472
|
+
onSetDefault={handleSetDefault}
|
|
431
473
|
/>
|
|
432
474
|
)}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
<ContractsListHeader
|
|
438
|
-
searchTerm={searchTerm}
|
|
439
|
-
onSearch={setSearch}
|
|
440
|
-
from={from}
|
|
441
|
-
to={to}
|
|
442
|
-
total={total}
|
|
443
|
-
hasPrev={hasPrev}
|
|
444
|
-
hasNext={hasNext}
|
|
445
|
-
onPrev={prevPage}
|
|
446
|
-
onNext={nextPage}
|
|
447
|
-
/>
|
|
448
|
-
<ContractSelectAllRow
|
|
449
|
-
total={total}
|
|
450
|
-
selectedCount={selectedInFiltered}
|
|
451
|
-
onToggle={handleToggleSelectAll}
|
|
452
|
-
/>
|
|
453
|
-
{isRefreshing ? (
|
|
454
|
-
<ContractSelectionListSkeleton
|
|
455
|
-
rows={Math.max(pageItems.length, 3)}
|
|
475
|
+
<ContractSelectionBar
|
|
476
|
+
selectedCount={selectedIds.size}
|
|
477
|
+
onClear={clearSelection}
|
|
478
|
+
onRemove={() => handleRequestRemove()}
|
|
456
479
|
/>
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
selectedIds={selectedIds}
|
|
462
|
-
onKeyDown={handleKeyDown}
|
|
463
|
-
onSelect={handleSelect}
|
|
464
|
-
onItemRemove={handleItemRemove}
|
|
465
|
-
onSetDefault={handleSetDefault}
|
|
466
|
-
/>
|
|
467
|
-
)}
|
|
468
|
-
<ContractSelectionBar
|
|
469
|
-
selectedCount={selectedIds.size}
|
|
470
|
-
onClear={clearSelection}
|
|
471
|
-
onRemove={() => handleRequestRemove()}
|
|
472
|
-
/>
|
|
473
|
-
</>
|
|
474
|
-
)}
|
|
475
|
-
</section>
|
|
480
|
+
</>
|
|
481
|
+
)}
|
|
482
|
+
</section>
|
|
483
|
+
</div>
|
|
476
484
|
</div>
|
|
477
485
|
|
|
478
486
|
{isAccountingFieldDrawerOpen && (
|
|
@@ -13,62 +13,104 @@
|
|
|
13
13
|
@import "../../components/AddContractsDrawer/add-contracts-drawer.scss";
|
|
14
14
|
@import "../../components/ConfirmRemoveDrawer/confirm-remove-drawer.scss";
|
|
15
15
|
|
|
16
|
+
// Full viewport height, so the sidebar divider reaches the bottom on short pages
|
|
17
|
+
[data-fs-bp-contract-listing-page] {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
min-height: 100vh;
|
|
21
|
+
min-height: 100dvh;
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
[data-fs-bp-contract-listing-body] {
|
|
17
25
|
display: grid;
|
|
26
|
+
flex: 1 0 auto;
|
|
18
27
|
grid-template-columns: 1fr;
|
|
19
28
|
width: 100%;
|
|
20
|
-
max-width: 90rem;
|
|
21
|
-
margin: var(--fs-bp-margin-0) var(--fs-bp-margin-auto);
|
|
22
29
|
|
|
23
30
|
@include u.media(">=notebook") {
|
|
24
31
|
grid-template-columns: 20rem 1fr;
|
|
25
32
|
}
|
|
33
|
+
|
|
34
|
+
> [data-fs-bp-contract-listing-sidebar] {
|
|
35
|
+
@include u.media(">=notebook") {
|
|
36
|
+
position: sticky;
|
|
37
|
+
top: 0;
|
|
38
|
+
align-self: start;
|
|
39
|
+
width: 20rem;
|
|
40
|
+
min-width: 20rem;
|
|
41
|
+
max-height: 100vh;
|
|
42
|
+
max-height: 100dvh;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
26
45
|
}
|
|
27
46
|
|
|
28
47
|
[data-fs-bp-contract-listing-sidebar] {
|
|
29
48
|
@import "../../../shared/components/VerticalNav/vertical-nav.scss";
|
|
30
49
|
@import "../../../shared/components/LetterHighlight/letter-highlight.scss";
|
|
31
50
|
|
|
51
|
+
// This padding plus the items' own inset matches the header's side
|
|
52
|
+
// padding, so the item text lines up with the logo.
|
|
32
53
|
display: none;
|
|
33
|
-
padding: var(--fs-bp-padding-5)
|
|
34
|
-
border-right: 1px solid var(--fs-bp-color-neutral-2);
|
|
54
|
+
padding: var(--fs-bp-padding-5);
|
|
35
55
|
overflow-y: auto;
|
|
36
56
|
|
|
37
57
|
@include u.media(">=notebook") {
|
|
38
58
|
display: block;
|
|
39
59
|
}
|
|
40
60
|
|
|
41
|
-
[data-fs-bp-
|
|
61
|
+
// [href] outranks BasicDrawer's "[data-fs-bp-basic-drawer-body] a" color,
|
|
62
|
+
// which otherwise turns the link blue when the sidebar opens in the drawer.
|
|
63
|
+
a[data-fs-bp-contract-listing-back-link][href] {
|
|
42
64
|
display: inline-flex;
|
|
43
65
|
align-items: center;
|
|
44
|
-
gap: var(--fs-bp-gap-
|
|
45
|
-
|
|
46
|
-
|
|
66
|
+
gap: var(--fs-bp-gap-1);
|
|
67
|
+
min-height: var(--fs-bp-spacing-9);
|
|
68
|
+
margin: var(--fs-bp-margin-0) var(--fs-bp-margin-5) var(--fs-bp-margin-5);
|
|
69
|
+
font-size: var(--fs-bp-text-size-0);
|
|
70
|
+
font-weight: var(--fs-bp-weight-medium);
|
|
71
|
+
line-height: var(--fs-bp-line-height-base);
|
|
72
|
+
color: var(--fs-bp-color-neutral-7);
|
|
47
73
|
text-decoration: none;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
74
|
+
transition: color var(--fs-transition-timing) var(--fs-transition-function),
|
|
75
|
+
transform var(--fs-transition-timing) var(--fs-transition-function);
|
|
76
|
+
|
|
77
|
+
[data-fs-icon] {
|
|
78
|
+
transform: rotate(180deg);
|
|
79
|
+
transition: transform var(--fs-transition-timing)
|
|
80
|
+
var(--fs-transition-function);
|
|
81
|
+
}
|
|
51
82
|
|
|
52
83
|
&:hover {
|
|
53
|
-
|
|
84
|
+
color: var(--fs-bp-color-brand);
|
|
85
|
+
|
|
86
|
+
// The icon is rotated, so +x moves the chevron left
|
|
87
|
+
[data-fs-icon] {
|
|
88
|
+
transform: rotate(180deg) translateX(var(--fs-border-width-thick));
|
|
89
|
+
}
|
|
54
90
|
}
|
|
55
91
|
|
|
56
|
-
|
|
57
|
-
transform:
|
|
92
|
+
&:active {
|
|
93
|
+
transform: scale(0.95);
|
|
58
94
|
}
|
|
59
95
|
}
|
|
60
96
|
|
|
61
97
|
[data-fs-bp-suma-sidebar-identity] {
|
|
62
|
-
|
|
98
|
+
display: flex;
|
|
99
|
+
flex-direction: column;
|
|
100
|
+
padding: var(--fs-bp-padding-0) var(--fs-bp-padding-5);
|
|
63
101
|
margin-bottom: var(--fs-bp-margin-5);
|
|
64
102
|
|
|
65
103
|
[data-fs-bp-letter-highlight] {
|
|
66
|
-
background-color:
|
|
104
|
+
background-color: var(--fs-bp-color-black);
|
|
67
105
|
color: var(--fs-bp-color-white);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
106
|
+
// 52px: no single token, so spacing-10 (48px) + spacing-1 (4px).
|
|
107
|
+
width: calc(var(--fs-bp-spacing-10) + var(--fs-bp-spacing-1));
|
|
108
|
+
height: calc(var(--fs-bp-spacing-10) + var(--fs-bp-spacing-1));
|
|
109
|
+
// 18px: text-size-2 (16px) plus FastStore's mobile type-scale step (2px)
|
|
110
|
+
font-size: calc(var(--fs-bp-text-size-2) + var(--fs-text-scale-mobile));
|
|
111
|
+
font-weight: var(--fs-bp-weight-semibold);
|
|
112
|
+
margin-bottom: var(--fs-bp-margin-3);
|
|
113
|
+
box-shadow: var(--fs-shadow-hover);
|
|
72
114
|
}
|
|
73
115
|
|
|
74
116
|
[data-fs-bp-suma-sidebar-identity-row] {
|
|
@@ -77,26 +119,18 @@
|
|
|
77
119
|
gap: var(--fs-bp-gap-3);
|
|
78
120
|
|
|
79
121
|
[data-fs-bp-suma-sidebar-identity-name] {
|
|
80
|
-
|
|
81
|
-
font-weight: var(--fs-bp-weight-
|
|
122
|
+
font-size: calc(var(--fs-bp-text-size-2) + var(--fs-text-scale-mobile));
|
|
123
|
+
font-weight: var(--fs-bp-weight-semibold);
|
|
124
|
+
line-height: var(--fs-bp-line-height-base);
|
|
82
125
|
color: var(--fs-bp-color-black);
|
|
83
|
-
|
|
84
|
-
overflow:
|
|
85
|
-
text-overflow: ellipsis;
|
|
126
|
+
min-width: 0;
|
|
127
|
+
overflow-wrap: anywhere;
|
|
86
128
|
}
|
|
87
129
|
|
|
88
130
|
[data-fs-bp-suma-sidebar-identity-default] {
|
|
89
131
|
flex-shrink: 0;
|
|
90
132
|
color: var(--fs-bp-color-brand);
|
|
91
133
|
}
|
|
92
|
-
|
|
93
|
-
[data-fs-bp-suma-sidebar-identity-contract] {
|
|
94
|
-
@include text-style("body");
|
|
95
|
-
color: var(--fs-bp-color-neutral-8);
|
|
96
|
-
white-space: nowrap;
|
|
97
|
-
overflow: hidden;
|
|
98
|
-
text-overflow: ellipsis;
|
|
99
|
-
}
|
|
100
134
|
}
|
|
101
135
|
}
|
|
102
136
|
|
|
@@ -117,22 +151,6 @@
|
|
|
117
151
|
|
|
118
152
|
[data-fs-vertical-nav-menu-list] {
|
|
119
153
|
margin-top: var(--fs-bp-margin-0);
|
|
120
|
-
@include text-style("emphasis");
|
|
121
|
-
color: var(--fs-bp-color-black);
|
|
122
|
-
|
|
123
|
-
[data-fs-vertical-nav-menu-link],
|
|
124
|
-
[data-fs-bp-vertical-submenu-title] {
|
|
125
|
-
@include text-style("emphasis");
|
|
126
|
-
color: var(--fs-bp-color-neutral-9);
|
|
127
|
-
|
|
128
|
-
@include u.media(">=tablet") {
|
|
129
|
-
color: var(--fs-bp-color-neutral-8);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
[data-fs-bp-vertical-submenu-title] {
|
|
134
|
-
color: #858585;
|
|
135
|
-
}
|
|
136
154
|
}
|
|
137
155
|
}
|
|
138
156
|
}
|
|
@@ -140,21 +158,18 @@
|
|
|
140
158
|
&[data-fs-bp-suma-sidebar-variant="unit"] {
|
|
141
159
|
[data-fs-vertical-nav-menu-list] {
|
|
142
160
|
margin-top: var(--fs-bp-margin-0);
|
|
143
|
-
@include text-style("emphasis");
|
|
144
|
-
|
|
145
|
-
[data-fs-vertical-nav-menu-link] {
|
|
146
|
-
@include text-style("emphasis");
|
|
147
|
-
color: var(--fs-bp-color-neutral-9);
|
|
148
|
-
|
|
149
|
-
@include u.media(">=tablet") {
|
|
150
|
-
color: var(--fs-bp-color-neutral-8);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
161
|
}
|
|
154
162
|
}
|
|
155
163
|
|
|
156
|
-
|
|
157
|
-
|
|
164
|
+
@media (prefers-reduced-motion: reduce) {
|
|
165
|
+
a[data-fs-bp-contract-listing-back-link][href],
|
|
166
|
+
a[data-fs-bp-contract-listing-back-link][href] [data-fs-icon] {
|
|
167
|
+
transition: none;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
a[data-fs-bp-contract-listing-back-link][href]:active {
|
|
171
|
+
transform: none;
|
|
172
|
+
}
|
|
158
173
|
}
|
|
159
174
|
}
|
|
160
175
|
|
|
@@ -174,9 +189,12 @@
|
|
|
174
189
|
padding-right: var(--fs-bp-padding-10);
|
|
175
190
|
}
|
|
176
191
|
|
|
192
|
+
// The divider lives on the section, not the sticky sidebar, so it spans the
|
|
193
|
+
// full body height.
|
|
177
194
|
@include u.media(">=notebook") {
|
|
178
195
|
padding-left: var(--fs-bp-padding-12);
|
|
179
196
|
padding-right: var(--fs-bp-padding-12);
|
|
197
|
+
border-left: var(--fs-border-width) solid var(--fs-bp-color-neutral-3);
|
|
180
198
|
}
|
|
181
199
|
|
|
182
200
|
[data-fs-bp-contracts-settings-card] {
|
|
@@ -5,21 +5,14 @@ import { useRouter } from "next/router";
|
|
|
5
5
|
import { useLink_unstable as useLink } from "@faststore/core/experimental";
|
|
6
6
|
import { Link } from "@faststore/ui";
|
|
7
7
|
|
|
8
|
+
import { isNavLinkActive } from "../../utils/isNavLinkActive";
|
|
9
|
+
|
|
8
10
|
export type VerticalNavLinkProps = {
|
|
9
11
|
children: ReactNode;
|
|
10
12
|
link: string;
|
|
11
13
|
depth?: number;
|
|
12
14
|
};
|
|
13
15
|
|
|
14
|
-
function isActiveLink(asPath: string, link: string) {
|
|
15
|
-
const normalizedLink = link.startsWith("/") ? link : link.slice(0, -1);
|
|
16
|
-
return (
|
|
17
|
-
asPath === normalizedLink ||
|
|
18
|
-
asPath.startsWith(normalizedLink + "/") ||
|
|
19
|
-
asPath.startsWith(normalizedLink + "?")
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
16
|
export const VerticalNavLink = ({
|
|
24
17
|
link,
|
|
25
18
|
children,
|
|
@@ -29,7 +22,7 @@ export const VerticalNavLink = ({
|
|
|
29
22
|
const { resolveLink } = useLink();
|
|
30
23
|
const resolvedLink = resolveLink(link);
|
|
31
24
|
|
|
32
|
-
const isActive =
|
|
25
|
+
const isActive = isNavLinkActive(asPath, link);
|
|
33
26
|
|
|
34
27
|
return (
|
|
35
28
|
<li key={resolvedLink} data-fs-vertical-nav-menu-item>
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { IconButton } from "@faststore/ui";
|
|
1
|
+
import type { MouseEvent } from "react";
|
|
4
2
|
|
|
5
3
|
import { Icon } from "../Icon";
|
|
6
4
|
|
|
@@ -22,24 +20,11 @@ const VerticalNavTreeItem = ({
|
|
|
22
20
|
link,
|
|
23
21
|
submenu,
|
|
24
22
|
actions,
|
|
25
|
-
collapsible = false,
|
|
26
23
|
depth = 0,
|
|
27
24
|
hasNotification = false,
|
|
28
25
|
loading = false,
|
|
29
26
|
}: VerticalNavTreeItemProps) => {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const onClickToggleBtn = (e: React.MouseEvent) => {
|
|
33
|
-
e.preventDefault();
|
|
34
|
-
|
|
35
|
-
if (!collapsible) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
setIsOpen(!isOpen);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const handleActionsClick = (e: React.MouseEvent) => e.preventDefault();
|
|
27
|
+
const handleActionsClick = (e: MouseEvent) => e.preventDefault();
|
|
43
28
|
|
|
44
29
|
return !Array.isArray(submenu?.items) ? (
|
|
45
30
|
<VerticalNav.Link link={link ?? ""} depth={depth}>
|
|
@@ -56,14 +41,6 @@ const VerticalNavTreeItem = ({
|
|
|
56
41
|
) : (
|
|
57
42
|
<li>
|
|
58
43
|
<div data-fs-bp-vertical-submenu-title>
|
|
59
|
-
{submenu.items.length > 0 && collapsible && (
|
|
60
|
-
<IconButton
|
|
61
|
-
aria-label="toggle vertical submenu"
|
|
62
|
-
data-fs-bp-vertical-submenu-toggle={isOpen}
|
|
63
|
-
icon={<Icon name="ArrowRight" width={20} height={20} />}
|
|
64
|
-
onClick={onClickToggleBtn}
|
|
65
|
-
/>
|
|
66
|
-
)}
|
|
67
44
|
{name}
|
|
68
45
|
{hasNotification && (
|
|
69
46
|
<span data-fs-bp-vertical-item-has-notification></span>
|
|
@@ -85,11 +62,9 @@ const VerticalNavTreeItem = ({
|
|
|
85
62
|
</div>
|
|
86
63
|
)}
|
|
87
64
|
</div>
|
|
88
|
-
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
</ul>
|
|
92
|
-
)}
|
|
65
|
+
<ul>
|
|
66
|
+
<VerticalNavTree items={submenu.items} depth={depth + 1} />
|
|
67
|
+
</ul>
|
|
93
68
|
</li>
|
|
94
69
|
);
|
|
95
70
|
};
|
|
@@ -31,12 +31,17 @@
|
|
|
31
31
|
width: 100%;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
li + li,
|
|
35
|
+
li > ul {
|
|
36
|
+
margin-top: var(--fs-border-width-thick);
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
[data-fs-vertical-nav-menu-link],
|
|
35
40
|
[data-fs-bp-vertical-submenu-title] {
|
|
36
41
|
display: flex;
|
|
37
42
|
text-decoration: none;
|
|
38
43
|
@include text-style('emphasis');
|
|
39
|
-
color: var(--fs-bp-color-neutral-
|
|
44
|
+
color: var(--fs-bp-color-neutral-7);
|
|
40
45
|
padding: var(--fs-bp-padding-1) var(--fs-bp-padding-5);
|
|
41
46
|
width: 21.25rem;
|
|
42
47
|
min-height: var(--fs-bp-spacing-9);
|
|
@@ -46,10 +51,19 @@
|
|
|
46
51
|
align-items: center;
|
|
47
52
|
position: relative;
|
|
48
53
|
gap: var(--fs-bp-gap-1);
|
|
54
|
+
transition:
|
|
55
|
+
background-color var(--fs-transition-timing) var(--fs-transition-function),
|
|
56
|
+
color var(--fs-transition-timing) var(--fs-transition-function);
|
|
49
57
|
|
|
50
|
-
&:
|
|
58
|
+
&:has([data-fs-bp-vertical-nav-link-actions]) {
|
|
59
|
+
padding-right: var(--fs-bp-padding-1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&:hover,
|
|
63
|
+
&:focus-within {
|
|
51
64
|
[data-fs-bp-vertical-nav-link-actions] {
|
|
52
65
|
visibility: visible;
|
|
66
|
+
opacity: 1;
|
|
53
67
|
}
|
|
54
68
|
}
|
|
55
69
|
|
|
@@ -67,10 +81,15 @@
|
|
|
67
81
|
gap: var(--fs-bp-gap-2);
|
|
68
82
|
margin-left: auto;
|
|
69
83
|
visibility: hidden;
|
|
84
|
+
opacity: 0;
|
|
85
|
+
transition:
|
|
86
|
+
opacity var(--fs-transition-timing) var(--fs-transition-function),
|
|
87
|
+
visibility var(--fs-transition-timing) var(--fs-transition-function);
|
|
70
88
|
|
|
71
89
|
&:has([data-fs-button][aria-expanded="true"]),
|
|
72
90
|
&[data-fs-bp-vertical-nav-link-loading] {
|
|
73
91
|
visibility: visible;
|
|
92
|
+
opacity: 1;
|
|
74
93
|
}
|
|
75
94
|
}
|
|
76
95
|
|
|
@@ -79,31 +98,16 @@
|
|
|
79
98
|
}
|
|
80
99
|
|
|
81
100
|
[data-fs-button][data-fs-icon-button=true] {
|
|
82
|
-
--fs-button-height: var(--fs-bp-spacing-
|
|
101
|
+
--fs-button-height: var(--fs-bp-spacing-8);
|
|
83
102
|
--fs-button-border-radius: var(--fs-bp-border-radius-full);
|
|
103
|
+
// One step darker than the item's hover/active background
|
|
104
|
+
--fs-button-tertiary-bkg-color-hover: var(--fs-bp-color-neutral-2);
|
|
84
105
|
|
|
85
106
|
svg {
|
|
86
107
|
color: var(--fs-bp-color-neutral-8);
|
|
87
108
|
}
|
|
88
109
|
}
|
|
89
110
|
|
|
90
|
-
[data-fs-bp-vertical-submenu-toggle] {
|
|
91
|
-
margin-left: calc(-1 * var(--fs-bp-margin-8));
|
|
92
|
-
|
|
93
|
-
&[data-fs-button][data-fs-icon-button=true] {
|
|
94
|
-
svg {
|
|
95
|
-
transition: all 0.2s;
|
|
96
|
-
color: var(--fs-bp-color-neutral-7);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
&[data-fs-bp-vertical-submenu-toggle="true"] {
|
|
101
|
-
svg {
|
|
102
|
-
transform: rotate(90deg);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
111
|
[data-fs-bp-vertical-item-has-notification] {
|
|
108
112
|
flex: 0 0 auto;
|
|
109
113
|
width: 0.438rem; // 7px
|
|
@@ -126,22 +130,16 @@
|
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
[data-fs-vertical-nav-menu-link] {
|
|
133
|
+
// Stays highlighted while the pointer is on the item's action button
|
|
129
134
|
&:hover {
|
|
130
135
|
background-color: var(--fs-bp-color-neutral-1);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
@include u.media(">=tablet") {
|
|
134
136
|
color: var(--fs-bp-color-neutral-8);
|
|
135
137
|
}
|
|
136
|
-
|
|
137
|
-
&:has([data-fs-bp-vertical-nav-link-actions]:hover),
|
|
138
|
-
&:has([data-fs-bp-vertical-submenu-toggle]:hover) {
|
|
139
|
-
background-color: transparent;
|
|
140
|
-
}
|
|
141
138
|
}
|
|
142
139
|
|
|
143
140
|
[data-fs-vertical-nav-menu-link-is-active="true"] {
|
|
144
141
|
background-color: var(--fs-bp-color-neutral-1);
|
|
142
|
+
color: var(--fs-bp-color-neutral-8);
|
|
145
143
|
}
|
|
146
144
|
|
|
147
145
|
&:first-child {
|
|
@@ -149,7 +147,22 @@
|
|
|
149
147
|
}
|
|
150
148
|
|
|
151
149
|
[data-fs-bp-vertical-submenu-title] {
|
|
152
|
-
color:
|
|
150
|
+
color: var(--fs-bp-color-neutral-5);
|
|
151
|
+
// Same inset as the items' action button, so "+" and "..." line up
|
|
152
|
+
padding-right: var(--fs-bp-padding-1);
|
|
153
|
+
|
|
154
|
+
// The group's add action stays visible, like the prototype's "+"
|
|
155
|
+
> [data-fs-bp-vertical-nav-link-actions] {
|
|
156
|
+
visibility: visible;
|
|
157
|
+
opacity: 1;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@media (prefers-reduced-motion: reduce) {
|
|
163
|
+
[data-fs-vertical-nav-menu-link],
|
|
164
|
+
[data-fs-bp-vertical-nav-link-actions] {
|
|
165
|
+
transition: none;
|
|
153
166
|
}
|
|
154
167
|
}
|
|
155
168
|
}
|
|
@@ -9,6 +9,7 @@ export {
|
|
|
9
9
|
export { useQuery, type QueryOptions } from "./useQuery";
|
|
10
10
|
export { useQueryParams } from "./useQueryParams";
|
|
11
11
|
export { useDebounce } from "./useDebounce";
|
|
12
|
+
export { useDropdownAlign } from "./useDropdownAlign";
|
|
12
13
|
export { useAddToScope } from "./useAddToScope";
|
|
13
14
|
export { useRemoveFromScope } from "./useRemoveFromScope";
|
|
14
15
|
export { usePageItems, type UsePageItemsProps } from "./usePageItems";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCallback, useState, type SyntheticEvent } from "react";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getDropdownAlign,
|
|
5
|
+
type DropdownAlign,
|
|
6
|
+
} from "../utils/getDropdownAlign";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Opens a dropdown menu toward the side of the viewport with more space.
|
|
10
|
+
* Attach `updateAlign` to the trigger's `onPointerDown` and `onKeyDown` (not
|
|
11
|
+
* `onClick`, which `DropdownButton asChild` uses to toggle the menu); both run
|
|
12
|
+
* before the click that opens it.
|
|
13
|
+
*/
|
|
14
|
+
export const useDropdownAlign = (initialAlign: DropdownAlign = "left") => {
|
|
15
|
+
const [align, setAlign] = useState<DropdownAlign>(initialAlign);
|
|
16
|
+
|
|
17
|
+
const updateAlign = useCallback((event: SyntheticEvent<HTMLElement>) => {
|
|
18
|
+
setAlign(
|
|
19
|
+
getDropdownAlign(
|
|
20
|
+
event.currentTarget.getBoundingClientRect(),
|
|
21
|
+
document.documentElement.clientWidth
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
}, []);
|
|
25
|
+
|
|
26
|
+
return { align, updateAlign };
|
|
27
|
+
};
|
|
@@ -42,7 +42,7 @@ export const ContractTabsLayout = ({
|
|
|
42
42
|
|
|
43
43
|
if (featureFlags?.suma && resolvedOrgUnitId) {
|
|
44
44
|
return (
|
|
45
|
-
|
|
45
|
+
<div data-fs-bp-contract-listing-page>
|
|
46
46
|
<OrgUnitDetailsNavbar
|
|
47
47
|
orgId={resolvedOrgUnitId}
|
|
48
48
|
contractId={resolvedContractId}
|
|
@@ -64,7 +64,7 @@ export const ContractTabsLayout = ({
|
|
|
64
64
|
/>
|
|
65
65
|
<section data-fs-bp-contract-listing-section>{children}</section>
|
|
66
66
|
</div>
|
|
67
|
-
|
|
67
|
+
</div>
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -40,7 +40,7 @@ export const SumaPageLayout = ({
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
return (
|
|
43
|
-
|
|
43
|
+
<div data-fs-bp-contract-listing-page>
|
|
44
44
|
<OrgUnitDetailsNavbar
|
|
45
45
|
orgId={currentOrgUnit.id}
|
|
46
46
|
contractId={contractId}
|
|
@@ -62,6 +62,6 @@ export const SumaPageLayout = ({
|
|
|
62
62
|
/>
|
|
63
63
|
<section data-fs-bp-contract-listing-section>{children}</section>
|
|
64
64
|
</div>
|
|
65
|
-
|
|
65
|
+
</div>
|
|
66
66
|
);
|
|
67
67
|
};
|
|
@@ -26,21 +26,15 @@ export const SumaSidebar = ({
|
|
|
26
26
|
showBackLink = false,
|
|
27
27
|
loading = false,
|
|
28
28
|
}: SumaSidebarProps) => {
|
|
29
|
-
const { featureFlags, currentContract
|
|
29
|
+
const { featureFlags, currentContract } = useBuyerPortal();
|
|
30
30
|
const { t } = useLocalization();
|
|
31
31
|
const config = getSumaSidebarConfig(variant, showBackLink);
|
|
32
32
|
const contractsUrl = buyerPortalRoutes.contracts({ orgUnitId });
|
|
33
33
|
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
// otherwise indistinguishable from it. The contract becomes a secondary
|
|
37
|
-
// line; contract-only identity is kept for pages with no unit context.
|
|
34
|
+
// Inside a contract the sidebar identifies the contract only; the org unit
|
|
35
|
+
// is already shown by the header.
|
|
38
36
|
const contractName = currentContract?.name ?? currentContract?.email ?? "";
|
|
39
|
-
const
|
|
40
|
-
const identityName = unitName || contractName;
|
|
41
|
-
const showIdentity = config.showIdentity && !!identityName;
|
|
42
|
-
const showContractLine =
|
|
43
|
-
config.showContractIdentity && !!unitName && !!contractName;
|
|
37
|
+
const showIdentity = config.showIdentity && !!contractName;
|
|
44
38
|
|
|
45
39
|
return (
|
|
46
40
|
<aside
|
|
@@ -60,37 +54,19 @@ export const SumaSidebar = ({
|
|
|
60
54
|
|
|
61
55
|
{showIdentity && (
|
|
62
56
|
<div data-fs-bp-suma-sidebar-identity>
|
|
63
|
-
<LetterHighlight size="large" letter={
|
|
57
|
+
<LetterHighlight size="large" letter={contractName} />
|
|
64
58
|
<div data-fs-bp-suma-sidebar-identity-row>
|
|
65
|
-
<span data-fs-bp-suma-sidebar-identity-name>{
|
|
66
|
-
{config.showContractIdentity &&
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
/>
|
|
76
|
-
)}
|
|
59
|
+
<span data-fs-bp-suma-sidebar-identity-name>{contractName}</span>
|
|
60
|
+
{config.showContractIdentity && currentContract?.isDefault && (
|
|
61
|
+
<Icon
|
|
62
|
+
name="Default"
|
|
63
|
+
width={20}
|
|
64
|
+
height={20}
|
|
65
|
+
data-fs-bp-suma-sidebar-identity-default
|
|
66
|
+
aria-label="Default contract"
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
77
69
|
</div>
|
|
78
|
-
{showContractLine && (
|
|
79
|
-
<div data-fs-bp-suma-sidebar-identity-row>
|
|
80
|
-
<span data-fs-bp-suma-sidebar-identity-contract>
|
|
81
|
-
{contractName}
|
|
82
|
-
</span>
|
|
83
|
-
{currentContract?.isDefault && (
|
|
84
|
-
<Icon
|
|
85
|
-
name="Default"
|
|
86
|
-
width={16}
|
|
87
|
-
height={16}
|
|
88
|
-
data-fs-bp-suma-sidebar-identity-default
|
|
89
|
-
aria-label="Default contract"
|
|
90
|
-
/>
|
|
91
|
-
)}
|
|
92
|
-
</div>
|
|
93
|
-
)}
|
|
94
70
|
</div>
|
|
95
71
|
)}
|
|
96
72
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { getDropdownAlign } from "../getDropdownAlign";
|
|
4
|
+
|
|
5
|
+
describe("getDropdownAlign", () => {
|
|
6
|
+
it("opens to the right when the trigger is on the left side", () => {
|
|
7
|
+
expect(getDropdownAlign({ left: 260, right: 292 }, 1440)).toBe("left");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("opens to the left when the trigger is on the right side", () => {
|
|
11
|
+
expect(getDropdownAlign({ left: 1380, right: 1412 }, 1440)).toBe("right");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("opens to the right when both sides have the same space", () => {
|
|
15
|
+
expect(getDropdownAlign({ left: 704, right: 736 }, 1440)).toBe("left");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { buyerPortalRoutes } from "../buyerPortalRoutes";
|
|
4
|
+
import { isNavLinkActive } from "../isNavLinkActive";
|
|
5
|
+
|
|
6
|
+
const orgUnitId = "unit-1";
|
|
7
|
+
const contractId = "contract-1";
|
|
8
|
+
|
|
9
|
+
describe("isNavLinkActive", () => {
|
|
10
|
+
it("is active on the link's own page", () => {
|
|
11
|
+
const link = buyerPortalRoutes.addresses({ orgUnitId, contractId });
|
|
12
|
+
|
|
13
|
+
expect(isNavLinkActive(link, link)).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("keeps Addresses active on an address's details page", () => {
|
|
17
|
+
expect(
|
|
18
|
+
isNavLinkActive(
|
|
19
|
+
buyerPortalRoutes.addressDetails({
|
|
20
|
+
orgUnitId,
|
|
21
|
+
contractId,
|
|
22
|
+
addressId: "address-1",
|
|
23
|
+
}),
|
|
24
|
+
buyerPortalRoutes.addresses({ orgUnitId, contractId })
|
|
25
|
+
)
|
|
26
|
+
).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("keeps Users active on a user's details page", () => {
|
|
30
|
+
expect(
|
|
31
|
+
isNavLinkActive(
|
|
32
|
+
buyerPortalRoutes.userDetails({ orgUnitId, userId: "user-1" }),
|
|
33
|
+
buyerPortalRoutes.users({ orgUnitId, contractId })
|
|
34
|
+
)
|
|
35
|
+
).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("keeps Roles active on a role's details page", () => {
|
|
39
|
+
expect(
|
|
40
|
+
isNavLinkActive(
|
|
41
|
+
buyerPortalRoutes.roleDetails({ orgUnitId, roleName: "buyer" }),
|
|
42
|
+
buyerPortalRoutes.roles({ orgUnitId, contractId })
|
|
43
|
+
)
|
|
44
|
+
).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("keeps Buying policies active on a buying policy's details page", () => {
|
|
48
|
+
expect(
|
|
49
|
+
isNavLinkActive(
|
|
50
|
+
buyerPortalRoutes.buyingPolicyDetails({
|
|
51
|
+
orgUnitId,
|
|
52
|
+
contractId,
|
|
53
|
+
buyingPolicyId: "policy-1",
|
|
54
|
+
}),
|
|
55
|
+
buyerPortalRoutes.buyingPolicies({ orgUnitId, contractId })
|
|
56
|
+
)
|
|
57
|
+
).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("keeps Budgets active on a budget's details page", () => {
|
|
61
|
+
expect(
|
|
62
|
+
isNavLinkActive(
|
|
63
|
+
buyerPortalRoutes.budgetsDetails({
|
|
64
|
+
orgUnitId,
|
|
65
|
+
contractId,
|
|
66
|
+
budgetId: "budget-1",
|
|
67
|
+
}),
|
|
68
|
+
buyerPortalRoutes.budgets({ orgUnitId, contractId })
|
|
69
|
+
)
|
|
70
|
+
).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("keeps Contracts active on a contract's information page", () => {
|
|
74
|
+
expect(
|
|
75
|
+
isNavLinkActive(
|
|
76
|
+
buyerPortalRoutes.contractInformation({ orgUnitId, contractId }),
|
|
77
|
+
buyerPortalRoutes.contracts({ orgUnitId })
|
|
78
|
+
)
|
|
79
|
+
).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("ignores the query string on both sides", () => {
|
|
83
|
+
expect(
|
|
84
|
+
isNavLinkActive(
|
|
85
|
+
`${buyerPortalRoutes.users({ orgUnitId })}?page=2`,
|
|
86
|
+
buyerPortalRoutes.users({ orgUnitId, contractId })
|
|
87
|
+
)
|
|
88
|
+
).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("does not activate a link from another org unit", () => {
|
|
92
|
+
expect(
|
|
93
|
+
isNavLinkActive(
|
|
94
|
+
buyerPortalRoutes.userDetails({ orgUnitId: "unit-2", userId: "u" }),
|
|
95
|
+
buyerPortalRoutes.users({ orgUnitId })
|
|
96
|
+
)
|
|
97
|
+
).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("does not activate Organizational units on a unit's home page", () => {
|
|
101
|
+
expect(
|
|
102
|
+
isNavLinkActive(
|
|
103
|
+
buyerPortalRoutes.orgUnitDetails({ orgUnitId }),
|
|
104
|
+
buyerPortalRoutes.orgUnits({ orgUnitId })
|
|
105
|
+
)
|
|
106
|
+
).toBe(false);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("does not activate a link that only shares a prefix", () => {
|
|
110
|
+
expect(
|
|
111
|
+
isNavLinkActive(
|
|
112
|
+
buyerPortalRoutes.addresses({ orgUnitId, contractId: "contract-10" }),
|
|
113
|
+
buyerPortalRoutes.addresses({ orgUnitId, contractId })
|
|
114
|
+
)
|
|
115
|
+
).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type DropdownAlign = "left" | "right";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* FastStore's `align="left"` pins the menu's left edge to the trigger, so the
|
|
5
|
+
* menu grows to the right (and `"right"` grows to the left). Picks the side
|
|
6
|
+
* with more room; ties go to the right.
|
|
7
|
+
*/
|
|
8
|
+
export const getDropdownAlign = (
|
|
9
|
+
{ left, right }: Pick<DOMRect, "left" | "right">,
|
|
10
|
+
viewportWidth: number
|
|
11
|
+
): DropdownAlign => (viewportWidth - right >= left ? "left" : "right");
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const base = "/pvt/organization-account";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Detail routes whose first segment differs from their listing's
|
|
5
|
+
* (`/address/...` vs `/addresses/...`). `org-unit` is left out on purpose:
|
|
6
|
+
* `/org-unit/[orgUnitId]` is a unit's home page, not an item of the
|
|
7
|
+
* Organizational units list.
|
|
8
|
+
*/
|
|
9
|
+
const DETAIL_TO_LISTING_SEGMENT: Record<string, string> = {
|
|
10
|
+
address: "addresses",
|
|
11
|
+
user: "users",
|
|
12
|
+
"buying-policy": "buying-policies",
|
|
13
|
+
"contract-information": "contracts",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const stripQuery = (path: string) => path.split(/[?#]/)[0];
|
|
17
|
+
|
|
18
|
+
const toListingPath = (path: string) => {
|
|
19
|
+
if (!path.startsWith(`${base}/`)) return path;
|
|
20
|
+
|
|
21
|
+
const [segment, ...rest] = path.slice(base.length + 1).split("/");
|
|
22
|
+
const listingSegment = DETAIL_TO_LISTING_SEGMENT[segment];
|
|
23
|
+
|
|
24
|
+
return listingSegment
|
|
25
|
+
? [`${base}/${listingSegment}`, ...rest].join("/")
|
|
26
|
+
: path;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A sidebar link stays active on its own page and on every page inside it
|
|
31
|
+
* (e.g. Addresses on an address's details page), whatever the query string.
|
|
32
|
+
*/
|
|
33
|
+
export const isNavLinkActive = (asPath: string, link: string) => {
|
|
34
|
+
const normalizedLink = stripQuery(
|
|
35
|
+
link.startsWith("/") ? link : link.slice(0, -1)
|
|
36
|
+
);
|
|
37
|
+
const path = toListingPath(stripQuery(asPath));
|
|
38
|
+
|
|
39
|
+
return path === normalizedLink || path.startsWith(`${normalizedLink}/`);
|
|
40
|
+
};
|
package/src/features/users/components/CreateUserDrawerWithUsername/CreateUserDrawerWithUsername.tsx
CHANGED
|
@@ -18,6 +18,7 @@ import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
|
|
|
18
18
|
import { normalizePhoneNumber } from "../../../shared/utils/phoneNumber";
|
|
19
19
|
import { useAddUserToOrgUnit, useResetPassword } from "../../hooks";
|
|
20
20
|
import { detectLoginType } from "../../utils/detectLoginType";
|
|
21
|
+
import { resolveAccessCodeRecipient } from "../../utils/resolveAccessCodeRecipient";
|
|
21
22
|
import {
|
|
22
23
|
EMPTY_FORM,
|
|
23
24
|
UserFormFields,
|
|
@@ -134,13 +135,6 @@ export const CreateUserDrawerWithUsername = ({
|
|
|
134
135
|
};
|
|
135
136
|
};
|
|
136
137
|
|
|
137
|
-
const getEffectiveEmail = () => {
|
|
138
|
-
if (loginType === "email") {
|
|
139
|
-
return useLoginAsTransactional ? login : transactionalEmail;
|
|
140
|
-
}
|
|
141
|
-
return email;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
138
|
const handleResetPasswordSuccess = useCallback(
|
|
145
139
|
(data: { accessCode: string }) => {
|
|
146
140
|
setAccessToken(data.accessCode);
|
|
@@ -174,7 +168,12 @@ export const CreateUserDrawerWithUsername = ({
|
|
|
174
168
|
org_unit_id: orgUnitId,
|
|
175
169
|
});
|
|
176
170
|
|
|
177
|
-
const effectiveEmail =
|
|
171
|
+
const effectiveEmail = resolveAccessCodeRecipient({
|
|
172
|
+
login,
|
|
173
|
+
email,
|
|
174
|
+
transactionalEmail,
|
|
175
|
+
useLoginAsTransactional,
|
|
176
|
+
});
|
|
178
177
|
const shouldResetPassword =
|
|
179
178
|
!effectiveEmail?.trim() || drawerState === "CONFIRM_SHARED_EMAIL";
|
|
180
179
|
|
|
@@ -186,7 +185,7 @@ export const CreateUserDrawerWithUsername = ({
|
|
|
186
185
|
pushToast({
|
|
187
186
|
title: t("users.create.toasts.userAddedSuccessfully"),
|
|
188
187
|
message: `${t("users.create.toasts.accessCodeSent", [
|
|
189
|
-
`[${
|
|
188
|
+
`[${effectiveEmail}](mailto:${effectiveEmail})`,
|
|
190
189
|
])}\n${t("shared.messages.changesTimeout")}`,
|
|
191
190
|
status: "INFO",
|
|
192
191
|
icon: (
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { resolveAccessCodeRecipient } from "../resolveAccessCodeRecipient";
|
|
4
|
+
|
|
5
|
+
describe("resolveAccessCodeRecipient", () => {
|
|
6
|
+
it("uses the login when it is an email and the email field stays empty", () => {
|
|
7
|
+
expect(
|
|
8
|
+
resolveAccessCodeRecipient({
|
|
9
|
+
login: "novo.usuario@empresa.com",
|
|
10
|
+
email: "",
|
|
11
|
+
transactionalEmail: "",
|
|
12
|
+
useLoginAsTransactional: true,
|
|
13
|
+
})
|
|
14
|
+
).toBe("novo.usuario@empresa.com");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("uses the transactional email when login is an email and the checkbox is off", () => {
|
|
18
|
+
expect(
|
|
19
|
+
resolveAccessCodeRecipient({
|
|
20
|
+
login: "novo.usuario@empresa.com",
|
|
21
|
+
email: "",
|
|
22
|
+
transactionalEmail: "avisos@empresa.com",
|
|
23
|
+
useLoginAsTransactional: false,
|
|
24
|
+
})
|
|
25
|
+
).toBe("avisos@empresa.com");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("uses the email field when login is a phone or username", () => {
|
|
29
|
+
expect(
|
|
30
|
+
resolveAccessCodeRecipient({
|
|
31
|
+
login: "15551234567",
|
|
32
|
+
email: "pessoa@empresa.com",
|
|
33
|
+
transactionalEmail: "",
|
|
34
|
+
useLoginAsTransactional: true,
|
|
35
|
+
})
|
|
36
|
+
).toBe("pessoa@empresa.com");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { detectLoginType } from "./detectLoginType";
|
|
2
|
+
|
|
3
|
+
export interface AccessCodeRecipientInput {
|
|
4
|
+
login: string;
|
|
5
|
+
email: string;
|
|
6
|
+
transactionalEmail: string;
|
|
7
|
+
useLoginAsTransactional: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Address that receives the first-access code.
|
|
12
|
+
* When login is an email, the separate email field is hidden, so the
|
|
13
|
+
* recipient is the login or the transactional override.
|
|
14
|
+
*/
|
|
15
|
+
export function resolveAccessCodeRecipient({
|
|
16
|
+
login,
|
|
17
|
+
email,
|
|
18
|
+
transactionalEmail,
|
|
19
|
+
useLoginAsTransactional,
|
|
20
|
+
}: AccessCodeRecipientInput): string {
|
|
21
|
+
if (detectLoginType(login.trim()) === "email") {
|
|
22
|
+
return useLoginAsTransactional ? login : transactionalEmail;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return email;
|
|
26
|
+
}
|