@dropins/storefront-company-management 1.0.0-beta13 → 1.0.0-beta15
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/api/deleteCompanyTeam/deleteCompanyTeam.d.ts +1 -1
- package/api/deleteCompanyUser/deleteCompanyUser.d.ts +1 -1
- package/api/getCompanyTeam/getCompanyTeam.d.ts +1 -1
- package/api/getCompanyUser/getCompanyUser.d.ts +1 -1
- package/api/getCompanyUsers/getCompanyUsers.d.ts +1 -1
- package/api/updateCompanyTeam/updateCompanyTeam.d.ts +1 -1
- package/api/updateCompanyUser/updateCompanyUser.d.ts +1 -1
- package/api/updateCompanyUserStatus/updateCompanyUserStatus.d.ts +1 -1
- package/api.js +3 -3
- package/chunks/CompanyLoaders.js +1 -1
- package/chunks/CompanyUserForm.js +1 -1
- package/chunks/Tree.js +1 -1
- package/chunks/Tree.js.map +1 -1
- package/chunks/company-permissions.js +1 -1
- package/chunks/fetchUserPermissions.js +1 -1
- package/chunks/transform-store-config.js +1 -1
- package/chunks/transform-store-config.js.map +1 -1
- package/chunks/updateCompany.js +1 -1
- package/chunks/updateCompanyTeam.js +7 -7
- package/chunks/updateCompanyTeam.js.map +1 -1
- package/chunks/updateCompanyUser.js +6 -6
- package/chunks/updateCompanyUser.js.map +1 -1
- package/chunks/updateCompanyUserStatus.js +3 -3
- package/chunks/updateCompanyUserStatus.js.map +1 -1
- package/chunks/useCompanyContextListener.js.map +1 -1
- package/chunks/useCompanyRoles.js +1 -1
- package/chunks/useCompanyRoles.js.map +1 -1
- package/chunks/useCustomerCompanyInfo.js +1 -1
- package/chunks/useCustomerCompanyInfo.js.map +1 -1
- package/chunks/useUserPermissions.js +1 -1
- package/chunks/useUserPermissions.js.map +1 -1
- package/chunks/validateCompanyEmail.js +1 -1
- package/containers/CompanyCredit.js +1 -1
- package/containers/CompanyProfile.js +1 -1
- package/containers/CompanyProfile.js.map +1 -1
- package/containers/CompanyStructure.js +1 -1
- package/containers/CompanyStructure.js.map +1 -1
- package/containers/CompanyUsers.js +1 -1
- package/containers/CompanyUsers.js.map +1 -1
- package/containers/CustomerCompanyInfo.js +1 -1
- package/containers/CustomerCompanyInfo.js.map +1 -1
- package/containers/RolesAndPermissions.js +1 -1
- package/containers/RolesAndPermissions.js.map +1 -1
- package/data/models/company-role.d.ts +1 -1
- package/package.json +1 -1
- package/render.js +7 -7
- package/types/api/companyRoles.types.d.ts +1 -1
- package/chunks/useCompanyContextListener2.js +0 -4
- package/chunks/useCompanyContextListener2.js.map +0 -1
- package/containers/CompanyUsers/hooks/index.d.ts +0 -19
- package/containers/CompanyUsers/hooks/useCompanyContextListener.d.ts +0 -62
- package/containers/CompanyUsers/hooks.d.ts +0 -1
- package/containers/CompanyUsers/hooks.js +0 -4
- package/containers/CompanyUsers/hooks.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Deletes a company team by their ID
|
|
3
3
|
*
|
|
4
|
-
* @param id - The ID of the company team to delete
|
|
4
|
+
* @param id - The ID of the company team to delete (base64 encoded UID from GraphQL)
|
|
5
5
|
* @returns Promise resolving to boolean indicating success
|
|
6
6
|
* @throws {Error} When network errors or GraphQL errors occur
|
|
7
7
|
*/
|
|
@@ -3,7 +3,7 @@ import { DeleteCompanyUserParams, DeleteCompanyUserResponse } from '../../types'
|
|
|
3
3
|
/**
|
|
4
4
|
* Deletes a company user by their ID
|
|
5
5
|
* @param params - The parameters containing user ID
|
|
6
|
-
* @param params.id - The ID of the user to delete (
|
|
6
|
+
* @param params.id - The ID of the user to delete (base64 encoded UID from GraphQL)
|
|
7
7
|
* @returns Promise<DeleteCompanyUserResponse> - Object containing success status
|
|
8
8
|
*/
|
|
9
9
|
export declare const deleteCompanyUser: (params: DeleteCompanyUserParams) => Promise<DeleteCompanyUserResponse>;
|
|
@@ -3,7 +3,7 @@ import { CompanyTeamModel } from '../../data/models';
|
|
|
3
3
|
/**
|
|
4
4
|
* Retrieves a specific company team by their ID
|
|
5
5
|
*
|
|
6
|
-
* @param id - The ID of the company team to retrieve
|
|
6
|
+
* @param id - The ID of the company team to retrieve (base64 encoded UID from GraphQL)
|
|
7
7
|
* @returns Promise resolving to CompanyTeamModel or null if team not found
|
|
8
8
|
* @throws {Error} When network errors or GraphQL errors occur
|
|
9
9
|
*/
|
|
@@ -2,7 +2,7 @@ import { CompanyUserModel } from '../../data/models';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Retrieves a specific company user by their ID
|
|
5
|
-
* @param id - The ID of the company user to retrieve (
|
|
5
|
+
* @param id - The ID of the company user to retrieve (base64 encoded UID from GraphQL)
|
|
6
6
|
* @returns Promise resolving to CompanyUserModel or null if user not found
|
|
7
7
|
*/
|
|
8
8
|
export declare function getCompanyUser(id: string): Promise<CompanyUserModel | null>;
|
|
@@ -6,7 +6,7 @@ import { CompanyUsersParams, CompanyUsersResponse } from '../../types';
|
|
|
6
6
|
* @param params.pageSize - Number of items per page (default: 20)
|
|
7
7
|
* @param params.currentPage - Current page number (default: 1)
|
|
8
8
|
* @param params.filter - Optional filter to apply (e.g., { status: 'ACTIVE' })
|
|
9
|
-
* @returns Promise<CompanyUsersResponse> - Object containing array of company users and pagination info
|
|
9
|
+
* @returns Promise<CompanyUsersResponse> - Object containing array of company users with base64-encoded IDs and pagination info
|
|
10
10
|
*/
|
|
11
11
|
export declare const getCompanyUsers: (params?: CompanyUsersParams) => Promise<CompanyUsersResponse>;
|
|
12
12
|
//# sourceMappingURL=getCompanyUsers.d.ts.map
|
|
@@ -3,7 +3,7 @@ import { UpdateCompanyTeamInput } from '../../types/api/updateCompanyTeam.types'
|
|
|
3
3
|
/**
|
|
4
4
|
* Updates an existing company team with the provided information
|
|
5
5
|
*
|
|
6
|
-
* @param input - Team information including ID and fields to update
|
|
6
|
+
* @param input - Team information including ID (base64 encoded UID) and fields to update
|
|
7
7
|
* @returns Promise resolving to boolean indicating success
|
|
8
8
|
* @throws {Error} When network errors or GraphQL errors occur
|
|
9
9
|
*/
|
|
@@ -2,7 +2,7 @@ import { UpdateCompanyUserInput } from '../../types';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Updates an existing company user with the provided information
|
|
5
|
-
* @param input - User information including ID and fields to update
|
|
5
|
+
* @param input - User information including ID (base64 encoded UID) and fields to update
|
|
6
6
|
* @returns Promise resolving to boolean indicating success
|
|
7
7
|
*/
|
|
8
8
|
export declare function updateCompanyUser(input: UpdateCompanyUserInput): Promise<boolean>;
|
|
@@ -3,7 +3,7 @@ import { UpdateCompanyUserStatusParams, UpdateCompanyUserStatusResponse } from '
|
|
|
3
3
|
/**
|
|
4
4
|
* Updates a company user's status (Active/Inactive)
|
|
5
5
|
* @param params - The parameters containing user ID and new status
|
|
6
|
-
* @param params.id - The ID of the user to update (
|
|
6
|
+
* @param params.id - The ID of the user to update (base64 encoded UID from GraphQL)
|
|
7
7
|
* @param params.status - The new status for the user (ACTIVE or INACTIVE)
|
|
8
8
|
* @returns Promise<UpdateCompanyUserStatusResponse> - Object containing success status and updated user data
|
|
9
9
|
*/
|
package/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{f as m,h as c}from"./chunks/network-error.js";import{g as I,r as P,s as G,a as L,b as M}from"./chunks/network-error.js";import{f as D}from"./chunks/fetchUserPermissions.js";import{a as w,i as F}from"./chunks/isCompanyUser.js";import{c as B,g as Q}from"./chunks/getCustomerCompany.js";import{D as q,S as K,c as W,g as z}from"./chunks/transform-store-config.js";import{c as J,d as V,
|
|
3
|
+
import{f as m,h as c}from"./chunks/network-error.js";import{g as I,r as P,s as G,a as L,b as M}from"./chunks/network-error.js";import{f as D}from"./chunks/fetchUserPermissions.js";import{a as w,i as F}from"./chunks/isCompanyUser.js";import{c as B,g as Q}from"./chunks/getCustomerCompany.js";import{D as q,S as K,c as W,g as z}from"./chunks/transform-store-config.js";import{c as J,d as V,a as X,g as Z,b as $,u as ee}from"./chunks/updateCompanyTeam.js";import{c as ae,d as te,g as oe,i as ne,u as se}from"./chunks/updateCompanyUser.js";import{g as ie,u as ce}from"./chunks/updateCompany.js";import{g as pe,u as de}from"./chunks/updateCompanyUserStatus.js";import{g as ue,v as fe}from"./chunks/validateCompanyEmail.js";import{a as Ee,g as ge}from"./chunks/getCompanyCreditHistory.js";import{G as l,t as p}from"./chunks/isCompanyRoleNameAvailable.js";import{c as Re,d as Te,a as Ae,g as _e,i as Ue,u as Se}from"./chunks/isCompanyRoleNameAvailable.js";import{f as d}from"./chunks/company-permissions.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/event-bus.js";import"./chunks/fetch-error.js";const A=async e=>{try{const r=await m(l,{variables:e,method:"GET",cache:"no-cache"});return p(r)}catch(r){return c(r)}},_=e=>d(e),U=(e,r)=>{const n=new Set(r),a=t=>{var o;const s=((o=t.children)==null?void 0:o.map(a).filter(i=>i!==null))||[];return n.has(t.id)||s.length>0?{...t,children:s}:null};return e.map(a).filter(t=>t!==null)},S=async(e={})=>({success:!0,config:e}),C=`
|
|
4
4
|
query GET_CUSTOMER_COMPANIES_WITH_ROLES {
|
|
5
5
|
customer {
|
|
6
6
|
companies(input: {}) {
|
|
@@ -15,11 +15,11 @@ import{f as m,h as c}from"./chunks/network-error.js";import{g as I,r as P,s as G
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
`,b=async()=>{var e,
|
|
18
|
+
`,b=async()=>{var e,r,n;try{const a=await m(C,{method:"POST"});if((e=a.errors)!=null&&e.length)return!1;const t=(r=a.data)==null?void 0:r.customer;if(!t)return!1;const s=((n=t.companies)==null?void 0:n.items)??[];if(!Array.isArray(s)||s.length===0)return!1;const o=t.role;return o?o.id==="0"||typeof o.id=="number"&&o.id===0||o.name==="Company Administrator":!1}catch(a){return console.error("Error checking if customer is company admin:",a),!1}};var u=(e=>(e.ALLOCATION="ALLOCATION",e.UPDATE="UPDATE",e.PURCHASE="PURCHASE",e.REIMBURSEMENT="REIMBURSEMENT",e))(u||{});const f=`
|
|
19
19
|
query CHECK_COMPANY_CREDIT_ENABLED {
|
|
20
20
|
storeConfig{
|
|
21
21
|
company_credit_enabled
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
`,N=async()=>{var e,
|
|
24
|
+
`,N=async()=>{var e,r,n;try{const a=await m(f,{method:"GET",cache:"no-cache"});return(e=a.errors)!=null&&e.length?{creditEnabled:!1,error:"Unable to check company credit configuration"}:((n=(r=a.data)==null?void 0:r.storeConfig)==null?void 0:n.company_credit_enabled)===!0?{creditEnabled:!0}:{creditEnabled:!1,error:"Company credit is not enabled in store configuration"}}catch{return{creditEnabled:!1,error:"Company credit functionality not available"}}};export{u as CompanyCreditOperationType,q as DEFAULT_COUNTRY,K as STORE_CONFIG_DEFAULTS,w as allowCompanyRegistration,U as buildPermissionTree,N as checkCompanyCreditEnabled,B as companyEnabled,W as createCompany,Re as createCompanyRole,J as createCompanyTeam,ae as createCompanyUser,Te as deleteCompanyRole,V as deleteCompanyTeam,te as deleteCompanyUser,m as fetchGraphQl,D as fetchUserPermissions,_ as flattenPermissionIds,ie as getCompany,Ae as getCompanyAclResources,Ee as getCompanyCredit,ge as getCompanyCreditHistory,A as getCompanyRole,_e as getCompanyRoles,X as getCompanyStructure,Z as getCompanyTeam,oe as getCompanyUser,pe as getCompanyUsers,I as getConfig,ue as getCountries,Q as getCustomerCompany,z as getStoreConfig,S as initialize,b as isCompanyAdmin,Ue as isCompanyRoleNameAvailable,F as isCompanyUser,ne as isCompanyUserEmailAvailable,P as removeFetchGraphQlHeader,G as setEndpoint,L as setFetchGraphQlHeader,M as setFetchGraphQlHeaders,ce as updateCompany,Se as updateCompanyRole,$ as updateCompanyStructure,ee as updateCompanyTeam,se as updateCompanyUser,de as updateCompanyUserStatus,fe as validateCompanyEmail};
|
|
25
25
|
//# sourceMappingURL=api.js.map
|
package/chunks/CompanyLoaders.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as e,jsxs as t}from"@dropins/tools/preact-jsx-runtime.js";import{Skeleton as i,SkeletonRow as a,Card as n}from"@dropins/tools/components.js";import{classes as o}from"@dropins/tools/lib.js";const u=({testId:r,withCard:l=!0})=>{const s=t(i,{"data-testid":r||"companySkeletonLoader",children:[e(a,{variant:"heading",size:"xlarge",fullWidth:!1,lines:1}),e(a,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1}),e(a,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1})]});return l?s:e(n,{variant:"secondary",className:o(["company-company-loaders","company-company-loaders--card-loader"]),children:s})},h=({testId:r})=>e("div",{className:"company-users-skeleton-loader","data-testid":r||"companyUsersSkeletonLoader",children:e(i,{children:e(a,{variant:"row",size:"small",fullWidth:!0,lines:3})})}),p=({testId:r})=>t("div",{className:"company-credit-skeleton-loader","data-testid":r||"companyCreditSkeletonLoader",children:[e(i,{children:e(a,{variant:"row",size:"small",lines:2})}),e(i,{children:e(a,{variant:"row",size:"small",lines:2})}),e(i,{children:e(a,{variant:"row",size:"small",lines:2})})]}),y=({testId:r})=>e("div",{className:"company-credit-history-skeleton-loader","data-testid":r||"companyCreditHistorySkeletonLoader",children:e(i,{children:e(a,{variant:"row",size:"small",fullWidth:!0,lines:3})})}),z=({rows:r=6})=>t(i,{"data-testid":"companyStructureLoader",children:[e(a,{variant:"heading",size:"medium"}),e(a,{variant:"empty",size:"small"}),Array.from({length:r}).map((l,s)=>e(a,{size:"large",fullWidth:!0},s))]}),g=()=>t(i,{"data-testid":"companyUserFormLoader",children:[e(a,{variant:"heading",size:"medium"}),e(a,{variant:"empty",size:"small"}),e(a,{size:"large"}),e(a,{size:"large"}),e(a,{size:"large"}),e(a,{size:"large"}),e(a,{size:"large",fullWidth:!0}),e(a,{size:"large"}),e(a,{size:"large"})]}),v=()=>t(i,{"data-testid":"companyTeamFormLoader",children:[e(a,{variant:"heading",size:"medium"}),e(a,{variant:"empty",size:"small"}),e(a,{size:"large"}),e(a,{size:"large",fullWidth:!0}),e(a,{size:"large"})]});export{
|
|
3
|
+
import{jsx as e,jsxs as t}from"@dropins/tools/preact-jsx-runtime.js";import{Skeleton as i,SkeletonRow as a,Card as n}from"@dropins/tools/components.js";import{classes as o}from"@dropins/tools/lib.js";const u=({testId:r,withCard:l=!0})=>{const s=t(i,{"data-testid":r||"companySkeletonLoader",children:[e(a,{variant:"heading",size:"xlarge",fullWidth:!1,lines:1}),e(a,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1}),e(a,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1})]});return l?s:e(n,{variant:"secondary",className:o(["company-company-loaders","company-company-loaders--card-loader"]),children:s})},h=({testId:r})=>e("div",{className:"company-users-skeleton-loader","data-testid":r||"companyUsersSkeletonLoader",children:e(i,{children:e(a,{variant:"row",size:"small",fullWidth:!0,lines:3})})}),p=({testId:r})=>t("div",{className:"company-credit-skeleton-loader","data-testid":r||"companyCreditSkeletonLoader",children:[e(i,{children:e(a,{variant:"row",size:"small",lines:2})}),e(i,{children:e(a,{variant:"row",size:"small",lines:2})}),e(i,{children:e(a,{variant:"row",size:"small",lines:2})})]}),y=({testId:r})=>e("div",{className:"company-credit-history-skeleton-loader","data-testid":r||"companyCreditHistorySkeletonLoader",children:e(i,{children:e(a,{variant:"row",size:"small",fullWidth:!0,lines:3})})}),z=({rows:r=6})=>t(i,{"data-testid":"companyStructureLoader",children:[e(a,{variant:"heading",size:"medium"}),e(a,{variant:"empty",size:"small"}),Array.from({length:r}).map((l,s)=>e(a,{size:"large",fullWidth:!0},s))]}),g=()=>t(i,{"data-testid":"companyUserFormLoader",children:[e(a,{variant:"heading",size:"medium"}),e(a,{variant:"empty",size:"small"}),e(a,{size:"large"}),e(a,{size:"large"}),e(a,{size:"large"}),e(a,{size:"large"}),e(a,{size:"large",fullWidth:!0}),e(a,{size:"large"}),e(a,{size:"large"})]}),v=()=>t(i,{"data-testid":"companyTeamFormLoader",children:[e(a,{variant:"heading",size:"medium"}),e(a,{variant:"empty",size:"small"}),e(a,{size:"large"}),e(a,{size:"large",fullWidth:!0}),e(a,{size:"large"})]});export{h as C,v as a,z as b,g as c,u as d,p as e,y as f};
|
|
4
4
|
//# sourceMappingURL=CompanyLoaders.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsxs as L,jsx as s}from"@dropins/tools/preact-jsx-runtime.js";import{memo as G}from"@dropins/tools/preact-compat.js";import{useState as u,useEffect as D}from"@dropins/tools/preact-hooks.js";import{Card as H,InLineAlert as J,ProgressSpinner as K,Field as g,Input as A,Picker as P,Button as $}from"@dropins/tools/components.js";import{
|
|
3
|
+
import{jsxs as L,jsx as s}from"@dropins/tools/preact-jsx-runtime.js";import{memo as G}from"@dropins/tools/preact-compat.js";import{useState as u,useEffect as D}from"@dropins/tools/preact-hooks.js";import{Card as H,InLineAlert as J,ProgressSpinner as K,Field as g,Input as A,Picker as P,Button as $}from"@dropins/tools/components.js";import{c as Q}from"./CompanyLoaders.js";import{i as W}from"./company-permissions.js";import{g as X,c as Y,u as Z,i as ee}from"./updateCompanyUser.js";import{useText as O}from"@dropins/tools/i18n.js";import{u as ae}from"./useCompanyRoles.js";function te(U){const{mode:I,entityId:C,parentStructureId:E,onSaved:q,onError:v}=U,c=O({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",createUserError:"Company.CompanyStructure.messages.createUserError",saveUserError:"Company.CompanyStructure.messages.saveUserError"}),[r,T]=u({firstName:"",lastName:"",email:"",jobTitle:"",telephone:"",roleId:"",status:"ACTIVE"}),[w,d]=u({}),[m,p]=u({}),[x,R]=u(!1),[y,j]=u(null),[S,_]=u(null),[N,V]=u(""),[l,a]=u(""),[i,k]=u(!1);D(()=>{I!=="edit"||!C||(R(!0),X(C).then(e=>{var f;if(!e)return;const t=e.email||"";T(b=>({...b,firstName:e.firstName||"",lastName:e.lastName||"",email:t,jobTitle:e.jobTitle||"",telephone:e.telephone||"",status:e.status||"ACTIVE"})),a(t),(f=e==null?void 0:e.role)!=null&&f.id&&T(b=>({...b,roleId:e.role.id})),k((e==null?void 0:e.isCompanyAdmin)??!1)}).finally(()=>R(!1)))},[I,C]);const z=e=>/.+@.+\..+/.test(e),F=(e,t)=>e==="firstName"?t!=null&&t.trim()?null:c.firstNameRequired:e==="lastName"?t!=null&&t.trim()?null:c.lastNameRequired:e==="email"?t!=null&&t.trim()?z(t.trim())?null:c.emailInvalid:c.emailRequired:e==="roleId"?t?null:c.selectRole:null,M=(e,t)=>{T(f=>({...f,[e]:t})),e==="email"&&_(null),y&&j(null)};return{values:r,errors:w,touched:m,loading:x,setValue:M,onBlur:async(e,t)=>{t!==void 0&&M(e,t),p(h=>({...h,[e]:!0}));const f=t!==void 0?t:r[e],b=F(e,f);if(d(b?h=>({...h,[e]:b}):h=>{const o={...h};return delete o[e],o}),e==="email"){const o=(t!==void 0?t:r.email||"").trim();if(I==="edit"&&o.toLowerCase()===(l||"").trim().toLowerCase()){_(null);return}if(z(o)&&o!==N){const n=await ee(o);V(o),_(n),n===!1&&d(B=>({...B,email:"A user with this email address is already a member of your company."}))}}},submit:async()=>{const e=["firstName","lastName","email","roleId"],t={};for(const o of e){const n=F(o,r[o]);n&&(t[o]=n)}if(d(t),p({firstName:!0,lastName:!0,email:!0,roleId:!0}),Object.keys(t).length||S===!1){setTimeout(()=>{const o=document.querySelector(".company-user-form__content .dropin-field__hint--error");if(o){const n=o.closest(".dropin-field");if(n){n.scrollIntoView({behavior:"smooth",block:"center"});const B=n.querySelector("input, select");B&&B.focus()}}},100);return}const f=`${r.firstName||""} ${r.lastName||""}`.trim()||r.email||"",h=i||W({id:r.roleId})?"ACTIVE":r.status;try{if(I==="add"){const o=await Y({email:r.email||"",firstName:r.firstName||"",lastName:r.lastName||"",jobTitle:r.jobTitle||"",telephone:r.telephone||"",roleId:r.roleId,status:h,targetId:E??null});if(!o){const n=c.createUserError;v?v(n):j(n);return}q({label:f,structureId:o.structureId,entityId:o.id,type:"user"})}else C&&(await Z({id:C,email:r.email||"",firstName:r.firstName||"",lastName:r.lastName||"",jobTitle:r.jobTitle||"",telephone:r.telephone||"",status:h,roleId:r.roleId}),q({label:f,entityId:C,type:"user"}))}catch(o){const n=o instanceof Error?o.message:c.saveUserError;v?v(n):j(n)}},isCompanyAdmin:i,generalError:y}}const ye=G(({mode:U,entityId:I,parentStructureId:C,permissions:E,onSaved:q,onCancel:v,onError:c})=>{const r=(E==null?void 0:E.canEditUsers)??!1,{roles:T,isLoading:w}=ae(),{values:d,errors:m,touched:p,loading:x,setValue:R,onBlur:y,submit:j,isCompanyAdmin:S,generalError:_}=te({mode:U,entityId:I,parentStructureId:C,onSaved:q,onError:c?a=>{c(a),v()}:void 0}),[N,V]=u(!1),l=O({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 L("div",{children:[s("h3",{className:"acm-structure-panel__title",children:U==="add"?l.addUser:l.editUser}),L(H,{variant:"secondary",className:`company-user-form__card ${N?"is-working":""}`,children:[!c&&_?s(J,{className:"company-user-form__notification",type:"error",variant:"secondary",heading:_}):null,N?s("div",{className:"company-user-form__overlay","aria-live":"polite",children:s(K,{size:"small"})}):null,x||w?s(Q,{}):L("div",{className:"company-user-form__content",children:[s(g,{label:l.jobTitle,className:"acm-structure-panel__field",error:p.jobTitle&&m.jobTitle?m.jobTitle:void 0,children:s(A,{name:"job_title",type:"text",value:d.jobTitle||"",onBlur:a=>{const i=a.target;y("jobTitle",i.value)},variant:"primary",size:"medium"})}),s(g,{label:l.userRole,required:!0,className:"acm-structure-panel__field",error:!S&&p.roleId&&m.roleId?m.roleId:void 0,disabled:S,children:S?s(P,{name:"role",value:"MA==",options:[{value:"MA==",text:l.companyAdministrator}]}):s(P,{name:"role",value:d.roleId||"placeholder",onChange:a=>{var i,k;return R("roleId",String(((i=a==null?void 0:a.target)==null?void 0:i.value)==="placeholder"?"":((k=a==null?void 0:a.target)==null?void 0:k.value)??""))},onBlur:a=>{const i=a.target;y("roleId",i.value==="placeholder"?"":i.value)},options:[{value:"placeholder",text:l.selectRole,disabled:!0},...T.map(a=>({value:a.id,text:a.name}))]})}),s(g,{label:l.firstName,required:!0,className:"acm-structure-panel__field",error:p.firstName&&m.firstName?m.firstName:void 0,children:s(A,{name:"first_name",type:"text",value:d.firstName,onBlur:a=>{const i=a.target;y("firstName",i.value)},variant:"primary",size:"medium"})}),s(g,{label:l.lastName,required:!0,className:"acm-structure-panel__field",error:p.lastName&&m.lastName?m.lastName:void 0,children:s(A,{name:"last_name",type:"text",value:d.lastName,onBlur:a=>{const i=a.target;y("lastName",i.value)},variant:"primary",size:"medium"})}),s(g,{label:l.email,required:!0,className:"acm-structure-panel__field",error:p.email&&m.email?m.email:void 0,children:s(A,{name:"email",type:"email",value:d.email,onBlur:a=>{const i=a.target;y("email",i.value)},placeholder:"jdoe@example.com",variant:"primary",size:"medium"})}),s(g,{label:l.workPhoneNumber,className:"acm-structure-panel__field",error:p.telephone&&m.telephone?m.telephone:void 0,children:s(A,{name:"telephone",type:"text",value:d.telephone||"",onBlur:a=>{const i=a.target;y("telephone",i.value)},variant:"primary",size:"medium"})}),s(g,{label:l.status,className:"acm-structure-panel__field",disabled:S||!r,children:s(P,{name:"status",value:d.status,onChange:a=>{var i;return R("status",String(((i=a==null?void 0:a.target)==null?void 0:i.value)??"ACTIVE"))},options:[{value:"ACTIVE",text:l.active},{value:"INACTIVE",text:l.inactive}]})})]})]}),x||w?null:L("div",{className:"acm-structure-modal__actions",children:[s($,{type:"button",variant:"primary",disabled:N||!r,onClick:async()=>{if(!N){V(!0);try{await j()}finally{V(!1)}}},children:l.save}),s($,{type:"button",variant:"secondary",disabled:N,onClick:v,children:l.cancel})]})]})});export{ye as C};
|
|
4
4
|
//# sourceMappingURL=CompanyUserForm.js.map
|
package/chunks/Tree.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as
|
|
3
|
+
import{jsx as O,jsxs as re}from"@dropins/tools/preact-jsx-runtime.js";import{useMemo as X,useRef as Y,useCallback as g}from"@dropins/tools/preact-hooks.js";import{Checkbox as se}from"@dropins/tools/components.js";const ce=(k,S=!1)=>{const x=new Map;for(const h of k){const w=h.parentId??null,u=x.get(w)??[];u.push(h),x.set(w,u)}if(!S)for(const[,h]of x)h.sort((w,u)=>w.label.localeCompare(u.label));return x},ie=({items:k,rootId:S=null,className:x,expandedIds:h,selectedId:w=null,selectedIds:u,onExpandedChange:$,onSelectedChange:D,onSelectedIdsChange:_,renderNode:Z,role:E="tree",preserveOrder:q=!1,draggable:j,canDrop:v,onMove:F,isCheckable:M,checkedIds:P,onCheckedChange:b,biDirectionalChecking:R=!1,renderExpander:A,renderCheckbox:I,renderIcon:B})=>{const T=X(()=>ce(k,q),[k,q]),N=Y(null),K=Y(!1),d=X(()=>new Map(k.map(e=>[e.id,e])),[k]),C=(e,n)=>{const a=[],o=[n];for(;o.length;){const t=o.pop(),s=e.get(t)??[];for(const r of s)a.push(r.id),o.push(r.id)}return a},y=g(e=>C(T,e),[T]),f=g(e=>M?M(e):!0,[M]),z=g(e=>{if(!d.get(e))return{checked:!1,indeterminate:!1};const a=P??new Set;if(R){if(a.has(e))return{checked:!0,indeterminate:!1};const s=y(e).filter(l=>{const p=d.get(l);return p?f(p):!1});return s.length===0?{checked:!1,indeterminate:!1}:s.reduce((l,p)=>a.has(p)?l+1:l,0)===0?{checked:!1,indeterminate:!1}:{checked:!1,indeterminate:!0}}const o=[e,...y(e)].filter(s=>{const r=d.get(s);return r?f(r):!1});if(o.length===0)return{checked:!1,indeterminate:!1};const t=o.reduce((s,r)=>a.has(r)?s+1:s,0);return t===0?{checked:!1,indeterminate:!1}:t===o.length?{checked:!0,indeterminate:!1}:{checked:!1,indeterminate:!0}},[d,y,f,P,R]),H=g(e=>{if(!b)return;const n=new Set(P??[]),{checked:a}=z(e),o=y(e),t=[e,...o].filter(s=>{const r=d.get(s);return r?f(r):!1});if(a)for(const s of t)n.delete(s);else for(const s of t)n.add(s);if(R&&!a){const s=d.get(e);if(s){let r=s.parentId;for(;r;){const l=d.get(r);if(!l||!f(l))break;n.add(r),r=l.parentId}}}b(n)},[P,b,z,y,d,f,R]),ee=g(e=>O(se,{name:`tree-checkbox-${Math.random().toString(36).substr(2,9)}`,checked:e.checked,indeterminate:e.indeterminate,onChange:e.onCheck}),[]),G=g(e=>{const n=new Set(h);n.has(e)?n.delete(e):n.add(e),$(n)},[h,$]),te=g(e=>{const n=d.get(e);if(n&&f(n)&&b&&H(e),!_){D==null||D(e);return}const a=!!K.current,o=a?new Set(u??[]):new Set;a&&o.has(e)?o.delete(e):o.add(e),_(o),K.current=!1},[D,_,u,d,f,b,H]),J=(e,n)=>{const a=T.get(e)??[];return a.length?O("ul",{role:n===1?E:"group",className:n===1?x??"acm-tree":"acm-tree__group",children:a.map((t,s)=>{const r=(T.get(t.id)??[]).length>0,l=h.has(t.id),p=u?u.has(t.id):w===t.id,L=!!(j!=null&&j(t)),Q=c=>v?v(c,t.id):c!==t.id,U=r?()=>A?A({expanded:l,hasChildren:r,toggle:()=>G(t.id)}):null:void 0,V=(()=>{if(!b)return;const c=d.get(t.id);if(!c||!f(c))return;const i=z(t.id),m=I||ee;return()=>m({checked:i.checked,indeterminate:i.indeterminate,onCheck:()=>H(t.id)})})(),W=B?()=>B({item:t,level:n,hasChildren:r,expanded:l}):void 0,ne=Z({item:t,level:n,expanded:l,selected:!!p,hasChildren:r,toggle:()=>G(t.id),select:()=>te(t.id),...U?{expander:U}:{},...V?{checkbox:V}:{},...W?{icon:W}:{}});return re("li",{role:"treeitem",className:"acm-tree__item","data-level":n,"aria-expanded":r?l:void 0,"aria-selected":p||void 0,"aria-level":n,"aria-setsize":a.length,"aria-posinset":s+1,draggable:L,onMouseDown:c=>{K.current=!!(c.metaKey||c.ctrlKey)},onDragStart:c=>{var i;if(c.stopPropagation(),!!L){N.current=t.id;try{(i=c.dataTransfer)==null||i.setData("text/plain",t.id)}catch{}}},onDragOver:c=>{var m;c.stopPropagation();const i=N.current??(((m=c.dataTransfer)==null?void 0:m.getData("text/plain"))||"");i&&Q(i)&&c.preventDefault()},onDrop:c=>{var m;c.stopPropagation();const i=N.current??(((m=c.dataTransfer)==null?void 0:m.getData("text/plain"))||"");N.current=null,i&&Q(i)&&(F==null||F({id:i,newParentId:t.id}))},children:[ne,r&&l?J(t.id,n+1):null]},t.id)})}):null};return O("div",{className:"acm-tree-root",children:J(S,1)})};export{ie as T};
|
|
4
4
|
//# sourceMappingURL=Tree.js.map
|
package/chunks/Tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.js","sources":["/@dropins/storefront-company-management/src/components/Tree/Tree.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 *******************************************************************/\n\nimport { FunctionComponent } from 'preact';\nimport { useMemo, useCallback, useRef } from 'preact/hooks';\nimport { Checkbox } from '@adobe-commerce/elsie/components';\nimport './Tree.css';\n\nexport interface TreeItem {\n id: string;\n parentId?: string | null;\n label: string;\n}\n\nexport interface RenderNodeArgs {\n item: TreeItem;\n level: number;\n expanded: boolean;\n selected: boolean;\n hasChildren: boolean;\n toggle: () => void;\n select: () => void;\n // Optional Elsie-friendly render helpers\n expander?: () => any;\n checkbox?: () => any;\n icon?: () => any;\n}\n\nexport interface TreeProps {\n items: TreeItem[];\n rootId?: string | null;\n className?: string;\n expandedIds: Set<string>;\n selectedId?: string | null;\n selectedIds?: Set<string>;\n onExpandedChange: (next: Set<string>) => void;\n onSelectedChange?: (id: string | null) => void;\n onSelectedIdsChange?: (ids: Set<string>) => void;\n renderNode: (args: RenderNodeArgs) => any;\n role?: 'tree' | 'list' | 'grid'; // default 'tree'\n // Sorting behavior (optional)\n preserveOrder?: boolean; // If true, preserve the original order of items. If false/undefined, sort alphabetically by label\n // Drag & Drop (optional)\n draggable?: (item: TreeItem) => boolean;\n canDrop?: (dragId: string, targetId: string) => boolean;\n onMove?: (args: { id: string; newParentId: string }) => void;\n // Checkable (optional)\n isCheckable?: (item: TreeItem) => boolean;\n checkedIds?: Set<string>;\n onCheckedChange?: (next: Set<string>) => void;\n // Checkbox behavior (optional)\n biDirectionalChecking?: boolean; // If true, checking a node directly marks it as checked. If false, uses descendant-based logic (default: false)\n // Optional Elsie-friendly render-props to build UI primitives\n renderExpander?: (args: { expanded: boolean; hasChildren: boolean; toggle: () => void }) => any;\n renderCheckbox?: (args: { checked: boolean; indeterminate: boolean; onCheck: () => void }) => any;\n renderIcon?: (args: { item: TreeItem; level: number; hasChildren: boolean; expanded: boolean }) => any;\n}\n\nconst buildChildrenMap = (items: TreeItem[], preserveOrder: boolean = false): Map<string | null, TreeItem[]> => {\n const byParent = new Map<string | null, TreeItem[]>();\n for (const item of items) {\n const key = (item.parentId ?? null) as string | null;\n const list = byParent.get(key) ?? [];\n list.push(item);\n byParent.set(key, list);\n }\n \n // Apply sorting based on preserveOrder flag\n if (!preserveOrder) {\n // Default behavior: stable sort by label for determinism\n for (const [, list] of byParent) {\n list.sort((a, b) => a.label.localeCompare(b.label));\n }\n }\n // If preserveOrder is true, keep the original order (e.g., sorted by sort_order)\n \n return byParent;\n};\n\nexport const Tree: FunctionComponent<TreeProps> = ({\n items,\n rootId = null,\n className,\n expandedIds,\n selectedId = null,\n selectedIds,\n onExpandedChange,\n onSelectedChange,\n onSelectedIdsChange,\n renderNode,\n role = 'tree',\n preserveOrder = false,\n draggable,\n canDrop,\n onMove,\n isCheckable,\n checkedIds,\n onCheckedChange,\n biDirectionalChecking = false,\n renderExpander,\n renderCheckbox,\n renderIcon,\n}) => {\n const byParent = useMemo(() => buildChildrenMap(items, preserveOrder), [items, preserveOrder]);\n const draggingIdRef = useRef<string | null>(null);\n const multiSelectRef = useRef<boolean>(false);\n\n const byId = useMemo(() => new Map(items.map((i) => [i.id, i] as const)), [items]);\n\n const collectDescendants = (\n byParentMap: Map<string | null, TreeItem[]>,\n id: string\n ): string[] => {\n const out: string[] = [];\n const stack = [id];\n while (stack.length) {\n const cur = stack.pop()!;\n const children = byParentMap.get(cur) ?? [];\n for (const ch of children) {\n out.push(ch.id);\n stack.push(ch.id);\n }\n }\n return out;\n };\n\n const getDescendants = useCallback(\n (id: string): string[] => {\n return collectDescendants(byParent, id);\n },\n [byParent]\n );\n\n const isNodeCheckable = useCallback((item: TreeItem) => (isCheckable ? isCheckable(item) : true), [isCheckable]);\n\n const computeCheckedState = useCallback(\n (id: string): { checked: boolean; indeterminate: boolean } => {\n const item = byId.get(id);\n if (!item) return { checked: false, indeterminate: false };\n \n const set = checkedIds ?? new Set<string>();\n \n if (biDirectionalChecking) {\n // If this node is directly checked, show it as checked\n if (set.has(id)) {\n return { checked: true, indeterminate: false };\n }\n \n // Otherwise, check descendants to determine indeterminate state\n const descendants = getDescendants(id).filter((nid) => {\n const node = byId.get(nid);\n return node ? isNodeCheckable(node) : false;\n });\n \n if (descendants.length === 0) return { checked: false, indeterminate: false };\n \n const numCheckedDescendants = descendants.reduce((acc, nid) => (set.has(nid) ? acc + 1 : acc), 0);\n \n if (numCheckedDescendants === 0) return { checked: false, indeterminate: false };\n return { checked: false, indeterminate: true };\n }\n \n // Check if node and ALL descendants are checked\n const all = [id, ...getDescendants(id)].filter((nid) => {\n const node = byId.get(nid);\n return node ? isNodeCheckable(node) : false;\n });\n \n if (all.length === 0) return { checked: false, indeterminate: false };\n \n const numChecked = all.reduce((acc, nid) => (set.has(nid) ? acc + 1 : acc), 0);\n \n if (numChecked === 0) return { checked: false, indeterminate: false };\n if (numChecked === all.length) return { checked: true, indeterminate: false };\n return { checked: false, indeterminate: true };\n },\n [byId, getDescendants, isNodeCheckable, checkedIds, biDirectionalChecking]\n );\n\n const toggleCheck = useCallback(\n (id: string) => {\n if (!onCheckedChange) return;\n \n const set = new Set(checkedIds ?? []);\n const { checked } = computeCheckedState(id);\n \n // 1) Handle downward propagation: check/uncheck this node and all descendants\n const descendants = getDescendants(id);\n const targets = [id, ...descendants].filter((nid) => {\n const node = byId.get(nid);\n return node ? isNodeCheckable(node) : false;\n });\n \n if (checked) {\n // Unchecking: remove this node and all descendants\n for (const nid of targets) set.delete(nid);\n } else {\n // Checking: add this node and all descendants\n for (const nid of targets) set.add(nid);\n }\n \n // 2) Handle upward propagation: check/uncheck all ancestors (only if biDirectionalChecking is enabled)\n if (biDirectionalChecking) {\n const item = byId.get(id);\n if (item) {\n let currentParentId = item.parentId;\n while (currentParentId) {\n const parentItem = byId.get(currentParentId);\n if (!parentItem || !isNodeCheckable(parentItem)) break;\n \n if (!checked) {\n // When checking a child, check the parent\n set.add(currentParentId);\n } else {\n // When unchecking a child, check if parent should be unchecked\n const parentChildren = byParent.get(currentParentId) ?? [];\n const hasCheckedChildren = parentChildren.some(child => \n isNodeCheckable(child) && set.has(child.id)\n );\n \n if (!hasCheckedChildren) {\n // No children are checked, so uncheck this parent\n set.delete(currentParentId);\n }\n }\n \n // Move up to the next parent\n currentParentId = parentItem.parentId;\n }\n }\n }\n \n onCheckedChange(set);\n },\n [checkedIds, onCheckedChange, computeCheckedState, getDescendants, byId, byParent, isNodeCheckable, biDirectionalChecking]\n );\n\n // Default checkbox renderer that handles tri-state logic\n const defaultCheckboxRenderer = useCallback(\n (args: { checked: boolean; indeterminate: boolean; onCheck: () => void }) => {\n return (\n <Checkbox\n name={`tree-checkbox-${Math.random().toString(36).substr(2, 9)}`}\n checked={args.checked}\n indeterminate={args.indeterminate}\n onChange={args.onCheck}\n />\n );\n },\n []\n );\n\n const toggle = useCallback(\n (id: string) => {\n const next = new Set(expandedIds);\n if (next.has(id)) next.delete(id);\n else next.add(id);\n onExpandedChange(next);\n },\n [expandedIds, onExpandedChange]\n );\n\n const select = useCallback(\n (id: string) => {\n // If the node is checkable, toggle its checkbox state\n const item = byId.get(id);\n if (item && isNodeCheckable(item) && onCheckedChange) {\n toggleCheck(id);\n }\n\n if (!onSelectedIdsChange) {\n onSelectedChange?.(id);\n return;\n }\n\n const isMulti = !!multiSelectRef.current;\n const next = isMulti ? new Set(selectedIds ?? []) : new Set<string>();\n \n if (isMulti && next.has(id)) {\n next.delete(id);\n } else {\n next.add(id);\n }\n \n onSelectedIdsChange(next);\n multiSelectRef.current = false;\n },\n [onSelectedChange, onSelectedIdsChange, selectedIds, byId, isNodeCheckable, onCheckedChange, toggleCheck]\n );\n\n const renderSubtree = (parentId: string | null, level: number): any => {\n const children = byParent.get(parentId) ?? [];\n if (!children.length) return null;\n const ulClass = level === 1 ? (className ?? 'acm-tree') : 'acm-tree__group';\n return (\n <ul role={level === 1 ? (role as any) : 'group'} className={ulClass}>\n {children.map((item, index) => {\n const childHasChildren = (byParent.get(item.id) ?? []).length > 0;\n const isExpanded = expandedIds.has(item.id);\n const isSelected = (selectedIds ? selectedIds.has(item.id) : (selectedId === item.id));\n const isDraggable = !!draggable?.(item);\n const allowDrop = (dragId: string) => (canDrop ? canDrop(dragId, item.id) : dragId !== item.id);\n // Optional helpers for Elsie-based UIs\n const expanderFactory = childHasChildren\n ? () => (renderExpander ? renderExpander({ expanded: isExpanded, hasChildren: childHasChildren, toggle: () => toggle(item.id) }) : null)\n : undefined;\n const checkboxFactory = (() => {\n if (!onCheckedChange) return undefined;\n const nodeObj = byId.get(item.id);\n if (!nodeObj || !isNodeCheckable(nodeObj)) return undefined;\n const s = computeCheckedState(item.id);\n const checkboxRenderer = renderCheckbox || defaultCheckboxRenderer;\n return () => checkboxRenderer({ checked: s.checked, indeterminate: s.indeterminate, onCheck: () => toggleCheck(item.id) });\n })();\n const iconFactory = renderIcon\n ? () => renderIcon({ item, level, hasChildren: childHasChildren, expanded: isExpanded })\n : undefined;\n\n const node = renderNode({\n item,\n level,\n expanded: isExpanded,\n selected: !!isSelected,\n hasChildren: childHasChildren,\n toggle: () => toggle(item.id),\n select: () => select(item.id),\n ...(expanderFactory ? { expander: expanderFactory } : {}),\n ...(checkboxFactory ? { checkbox: checkboxFactory } : {}),\n ...(iconFactory ? { icon: iconFactory } : {}),\n });\n return (\n <li\n key={item.id}\n role=\"treeitem\"\n className=\"acm-tree__item\"\n data-level={level}\n aria-expanded={childHasChildren ? isExpanded : undefined}\n aria-selected={isSelected || undefined}\n aria-level={level as any}\n aria-setsize={children.length as any}\n aria-posinset={(index + 1) as any}\n draggable={isDraggable}\n onMouseDown={(e) => {\n // Command (mac) or Ctrl (win/linux) enables multi-select\n multiSelectRef.current = !!(e.metaKey || e.ctrlKey);\n }}\n onDragStart={(e) => {\n e.stopPropagation();\n if (!isDraggable) return;\n draggingIdRef.current = item.id;\n try { e.dataTransfer?.setData('text/plain', item.id); } catch {}\n }}\n onDragOver={(e) => {\n e.stopPropagation();\n const dragId = draggingIdRef.current ?? (e.dataTransfer?.getData('text/plain') || '');\n if (dragId && allowDrop(dragId)) {\n e.preventDefault();\n }\n }}\n onDrop={(e) => {\n e.stopPropagation();\n const dragId = draggingIdRef.current ?? (e.dataTransfer?.getData('text/plain') || '');\n draggingIdRef.current = null;\n if (dragId && allowDrop(dragId)) {\n onMove?.({ id: dragId, newParentId: item.id });\n }\n }}\n >\n {node}\n {childHasChildren && isExpanded ? renderSubtree(item.id, level + 1) : null}\n </li>\n );\n })}\n </ul>\n );\n };\n\n return <div className=\"acm-tree-root\">{renderSubtree(rootId, 1)}</div>;\n};\n\nexport default Tree;\n"],"names":["buildChildrenMap","items","preserveOrder","byParent","item","key","list","a","b","Tree","rootId","className","expandedIds","selectedId","selectedIds","onExpandedChange","onSelectedChange","onSelectedIdsChange","renderNode","role","draggable","canDrop","onMove","isCheckable","checkedIds","onCheckedChange","biDirectionalChecking","renderExpander","renderCheckbox","renderIcon","useMemo","draggingIdRef","useRef","multiSelectRef","byId","i","collectDescendants","byParentMap","id","out","stack","cur","children","ch","getDescendants","useCallback","isNodeCheckable","computeCheckedState","set","descendants","nid","node","acc","all","numChecked","toggleCheck","checked","targets","currentParentId","parentItem","child","defaultCheckboxRenderer","args","jsx","Checkbox","toggle","next","select","isMulti","renderSubtree","parentId","level","index","childHasChildren","isExpanded","isSelected","isDraggable","allowDrop","dragId","expanderFactory","checkboxFactory","nodeObj","s","checkboxRenderer","iconFactory","jsxs","e","_a"],"mappings":"qNAwEA,MAAMA,GAAmB,CAACC,EAAmBC,EAAyB,KAA0C,CAC9G,MAAMC,MAAe,IACrB,UAAWC,KAAQH,EAAO,CACxB,MAAMI,EAAOD,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OAC7B,aAAYJ,EACZ,eAAc7B,EAAS,OACvB,gBAAgB8B,EAAQ,EACxB,UAAWI,EACX,YAAcU,GAAM,CAElBrD,EAAe,QAAU,CAAC,EAAEqD,EAAE,SAAWA,EAAE,QAC7C,EACA,YAAcA,GAAM,OAElB,GADAA,EAAE,gBAAA,EACE,EAACV,EACL,CAAA7C,EAAc,QAAU3B,EAAK,GAC7B,GAAI,EAAEmF,EAAAD,EAAE,eAAF,MAAAC,EAAgB,QAAQ,aAAcnF,EAAK,GAAK,MAAQ,CAAC,EACjE,EACA,WAAakF,GAAM,OACjBA,EAAE,gBAAA,EACF,MAAMR,EAAS/C,EAAc,YAAYwD,EAAAD,EAAE,eAAF,YAAAC,EAAgB,QAAQ,gBAAiB,IAC9ET,GAAUD,EAAUC,CAAM,GAC5BQ,EAAE,eAAA,CAEN,EACA,OAASA,GAAM,OACbA,EAAE,gBAAA,EACF,MAAMR,EAAS/C,EAAc,YAAYwD,EAAAD,EAAE,eAAF,YAAAC,EAAgB,QAAQ,gBAAiB,IAClFxD,EAAc,QAAU,KACpB+C,GAAUD,EAAUC,CAAM,IAC5BxD,GAAA,MAAAA,EAAS,CAAE,GAAIwD,EAAQ,YAAa1E,EAAK,KAE7C,EAEC,SAAA,CAAA+C,GACAsB,GAAoBC,EAAaL,EAAcjE,EAAK,GAAImE,EAAQ,CAAC,EAAI,IAAA,CAAA,EArCjEnE,EAAK,EAAA,CAwChB,CAAC,CAAA,CACH,EAjF2B,IAmF/B,EAEA,SAAQ,MAAA,CAAI,UAAU,gBAAiB,SAAAiE,EAAc3D,EAAQ,CAAC,EAAE,CAClE"}
|
|
1
|
+
{"version":3,"file":"Tree.js","sources":["/@dropins/storefront-company-management/src/components/Tree/Tree.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 *******************************************************************/\n\nimport { FunctionComponent } from 'preact';\nimport { useMemo, useCallback, useRef } from 'preact/hooks';\nimport { Checkbox } from '@adobe-commerce/elsie/components';\nimport './Tree.css';\n\nexport interface TreeItem {\n id: string;\n parentId?: string | null;\n label: string;\n}\n\nexport interface RenderNodeArgs {\n item: TreeItem;\n level: number;\n expanded: boolean;\n selected: boolean;\n hasChildren: boolean;\n toggle: () => void;\n select: () => void;\n // Optional Elsie-friendly render helpers\n expander?: () => any;\n checkbox?: () => any;\n icon?: () => any;\n}\n\nexport interface TreeProps {\n items: TreeItem[];\n rootId?: string | null;\n className?: string;\n expandedIds: Set<string>;\n selectedId?: string | null;\n selectedIds?: Set<string>;\n onExpandedChange: (next: Set<string>) => void;\n onSelectedChange?: (id: string | null) => void;\n onSelectedIdsChange?: (ids: Set<string>) => void;\n renderNode: (args: RenderNodeArgs) => any;\n role?: 'tree' | 'list' | 'grid'; // default 'tree'\n // Sorting behavior (optional)\n preserveOrder?: boolean; // If true, preserve the original order of items. If false/undefined, sort alphabetically by label\n // Drag & Drop (optional)\n draggable?: (item: TreeItem) => boolean;\n canDrop?: (dragId: string, targetId: string) => boolean;\n onMove?: (args: { id: string; newParentId: string }) => void;\n // Checkable (optional)\n isCheckable?: (item: TreeItem) => boolean;\n checkedIds?: Set<string>;\n onCheckedChange?: (next: Set<string>) => void;\n // Checkbox behavior (optional)\n biDirectionalChecking?: boolean; // If true, checking a node directly marks it as checked. If false, uses descendant-based logic (default: false)\n // Optional Elsie-friendly render-props to build UI primitives\n renderExpander?: (args: { expanded: boolean; hasChildren: boolean; toggle: () => void }) => any;\n renderCheckbox?: (args: { checked: boolean; indeterminate: boolean; onCheck: () => void }) => any;\n renderIcon?: (args: { item: TreeItem; level: number; hasChildren: boolean; expanded: boolean }) => any;\n}\n\nconst buildChildrenMap = (items: TreeItem[], preserveOrder: boolean = false): Map<string | null, TreeItem[]> => {\n const byParent = new Map<string | null, TreeItem[]>();\n for (const item of items) {\n const key = (item.parentId ?? null) as string | null;\n const list = byParent.get(key) ?? [];\n list.push(item);\n byParent.set(key, list);\n }\n \n // Apply sorting based on preserveOrder flag\n if (!preserveOrder) {\n // Default behavior: stable sort by label for determinism\n for (const [, list] of byParent) {\n list.sort((a, b) => a.label.localeCompare(b.label));\n }\n }\n // If preserveOrder is true, keep the original order (e.g., sorted by sort_order)\n \n return byParent;\n};\n\nexport const Tree: FunctionComponent<TreeProps> = ({\n items,\n rootId = null,\n className,\n expandedIds,\n selectedId = null,\n selectedIds,\n onExpandedChange,\n onSelectedChange,\n onSelectedIdsChange,\n renderNode,\n role = 'tree',\n preserveOrder = false,\n draggable,\n canDrop,\n onMove,\n isCheckable,\n checkedIds,\n onCheckedChange,\n biDirectionalChecking = false,\n renderExpander,\n renderCheckbox,\n renderIcon,\n}) => {\n const byParent = useMemo(() => buildChildrenMap(items, preserveOrder), [items, preserveOrder]);\n const draggingIdRef = useRef<string | null>(null);\n const multiSelectRef = useRef<boolean>(false);\n\n const byId = useMemo(() => new Map(items.map((i) => [i.id, i] as const)), [items]);\n\n const collectDescendants = (\n byParentMap: Map<string | null, TreeItem[]>,\n id: string\n ): string[] => {\n const out: string[] = [];\n const stack = [id];\n while (stack.length) {\n const cur = stack.pop()!;\n const children = byParentMap.get(cur) ?? [];\n for (const ch of children) {\n out.push(ch.id);\n stack.push(ch.id);\n }\n }\n return out;\n };\n\n const getDescendants = useCallback(\n (id: string): string[] => {\n return collectDescendants(byParent, id);\n },\n [byParent]\n );\n\n const isNodeCheckable = useCallback((item: TreeItem) => (isCheckable ? isCheckable(item) : true), [isCheckable]);\n\n const computeCheckedState = useCallback(\n (id: string): { checked: boolean; indeterminate: boolean } => {\n const item = byId.get(id);\n if (!item) return { checked: false, indeterminate: false };\n \n const set = checkedIds ?? new Set<string>();\n \n if (biDirectionalChecking) {\n // If this node is directly checked, show it as checked\n if (set.has(id)) {\n return { checked: true, indeterminate: false };\n }\n \n // Otherwise, check descendants to determine indeterminate state\n const descendants = getDescendants(id).filter((nid) => {\n const node = byId.get(nid);\n return node ? isNodeCheckable(node) : false;\n });\n \n if (descendants.length === 0) return { checked: false, indeterminate: false };\n \n const numCheckedDescendants = descendants.reduce((acc, nid) => (set.has(nid) ? acc + 1 : acc), 0);\n \n if (numCheckedDescendants === 0) return { checked: false, indeterminate: false };\n return { checked: false, indeterminate: true };\n }\n \n // Check if node and ALL descendants are checked\n const all = [id, ...getDescendants(id)].filter((nid) => {\n const node = byId.get(nid);\n return node ? isNodeCheckable(node) : false;\n });\n \n if (all.length === 0) return { checked: false, indeterminate: false };\n \n const numChecked = all.reduce((acc, nid) => (set.has(nid) ? acc + 1 : acc), 0);\n \n if (numChecked === 0) return { checked: false, indeterminate: false };\n if (numChecked === all.length) return { checked: true, indeterminate: false };\n return { checked: false, indeterminate: true };\n },\n [byId, getDescendants, isNodeCheckable, checkedIds, biDirectionalChecking]\n );\n\n const toggleCheck = useCallback(\n (id: string) => {\n if (!onCheckedChange) return;\n \n const set = new Set(checkedIds ?? []);\n const { checked } = computeCheckedState(id);\n \n // 1) Handle downward propagation: check/uncheck this node and all descendants\n const descendants = getDescendants(id);\n const targets = [id, ...descendants].filter((nid) => {\n const node = byId.get(nid);\n return node ? isNodeCheckable(node) : false;\n });\n \n if (checked) {\n // Unchecking: remove this node and all descendants\n for (const nid of targets) set.delete(nid);\n } else {\n // Checking: add this node and all descendants\n for (const nid of targets) set.add(nid);\n }\n \n // 2) Handle upward propagation: only check ancestors when checking\n if (biDirectionalChecking && !checked) {\n const item = byId.get(id);\n if (item) {\n let currentParentId = item.parentId;\n while (currentParentId) {\n const parentItem = byId.get(currentParentId);\n if (!parentItem || !isNodeCheckable(parentItem)) break;\n \n // When checking a child, check the parent\n set.add(currentParentId);\n \n // Move up to the next parent\n currentParentId = parentItem.parentId;\n }\n }\n }\n \n onCheckedChange(set);\n },\n [checkedIds, onCheckedChange, computeCheckedState, getDescendants, byId, isNodeCheckable, biDirectionalChecking]\n );\n\n // Default checkbox renderer that handles tri-state logic\n const defaultCheckboxRenderer = useCallback(\n (args: { checked: boolean; indeterminate: boolean; onCheck: () => void }) => {\n return (\n <Checkbox\n name={`tree-checkbox-${Math.random().toString(36).substr(2, 9)}`}\n checked={args.checked}\n indeterminate={args.indeterminate}\n onChange={args.onCheck}\n />\n );\n },\n []\n );\n\n const toggle = useCallback(\n (id: string) => {\n const next = new Set(expandedIds);\n if (next.has(id)) next.delete(id);\n else next.add(id);\n onExpandedChange(next);\n },\n [expandedIds, onExpandedChange]\n );\n\n const select = useCallback(\n (id: string) => {\n // If the node is checkable, toggle its checkbox state\n const item = byId.get(id);\n if (item && isNodeCheckable(item) && onCheckedChange) {\n toggleCheck(id);\n }\n\n if (!onSelectedIdsChange) {\n onSelectedChange?.(id);\n return;\n }\n\n const isMulti = !!multiSelectRef.current;\n const next = isMulti ? new Set(selectedIds ?? []) : new Set<string>();\n \n if (isMulti && next.has(id)) {\n next.delete(id);\n } else {\n next.add(id);\n }\n \n onSelectedIdsChange(next);\n multiSelectRef.current = false;\n },\n [onSelectedChange, onSelectedIdsChange, selectedIds, byId, isNodeCheckable, onCheckedChange, toggleCheck]\n );\n\n const renderSubtree = (parentId: string | null, level: number): any => {\n const children = byParent.get(parentId) ?? [];\n if (!children.length) return null;\n const ulClass = level === 1 ? (className ?? 'acm-tree') : 'acm-tree__group';\n return (\n <ul role={level === 1 ? (role as any) : 'group'} className={ulClass}>\n {children.map((item, index) => {\n const childHasChildren = (byParent.get(item.id) ?? []).length > 0;\n const isExpanded = expandedIds.has(item.id);\n const isSelected = (selectedIds ? selectedIds.has(item.id) : (selectedId === item.id));\n const isDraggable = !!draggable?.(item);\n const allowDrop = (dragId: string) => (canDrop ? canDrop(dragId, item.id) : dragId !== item.id);\n // Optional helpers for Elsie-based UIs\n const expanderFactory = childHasChildren\n ? () => (renderExpander ? renderExpander({ expanded: isExpanded, hasChildren: childHasChildren, toggle: () => toggle(item.id) }) : null)\n : undefined;\n const checkboxFactory = (() => {\n if (!onCheckedChange) return undefined;\n const nodeObj = byId.get(item.id);\n if (!nodeObj || !isNodeCheckable(nodeObj)) return undefined;\n const s = computeCheckedState(item.id);\n const checkboxRenderer = renderCheckbox || defaultCheckboxRenderer;\n return () => checkboxRenderer({ checked: s.checked, indeterminate: s.indeterminate, onCheck: () => toggleCheck(item.id) });\n })();\n const iconFactory = renderIcon\n ? () => renderIcon({ item, level, hasChildren: childHasChildren, expanded: isExpanded })\n : undefined;\n\n const node = renderNode({\n item,\n level,\n expanded: isExpanded,\n selected: !!isSelected,\n hasChildren: childHasChildren,\n toggle: () => toggle(item.id),\n select: () => select(item.id),\n ...(expanderFactory ? { expander: expanderFactory } : {}),\n ...(checkboxFactory ? { checkbox: checkboxFactory } : {}),\n ...(iconFactory ? { icon: iconFactory } : {}),\n });\n return (\n <li\n key={item.id}\n role=\"treeitem\"\n className=\"acm-tree__item\"\n data-level={level}\n aria-expanded={childHasChildren ? isExpanded : undefined}\n aria-selected={isSelected || undefined}\n aria-level={level as any}\n aria-setsize={children.length as any}\n aria-posinset={(index + 1) as any}\n draggable={isDraggable}\n onMouseDown={(e) => {\n // Command (mac) or Ctrl (win/linux) enables multi-select\n multiSelectRef.current = !!(e.metaKey || e.ctrlKey);\n }}\n onDragStart={(e) => {\n e.stopPropagation();\n if (!isDraggable) return;\n draggingIdRef.current = item.id;\n try { e.dataTransfer?.setData('text/plain', item.id); } catch {}\n }}\n onDragOver={(e) => {\n e.stopPropagation();\n const dragId = draggingIdRef.current ?? (e.dataTransfer?.getData('text/plain') || '');\n if (dragId && allowDrop(dragId)) {\n e.preventDefault();\n }\n }}\n onDrop={(e) => {\n e.stopPropagation();\n const dragId = draggingIdRef.current ?? (e.dataTransfer?.getData('text/plain') || '');\n draggingIdRef.current = null;\n if (dragId && allowDrop(dragId)) {\n onMove?.({ id: dragId, newParentId: item.id });\n }\n }}\n >\n {node}\n {childHasChildren && isExpanded ? renderSubtree(item.id, level + 1) : null}\n </li>\n );\n })}\n </ul>\n );\n };\n\n return <div className=\"acm-tree-root\">{renderSubtree(rootId, 1)}</div>;\n};\n\nexport default Tree;\n"],"names":["buildChildrenMap","items","preserveOrder","byParent","item","key","list","a","b","Tree","rootId","className","expandedIds","selectedId","selectedIds","onExpandedChange","onSelectedChange","onSelectedIdsChange","renderNode","role","draggable","canDrop","onMove","isCheckable","checkedIds","onCheckedChange","biDirectionalChecking","renderExpander","renderCheckbox","renderIcon","useMemo","draggingIdRef","useRef","multiSelectRef","byId","i","collectDescendants","byParentMap","id","out","stack","cur","children","ch","getDescendants","useCallback","isNodeCheckable","computeCheckedState","set","descendants","nid","node","acc","all","numChecked","toggleCheck","checked","targets","currentParentId","parentItem","defaultCheckboxRenderer","args","jsx","Checkbox","toggle","next","select","isMulti","renderSubtree","parentId","level","index","childHasChildren","isExpanded","isSelected","isDraggable","allowDrop","dragId","expanderFactory","checkboxFactory","nodeObj","s","checkboxRenderer","iconFactory","jsxs","e","_a"],"mappings":"qNAwEA,MAAMA,GAAmB,CAACC,EAAmBC,EAAyB,KAA0C,CAC9G,MAAMC,MAAe,IACrB,UAAWC,KAAQH,EAAO,CACxB,MAAMI,EAAOD,EAAK,UAAY,KACxBE,EAAOH,EAAS,IAAIE,CAAG,GAAK,CAAA,EAClCC,EAAK,KAAKF,CAAI,EACdD,EAAS,IAAIE,EAAKC,CAAI,CACxB,CAGA,GAAI,CAACJ,EAEH,SAAW,CAAA,CAAGI,CAAI,IAAKH,EACrBG,EAAK,KAAK,CAACC,EAAGC,IAAMD,EAAE,MAAM,cAAcC,EAAE,KAAK,CAAC,EAKtD,OAAOL,CACT,EAEaM,GAAqC,CAAC,CACjD,MAAAR,EACA,OAAAS,EAAS,KACT,UAAAC,EACA,YAAAC,EACA,WAAAC,EAAa,KACb,YAAAC,EACA,iBAAAC,EACA,iB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A,EAAE,gBAAA,EACF,MAAMR,EAAS9C,EAAc,YAAYuD,EAAAD,EAAE,eAAF,YAAAC,EAAgB,QAAQ,gBAAiB,IAClFvD,EAAc,QAAU,KACpB8C,GAAUD,EAAUC,CAAM,IAC5BvD,GAAA,MAAAA,EAAS,CAAE,GAAIuD,EAAQ,YAAazE,EAAK,KAE7C,EAEC,SAAA,CAAA+C,GACAqB,GAAoBC,EAAaL,EAAchE,EAAK,GAAIkE,EAAQ,CAAC,EAAI,IAAA,CAAA,EArCjElE,EAAK,EAAA,CAwChB,CAAC,CAAA,CACH,EAjF2B,IAmF/B,EAEA,SAAQ,MAAA,CAAI,UAAU,gBAAiB,SAAAgE,EAAc1D,EAAQ,CAAC,EAAE,CAClE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
const i=(n=[])=>{const t=new Set,a=[...n];for(;a.length;){const s=a.pop();if(s&&(typeof s.id=="string"&&t.add(s.id),Array.isArray(s.children)&&s.children.length))for(const o of s.children)a.push(o)}return t},c=(n=[])=>Array.from(i(n)),e=n=>(n==null?void 0:n.id)==="0"||typeof(n==null?void 0:n.id)=="number"&&(n==null?void 0:n.id)===0||(n==null?void 0:n.id)==="MA=="||(n==null?void 0:n.name)==="Company Administrator",d=()=>["Magento_Company::view_account","Magento_Company::edit_account","Magento_Company::view_address","Magento_Company::edit_address","Magento_Company::contacts","Magento_Company::payment_information","Magento_Company::shipping_information","Magento_Company::users_view","Magento_Company::users_edit","Magento_Company::roles_view","Magento_Company::roles_edit"],m=n=>{const t=i((n==null?void 0:n.permissions)||[]),a=e(n);return{canViewAccount:a||t.has("Magento_Company::view_account"),canEditAccount:a||t.has("Magento_Company::edit_account"),canViewAddress:a||t.has("Magento_Company::view_address"),canEditAddress:a||t.has("Magento_Company::edit_address"),canViewContacts:a||t.has("Magento_Company::contacts"),canViewPaymentInformation:a||t.has("Magento_Company::payment_information"),canViewShippingInformation:a||t.has("Magento_Company::shipping_information"),canViewUsers:a||t.has("Magento_Company::users_view"),canEditUsers:a||t.has("Magento_Company::users_edit"),canViewRoles:a||t.has("Magento_Company::roles_view"),canManageRoles:a||t.has("Magento_Company::roles_edit")}};export{
|
|
3
|
+
const i=(n=[])=>{const t=new Set,a=[...n];for(;a.length;){const s=a.pop();if(s&&(typeof s.id=="string"&&t.add(s.id),Array.isArray(s.children)&&s.children.length))for(const o of s.children)a.push(o)}return t},c=(n=[])=>Array.from(i(n)),e=n=>(n==null?void 0:n.id)==="0"||typeof(n==null?void 0:n.id)=="number"&&(n==null?void 0:n.id)===0||(n==null?void 0:n.id)==="MA=="||(n==null?void 0:n.name)==="Company Administrator",d=()=>["Magento_Company::view_account","Magento_Company::edit_account","Magento_Company::view_address","Magento_Company::edit_address","Magento_Company::contacts","Magento_Company::payment_information","Magento_Company::shipping_information","Magento_Company::users_view","Magento_Company::users_edit","Magento_Company::roles_view","Magento_Company::roles_edit"],m=n=>{const t=i((n==null?void 0:n.permissions)||[]),a=e(n);return{canViewAccount:a||t.has("Magento_Company::view_account"),canEditAccount:a||t.has("Magento_Company::edit_account"),canViewAddress:a||t.has("Magento_Company::view_address"),canEditAddress:a||t.has("Magento_Company::edit_address"),canViewContacts:a||t.has("Magento_Company::contacts"),canViewPaymentInformation:a||t.has("Magento_Company::payment_information"),canViewShippingInformation:a||t.has("Magento_Company::shipping_information"),canViewUsers:a||t.has("Magento_Company::users_view"),canEditUsers:a||t.has("Magento_Company::users_edit"),canViewRoles:a||t.has("Magento_Company::roles_view"),canManageRoles:a||t.has("Magento_Company::roles_edit")}};export{i as a,m as b,c as f,d as g,e as i};
|
|
4
4
|
//# sourceMappingURL=company-permissions.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{
|
|
3
|
+
import{a as c,i as h,g as m}from"./company-permissions.js";import{h as e}from"./fetch-error.js";import{f as o,h as f}from"./network-error.js";const E=`
|
|
4
4
|
query GET_CUSTOMER_ROLE_PERMISSIONS {
|
|
5
5
|
customer {
|
|
6
6
|
role {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{a}from"./validateCompanyEmail.js";import{f as d,h as l}from"./network-error.js";import{h as g}from"./fetch-error.js";const u=`
|
|
3
|
+
import{t as a}from"./validateCompanyEmail.js";import{f as d,h as l}from"./network-error.js";import{h as g}from"./fetch-error.js";const u=`
|
|
4
4
|
mutation CreateCompany($input: CompanyCreateInput!) {
|
|
5
5
|
createCompany(input: $input) {
|
|
6
6
|
company {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-store-config.js","sources":["/@dropins/storefront-company-management/src/api/createCompany/graphql/createCompany.graphql.ts","/@dropins/storefront-company-management/src/data/transforms/company.ts","/@dropins/storefront-company-management/src/api/createCompany/createCompany.ts","/@dropins/storefront-company-management/src/api/getStoreConfig/graphql/getStoreConfig.graphql.ts","/@dropins/storefront-company-management/src/api/getStoreConfig/getStoreConfig.ts","/@dropins/storefront-company-management/src/data/transforms/transform-store-config.ts"],"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 *******************************************************************/\n\nexport const CREATE_COMPANY_MUTATION = /* GraphQL */ `\n mutation CreateCompany($input: CompanyCreateInput!) {\n createCompany(input: $input) {\n company {\n id\n name\n email\n legal_name\n vat_tax_id\n reseller_id\n legal_address {\n street\n city\n region {\n region_code\n region\n region_id\n }\n postcode\n country_code\n telephone\n }\n company_admin {\n id\n firstname\n lastname\n email\n job_title\n telephone\n }\n }\n }\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 *******************************************************************/\n\nimport { CompanyFormData } from '../models/company';\nimport { CompanyCreateInput } from '@/company-management/api/createCompany';\n\nexport const transformFormDataToCreateInput = (formData: CompanyFormData): CompanyCreateInput => {\n // Build region object - ensure we have at least one region field\n const regionInput: any = {};\n \n // Handle region data based on what we receive from the form\n if (formData.regionCode && formData.regionCode.trim()) {\n // We have regionCode (preferred path)\n regionInput.region_code = formData.regionCode.trim();\n if (formData.regionId) {\n regionInput.region_id = typeof formData.regionId === 'string' ? parseInt(formData.regionId, 10) : formData.regionId;\n }\n } else if (formData.region && typeof formData.region === 'string' && formData.region.includes(',')) {\n // Dropdown selection: parse \"AL,4\" format as fallback\n const [regionCode, regionId] = formData.region.split(',');\n regionInput.region_code = regionCode.trim();\n regionInput.region_id = parseInt(regionId.trim(), 10);\n } else if (formData.region && formData.region.trim()) {\n const regionValue = formData.region.trim();\n // Check if this is a numeric regionId (from dropdown) or text region name\n if (/^\\d+$/.test(regionValue)) {\n // This is likely a regionId from dropdown, but we only have the ID\n // We need both region_code and region_id for GraphQL, but we can't proceed without region_code\n throw new Error('Region selection error: Missing region code. Please ensure regions are properly loaded.');\n } else {\n // Text input: free-form region name (countries without predefined regions)\n regionInput.region = regionValue;\n regionInput.region_code = regionValue;\n }\n }\n \n // Ensure we have at least region_code (required by GraphQL)\n if (!regionInput.region_code) {\n throw new Error('Region code is required. Please select a state/province or enter a region name.');\n }\n\n return {\n company_name: formData.companyName,\n company_email: formData.companyEmail,\n legal_name: formData.legalName,\n vat_tax_id: formData.vatTaxId,\n reseller_id: formData.resellerId,\n legal_address: {\n street: Array.isArray(formData.street) \n ? formData.street.filter((line: string) => line && line.trim() !== '') // Remove empty lines\n : [formData.street].filter((line: string) => line && line.trim() !== ''), // Handle case where street is not an array\n city: formData.city,\n region: regionInput,\n postcode: formData.postcode,\n country_id: formData.countryCode,\n telephone: formData.addressTelephone,\n },\n company_admin: {\n email: formData.adminEmail,\n firstname: formData.adminFirstname?.trim() || '',\n lastname: formData.adminLastname?.trim() || '',\n job_title: formData.adminJobTitle,\n telephone: formData.adminWorkTelephone,\n gender: formData.adminGender ? (typeof formData.adminGender === 'string' ? parseInt(formData.adminGender, 10) : formData.adminGender) : undefined,\n custom_attributes: formData.adminCustomAttributes?.map(attr => ({\n attribute_code: attr.attribute_code,\n value: attr.value,\n })) || [],\n },\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 *******************************************************************/\n\nimport { fetchGraphQl } from '@/company-management/api/fetch-graphql';\nimport { CREATE_COMPANY_MUTATION } from './graphql/createCompany.graphql';\nimport { CompanyRegistrationModel } from '@/company-management/data/models/company';\nimport { transformFormDataToCreateInput } from '@/company-management/data/transforms/company';\nimport { transformCreateCompanyResponse } from '@/company-management/data/transforms/transform-company';\n\nexport interface CompanyCreateInput {\n company_name: string;\n company_email: string;\n legal_name?: string;\n vat_tax_id?: string;\n reseller_id?: string;\n legal_address: {\n street: string[];\n city: string;\n region: {\n region_code: string;\n region?: string;\n region_id?: number;\n };\n postcode: string;\n country_id: string;\n telephone?: string;\n };\n company_admin: {\n email: string;\n firstname: string;\n lastname: string;\n job_title?: string;\n telephone?: string;\n gender?: number;\n custom_attributes?: Array<{\n attribute_code: string;\n value: string;\n }>;\n };\n}\n\n\nexport const createCompany = async (formData: any): Promise<{ success: boolean; company?: CompanyRegistrationModel; errors?: string[] }> => {\n try {\n const input = transformFormDataToCreateInput(formData);\n const response = await fetchGraphQl(CREATE_COMPANY_MUTATION, {\n method: 'POST',\n variables: { input },\n });\n\n if (response.errors?.length) {\n return {\n success: false,\n errors: response.errors.map((error: any) => error.message),\n };\n }\n\n // Transform the GraphQL response using the dedicated transformer\n const transformedCompany = transformCreateCompanyResponse(response);\n\n return {\n success: true,\n company: transformedCompany,\n };\n } catch (error) {\n console.error('Failed to create company:', error);\n return {\n success: false,\n errors: ['Failed to create company. Please try again.'],\n };\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 *******************************************************************/\n\nexport const GET_STORE_CONFIG_QUERY = /* GraphQL */ `\n query getStoreConfig {\n storeConfig {\n default_country\n store_code\n }\n }\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 *******************************************************************/\n\nimport { fetchGraphQl } from '../fetch-graphql';\nimport { GET_STORE_CONFIG_QUERY } from './graphql/getStoreConfig.graphql';\nimport { handleNetworkError } from '@/company-management/lib/network-error';\nimport { handleFetchError } from '@/company-management/lib/fetch-error';\nimport { GetStoreConfigResponse, StoreConfigModel } from '@/company-management/types';\nimport { transformStoreConfig } from '@/company-management/data/transforms';\n\nexport const DEFAULT_COUNTRY = 'US';\n\nexport const STORE_CONFIG_DEFAULTS: StoreConfigModel = {\n defaultCountry: DEFAULT_COUNTRY,\n storeCode: '',\n};\n\nexport const getStoreConfig = async (): Promise<StoreConfigModel> => {\n return await fetchGraphQl(GET_STORE_CONFIG_QUERY, {\n method: 'GET',\n })\n .then((response: GetStoreConfigResponse) => {\n if (response.errors?.length) return handleFetchError(response.errors);\n\n return transformStoreConfig(response);\n })\n .catch(handleNetworkError);\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 *******************************************************************/\n\nimport { GetStoreConfigResponse, StoreConfigModel } from '@/company-management/types';\nimport { STORE_CONFIG_DEFAULTS } from '@/company-management/api/getStoreConfig/getStoreConfig';\n\nexport const transformStoreConfig = (\n response: GetStoreConfigResponse\n): StoreConfigModel => {\n if (!response?.data?.storeConfig) return STORE_CONFIG_DEFAULTS;\n\n const { default_country, store_code } = response.data.storeConfig;\n\n return {\n defaultCountry: default_country || STORE_CONFIG_DEFAULTS.defaultCountry,\n storeCode: store_code || STORE_CONFIG_DEFAULTS.storeCode,\n };\n};\n"],"names":["CREATE_COMPANY_MUTATION","transformFormDataToCreateInput","formData","regionInput","regionCode","regionId","regionValue","line","_a","_b","_c","attr","createCompany","input","response","fetchGraphQl","error","transformCreateCompanyResponse","GET_STORE_CONFIG_QUERY","D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Q,KAAA,CACT,EACE,KAAMJ,GAAqC,OAC1C,OAAIN,EAAAM,EAAS,SAAT,MAAAN,EAAiB,OAAec,EAAiBR,EAAS,MAAM,EAE7DS,EAAqBT,CAAQ,CACtC,CAAC,EACA,MAAMU,CAAkB,ECpBhBD,EACXT,GACqB,OACrB,GAAI,GAACN,EAAAM,GAAA,YAAAA,EAAU,OAAV,MAAAN,EAAgB,aAAa,OAAOY,EAEzC,KAAM,CAAE,gBAAAK,EAAiB,WAAAC,CAAA,EAAeZ,EAAS,KAAK,YAEtD,MAAO,CACL,eAAgBW,GAAmBL,EAAsB,eACzD,UAAWM,GAAcN,EAAsB,SAAA,CAEnD"}
|
|
1
|
+
{"version":3,"file":"transform-store-config.js","sources":["/@dropins/storefront-company-management/src/api/createCompany/graphql/createCompany.graphql.ts","/@dropins/storefront-company-management/src/data/transforms/company.ts","/@dropins/storefront-company-management/src/api/createCompany/createCompany.ts","/@dropins/storefront-company-management/src/api/getStoreConfig/graphql/getStoreConfig.graphql.ts","/@dropins/storefront-company-management/src/api/getStoreConfig/getStoreConfig.ts","/@dropins/storefront-company-management/src/data/transforms/transform-store-config.ts"],"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 *******************************************************************/\n\nexport const CREATE_COMPANY_MUTATION = /* GraphQL */ `\n mutation CreateCompany($input: CompanyCreateInput!) {\n createCompany(input: $input) {\n company {\n id\n name\n email\n legal_name\n vat_tax_id\n reseller_id\n legal_address {\n street\n city\n region {\n region_code\n region\n region_id\n }\n postcode\n country_code\n telephone\n }\n company_admin {\n id\n firstname\n lastname\n email\n job_title\n telephone\n }\n }\n }\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 *******************************************************************/\n\nimport { CompanyFormData } from '../models/company';\nimport { CompanyCreateInput } from '@/company-management/api/createCompany';\n\nexport const transformFormDataToCreateInput = (formData: CompanyFormData): CompanyCreateInput => {\n // Build region object - ensure we have at least one region field\n const regionInput: any = {};\n \n // Handle region data based on what we receive from the form\n if (formData.regionCode && formData.regionCode.trim()) {\n // We have regionCode (preferred path)\n regionInput.region_code = formData.regionCode.trim();\n if (formData.regionId) {\n regionInput.region_id = typeof formData.regionId === 'string' ? parseInt(formData.regionId, 10) : formData.regionId;\n }\n } else if (formData.region && typeof formData.region === 'string' && formData.region.includes(',')) {\n // Dropdown selection: parse \"AL,4\" format as fallback\n const [regionCode, regionId] = formData.region.split(',');\n regionInput.region_code = regionCode.trim();\n regionInput.region_id = parseInt(regionId.trim(), 10);\n } else if (formData.region && formData.region.trim()) {\n const regionValue = formData.region.trim();\n // Check if this is a numeric regionId (from dropdown) or text region name\n if (/^\\d+$/.test(regionValue)) {\n // This is likely a regionId from dropdown, but we only have the ID\n // We need both region_code and region_id for GraphQL, but we can't proceed without region_code\n throw new Error('Region selection error: Missing region code. Please ensure regions are properly loaded.');\n } else {\n // Text input: free-form region name (countries without predefined regions)\n regionInput.region = regionValue;\n regionInput.region_code = regionValue;\n }\n }\n \n // Ensure we have at least region_code (required by GraphQL)\n if (!regionInput.region_code) {\n throw new Error('Region code is required. Please select a state/province or enter a region name.');\n }\n\n return {\n company_name: formData.companyName,\n company_email: formData.companyEmail,\n legal_name: formData.legalName,\n vat_tax_id: formData.vatTaxId,\n reseller_id: formData.resellerId,\n legal_address: {\n street: Array.isArray(formData.street) \n ? formData.street.filter((line: string) => line && line.trim() !== '') // Remove empty lines\n : [formData.street].filter((line: string) => line && line.trim() !== ''), // Handle case where street is not an array\n city: formData.city,\n region: regionInput,\n postcode: formData.postcode,\n country_id: formData.countryCode,\n telephone: formData.addressTelephone,\n },\n company_admin: {\n email: formData.adminEmail,\n firstname: formData.adminFirstname?.trim() || '',\n lastname: formData.adminLastname?.trim() || '',\n job_title: formData.adminJobTitle,\n telephone: formData.adminWorkTelephone,\n gender: formData.adminGender ? (typeof formData.adminGender === 'string' ? parseInt(formData.adminGender, 10) : formData.adminGender) : undefined,\n custom_attributes: formData.adminCustomAttributes?.map(attr => ({\n attribute_code: attr.attribute_code,\n value: attr.value,\n })) || [],\n },\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 *******************************************************************/\n\nimport { fetchGraphQl } from '@/company-management/api/fetch-graphql';\nimport { CREATE_COMPANY_MUTATION } from './graphql/createCompany.graphql';\nimport { CompanyRegistrationModel } from '@/company-management/data/models/company';\nimport { transformFormDataToCreateInput } from '@/company-management/data/transforms/company';\nimport { transformCreateCompanyResponse } from '@/company-management/data/transforms/transform-company';\n\nexport interface CompanyCreateInput {\n company_name: string;\n company_email: string;\n legal_name?: string;\n vat_tax_id?: string;\n reseller_id?: string;\n legal_address: {\n street: string[];\n city: string;\n region: {\n region_code: string;\n region?: string;\n region_id?: number;\n };\n postcode: string;\n country_id: string;\n telephone?: string;\n };\n company_admin: {\n email: string;\n firstname: string;\n lastname: string;\n job_title?: string;\n telephone?: string;\n gender?: number;\n custom_attributes?: Array<{\n attribute_code: string;\n value: string;\n }>;\n };\n}\n\n\nexport const createCompany = async (formData: any): Promise<{ success: boolean; company?: CompanyRegistrationModel; errors?: string[] }> => {\n try {\n const input = transformFormDataToCreateInput(formData);\n const response = await fetchGraphQl(CREATE_COMPANY_MUTATION, {\n method: 'POST',\n variables: { input },\n });\n\n if (response.errors?.length) {\n return {\n success: false,\n errors: response.errors.map((error: any) => error.message),\n };\n }\n\n // Transform the GraphQL response using the dedicated transformer\n const transformedCompany = transformCreateCompanyResponse(response);\n\n return {\n success: true,\n company: transformedCompany,\n };\n } catch (error) {\n console.error('Failed to create company:', error);\n return {\n success: false,\n errors: ['Failed to create company. Please try again.'],\n };\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 *******************************************************************/\n\nexport const GET_STORE_CONFIG_QUERY = /* GraphQL */ `\n query getStoreConfig {\n storeConfig {\n default_country\n store_code\n }\n }\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 *******************************************************************/\n\nimport { fetchGraphQl } from '../fetch-graphql';\nimport { GET_STORE_CONFIG_QUERY } from './graphql/getStoreConfig.graphql';\nimport { handleNetworkError } from '@/company-management/lib/network-error';\nimport { handleFetchError } from '@/company-management/lib/fetch-error';\nimport { GetStoreConfigResponse, StoreConfigModel } from '@/company-management/types';\nimport { transformStoreConfig } from '@/company-management/data/transforms';\n\nexport const DEFAULT_COUNTRY = 'US';\n\nexport const STORE_CONFIG_DEFAULTS: StoreConfigModel = {\n defaultCountry: DEFAULT_COUNTRY,\n storeCode: '',\n};\n\nexport const getStoreConfig = async (): Promise<StoreConfigModel> => {\n return await fetchGraphQl(GET_STORE_CONFIG_QUERY, {\n method: 'GET',\n })\n .then((response: GetStoreConfigResponse) => {\n if (response.errors?.length) return handleFetchError(response.errors);\n\n return transformStoreConfig(response);\n })\n .catch(handleNetworkError);\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 *******************************************************************/\n\nimport { GetStoreConfigResponse, StoreConfigModel } from '@/company-management/types';\nimport { STORE_CONFIG_DEFAULTS } from '@/company-management/api/getStoreConfig/getStoreConfig';\n\nexport const transformStoreConfig = (\n response: GetStoreConfigResponse\n): StoreConfigModel => {\n if (!response?.data?.storeConfig) return STORE_CONFIG_DEFAULTS;\n\n const { default_country, store_code } = response.data.storeConfig;\n\n return {\n defaultCountry: default_country || STORE_CONFIG_DEFAULTS.defaultCountry,\n storeCode: store_code || STORE_CONFIG_DEFAULTS.storeCode,\n };\n};\n"],"names":["CREATE_COMPANY_MUTATION","transformFormDataToCreateInput","formData","regionInput","regionCode","regionId","regionValue","line","_a","_b","_c","attr","createCompany","input","response","fetchGraphQl","error","transformCreateCompanyResponse","GET_STORE_CONFIG_QUERY","DEFAULT_COUNTRY","STORE_CONFIG_DEFAULTS","getStoreConfig","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N,EAAAM,EAAS,SAAT,MAAAN,EAAiB,OAAec,EAAiBR,EAAS,MAAM,EAE7DS,EAAqBT,CAAQ,CACtC,CAAC,EACA,MAAMU,CAAkB,ECpBhBD,EACXT,GACqB,OACrB,GAAI,GAACN,EAAAM,GAAA,YAAAA,EAAU,OAAV,MAAAN,EAAgB,aAAa,OAAOY,EAEzC,KAAM,CAAE,gBAAAK,EAAiB,WAAAC,CAAA,EAAeZ,EAAS,KAAK,YAEtD,MAAO,CACL,eAAgBW,GAAmBL,EAAsB,eACzD,UAAWM,GAAcN,EAAsB,SAAA,CAEnD"}
|
package/chunks/updateCompany.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{f as _}from"./fetchUserPermissions.js";import{f as m,h as A}from"./network-error.js";import{h as c}from"./fetch-error.js";import{
|
|
3
|
+
import{f as _}from"./fetchUserPermissions.js";import{f as m,h as A}from"./network-error.js";import{h as c}from"./fetch-error.js";import{a as C}from"./validateCompanyEmail.js";const f=`
|
|
4
4
|
fragment COMPANY_LEGAL_ADDRESS_FRAGMENT on CompanyLegalAddress {
|
|
5
5
|
street
|
|
6
6
|
city
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{f as o,h as
|
|
3
|
+
import{f as o,h as u}from"./network-error.js";import{h as i}from"./fetch-error.js";const d=`
|
|
4
4
|
mutation createCompanyTeam($input: CompanyTeamCreateInput!) {
|
|
5
5
|
createCompanyTeam(input: $input) { __typename team { id structure_id name } }
|
|
6
6
|
}
|
|
7
|
-
`;async function
|
|
7
|
+
`;async function f(a){const n={name:a.name,description:a.description,target_id:a.targetId};return await o(d,{variables:{input:n}}).then(e=>{var r,m,p;if((r=e.errors)!=null&&r.length)return i(e.errors);const t=(p=(m=e==null?void 0:e.data)==null?void 0:m.createCompanyTeam)==null?void 0:p.team;return t?{id:t.id,structureId:t.structure_id,name:t.name}:null}).catch(u)}const c=`
|
|
8
8
|
mutation deleteCompanyTeam($id: ID!) {
|
|
9
9
|
deleteCompanyTeam(id: $id) { __typename }
|
|
10
10
|
}
|
|
11
|
-
`;async function
|
|
11
|
+
`;async function E(a){return await o(c,{variables:{id:a}}).then(n=>{var e,t;return(e=n.errors)!=null&&e.length?i(n.errors):!!((t=n==null?void 0:n.data)!=null&&t.deleteCompanyTeam)}).catch(u)}function y(a){return a.items.map(t=>({structureId:t.entity.structure_id,parentStructureId:t.parent_id||null,label:t.entity.__typename==="CompanyTeam"?t.entity.name||"":`${t.entity.firstname||""} ${t.entity.lastname||""}`.trim(),type:t.entity.__typename==="CompanyTeam"?"team":"user",entityId:(t.entity.__typename==="CompanyTeam"?t.entity.companyTeamId:t.entity.customerId)||"",description:t.entity.__typename==="CompanyTeam"&&t.entity.description||null})).map(t=>{const r=t.parentStructureId||null,m=!r||r==="MA=="?null:r;return{id:t.structureId,parentId:m,label:t.label,type:t.type,entityId:t.entityId,description:t.description}})}const s=a=>{if(!a)throw new Error("Invalid response: missing team data");return{id:a.id,name:a.name,description:a.description}},T=`
|
|
12
12
|
query getCompanyStructure {
|
|
13
13
|
company {
|
|
14
14
|
structure {
|
|
@@ -24,19 +24,19 @@ import{f as o,h as i}from"./network-error.js";import{h as u}from"./fetch-error.j
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
`;async function
|
|
27
|
+
`;async function g(){return await o(T,{method:"GET",cache:"no-cache"}).then(a=>{var e;if((e=a.errors)!=null&&e.length)return i(a.errors);const n=a.data.company.structure;return y(n)}).catch(u)}const l=`
|
|
28
28
|
query getCompanyTeam($id: ID!) {
|
|
29
29
|
company { team(id: $id) { id name description } }
|
|
30
30
|
}
|
|
31
|
-
`;async function
|
|
31
|
+
`;async function A(a){return await o(l,{variables:{id:a}}).then(n=>{var t,r,m;if((t=n.errors)!=null&&t.length)return i(n.errors);const e=(m=(r=n==null?void 0:n.data)==null?void 0:r.company)==null?void 0:m.team;return e?s(e):null}).catch(u)}const _=`
|
|
32
32
|
mutation updateCompanyStructure($treeId: ID!, $parentTreeId: ID!) {
|
|
33
33
|
updateCompanyStructure(input: { tree_id: $treeId, parent_tree_id: $parentTreeId }) {
|
|
34
34
|
__typename
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
`;async function
|
|
37
|
+
`;async function $(a){const n={treeId:a.id,parentTreeId:a.parentId};return await o(_,{variables:n}).then(e=>{var t,r;return(t=e.errors)!=null&&t.length?i(e.errors):!!((r=e==null?void 0:e.data)!=null&&r.updateCompanyStructure)}).catch(u)}const C=`
|
|
38
38
|
mutation updateCompanyTeam($input: CompanyTeamUpdateInput!) {
|
|
39
39
|
updateCompanyTeam(input: $input) { __typename team { id name } }
|
|
40
40
|
}
|
|
41
|
-
`;async function
|
|
41
|
+
`;async function M(a){const n={id:a.id,name:a.name,description:a.description};return await o(C,{variables:{input:n}}).then(e=>{var t,r,m,p;return(t=e.errors)!=null&&t.length?i(e.errors):!!((p=(m=(r=e==null?void 0:e.data)==null?void 0:r.updateCompanyTeam)==null?void 0:m.team)!=null&&p.id)}).catch(u)}export{g as a,$ as b,f as c,E as d,A as g,M as u};
|
|
42
42
|
//# sourceMappingURL=updateCompanyTeam.js.map
|