interface: fix new channel redirect

This commit is contained in:
Liam Fitzgerald 2021-09-08 16:36:34 +10:00
parent f24fbe3eba
commit 797e3453aa

View File

@ -8,7 +8,7 @@ import { addTag, createManagedGraph, createUnmanagedGraph } from '@urbit/api';
import { Form, Formik } from 'formik'; import { Form, Formik } from 'formik';
import _ from 'lodash'; import _ from 'lodash';
import React, { ReactElement } from 'react'; import React, { ReactElement } from 'react';
import { useHistory } from 'react-router-dom'; import { useHistory, useRouteMatch } from 'react-router-dom';
import * as Yup from 'yup'; import * as Yup from 'yup';
import { resourceFromPath } from '~/logic/lib/group'; import { resourceFromPath } from '~/logic/lib/group';
import { useWaitForProps } from '~/logic/lib/useWaitForProps'; import { useWaitForProps } from '~/logic/lib/useWaitForProps';
@ -49,6 +49,7 @@ type NewChannelProps = {
export function NewChannel(props: NewChannelProps): ReactElement { export function NewChannel(props: NewChannelProps): ReactElement {
const history = useHistory(); const history = useHistory();
const match = useRouteMatch();
const { group, workspace, existingMembers, ...rest } = props; const { group, workspace, existingMembers, ...rest } = props;
const groups = useGroupState(state => state.groups); const groups = useGroupState(state => state.groups);
const waiter = useWaitForProps({ groups }, 5000); const waiter = useWaitForProps({ groups }, 5000);
@ -121,9 +122,9 @@ export function NewChannel(props: NewChannelProps): ReactElement {
); );
} }
actions.setStatus({ success: null }); actions.setStatus({ success: null });
const resourceUrl = location.pathname.includes('/messages') const resourceUrl = match.url.includes('/messages')
? '/~landscape/messages' ? '/~landscape/messages'
: parentPath(location.pathname); : parentPath(match.path);
history.push( history.push(
`${resourceUrl}/resource/${moduleType}/ship/~${window.ship}/${resId}` `${resourceUrl}/resource/${moduleType}/ship/~${window.ship}/${resId}`
); );