index.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { Button, DataTableBulkActionItem, defineDashboardExtension, usePage } from '@vendure/dashboard';
  2. import { InfoIcon } from 'lucide-react';
  3. import { toast } from 'sonner';
  4. import {
  5. BodyInputComponent,
  6. ResponseDisplay,
  7. ReviewMultiSelect,
  8. ReviewSingleSelect,
  9. ReviewStateSelect,
  10. TextareaCustomField,
  11. } from './custom-form-components';
  12. import { CustomWidget } from './custom-widget';
  13. import { reviewDetail } from './review-detail';
  14. import { reviewList } from './review-list';
  15. import { ReviewSelectWithCreate } from './review-select-with-create';
  16. import { routeWithoutAuth } from './route-without-auth';
  17. defineDashboardExtension({
  18. login: {
  19. afterForm: {
  20. component: () => (
  21. <div>
  22. <Button variant="secondary" className="w-full">
  23. Login with Vendure ID
  24. </Button>
  25. </div>
  26. ),
  27. },
  28. },
  29. routes: [reviewList, reviewDetail, routeWithoutAuth],
  30. widgets: [
  31. {
  32. id: 'custom-widget',
  33. name: 'Custom Widget',
  34. component: CustomWidget,
  35. defaultSize: { w: 3, h: 3 },
  36. },
  37. ],
  38. actionBarItems: [
  39. {
  40. pageId: 'product-detail',
  41. component: props => {
  42. const page = usePage();
  43. return (
  44. <Button
  45. type="button"
  46. onClick={() => {
  47. console.log('Clicked custom action bar item');
  48. }}
  49. >
  50. Test Button
  51. </Button>
  52. );
  53. },
  54. },
  55. ],
  56. pageBlocks: [
  57. {
  58. id: 'my-block',
  59. component: ({ context }) => {
  60. return <div>Here is my custom block!</div>;
  61. },
  62. title: 'My Custom Block',
  63. location: {
  64. pageId: 'product-detail',
  65. column: 'side',
  66. position: { blockId: 'main-form', order: 'after' },
  67. },
  68. },
  69. ],
  70. customFormComponents: {
  71. customFields: [
  72. {
  73. id: 'textarea',
  74. component: TextareaCustomField,
  75. },
  76. {
  77. id: 'review-single-select',
  78. component: ReviewSingleSelect,
  79. },
  80. {
  81. id: 'review-multi-select',
  82. component: ReviewMultiSelect,
  83. },
  84. {
  85. id: 'review-multi-select-with-create',
  86. component: ReviewSelectWithCreate,
  87. },
  88. ],
  89. },
  90. detailForms: [
  91. {
  92. pageId: 'product-variant-detail',
  93. // extendDetailDocument: `
  94. // query {
  95. // productVariant(id: $id) {
  96. // stockOnHand
  97. // product {
  98. // facetValues {
  99. // id
  100. // name
  101. // facet {
  102. // code
  103. // }
  104. // }
  105. // customFields {
  106. // featuredReview {
  107. // id
  108. // productVariant {
  109. // id
  110. // name
  111. // }
  112. // product {
  113. // name
  114. // }
  115. // }
  116. // }
  117. // }
  118. // }
  119. // }
  120. // `,
  121. },
  122. {
  123. pageId: 'review-detail',
  124. inputs: [
  125. {
  126. blockId: 'main-form',
  127. field: 'body',
  128. component: BodyInputComponent,
  129. },
  130. {
  131. blockId: 'main-form',
  132. field: 'state',
  133. component: ReviewStateSelect,
  134. },
  135. {
  136. blockId: 'main-form',
  137. field: 'response',
  138. component: ResponseDisplay,
  139. },
  140. ],
  141. },
  142. ],
  143. dataTables: [
  144. {
  145. pageId: 'product-list',
  146. bulkActions: [
  147. {
  148. component: props => (
  149. <DataTableBulkActionItem
  150. onClick={() => {
  151. console.log('Selection:', props.selection);
  152. toast.message(`There are ${props.selection.length} selected items`);
  153. }}
  154. label="My Custom Action"
  155. icon={InfoIcon}
  156. />
  157. ),
  158. },
  159. ],
  160. // extendListDocument: `
  161. // query {
  162. // products {
  163. // items {
  164. // customFields {
  165. // featuredReview {
  166. // id
  167. // productVariant {
  168. // id
  169. // name
  170. // }
  171. // }
  172. // }
  173. // }
  174. // }
  175. // }
  176. // `,
  177. },
  178. ],
  179. });