CustomDetailComponent.tsx 1.0 KB

123456789101112131415161718192021222324252627282930
  1. import { Card, useDetailComponentData, useInjector } from '@vendure/admin-ui/react';
  2. import React, { useEffect, useState } from 'react';
  3. import { CmsDataService } from '../providers/cms-data.service';
  4. export function ProductInfo() {
  5. // The "entity" will vary depending on which detail page this component
  6. // is embedded in. In this case, it will be a "product" entity.
  7. const { entity, detailForm } = useDetailComponentData();
  8. const cmsDataService = useInjector(CmsDataService);
  9. const [extraInfo, setExtraInfo] = useState<any>();
  10. useEffect(() => {
  11. if (!(entity as any)?.id) {
  12. return;
  13. }
  14. const subscription = cmsDataService.getDataFor((entity as any).id).subscribe(data => {
  15. setExtraInfo(data);
  16. });
  17. return () => subscription.unsubscribe();
  18. }, [(entity as any)?.id]);
  19. return (
  20. <div className="mb-4">
  21. <Card title="CMS Info">
  22. <pre>{JSON.stringify(extraInfo, null, 2)}</pre>
  23. </Card>
  24. </div>
  25. );
  26. }