index.tsx 4.9 KB

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