@dropins/storefront-company-management 1.0.0-beta24 → 1.0.0-beta26
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/LICENSE.md +25 -26
- package/chunks/CompanyUserForm.js +1 -1
- package/chunks/CompanyUserForm.js.map +1 -1
- package/containers/CompanyStructure.js +1 -1
- package/containers/CompanyStructure.js.map +1 -1
- package/containers/CompanyUsers.js +1 -1
- package/hooks/useCompanyTeamForm.d.ts +1 -1
- package/i18n/en_US.json.d.ts +5 -2
- package/package.json +1 -1
- package/render.js +1 -1
- package/render.js.map +1 -1
package/LICENSE.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Last Updated: 28 October 2024
|
|
1
|
+
Last Updated: 8 December 2025
|
|
3
2
|
|
|
4
|
-
ADOBE COMMERCE DROP-IN LICENSE AGREEMENT
|
|
3
|
+
**ADOBE COMMERCE DROP-IN LICENSE AGREEMENT**
|
|
5
4
|
|
|
6
|
-
applicable to Adobe Commerce Customers
|
|
5
|
+
applicable to Adobe Commerce as a Cloud Service and Adobe Commerce Optimizer Customers
|
|
7
6
|
|
|
8
7
|
**Effective Date:** first date you download or use the Drop-in
|
|
9
8
|
|
|
10
|
-
NOTICE TO USER: The Adobe Commerce Drop-in (
|
|
9
|
+
NOTICE TO USER: The Adobe Commerce Drop-ins are licensed only for use with Adobe Commerce as a Cloud Service and Adobe Commerce Optimizer. The Adobe Commerce Drop-in ("Drop-in") is licensed to you subject to the terms and conditions below which form a binding agreement between you and Adobe. **By downloading, installing, or making use of any portion of the Drop-in, you are agreeing to the following terms and conditions. If you do not agree to the terms and conditions below, do not use the Drop-in**. If you agree to be bound by this agreement on behalf of your employer or other entity, you must have the legal authority to do so. If you are not authorized to so bind your employer or such entity, do not download and do not use the Drop-in.
|
|
11
10
|
|
|
12
11
|
Your access to and use of the Drop-in is governed by the Adobe Enterprise Licensing Terms previously agreed to by you and Adobe or an authorized Adobe Reseller in a separate agreement. If you have not previously agreed to licensing terms then your installation and use of the Drop-in is subject to the current applicable Adobe Enterprise Licensing Terms available at <http://www.adobe.com/legal/terms/enterprise-licensing.html>. You agree that this agreement will have the same effect as any written negotiated agreement signed by you.
|
|
13
12
|
|
|
@@ -15,7 +14,7 @@ By downloading, installing or making use of any portion of the Drop-in, you acce
|
|
|
15
14
|
|
|
16
15
|
This agreement is enforceable against any person or entity that installs and uses the Drop-in and any person or entity (e.g., system integrator, consultant or contractor) that installs or uses the drop-in on another person's or entity's behalf (e.g., Adobe Customer).
|
|
17
16
|
|
|
18
|
-
Notice to U.S. Government End Users: Products and services are
|
|
17
|
+
Notice to U.S. Government End Users: Products and services are "Commercial Product(s)," and "Commercial Service(s)" as those terms are defined at 48 C.F.R. section 2.101, consisting of "Commercial Computer Software" and "Commercial Computer Software Documentation," as the terms are used in 48 C.F.R. section 12.212 or 48 C.F.R. section 227.7202, as applicable. Customer agrees, consistent with 48 C.F.R. section 12.212 or 48 C.F.R. sections 227.7202-1 through 227.72024, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (A) only as Commercial Products and Services; and (B) with only those rights as are granted to all other end users pursuant to the terms and conditions herein. Unpublished rights are reserved under the copyright laws of the United States.
|
|
19
18
|
|
|
20
19
|
**ADOBE COMMERCE DROP-IN LICENSE AGREEMENT**
|
|
21
20
|
|
|
@@ -23,21 +22,21 @@ applicable to Developers
|
|
|
23
22
|
|
|
24
23
|
**Effective Date:** first date you download or use the Drop-in
|
|
25
24
|
|
|
26
|
-
The Adobe Commerce Drop-in (
|
|
25
|
+
The Adobe Commerce Drop-ins are licensed only for use with Adobe Commerce as a Cloud Service and Adobe Commerce Optimizer. The Adobe Commerce Drop-in ("Drop-in") is licensed to you subject to the terms and conditions below which form a binding agreement between you and Adobe. **By downloading, installing, or making use of any portion of the Drop-in, you are agreeing to the following terms and conditions. If you do not agree to the terms and conditions below, do not use the Drop-in**. If you agree to be bound by this agreement on behalf of your employer or other entity, you must have the legal authority to do so. If you are not authorized to so bind your employer or such entity, do not download and do not use the Drop-in.
|
|
27
26
|
|
|
28
27
|
**AGREED TERMS AND CONDITIONS**
|
|
29
28
|
|
|
30
29
|
1. **DEFINITIONS**.
|
|
31
30
|
|
|
32
|
-
1.1
|
|
31
|
+
1.1 "**Adobe**" means collectively, Adobe Inc., a company incorporated in Delaware, U.S.A., having a place of business at 345 Park Avenue, San Jose, California USA 95110-2704, U.S.A. ("**Adobe US**") and Adobe Systems Software Ireland, company incorporated in Ireland, having a place of business 4-6 Riverwalk, City West Business Campus, Saggart, Dublin 24, Ireland ("**Adobe Ireland**").
|
|
33
32
|
|
|
34
|
-
1.2
|
|
33
|
+
1.2 "**Adobe Product(s)**" means software applications, programs and other technologies not included in or with the Drop-in which are or may be made available by Adobe for licensing to the general public. This agreement does not govern use of Adobe Products. See the end user license agreement accompanying an Adobe Product for terms governing its use.
|
|
35
34
|
|
|
36
|
-
1.3
|
|
35
|
+
1.3 "**Developer Product(s)**" means any software application(s), program(s) and other technolog(y/ies) you develop with use of the Drop-in to function or interoperate with Adobe Products.
|
|
37
36
|
|
|
38
|
-
1.4
|
|
37
|
+
1.4 "**Intellectual Property Rights**" means copyright, moral rights, trademark, trade dress, patent, trade secret, unfair competition, and any other intellectual and proprietary rights.
|
|
39
38
|
|
|
40
|
-
1.5
|
|
39
|
+
1.5 "**Adobe Commerce Drop-in**" or "Drop-in" means all items comprising the application and all associated materials licensed to you by Adobe as part of the Drop-in, including all Drop-in system files, tools, programs and utilities, as well as any plug-ins or other application programming interfaces, header or JAR files ("**API**"), sample images, sounds, or similar assets ("**Content** **Files**"), software code samples, runtimes and libraries, including any portion(s) that is modified by you, or merged or incorporated with your Developer Products ("**Sample Code**"), and any related documentation, technical specifications, notes and explanatory materials, as well any modifications, updates, upgrades, or copies of, any of the foregoing items, that may be made available by Adobe, whether online or recorded on media, or manually downloaded by you.
|
|
41
40
|
|
|
42
41
|
2. **LICENSES GRANTED TO YOU**.
|
|
43
42
|
|
|
@@ -51,23 +50,23 @@ The Adobe Commerce Drop-in (“Drop-in”) is licensed to you subject to the ter
|
|
|
51
50
|
|
|
52
51
|
3. **SCOPE OF LICENSE; LIMITATIONS AND RESTRICTIONS**
|
|
53
52
|
|
|
54
|
-
3.1 You may not distribute the Drop-ins or any of its component parts to interoperate with or to run on a platform other than
|
|
53
|
+
3.1 You may not distribute the Drop-ins or any of its component parts to interoperate with or to run on a platform other than Adobe Commerce as a Cloud Service and Adobe Commerce Optimizer.
|
|
55
54
|
|
|
56
55
|
3.2 Third-Party Software. The Drop-ins may contain third-party software, subject to additional terms and conditions, available at <http://www.adobe.com/go/thirdparty>; and
|
|
57
56
|
|
|
58
|
-
3.3 You may not modify, port, adapt,
|
|
57
|
+
3.3 You may not modify, port, adapt, create derivate works, redistribute, or translate any portion of this Drop-in; or add or delete any Drop-in program files that would in any way result in modifying the functionality or appearance of any element of the Adobe Products.
|
|
59
58
|
|
|
60
|
-
3.4 You may not reverse engineer, decompile, disassemble, or otherwise attempt to discover the source code of, any portion of the Drop-in, except and only to the extent that applicable laws of the jurisdiction where you are located grant you the right to decompile the Drop-in in order to obtain information necessary to render the Drop-in interoperable with other software; in which case you must first request the information from Adobe in writing and Adobe may, in its discretion, either provide such information to you or impose reasonable conditions, including reasonable fees, on your use of the Drop-in to ensure that Adobe
|
|
59
|
+
3.4 You may not reverse engineer, decompile, disassemble, or otherwise attempt to discover the source code of, any portion of the Drop-in, except and only to the extent that applicable laws of the jurisdiction where you are located grant you the right to decompile the Drop-in in order to obtain information necessary to render the Drop-in interoperable with other software; in which case you must first request the information from Adobe in writing and Adobe may, in its discretion, either provide such information to you or impose reasonable conditions, including reasonable fees, on your use of the Drop-in to ensure that Adobe's and its licensors' Intellectual Proprietary Rights in the Drop-in are protected.
|
|
61
60
|
|
|
62
|
-
3.5 You may not unbundle, repackage, distribute, rent, lease, offer, sell, resale, sublicense, assign or transfer all, or any component parts of the Drop-in, or any of your rights in the Drop-in, nor authorize any portion of the Drop-in to be copied onto another
|
|
61
|
+
3.5 You may not unbundle, repackage, distribute, rent, lease, offer, sell, resale, sublicense, assign or transfer all, or any component parts of the Drop-in, or any of your rights in the Drop-in, nor authorize any portion of the Drop-in to be copied onto another's device, computer or platform, including on a service bureau basis to other providers (i.e., volume printing, banking, payroll service providers, etc) who provide you free or fee-based business services.
|
|
63
62
|
|
|
64
63
|
4. **VIRAL OPEN SOURCE SOFTWARE AND SERVICES**
|
|
65
64
|
|
|
66
|
-
You are not
|
|
65
|
+
You are not licensed to (and you agree that you will not) merge, integrate or use the Drop-in with any Viral Open Source Software or Viral Service, or otherwise take any action that could require disclosure, distribution, or licensing of all or any part of the Drop-in in source code form for any purpose whatsoever. For purposes of this Section, "**Viral Open Source Software**" means software licensed under the GNU General Public License, the GNU Affero General Public License (AGPL), the GNU Lesser General Public License (LGPL), or any other license terms that would require, or condition your use, modification, or distribution of such licensed software on the disclosure, distribution, or licensing of any other software in source code form, for the purpose of making derivative works, or at no charge, and "**Viral Service**" means any service that contains any viruses, Trojan horses, worms, time bombs, cancelbots or other computer programming routines that are intended to damage, detrimentally interfere with, surreptitiously intercept, expropriate or deprive owners' possession of any system, data or personal information, or that in any way violates any law, statute, ordinance, regulation or rights (including any law, regulations or rights respecting intellectual property, computer spyware, privacy, export control, unfair competition, antidiscrimination or false advertising), or otherwise interferes with the operability of Adobe Products or third-party programs or software.
|
|
67
66
|
|
|
68
67
|
5. **NON-BLOCKING OF ADOBE DEVELOPMENT**
|
|
69
68
|
|
|
70
|
-
You acknowledge that Adobe is currently developing or may develop technologies and Adobe Products in the future that have, or may have, design or functionality similar to Developer Products that you may develop based on the license granted to you in this agreement. Nothing in this agreement will impair, limit or curtail Adobe
|
|
69
|
+
You acknowledge that Adobe is currently developing or may develop technologies and Adobe Products in the future that have, or may have, design or functionality similar to Developer Products that you may develop based on the license granted to you in this agreement. Nothing in this agreement will impair, limit or curtail Adobe's right to continue with its development, maintenance or distribution of Adobe Products. You agree that you will not assert in any way any patent owned by you arising out of or in connection with your use of the Drop-in, or any Drop-in modifications made by you, against Adobe, its customers, subsidiaries or affiliates, or any of their customers, direct or indirect, agents and contractors for the manufacture, use, import, license, offer for sale, or sale of any Adobe Products.
|
|
71
70
|
|
|
72
71
|
6. **OWNERSHIP; INTELLECTUAL PROPERTY RIGHTS**
|
|
73
72
|
|
|
@@ -75,13 +74,13 @@ The Adobe Commerce Drop-in (“Drop-in”) is licensed to you subject to the ter
|
|
|
75
74
|
|
|
76
75
|
6.2 The Drop-in, or any of its component parts, may be supplied to you with certain accompanying proprietary notices, including patent, copyright and trademark notices. You agree to protect all copyright and other ownership interests of Adobe and its licensors in the Drop-in supplied to you under this agreement; to preserve exactly (and not remove or alter) all proprietary notices displayed in or on the Drop-in; to reproduce the same proprietary notices in all copies you make of any portion of the Drop-in.
|
|
77
76
|
|
|
78
|
-
6.3 You agree to include in your Developer Products Adobe
|
|
77
|
+
6.3 You agree to include in your Developer Products Adobe's copyright notices, wherever such notices are customarily posted, in substantially the following form: _Portions of software used to develop this product copyrighted by Adobe and its licensors. All Rights Reserved_.
|
|
79
78
|
|
|
80
79
|
6.4 Nothing in this agreement gives you a right to use the name, logo or trademarks of Adobe or its licensors to market your Developer Products.
|
|
81
80
|
|
|
82
81
|
7. **CONFIDENTIAL INFORMATION**
|
|
83
82
|
|
|
84
|
-
With respect to the API, and any portion, included in the Drop-in (for purposes of this Section,
|
|
83
|
+
With respect to the API, and any portion, included in the Drop-in (for purposes of this Section, "**Adobe Confidential Information**"), you will treat the Adobe Confidential Information, and exercise the same degree of care to protect it, as you afford to your own confidential information. Your obligations under this Section will terminate when you can document that (a) the Adobe Confidential Information was in the public domain at or subsequent to the time Adobe communicated or provided it to you with no fault of your own; (b) your employees or agents developed independently without reference to any Adobe Confidential Information Adobe communicated or provided to you; or (c) your communication of Adobe Confidential Information was in response to a valid order by a court or other governmental body, was otherwise required by law, or was necessary to establish the rights of a party under this agreement.
|
|
85
84
|
|
|
86
85
|
8. **TERM; TERMINATION**
|
|
87
86
|
|
|
@@ -91,13 +90,13 @@ The Adobe Commerce Drop-in (“Drop-in”) is licensed to you subject to the ter
|
|
|
91
90
|
|
|
92
91
|
You expressly understand and agree that, to the maximum extent permitted by applicable law:
|
|
93
92
|
|
|
94
|
-
9.1 **Use
|
|
93
|
+
9.1 **Use of the DROP-IN is entirely at your own risk. The Drop-in is provided by Adobe "AS-IS" and with all faults. Adobe and its licensors are not liable to you or anyone else for any special, incidental, indirect, consequential, or punitive damages whatsoever (even if Adobe has been advised of the possibility of such damages), including (a) damages resulting from loss of use, data, or profits, whether or not foreseeable, (b) damages based on any theory of liability, including breach of contract or warranty, negligence or other tortious action, or (c) damages arising from any other claim arising out of or in connection with your use of the Drop-in.**
|
|
95
94
|
|
|
96
|
-
9.2 **Adobe
|
|
95
|
+
9.2 **Adobe's total liability in any matter arising out of or related to these terms is limited to US $100. This limitation will apply even if Adobe has been advised of the possibility of such damages and regardless of any failure of the essential purpose of any limited remedy.**
|
|
97
96
|
|
|
98
97
|
10. **INDEMNIFICATION**
|
|
99
98
|
|
|
100
|
-
To the maximum extent permitted by law, you agree to indemnify Adobe, its subsidiaries, affiliates, officers, agents, employees, partners, licensors, or suppliers from any claim or demand, including reasonable attorneys
|
|
99
|
+
To the maximum extent permitted by law, you agree to indemnify Adobe, its subsidiaries, affiliates, officers, agents, employees, partners, licensors, or suppliers from any claim or demand, including reasonable attorneys' fees, that arise from the use and distribution of your Developer Products that contain or are based upon any portion of the Drop-in, or from your violation of the terms of this agreement.
|
|
101
100
|
|
|
102
101
|
11. **DISPUTE RESOLUTION**
|
|
103
102
|
|
|
@@ -105,7 +104,7 @@ The Adobe Commerce Drop-in (“Drop-in”) is licensed to you subject to the ter
|
|
|
105
104
|
|
|
106
105
|
11.2 **Venue.** You agree that any claim or dispute you may have against Adobe must be resolved by a court located in Santa Clara County, California, United States of America. You agree to submit to the personal jurisdiction of the courts located in Santa Clara County, California, United States of America when the laws of California apply, and the courts of Dublin, Ireland, when the laws of Ireland applies, for the purpose of litigating such claims or disputes. The parties specifically disclaim the U.N. Convention on Contracts for the International Sale of Goods.
|
|
107
106
|
|
|
108
|
-
11.3 **Injunctive Relief.** Notwithstanding the foregoing, in the event of your or others
|
|
107
|
+
11.3 **Injunctive Relief.** Notwithstanding the foregoing, in the event of your or others' unauthorized access to or use of the Drop-in in violation of this Agreement, you agree that Adobe is entitled to apply for injunctive remedies (or an equivalent type of urgent legal relief) in any jurisdiction.
|
|
109
108
|
|
|
110
109
|
12. **EXPORT RULES**
|
|
111
110
|
|
|
@@ -113,7 +112,7 @@ The Adobe Commerce Drop-in (“Drop-in”) is licensed to you subject to the ter
|
|
|
113
112
|
|
|
114
113
|
13. **NOTICE TO U.S. GOVERNMENT END USERS**
|
|
115
114
|
|
|
116
|
-
Products and services are
|
|
115
|
+
Products and services are "Commercial Product(s)," and "Commercial Service(s)" as those terms are defined at 48 C.F.R. section 2.101, consisting of "Commercial Computer Software" and "Commercial Computer Software Documentation," as the terms are used in 48 C.F.R. section 12.212 or 48 C.F.R. section 227.7202, as applicable. Customer agrees, consistent with 48 C.F.R. section 12.212 or 48 C.F.R. sections 227.7202-1 through 227.72024, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (A) only as Commercial Products and Services; and (B) with only those rights as are granted to all other end users pursuant to the terms and conditions herein. Unpublished rights are reserved under the copyright laws of the United States.
|
|
117
116
|
|
|
118
117
|
14. **GENERAL PROVISIONS**
|
|
119
118
|
|
|
@@ -125,4 +124,4 @@ The Adobe Commerce Drop-in (“Drop-in”) is licensed to you subject to the ter
|
|
|
125
124
|
|
|
126
125
|
14.4 **Entire Agreement.** This Agreement is the entire agreement, superseding any prior written or oral agreements, between you and Adobe relating to the Drop-in.
|
|
127
126
|
|
|
128
|
-
Adobe Commerce Drop-in License Agreement_en_US-
|
|
127
|
+
Adobe Commerce Drop-in License Agreement_en_US-20251208_v1
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsxs as F,jsx as s}from"@dropins/tools/preact-jsx-runtime.js";import{memo as
|
|
3
|
+
import{jsxs as F,jsx as s}from"@dropins/tools/preact-jsx-runtime.js";import{memo as Z}from"@dropins/tools/preact-compat.js";import{useState as p,useEffect as J}from"@dropins/tools/preact-hooks.js";import{Card as K,InLineAlert as Q,ProgressSpinner as W,Field as T,Input as R,Picker as P,Button as H}from"@dropins/tools/components.js";import{i as Y}from"./company-permissions.js";import{g as ee,c as te,a as ae,i as re}from"./updateCompanyUserStatus.js";import{useText as X}from"@dropins/tools/i18n.js";import{u as se}from"./useCompanyRoles.js";import{b as ne}from"./CompanyLoaders.js";const h={firstName:255,lastName:255,email:254,jobTitle:255,telephone:20},z={name:/^[a-zA-ZÀ-ÿ0-9\s,\-_.'`&]+$/,telephone:/^[\d\s+\-()]+$/};function ie(M){const{mode:_,entityId:v,parentStructureId:E,onSaved:q,onError:b,onSuccess:g}=M,i=X({firstNameRequired:"Company.CompanyStructure.shared.validation.firstNameRequired",lastNameRequired:"Company.CompanyStructure.shared.validation.lastNameRequired",emailRequired:"Company.CompanyStructure.shared.validation.emailRequired",emailInvalid:"Company.CompanyStructure.shared.validation.emailInvalid",jobTitleRequired:"Company.CompanyStructure.shared.validation.jobTitleRequired",workPhoneRequired:"Company.CompanyStructure.shared.validation.workPhoneRequired",selectRole:"Company.CompanyStructure.shared.validation.selectRole",firstNameMaxLength:"Company.CompanyStructure.shared.validation.firstNameMaxLength",lastNameMaxLength:"Company.CompanyStructure.shared.validation.lastNameMaxLength",emailMaxLength:"Company.CompanyStructure.shared.validation.emailMaxLength",jobTitleMaxLength:"Company.CompanyStructure.shared.validation.jobTitleMaxLength",telephoneMaxLength:"Company.CompanyStructure.shared.validation.telephoneMaxLength",firstNameInvalidChars:"Company.CompanyStructure.shared.validation.firstNameInvalidChars",lastNameInvalidChars:"Company.CompanyStructure.shared.validation.lastNameInvalidChars",telephoneInvalidChars:"Company.CompanyStructure.shared.validation.telephoneInvalidChars",createUserError:"Company.CompanyStructure.messages.createUserError",saveUserError:"Company.CompanyStructure.messages.saveUserError",createUserSuccess:"Company.CompanyStructure.messages.createUserSuccess",updateUserSuccess:"Company.CompanyStructure.messages.updateUserSuccess"}),[r,L]=p({firstName:"",lastName:"",email:"",jobTitle:"",telephone:"",roleId:"",status:"ACTIVE"}),[w,u]=p({}),[m,y]=p({}),[V,U]=p(!1),[f,A]=p(null),[x,j]=p(null),[S,k]=p(""),[l,a]=p(""),[n,B]=p(!1);J(()=>{_!=="edit"||!v||(U(!0),ee(v).then(t=>{var C;if(!t)return;const e=t.email||"";L(N=>({...N,firstName:t.firstName||"",lastName:t.lastName||"",email:e,jobTitle:t.jobTitle||"",telephone:t.telephone||"",status:t.status||"ACTIVE"})),a(e),(C=t==null?void 0:t.role)!=null&&C.id&&L(N=>({...N,roleId:t.role.id})),B((t==null?void 0:t.isCompanyAdmin)??!1)}).finally(()=>U(!1)))},[_,v]);const $=t=>/.+@.+\..+/.test(t),O=(t,e)=>t==="firstName"?e!=null&&e.trim()?e.length>h.firstName?i.firstNameMaxLength:z.name.test(e)?null:i.firstNameInvalidChars:i.firstNameRequired:t==="lastName"?e!=null&&e.trim()?e.length>h.lastName?i.lastNameMaxLength:z.name.test(e)?null:i.lastNameInvalidChars:i.lastNameRequired:t==="email"?e!=null&&e.trim()?e.length>h.email?i.emailMaxLength:$(e.trim())?null:i.emailInvalid:i.emailRequired:t==="jobTitle"?e&&e.length>h.jobTitle?i.jobTitleMaxLength:null:t==="telephone"?e&&e.length>h.telephone?i.telephoneMaxLength:e&&e.trim()&&!z.telephone.test(e)?i.telephoneInvalidChars:null:t==="roleId"?e?null:i.selectRole:null,D=(t,e)=>{L(C=>({...C,[t]:e})),t==="email"&&j(null),f&&A(null)};return{values:r,errors:w,touched:m,loading:V,setValue:D,onBlur:async(t,e)=>{e!==void 0&&D(t,e),y(I=>({...I,[t]:!0}));const C=e!==void 0?e:r[t],N=O(t,C);if(u(N?I=>({...I,[t]:N}):I=>{const c={...I};return delete c[t],c}),t==="email"){const c=(e!==void 0?e:r.email||"").trim();if(_==="edit"&&c.toLowerCase()===(l||"").trim().toLowerCase()){j(null);return}if($(c)&&c!==S){const o=await re(c);k(c),j(o),o===!1&&u(d=>({...d,email:"A user with this email address is already a member of your company."}))}}},submit:async()=>{const t=["firstName","lastName","email","roleId","jobTitle","telephone"],e={},C={};for(const o of t){C[o]=!0;const d=O(o,r[o]);d&&(e[o]=d)}if(u(e),y(C),Object.keys(e).length||x===!1){setTimeout(()=>{const o=document.querySelector(".company-user-form__content .dropin-field__hint--error");if(o){const d=o.closest(".dropin-field");if(d){d.scrollIntoView({behavior:"smooth",block:"center"});const G=d.querySelector("input, select");G&&G.focus()}}},100);return}const N=`${r.firstName||""} ${r.lastName||""}`.trim()||r.email||"",c=n||Y({id:r.roleId})?"ACTIVE":r.status;try{if(_==="add"){const o=await te({email:r.email||"",firstName:r.firstName||"",lastName:r.lastName||"",jobTitle:r.jobTitle||"",telephone:r.telephone||"",roleId:r.roleId,status:c,targetId:E??null});if(!o){const d=i.createUserError;b?b(d):A(d);return}q({label:N,structureId:o.structureId,entityId:o.id,type:"user",status:c,jobTitle:o.jobTitle}),g&&g(i.createUserSuccess)}else v&&(await ae({id:v,email:r.email||"",firstName:r.firstName||"",lastName:r.lastName||"",jobTitle:r.jobTitle||"",telephone:r.telephone||"",status:c,roleId:r.roleId}),q({label:N,entityId:v,type:"user",status:c,jobTitle:r.jobTitle}),g&&g(i.updateUserSuccess))}catch(o){const d=o instanceof Error?o.message:i.saveUserError;b?b(d):A(d)}},isCompanyAdmin:n,generalError:f}}const Ne=Z(({mode:M,entityId:_,parentStructureId:v,permissions:E,onSaved:q,onCancel:b,onError:g,onSuccess:i})=>{const r=(E==null?void 0:E.canEditUsers)??!1,{roles:L,isLoading:w}=se(),{values:u,errors:m,touched:y,loading:V,setValue:U,onBlur:f,submit:A,isCompanyAdmin:x,generalError:j}=ie({mode:M,entityId:_,parentStructureId:v,onSaved:q,onError:g?a=>{g(a),b()}:void 0,onSuccess:i}),[S,k]=p(!1),l=X({addUser:"Company.CompanyStructure.shared.titles.addUser",editUser:"Company.CompanyStructure.shared.titles.editUser",jobTitle:"Company.CompanyStructure.shared.fields.jobTitle",userRole:"Company.CompanyStructure.shared.fields.userRole",firstName:"Company.CompanyStructure.shared.fields.firstName",lastName:"Company.CompanyStructure.shared.fields.lastName",email:"Company.CompanyStructure.shared.fields.email",workPhoneNumber:"Company.CompanyStructure.shared.fields.workPhoneNumber",status:"Company.CompanyStructure.shared.fields.status",selectRole:"Company.CompanyStructure.shared.options.selectRole",active:"Company.CompanyStructure.shared.options.active",inactive:"Company.CompanyStructure.shared.options.inactive",companyAdministrator:"Company.CompanyStructure.shared.options.companyAdministrator",save:"Company.CompanyStructure.shared.buttons.save",cancel:"Company.CompanyStructure.shared.buttons.cancel"});return F("div",{children:[s("h3",{className:"acm-structure-panel__title",children:M==="add"?l.addUser:l.editUser}),F(K,{variant:"secondary",className:`company-user-form__card ${S?"is-working":""}`,children:[!g&&j?s(Q,{className:"company-user-form__notification",type:"error",variant:"secondary",heading:j}):null,S?s("div",{className:"company-user-form__overlay","aria-live":"polite",children:s(W,{size:"small"})}):null,V||w?s(ne,{}):F("div",{className:"company-user-form__content",children:[s(T,{label:l.jobTitle,className:"acm-structure-panel__field",error:y.jobTitle&&m.jobTitle?m.jobTitle:void 0,children:s(R,{name:"job_title",type:"text",value:u.jobTitle||"",onBlur:a=>{const n=a.target;f("jobTitle",n.value)},variant:"primary",size:"medium",maxLength:h.jobTitle})}),s(T,{label:l.userRole,required:!0,className:"acm-structure-panel__field",error:!x&&y.roleId&&m.roleId?m.roleId:void 0,disabled:x,children:x?s(P,{name:"role",value:"MA==",options:[{value:"MA==",text:l.companyAdministrator}]}):s(P,{name:"role",value:u.roleId||"placeholder",onChange:a=>{var n,B;return U("roleId",String(((n=a==null?void 0:a.target)==null?void 0:n.value)==="placeholder"?"":((B=a==null?void 0:a.target)==null?void 0:B.value)??""))},onBlur:a=>{const n=a.target;f("roleId",n.value==="placeholder"?"":n.value)},options:[{value:"placeholder",text:l.selectRole,disabled:!0},...L.map(a=>({value:a.id,text:a.name}))]})}),s(T,{label:l.firstName,required:!0,className:"acm-structure-panel__field",error:y.firstName&&m.firstName?m.firstName:void 0,children:s(R,{name:"first_name",type:"text",value:u.firstName,onBlur:a=>{const n=a.target;f("firstName",n.value)},variant:"primary",size:"medium",maxLength:h.firstName})}),s(T,{label:l.lastName,required:!0,className:"acm-structure-panel__field",error:y.lastName&&m.lastName?m.lastName:void 0,children:s(R,{name:"last_name",type:"text",value:u.lastName,onBlur:a=>{const n=a.target;f("lastName",n.value)},variant:"primary",size:"medium",maxLength:h.lastName})}),s(T,{label:l.email,required:!0,className:"acm-structure-panel__field",error:y.email&&m.email?m.email:void 0,children:s(R,{name:"email",type:"email",value:u.email,onBlur:a=>{const n=a.target;f("email",n.value)},placeholder:"jdoe@example.com",variant:"primary",size:"medium",maxLength:h.email})}),s(T,{label:l.workPhoneNumber,className:"acm-structure-panel__field",error:y.telephone&&m.telephone?m.telephone:void 0,children:s(R,{name:"telephone",type:"text",value:u.telephone||"",onBlur:a=>{const n=a.target;f("telephone",n.value)},variant:"primary",size:"medium",maxLength:h.telephone})}),s(T,{label:l.status,className:"acm-structure-panel__field",disabled:x||!r,children:s(P,{name:"status",value:u.status,onChange:a=>{var n;return U("status",String(((n=a==null?void 0:a.target)==null?void 0:n.value)??"ACTIVE"))},options:[{value:"ACTIVE",text:l.active},{value:"INACTIVE",text:l.inactive}]})})]})]}),V||w?null:F("div",{className:"acm-structure-modal__actions",children:[s(H,{type:"button",variant:"primary",disabled:S||!r,onClick:async()=>{if(!S){k(!0);try{await A()}finally{k(!1)}}},children:l.save}),s(H,{type:"button",variant:"secondary",disabled:S,onClick:b,children:l.cancel})]})]})});export{Ne as C};
|
|
4
4
|
//# sourceMappingURL=CompanyUserForm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompanyUserForm.js","sources":["/@dropins/storefront-company-management/src/hooks/useCompanyUserForm.ts","/@dropins/storefront-company-management/src/components/CompanyUserForm/CompanyUserForm.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport { useEffect, useState } from 'preact/hooks';\nimport { createCompanyUser, getCompanyUser, isCompanyUserEmailAvailable, updateCompanyUser } from '@/company-management/api';\nimport { isCompanyAdministrator } from '@/company-management/lib';\nimport { CompanyUserModel } from '@/company-management/data/models';\nimport { useText } from '@adobe-commerce/elsie/i18n';\n\nexport type UserStatus = 'ACTIVE' | 'INACTIVE';\n\n// Field length constants (based on Magento backend validation)\nexport const FIELD_MAX_LENGTHS = {\n firstName: 255,\n lastName: 255,\n email: 254,\n jobTitle: 255,\n telephone: 20,\n} as const;\n\nexport function useCompanyUserForm(opts: {\n mode: 'add' | 'edit';\n entityId?: string;\n parentStructureId?: string | null;\n onSaved: (result: { label: string; structureId?: string; entityId?: string; type: 'user'; status?: UserStatus; jobTitle?: string | null }) => void;\n onError?: (error: string) => void;\n onSuccess?: (message: string) => void;\n}) {\n const { mode, entityId, parentStructureId, onSaved, onError, onSuccess } = opts;\n \n const translations = useText({\n firstNameRequired: 'Company.CompanyStructure.shared.validation.firstNameRequired',\n lastNameRequired: 'Company.CompanyStructure.shared.validation.lastNameRequired',\n emailRequired: 'Company.CompanyStructure.shared.validation.emailRequired',\n emailInvalid: 'Company.CompanyStructure.shared.validation.emailInvalid',\n jobTitleRequired: 'Company.CompanyStructure.shared.validation.jobTitleRequired',\n workPhoneRequired: 'Company.CompanyStructure.shared.validation.workPhoneRequired',\n selectRole: 'Company.CompanyStructure.shared.validation.selectRole',\n firstNameMaxLength: 'Company.CompanyStructure.shared.validation.firstNameMaxLength',\n lastNameMaxLength: 'Company.CompanyStructure.shared.validation.lastNameMaxLength',\n emailMaxLength: 'Company.CompanyStructure.shared.validation.emailMaxLength',\n jobTitleMaxLength: 'Company.CompanyStructure.shared.validation.jobTitleMaxLength',\n telephoneMaxLength: 'Company.CompanyStructure.shared.validation.telephoneMaxLength',\n createUserError: 'Company.CompanyStructure.messages.createUserError',\n saveUserError: 'Company.CompanyStructure.messages.saveUserError',\n createUserSuccess: 'Company.CompanyStructure.messages.createUserSuccess',\n updateUserSuccess: 'Company.CompanyStructure.messages.updateUserSuccess',\n });\n const [values, setValues] = useState<Partial<CompanyUserModel> & { roleId: string; status: UserStatus }>({ \n firstName: '', \n lastName: '', \n email: '', \n jobTitle: '', \n telephone: '', \n roleId: '', \n status: 'ACTIVE' \n });\n const [errors, setErrors] = useState<Record<string, string>>({});\n const [touched, setTouched] = useState<Record<string, boolean>>({});\n const [loading, setLoading] = useState(false);\n const [generalError, setGeneralError] = useState<string | null>(null);\n const [emailAvailable, setEmailAvailable] = useState<boolean | null>(null);\n const [emailChecked, setEmailChecked] = useState<string>('');\n const [originalEmail, setOriginalEmail] = useState<string>('');\n const [isCompanyAdmin, setIsCompanyAdmin] = useState<boolean>(false);\n\n useEffect(() => {\n if (mode !== 'edit' || !entityId) return;\n setLoading(true);\n void getCompanyUser(entityId).then((u) => {\n if (!u) return;\n const loadedEmail = u.email || '';\n setValues((v) => ({ ...v, firstName: u.firstName || '', lastName: u.lastName || '', email: loadedEmail, jobTitle: u.jobTitle || '', telephone: u.telephone || '', status: (u.status || 'ACTIVE') as UserStatus }));\n setOriginalEmail(loadedEmail);\n if (u?.role?.id) setValues((v) => ({ ...v, roleId: u.role!.id }));\n setIsCompanyAdmin(u?.isCompanyAdmin ?? false);\n }).finally(() => setLoading(false));\n }, [mode, entityId]);\n\n const isEmailValid = (value: string): boolean => /.+@.+\\..+/.test(value);\n const validateField = (field: keyof CompanyUserModel | 'roleId', value: any): string | null => {\n if (field === 'firstName') {\n if (!value?.trim()) return translations.firstNameRequired;\n if (value.length > FIELD_MAX_LENGTHS.firstName) return translations.firstNameMaxLength;\n return null;\n }\n if (field === 'lastName') {\n if (!value?.trim()) return translations.lastNameRequired;\n if (value.length > FIELD_MAX_LENGTHS.lastName) return translations.lastNameMaxLength;\n return null;\n }\n if (field === 'email') {\n if (!value?.trim()) return translations.emailRequired;\n if (value.length > FIELD_MAX_LENGTHS.email) return translations.emailMaxLength;\n return isEmailValid(value.trim()) ? null : translations.emailInvalid;\n }\n // jobTitle and telephone are now optional fields (USF-3012)\n if (field === 'jobTitle') {\n if (value && value.length > FIELD_MAX_LENGTHS.jobTitle) return translations.jobTitleMaxLength;\n return null;\n }\n if (field === 'telephone') {\n if (value && value.length > FIELD_MAX_LENGTHS.telephone) return translations.telephoneMaxLength;\n return null;\n }\n if (field === 'roleId') return value ? null : translations.selectRole;\n return null;\n };\n\n const setValue = (field: keyof CompanyUserModel | 'roleId', value: any) => {\n setValues((v) => ({ ...v, [field]: value }));\n if (field === 'email') setEmailAvailable(null);\n if (generalError) setGeneralError(null);\n };\n\n const onBlur = async (field: keyof CompanyUserModel | 'roleId', value?: any) => {\n // Update form data if value is provided (this preserves spaces and other characters)\n if (value !== undefined) {\n setValue(field, value);\n }\n \n setTouched((t) => ({ ...t, [field]: true }));\n \n // Use provided value or current state value for validation\n const valueToValidate = value !== undefined ? value : values[field];\n const err = validateField(field, valueToValidate);\n if (err) {\n setErrors((p) => ({ ...p, [field]: err }));\n } else {\n // Clear error if field is now valid\n setErrors((p) => {\n const newErrors = { ...p };\n delete newErrors[field];\n return newErrors;\n });\n }\n \n if (field === 'email') {\n const emailValue = value !== undefined ? value : (values.email || '');\n const trimmed = emailValue.trim();\n if (mode === 'edit' && trimmed.toLowerCase() === (originalEmail || '').trim().toLowerCase()) {\n setEmailAvailable(null);\n return;\n }\n if (isEmailValid(trimmed) && trimmed !== emailChecked) {\n const available = await isCompanyUserEmailAvailable(trimmed);\n setEmailChecked(trimmed);\n setEmailAvailable(available);\n if (available === false) setErrors((p) => ({ ...p, email: 'A user with this email address is already a member of your company.' }));\n }\n }\n };\n\n const submit = async () => {\n // Validate all fields including optional ones for length (USF-3474)\n const fields: (keyof CompanyUserModel | 'roleId')[] = ['firstName', 'lastName', 'email', 'roleId', 'jobTitle', 'telephone'];\n const next: Record<string, string> = {};\n const touchedFields: Record<string, boolean> = {};\n \n for (const f of fields) {\n touchedFields[f as string] = true;\n const err = validateField(f, values[f]);\n if (err) next[f as string] = err;\n }\n \n setErrors(next);\n setTouched(touchedFields);\n \n if (Object.keys(next).length || emailAvailable === false) {\n // Scroll to the first error field\n setTimeout(() => {\n const firstErrorField = document.querySelector('.company-user-form__content .dropin-field__hint--error');\n if (firstErrorField) {\n const fieldContainer = firstErrorField.closest('.dropin-field');\n if (fieldContainer) {\n fieldContainer.scrollIntoView({ behavior: 'smooth', block: 'center' });\n const input = fieldContainer.querySelector('input, select') as HTMLElement;\n if (input) {\n input.focus();\n }\n }\n }\n }, 100);\n return;\n }\n\n const label = `${values.firstName || ''} ${values.lastName || ''}`.trim() || values.email || '';\n const adminEffective = isCompanyAdmin || isCompanyAdministrator({ id: values.roleId });\n const effectiveStatus = adminEffective ? 'ACTIVE' : values.status;\n try {\n if (mode === 'add') {\n const res = await createCompanyUser({ email: values.email || '', firstName: values.firstName || '', lastName: values.lastName || '', jobTitle: values.jobTitle || '', telephone: values.telephone || '', roleId: values.roleId, status: effectiveStatus, targetId: parentStructureId ?? null });\n if (!res) {\n const errorMessage = translations.createUserError;\n if (onError) {\n onError(errorMessage);\n } else {\n setGeneralError(errorMessage);\n }\n return;\n }\n onSaved({ label, structureId: res.structureId, entityId: res.id, type: 'user', status: effectiveStatus, jobTitle: res.jobTitle });\n if (onSuccess) {\n onSuccess(translations.createUserSuccess);\n }\n } else if (entityId) {\n await updateCompanyUser({ id: entityId, email: values.email || '', firstName: values.firstName || '', lastName: values.lastName || '', jobTitle: values.jobTitle || '', telephone: values.telephone || '', status: effectiveStatus, roleId: values.roleId });\n onSaved({ label, entityId, type: 'user', status: effectiveStatus, jobTitle: values.jobTitle });\n if (onSuccess) {\n onSuccess(translations.updateUserSuccess);\n }\n }\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : translations.saveUserError;\n if (onError) {\n onError(errorMessage);\n } else {\n setGeneralError(errorMessage);\n }\n }\n };\n\n return { values, errors, touched, loading, setValue, onBlur, submit, isCompanyAdmin, generalError };\n}\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport { FunctionComponent } from 'preact';\nimport { memo } from 'preact/compat';\nimport { useState } from 'preact/hooks';\nimport { Field, Input, Button, Card, Picker, ProgressSpinner, InLineAlert } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { CompanyUserFormLoader } from '@/company-management/components/CompanyLoaders';\nimport { useCompanyUserForm, FIELD_MAX_LENGTHS } from '@/company-management/hooks/useCompanyUserForm';\nimport { useCompanyRoles } from '@/company-management/hooks/useCompanyRoles';\nimport { CompanyUserFormProps } from '@/company-management/types/companyForm.types';\nimport './CompanyUserForm.css';\n\n/**\n * CompanyUserForm component for creating and editing company users\n * Provides form fields for user information including name, email, role, and status\n */\nexport const CompanyUserForm: FunctionComponent<CompanyUserFormProps> = memo(({ mode, entityId, parentStructureId, permissions, onSaved, onCancel, onError, onSuccess }) => {\n const canEditUsers = permissions?.canEditUsers ?? false;\n const { roles, isLoading: rolesLoading } = useCompanyRoles();\n const { values, errors, touched, loading, setValue, onBlur, submit, isCompanyAdmin, generalError } = useCompanyUserForm({ \n mode, \n entityId, \n parentStructureId, \n onSaved,\n onError: onError ? (error: string) => {\n onError(error);\n onCancel();\n } : undefined,\n onSuccess\n });\n const [saving, setSaving] = useState(false);\n \n const translations = useText({\n addUser: 'Company.CompanyStructure.shared.titles.addUser',\n editUser: 'Company.CompanyStructure.shared.titles.editUser',\n jobTitle: 'Company.CompanyStructure.shared.fields.jobTitle',\n userRole: 'Company.CompanyStructure.shared.fields.userRole',\n firstName: 'Company.CompanyStructure.shared.fields.firstName',\n lastName: 'Company.CompanyStructure.shared.fields.lastName',\n email: 'Company.CompanyStructure.shared.fields.email',\n workPhoneNumber: 'Company.CompanyStructure.shared.fields.workPhoneNumber',\n status: 'Company.CompanyStructure.shared.fields.status',\n selectRole: 'Company.CompanyStructure.shared.options.selectRole',\n active: 'Company.CompanyStructure.shared.options.active',\n inactive: 'Company.CompanyStructure.shared.options.inactive',\n companyAdministrator: 'Company.CompanyStructure.shared.options.companyAdministrator',\n save: 'Company.CompanyStructure.shared.buttons.save',\n cancel: 'Company.CompanyStructure.shared.buttons.cancel',\n });\n\n return (\n <div>\n <h3 className=\"acm-structure-panel__title\">{mode === 'add' ? translations.addUser : translations.editUser}</h3>\n <Card variant=\"secondary\" className={`company-user-form__card ${saving ? 'is-working' : ''}`}>\n {!onError && generalError ? (\n <InLineAlert \n className=\"company-user-form__notification\" \n type=\"error\" \n variant=\"secondary\" \n heading={generalError} \n />\n ) : null}\n {saving ? <div className=\"company-user-form__overlay\" aria-live=\"polite\"><ProgressSpinner size=\"small\" /></div> : null}\n {loading || rolesLoading ? (\n <CompanyUserFormLoader />\n ) : (\n <div className=\"company-user-form__content\">\n\n <Field label={translations.jobTitle} className=\"acm-structure-panel__field\" error={touched.jobTitle && errors.jobTitle ? errors.jobTitle : undefined}>\n <Input name=\"job_title\" type=\"text\" value={values.jobTitle || ''} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('jobTitle', target.value); }} variant=\"primary\" size=\"medium\" maxLength={FIELD_MAX_LENGTHS.jobTitle} />\n </Field>\n\n <Field label={translations.userRole} required className=\"acm-structure-panel__field\" error={!isCompanyAdmin && touched.roleId && errors.roleId ? errors.roleId : undefined} disabled={isCompanyAdmin}>\n {isCompanyAdmin ? (\n <Picker name=\"role\" value={'MA=='} options={[{ value: 'MA==', text: translations.companyAdministrator }]} />\n ) : (\n <Picker\n name=\"role\"\n value={values.roleId || 'placeholder'}\n onChange={(e: any) => setValue('roleId', String(e?.target?.value === 'placeholder' ? '' : e?.target?.value ?? ''))}\n onBlur={(e: Event) => { const target = e.target as HTMLSelectElement; void onBlur('roleId', target.value === 'placeholder' ? '' : target.value); }}\n options={[{ value: 'placeholder', text: translations.selectRole, disabled: true }, ...roles.map((r) => ({ value: r.id, text: r.name }))]}\n />\n )}\n </Field>\n\n <Field label={translations.firstName} required className=\"acm-structure-panel__field\" error={touched.firstName && errors.firstName ? errors.firstName : undefined}>\n <Input name=\"first_name\" type=\"text\" value={values.firstName} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('firstName', target.value); }} variant=\"primary\" size=\"medium\" maxLength={FIELD_MAX_LENGTHS.firstName} />\n </Field>\n\n <Field label={translations.lastName} required className=\"acm-structure-panel__field\" error={touched.lastName && errors.lastName ? errors.lastName : undefined}>\n <Input name=\"last_name\" type=\"text\" value={values.lastName} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('lastName', target.value); }} variant=\"primary\" size=\"medium\" maxLength={FIELD_MAX_LENGTHS.lastName} />\n </Field>\n\n <Field label={translations.email} required className=\"acm-structure-panel__field\" error={touched.email && errors.email ? errors.email : undefined}>\n <Input name=\"email\" type=\"email\" value={values.email} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; void onBlur('email', target.value); }} placeholder=\"jdoe@example.com\" variant=\"primary\" size=\"medium\" maxLength={FIELD_MAX_LENGTHS.email} />\n </Field>\n\n <Field label={translations.workPhoneNumber} className=\"acm-structure-panel__field\" error={touched.telephone && errors.telephone ? errors.telephone : undefined}>\n <Input name=\"telephone\" type=\"text\" value={values.telephone || ''} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('telephone', target.value); }} variant=\"primary\" size=\"medium\" maxLength={FIELD_MAX_LENGTHS.telephone} />\n </Field>\n\n <Field label={translations.status} className=\"acm-structure-panel__field\" disabled={isCompanyAdmin || !canEditUsers}>\n <Picker\n name=\"status\"\n value={values.status}\n onChange={(e: any) => setValue('status', String(e?.target?.value ?? 'ACTIVE'))}\n options={[{ value: 'ACTIVE', text: translations.active }, { value: 'INACTIVE', text: translations.inactive }]}\n />\n </Field>\n </div>\n )}\n </Card>\n {!(loading || rolesLoading) ? (\n <div className=\"acm-structure-modal__actions\">\n <Button type=\"button\" variant=\"primary\" disabled={saving || !canEditUsers} onClick={async () => { if (saving) return; setSaving(true); try { await submit(); } finally { setSaving(false); } }}>\n {translations.save}\n </Button>\n <Button\n type=\"button\"\n variant=\"secondary\"\n disabled={saving}\n onClick={onCancel}\n >\n {translations.cancel}\n </Button>\n </div>\n ) : null}\n </div>\n );\n});\n\nexport default CompanyUserForm;\n"],"names":["FIELD_MAX_LENGTHS","useCompanyUserForm","opts","mode","entityId","parentStructureId","onSaved","onError","onSuccess","translations","useText","values","setValues","useState","errors","setErrors","touched","setTouched","loading","setLoading","generalError","setGeneralError","emailAvailable","setEmailAvailable","emailChecked","setEmailChecked","originalEmail","setOriginalEmail","isCompanyAdmin","setIsCompanyAdmin","useEffect","getCompanyUser","u","loadedEmail","v","_a","isEmailValid","value","validateField","field","setValue","t","valueToValidate","err","p","newErrors","trimmed","available","isCompanyUserEmailAvailable","fields","next","touchedFields","f","firstErrorField","fieldContainer","input","label","effectiveStatus","isCompanyAdministrator","res","createCompanyUser","errorMessage","updateCompanyUser","error","CompanyUserForm","memo","permissions","onCancel","canEditUsers","roles","rolesLoading","useCompanyRoles","onBlur","submit","saving","setSaving","jsx","jsxs","Card","InLineAlert","ProgressSpinner","CompanyUserFormLoader","Field","Input","e","target","Picker","_b","r","Button"],"mappings":"ukBAyBO,MAAMA,EAAoB,CAC/B,UAAW,IACX,SAAU,IACV,MAAO,IACP,SAAU,IACV,UAAW,EACb,EAEO,SAASC,GAAmBC,EAOhC,CACD,KAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,kBAAAC,EAAmB,QAAAC,EAAS,QAAAC,EAAS,UAAAC,GAAcN,EAErEO,EAAeC,EAAQ,CAC3B,kBAAmB,+DACnB,iBAAkB,8DAClB,cAAe,2DACf,aAAc,0DACd,iBAAkB,8DAClB,kBAAmB,+DACnB,WAAY,wDACZ,mBAAoB,gEACpB,kBAAmB,+DACnB,eAAgB,4DAChB,kBAAmB,+DACnB,mBAAoB,gEACpB,gBAAiB,oDACjB,cAAe,kDACf,kBAAmB,sDACnB,kBAAmB,qDAAA,CACpB,EACK,CAACC,EAAQC,CAAS,EAAIC,EAA6E,CACvG,UAAW,GACX,SAAU,GACV,MAAO,GACP,SAAU,GACV,UAAW,GACX,OAAQ,GACR,OAAQ,QAAA,CACT,EACK,CAACC,EAAQC,CAAS,EAAIF,EAAiC,CAAA,CAAE,EACzD,CAACG,EAASC,CAAU,EAAIJ,EAAkC,CAAA,CAAE,EAC5D,CAACK,EAASC,CAAU,EAAIN,EAAS,EAAK,EACtC,CAACO,EAAcC,CAAe,EAAIR,EAAwB,IAAI,EAC9D,CAACS,EAAgBC,CAAiB,EAAIV,EAAyB,IAAI,EACnE,CAACW,EAAcC,CAAe,EAAIZ,EAAiB,EAAE,EACrD,CAACa,EAAeC,CAAgB,EAAId,EAAiB,EAAE,EACvD,CAACe,EAAgBC,CAAiB,EAAIhB,EAAkB,EAAK,EAEnEiB,EAAU,IAAM,CACV3B,IAAS,QAAU,CAACC,IACxBe,EAAW,EAAI,EACVY,EAAe3B,CAAQ,EAAE,KAAM4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GAAU,CAACN,EAAc,QAAS,SAAY,CAAE,GAAI,CAAAM,EAAgB,CAAAC,EAAU,EAAI,EAAG,GAAI,CAAE,MAAMF,EAAA,CAAU,QAAA,CAAYE,EAAU,EAAK,CAAG,EAAE,EAC1L,WAAa,KAChB,EACAC,EAACa,EAAA,CACC,KAAK,SACL,QAAQ,YACR,SAAUf,EACV,QAASP,EAER,SAAA1D,EAAa,MAAA,CAAA,CAChB,CAAA,CACF,CACE,EACN,CAEJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"CompanyUserForm.js","sources":["/@dropins/storefront-company-management/src/hooks/useCompanyUserForm.ts","/@dropins/storefront-company-management/src/components/CompanyUserForm/CompanyUserForm.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport { useEffect, useState } from 'preact/hooks';\nimport { createCompanyUser, getCompanyUser, isCompanyUserEmailAvailable, updateCompanyUser } from '@/company-management/api';\nimport { isCompanyAdministrator } from '@/company-management/lib';\nimport { CompanyUserModel } from '@/company-management/data/models';\nimport { useText } from '@adobe-commerce/elsie/i18n';\n\nexport type UserStatus = 'ACTIVE' | 'INACTIVE';\n\n// Field length constants (based on Magento backend validation)\nexport const FIELD_MAX_LENGTHS = {\n firstName: 255,\n lastName: 255,\n email: 254,\n jobTitle: 255,\n telephone: 20,\n} as const;\n\n// Character validation patterns (USF-3474)\nconst VALIDATION_PATTERNS = {\n // Match Magento's Name validator: /(?:[\\p{L}\\p{M}\\,\\-\\_\\.\\''`&\\s\\d]){1,255}+/u\n name: /^[a-zA-ZÀ-ÿ0-9\\s,\\-_.'`&]+$/,\n // Match Magento's Telephone validator: /(?:[\\d\\s\\+\\-\\()]{1,20})/u\n telephone: /^[\\d\\s+\\-()]+$/,\n} as const;\n\nexport function useCompanyUserForm(opts: {\n mode: 'add' | 'edit';\n entityId?: string;\n parentStructureId?: string | null;\n onSaved: (result: { label: string; structureId?: string; entityId?: string; type: 'user'; status?: UserStatus; jobTitle?: string | null }) => void;\n onError?: (error: string) => void;\n onSuccess?: (message: string) => void;\n}) {\n const { mode, entityId, parentStructureId, onSaved, onError, onSuccess } = opts;\n \n const translations = useText({\n firstNameRequired: 'Company.CompanyStructure.shared.validation.firstNameRequired',\n lastNameRequired: 'Company.CompanyStructure.shared.validation.lastNameRequired',\n emailRequired: 'Company.CompanyStructure.shared.validation.emailRequired',\n emailInvalid: 'Company.CompanyStructure.shared.validation.emailInvalid',\n jobTitleRequired: 'Company.CompanyStructure.shared.validation.jobTitleRequired',\n workPhoneRequired: 'Company.CompanyStructure.shared.validation.workPhoneRequired',\n selectRole: 'Company.CompanyStructure.shared.validation.selectRole',\n firstNameMaxLength: 'Company.CompanyStructure.shared.validation.firstNameMaxLength',\n lastNameMaxLength: 'Company.CompanyStructure.shared.validation.lastNameMaxLength',\n emailMaxLength: 'Company.CompanyStructure.shared.validation.emailMaxLength',\n jobTitleMaxLength: 'Company.CompanyStructure.shared.validation.jobTitleMaxLength',\n telephoneMaxLength: 'Company.CompanyStructure.shared.validation.telephoneMaxLength',\n firstNameInvalidChars: 'Company.CompanyStructure.shared.validation.firstNameInvalidChars',\n lastNameInvalidChars: 'Company.CompanyStructure.shared.validation.lastNameInvalidChars',\n telephoneInvalidChars: 'Company.CompanyStructure.shared.validation.telephoneInvalidChars',\n createUserError: 'Company.CompanyStructure.messages.createUserError',\n saveUserError: 'Company.CompanyStructure.messages.saveUserError',\n createUserSuccess: 'Company.CompanyStructure.messages.createUserSuccess',\n updateUserSuccess: 'Company.CompanyStructure.messages.updateUserSuccess',\n });\n const [values, setValues] = useState<Partial<CompanyUserModel> & { roleId: string; status: UserStatus }>({ \n firstName: '', \n lastName: '', \n email: '', \n jobTitle: '', \n telephone: '', \n roleId: '', \n status: 'ACTIVE' \n });\n const [errors, setErrors] = useState<Record<string, string>>({});\n const [touched, setTouched] = useState<Record<string, boolean>>({});\n const [loading, setLoading] = useState(false);\n const [generalError, setGeneralError] = useState<string | null>(null);\n const [emailAvailable, setEmailAvailable] = useState<boolean | null>(null);\n const [emailChecked, setEmailChecked] = useState<string>('');\n const [originalEmail, setOriginalEmail] = useState<string>('');\n const [isCompanyAdmin, setIsCompanyAdmin] = useState<boolean>(false);\n\n useEffect(() => {\n if (mode !== 'edit' || !entityId) return;\n setLoading(true);\n void getCompanyUser(entityId).then((u) => {\n if (!u) return;\n const loadedEmail = u.email || '';\n setValues((v) => ({ ...v, firstName: u.firstName || '', lastName: u.lastName || '', email: loadedEmail, jobTitle: u.jobTitle || '', telephone: u.telephone || '', status: (u.status || 'ACTIVE') as UserStatus }));\n setOriginalEmail(loadedEmail);\n if (u?.role?.id) setValues((v) => ({ ...v, roleId: u.role!.id }));\n setIsCompanyAdmin(u?.isCompanyAdmin ?? false);\n }).finally(() => setLoading(false));\n }, [mode, entityId]);\n\n const isEmailValid = (value: string): boolean => /.+@.+\\..+/.test(value);\n const validateField = (field: keyof CompanyUserModel | 'roleId', value: any): string | null => {\n if (field === 'firstName') {\n if (!value?.trim()) return translations.firstNameRequired;\n if (value.length > FIELD_MAX_LENGTHS.firstName) return translations.firstNameMaxLength;\n if (!VALIDATION_PATTERNS.name.test(value)) return translations.firstNameInvalidChars;\n return null;\n }\n if (field === 'lastName') {\n if (!value?.trim()) return translations.lastNameRequired;\n if (value.length > FIELD_MAX_LENGTHS.lastName) return translations.lastNameMaxLength;\n if (!VALIDATION_PATTERNS.name.test(value)) return translations.lastNameInvalidChars;\n return null;\n }\n if (field === 'email') {\n if (!value?.trim()) return translations.emailRequired;\n if (value.length > FIELD_MAX_LENGTHS.email) return translations.emailMaxLength;\n return isEmailValid(value.trim()) ? null : translations.emailInvalid;\n }\n // jobTitle and telephone are now optional fields (USF-3012)\n if (field === 'jobTitle') {\n if (value && value.length > FIELD_MAX_LENGTHS.jobTitle) return translations.jobTitleMaxLength;\n return null;\n }\n if (field === 'telephone') {\n if (value && value.length > FIELD_MAX_LENGTHS.telephone) return translations.telephoneMaxLength;\n if (value && value.trim() && !VALIDATION_PATTERNS.telephone.test(value)) return translations.telephoneInvalidChars;\n return null;\n }\n if (field === 'roleId') return value ? null : translations.selectRole;\n return null;\n };\n\n const setValue = (field: keyof CompanyUserModel | 'roleId', value: any) => {\n setValues((v) => ({ ...v, [field]: value }));\n if (field === 'email') setEmailAvailable(null);\n if (generalError) setGeneralError(null);\n };\n\n const onBlur = async (field: keyof CompanyUserModel | 'roleId', value?: any) => {\n // Update form data if value is provided (this preserves spaces and other characters)\n if (value !== undefined) {\n setValue(field, value);\n }\n \n setTouched((t) => ({ ...t, [field]: true }));\n \n // Use provided value or current state value for validation\n const valueToValidate = value !== undefined ? value : values[field];\n const err = validateField(field, valueToValidate);\n if (err) {\n setErrors((p) => ({ ...p, [field]: err }));\n } else {\n // Clear error if field is now valid\n setErrors((p) => {\n const newErrors = { ...p };\n delete newErrors[field];\n return newErrors;\n });\n }\n \n if (field === 'email') {\n const emailValue = value !== undefined ? value : (values.email || '');\n const trimmed = emailValue.trim();\n if (mode === 'edit' && trimmed.toLowerCase() === (originalEmail || '').trim().toLowerCase()) {\n setEmailAvailable(null);\n return;\n }\n if (isEmailValid(trimmed) && trimmed !== emailChecked) {\n const available = await isCompanyUserEmailAvailable(trimmed);\n setEmailChecked(trimmed);\n setEmailAvailable(available);\n if (available === false) setErrors((p) => ({ ...p, email: 'A user with this email address is already a member of your company.' }));\n }\n }\n };\n\n const submit = async () => {\n // Validate all fields including optional ones for length (USF-3474)\n const fields: (keyof CompanyUserModel | 'roleId')[] = ['firstName', 'lastName', 'email', 'roleId', 'jobTitle', 'telephone'];\n const next: Record<string, string> = {};\n const touchedFields: Record<string, boolean> = {};\n \n for (const f of fields) {\n touchedFields[f as string] = true;\n const err = validateField(f, values[f]);\n if (err) next[f as string] = err;\n }\n \n setErrors(next);\n setTouched(touchedFields);\n \n if (Object.keys(next).length || emailAvailable === false) {\n // Scroll to the first error field\n setTimeout(() => {\n const firstErrorField = document.querySelector('.company-user-form__content .dropin-field__hint--error');\n if (firstErrorField) {\n const fieldContainer = firstErrorField.closest('.dropin-field');\n if (fieldContainer) {\n fieldContainer.scrollIntoView({ behavior: 'smooth', block: 'center' });\n const input = fieldContainer.querySelector('input, select') as HTMLElement;\n if (input) {\n input.focus();\n }\n }\n }\n }, 100);\n return;\n }\n\n const label = `${values.firstName || ''} ${values.lastName || ''}`.trim() || values.email || '';\n const adminEffective = isCompanyAdmin || isCompanyAdministrator({ id: values.roleId });\n const effectiveStatus = adminEffective ? 'ACTIVE' : values.status;\n try {\n if (mode === 'add') {\n const res = await createCompanyUser({ email: values.email || '', firstName: values.firstName || '', lastName: values.lastName || '', jobTitle: values.jobTitle || '', telephone: values.telephone || '', roleId: values.roleId, status: effectiveStatus, targetId: parentStructureId ?? null });\n if (!res) {\n const errorMessage = translations.createUserError;\n if (onError) {\n onError(errorMessage);\n } else {\n setGeneralError(errorMessage);\n }\n return;\n }\n onSaved({ label, structureId: res.structureId, entityId: res.id, type: 'user', status: effectiveStatus, jobTitle: res.jobTitle });\n if (onSuccess) {\n onSuccess(translations.createUserSuccess);\n }\n } else if (entityId) {\n await updateCompanyUser({ id: entityId, email: values.email || '', firstName: values.firstName || '', lastName: values.lastName || '', jobTitle: values.jobTitle || '', telephone: values.telephone || '', status: effectiveStatus, roleId: values.roleId });\n onSaved({ label, entityId, type: 'user', status: effectiveStatus, jobTitle: values.jobTitle });\n if (onSuccess) {\n onSuccess(translations.updateUserSuccess);\n }\n }\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : translations.saveUserError;\n if (onError) {\n onError(errorMessage);\n } else {\n setGeneralError(errorMessage);\n }\n }\n };\n\n return { values, errors, touched, loading, setValue, onBlur, submit, isCompanyAdmin, generalError };\n}\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport { FunctionComponent } from 'preact';\nimport { memo } from 'preact/compat';\nimport { useState } from 'preact/hooks';\nimport { Field, Input, Button, Card, Picker, ProgressSpinner, InLineAlert } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { CompanyUserFormLoader } from '@/company-management/components/CompanyLoaders';\nimport { useCompanyUserForm, FIELD_MAX_LENGTHS } from '@/company-management/hooks/useCompanyUserForm';\nimport { useCompanyRoles } from '@/company-management/hooks/useCompanyRoles';\nimport { CompanyUserFormProps } from '@/company-management/types/companyForm.types';\nimport './CompanyUserForm.css';\n\n/**\n * CompanyUserForm component for creating and editing company users\n * Provides form fields for user information including name, email, role, and status\n */\nexport const CompanyUserForm: FunctionComponent<CompanyUserFormProps> = memo(({ mode, entityId, parentStructureId, permissions, onSaved, onCancel, onError, onSuccess }) => {\n const canEditUsers = permissions?.canEditUsers ?? false;\n const { roles, isLoading: rolesLoading } = useCompanyRoles();\n const { values, errors, touched, loading, setValue, onBlur, submit, isCompanyAdmin, generalError } = useCompanyUserForm({ \n mode, \n entityId, \n parentStructureId, \n onSaved,\n onError: onError ? (error: string) => {\n onError(error);\n onCancel();\n } : undefined,\n onSuccess\n });\n const [saving, setSaving] = useState(false);\n \n const translations = useText({\n addUser: 'Company.CompanyStructure.shared.titles.addUser',\n editUser: 'Company.CompanyStructure.shared.titles.editUser',\n jobTitle: 'Company.CompanyStructure.shared.fields.jobTitle',\n userRole: 'Company.CompanyStructure.shared.fields.userRole',\n firstName: 'Company.CompanyStructure.shared.fields.firstName',\n lastName: 'Company.CompanyStructure.shared.fields.lastName',\n email: 'Company.CompanyStructure.shared.fields.email',\n workPhoneNumber: 'Company.CompanyStructure.shared.fields.workPhoneNumber',\n status: 'Company.CompanyStructure.shared.fields.status',\n selectRole: 'Company.CompanyStructure.shared.options.selectRole',\n active: 'Company.CompanyStructure.shared.options.active',\n inactive: 'Company.CompanyStructure.shared.options.inactive',\n companyAdministrator: 'Company.CompanyStructure.shared.options.companyAdministrator',\n save: 'Company.CompanyStructure.shared.buttons.save',\n cancel: 'Company.CompanyStructure.shared.buttons.cancel',\n });\n\n return (\n <div>\n <h3 className=\"acm-structure-panel__title\">{mode === 'add' ? translations.addUser : translations.editUser}</h3>\n <Card variant=\"secondary\" className={`company-user-form__card ${saving ? 'is-working' : ''}`}>\n {!onError && generalError ? (\n <InLineAlert \n className=\"company-user-form__notification\" \n type=\"error\" \n variant=\"secondary\" \n heading={generalError} \n />\n ) : null}\n {saving ? <div className=\"company-user-form__overlay\" aria-live=\"polite\"><ProgressSpinner size=\"small\" /></div> : null}\n {loading || rolesLoading ? (\n <CompanyUserFormLoader />\n ) : (\n <div className=\"company-user-form__content\">\n\n <Field label={translations.jobTitle} className=\"acm-structure-panel__field\" error={touched.jobTitle && errors.jobTitle ? errors.jobTitle : undefined}>\n <Input name=\"job_title\" type=\"text\" value={values.jobTitle || ''} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('jobTitle', target.value); }} variant=\"primary\" size=\"medium\" maxLength={FIELD_MAX_LENGTHS.jobTitle} />\n </Field>\n\n <Field label={translations.userRole} required className=\"acm-structure-panel__field\" error={!isCompanyAdmin && touched.roleId && errors.roleId ? errors.roleId : undefined} disabled={isCompanyAdmin}>\n {isCompanyAdmin ? (\n <Picker name=\"role\" value={'MA=='} options={[{ value: 'MA==', text: translations.companyAdministrator }]} />\n ) : (\n <Picker\n name=\"role\"\n value={values.roleId || 'placeholder'}\n onChange={(e: any) => setValue('roleId', String(e?.target?.value === 'placeholder' ? '' : e?.target?.value ?? ''))}\n onBlur={(e: Event) => { const target = e.target as HTMLSelectElement; void onBlur('roleId', target.value === 'placeholder' ? '' : target.value); }}\n options={[{ value: 'placeholder', text: translations.selectRole, disabled: true }, ...roles.map((r) => ({ value: r.id, text: r.name }))]}\n />\n )}\n </Field>\n\n <Field label={translations.firstName} required className=\"acm-structure-panel__field\" error={touched.firstName && errors.firstName ? errors.firstName : undefined}>\n <Input name=\"first_name\" type=\"text\" value={values.firstName} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('firstName', target.value); }} variant=\"primary\" size=\"medium\" maxLength={FIELD_MAX_LENGTHS.firstName} />\n </Field>\n\n <Field label={translations.lastName} required className=\"acm-structure-panel__field\" error={touched.lastName && errors.lastName ? errors.lastName : undefined}>\n <Input name=\"last_name\" type=\"text\" value={values.lastName} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('lastName', target.value); }} variant=\"primary\" size=\"medium\" maxLength={FIELD_MAX_LENGTHS.lastName} />\n </Field>\n\n <Field label={translations.email} required className=\"acm-structure-panel__field\" error={touched.email && errors.email ? errors.email : undefined}>\n <Input name=\"email\" type=\"email\" value={values.email} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; void onBlur('email', target.value); }} placeholder=\"jdoe@example.com\" variant=\"primary\" size=\"medium\" maxLength={FIELD_MAX_LENGTHS.email} />\n </Field>\n\n <Field label={translations.workPhoneNumber} className=\"acm-structure-panel__field\" error={touched.telephone && errors.telephone ? errors.telephone : undefined}>\n <Input name=\"telephone\" type=\"text\" value={values.telephone || ''} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('telephone', target.value); }} variant=\"primary\" size=\"medium\" maxLength={FIELD_MAX_LENGTHS.telephone} />\n </Field>\n\n <Field label={translations.status} className=\"acm-structure-panel__field\" disabled={isCompanyAdmin || !canEditUsers}>\n <Picker\n name=\"status\"\n value={values.status}\n onChange={(e: any) => setValue('status', String(e?.target?.value ?? 'ACTIVE'))}\n options={[{ value: 'ACTIVE', text: translations.active }, { value: 'INACTIVE', text: translations.inactive }]}\n />\n </Field>\n </div>\n )}\n </Card>\n {!(loading || rolesLoading) ? (\n <div className=\"acm-structure-modal__actions\">\n <Button type=\"button\" variant=\"primary\" disabled={saving || !canEditUsers} onClick={async () => { if (saving) return; setSaving(true); try { await submit(); } finally { setSaving(false); } }}>\n {translations.save}\n </Button>\n <Button\n type=\"button\"\n variant=\"secondary\"\n disabled={saving}\n onClick={onCancel}\n >\n {translations.cancel}\n </Button>\n </div>\n ) : null}\n </div>\n );\n});\n\nexport default CompanyUserForm;\n"],"names":["FIELD_MAX_LENGTHS","VALIDATION_PATTERNS","useCompanyUserForm","opts","mode","entityId","parentStructureId","onSaved","onError","onSuccess","translations","useText","values","setValues","useState","errors","setErrors","touched","setTouched","loading","setLoading","generalError","setGeneralError","emailAvailable","setEmailAvailable","emailChecked","setEmailChecked","originalEmail","setOriginalEmail","isCompanyAdmin","setIsCompanyAdmin","useEffect","getCompanyUser","u","loadedEmail","v","_a","isEmailValid","value","validateField","field","setValue","t","valueToValidate","err","p","newErrors","trimmed","available","isCompanyUserEmailAvailable","fields","next","touchedFields","f","firstErrorField","fieldContainer","input","label","effectiveStatus","isCompanyAdministrator","res","createCompanyUser","errorMessage","updateCompanyUser","error","CompanyUserForm","memo","permissions","onCancel","canEditUsers","roles","rolesLoading","useCompanyRoles","onBlur","submit","saving","setSaving","jsx","jsxs","Card","InLineAlert","ProgressSpinner","CompanyUserFormLoader","Field","Input","e","target","Picker","_b","r","Button"],"mappings":"wkBAyBO,MAAMA,EAAoB,CAC/B,UAAW,IACX,SAAU,IACV,MAAO,IACP,SAAU,IACV,UAAW,EACb,EAGMC,EAAsB,CAE1B,KAAM,8BAEN,UAAW,gBACb,EAEO,SAASC,GAAmBC,EAOhC,CACD,KAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,kBAAAC,EAAmB,QA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,EAAG,GAAI,CAAE,MAAMF,EAAA,CAAU,QAAA,CAAYE,EAAU,EAAK,CAAG,EAAE,EAC1L,WAAa,KAChB,EACAC,EAACa,EAAA,CACC,KAAK,SACL,QAAQ,YACR,SAAUf,EACV,QAASP,EAER,SAAA1D,EAAa,MAAA,CAAA,CAChB,CAAA,CACF,CACE,EACN,CAEJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsxs as V,jsx as e,Fragment as pe}from"@dropins/tools/preact-jsx-runtime.js";import{useState as b,useEffect as q,useRef as ce,useCallback as B}from"@dropins/tools/preact-hooks.js";import{Slot as Ie,classes as ve}from"@dropins/tools/lib.js";import{Card as re,InLineAlert as ue,ProgressSpinner as de,Field as ye,Input as Ce,Button as k,Modal as fe,IllustratedMessage as Le,Icon as Te,Header as we}from"@dropins/tools/components.js";import{f as he}from"../chunks/fetchUserPermissions.js";import{b as ge}from"../chunks/company-permissions.js";import{useText as K}from"@dropins/tools/i18n.js";import{u as Ee}from"../chunks/useCompanyContextListener.js";import{a as Ne,i as xe}from"../chunks/isCompanyUser.js";import*as Se from"@dropins/tools/preact-compat.js";import{memo as be}from"@dropins/tools/preact-compat.js";import{T as Ue}from"../chunks/Tree.js";import{C as Ae}from"../chunks/CompanyUserForm.js";import{events as se}from"@dropins/tools/event-bus.js";import{p as ie,E as le}from"../chunks/acdl.js";import{g as Ze,c as De,u as _e,a as ke,b as Ve,d as Pe}from"../chunks/updateCompanyTeam.js";import{u as He}from"../chunks/updateCompanyUserStatus.js";import{u as Fe}from"../chunks/useInLineAlert.js";import{C as Re,a as Be}from"../chunks/CompanyLoaders.js";import"../chunks/fetch-error.js";import"../chunks/network-error.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/useCompanyRoles.js";import"../chunks/isCompanyRoleNameAvailable.js";const Oe=l=>Se.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...l},Se.createElement("path",{d:"M12.002 21L11.8275 21.4686C11.981 21.5257 12.1528 21.5041 12.2873 21.4106C12.4218 21.3172 12.502 21.1638 12.502 21H12.002ZM3.89502 17.9823H3.39502C3.39502 18.1912 3.52485 18.378 3.72059 18.4509L3.89502 17.9823ZM3.89502 8.06421L4.07193 7.59655C3.91831 7.53844 3.74595 7.55948 3.61082 7.65284C3.47568 7.74619 3.39502 7.89997 3.39502 8.06421H3.89502ZM12.0007 21H11.5007C11.5007 21.1638 11.5809 21.3172 11.7154 21.4106C11.8499 21.5041 12.0216 21.5257 12.1751 21.4686L12.0007 21ZM20.1076 17.9823L20.282 18.4509C20.4778 18.378 20.6076 18.1912 20.6076 17.9823H20.1076ZM20.1076 8.06421H20.6076C20.6076 7.89997 20.527 7.74619 20.3918 7.65284C20.2567 7.55948 20.0843 7.53844 19.9307 7.59655L20.1076 8.06421ZM12.0007 11.1311L11.8238 10.6634C11.6293 10.737 11.5007 10.9232 11.5007 11.1311H12.0007ZM20.2858 8.53191C20.5441 8.43421 20.6743 8.14562 20.5766 7.88734C20.4789 7.62906 20.1903 7.49889 19.932 7.5966L20.2858 8.53191ZM12.002 4.94826L12.1775 4.48008C12.0605 4.43623 11.9314 4.43775 11.8154 4.48436L12.002 4.94826ZM5.87955 6.87106C5.62334 6.97407 5.49915 7.26528 5.60217 7.52149C5.70518 7.77769 5.99639 7.90188 6.2526 7.79887L5.87955 6.87106ZM18.1932 7.80315C18.4518 7.90008 18.74 7.76904 18.8369 7.51047C18.9338 7.2519 18.8028 6.96371 18.5442 6.86678L18.1932 7.80315ZM12 4.94827L11.5879 5.23148C11.6812 5.36719 11.8353 5.44827 12 5.44827C12.1647 5.44827 12.3188 5.36719 12.4121 5.23148L12 4.94827ZM14.0263 2L14.2028 1.53218C13.9875 1.45097 13.7446 1.52717 13.6143 1.71679L14.0263 2ZM21.8421 4.94827L22.2673 5.2113C22.3459 5.08422 22.3636 4.92863 22.3154 4.78717C22.2673 4.64571 22.1584 4.53319 22.0186 4.48045L21.8421 4.94827ZM9.97368 2L10.3857 1.71679C10.2554 1.52717 10.0125 1.45097 9.79721 1.53218L9.97368 2ZM2.15789 4.94827L1.98142 4.48045C1.84161 4.53319 1.73271 4.64571 1.68456 4.78717C1.63641 4.92863 1.65406 5.08422 1.73267 5.2113L2.15789 4.94827ZM12 11.1256L11.6702 11.5014C11.8589 11.667 12.1411 11.667 12.3298 11.5014L12 11.1256ZM15.0395 8.45812L14.8732 7.98659C14.8131 8.00779 14.7576 8.04028 14.7097 8.08232L15.0395 8.45812ZM23 5.65024L23.3288 6.0269C23.5095 5.86916 23.5527 5.60532 23.4318 5.39817C23.3109 5.19102 23.0599 5.09893 22.8337 5.17871L23 5.65024ZM8.96053 8.45812L9.29034 8.08232C9.24244 8.04028 9.18695 8.00779 9.12685 7.98659L8.96053 8.45812ZM1 5.65024L1.16632 5.17871C0.940115 5.09893 0.689119 5.19102 0.568192 5.39817C0.447264 5.60532 0.49048 5.86916 0.671176 6.0269L1 5.65024ZM12.1764 20.5314L4.06945 17.5137L3.72059 18.4509L11.8275 21.4686L12.1764 20.5314ZM4.39502 17.9823V8.06421H3.39502V17.9823H4.39502ZM3.71811 8.53187L11.8251 11.5987L12.1789 10.6634L4.07193 7.59655L3.71811 8.53187ZM11.502 11.1311V21H12.502V11.1311H11.502ZM12.1751 21.4686L20.282 18.4509L19.9332 17.5137L11.8262 20.5314L12.1751 21.4686ZM20.6076 17.9823V8.06421H19.6076V17.9823H20.6076ZM19.9307 7.59655L11.8238 10.6634L12.1776 11.5987L20.2845 8.53187L19.9307 7.59655ZM11.5007 11.1311V21H12.5007V11.1311H11.5007ZM19.932 7.5966L11.8251 10.6634L12.1789 11.5987L20.2858 8.53191L19.932 7.5966ZM11.8154 4.48436L5.87955 6.87106L6.2526 7.79887L12.1885 5.41217L11.8154 4.48436ZM11.8265 5.41645L18.1932 7.80315L18.5442 6.86678L12.1775 4.48008L11.8265 5.41645ZM11.502 4.94826V11.1311H12.502V4.94826H11.502ZM12.4121 5.23148L14.4384 2.28321L13.6143 1.71679L11.5879 4.66507L12.4121 5.23148ZM13.8498 2.46782L21.6656 5.4161L22.0186 4.48045L14.2028 1.53218L13.8498 2.46782ZM21.4169 4.68525L20.5485 6.08919L21.3989 6.61524L22.2673 5.2113L21.4169 4.68525ZM12.4121 4.66507L10.3857 1.71679L9.56162 2.28321L11.5879 5.23148L12.4121 4.66507ZM9.79721 1.53218L1.98142 4.48045L2.33437 5.4161L10.1502 2.46782L9.79721 1.53218ZM1.73267 5.2113L2.60109 6.61524L3.45154 6.08919L2.58312 4.68525L1.73267 5.2113ZM12.3298 11.5014L15.3693 8.83392L14.7097 8.08232L11.6702 10.7498L12.3298 11.5014ZM15.2058 8.92965L23.1663 6.12177L22.8337 5.17871L14.8732 7.98659L15.2058 8.92965ZM22.6712 5.27358L19.7764 7.80067L20.4341 8.554L23.3288 6.0269L22.6712 5.27358ZM12.3298 10.7498L9.29034 8.08232L8.63072 8.83392L11.6702 11.5014L12.3298 10.7498ZM9.12685 7.98659L1.16632 5.17871L0.83368 6.12177L8.79421 8.92965L9.12685 7.98659ZM0.671176 6.0269L3.56591 8.554L4.22356 7.80067L1.32882 5.27358L0.671176 6.0269Z",fill:"currentColor"})),oe={name:40,description:1e3};function ze(l){const{mode:N,entityId:C,parentStructureId:p,onSaved:t,onError:M,onSuccess:o}=l,r=K({teamTitleRequired:"Company.CompanyStructure.shared.validation.teamTitleRequired",teamNameMaxLength:"Company.CompanyStructure.shared.validation.teamNameMaxLength",teamDescriptionMaxLength:"Company.CompanyStructure.shared.validation.teamDescriptionMaxLength",createTeamError:"Company.CompanyStructure.messages.createTeamError",saveTeamError:"Company.CompanyStructure.messages.saveTeamError",createTeamSuccess:"Company.CompanyStructure.messages.createTeamSuccess",updateTeamSuccess:"Company.CompanyStructure.messages.updateTeamSuccess"}),[d,m]=b({id:"",name:"",description:""}),[u,g]=b({}),[y,w]=b({}),[I,U]=b(!1),[H,P]=b(null);q(()=>{N!=="edit"||!C||(U(!0),Ze(C).then(h=>{h&&m({id:h.id,name:h.name||"",description:h.description||""})}).finally(()=>U(!1)))},[N,C]);const F=(h,S)=>h==="name"?S.trim()?S.length>oe.name?r.teamNameMaxLength:null:r.teamTitleRequired:h==="description"&&S&&S.length>oe.description?r.teamDescriptionMaxLength:null,A=(h,S)=>{m(Z=>({...Z,[h]:S})),H&&P(null)};return{values:d,errors:u,touched:y,loading:I,setValue:A,onBlur:(h,S)=>{S!==void 0&&A(h,S),w(D=>({...D,[h]:!0}));const Z=S!==void 0?S:d[h]||"",E=F(h,Z);g(E?D=>({...D,[h]:E}):D=>{const x={...D};return delete x[h],x})},submit:async()=>{const h=F("name",d.name),S=F("description",d.description||""),Z={},E={name:!0,description:!0};if(h&&(Z.name=h),S&&(Z.description=S),w(E),Object.keys(Z).length>0){g(Z);return}const D=d.name;try{if(N==="add"){const x=await De({name:d.name,description:d.description||null,targetId:p??null});if(!x){const $=r.createTeamError;M?M($):P($);return}t({label:D,structureId:x.structureId,entityId:x.id,type:"team",description:d.description||void 0}),o&&o(r.createTeamSuccess)}else C&&(await _e({id:C,name:d.name,description:d.description||null}),t({label:D,entityId:C,type:"team",description:d.description||void 0}),o&&o(r.updateTeamSuccess))}catch(x){const $=x instanceof Error?x.message:r.saveTeamError;M?M($):P($)}},generalError:H}}const Ye=be(({mode:l,entityId:N,parentStructureId:C,permissions:p,onSaved:t,onCancel:M,onError:o,onSuccess:r})=>{const d=(p==null?void 0:p.canEditUsers)??!1,{values:m,errors:u,touched:g,loading:y,onBlur:w,submit:I,generalError:U}=ze({mode:l,entityId:N,parentStructureId:C,onSaved:t,onError:o?A=>{o(A),M()}:void 0,onSuccess:r}),[H,P]=b(!1),F=K({addTeam:"Company.CompanyStructure.shared.titles.addTeam",editTeam:"Company.CompanyStructure.shared.titles.editTeam",teamTitle:"Company.CompanyStructure.shared.fields.teamTitle",description:"Company.CompanyStructure.shared.fields.description"});return V("div",{children:[e("h3",{className:"acm-structure-panel__title",children:l==="add"?F.addTeam:F.editTeam}),V(re,{variant:"secondary",className:`company-team-form__card ${H?"is-working":""}`,children:[!o&&U?e(ue,{className:"company-team-form__notification",type:"error",variant:"secondary",heading:U}):null,H?e("div",{className:"company-team-form__overlay","aria-live":"polite",children:e(de,{size:"small"})}):null,y?e(Re,{}):V("div",{className:"company-team-form__content",children:[e(ye,{label:F.teamTitle,required:!0,className:"acm-structure-panel__field",error:g.name&&u.name?u.name:void 0,children:e(Ce,{name:"team_title",type:"text",value:m.name,onBlur:A=>{const Y=A.target;w("name",Y.value)},variant:"primary",size:"medium",disabled:!d,maxLength:oe.name})}),e(ye,{label:F.description,className:"acm-structure-panel__field",error:g.description&&u.description?u.description:void 0,children:e(Ce,{name:"team_description",type:"textarea",value:m.description||"",onBlur:A=>{const Y=A.target;w("description",Y.value)},variant:"primary",size:"medium",disabled:!d,maxLength:oe.description})})]})]}),y?null:V("div",{className:"acm-structure-modal__actions",children:[e(k,{type:"button",variant:"primary",onClick:async()=>{if(!H){P(!0);try{await I()}finally{P(!1)}}},disabled:H||!d,children:"Save"}),e(k,{type:"button",variant:"secondary",disabled:H,onClick:M,children:"Cancel"})]})]})});function $e({handleSetInLineAlert:l,permissions:N}={permissions:null}){const C=(N==null?void 0:N.canViewUsers)??!1,p=K({loadError:"Company.CompanyStructure.messages.loadError",updateError:"Company.CompanyStructure.messages.updateError",failedToMoveItem:"Company.CompanyStructure.messages.failedToMoveItem",removeUserSuccess:"Company.CompanyStructure.messages.removeUserSuccess",deleteTeamSuccess:"Company.CompanyStructure.messages.deleteTeamSuccess",removeMultipleSuccess:"Company.CompanyStructure.messages.removeMultipleSuccess",moveUserSuccess:"Company.CompanyStructure.messages.moveUserSuccess",moveTeamSuccess:"Company.CompanyStructure.messages.moveTeamSuccess"}),{loadError:t,updateError:M}=p,[o,r]=b(null),[d,m]=b(!0),[u,g]=b(!1),[y,w]=b(!1),[I,U]=b(new Set),[H,P]=b(null),[F,A]=b(new Set),[Y,G]=b({}),h=ce(l),S=ce(!1),Z=ce(!1);q(()=>{h.current=l},[l]);const E=B((s,i)=>{l&&(s==="success"?l({type:"success",text:i}):s==="error"?l({type:"error",text:i}):l(),g(!1))},[l]),D=B(async()=>{if(S.current)return null;if(S.current=!0,!C)return m(!1),r(null),U(new Set),P(null),A(new Set),S.current=!1,null;m(!0);try{const i=await ke();return r(i),U(new Set(i.map(_=>_.id))),m(!1),i}catch{return m(!1),h.current&&h.current({type:"error",text:t}),null}finally{S.current=!1}},[C,t]);q(()=>{C&&!Z.current&&(Z.current=!0,D())},[C,D]),q(()=>{const s=()=>{m(!0),U(new Set),P(null),A(new Set),D()},i=se.on("companyContext/changed",s,{eager:!0});return()=>{i==null||i.off()}},[D]);const x=B(async(s,i)=>{try{if(g(!0),!await Ve({id:s,parentId:i}))return E("error",p.failedToMoveItem),!1;const L=new Map(o==null?void 0:o.map(a=>[a.id,a])).get(s),R=(L==null?void 0:L.type)==="team"?p.moveTeamSuccess:p.moveUserSuccess;return r(a=>a?a.map(c=>c.id===s?{...c,parentId:i}:c):null),U(a=>new Set([...a,i])),ie(le.EDIT_COMPANY_STRUCTURE_EVENT,{action:"move",nodeId:s,newParentId:i}),se.emit("companyStructure/updated",{message:"Structure updated",action:"move",nodeId:s,newParentId:i,nodes:o||[]}),E("success",R),!0}catch(_){const O=_ instanceof Error?_.message:M;return E("error",O),!1}finally{g(!1)}},[o,E,M,p.failedToMoveItem,p.moveUserSuccess,p.moveTeamSuccess]),$=B(()=>{o&&U(new Set(o.map(s=>s.id)))},[o]),j=B(()=>{if(o){const s=o.filter(i=>i.parentId===null).map(i=>i.id);U(new Set(s))}},[o]),X=B(s=>{r(i=>{const _=i?[...i,{id:s.id,parentId:s.parentId,label:s.label,type:s.type,entityId:s.entityId,description:s.description}]:[{id:s.id,parentId:s.parentId,label:s.label,type:s.type,entityId:s.entityId,description:s.description}];return se.emit("companyStructure/updated",{message:"Structure updated",action:"add",nodeId:s.id,newParentId:s.parentId||void 0,nodes:_}),ie(le.EDIT_COMPANY_STRUCTURE_EVENT,{action:"add",nodeId:s.id,newParentId:s.parentId||void 0,nodeType:s.type}),_}),s.parentId&&U(i=>new Set([...i,s.parentId]))},[]),W=B((s,i,_)=>{i&&r(O=>O?O.map(L=>s.includes(L.id)?{...L,label:i,description:_}:L):null)},[]),ee=B(async s=>{if(s.length)try{g(!0);const i=new Map((o||[]).map(L=>[L.id,L])),_=s.map(L=>i.get(L)).filter(Boolean);for(const L of s){const R=i.get(L);!R||!R.entityId||(R.type==="team"?await Pe(R.entityId):await He({id:R.entityId,status:"INACTIVE"}))}r(L=>{if(!L)return null;const R=new Set(s);return L.filter(a=>!R.has(a.id))}),P(null),A(new Set),ie(le.EDIT_COMPANY_STRUCTURE_EVENT,{action:"remove",nodeIds:s}),se.emit("companyStructure/updated",{message:"Structure updated",action:"remove",nodeIds:s,nodes:o||[]});let O;if(s.length===1){const L=_[0];O=(L==null?void 0:L.type)==="team"?p.deleteTeamSuccess:p.removeUserSuccess}else O=p.removeMultipleSuccess.replace("{count}",s.length.toString());E("success",O)}catch(i){const _=i instanceof Error?i.message:M;E("error",_)}finally{g(!1)}},[o,E,M,p.removeUserSuccess,p.deleteTeamSuccess,p.removeMultipleSuccess]),te=B(s=>{G(s)},[]),Q=B(()=>{w(!0),E("success",""),G({})},[E]),ae=B(s=>{s==null||s(),w(!1),G({})},[]);return{nodes:o,loading:d,submitLoading:u,showEditForm:y,inputChange:Y,expanded:I,setExpanded:U,selected:H,setSelected:P,selectedMany:F,setSelectedMany:A,move:x,expandAll:$,collapseAll:j,insertNode:X,renameNodes:W,removeNodes:ee,handleInputChange:te,handleShowEditForm:Q,handleHideEditForm:ae,renderAlertMessage:E,working:u}}const je=be(({permissions:l,slots:N})=>{var R;const C=(l==null?void 0:l.canEditUsers)??!1,p=(l==null?void 0:l.canViewUsers)??!1,t=K({expandAll:"Company.CompanyStructure.shared.buttons.expandAll",collapseAll:"Company.CompanyStructure.shared.buttons.collapseAll",addUser:"Company.CompanyStructure.shared.buttons.addUser",addTeam:"Company.CompanyStructure.shared.buttons.addTeam",editSelected:"Company.CompanyStructure.shared.buttons.editSelected",remove:"Company.CompanyStructure.shared.buttons.remove",ok:"Company.CompanyStructure.shared.buttons.ok",cancel:"Company.CompanyStructure.shared.buttons.cancel",close:"Company.CompanyStructure.shared.buttons.close",deleting:"Company.CompanyStructure.shared.buttons.deleting",removing:"Company.CompanyStructure.shared.buttons.removing",noStructureData:"Company.CompanyStructure.messages.noStructureData",processing:"Company.CompanyStructure.shared.messages.processing",cannotDeleteUser:"Company.CompanyStructure.messages.cannotDeleteUser",cannotDeleteTeam:"Company.CompanyStructure.messages.cannotDeleteTeam",removeUserConfirm:"Company.CompanyStructure.messages.removeUserConfirm",deleteTeamConfirm:"Company.CompanyStructure.messages.deleteTeamConfirm",removeItemsConfirm:"Company.CompanyStructure.messages.removeItemsConfirm",teamDescription:"Company.CompanyStructure.shared.messages.teamDescription",removeUserMessage:"Company.CompanyStructure.messages.removeUserMessage",cannotDeleteUserMessage:"Company.CompanyStructure.messages.cannotDeleteUserMessage",cannotDeleteTeamMessage:"Company.CompanyStructure.messages.cannotDeleteTeamMessage",removeItemsMessage:"Company.CompanyStructure.messages.removeItemsMessage",companyStructureActions:"Company.CompanyStructure.shared.ariaLabels.companyStructureActions",expandAllNodes:"Company.CompanyStructure.shared.ariaLabels.expandAllNodes",collapseAllNodes:"Company.CompanyStructure.shared.ariaLabels.collapseAllNodes",addUserAria:"Company.CompanyStructure.shared.ariaLabels.addUser",addTeamAria:"Company.CompanyStructure.shared.ariaLabels.addTeam",editSelectedAria:"Company.CompanyStructure.shared.ariaLabels.editSelected",removeSelectedAria:"Company.CompanyStructure.shared.ariaLabels.removeSelected",showDescription:"Company.CompanyStructure.shared.ariaLabels.showDescription",delete:"Company.CompanyStructure.shared.options.delete",expand:"Company.CompanyStructure.shared.options.expand",collapse:"Company.CompanyStructure.shared.options.collapse",deleteTeamMessage:"Company.CompanyStructure.messages.deleteTeamMessage"}),{inLineAlertProps:M,handleSetInLineAlert:o}=Fe(),{nodes:r,loading:d,submitLoading:m,expanded:u,setExpanded:g,selected:y,setSelected:w,selectedMany:I,setSelectedMany:U,move:H,expandAll:P,collapseAll:F,insertNode:A,renameNodes:Y,removeNodes:G}=$e({handleSetInLineAlert:o,permissions:l}),[h,S]=b(null),[Z,E]=b("add"),[D,x]=b(!1),[$,j]=b([]),[X,W]=b({title:"",body:"",confirmLabel:t.remove,blocked:!1}),[ee,te]=b(null),Q=()=>S(null),ae=((R=r==null?void 0:r.find(a=>a.parentId===null))==null?void 0:R.id)??null,s=(r||[]).map(a=>({id:a.id,parentId:a.parentId,label:a.label})),i=a=>{if(!r)return 0;let c=0;const f=[a],n=new Set;for(;f.length>0;){const T=f.pop();if(!T||n.has(T))continue;n.add(T);const v=r.filter(z=>z.parentId===T);c+=v.length,v.forEach(z=>f.push(z.id))}return c},_=(a,c)=>{let f=a;const n=new Map(s.map(v=>[v.id,v])),T=new Set;for(;f&&!T.has(f);){T.add(f);const v=n.get(f);if(!v)break;if(v.parentId===c)return!0;f=v.parentId??null}return!1},O=(r||[]).map(a=>({id:a.id,parentId:a.parentId,label:a.label,type:a.type,description:a.description,entityId:a.entityId})),L=V(pe,{children:[(()=>{const a=I!=null&&I.size?Array.from(I):y?[y]:[],c=C&&a.length===1,f=C&&a.length>=1;return e(re,{variant:"secondary",className:"acm-structure-toolbar-card acm-structure-toolbar-card--spaced",children:V("div",{className:"acm-structure-toolbar",role:"toolbar","aria-label":t.companyStructureActions,children:[e(k,{type:"button",variant:"secondary",onClick:P,"aria-label":t.expandAllNodes,disabled:!p,"aria-disabled":!p,children:t.expandAll}),e(k,{type:"button",variant:"secondary",onClick:F,"aria-label":t.collapseAllNodes,disabled:!p,"aria-disabled":!p,children:t.collapseAll}),e(k,{type:"button",variant:"primary",onClick:()=>{E("add"),S("user")},"aria-label":t.addUserAria,disabled:!C,"aria-disabled":!C,children:t.addUser}),e(k,{type:"button",variant:"primary",onClick:()=>{E("add"),S("team")},"aria-label":t.addTeamAria,disabled:!C,"aria-disabled":!C,children:t.addTeam}),e(k,{type:"button",variant:"primary",disabled:!c,"aria-disabled":!c,"aria-label":t.editSelectedAria,onClick:()=>{if(!c)return;const n=a,T=r==null?void 0:r.find(v=>v.id===n[0]);(T==null?void 0:T.type)==="user"?(E("edit"),S("user")):(E("edit"),S("team"))},children:t.editSelected}),e(k,{type:"button",variant:"secondary",disabled:!f||m,"aria-disabled":!f||m,"aria-label":t.removeSelectedAria,onClick:()=>{if(!f||m)return;const n=a;if(n.length===1){const T=r==null?void 0:r.find(z=>z.id===n[0]);if(!T)return;(r==null?void 0:r.some(z=>z.parentId===T.id))?(W({title:T.type==="user"?t.cannotDeleteUser:t.cannotDeleteTeam,body:T.type==="user"?t.cannotDeleteUserMessage:t.cannotDeleteTeamMessage,confirmLabel:void 0,blocked:!0}),j([]),x(!0)):(W({title:T.type==="user"?t.removeUserConfirm:t.deleteTeamConfirm,body:T.type==="user"?t.removeUserMessage:t.deleteTeamMessage,confirmLabel:T.type==="user"?t.remove:t.delete,blocked:!1}),j(n),x(!0))}else W({title:t.removeItemsConfirm.replace("{count}",n.length.toString()),body:t.removeItemsMessage,confirmLabel:t.remove,blocked:!1}),j(n),x(!0)},children:t.remove})]})})})(),h?V("div",{className:"acm-structure-panel",children:[m?V("div",{className:"acm-structure-working","aria-live":"polite",children:[e(de,{size:"small"})," ",t.processing]}):null,h==="user"?(()=>{const a=I!=null&&I.size?Array.from(I):y?[y]:[],c=a.length?r==null?void 0:r.find(n=>n.id===a[0]):void 0,f=(c==null?void 0:c.id)??ae;return e(Ae,{mode:Z,entityId:c==null?void 0:c.entityId,parentStructureId:f,permissions:l,onSaved:n=>{Z==="add"?n.structureId&&(A({id:n.structureId,parentId:f,label:n.label,type:n.type,entityId:n.entityId,description:n.jobTitle??void 0}),n.structureId&&(w(n.structureId),U(new Set([n.structureId])))):a.length&&(n.status==="INACTIVE"?G(a):Y(a,n.label,n.jobTitle??void 0)),Q()},onCancel:Q,onError:n=>{o({text:n,type:"error"})},onSuccess:n=>{o({text:n,type:"success"})}})})():null,h==="team"?(()=>{const a=I!=null&&I.size?Array.from(I):y?[y]:[],c=a.length?r==null?void 0:r.find(n=>n.id===a[0]):void 0,f=(c==null?void 0:c.id)??ae;return e(Ye,{mode:Z,entityId:c==null?void 0:c.entityId,parentStructureId:f,permissions:l,onSaved:n=>{Z==="add"?n.structureId&&(A({id:n.structureId,parentId:f,label:n.label,type:n.type,entityId:n.entityId,description:n.description}),n.structureId&&(w(n.structureId),U(new Set([n.structureId])))):a.length&&Y(a,n.label,n.description),Q()},onCancel:Q,onError:n=>{o({text:n,type:"error"})},onSuccess:n=>{o({text:n,type:"success"})}})})():null]}):null,M&&M.text?e(re,{variant:"secondary",className:"acm-structure-message-card",children:e(ue,{className:"acm-structure-panel__notification",type:M.type||"success",variant:"secondary",heading:M.text})}):null,!d&&!m&&r&&r.length===0?e(re,{variant:"secondary",className:"acm-structure-message-card",children:e(ue,{className:"acm-structure-panel__notification",type:"warning",variant:"secondary",heading:t.noStructureData})}):null,!d&&m?e("div",{className:"acm-structure-tree-overlay","aria-live":"polite",children:e(de,{size:"medium"})}):null,d?e(re,{variant:"secondary",className:"acm-structure-message-card",children:e("div",{className:"acm-structure-tree-content",children:e(Be,{rows:8})})}):null,!d&&r&&r.length>0?e("div",{className:`acm-structure-tree-card ${m?"is-working":""}`,children:e(Ue,{rootId:null,items:s,expandedIds:u,selectedId:y,selectedIds:I,onExpandedChange:g,onSelectedChange:w,onSelectedIdsChange:U,renderExpander:({expanded:a,toggle:c})=>e("button",{type:"button",className:`acm-structure-expander acm-structure-expander-button ${a?"is-open":""}`,"aria-label":a?t.collapse:t.expand,onClick:f=>{f.stopPropagation(),c()},children:e("span",{className:`acm-structure-chevron ${a?"is-expanded":""}`})}),renderNode:({item:a,hasChildren:c,expander:f,icon:n,select:T})=>{const v=r==null?void 0:r.find(J=>J.id===a.id),z=i(a.id),ne=(v==null?void 0:v.description)||"",Me=(v==null?void 0:v.type)==="team"&&ne,me=(v==null?void 0:v.parentId)===null;return V("div",{className:"acm-structure-row",onClick:T,children:[!me&&e("span",{className:"acm-structure-handle","aria-hidden":!0}),n?e("span",{onClick:J=>J.stopPropagation(),children:n()}):e("span",{className:`acm-structure-icon ${(v==null?void 0:v.type)==="team"?"is-team":"is-user"} ${me?"is-root":""}`,"aria-hidden":!0}),V("div",{className:"acm-structure-info",children:[e("span",{className:"acm-structure-label",children:a.label}),ne?e("span",{className:"acm-structure-description",children:ne}):null]}),Me?e(k,{type:"button",variant:"secondary",onClick:J=>{J.stopPropagation(),te({id:a.id,text:ne})},"aria-label":t.showDescription,className:"acm-structure-description-button",children:"?"}):null,z>0?e("span",{className:"acm-structure-count",children:z}):null,c&&f?e("span",{className:"acm-structure-expander-wrapper",onClick:J=>J.stopPropagation(),children:f()}):null]})},draggable:a=>{const c=r==null?void 0:r.find(n=>n.id===a.id),f=c?c.parentId===null:!1;return!m&&C&&!f},canDrop:(a,c)=>{if(!C||a===c)return!1;const f=r==null?void 0:r.find(n=>n.id===a);return f&&f.parentId===c?!1:!_(c,a)},onMove:async({id:a,newParentId:c})=>{C&&await H(a,c)}})}):null,D?e(fe,{open:D,onClose:()=>{m||(x(!1),j([]))},children:V("div",{className:"acm-structure-modal-content",children:[e("h3",{className:"acm-structure-modal-title",children:X.title}),e("div",{children:X.body}),e("div",{className:"acm-structure-modal-actions",children:X.blocked?e(k,{type:"button",variant:"secondary",disabled:m,onClick:()=>{m||(x(!1),j([]))},children:t.ok}):V(pe,{children:[e(k,{type:"button",variant:"secondary",disabled:m,onClick:()=>{m||(x(!1),j([]))},children:t.cancel}),e(k,{type:"button",variant:"primary",disabled:m,onClick:async()=>{await G($),x(!1),j([])},children:m?X.confirmLabel===t.delete?t.deleting:t.removing:X.confirmLabel||t.remove})]})})]})}):null,ee?e(fe,{open:!!ee,onClose:()=>te(null),children:V("div",{className:"acm-structure-modal-content",children:[e("h3",{className:"acm-structure-modal-title",children:t.teamDescription}),e("div",{children:ee.text}),e("div",{className:"acm-structure-modal-actions",children:e(k,{type:"button",variant:"secondary",onClick:()=>te(null),children:t.close})})]})}):null]});return N!=null&&N.StructureData?e(Ie,{name:"StructureData",slot:N.StructureData,context:{structureData:O,Default:L}}):L}),qe=()=>{const l=K({fetchPermissionsError:"Company.CompanyStructure.messages.fetchPermissionsError"}),[N,C]=b(null),[p,t]=b(!0),[M,o]=b(null),r=B(async()=>{var d,m;try{t(!0),o(null);const{roleResponse:u}=await he(),g=(m=(d=u==null?void 0:u.data)==null?void 0:d.customer)==null?void 0:m.role,y=ge(g);C(y)}catch(u){o(u instanceof Error?u:new Error(l.fetchPermissionsError))}finally{t(!1)}},[l.fetchPermissionsError]);return q(()=>{let d=!0;return(async()=>{var u,g;try{t(!0),o(null);const{roleResponse:y}=await he();if(!d)return;const w=(g=(u=y==null?void 0:y.data)==null?void 0:u.customer)==null?void 0:g.role,I=ge(w);C(I)}catch(y){if(!d)return;o(y instanceof Error?y:new Error(l.fetchPermissionsError))}finally{d&&t(!1)}})(),()=>{d=!1}},[]),{permissions:N,loading:p,error:M,refreshPermissions:r}},Ge="/customer/company/create",Xe=({className:l,children:N,createCompanyAccountUrl:C=Ge,...p})=>{const t=K({individualUserMessage:"Company.CustomerCompanyInfo.individualUserMessage",createAccountCta:"Company.CustomerCompanyInfo.createAccountCta"});return e(Le,{className:ve(["company-management-company-structure-empty",l]),icon:e(Te,{source:Oe}),heading:t.individualUserMessage||"You don't have a company account yet.",action:e(k,{as:"a",href:C,variant:"primary","data-testid":"company-structure-create-company-button",children:t.createAccountCta||"Create a Company Account"}),variant:"secondary","data-testid":"company-structure-empty",...p})},St=({className:l,withHeader:N=!1,slots:C,isAuthenticated:p=!1,onRedirectLogin:t,onRedirectAccount:M})=>{const o=K({containerTitle:"Company.CompanyStructure.containerTitle",noAccessTitle:"Company.CompanyStructure.noAccess.title",noAccessMessage:"Company.CompanyStructure.noAccess.message"}),{permissions:r,loading:d,refreshPermissions:m}=qe(),[u,g]=b("loading");return Ee(m),q(()=>{let y=!0;return(async()=>{try{if(!p){y&&g("redirect-login");return}if(!await Ne()){y&&(console.log("Company registration disabled - redirecting to account dashboard"),g("redirect-account"));return}await xe()?y&&g("show-structure"):y&&g("show-empty")}catch(w){console.error("Error in CompanyStructure - redirecting to login page:",w),y&&g("redirect-login")}})(),()=>{y=!1}},[p]),q(()=>{if(u!=="show-structure"&&u!=="no-access"||d||!r)return;const w=r.canViewUsers??!1?"show-structure":"no-access";u!==w&&g(w)},[u,r,d]),q(()=>{u==="redirect-login"&&t&&t(),u==="redirect-account"&&M&&M()},[u,t,M]),u==="loading"||u==="redirect-login"||u==="redirect-account"?null:u==="show-empty"?e(Xe,{className:l}):u==="no-access"?e(Le,{className:l,heading:o.noAccessTitle||"Access Restricted",message:e("p",{children:o.noAccessMessage||"You don't have permission to view the company structure. Please contact your company administrator."})}):u==="show-structure"?d||!r?null:V("div",{className:ve(["account-company-structure",l]),children:[N?e(we,{title:o.containerTitle,divider:!1,className:"company-structure__title"}):null,e(je,{slots:C,permissions:r})]}):null};export{St as CompanyStructure,St as default};
|
|
3
|
+
import{jsxs as V,jsx as e,Fragment as pe}from"@dropins/tools/preact-jsx-runtime.js";import{useState as b,useEffect as q,useRef as ce,useCallback as B}from"@dropins/tools/preact-hooks.js";import{Slot as Ie,classes as ve}from"@dropins/tools/lib.js";import{Card as re,InLineAlert as ue,ProgressSpinner as de,Field as ye,Input as Ce,Button as k,Modal as fe,IllustratedMessage as Le,Icon as Te,Header as we}from"@dropins/tools/components.js";import{f as he}from"../chunks/fetchUserPermissions.js";import{b as ge}from"../chunks/company-permissions.js";import{useText as K}from"@dropins/tools/i18n.js";import{u as Ee}from"../chunks/useCompanyContextListener.js";import{a as Ne,i as xe}from"../chunks/isCompanyUser.js";import*as Se from"@dropins/tools/preact-compat.js";import{memo as be}from"@dropins/tools/preact-compat.js";import{T as Ue}from"../chunks/Tree.js";import{C as Ae}from"../chunks/CompanyUserForm.js";import{events as se}from"@dropins/tools/event-bus.js";import{p as ie,E as le}from"../chunks/acdl.js";import{g as Ze,c as De,u as _e,a as ke,b as Ve,d as Pe}from"../chunks/updateCompanyTeam.js";import{u as He}from"../chunks/updateCompanyUserStatus.js";import{u as Fe}from"../chunks/useInLineAlert.js";import{C as Re,a as Be}from"../chunks/CompanyLoaders.js";import"../chunks/fetch-error.js";import"../chunks/network-error.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/useCompanyRoles.js";import"../chunks/isCompanyRoleNameAvailable.js";const Oe=l=>Se.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...l},Se.createElement("path",{d:"M12.002 21L11.8275 21.4686C11.981 21.5257 12.1528 21.5041 12.2873 21.4106C12.4218 21.3172 12.502 21.1638 12.502 21H12.002ZM3.89502 17.9823H3.39502C3.39502 18.1912 3.52485 18.378 3.72059 18.4509L3.89502 17.9823ZM3.89502 8.06421L4.07193 7.59655C3.91831 7.53844 3.74595 7.55948 3.61082 7.65284C3.47568 7.74619 3.39502 7.89997 3.39502 8.06421H3.89502ZM12.0007 21H11.5007C11.5007 21.1638 11.5809 21.3172 11.7154 21.4106C11.8499 21.5041 12.0216 21.5257 12.1751 21.4686L12.0007 21ZM20.1076 17.9823L20.282 18.4509C20.4778 18.378 20.6076 18.1912 20.6076 17.9823H20.1076ZM20.1076 8.06421H20.6076C20.6076 7.89997 20.527 7.74619 20.3918 7.65284C20.2567 7.55948 20.0843 7.53844 19.9307 7.59655L20.1076 8.06421ZM12.0007 11.1311L11.8238 10.6634C11.6293 10.737 11.5007 10.9232 11.5007 11.1311H12.0007ZM20.2858 8.53191C20.5441 8.43421 20.6743 8.14562 20.5766 7.88734C20.4789 7.62906 20.1903 7.49889 19.932 7.5966L20.2858 8.53191ZM12.002 4.94826L12.1775 4.48008C12.0605 4.43623 11.9314 4.43775 11.8154 4.48436L12.002 4.94826ZM5.87955 6.87106C5.62334 6.97407 5.49915 7.26528 5.60217 7.52149C5.70518 7.77769 5.99639 7.90188 6.2526 7.79887L5.87955 6.87106ZM18.1932 7.80315C18.4518 7.90008 18.74 7.76904 18.8369 7.51047C18.9338 7.2519 18.8028 6.96371 18.5442 6.86678L18.1932 7.80315ZM12 4.94827L11.5879 5.23148C11.6812 5.36719 11.8353 5.44827 12 5.44827C12.1647 5.44827 12.3188 5.36719 12.4121 5.23148L12 4.94827ZM14.0263 2L14.2028 1.53218C13.9875 1.45097 13.7446 1.52717 13.6143 1.71679L14.0263 2ZM21.8421 4.94827L22.2673 5.2113C22.3459 5.08422 22.3636 4.92863 22.3154 4.78717C22.2673 4.64571 22.1584 4.53319 22.0186 4.48045L21.8421 4.94827ZM9.97368 2L10.3857 1.71679C10.2554 1.52717 10.0125 1.45097 9.79721 1.53218L9.97368 2ZM2.15789 4.94827L1.98142 4.48045C1.84161 4.53319 1.73271 4.64571 1.68456 4.78717C1.63641 4.92863 1.65406 5.08422 1.73267 5.2113L2.15789 4.94827ZM12 11.1256L11.6702 11.5014C11.8589 11.667 12.1411 11.667 12.3298 11.5014L12 11.1256ZM15.0395 8.45812L14.8732 7.98659C14.8131 8.00779 14.7576 8.04028 14.7097 8.08232L15.0395 8.45812ZM23 5.65024L23.3288 6.0269C23.5095 5.86916 23.5527 5.60532 23.4318 5.39817C23.3109 5.19102 23.0599 5.09893 22.8337 5.17871L23 5.65024ZM8.96053 8.45812L9.29034 8.08232C9.24244 8.04028 9.18695 8.00779 9.12685 7.98659L8.96053 8.45812ZM1 5.65024L1.16632 5.17871C0.940115 5.09893 0.689119 5.19102 0.568192 5.39817C0.447264 5.60532 0.49048 5.86916 0.671176 6.0269L1 5.65024ZM12.1764 20.5314L4.06945 17.5137L3.72059 18.4509L11.8275 21.4686L12.1764 20.5314ZM4.39502 17.9823V8.06421H3.39502V17.9823H4.39502ZM3.71811 8.53187L11.8251 11.5987L12.1789 10.6634L4.07193 7.59655L3.71811 8.53187ZM11.502 11.1311V21H12.502V11.1311H11.502ZM12.1751 21.4686L20.282 18.4509L19.9332 17.5137L11.8262 20.5314L12.1751 21.4686ZM20.6076 17.9823V8.06421H19.6076V17.9823H20.6076ZM19.9307 7.59655L11.8238 10.6634L12.1776 11.5987L20.2845 8.53187L19.9307 7.59655ZM11.5007 11.1311V21H12.5007V11.1311H11.5007ZM19.932 7.5966L11.8251 10.6634L12.1789 11.5987L20.2858 8.53191L19.932 7.5966ZM11.8154 4.48436L5.87955 6.87106L6.2526 7.79887L12.1885 5.41217L11.8154 4.48436ZM11.8265 5.41645L18.1932 7.80315L18.5442 6.86678L12.1775 4.48008L11.8265 5.41645ZM11.502 4.94826V11.1311H12.502V4.94826H11.502ZM12.4121 5.23148L14.4384 2.28321L13.6143 1.71679L11.5879 4.66507L12.4121 5.23148ZM13.8498 2.46782L21.6656 5.4161L22.0186 4.48045L14.2028 1.53218L13.8498 2.46782ZM21.4169 4.68525L20.5485 6.08919L21.3989 6.61524L22.2673 5.2113L21.4169 4.68525ZM12.4121 4.66507L10.3857 1.71679L9.56162 2.28321L11.5879 5.23148L12.4121 4.66507ZM9.79721 1.53218L1.98142 4.48045L2.33437 5.4161L10.1502 2.46782L9.79721 1.53218ZM1.73267 5.2113L2.60109 6.61524L3.45154 6.08919L2.58312 4.68525L1.73267 5.2113ZM12.3298 11.5014L15.3693 8.83392L14.7097 8.08232L11.6702 10.7498L12.3298 11.5014ZM15.2058 8.92965L23.1663 6.12177L22.8337 5.17871L14.8732 7.98659L15.2058 8.92965ZM22.6712 5.27358L19.7764 7.80067L20.4341 8.554L23.3288 6.0269L22.6712 5.27358ZM12.3298 10.7498L9.29034 8.08232L8.63072 8.83392L11.6702 11.5014L12.3298 10.7498ZM9.12685 7.98659L1.16632 5.17871L0.83368 6.12177L8.79421 8.92965L9.12685 7.98659ZM0.671176 6.0269L3.56591 8.554L4.22356 7.80067L1.32882 5.27358L0.671176 6.0269Z",fill:"currentColor"})),oe={name:39,description:1e3};function ze(l){const{mode:N,entityId:C,parentStructureId:p,onSaved:t,onError:M,onSuccess:o}=l,r=K({teamTitleRequired:"Company.CompanyStructure.shared.validation.teamTitleRequired",teamNameMaxLength:"Company.CompanyStructure.shared.validation.teamNameMaxLength",teamDescriptionMaxLength:"Company.CompanyStructure.shared.validation.teamDescriptionMaxLength",createTeamError:"Company.CompanyStructure.messages.createTeamError",saveTeamError:"Company.CompanyStructure.messages.saveTeamError",createTeamSuccess:"Company.CompanyStructure.messages.createTeamSuccess",updateTeamSuccess:"Company.CompanyStructure.messages.updateTeamSuccess"}),[d,m]=b({id:"",name:"",description:""}),[u,g]=b({}),[y,w]=b({}),[I,U]=b(!1),[H,P]=b(null);q(()=>{N!=="edit"||!C||(U(!0),Ze(C).then(h=>{h&&m({id:h.id,name:h.name||"",description:h.description||""})}).finally(()=>U(!1)))},[N,C]);const F=(h,S)=>h==="name"?S.trim()?S.length>oe.name?r.teamNameMaxLength:null:r.teamTitleRequired:h==="description"&&S&&S.length>oe.description?r.teamDescriptionMaxLength:null,A=(h,S)=>{m(Z=>({...Z,[h]:S})),H&&P(null)};return{values:d,errors:u,touched:y,loading:I,setValue:A,onBlur:(h,S)=>{S!==void 0&&A(h,S),w(D=>({...D,[h]:!0}));const Z=S!==void 0?S:d[h]||"",E=F(h,Z);g(E?D=>({...D,[h]:E}):D=>{const x={...D};return delete x[h],x})},submit:async()=>{const h=F("name",d.name),S=F("description",d.description||""),Z={},E={name:!0,description:!0};if(h&&(Z.name=h),S&&(Z.description=S),w(E),Object.keys(Z).length>0){g(Z);return}const D=d.name;try{if(N==="add"){const x=await De({name:d.name,description:d.description||null,targetId:p??null});if(!x){const $=r.createTeamError;M?M($):P($);return}t({label:D,structureId:x.structureId,entityId:x.id,type:"team",description:d.description||void 0}),o&&o(r.createTeamSuccess)}else C&&(await _e({id:C,name:d.name,description:d.description||null}),t({label:D,entityId:C,type:"team",description:d.description||void 0}),o&&o(r.updateTeamSuccess))}catch(x){const $=x instanceof Error?x.message:r.saveTeamError;M?M($):P($)}},generalError:H}}const Ye=be(({mode:l,entityId:N,parentStructureId:C,permissions:p,onSaved:t,onCancel:M,onError:o,onSuccess:r})=>{const d=(p==null?void 0:p.canEditUsers)??!1,{values:m,errors:u,touched:g,loading:y,onBlur:w,submit:I,generalError:U}=ze({mode:l,entityId:N,parentStructureId:C,onSaved:t,onError:o?A=>{o(A),M()}:void 0,onSuccess:r}),[H,P]=b(!1),F=K({addTeam:"Company.CompanyStructure.shared.titles.addTeam",editTeam:"Company.CompanyStructure.shared.titles.editTeam",teamTitle:"Company.CompanyStructure.shared.fields.teamTitle",description:"Company.CompanyStructure.shared.fields.description"});return V("div",{children:[e("h3",{className:"acm-structure-panel__title",children:l==="add"?F.addTeam:F.editTeam}),V(re,{variant:"secondary",className:`company-team-form__card ${H?"is-working":""}`,children:[!o&&U?e(ue,{className:"company-team-form__notification",type:"error",variant:"secondary",heading:U}):null,H?e("div",{className:"company-team-form__overlay","aria-live":"polite",children:e(de,{size:"small"})}):null,y?e(Re,{}):V("div",{className:"company-team-form__content",children:[e(ye,{label:F.teamTitle,required:!0,className:"acm-structure-panel__field",error:g.name&&u.name?u.name:void 0,children:e(Ce,{name:"team_title",type:"text",value:m.name,onBlur:A=>{const Y=A.target;w("name",Y.value)},variant:"primary",size:"medium",disabled:!d,maxLength:oe.name})}),e(ye,{label:F.description,className:"acm-structure-panel__field",error:g.description&&u.description?u.description:void 0,children:e(Ce,{name:"team_description",type:"textarea",value:m.description||"",onBlur:A=>{const Y=A.target;w("description",Y.value)},variant:"primary",size:"medium",disabled:!d,maxLength:oe.description})})]})]}),y?null:V("div",{className:"acm-structure-modal__actions",children:[e(k,{type:"button",variant:"primary",onClick:async()=>{if(!H){P(!0);try{await I()}finally{P(!1)}}},disabled:H||!d,children:"Save"}),e(k,{type:"button",variant:"secondary",disabled:H,onClick:M,children:"Cancel"})]})]})});function $e({handleSetInLineAlert:l,permissions:N}={permissions:null}){const C=(N==null?void 0:N.canViewUsers)??!1,p=K({loadError:"Company.CompanyStructure.messages.loadError",updateError:"Company.CompanyStructure.messages.updateError",failedToMoveItem:"Company.CompanyStructure.messages.failedToMoveItem",removeUserSuccess:"Company.CompanyStructure.messages.removeUserSuccess",deleteTeamSuccess:"Company.CompanyStructure.messages.deleteTeamSuccess",removeMultipleSuccess:"Company.CompanyStructure.messages.removeMultipleSuccess",moveUserSuccess:"Company.CompanyStructure.messages.moveUserSuccess",moveTeamSuccess:"Company.CompanyStructure.messages.moveTeamSuccess"}),{loadError:t,updateError:M}=p,[o,r]=b(null),[d,m]=b(!0),[u,g]=b(!1),[y,w]=b(!1),[I,U]=b(new Set),[H,P]=b(null),[F,A]=b(new Set),[Y,G]=b({}),h=ce(l),S=ce(!1),Z=ce(!1);q(()=>{h.current=l},[l]);const E=B((s,i)=>{l&&(s==="success"?l({type:"success",text:i}):s==="error"?l({type:"error",text:i}):l(),g(!1))},[l]),D=B(async()=>{if(S.current)return null;if(S.current=!0,!C)return m(!1),r(null),U(new Set),P(null),A(new Set),S.current=!1,null;m(!0);try{const i=await ke();return r(i),U(new Set(i.map(_=>_.id))),m(!1),i}catch{return m(!1),h.current&&h.current({type:"error",text:t}),null}finally{S.current=!1}},[C,t]);q(()=>{C&&!Z.current&&(Z.current=!0,D())},[C,D]),q(()=>{const s=()=>{m(!0),U(new Set),P(null),A(new Set),D()},i=se.on("companyContext/changed",s,{eager:!0});return()=>{i==null||i.off()}},[D]);const x=B(async(s,i)=>{try{if(g(!0),!await Ve({id:s,parentId:i}))return E("error",p.failedToMoveItem),!1;const L=new Map(o==null?void 0:o.map(a=>[a.id,a])).get(s),R=(L==null?void 0:L.type)==="team"?p.moveTeamSuccess:p.moveUserSuccess;return r(a=>a?a.map(c=>c.id===s?{...c,parentId:i}:c):null),U(a=>new Set([...a,i])),ie(le.EDIT_COMPANY_STRUCTURE_EVENT,{action:"move",nodeId:s,newParentId:i}),se.emit("companyStructure/updated",{message:"Structure updated",action:"move",nodeId:s,newParentId:i,nodes:o||[]}),E("success",R),!0}catch(_){const O=_ instanceof Error?_.message:M;return E("error",O),!1}finally{g(!1)}},[o,E,M,p.failedToMoveItem,p.moveUserSuccess,p.moveTeamSuccess]),$=B(()=>{o&&U(new Set(o.map(s=>s.id)))},[o]),j=B(()=>{if(o){const s=o.filter(i=>i.parentId===null).map(i=>i.id);U(new Set(s))}},[o]),X=B(s=>{r(i=>{const _=i?[...i,{id:s.id,parentId:s.parentId,label:s.label,type:s.type,entityId:s.entityId,description:s.description}]:[{id:s.id,parentId:s.parentId,label:s.label,type:s.type,entityId:s.entityId,description:s.description}];return se.emit("companyStructure/updated",{message:"Structure updated",action:"add",nodeId:s.id,newParentId:s.parentId||void 0,nodes:_}),ie(le.EDIT_COMPANY_STRUCTURE_EVENT,{action:"add",nodeId:s.id,newParentId:s.parentId||void 0,nodeType:s.type}),_}),s.parentId&&U(i=>new Set([...i,s.parentId]))},[]),W=B((s,i,_)=>{i&&r(O=>O?O.map(L=>s.includes(L.id)?{...L,label:i,description:_}:L):null)},[]),ee=B(async s=>{if(s.length)try{g(!0);const i=new Map((o||[]).map(L=>[L.id,L])),_=s.map(L=>i.get(L)).filter(Boolean);for(const L of s){const R=i.get(L);!R||!R.entityId||(R.type==="team"?await Pe(R.entityId):await He({id:R.entityId,status:"INACTIVE"}))}r(L=>{if(!L)return null;const R=new Set(s);return L.filter(a=>!R.has(a.id))}),P(null),A(new Set),ie(le.EDIT_COMPANY_STRUCTURE_EVENT,{action:"remove",nodeIds:s}),se.emit("companyStructure/updated",{message:"Structure updated",action:"remove",nodeIds:s,nodes:o||[]});let O;if(s.length===1){const L=_[0];O=(L==null?void 0:L.type)==="team"?p.deleteTeamSuccess:p.removeUserSuccess}else O=p.removeMultipleSuccess.replace("{count}",s.length.toString());E("success",O)}catch(i){const _=i instanceof Error?i.message:M;E("error",_)}finally{g(!1)}},[o,E,M,p.removeUserSuccess,p.deleteTeamSuccess,p.removeMultipleSuccess]),te=B(s=>{G(s)},[]),Q=B(()=>{w(!0),E("success",""),G({})},[E]),ae=B(s=>{s==null||s(),w(!1),G({})},[]);return{nodes:o,loading:d,submitLoading:u,showEditForm:y,inputChange:Y,expanded:I,setExpanded:U,selected:H,setSelected:P,selectedMany:F,setSelectedMany:A,move:x,expandAll:$,collapseAll:j,insertNode:X,renameNodes:W,removeNodes:ee,handleInputChange:te,handleShowEditForm:Q,handleHideEditForm:ae,renderAlertMessage:E,working:u}}const je=be(({permissions:l,slots:N})=>{var R;const C=(l==null?void 0:l.canEditUsers)??!1,p=(l==null?void 0:l.canViewUsers)??!1,t=K({expandAll:"Company.CompanyStructure.shared.buttons.expandAll",collapseAll:"Company.CompanyStructure.shared.buttons.collapseAll",addUser:"Company.CompanyStructure.shared.buttons.addUser",addTeam:"Company.CompanyStructure.shared.buttons.addTeam",editSelected:"Company.CompanyStructure.shared.buttons.editSelected",remove:"Company.CompanyStructure.shared.buttons.remove",ok:"Company.CompanyStructure.shared.buttons.ok",cancel:"Company.CompanyStructure.shared.buttons.cancel",close:"Company.CompanyStructure.shared.buttons.close",deleting:"Company.CompanyStructure.shared.buttons.deleting",removing:"Company.CompanyStructure.shared.buttons.removing",noStructureData:"Company.CompanyStructure.messages.noStructureData",processing:"Company.CompanyStructure.shared.messages.processing",cannotDeleteUser:"Company.CompanyStructure.messages.cannotDeleteUser",cannotDeleteTeam:"Company.CompanyStructure.messages.cannotDeleteTeam",removeUserConfirm:"Company.CompanyStructure.messages.removeUserConfirm",deleteTeamConfirm:"Company.CompanyStructure.messages.deleteTeamConfirm",removeItemsConfirm:"Company.CompanyStructure.messages.removeItemsConfirm",teamDescription:"Company.CompanyStructure.shared.messages.teamDescription",removeUserMessage:"Company.CompanyStructure.messages.removeUserMessage",cannotDeleteUserMessage:"Company.CompanyStructure.messages.cannotDeleteUserMessage",cannotDeleteTeamMessage:"Company.CompanyStructure.messages.cannotDeleteTeamMessage",removeItemsMessage:"Company.CompanyStructure.messages.removeItemsMessage",companyStructureActions:"Company.CompanyStructure.shared.ariaLabels.companyStructureActions",expandAllNodes:"Company.CompanyStructure.shared.ariaLabels.expandAllNodes",collapseAllNodes:"Company.CompanyStructure.shared.ariaLabels.collapseAllNodes",addUserAria:"Company.CompanyStructure.shared.ariaLabels.addUser",addTeamAria:"Company.CompanyStructure.shared.ariaLabels.addTeam",editSelectedAria:"Company.CompanyStructure.shared.ariaLabels.editSelected",removeSelectedAria:"Company.CompanyStructure.shared.ariaLabels.removeSelected",showDescription:"Company.CompanyStructure.shared.ariaLabels.showDescription",delete:"Company.CompanyStructure.shared.options.delete",expand:"Company.CompanyStructure.shared.options.expand",collapse:"Company.CompanyStructure.shared.options.collapse",deleteTeamMessage:"Company.CompanyStructure.messages.deleteTeamMessage"}),{inLineAlertProps:M,handleSetInLineAlert:o}=Fe(),{nodes:r,loading:d,submitLoading:m,expanded:u,setExpanded:g,selected:y,setSelected:w,selectedMany:I,setSelectedMany:U,move:H,expandAll:P,collapseAll:F,insertNode:A,renameNodes:Y,removeNodes:G}=$e({handleSetInLineAlert:o,permissions:l}),[h,S]=b(null),[Z,E]=b("add"),[D,x]=b(!1),[$,j]=b([]),[X,W]=b({title:"",body:"",confirmLabel:t.remove,blocked:!1}),[ee,te]=b(null),Q=()=>S(null),ae=((R=r==null?void 0:r.find(a=>a.parentId===null))==null?void 0:R.id)??null,s=(r||[]).map(a=>({id:a.id,parentId:a.parentId,label:a.label})),i=a=>{if(!r)return 0;let c=0;const f=[a],n=new Set;for(;f.length>0;){const T=f.pop();if(!T||n.has(T))continue;n.add(T);const v=r.filter(z=>z.parentId===T);c+=v.length,v.forEach(z=>f.push(z.id))}return c},_=(a,c)=>{let f=a;const n=new Map(s.map(v=>[v.id,v])),T=new Set;for(;f&&!T.has(f);){T.add(f);const v=n.get(f);if(!v)break;if(v.parentId===c)return!0;f=v.parentId??null}return!1},O=(r||[]).map(a=>({id:a.id,parentId:a.parentId,label:a.label,type:a.type,description:a.description,entityId:a.entityId})),L=V(pe,{children:[(()=>{const a=I!=null&&I.size?Array.from(I):y?[y]:[],c=C&&a.length===1,f=C&&a.length>=1;return e(re,{variant:"secondary",className:"acm-structure-toolbar-card acm-structure-toolbar-card--spaced",children:V("div",{className:"acm-structure-toolbar",role:"toolbar","aria-label":t.companyStructureActions,children:[e(k,{type:"button",variant:"secondary",onClick:P,"aria-label":t.expandAllNodes,disabled:!p,"aria-disabled":!p,children:t.expandAll}),e(k,{type:"button",variant:"secondary",onClick:F,"aria-label":t.collapseAllNodes,disabled:!p,"aria-disabled":!p,children:t.collapseAll}),e(k,{type:"button",variant:"primary",onClick:()=>{E("add"),S("user")},"aria-label":t.addUserAria,disabled:!C,"aria-disabled":!C,children:t.addUser}),e(k,{type:"button",variant:"primary",onClick:()=>{E("add"),S("team")},"aria-label":t.addTeamAria,disabled:!C,"aria-disabled":!C,children:t.addTeam}),e(k,{type:"button",variant:"primary",disabled:!c,"aria-disabled":!c,"aria-label":t.editSelectedAria,onClick:()=>{if(!c)return;const n=a,T=r==null?void 0:r.find(v=>v.id===n[0]);(T==null?void 0:T.type)==="user"?(E("edit"),S("user")):(E("edit"),S("team"))},children:t.editSelected}),e(k,{type:"button",variant:"secondary",disabled:!f||m,"aria-disabled":!f||m,"aria-label":t.removeSelectedAria,onClick:()=>{if(!f||m)return;const n=a;if(n.length===1){const T=r==null?void 0:r.find(z=>z.id===n[0]);if(!T)return;(r==null?void 0:r.some(z=>z.parentId===T.id))?(W({title:T.type==="user"?t.cannotDeleteUser:t.cannotDeleteTeam,body:T.type==="user"?t.cannotDeleteUserMessage:t.cannotDeleteTeamMessage,confirmLabel:void 0,blocked:!0}),j([]),x(!0)):(W({title:T.type==="user"?t.removeUserConfirm:t.deleteTeamConfirm,body:T.type==="user"?t.removeUserMessage:t.deleteTeamMessage,confirmLabel:T.type==="user"?t.remove:t.delete,blocked:!1}),j(n),x(!0))}else W({title:t.removeItemsConfirm.replace("{count}",n.length.toString()),body:t.removeItemsMessage,confirmLabel:t.remove,blocked:!1}),j(n),x(!0)},children:t.remove})]})})})(),h?V("div",{className:"acm-structure-panel",children:[m?V("div",{className:"acm-structure-working","aria-live":"polite",children:[e(de,{size:"small"})," ",t.processing]}):null,h==="user"?(()=>{const a=I!=null&&I.size?Array.from(I):y?[y]:[],c=a.length?r==null?void 0:r.find(n=>n.id===a[0]):void 0,f=(c==null?void 0:c.id)??ae;return e(Ae,{mode:Z,entityId:c==null?void 0:c.entityId,parentStructureId:f,permissions:l,onSaved:n=>{Z==="add"?n.structureId&&(A({id:n.structureId,parentId:f,label:n.label,type:n.type,entityId:n.entityId,description:n.jobTitle??void 0}),n.structureId&&(w(n.structureId),U(new Set([n.structureId])))):a.length&&(n.status==="INACTIVE"?G(a):Y(a,n.label,n.jobTitle??void 0)),Q()},onCancel:Q,onError:n=>{o({text:n,type:"error"})},onSuccess:n=>{o({text:n,type:"success"})}})})():null,h==="team"?(()=>{const a=I!=null&&I.size?Array.from(I):y?[y]:[],c=a.length?r==null?void 0:r.find(n=>n.id===a[0]):void 0,f=(c==null?void 0:c.id)??ae;return e(Ye,{mode:Z,entityId:c==null?void 0:c.entityId,parentStructureId:f,permissions:l,onSaved:n=>{Z==="add"?n.structureId&&(A({id:n.structureId,parentId:f,label:n.label,type:n.type,entityId:n.entityId,description:n.description}),n.structureId&&(w(n.structureId),U(new Set([n.structureId])))):a.length&&Y(a,n.label,n.description),Q()},onCancel:Q,onError:n=>{o({text:n,type:"error"})},onSuccess:n=>{o({text:n,type:"success"})}})})():null]}):null,M&&M.text?e(re,{variant:"secondary",className:"acm-structure-message-card",children:e(ue,{className:"acm-structure-panel__notification",type:M.type||"success",variant:"secondary",heading:M.text})}):null,!d&&!m&&r&&r.length===0?e(re,{variant:"secondary",className:"acm-structure-message-card",children:e(ue,{className:"acm-structure-panel__notification",type:"warning",variant:"secondary",heading:t.noStructureData})}):null,!d&&m?e("div",{className:"acm-structure-tree-overlay","aria-live":"polite",children:e(de,{size:"medium"})}):null,d?e(re,{variant:"secondary",className:"acm-structure-message-card",children:e("div",{className:"acm-structure-tree-content",children:e(Be,{rows:8})})}):null,!d&&r&&r.length>0?e("div",{className:`acm-structure-tree-card ${m?"is-working":""}`,children:e(Ue,{rootId:null,items:s,expandedIds:u,selectedId:y,selectedIds:I,onExpandedChange:g,onSelectedChange:w,onSelectedIdsChange:U,renderExpander:({expanded:a,toggle:c})=>e("button",{type:"button",className:`acm-structure-expander acm-structure-expander-button ${a?"is-open":""}`,"aria-label":a?t.collapse:t.expand,onClick:f=>{f.stopPropagation(),c()},children:e("span",{className:`acm-structure-chevron ${a?"is-expanded":""}`})}),renderNode:({item:a,hasChildren:c,expander:f,icon:n,select:T})=>{const v=r==null?void 0:r.find(J=>J.id===a.id),z=i(a.id),ne=(v==null?void 0:v.description)||"",Me=(v==null?void 0:v.type)==="team"&&ne,me=(v==null?void 0:v.parentId)===null;return V("div",{className:"acm-structure-row",onClick:T,children:[!me&&e("span",{className:"acm-structure-handle","aria-hidden":!0}),n?e("span",{onClick:J=>J.stopPropagation(),children:n()}):e("span",{className:`acm-structure-icon ${(v==null?void 0:v.type)==="team"?"is-team":"is-user"} ${me?"is-root":""}`,"aria-hidden":!0}),V("div",{className:"acm-structure-info",children:[e("span",{className:"acm-structure-label",children:a.label}),ne?e("span",{className:"acm-structure-description",children:ne}):null]}),Me?e(k,{type:"button",variant:"secondary",onClick:J=>{J.stopPropagation(),te({id:a.id,text:ne})},"aria-label":t.showDescription,className:"acm-structure-description-button",children:"?"}):null,z>0?e("span",{className:"acm-structure-count",children:z}):null,c&&f?e("span",{className:"acm-structure-expander-wrapper",onClick:J=>J.stopPropagation(),children:f()}):null]})},draggable:a=>{const c=r==null?void 0:r.find(n=>n.id===a.id),f=c?c.parentId===null:!1;return!m&&C&&!f},canDrop:(a,c)=>{if(!C||a===c)return!1;const f=r==null?void 0:r.find(n=>n.id===a);return f&&f.parentId===c?!1:!_(c,a)},onMove:async({id:a,newParentId:c})=>{C&&await H(a,c)}})}):null,D?e(fe,{open:D,onClose:()=>{m||(x(!1),j([]))},children:V("div",{className:"acm-structure-modal-content",children:[e("h3",{className:"acm-structure-modal-title",children:X.title}),e("div",{children:X.body}),e("div",{className:"acm-structure-modal-actions",children:X.blocked?e(k,{type:"button",variant:"secondary",disabled:m,onClick:()=>{m||(x(!1),j([]))},children:t.ok}):V(pe,{children:[e(k,{type:"button",variant:"secondary",disabled:m,onClick:()=>{m||(x(!1),j([]))},children:t.cancel}),e(k,{type:"button",variant:"primary",disabled:m,onClick:async()=>{await G($),x(!1),j([])},children:m?X.confirmLabel===t.delete?t.deleting:t.removing:X.confirmLabel||t.remove})]})})]})}):null,ee?e(fe,{open:!!ee,onClose:()=>te(null),children:V("div",{className:"acm-structure-modal-content",children:[e("h3",{className:"acm-structure-modal-title",children:t.teamDescription}),e("div",{children:ee.text}),e("div",{className:"acm-structure-modal-actions",children:e(k,{type:"button",variant:"secondary",onClick:()=>te(null),children:t.close})})]})}):null]});return N!=null&&N.StructureData?e(Ie,{name:"StructureData",slot:N.StructureData,context:{structureData:O,Default:L}}):L}),qe=()=>{const l=K({fetchPermissionsError:"Company.CompanyStructure.messages.fetchPermissionsError"}),[N,C]=b(null),[p,t]=b(!0),[M,o]=b(null),r=B(async()=>{var d,m;try{t(!0),o(null);const{roleResponse:u}=await he(),g=(m=(d=u==null?void 0:u.data)==null?void 0:d.customer)==null?void 0:m.role,y=ge(g);C(y)}catch(u){o(u instanceof Error?u:new Error(l.fetchPermissionsError))}finally{t(!1)}},[l.fetchPermissionsError]);return q(()=>{let d=!0;return(async()=>{var u,g;try{t(!0),o(null);const{roleResponse:y}=await he();if(!d)return;const w=(g=(u=y==null?void 0:y.data)==null?void 0:u.customer)==null?void 0:g.role,I=ge(w);C(I)}catch(y){if(!d)return;o(y instanceof Error?y:new Error(l.fetchPermissionsError))}finally{d&&t(!1)}})(),()=>{d=!1}},[]),{permissions:N,loading:p,error:M,refreshPermissions:r}},Ge="/customer/company/create",Xe=({className:l,children:N,createCompanyAccountUrl:C=Ge,...p})=>{const t=K({individualUserMessage:"Company.CustomerCompanyInfo.individualUserMessage",createAccountCta:"Company.CustomerCompanyInfo.createAccountCta"});return e(Le,{className:ve(["company-management-company-structure-empty",l]),icon:e(Te,{source:Oe}),heading:t.individualUserMessage||"You don't have a company account yet.",action:e(k,{as:"a",href:C,variant:"primary","data-testid":"company-structure-create-company-button",children:t.createAccountCta||"Create a Company Account"}),variant:"secondary","data-testid":"company-structure-empty",...p})},St=({className:l,withHeader:N=!1,slots:C,isAuthenticated:p=!1,onRedirectLogin:t,onRedirectAccount:M})=>{const o=K({containerTitle:"Company.CompanyStructure.containerTitle",noAccessTitle:"Company.CompanyStructure.noAccess.title",noAccessMessage:"Company.CompanyStructure.noAccess.message"}),{permissions:r,loading:d,refreshPermissions:m}=qe(),[u,g]=b("loading");return Ee(m),q(()=>{let y=!0;return(async()=>{try{if(!p){y&&g("redirect-login");return}if(!await Ne()){y&&(console.log("Company registration disabled - redirecting to account dashboard"),g("redirect-account"));return}await xe()?y&&g("show-structure"):y&&g("show-empty")}catch(w){console.error("Error in CompanyStructure - redirecting to login page:",w),y&&g("redirect-login")}})(),()=>{y=!1}},[p]),q(()=>{if(u!=="show-structure"&&u!=="no-access"||d||!r)return;const w=r.canViewUsers??!1?"show-structure":"no-access";u!==w&&g(w)},[u,r,d]),q(()=>{u==="redirect-login"&&t&&t(),u==="redirect-account"&&M&&M()},[u,t,M]),u==="loading"||u==="redirect-login"||u==="redirect-account"?null:u==="show-empty"?e(Xe,{className:l}):u==="no-access"?e(Le,{className:l,heading:o.noAccessTitle||"Access Restricted",message:e("p",{children:o.noAccessMessage||"You don't have permission to view the company structure. Please contact your company administrator."})}):u==="show-structure"?d||!r?null:V("div",{className:ve(["account-company-structure",l]),children:[N?e(we,{title:o.containerTitle,divider:!1,className:"company-structure__title"}):null,e(je,{slots:C,permissions:r})]}):null};export{St as CompanyStructure,St as default};
|
|
4
4
|
//# sourceMappingURL=CompanyStructure.js.map
|