custom-form-components.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import {
  2. CustomFormComponentInputProps,
  3. DataDisplayComponentProps,
  4. DataInputComponentProps,
  5. FormControl,
  6. MultiRelationInput,
  7. RelationSelectorConfig,
  8. ResultOf,
  9. Select,
  10. SelectContent,
  11. SelectItem,
  12. SelectTrigger,
  13. SelectValue,
  14. SingleRelationInput,
  15. Textarea,
  16. } from '@vendure/dashboard';
  17. import { graphql } from '../../../graphql/graphql';
  18. export function TextareaCustomField({ field }: CustomFormComponentInputProps) {
  19. return <Textarea {...field} rows={4} />;
  20. }
  21. export function ResponseDisplay({ value }: DataDisplayComponentProps) {
  22. return <div className="font-mono">{value}</div>;
  23. }
  24. export function BodyInputComponent(props: DataInputComponentProps) {
  25. return <Textarea {...props} rows={4} />;
  26. }
  27. const reviewFragment = graphql(`
  28. fragment Review on ProductReview {
  29. id
  30. summary
  31. }
  32. `);
  33. const reviewListQuery = graphql(
  34. `
  35. query GetReviewList($options: ProductReviewListOptions) {
  36. productReviews(options: $options) {
  37. items {
  38. ...Review
  39. }
  40. totalItems
  41. }
  42. }
  43. `,
  44. [reviewFragment],
  45. );
  46. export function ReviewSingleSelect(props: CustomFormComponentInputProps) {
  47. const config: RelationSelectorConfig<ResultOf<typeof reviewFragment>> = {
  48. listQuery: reviewListQuery,
  49. labelKey: 'summary',
  50. idKey: 'id',
  51. };
  52. return (
  53. <SingleRelationInput
  54. value={props.field.value}
  55. onChange={props.field.onChange}
  56. config={config}
  57. ></SingleRelationInput>
  58. );
  59. }
  60. export function ReviewMultiSelect(props: CustomFormComponentInputProps) {
  61. const config: RelationSelectorConfig<ResultOf<typeof reviewFragment>> = {
  62. listQuery: reviewListQuery,
  63. labelKey: 'summary',
  64. idKey: 'id',
  65. };
  66. return (
  67. <MultiRelationInput
  68. value={props.field.value}
  69. onChange={props.field.onChange}
  70. config={config}
  71. ></MultiRelationInput>
  72. );
  73. }
  74. export function ReviewStateSelect(props: DataInputComponentProps) {
  75. return (
  76. <Select value={props.value} onValueChange={props.onChange} key={props.value}>
  77. <FormControl>
  78. <SelectTrigger>
  79. <SelectValue placeholder="Select state..."></SelectValue>
  80. </SelectTrigger>
  81. </FormControl>
  82. <SelectContent>
  83. <SelectItem value="new">New</SelectItem>
  84. <SelectItem value="approved">Approved</SelectItem>
  85. <SelectItem value="rejected">Rejected</SelectItem>
  86. </SelectContent>
  87. </Select>
  88. );
  89. }