@vicacha-devs/medusa-plugin-b2b 0.0.0-stage → 0.0.1
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/.medusa/server/src/admin/index.cjs +8706 -0
- package/.medusa/server/src/admin/index.js +8683 -0
- package/.medusa/server/src/api/admin/b2b/approvals/[id]/route.js +24 -0
- package/.medusa/server/src/api/admin/b2b/approvals/middlewares.js +23 -0
- package/.medusa/server/src/api/admin/b2b/approvals/query-config.js +13 -0
- package/.medusa/server/src/api/admin/b2b/approvals/route.js +45 -0
- package/.medusa/server/src/api/admin/b2b/approvals/validators.js +15 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/approval-settings/route.js +36 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/customer-group/[customerGroupId]/route.js +10 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/customer-group/route.js +35 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/employees/[employeeId]/route.js +48 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/employees/route.js +64 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/route.js +48 -0
- package/.medusa/server/src/api/admin/b2b/companies/middlewares.js +77 -0
- package/.medusa/server/src/api/admin/b2b/companies/query-config.js +91 -0
- package/.medusa/server/src/api/admin/b2b/companies/route.js +68 -0
- package/.medusa/server/src/api/admin/b2b/companies/validators.js +113 -0
- package/.medusa/server/src/api/admin/b2b/customers/[id]/employee/route.js +20 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/messages/route.js +20 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/reject/route.js +19 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/route.js +30 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/send/route.js +19 -0
- package/.medusa/server/src/api/admin/b2b/quotes/middlewares.js +44 -0
- package/.medusa/server/src/api/admin/b2b/quotes/query-config.js +43 -0
- package/.medusa/server/src/api/admin/b2b/quotes/route.js +54 -0
- package/.medusa/server/src/api/admin/b2b/quotes/validators.js +37 -0
- package/.medusa/server/src/api/admin/companies/route.js +32 -0
- package/.medusa/server/src/api/admin/middlewares.js +9 -0
- package/.medusa/server/src/api/admin/validators.js +4 -0
- package/.medusa/server/src/api/admin/views/b2b-approvals/columns/route.js +119 -0
- package/.medusa/server/src/api/admin/views/b2b-companies/columns/route.js +144 -0
- package/.medusa/server/src/api/admin/views/b2b-company-employees/columns/route.js +73 -0
- package/.medusa/server/src/api/admin/views/b2b-quotes/columns/route.js +108 -0
- package/.medusa/server/src/api/middlewares/ensure-role.js +88 -0
- package/.medusa/server/src/api/middlewares.js +20 -0
- package/.medusa/server/src/api/store/b2b/approvals/[id]/route.js +24 -0
- package/.medusa/server/src/api/store/b2b/approvals/middlewares.js +71 -0
- package/.medusa/server/src/api/store/b2b/approvals/query-config.js +13 -0
- package/.medusa/server/src/api/store/b2b/approvals/route.js +76 -0
- package/.medusa/server/src/api/store/b2b/approvals/validators.js +22 -0
- package/.medusa/server/src/api/store/b2b/carts/[id]/approvals/route.js +24 -0
- package/.medusa/server/src/api/store/b2b/carts/[id]/line-items/bulk/route.js +26 -0
- package/.medusa/server/src/api/store/b2b/carts/middlewares.js +19 -0
- package/.medusa/server/src/api/store/b2b/carts/query-config.js +13 -0
- package/.medusa/server/src/api/store/b2b/carts/validators.js +12 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/approval-settings/route.js +21 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/employees/[employeeId]/route.js +53 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/employees/route.js +44 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/route.js +39 -0
- package/.medusa/server/src/api/store/b2b/companies/middlewares.js +94 -0
- package/.medusa/server/src/api/store/b2b/companies/query-config.js +62 -0
- package/.medusa/server/src/api/store/b2b/companies/route.js +18 -0
- package/.medusa/server/src/api/store/b2b/companies/validators.js +66 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/middlewares.js +15 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/prices/route.js +41 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/utils.js +51 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/validators.js +11 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/accept/route.js +20 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/messages/route.js +20 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/preview/route.js +19 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/reject/route.js +19 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/route.js +15 -0
- package/.medusa/server/src/api/store/b2b/quotes/middlewares.js +64 -0
- package/.medusa/server/src/api/store/b2b/quotes/query-config.js +58 -0
- package/.medusa/server/src/api/store/b2b/quotes/route.js +39 -0
- package/.medusa/server/src/api/store/b2b/quotes/validators.js +35 -0
- package/.medusa/server/src/api/store/middlewares.js +13 -0
- package/.medusa/server/src/api/store/validators.js +6 -0
- package/.medusa/server/src/api/validators.js +3 -0
- package/.medusa/server/src/jobs/expire-quotes.js +22 -0
- package/.medusa/server/src/links/cart-approval-status.js +12 -0
- package/.medusa/server/src/links/cart-approvals.js +13 -0
- package/.medusa/server/src/links/company-approval-setting.js +5 -0
- package/.medusa/server/src/links/company-carts.js +12 -0
- package/.medusa/server/src/links/company-customer-group.js +11 -0
- package/.medusa/server/src/links/employee-customer.js +9 -0
- package/.medusa/server/src/links/order-company.js +9 -0
- package/.medusa/server/src/links/quote-links.js +77 -0
- package/.medusa/server/src/modules/approval/index.js +7 -0
- package/.medusa/server/src/modules/approval/migrations/Migration20260912010000.js +22 -0
- package/.medusa/server/src/modules/approval/models/approval-settings.js +21 -0
- package/.medusa/server/src/modules/approval/models/approval-status.js +21 -0
- package/.medusa/server/src/modules/approval/models/approval.js +36 -0
- package/.medusa/server/src/modules/approval/models/index.js +4 -0
- package/.medusa/server/src/modules/approval/service.js +18 -0
- package/.medusa/server/src/modules/company/index.js +7 -0
- package/.medusa/server/src/modules/company/migrations/Migration20260912010000.js +24 -0
- package/.medusa/server/src/modules/company/models/company.js +44 -0
- package/.medusa/server/src/modules/company/models/employee.js +30 -0
- package/.medusa/server/src/modules/company/models/index.js +3 -0
- package/.medusa/server/src/modules/company/service.js +9 -0
- package/.medusa/server/src/modules/company/types/common.js +2 -0
- package/.medusa/server/src/modules/company/types/mutations.js +2 -0
- package/.medusa/server/src/modules/quote/index.js +5 -0
- package/.medusa/server/src/modules/quote/migrations/Migration20260912010000.js +29 -0
- package/.medusa/server/src/modules/quote/models/index.js +3 -0
- package/.medusa/server/src/modules/quote/models/message.js +34 -0
- package/.medusa/server/src/modules/quote/models/quote.js +57 -0
- package/.medusa/server/src/modules/quote/service.js +6 -0
- package/.medusa/server/src/rbac.js +122 -0
- package/.medusa/server/src/scripts/seed-b2b-data.js +99 -0
- package/.medusa/server/src/scripts/seed-b2b-test-data.js +813 -0
- package/.medusa/server/src/types/approval/http.js +2 -0
- package/.medusa/server/src/types/approval/index.js +5 -0
- package/.medusa/server/src/types/approval/module.js +14 -0
- package/.medusa/server/src/types/approval/query.js +2 -0
- package/.medusa/server/src/types/approval/service.js +2 -0
- package/.medusa/server/src/types/company/http.js +2 -0
- package/.medusa/server/src/types/company/index.js +5 -0
- package/.medusa/server/src/types/company/module.js +3 -0
- package/.medusa/server/src/types/company/query.js +2 -0
- package/.medusa/server/src/types/company/service.js +2 -0
- package/.medusa/server/src/types/constants.js +16 -0
- package/.medusa/server/src/types/enums.js +18 -0
- package/.medusa/server/src/types/index.js +6 -0
- package/.medusa/server/src/types/quote/http.js +2 -0
- package/.medusa/server/src/types/quote/index.js +5 -0
- package/.medusa/server/src/types/quote/module.js +3 -0
- package/.medusa/server/src/types/quote/query.js +2 -0
- package/.medusa/server/src/types/quote/service.js +2 -0
- package/.medusa/server/src/types/shipping-options/http.js +2 -0
- package/.medusa/server/src/types/shipping-options/index.js +2 -0
- package/.medusa/server/src/types/types.js +2 -0
- package/.medusa/server/src/utils/check-spending-limit.js +51 -0
- package/.medusa/server/src/utils/get-cart-approval-status.js +22 -0
- package/.medusa/server/src/workflows/approval/steps/create-approval-settings.js +18 -0
- package/.medusa/server/src/workflows/approval/steps/create-approval-status.js +37 -0
- package/.medusa/server/src/workflows/approval/steps/create-approvals.js +55 -0
- package/.medusa/server/src/workflows/approval/steps/delete-approval-settings.js +23 -0
- package/.medusa/server/src/workflows/approval/steps/delete-approvals.js +11 -0
- package/.medusa/server/src/workflows/approval/steps/index.js +9 -0
- package/.medusa/server/src/workflows/approval/steps/update-approval-settings.js +12 -0
- package/.medusa/server/src/workflows/approval/steps/update-approval-statuses.js +49 -0
- package/.medusa/server/src/workflows/approval/steps/update-approval.js +60 -0
- package/.medusa/server/src/workflows/approval/workflows/create-approval-settings.js +20 -0
- package/.medusa/server/src/workflows/approval/workflows/create-approvals.js +43 -0
- package/.medusa/server/src/workflows/approval/workflows/index.js +5 -0
- package/.medusa/server/src/workflows/approval/workflows/update-approval-settings.js +6 -0
- package/.medusa/server/src/workflows/approval/workflows/update-approval.js +8 -0
- package/.medusa/server/src/workflows/company/steps/add-company-employees-to-customer-group.js +41 -0
- package/.medusa/server/src/workflows/company/steps/create-companies.js +14 -0
- package/.medusa/server/src/workflows/company/steps/delete-companies.js +11 -0
- package/.medusa/server/src/workflows/company/steps/dismiss-company-customer-group-link.js +40 -0
- package/.medusa/server/src/workflows/company/steps/index.js +7 -0
- package/.medusa/server/src/workflows/company/steps/remove-company-employees-from-customer-group.js +39 -0
- package/.medusa/server/src/workflows/company/steps/update-companies.js +14 -0
- package/.medusa/server/src/workflows/company/workflows/add-company-to-customer-group.js +25 -0
- package/.medusa/server/src/workflows/company/workflows/create-companies.js +21 -0
- package/.medusa/server/src/workflows/company/workflows/delete-companies.js +12 -0
- package/.medusa/server/src/workflows/company/workflows/index.js +6 -0
- package/.medusa/server/src/workflows/company/workflows/remove-company-from-customer-group.js +22 -0
- package/.medusa/server/src/workflows/company/workflows/update-companies.js +6 -0
- package/.medusa/server/src/workflows/employee/steps/add-employee-to-customer-group.js +41 -0
- package/.medusa/server/src/workflows/employee/steps/create-employees.js +20 -0
- package/.medusa/server/src/workflows/employee/steps/delete-employees.js +14 -0
- package/.medusa/server/src/workflows/employee/steps/index.js +8 -0
- package/.medusa/server/src/workflows/employee/steps/link-employee-to-customer.js +29 -0
- package/.medusa/server/src/workflows/employee/steps/remove-admin-role.js +37 -0
- package/.medusa/server/src/workflows/employee/steps/set-admin-role.js +56 -0
- package/.medusa/server/src/workflows/employee/steps/sync-customer-company-name.js +41 -0
- package/.medusa/server/src/workflows/employee/steps/update-employees.js +29 -0
- package/.medusa/server/src/workflows/employee/workflows/create-employees.js +34 -0
- package/.medusa/server/src/workflows/employee/workflows/delete-employees.js +15 -0
- package/.medusa/server/src/workflows/employee/workflows/index.js +4 -0
- package/.medusa/server/src/workflows/employee/workflows/update-employees.js +14 -0
- package/.medusa/server/src/workflows/hooks/cart-created.js +37 -0
- package/.medusa/server/src/workflows/hooks/order-created.js +30 -0
- package/.medusa/server/src/workflows/hooks/validate-add-to-cart.js +20 -0
- package/.medusa/server/src/workflows/hooks/validate-cart-completion.js +38 -0
- package/.medusa/server/src/workflows/hooks/validate-update-cart.js +20 -0
- package/.medusa/server/src/workflows/index.js +6 -0
- package/.medusa/server/src/workflows/order/steps/update-order.js +28 -0
- package/.medusa/server/src/workflows/order/workflows/update-order.js +21 -0
- package/.medusa/server/src/workflows/quote/steps/create-quote-message.js +18 -0
- package/.medusa/server/src/workflows/quote/steps/create-quotes.js +18 -0
- package/.medusa/server/src/workflows/quote/steps/update-quotes.js +28 -0
- package/.medusa/server/src/workflows/quote/steps/validate-quote-acceptance.js +11 -0
- package/.medusa/server/src/workflows/quote/steps/validate-quote-rejection.js +10 -0
- package/.medusa/server/src/workflows/quote/workflows/create-quote-message.js +11 -0
- package/.medusa/server/src/workflows/quote/workflows/create-quote.js +9 -0
- package/.medusa/server/src/workflows/quote/workflows/create-request-for-quote.js +84 -0
- package/.medusa/server/src/workflows/quote/workflows/customer-accept-quote.js +39 -0
- package/.medusa/server/src/workflows/quote/workflows/customer-reject-quote.js +27 -0
- package/.medusa/server/src/workflows/quote/workflows/index.js +9 -0
- package/.medusa/server/src/workflows/quote/workflows/merchant-reject-quote.js +28 -0
- package/.medusa/server/src/workflows/quote/workflows/merchant-send-quote.js +29 -0
- package/.medusa/server/src/workflows/quote/workflows/update-quote.js +9 -0
- package/LICENSE +21 -0
- package/README.md +587 -2
- package/package.json +121 -3
- package/src/__tests__/b2b-contract.spec.ts +41 -0
- package/src/admin/README.md +73 -0
- package/src/admin/constants.ts +1 -0
- package/src/admin/hooks/api/approvals.tsx +106 -0
- package/src/admin/hooks/api/companies.tsx +288 -0
- package/src/admin/hooks/api/customers.tsx +44 -0
- package/src/admin/hooks/api/employees.tsx +170 -0
- package/src/admin/hooks/api/index.ts +5 -0
- package/src/admin/hooks/api/quotes.tsx +329 -0
- package/src/admin/i18n/README.md +78 -0
- package/src/admin/i18n/index.ts +23 -0
- package/src/admin/i18n/json/ar.json +388 -0
- package/src/admin/i18n/json/de.json +388 -0
- package/src/admin/i18n/json/en.json +388 -0
- package/src/admin/i18n/json/es.json +388 -0
- package/src/admin/i18n/json/fr.json +388 -0
- package/src/admin/i18n/json/it.json +388 -0
- package/src/admin/i18n/json/nl.json +388 -0
- package/src/admin/i18n/json/pl.json +388 -0
- package/src/admin/i18n/json/pt.json +388 -0
- package/src/admin/i18n/json/tr.json +388 -0
- package/src/admin/routes/b2b/approvals/components/approval-actions.tsx +129 -0
- package/src/admin/routes/b2b/approvals/components/approval-status-badge.tsx +24 -0
- package/src/admin/routes/b2b/approvals/components/approvals-items-popover.tsx +69 -0
- package/src/admin/routes/b2b/approvals/components/approvals-table-adapter.tsx +45 -0
- package/src/admin/routes/b2b/approvals/components/approvals-table-renderers.tsx +74 -0
- package/src/admin/routes/b2b/approvals/components/approvals-table.tsx +66 -0
- package/src/admin/routes/b2b/approvals/components/table/columns.tsx +113 -0
- package/src/admin/routes/b2b/approvals/components/table/filters.tsx +30 -0
- package/src/admin/routes/b2b/approvals/components/table/query.tsx +25 -0
- package/src/admin/routes/b2b/approvals/page.tsx +66 -0
- package/src/admin/routes/b2b/companies/@create/page.tsx +70 -0
- package/src/admin/routes/b2b/companies/[id]/@approval-settings/page.tsx +106 -0
- package/src/admin/routes/b2b/companies/[id]/@customer-group/page.tsx +152 -0
- package/src/admin/routes/b2b/companies/[id]/@edit/page.tsx +93 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/[employeeId]/page.tsx +82 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/employees-actions-menu.tsx +61 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/employees-create-form.tsx +190 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/employees-update-form.tsx +160 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/index.ts +3 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/validators.ts +25 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/create/page.tsx +91 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-approval-settings-section.tsx +67 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-customer-group-section.tsx +55 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-employees-section.tsx +70 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-employees-table-renderers.tsx +53 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-general-section.tsx +59 -0
- package/src/admin/routes/b2b/companies/[id]/page.tsx +85 -0
- package/src/admin/routes/b2b/companies/components/companies-table-adapter.tsx +46 -0
- package/src/admin/routes/b2b/companies/components/companies-table-renderers.tsx +53 -0
- package/src/admin/routes/b2b/companies/components/companies-table.tsx +83 -0
- package/src/admin/routes/b2b/companies/components/company-actions-menu.tsx +46 -0
- package/src/admin/routes/b2b/companies/components/company-create-admin-tab.tsx +185 -0
- package/src/admin/routes/b2b/companies/components/company-create-details-tab.tsx +169 -0
- package/src/admin/routes/b2b/companies/components/company-create-form.tsx +201 -0
- package/src/admin/routes/b2b/companies/components/company-form-admin-tab.tsx +99 -0
- package/src/admin/routes/b2b/companies/components/company-form-details-tab.tsx +159 -0
- package/src/admin/routes/b2b/companies/components/company-form.tsx +159 -0
- package/src/admin/routes/b2b/companies/components/index.ts +9 -0
- package/src/admin/routes/b2b/companies/components/table/columns.tsx +81 -0
- package/src/admin/routes/b2b/companies/components/table/filters.tsx +23 -0
- package/src/admin/routes/b2b/companies/components/table/query.tsx +27 -0
- package/src/admin/routes/b2b/companies/components/use-delete-company-list-action.tsx +37 -0
- package/src/admin/routes/b2b/companies/components/validators.ts +49 -0
- package/src/admin/routes/b2b/companies/page.tsx +66 -0
- package/src/admin/routes/b2b/components/index.ts +6 -0
- package/src/admin/routes/b2b/components/navigation-card.tsx +51 -0
- package/src/admin/routes/b2b/components/stat-card.tsx +48 -0
- package/src/admin/routes/b2b/page.tsx +173 -0
- package/src/admin/routes/b2b/quotes/[id]/components/index.ts +8 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-company-section.tsx +54 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-customer-section.tsx +75 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-detail-actions.tsx +57 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-general-section.tsx +66 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-message-bubble.tsx +132 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-message-composer.tsx +135 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-messages-section.tsx +100 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-order-section.tsx +115 -0
- package/src/admin/routes/b2b/quotes/[id]/components/validators.ts +8 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/index.ts +7 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-item-info.tsx +63 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-item-price-form.tsx +60 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-item.tsx +227 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-items-section.tsx +145 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-items-table.tsx +117 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-quote-form.tsx +187 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/columns.tsx +29 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/filters.tsx +8 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/index.ts +3 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/query.tsx +25 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/validators.ts +5 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/page.tsx +60 -0
- package/src/admin/routes/b2b/quotes/[id]/page.tsx +213 -0
- package/src/admin/routes/b2b/quotes/components/index.ts +4 -0
- package/src/admin/routes/b2b/quotes/components/quote-actions-menu.tsx +119 -0
- package/src/admin/routes/b2b/quotes/components/quote-status-badge.tsx +30 -0
- package/src/admin/routes/b2b/quotes/components/quotes-table-adapter.tsx +43 -0
- package/src/admin/routes/b2b/quotes/components/quotes-table-renderers.tsx +87 -0
- package/src/admin/routes/b2b/quotes/components/quotes-table.tsx +70 -0
- package/src/admin/routes/b2b/quotes/components/send-quote-drawer.tsx +69 -0
- package/src/admin/routes/b2b/quotes/components/table/columns.tsx +75 -0
- package/src/admin/routes/b2b/quotes/components/table/filters.tsx +44 -0
- package/src/admin/routes/b2b/quotes/components/table/query.tsx +27 -0
- package/src/admin/routes/b2b/quotes/page.tsx +65 -0
- package/src/admin/tsconfig.json +23 -0
- package/src/admin/validators.ts +4 -0
- package/src/admin/vite-env.d.ts +1 -0
- package/src/admin/widgets/customer-company-widget.tsx +63 -0
- package/src/admin/widgets/customer-employee-widget.tsx +48 -0
- package/src/admin/widgets/customer-group-companies-widget.tsx +68 -0
- package/src/api/README.md +64 -0
- package/src/api/admin/b2b/approvals/[id]/route.ts +34 -0
- package/src/api/admin/b2b/approvals/middlewares.ts +31 -0
- package/src/api/admin/b2b/approvals/query-config.ts +13 -0
- package/src/api/admin/b2b/approvals/route.ts +56 -0
- package/src/api/admin/b2b/approvals/validators.ts +23 -0
- package/src/api/admin/b2b/companies/[id]/approval-settings/route.ts +57 -0
- package/src/api/admin/b2b/companies/[id]/customer-group/[customerGroupId]/route.ts +17 -0
- package/src/api/admin/b2b/companies/[id]/customer-group/route.ts +56 -0
- package/src/api/admin/b2b/companies/[id]/employees/[employeeId]/route.ts +84 -0
- package/src/api/admin/b2b/companies/[id]/employees/route.ts +90 -0
- package/src/api/admin/b2b/companies/[id]/route.ts +88 -0
- package/src/api/admin/b2b/companies/middlewares.ts +123 -0
- package/src/api/admin/b2b/companies/query-config.ts +99 -0
- package/src/api/admin/b2b/companies/route.ts +101 -0
- package/src/api/admin/b2b/companies/validators.ts +165 -0
- package/src/api/admin/b2b/customers/[id]/employee/route.ts +31 -0
- package/src/api/admin/b2b/quotes/[id]/messages/route.ts +36 -0
- package/src/api/admin/b2b/quotes/[id]/reject/route.ts +35 -0
- package/src/api/admin/b2b/quotes/[id]/route.ts +48 -0
- package/src/api/admin/b2b/quotes/[id]/send/route.ts +35 -0
- package/src/api/admin/b2b/quotes/middlewares.ts +71 -0
- package/src/api/admin/b2b/quotes/query-config.ts +45 -0
- package/src/api/admin/b2b/quotes/route.ts +72 -0
- package/src/api/admin/b2b/quotes/validators.ts +49 -0
- package/src/api/admin/companies/route.ts +43 -0
- package/src/api/admin/middlewares.ts +10 -0
- package/src/api/admin/validators.ts +3 -0
- package/src/api/admin/views/b2b-approvals/columns/route.ts +121 -0
- package/src/api/admin/views/b2b-companies/columns/route.ts +146 -0
- package/src/api/admin/views/b2b-company-employees/columns/route.ts +74 -0
- package/src/api/admin/views/b2b-quotes/columns/route.ts +110 -0
- package/src/api/middlewares/ensure-role.ts +138 -0
- package/src/api/middlewares.ts +26 -0
- package/src/api/store/b2b/approvals/[id]/route.ts +34 -0
- package/src/api/store/b2b/approvals/middlewares.ts +103 -0
- package/src/api/store/b2b/approvals/query-config.ts +13 -0
- package/src/api/store/b2b/approvals/route.ts +105 -0
- package/src/api/store/b2b/approvals/validators.ts +30 -0
- package/src/api/store/b2b/carts/[id]/approvals/route.ts +33 -0
- package/src/api/store/b2b/carts/[id]/line-items/bulk/route.ts +46 -0
- package/src/api/store/b2b/carts/middlewares.ts +27 -0
- package/src/api/store/b2b/carts/query-config.ts +13 -0
- package/src/api/store/b2b/carts/validators.ts +19 -0
- package/src/api/store/b2b/companies/[id]/approval-settings/route.ts +33 -0
- package/src/api/store/b2b/companies/[id]/employees/[employeeId]/route.ts +86 -0
- package/src/api/store/b2b/companies/[id]/employees/route.ts +72 -0
- package/src/api/store/b2b/companies/[id]/route.ts +70 -0
- package/src/api/store/b2b/companies/middlewares.ts +137 -0
- package/src/api/store/b2b/companies/query-config.ts +76 -0
- package/src/api/store/b2b/companies/route.ts +34 -0
- package/src/api/store/b2b/companies/validators.ts +88 -0
- package/src/api/store/b2b/free-shipping/middlewares.ts +16 -0
- package/src/api/store/b2b/free-shipping/prices/route.ts +71 -0
- package/src/api/store/b2b/free-shipping/utils.ts +60 -0
- package/src/api/store/b2b/free-shipping/validators.ts +16 -0
- package/src/api/store/b2b/quotes/[id]/accept/route.ts +36 -0
- package/src/api/store/b2b/quotes/[id]/messages/route.ts +36 -0
- package/src/api/store/b2b/quotes/[id]/preview/route.ts +45 -0
- package/src/api/store/b2b/quotes/[id]/reject/route.ts +35 -0
- package/src/api/store/b2b/quotes/[id]/route.ts +30 -0
- package/src/api/store/b2b/quotes/middlewares.ts +96 -0
- package/src/api/store/b2b/quotes/query-config.ts +59 -0
- package/src/api/store/b2b/quotes/route.ts +65 -0
- package/src/api/store/b2b/quotes/validators.ts +51 -0
- package/src/api/store/middlewares.ts +14 -0
- package/src/api/store/validators.ts +5 -0
- package/src/api/validators.ts +2 -0
- package/src/jobs/expire-quotes.ts +31 -0
- package/src/links/README.md +62 -0
- package/src/links/cart-approval-status.ts +14 -0
- package/src/links/cart-approvals.ts +15 -0
- package/src/links/company-approval-setting.ts +8 -0
- package/src/links/company-carts.ts +14 -0
- package/src/links/company-customer-group.ts +16 -0
- package/src/links/employee-customer.ts +14 -0
- package/src/links/order-company.ts +14 -0
- package/src/links/quote-links.ts +77 -0
- package/src/modules/README.md +75 -0
- package/src/modules/approval/index.ts +8 -0
- package/src/modules/approval/migrations/Migration20260912010000.ts +47 -0
- package/src/modules/approval/models/approval-settings.ts +21 -0
- package/src/modules/approval/models/approval-status.ts +21 -0
- package/src/modules/approval/models/approval.ts +36 -0
- package/src/modules/approval/models/index.ts +3 -0
- package/src/modules/approval/service.ts +20 -0
- package/src/modules/company/index.ts +8 -0
- package/src/modules/company/migrations/Migration20260912010000.ts +50 -0
- package/src/modules/company/models/company.ts +44 -0
- package/src/modules/company/models/employee.ts +30 -0
- package/src/modules/company/models/index.ts +2 -0
- package/src/modules/company/service.ts +9 -0
- package/src/modules/company/types/common.ts +30 -0
- package/src/modules/company/types/mutations.ts +30 -0
- package/src/modules/quote/index.ts +6 -0
- package/src/modules/quote/migrations/Migration20260912010000.ts +65 -0
- package/src/modules/quote/models/index.ts +2 -0
- package/src/modules/quote/models/message.ts +35 -0
- package/src/modules/quote/models/quote.ts +58 -0
- package/src/modules/quote/service.ts +6 -0
- package/src/rbac.ts +136 -0
- package/src/scripts/README.md +40 -0
- package/src/scripts/seed-b2b-data.ts +177 -0
- package/src/scripts/seed-b2b-test-data.ts +986 -0
- package/src/types/README.md +52 -0
- package/src/types/approval/http.ts +56 -0
- package/src/types/approval/index.ts +4 -0
- package/src/types/approval/module.ts +77 -0
- package/src/types/approval/query.ts +11 -0
- package/src/types/approval/service.ts +126 -0
- package/src/types/company/http.ts +126 -0
- package/src/types/company/index.ts +4 -0
- package/src/types/company/module.ts +78 -0
- package/src/types/company/query.ts +15 -0
- package/src/types/company/service.ts +109 -0
- package/src/types/constants.ts +16 -0
- package/src/types/enums.ts +16 -0
- package/src/types/index.ts +5 -0
- package/src/types/quote/http.ts +50 -0
- package/src/types/quote/index.ts +4 -0
- package/src/types/quote/module.ts +45 -0
- package/src/types/quote/query.ts +22 -0
- package/src/types/quote/service.ts +65 -0
- package/src/types/shipping-options/http.ts +7 -0
- package/src/types/shipping-options/index.ts +1 -0
- package/src/types/types.ts +5 -0
- package/src/utils/README.md +37 -0
- package/src/utils/check-spending-limit.ts +81 -0
- package/src/utils/get-cart-approval-status.ts +35 -0
- package/src/workflows/README.md +85 -0
- package/src/workflows/approval/steps/create-approval-settings.ts +34 -0
- package/src/workflows/approval/steps/create-approval-status.ts +56 -0
- package/src/workflows/approval/steps/create-approvals.ts +114 -0
- package/src/workflows/approval/steps/delete-approval-settings.ts +52 -0
- package/src/workflows/approval/steps/delete-approvals.ts +21 -0
- package/src/workflows/approval/steps/index.ts +8 -0
- package/src/workflows/approval/steps/update-approval-settings.ts +27 -0
- package/src/workflows/approval/steps/update-approval-statuses.ts +77 -0
- package/src/workflows/approval/steps/update-approval.ts +87 -0
- package/src/workflows/approval/workflows/create-approval-settings.ts +32 -0
- package/src/workflows/approval/workflows/create-approvals.ts +60 -0
- package/src/workflows/approval/workflows/index.ts +4 -0
- package/src/workflows/approval/workflows/update-approval-settings.ts +13 -0
- package/src/workflows/approval/workflows/update-approval.ts +17 -0
- package/src/workflows/company/steps/add-company-employees-to-customer-group.ts +74 -0
- package/src/workflows/company/steps/create-companies.ts +28 -0
- package/src/workflows/company/steps/delete-companies.ts +21 -0
- package/src/workflows/company/steps/dismiss-company-customer-group-link.ts +53 -0
- package/src/workflows/company/steps/index.ts +6 -0
- package/src/workflows/company/steps/remove-company-employees-from-customer-group.ts +76 -0
- package/src/workflows/company/steps/update-companies.ts +25 -0
- package/src/workflows/company/workflows/add-company-to-customer-group.ts +34 -0
- package/src/workflows/company/workflows/create-companies.ts +35 -0
- package/src/workflows/company/workflows/delete-companies.ts +18 -0
- package/src/workflows/company/workflows/index.ts +5 -0
- package/src/workflows/company/workflows/remove-company-from-customer-group.ts +30 -0
- package/src/workflows/company/workflows/update-companies.ts +13 -0
- package/src/workflows/employee/steps/add-employee-to-customer-group.ts +81 -0
- package/src/workflows/employee/steps/create-employees.ts +46 -0
- package/src/workflows/employee/steps/delete-employees.ts +25 -0
- package/src/workflows/employee/steps/index.ts +7 -0
- package/src/workflows/employee/steps/link-employee-to-customer.ts +49 -0
- package/src/workflows/employee/steps/remove-admin-role.ts +59 -0
- package/src/workflows/employee/steps/set-admin-role.ts +89 -0
- package/src/workflows/employee/steps/sync-customer-company-name.ts +83 -0
- package/src/workflows/employee/steps/update-employees.ts +61 -0
- package/src/workflows/employee/workflows/create-employees.ts +61 -0
- package/src/workflows/employee/workflows/delete-employees.ts +26 -0
- package/src/workflows/employee/workflows/index.ts +3 -0
- package/src/workflows/employee/workflows/update-employees.ts +31 -0
- package/src/workflows/hooks/cart-created.ts +56 -0
- package/src/workflows/hooks/order-created.ts +38 -0
- package/src/workflows/hooks/validate-add-to-cart.ts +32 -0
- package/src/workflows/hooks/validate-cart-completion.ts +61 -0
- package/src/workflows/hooks/validate-update-cart.ts +32 -0
- package/src/workflows/index.ts +5 -0
- package/src/workflows/order/steps/update-order.ts +53 -0
- package/src/workflows/order/workflows/update-order.ts +28 -0
- package/src/workflows/quote/steps/create-quote-message.ts +33 -0
- package/src/workflows/quote/steps/create-quotes.ts +32 -0
- package/src/workflows/quote/steps/update-quotes.ts +48 -0
- package/src/workflows/quote/steps/validate-quote-acceptance.ts +22 -0
- package/src/workflows/quote/steps/validate-quote-rejection.ts +17 -0
- package/src/workflows/quote/workflows/create-quote-message.ts +20 -0
- package/src/workflows/quote/workflows/create-quote.ts +16 -0
- package/src/workflows/quote/workflows/create-request-for-quote.ts +102 -0
- package/src/workflows/quote/workflows/customer-accept-quote.ts +49 -0
- package/src/workflows/quote/workflows/customer-reject-quote.ts +31 -0
- package/src/workflows/quote/workflows/index.ts +8 -0
- package/src/workflows/quote/workflows/merchant-reject-quote.ts +34 -0
- package/src/workflows/quote/workflows/merchant-send-quote.ts +33 -0
- package/src/workflows/quote/workflows/update-quote.ts +16 -0
- package/tsconfig.json +40 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { zodResolver } from "@hookform/resolvers/zod"
|
|
2
|
+
import { Form, KeyboundForm, RouteDrawer } from "@medusajs/dashboard/components"
|
|
3
|
+
import { Button, Container, CurrencyInput, Table, Text } from "@medusajs/ui"
|
|
4
|
+
import { getCurrencySymbol } from "@medusajs/dashboard/lib"
|
|
5
|
+
import { CoolSwitch } from "@vicacha-devs/medusa-shared-admin/admin"
|
|
6
|
+
import { useForm } from "react-hook-form"
|
|
7
|
+
import { useTranslation } from "react-i18next"
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
AdminUpdateEmployee,
|
|
11
|
+
QueryCompany,
|
|
12
|
+
QueryEmployee,
|
|
13
|
+
} from "../../../../../../../types"
|
|
14
|
+
import {
|
|
15
|
+
makeEmployeeUpdateFormSchema,
|
|
16
|
+
UpdateEmployeeFormValues,
|
|
17
|
+
} from "./validators"
|
|
18
|
+
|
|
19
|
+
export function EmployeesUpdateForm({
|
|
20
|
+
company,
|
|
21
|
+
employee,
|
|
22
|
+
handleSubmit,
|
|
23
|
+
loading,
|
|
24
|
+
error,
|
|
25
|
+
}: {
|
|
26
|
+
employee: QueryEmployee
|
|
27
|
+
company: QueryCompany
|
|
28
|
+
handleSubmit: (data: AdminUpdateEmployee) => Promise<void>
|
|
29
|
+
loading: boolean
|
|
30
|
+
error: Error | null
|
|
31
|
+
}) {
|
|
32
|
+
const { t } = useTranslation()
|
|
33
|
+
|
|
34
|
+
const form = useForm<UpdateEmployeeFormValues>({
|
|
35
|
+
resolver: zodResolver(makeEmployeeUpdateFormSchema()),
|
|
36
|
+
defaultValues: {
|
|
37
|
+
spending_limit: employee?.spending_limit?.toString() ?? "0",
|
|
38
|
+
is_admin: employee?.is_admin ?? false,
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const currencyKey = company.currency_code || "USD"
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<RouteDrawer.Form form={form}>
|
|
46
|
+
<KeyboundForm
|
|
47
|
+
onSubmit={form.handleSubmit((data) =>
|
|
48
|
+
handleSubmit({
|
|
49
|
+
spending_limit: data.spending_limit
|
|
50
|
+
? Number(data.spending_limit)
|
|
51
|
+
: undefined,
|
|
52
|
+
is_admin: data.is_admin,
|
|
53
|
+
})
|
|
54
|
+
)}
|
|
55
|
+
className="flex flex-1 flex-col overflow-hidden"
|
|
56
|
+
>
|
|
57
|
+
<RouteDrawer.Body className="flex flex-1 flex-col gap-y-6 overflow-auto p-4">
|
|
58
|
+
<div className="flex flex-col gap-y-4">
|
|
59
|
+
<div className="flex items-center justify-between">
|
|
60
|
+
<h2 className="h2-core">{t("employees.form.details")}</h2>
|
|
61
|
+
<a
|
|
62
|
+
href={`/app/customers/${employee?.customer?.id}/edit`}
|
|
63
|
+
className="txt-compact-small text-ui-fg-interactive hover:text-ui-fg-interactive-hover"
|
|
64
|
+
>
|
|
65
|
+
{t("employees.form.editCustomerDetails")}
|
|
66
|
+
</a>
|
|
67
|
+
</div>
|
|
68
|
+
<Container className="p-0 overflow-hidden">
|
|
69
|
+
<Table>
|
|
70
|
+
<Table.Body>
|
|
71
|
+
<Table.Row>
|
|
72
|
+
<Table.Cell className="font-medium font-sans txt-compact-small">
|
|
73
|
+
{t("employees.form.name")}
|
|
74
|
+
</Table.Cell>
|
|
75
|
+
<Table.Cell>
|
|
76
|
+
{employee?.customer?.first_name}{" "}
|
|
77
|
+
{employee?.customer?.last_name}
|
|
78
|
+
</Table.Cell>
|
|
79
|
+
</Table.Row>
|
|
80
|
+
<Table.Row>
|
|
81
|
+
<Table.Cell className="font-medium font-sans txt-compact-small">
|
|
82
|
+
{t("employees.form.email")}
|
|
83
|
+
</Table.Cell>
|
|
84
|
+
<Table.Cell>{employee?.customer?.email}</Table.Cell>
|
|
85
|
+
</Table.Row>
|
|
86
|
+
<Table.Row>
|
|
87
|
+
<Table.Cell className="font-medium font-sans txt-compact-small">
|
|
88
|
+
{t("employees.form.phone")}
|
|
89
|
+
</Table.Cell>
|
|
90
|
+
<Table.Cell>{employee?.customer?.phone ?? "—"}</Table.Cell>
|
|
91
|
+
</Table.Row>
|
|
92
|
+
<Table.Row>
|
|
93
|
+
<Table.Cell className="font-medium font-sans txt-compact-small">
|
|
94
|
+
{t("employees.form.company")}
|
|
95
|
+
</Table.Cell>
|
|
96
|
+
<Table.Cell>{company.name}</Table.Cell>
|
|
97
|
+
</Table.Row>
|
|
98
|
+
</Table.Body>
|
|
99
|
+
</Table>
|
|
100
|
+
</Container>
|
|
101
|
+
</div>
|
|
102
|
+
<div className="flex flex-col gap-y-4">
|
|
103
|
+
<h2 className="h2-core">{t("employees.form.permissions")}</h2>
|
|
104
|
+
<Form.Field
|
|
105
|
+
control={form.control}
|
|
106
|
+
name="spending_limit"
|
|
107
|
+
render={({ field }: any) => (
|
|
108
|
+
<Form.Item>
|
|
109
|
+
<Form.Label optional>{t("fields.spendingLimit")}</Form.Label>
|
|
110
|
+
<Form.Control>
|
|
111
|
+
<CurrencyInput
|
|
112
|
+
symbol={getCurrencySymbol(currencyKey)}
|
|
113
|
+
code={company.currency_code || "USD"}
|
|
114
|
+
placeholder="1000"
|
|
115
|
+
value={field.value ?? ""}
|
|
116
|
+
onChange={(e) =>
|
|
117
|
+
field.onChange(e.target.value.replace(/[^0-9]/g, ""))
|
|
118
|
+
}
|
|
119
|
+
/>
|
|
120
|
+
</Form.Control>
|
|
121
|
+
<Form.ErrorMessage />
|
|
122
|
+
</Form.Item>
|
|
123
|
+
)}
|
|
124
|
+
/>
|
|
125
|
+
<Form.Field
|
|
126
|
+
control={form.control}
|
|
127
|
+
name="is_admin"
|
|
128
|
+
render={({ field }: any) => (
|
|
129
|
+
<Form.Item>
|
|
130
|
+
<Form.Label optional>
|
|
131
|
+
{t("employees.form.adminAccess")}
|
|
132
|
+
</Form.Label>
|
|
133
|
+
<Form.Control>
|
|
134
|
+
<CoolSwitch
|
|
135
|
+
fieldName="is_admin"
|
|
136
|
+
label={t("employees.form.isAdmin")}
|
|
137
|
+
description={t("employees.form.isAdminDescription")}
|
|
138
|
+
checked={field.value}
|
|
139
|
+
onChange={field.onChange}
|
|
140
|
+
tooltip={t("employees.form.isAdminTooltip")}
|
|
141
|
+
/>
|
|
142
|
+
</Form.Control>
|
|
143
|
+
</Form.Item>
|
|
144
|
+
)}
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
</RouteDrawer.Body>
|
|
148
|
+
<RouteDrawer.Footer>
|
|
149
|
+
<RouteDrawer.Close asChild>
|
|
150
|
+
<Button variant="secondary">{t("actions.cancel")}</Button>
|
|
151
|
+
</RouteDrawer.Close>
|
|
152
|
+
<Button type="submit" isLoading={loading}>
|
|
153
|
+
{t("actions.save")}
|
|
154
|
+
</Button>
|
|
155
|
+
{error && <Text className="text-ui-fg-error">{error.message}</Text>}
|
|
156
|
+
</RouteDrawer.Footer>
|
|
157
|
+
</KeyboundForm>
|
|
158
|
+
</RouteDrawer.Form>
|
|
159
|
+
)
|
|
160
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
export const makeEmployeeCreateFormSchema = () =>
|
|
4
|
+
z.object({
|
|
5
|
+
first_name: z.string().optional().or(z.literal("")),
|
|
6
|
+
last_name: z.string().optional().or(z.literal("")),
|
|
7
|
+
email: z.email(),
|
|
8
|
+
phone: z.string().optional().or(z.literal("")),
|
|
9
|
+
spending_limit: z.string().optional(),
|
|
10
|
+
is_admin: z.boolean(),
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export type CreateEmployeeFormValues = z.infer<
|
|
14
|
+
ReturnType<typeof makeEmployeeCreateFormSchema>
|
|
15
|
+
>
|
|
16
|
+
|
|
17
|
+
export const makeEmployeeUpdateFormSchema = () =>
|
|
18
|
+
z.object({
|
|
19
|
+
spending_limit: z.string().optional(),
|
|
20
|
+
is_admin: z.boolean(),
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export type UpdateEmployeeFormValues = z.infer<
|
|
24
|
+
ReturnType<typeof makeEmployeeUpdateFormSchema>
|
|
25
|
+
>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { RouteDrawer, useRouteModal } from "@medusajs/dashboard/components"
|
|
2
|
+
import { Heading, toast } from "@medusajs/ui"
|
|
3
|
+
import { useCreateCustomer } from "@vicacha-devs/medusa-shared-admin/admin"
|
|
4
|
+
import { useTranslation } from "react-i18next"
|
|
5
|
+
import { useParams } from "react-router-dom"
|
|
6
|
+
|
|
7
|
+
import { useCompany, useCreateEmployee } from "../../../../../../hooks/api"
|
|
8
|
+
import { EmployeesCreateForm } from "../components/employees-create-form"
|
|
9
|
+
import { RbacGuard } from "@vicacha-devs/medusa-shared-admin/admin"
|
|
10
|
+
|
|
11
|
+
const CreateContent = () => {
|
|
12
|
+
const { t } = useTranslation()
|
|
13
|
+
const { id } = useParams()
|
|
14
|
+
const { handleSuccess } = useRouteModal()
|
|
15
|
+
|
|
16
|
+
const { data, isLoading } = useCompany(id!)
|
|
17
|
+
const company = data?.company
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
mutateAsync: createCustomer,
|
|
21
|
+
isPending: creatingCustomer,
|
|
22
|
+
error: customerError,
|
|
23
|
+
} = useCreateCustomer()
|
|
24
|
+
const {
|
|
25
|
+
mutateAsync: createEmployee,
|
|
26
|
+
isPending: creatingEmployee,
|
|
27
|
+
error: employeeError,
|
|
28
|
+
} = useCreateEmployee(id!)
|
|
29
|
+
|
|
30
|
+
if (isLoading || !company) return null
|
|
31
|
+
|
|
32
|
+
const handleSubmit = async (formData: any) => {
|
|
33
|
+
try {
|
|
34
|
+
const { customer } = await createCustomer({
|
|
35
|
+
email: formData.email,
|
|
36
|
+
first_name: formData.first_name || undefined,
|
|
37
|
+
last_name: formData.last_name || undefined,
|
|
38
|
+
phone: formData.phone || undefined,
|
|
39
|
+
company_name: company.name,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
if (!customer?.id) {
|
|
43
|
+
toast.error(t("employees.toasts.createCustomerError"))
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await createEmployee({
|
|
48
|
+
spending_limit: formData.spending_limit,
|
|
49
|
+
is_admin: formData.is_admin,
|
|
50
|
+
customer_id: customer.id,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
toast.success(
|
|
54
|
+
t("employees.toasts.created", {
|
|
55
|
+
firstName: customer.first_name,
|
|
56
|
+
lastName: customer.last_name,
|
|
57
|
+
})
|
|
58
|
+
)
|
|
59
|
+
handleSuccess()
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<EmployeesCreateForm
|
|
65
|
+
handleSubmit={handleSubmit}
|
|
66
|
+
loading={creatingCustomer || creatingEmployee}
|
|
67
|
+
error={customerError || employeeError}
|
|
68
|
+
company={company as any}
|
|
69
|
+
/>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const EmployeeCreate = () => {
|
|
74
|
+
const { t } = useTranslation()
|
|
75
|
+
return (
|
|
76
|
+
<RouteDrawer>
|
|
77
|
+
<RouteDrawer.Header>
|
|
78
|
+
<Heading>{t("employees.drawers.addTitle")}</Heading>
|
|
79
|
+
</RouteDrawer.Header>
|
|
80
|
+
<CreateContent />
|
|
81
|
+
</RouteDrawer>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const GuardedEmployeeCreate = () => (
|
|
86
|
+
<RbacGuard permission="b2b.write">
|
|
87
|
+
<EmployeeCreate />
|
|
88
|
+
</RbacGuard>
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
export default GuardedEmployeeCreate
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ActionMenu, SectionRow } from "@medusajs/dashboard/components"
|
|
2
|
+
import { LockClosedSolid } from "@medusajs/icons"
|
|
3
|
+
import { Badge, Container, Heading } from "@medusajs/ui"
|
|
4
|
+
import { useTranslation } from "react-i18next"
|
|
5
|
+
|
|
6
|
+
import { QueryCompany } from "../../../../../../types"
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
company: QueryCompany
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const BoolBadge = ({
|
|
13
|
+
value,
|
|
14
|
+
t,
|
|
15
|
+
}: {
|
|
16
|
+
value: boolean
|
|
17
|
+
t: (k: string) => string
|
|
18
|
+
}) =>
|
|
19
|
+
value ? (
|
|
20
|
+
<Badge size="xsmall" color="green">
|
|
21
|
+
{t("general.yes")}
|
|
22
|
+
</Badge>
|
|
23
|
+
) : (
|
|
24
|
+
<Badge size="xsmall" color="grey">
|
|
25
|
+
{t("general.no")}
|
|
26
|
+
</Badge>
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
export const CompanyApprovalSettingsSection = ({ company }: Props) => {
|
|
30
|
+
const { t } = useTranslation()
|
|
31
|
+
const c = company as any
|
|
32
|
+
const settings = c.approval_settings
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Container className="divide-y p-0">
|
|
36
|
+
<div className="flex items-center justify-between px-6 py-4">
|
|
37
|
+
<Heading level="h2">{t("companies.detail.approvalSettings")}</Heading>
|
|
38
|
+
<ActionMenu
|
|
39
|
+
groups={[
|
|
40
|
+
{
|
|
41
|
+
actions: [
|
|
42
|
+
{
|
|
43
|
+
label: t("companies.actions.approvalSettings"),
|
|
44
|
+
to: `/b2b/companies/${company.id}/approval-settings`,
|
|
45
|
+
icon: <LockClosedSolid />,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
]}
|
|
50
|
+
/>
|
|
51
|
+
</div>
|
|
52
|
+
<SectionRow
|
|
53
|
+
title={t("companies.approvalSettings.requiresAdmin")}
|
|
54
|
+
value={<BoolBadge value={!!settings?.requires_admin_approval} t={t} />}
|
|
55
|
+
/>
|
|
56
|
+
<SectionRow
|
|
57
|
+
title={t("companies.approvalSettings.requiresSalesManager")}
|
|
58
|
+
value={
|
|
59
|
+
<BoolBadge
|
|
60
|
+
value={!!settings?.requires_sales_manager_approval}
|
|
61
|
+
t={t}
|
|
62
|
+
/>
|
|
63
|
+
}
|
|
64
|
+
/>
|
|
65
|
+
</Container>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ActionMenu, SectionRow } from "@medusajs/dashboard/components"
|
|
2
|
+
import { Link as LinkIcon } from "@medusajs/icons"
|
|
3
|
+
import { Container, Heading } from "@medusajs/ui"
|
|
4
|
+
import { useTranslation } from "react-i18next"
|
|
5
|
+
import { Link } from "react-router-dom"
|
|
6
|
+
|
|
7
|
+
import { QueryCompany } from "../../../../../../types"
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
company: QueryCompany
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const CompanyCustomerGroupSection = ({ company }: Props) => {
|
|
14
|
+
const { t } = useTranslation()
|
|
15
|
+
const c = company as any
|
|
16
|
+
const group = Array.isArray(c.customer_group)
|
|
17
|
+
? c.customer_group[0]
|
|
18
|
+
: c.customer_group
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Container className="divide-y p-0">
|
|
22
|
+
<div className="flex items-center justify-between px-6 py-4">
|
|
23
|
+
<Heading level="h2">{t("companies.detail.customerGroup")}</Heading>
|
|
24
|
+
<ActionMenu
|
|
25
|
+
groups={[
|
|
26
|
+
{
|
|
27
|
+
actions: [
|
|
28
|
+
{
|
|
29
|
+
label: t("companies.actions.manageCustomerGroup"),
|
|
30
|
+
to: `/b2b/companies/${company.id}/customer-group`,
|
|
31
|
+
icon: <LinkIcon />,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
]}
|
|
36
|
+
/>
|
|
37
|
+
</div>
|
|
38
|
+
<SectionRow
|
|
39
|
+
title={t("companies.detail.customerGroup")}
|
|
40
|
+
value={
|
|
41
|
+
group?.id ? (
|
|
42
|
+
<Link
|
|
43
|
+
to={`/customer-groups/${group.id}`}
|
|
44
|
+
className="text-ui-fg-interactive hover:text-ui-fg-interactive-hover"
|
|
45
|
+
>
|
|
46
|
+
{group.name || group.id}
|
|
47
|
+
</Link>
|
|
48
|
+
) : (
|
|
49
|
+
"—"
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
/>
|
|
53
|
+
</Container>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ConfigurableDataTable } from "@medusajs/dashboard/components"
|
|
2
|
+
import { createTableAdapter, TableAdapter } from "@medusajs/dashboard/lib"
|
|
3
|
+
import { useMemo } from "react"
|
|
4
|
+
import { useTranslation } from "react-i18next"
|
|
5
|
+
|
|
6
|
+
import { QueryEmployee } from "../../../../../../types"
|
|
7
|
+
import { useEmployees } from "../../../../../hooks/api"
|
|
8
|
+
import { EmployeesActionsMenu } from "../@employee/components"
|
|
9
|
+
import "./company-employees-table-renderers"
|
|
10
|
+
|
|
11
|
+
function useCompanyEmployeesAdapter(
|
|
12
|
+
companyId: string
|
|
13
|
+
): TableAdapter<QueryEmployee> {
|
|
14
|
+
const { t } = useTranslation()
|
|
15
|
+
|
|
16
|
+
return useMemo(
|
|
17
|
+
() =>
|
|
18
|
+
createTableAdapter<QueryEmployee>({
|
|
19
|
+
entity: "b2b-company-employees",
|
|
20
|
+
queryPrefix: "cemp",
|
|
21
|
+
pageSize: 20,
|
|
22
|
+
useData: (_fields, params) => {
|
|
23
|
+
const { data, isPending, isError, error } = useEmployees(
|
|
24
|
+
companyId,
|
|
25
|
+
params
|
|
26
|
+
)
|
|
27
|
+
return {
|
|
28
|
+
data: data?.employees,
|
|
29
|
+
count: data?.count,
|
|
30
|
+
isLoading: isPending,
|
|
31
|
+
isError,
|
|
32
|
+
error,
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
getRowHref: (row) => {
|
|
36
|
+
const customerId = (row as any).original?.customer?.id
|
|
37
|
+
|
|
38
|
+
return customerId ? `/customers/${customerId}` : undefined
|
|
39
|
+
},
|
|
40
|
+
renderRowActions: (row) => <EmployeesActionsMenu employee={row} />,
|
|
41
|
+
emptyState: {
|
|
42
|
+
empty: { heading: t("employees.noRecords"), description: "" },
|
|
43
|
+
filtered: { heading: t("employees.noRecords"), description: "" },
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
[companyId, t]
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const CompanyEmployeesSection = ({
|
|
51
|
+
companyId,
|
|
52
|
+
}: {
|
|
53
|
+
companyId: string
|
|
54
|
+
}) => {
|
|
55
|
+
const { t } = useTranslation()
|
|
56
|
+
const adapter = useCompanyEmployeesAdapter(companyId)
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<ConfigurableDataTable
|
|
60
|
+
adapter={adapter}
|
|
61
|
+
heading={t("employees.title")}
|
|
62
|
+
actions={[
|
|
63
|
+
{
|
|
64
|
+
label: t("actions.add"),
|
|
65
|
+
to: `/b2b/companies/${companyId}/employee/create`,
|
|
66
|
+
},
|
|
67
|
+
]}
|
|
68
|
+
/>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { defineCellRenderer, getLocaleAmount } from "@medusajs/dashboard/lib"
|
|
2
|
+
import { Badge } from "@medusajs/ui"
|
|
3
|
+
|
|
4
|
+
defineCellRenderer("b2b-employee-name", {
|
|
5
|
+
render: (value) => {
|
|
6
|
+
const customer = value as any
|
|
7
|
+
const name = [customer?.first_name, customer?.last_name]
|
|
8
|
+
.filter(Boolean)
|
|
9
|
+
.join(" ")
|
|
10
|
+
return name || "—"
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
defineCellRenderer("b2b-employee-email", {
|
|
15
|
+
render: (_value, row) => {
|
|
16
|
+
return (row as any)?.customer?.email || "—"
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
defineCellRenderer("b2b-employee-spending-limit", {
|
|
21
|
+
render: (value, row, _column, t) => {
|
|
22
|
+
const currency = (row as any)?.company?.currency_code
|
|
23
|
+
if (!value || value === 0) {
|
|
24
|
+
return t("quotes.detail.unlimited")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return currency ? getLocaleAmount(Number(value), currency) : String(value)
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
defineCellRenderer("b2b-employee-is-admin", {
|
|
32
|
+
render: (value, _row, _column, t) => {
|
|
33
|
+
return value ? (
|
|
34
|
+
<Badge size="2xsmall" color="green">
|
|
35
|
+
{t("employees.admin")}
|
|
36
|
+
</Badge>
|
|
37
|
+
) : null
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
defineCellRenderer("b2b-employee-is-active", {
|
|
42
|
+
render: (value, _row, _column, t) => {
|
|
43
|
+
return value ? (
|
|
44
|
+
<Badge size="2xsmall" color="green">
|
|
45
|
+
{t("employees.active")}
|
|
46
|
+
</Badge>
|
|
47
|
+
) : (
|
|
48
|
+
<Badge size="2xsmall" color="grey">
|
|
49
|
+
{t("employees.inactive")}
|
|
50
|
+
</Badge>
|
|
51
|
+
)
|
|
52
|
+
},
|
|
53
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Badge, Container, Heading } from "@medusajs/ui"
|
|
2
|
+
import { SectionRow, Thumbnail } from "@medusajs/dashboard/components"
|
|
3
|
+
import { useTranslation } from "react-i18next"
|
|
4
|
+
|
|
5
|
+
import { QueryCompany } from "../../../../../../types"
|
|
6
|
+
import { CompanyActionsMenu } from "../../components/company-actions-menu"
|
|
7
|
+
|
|
8
|
+
interface CompanyGeneralSectionProps {
|
|
9
|
+
company: QueryCompany
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const CompanyGeneralSection = ({
|
|
13
|
+
company,
|
|
14
|
+
}: CompanyGeneralSectionProps) => {
|
|
15
|
+
const { t } = useTranslation()
|
|
16
|
+
const c = company as any
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Container className="divide-y p-0">
|
|
20
|
+
<div className="flex items-center justify-between px-6 py-4">
|
|
21
|
+
<div className="flex items-center gap-x-3">
|
|
22
|
+
<Thumbnail src={c.logo_url} />
|
|
23
|
+
<Heading>{c.name}</Heading>
|
|
24
|
+
</div>
|
|
25
|
+
<CompanyActionsMenu company={company} />
|
|
26
|
+
</div>
|
|
27
|
+
<SectionRow title={t("companies.detail.email")} value={c.email || "—"} />
|
|
28
|
+
<SectionRow title={t("companies.detail.phone")} value={c.phone || "—"} />
|
|
29
|
+
<SectionRow
|
|
30
|
+
title={t("companies.detail.address")}
|
|
31
|
+
value={c.address || "—"}
|
|
32
|
+
/>
|
|
33
|
+
<SectionRow title={t("companies.detail.city")} value={c.city || "—"} />
|
|
34
|
+
<SectionRow title={t("companies.detail.state")} value={c.state || "—"} />
|
|
35
|
+
{c.currency_code && (
|
|
36
|
+
<SectionRow
|
|
37
|
+
title={t("companies.detail.currency")}
|
|
38
|
+
value={
|
|
39
|
+
<Badge size="xsmall" color="grey">
|
|
40
|
+
{c.currency_code.toUpperCase()}
|
|
41
|
+
</Badge>
|
|
42
|
+
}
|
|
43
|
+
/>
|
|
44
|
+
)}
|
|
45
|
+
{c.spending_limit_reset_frequency && (
|
|
46
|
+
<SectionRow
|
|
47
|
+
title={t("companies.detail.spendingLimitResetFrequency")}
|
|
48
|
+
value={c.spending_limit_reset_frequency}
|
|
49
|
+
/>
|
|
50
|
+
)}
|
|
51
|
+
{c.spending_limit_reset_at && (
|
|
52
|
+
<SectionRow
|
|
53
|
+
title={t("companies.detail.spendingLimitResetAt")}
|
|
54
|
+
value={new Date(c.spending_limit_reset_at).toLocaleDateString()}
|
|
55
|
+
/>
|
|
56
|
+
)}
|
|
57
|
+
</Container>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LayoutComposer } from "@medusajs/dashboard/components"
|
|
2
|
+
import { CORE_LAYOUT_IDS } from "@medusajs/admin-shared"
|
|
3
|
+
import {
|
|
4
|
+
detailPageDefaultEntries,
|
|
5
|
+
TwoColumnPageSkeleton,
|
|
6
|
+
} from "@vicacha-devs/medusa-shared-admin/admin"
|
|
7
|
+
import { useParams } from "react-router-dom"
|
|
8
|
+
import { useTranslation } from "react-i18next"
|
|
9
|
+
|
|
10
|
+
import { useCompany } from "../../../../hooks/api"
|
|
11
|
+
import { CompanyGeneralSection } from "./components/company-general-section"
|
|
12
|
+
import { CompanyEmployeesSection } from "./components/company-employees-section"
|
|
13
|
+
import { CompanyApprovalSettingsSection } from "./components/company-approval-settings-section"
|
|
14
|
+
import { CompanyCustomerGroupSection } from "./components/company-customer-group-section"
|
|
15
|
+
import { RbacGuard } from "@vicacha-devs/medusa-shared-admin/admin"
|
|
16
|
+
|
|
17
|
+
const CompanyDetail = () => {
|
|
18
|
+
const { id } = useParams()
|
|
19
|
+
const { data, isLoading, isError, error } = useCompany(id!)
|
|
20
|
+
const company = data?.company
|
|
21
|
+
|
|
22
|
+
if (isLoading || !company) {
|
|
23
|
+
return (
|
|
24
|
+
<TwoColumnPageSkeleton
|
|
25
|
+
mainSections={2}
|
|
26
|
+
sidebarSections={2}
|
|
27
|
+
showJSON
|
|
28
|
+
showMetadata
|
|
29
|
+
/>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (isError) {
|
|
34
|
+
throw error
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<LayoutComposer
|
|
39
|
+
widgetsZonePrefix="b2b.company.details"
|
|
40
|
+
preferredLayoutId={CORE_LAYOUT_IDS.TWO_COLUMN}
|
|
41
|
+
data={company as any}
|
|
42
|
+
sections={{
|
|
43
|
+
main: (
|
|
44
|
+
<>
|
|
45
|
+
<LayoutComposer.Entry id="CompanyGeneralSection">
|
|
46
|
+
<CompanyGeneralSection company={company} />
|
|
47
|
+
</LayoutComposer.Entry>
|
|
48
|
+
<LayoutComposer.Entry id="CompanyEmployeesSection">
|
|
49
|
+
<CompanyEmployeesSection companyId={company.id} />
|
|
50
|
+
</LayoutComposer.Entry>
|
|
51
|
+
{detailPageDefaultEntries(company as any)}
|
|
52
|
+
</>
|
|
53
|
+
),
|
|
54
|
+
side: (
|
|
55
|
+
<>
|
|
56
|
+
<LayoutComposer.Entry id="CompanyCustomerGroupSection">
|
|
57
|
+
<CompanyCustomerGroupSection company={company} />
|
|
58
|
+
</LayoutComposer.Entry>
|
|
59
|
+
<LayoutComposer.Entry id="CompanyApprovalSettingsSection">
|
|
60
|
+
<CompanyApprovalSettingsSection company={company} />
|
|
61
|
+
</LayoutComposer.Entry>
|
|
62
|
+
</>
|
|
63
|
+
),
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const Breadcrumb = ({ id }: { id?: string }) => {
|
|
70
|
+
const { t } = useTranslation()
|
|
71
|
+
const { data } = useCompany(id ?? "", undefined, { enabled: !!id })
|
|
72
|
+
return data?.company?.name ?? id ?? t("companies.label")
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const handle = {
|
|
76
|
+
breadcrumb: (match: any) => <Breadcrumb id={match?.params?.id} />,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const GuardedCompanyDetail = () => (
|
|
80
|
+
<RbacGuard permission="b2b.read">
|
|
81
|
+
<CompanyDetail />
|
|
82
|
+
</RbacGuard>
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
export default GuardedCompanyDetail
|