EditChannel.view.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import React from 'react';
  2. import { RouteComponentProps } from 'react-router';
  3. import { MediaView } from '../MediaView';
  4. import { OuterProps, EditForm } from './EditChannel';
  5. import { JoyError } from '@polkadot/joy-utils/react/components';
  6. import { useApi } from '@polkadot/react-hooks';
  7. type Props = OuterProps;
  8. export const EditChannelView = MediaView<Props>({
  9. component: EditForm,
  10. membersOnly: true,
  11. triggers: ['id'],
  12. resolveProps: async (props) => {
  13. const { transport, id } = props;
  14. const entity = id && await transport.channelById(id);
  15. const constraints = await transport.channelValidationConstraints();
  16. return { entity, constraints };
  17. }
  18. });
  19. type WithRouterProps = Props & RouteComponentProps<any>
  20. export const EditChannelWithRouter = (props: WithRouterProps) => {
  21. const { match: { params: { id } } } = props;
  22. const { api } = useApi();
  23. if (id) {
  24. try {
  25. return <EditChannelView {...props} id={api.createType('ChannelId', id)} />;
  26. } catch (err) {
  27. console.log('EditChannelWithRouter failed:', err);
  28. }
  29. }
  30. return <JoyError title={'Invalid channel id in URL'}>{id}</JoyError>;
  31. };