@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,7 @@
|
|
|
1
|
+
export * from "./manage-item.tsx"
|
|
2
|
+
export * from "./manage-item-info.tsx"
|
|
3
|
+
export * from "./manage-item-price-form.tsx"
|
|
4
|
+
export * from "./manage-items-section.tsx"
|
|
5
|
+
export * from "./manage-items-table.tsx"
|
|
6
|
+
export * from "./manage-quote-form.tsx"
|
|
7
|
+
export * from "./table/index"
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Thumbnail } from "@medusajs/dashboard/components"
|
|
2
|
+
import { AdminOrderPreview } from "@medusajs/framework/types"
|
|
3
|
+
import { Badge, Text } from "@medusajs/ui"
|
|
4
|
+
import { useTranslation } from "react-i18next"
|
|
5
|
+
|
|
6
|
+
export interface ManageItemInfoProps {
|
|
7
|
+
item: AdminOrderPreview["items"][0]
|
|
8
|
+
isAddedItem: boolean
|
|
9
|
+
isItemUpdated: boolean
|
|
10
|
+
isItemRemoved: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const ManageItemInfo = ({
|
|
14
|
+
item,
|
|
15
|
+
isAddedItem,
|
|
16
|
+
isItemUpdated,
|
|
17
|
+
isItemRemoved,
|
|
18
|
+
}: ManageItemInfoProps) => {
|
|
19
|
+
const { t } = useTranslation()
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className="flex flex-1 items-center justify-between">
|
|
23
|
+
<div className="flex flex-row items-center gap-x-3">
|
|
24
|
+
<Thumbnail src={item.thumbnail} />
|
|
25
|
+
<div className="flex flex-col">
|
|
26
|
+
<div>
|
|
27
|
+
<Text className="txt-small" as="span" weight="plus">
|
|
28
|
+
{item.title}
|
|
29
|
+
</Text>
|
|
30
|
+
{item.variant_sku && (
|
|
31
|
+
<span className="txt-small text-ui-fg-subtle">
|
|
32
|
+
{" "}
|
|
33
|
+
({item.variant_sku})
|
|
34
|
+
</span>
|
|
35
|
+
)}
|
|
36
|
+
</div>
|
|
37
|
+
<Text as="div" className="text-ui-fg-subtle txt-small">
|
|
38
|
+
{item.product_title}
|
|
39
|
+
</Text>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<div className="flex items-center gap-1">
|
|
44
|
+
{isAddedItem && (
|
|
45
|
+
<Badge size="2xsmall" rounded="full" color="blue">
|
|
46
|
+
{t("general.new")}
|
|
47
|
+
</Badge>
|
|
48
|
+
)}
|
|
49
|
+
{isItemRemoved ? (
|
|
50
|
+
<Badge size="2xsmall" rounded="full" color="red">
|
|
51
|
+
{t("general.removed")}
|
|
52
|
+
</Badge>
|
|
53
|
+
) : (
|
|
54
|
+
isItemUpdated && (
|
|
55
|
+
<Badge size="2xsmall" rounded="full" color="orange">
|
|
56
|
+
{t("general.modified")}
|
|
57
|
+
</Badge>
|
|
58
|
+
)
|
|
59
|
+
)}
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getCurrencySymbol } from "@medusajs/dashboard/lib"
|
|
2
|
+
import { XMark } from "@medusajs/icons"
|
|
3
|
+
import { CurrencyInput, Hint, IconButton, Label } from "@medusajs/ui"
|
|
4
|
+
import { useTranslation } from "react-i18next"
|
|
5
|
+
|
|
6
|
+
export interface ManageItemPriceFormProps {
|
|
7
|
+
itemId: string
|
|
8
|
+
unitPrice: number
|
|
9
|
+
currencyCode: string
|
|
10
|
+
onPriceChange: (price: number) => void
|
|
11
|
+
onClose: () => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ManageItemPriceForm = ({
|
|
15
|
+
itemId,
|
|
16
|
+
unitPrice,
|
|
17
|
+
currencyCode,
|
|
18
|
+
onPriceChange,
|
|
19
|
+
onClose,
|
|
20
|
+
}: ManageItemPriceFormProps) => {
|
|
21
|
+
const { t } = useTranslation()
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div className="grid grid-cols-1 gap-2 p-3 md:grid-cols-2">
|
|
25
|
+
<div>
|
|
26
|
+
<Label size="small" weight="plus">
|
|
27
|
+
{t("fields.price")}
|
|
28
|
+
</Label>
|
|
29
|
+
<Hint className="!mt-1">{t("quotes.manage.priceOverrideHint")}</Hint>
|
|
30
|
+
</div>
|
|
31
|
+
<div className="flex items-center gap-1">
|
|
32
|
+
<div className="grow">
|
|
33
|
+
<CurrencyInput
|
|
34
|
+
key={`price-${itemId}-${unitPrice}`}
|
|
35
|
+
symbol={getCurrencySymbol(currencyCode) ?? currencyCode}
|
|
36
|
+
code={currencyCode}
|
|
37
|
+
defaultValue={unitPrice}
|
|
38
|
+
type="numeric"
|
|
39
|
+
min={0}
|
|
40
|
+
onChange={(e) => {
|
|
41
|
+
const price = parseFloat(e.target.value.replace(/,/g, ""))
|
|
42
|
+
if (!isNaN(price) && price > 0) {
|
|
43
|
+
onPriceChange(price)
|
|
44
|
+
}
|
|
45
|
+
}}
|
|
46
|
+
className="bg-ui-bg-field-component hover:bg-ui-bg-field-component-hover"
|
|
47
|
+
/>
|
|
48
|
+
</div>
|
|
49
|
+
<IconButton
|
|
50
|
+
type="button"
|
|
51
|
+
className="shrink"
|
|
52
|
+
variant="transparent"
|
|
53
|
+
onClick={onClose}
|
|
54
|
+
>
|
|
55
|
+
<XMark className="text-ui-fg-muted" />
|
|
56
|
+
</IconButton>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { ActionMenu } from "@medusajs/dashboard/components"
|
|
2
|
+
import { AdminOrder, AdminOrderPreview } from "@medusajs/framework/types"
|
|
3
|
+
import {
|
|
4
|
+
ArrowUturnLeft,
|
|
5
|
+
DocumentSeries,
|
|
6
|
+
PencilSquare,
|
|
7
|
+
XCircle,
|
|
8
|
+
} from "@medusajs/icons"
|
|
9
|
+
import { Input, Text, toast } from "@medusajs/ui"
|
|
10
|
+
import { AmountCell } from "@vicacha-devs/medusa-shared-admin/admin"
|
|
11
|
+
import debounce from "lodash/debounce"
|
|
12
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
|
13
|
+
import { useTranslation } from "react-i18next"
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
useAddItemsToQuote,
|
|
17
|
+
useRemoveQuoteItem,
|
|
18
|
+
useUpdateQuoteItem,
|
|
19
|
+
} from "../../../../../../hooks/api"
|
|
20
|
+
import { ManageItemInfo } from "./manage-item-info"
|
|
21
|
+
import { ManageItemPriceForm } from "./manage-item-price-form"
|
|
22
|
+
|
|
23
|
+
type ManageItemProps = {
|
|
24
|
+
originalItem: AdminOrder["items"][0]
|
|
25
|
+
item: AdminOrderPreview["items"][0]
|
|
26
|
+
currencyCode: string
|
|
27
|
+
orderId: string
|
|
28
|
+
onItemChange: (changes: { quantity?: number; unit_price?: number }) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const ManageItem = ({
|
|
32
|
+
originalItem,
|
|
33
|
+
item,
|
|
34
|
+
currencyCode,
|
|
35
|
+
orderId,
|
|
36
|
+
onItemChange,
|
|
37
|
+
}: ManageItemProps) => {
|
|
38
|
+
const { t } = useTranslation()
|
|
39
|
+
const [showPriceForm, setShowPriceForm] = useState(false)
|
|
40
|
+
const [localQty, setLocalQty] = useState(item.quantity)
|
|
41
|
+
const [localPrice, setLocalPrice] = useState(item.unit_price)
|
|
42
|
+
const prevServerValuesRef = useRef({
|
|
43
|
+
quantity: item.quantity,
|
|
44
|
+
unit_price: item.unit_price,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const { mutateAsync: addItems } = useAddItemsToQuote(orderId)
|
|
48
|
+
const { mutateAsync: updateOriginalItem } = useUpdateQuoteItem(orderId)
|
|
49
|
+
const { mutateAsync: undoAction } = useRemoveQuoteItem(orderId)
|
|
50
|
+
|
|
51
|
+
const debouncedPriceNotify = useCallback(
|
|
52
|
+
debounce((price: number) => onItemChange({ unit_price: price }), 400),
|
|
53
|
+
[]
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
return () => debouncedPriceNotify.cancel()
|
|
58
|
+
}, [debouncedPriceNotify])
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const prev = prevServerValuesRef.current
|
|
62
|
+
if (
|
|
63
|
+
prev.quantity !== item.quantity ||
|
|
64
|
+
prev.unit_price !== item.unit_price
|
|
65
|
+
) {
|
|
66
|
+
prevServerValuesRef.current = {
|
|
67
|
+
quantity: item.quantity,
|
|
68
|
+
unit_price: item.unit_price,
|
|
69
|
+
}
|
|
70
|
+
setLocalQty(item.quantity)
|
|
71
|
+
setLocalPrice(item.unit_price)
|
|
72
|
+
onItemChange({ quantity: item.quantity, unit_price: item.unit_price })
|
|
73
|
+
}
|
|
74
|
+
}, [item.quantity, item.unit_price])
|
|
75
|
+
|
|
76
|
+
const addItemAction = useMemo(
|
|
77
|
+
() => item.actions?.find((a) => a.action === "ITEM_ADD"),
|
|
78
|
+
[item]
|
|
79
|
+
)
|
|
80
|
+
const updateItemAction = useMemo(
|
|
81
|
+
() => item.actions?.find((a) => a.action === "ITEM_UPDATE"),
|
|
82
|
+
[item]
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
const isAddedItem = !!addItemAction
|
|
86
|
+
const isItemUpdated = !!updateItemAction
|
|
87
|
+
const isItemRemoved =
|
|
88
|
+
!!updateItemAction && item.quantity === item.detail.fulfilled_quantity
|
|
89
|
+
|
|
90
|
+
const localItemTotal = localQty * localPrice
|
|
91
|
+
|
|
92
|
+
const onRemove = async () => {
|
|
93
|
+
try {
|
|
94
|
+
if (addItemAction) {
|
|
95
|
+
await undoAction(addItemAction.id)
|
|
96
|
+
} else {
|
|
97
|
+
await updateOriginalItem({
|
|
98
|
+
quantity: item.detail.fulfilled_quantity,
|
|
99
|
+
itemId: item.id,
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
} catch (e: any) {
|
|
103
|
+
toast.error(e.message)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const onRemoveUndo = async () => {
|
|
108
|
+
try {
|
|
109
|
+
if (updateItemAction) {
|
|
110
|
+
await undoAction(updateItemAction.id)
|
|
111
|
+
}
|
|
112
|
+
} catch (e: any) {
|
|
113
|
+
toast.error(e.message)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const onDuplicate = async () => {
|
|
118
|
+
try {
|
|
119
|
+
await addItems({
|
|
120
|
+
items: [{ variant_id: item.variant_id, quantity: item.quantity }],
|
|
121
|
+
})
|
|
122
|
+
} catch (e: any) {
|
|
123
|
+
toast.error(e.message)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const handleQtyChange = (qty: number) => {
|
|
128
|
+
if (qty <= item.detail.fulfilled_quantity) {
|
|
129
|
+
toast.error(t("orders.edits.validation.quantityLowerThanFulfillment"))
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
setLocalQty(qty)
|
|
133
|
+
onItemChange({ quantity: qty })
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const handlePriceChange = (price: number) => {
|
|
137
|
+
setLocalPrice(price)
|
|
138
|
+
debouncedPriceNotify(price)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div className="bg-ui-bg-subtle shadow-elevation-card-rest my-2 rounded-xl">
|
|
143
|
+
<div className="flex flex-col items-center gap-x-2 gap-y-2 p-3 text-sm md:flex-row">
|
|
144
|
+
<ManageItemInfo
|
|
145
|
+
item={item}
|
|
146
|
+
isAddedItem={isAddedItem}
|
|
147
|
+
isItemUpdated={isItemUpdated}
|
|
148
|
+
isItemRemoved={isItemRemoved}
|
|
149
|
+
/>
|
|
150
|
+
|
|
151
|
+
<div className="flex flex-1 justify-between">
|
|
152
|
+
<div className="flex grow items-center gap-2">
|
|
153
|
+
<Input
|
|
154
|
+
className="bg-ui-bg-base txt-small w-[67px] rounded-lg [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none"
|
|
155
|
+
type="number"
|
|
156
|
+
disabled={item.detail.fulfilled_quantity === item.quantity}
|
|
157
|
+
min={item.detail.fulfilled_quantity}
|
|
158
|
+
value={localQty}
|
|
159
|
+
onChange={(e) => {
|
|
160
|
+
const qty =
|
|
161
|
+
e.target.value === "" ? localQty : Number(e.target.value)
|
|
162
|
+
handleQtyChange(qty)
|
|
163
|
+
}}
|
|
164
|
+
/>
|
|
165
|
+
<Text className="txt-small text-ui-fg-subtle">
|
|
166
|
+
{t("fields.qty")}
|
|
167
|
+
</Text>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<div className="text-ui-fg-subtle txt-small mr-2 flex shrink-0">
|
|
171
|
+
<AmountCell
|
|
172
|
+
currencyCode={currencyCode}
|
|
173
|
+
amount={localItemTotal}
|
|
174
|
+
originalAmount={originalItem?.total}
|
|
175
|
+
/>
|
|
176
|
+
</div>
|
|
177
|
+
|
|
178
|
+
<ActionMenu
|
|
179
|
+
groups={[
|
|
180
|
+
{
|
|
181
|
+
actions: [
|
|
182
|
+
{
|
|
183
|
+
label: t("quotes.manage.updatePrice"),
|
|
184
|
+
onClick: () => setShowPriceForm((v) => !v),
|
|
185
|
+
icon: <PencilSquare />,
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
label: t("actions.duplicate"),
|
|
189
|
+
onClick: onDuplicate,
|
|
190
|
+
icon: <DocumentSeries />,
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
actions: [
|
|
196
|
+
!isItemRemoved
|
|
197
|
+
? {
|
|
198
|
+
label: t("actions.remove"),
|
|
199
|
+
onClick: onRemove,
|
|
200
|
+
icon: <XCircle />,
|
|
201
|
+
disabled:
|
|
202
|
+
item.detail.fulfilled_quantity === item.quantity,
|
|
203
|
+
}
|
|
204
|
+
: {
|
|
205
|
+
label: t("actions.undo"),
|
|
206
|
+
onClick: onRemoveUndo,
|
|
207
|
+
icon: <ArrowUturnLeft />,
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
]}
|
|
212
|
+
/>
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
|
|
216
|
+
{showPriceForm && (
|
|
217
|
+
<ManageItemPriceForm
|
|
218
|
+
itemId={item.id}
|
|
219
|
+
unitPrice={item.unit_price}
|
|
220
|
+
currencyCode={currencyCode}
|
|
221
|
+
onPriceChange={handlePriceChange}
|
|
222
|
+
onClose={() => setShowPriceForm(false)}
|
|
223
|
+
/>
|
|
224
|
+
)}
|
|
225
|
+
</div>
|
|
226
|
+
)
|
|
227
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StackedFocusModal,
|
|
3
|
+
useStackedModal,
|
|
4
|
+
} from "@medusajs/dashboard/components"
|
|
5
|
+
import { AdminOrder, AdminOrderPreview } from "@medusajs/framework/types"
|
|
6
|
+
import { Button, Container, Heading, Input, toast } from "@medusajs/ui"
|
|
7
|
+
import { useMemo, useRef, useState } from "react"
|
|
8
|
+
import { useTranslation } from "react-i18next"
|
|
9
|
+
import { useAddItemsToQuote } from "../../../../../../hooks/api"
|
|
10
|
+
import { ManageItem } from "./manage-item.tsx"
|
|
11
|
+
import { ManageItemsTable } from "./manage-items-table.tsx"
|
|
12
|
+
|
|
13
|
+
type ManageItemsSectionProps = {
|
|
14
|
+
order: AdminOrder
|
|
15
|
+
preview: AdminOrderPreview
|
|
16
|
+
onItemChange: (
|
|
17
|
+
itemId: string,
|
|
18
|
+
changes: { quantity?: number; unit_price?: number }
|
|
19
|
+
) => void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const ManageItemsSection = ({
|
|
23
|
+
order,
|
|
24
|
+
preview,
|
|
25
|
+
onItemChange,
|
|
26
|
+
}: ManageItemsSectionProps) => {
|
|
27
|
+
const { t } = useTranslation()
|
|
28
|
+
const { setIsOpen } = useStackedModal()
|
|
29
|
+
const [filterTerm, setFilterTerm] = useState("")
|
|
30
|
+
const addedVariantsRef = useRef<string[]>([])
|
|
31
|
+
|
|
32
|
+
const { mutateAsync: addItems, isPending } = useAddItemsToQuote(preview.id)
|
|
33
|
+
|
|
34
|
+
const onItemsSelected = async () => {
|
|
35
|
+
try {
|
|
36
|
+
await addItems({
|
|
37
|
+
items: addedVariantsRef.current.map((i) => ({
|
|
38
|
+
variant_id: i,
|
|
39
|
+
quantity: 1,
|
|
40
|
+
})),
|
|
41
|
+
})
|
|
42
|
+
} catch (e: any) {
|
|
43
|
+
toast.error(e.message)
|
|
44
|
+
}
|
|
45
|
+
setIsOpen("inbound-items", false)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const filteredItems = useMemo(() => {
|
|
49
|
+
return preview.items.filter((i) => {
|
|
50
|
+
const term = filterTerm.toLowerCase()
|
|
51
|
+
return (
|
|
52
|
+
i.title.toLowerCase().includes(term) ||
|
|
53
|
+
(i as any).product_title?.toLowerCase().includes(term)
|
|
54
|
+
)
|
|
55
|
+
}) as any[]
|
|
56
|
+
}, [preview, filterTerm])
|
|
57
|
+
|
|
58
|
+
const originalItemsMap = useMemo(() => {
|
|
59
|
+
return new Map(order.items.map((item) => [item.id, item]))
|
|
60
|
+
}, [order])
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Container className="divide-y p-0">
|
|
64
|
+
{/* Header */}
|
|
65
|
+
<div className="flex items-center justify-between px-6 py-4">
|
|
66
|
+
<Heading level="h2">{t("fields.items")}</Heading>
|
|
67
|
+
|
|
68
|
+
<div className="flex gap-2">
|
|
69
|
+
<Input
|
|
70
|
+
value={filterTerm}
|
|
71
|
+
onChange={(e) => setFilterTerm(e.target.value)}
|
|
72
|
+
placeholder={t("fields.search")}
|
|
73
|
+
autoComplete="off"
|
|
74
|
+
type="search"
|
|
75
|
+
/>
|
|
76
|
+
|
|
77
|
+
<StackedFocusModal id="inbound-items">
|
|
78
|
+
<StackedFocusModal.Trigger asChild>
|
|
79
|
+
<Button variant="secondary" size="small">
|
|
80
|
+
{t("actions.addItems")}
|
|
81
|
+
</Button>
|
|
82
|
+
</StackedFocusModal.Trigger>
|
|
83
|
+
|
|
84
|
+
<StackedFocusModal.Content>
|
|
85
|
+
<StackedFocusModal.Header />
|
|
86
|
+
|
|
87
|
+
<ManageItemsTable
|
|
88
|
+
onSelectionChange={(finalSelection) => {
|
|
89
|
+
addedVariantsRef.current = finalSelection
|
|
90
|
+
}}
|
|
91
|
+
/>
|
|
92
|
+
|
|
93
|
+
<StackedFocusModal.Footer>
|
|
94
|
+
<div className="flex w-full items-center justify-end gap-x-4">
|
|
95
|
+
<div className="flex items-center justify-end gap-x-2">
|
|
96
|
+
<StackedFocusModal.Close asChild>
|
|
97
|
+
<Button type="button" variant="secondary" size="small">
|
|
98
|
+
{t("actions.cancel")}
|
|
99
|
+
</Button>
|
|
100
|
+
</StackedFocusModal.Close>
|
|
101
|
+
<Button
|
|
102
|
+
key="submit-button"
|
|
103
|
+
type="submit"
|
|
104
|
+
variant="primary"
|
|
105
|
+
size="small"
|
|
106
|
+
role="button"
|
|
107
|
+
disabled={isPending}
|
|
108
|
+
onClick={async () => await onItemsSelected()}
|
|
109
|
+
>
|
|
110
|
+
{t("actions.save")}
|
|
111
|
+
</Button>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</StackedFocusModal.Footer>
|
|
115
|
+
</StackedFocusModal.Content>
|
|
116
|
+
</StackedFocusModal>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
{/* Items list */}
|
|
121
|
+
<div className="flex flex-col px-4 py-2">
|
|
122
|
+
{filteredItems.map((item) => (
|
|
123
|
+
<ManageItem
|
|
124
|
+
key={item.id}
|
|
125
|
+
originalItem={originalItemsMap.get(item.id)!}
|
|
126
|
+
item={item}
|
|
127
|
+
orderId={order.id}
|
|
128
|
+
currencyCode={order.currency_code}
|
|
129
|
+
onItemChange={(changes) => onItemChange(item.id, changes)}
|
|
130
|
+
/>
|
|
131
|
+
))}
|
|
132
|
+
|
|
133
|
+
{filterTerm && !filteredItems.length && (
|
|
134
|
+
<div
|
|
135
|
+
style={{
|
|
136
|
+
background:
|
|
137
|
+
"repeating-linear-gradient(-45deg, rgb(212, 212, 216, 0.15), rgb(212, 212, 216,.15) 10px, transparent 10px, transparent 20px)",
|
|
138
|
+
}}
|
|
139
|
+
className="bg-ui-bg-field my-2 block h-[56px] w-full rounded-lg border border-dashed"
|
|
140
|
+
/>
|
|
141
|
+
)}
|
|
142
|
+
</div>
|
|
143
|
+
</Container>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { useVariants } from "@medusajs/dashboard/hooks"
|
|
2
|
+
import {
|
|
3
|
+
DataTable,
|
|
4
|
+
DataTablePaginationState,
|
|
5
|
+
DataTableRowSelectionState,
|
|
6
|
+
DataTableSortingState,
|
|
7
|
+
createDataTableColumnHelper,
|
|
8
|
+
useDataTable,
|
|
9
|
+
} from "@medusajs/ui"
|
|
10
|
+
import { useMemo, useState } from "react"
|
|
11
|
+
import { useTranslation } from "react-i18next"
|
|
12
|
+
|
|
13
|
+
import { PAGE_SIZE } from "../../../../../../constants"
|
|
14
|
+
import { useManageItemsTableColumns } from "./table/columns"
|
|
15
|
+
import { useManageItemsTableFilters } from "./table/filters"
|
|
16
|
+
import { useManageItemsTableQuery } from "./table/query"
|
|
17
|
+
|
|
18
|
+
type ManageItemsTableProps = {
|
|
19
|
+
onSelectionChange: (ids: string[]) => void
|
|
20
|
+
prefix?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const columnHelper = createDataTableColumnHelper<any>()
|
|
24
|
+
|
|
25
|
+
export const ManageItemsTable = ({
|
|
26
|
+
onSelectionChange,
|
|
27
|
+
prefix,
|
|
28
|
+
}: ManageItemsTableProps) => {
|
|
29
|
+
const { t } = useTranslation()
|
|
30
|
+
const [rowSelection, setRowSelection] = useState<DataTableRowSelectionState>(
|
|
31
|
+
{}
|
|
32
|
+
)
|
|
33
|
+
const [sorting, setSorting] = useState<DataTableSortingState | null>(null)
|
|
34
|
+
const [search, setSearch] = useState("")
|
|
35
|
+
const [pagination, setPagination] = useState<DataTablePaginationState>({
|
|
36
|
+
pageIndex: 0,
|
|
37
|
+
pageSize: PAGE_SIZE,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const { searchParams } = useManageItemsTableQuery({
|
|
41
|
+
pageSize: PAGE_SIZE,
|
|
42
|
+
prefix,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const orderParam = sorting
|
|
46
|
+
? `${sorting.desc ? "-" : ""}${sorting.id}`
|
|
47
|
+
: searchParams.order
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
variants = [],
|
|
51
|
+
count,
|
|
52
|
+
isPending,
|
|
53
|
+
isError,
|
|
54
|
+
error,
|
|
55
|
+
} = useVariants({
|
|
56
|
+
...searchParams,
|
|
57
|
+
q: search || searchParams.q,
|
|
58
|
+
order: orderParam,
|
|
59
|
+
limit: PAGE_SIZE,
|
|
60
|
+
offset: pagination.pageIndex * PAGE_SIZE,
|
|
61
|
+
fields: "*inventory_items.inventory.location_levels,+inventory_quantity",
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const filters = useManageItemsTableFilters()
|
|
65
|
+
const baseColumns = useManageItemsTableColumns()
|
|
66
|
+
const columns = useMemo(
|
|
67
|
+
() => [columnHelper.select(), ...baseColumns],
|
|
68
|
+
[baseColumns]
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
const instance = useDataTable({
|
|
72
|
+
columns,
|
|
73
|
+
data: variants,
|
|
74
|
+
getRowId: (row) => row.id,
|
|
75
|
+
rowSelection: {
|
|
76
|
+
state: rowSelection,
|
|
77
|
+
onRowSelectionChange: (state) => {
|
|
78
|
+
setRowSelection(state)
|
|
79
|
+
onSelectionChange(Object.keys(state))
|
|
80
|
+
},
|
|
81
|
+
enableRowSelection: true,
|
|
82
|
+
},
|
|
83
|
+
search: {
|
|
84
|
+
state: search,
|
|
85
|
+
onSearchChange: setSearch,
|
|
86
|
+
},
|
|
87
|
+
sorting: {
|
|
88
|
+
state: sorting,
|
|
89
|
+
onSortingChange: setSorting,
|
|
90
|
+
},
|
|
91
|
+
filters,
|
|
92
|
+
pagination: {
|
|
93
|
+
state: pagination,
|
|
94
|
+
onPaginationChange: setPagination,
|
|
95
|
+
},
|
|
96
|
+
rowCount: count ?? 0,
|
|
97
|
+
isLoading: isPending,
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
if (isError) throw error
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<DataTable instance={instance}>
|
|
104
|
+
<DataTable.Toolbar className="px-6 py-4">
|
|
105
|
+
<div className="flex w-full items-center justify-end gap-x-2">
|
|
106
|
+
<DataTable.FilterMenu />
|
|
107
|
+
<DataTable.SortingMenu />
|
|
108
|
+
<DataTable.Search
|
|
109
|
+
placeholder={t("quotes.manage.searchPlaceholder")}
|
|
110
|
+
/>
|
|
111
|
+
</div>
|
|
112
|
+
</DataTable.Toolbar>
|
|
113
|
+
<DataTable.Table />
|
|
114
|
+
<DataTable.Pagination />
|
|
115
|
+
</DataTable>
|
|
116
|
+
)
|
|
117
|
+
}
|