landscape: support groupifying chats

This commit is contained in:
Liam Fitzgerald 2020-11-05 12:02:08 +10:00
parent 414567b843
commit 9ab43333e2
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB

View File

@ -7,6 +7,7 @@ import { Groups, Associations, Association } from "~/types";
import { Formik, FormikHelpers, Form } from "formik"; import { Formik, FormikHelpers, Form } from "formik";
import GroupSearch from "~/views/components/GroupSearch"; import GroupSearch from "~/views/components/GroupSearch";
import { AsyncButton } from "~/views/components/AsyncButton"; import { AsyncButton } from "~/views/components/AsyncButton";
import {useHistory} from "react-router-dom";
const formSchema = Yup.object({ const formSchema = Yup.object({
group: Yup.string().nullable(), group: Yup.string().nullable(),
@ -24,17 +25,29 @@ interface GroupifyFormProps {
} }
export function GroupifyForm(props: GroupifyFormProps) { export function GroupifyForm(props: GroupifyFormProps) {
const history = useHistory();
const { association } = props;
const onGroupify = async ( const onGroupify = async (
values: FormSchema, values: FormSchema,
actions: FormikHelpers<FormSchema> actions: FormikHelpers<FormSchema>
) => { ) => {
try { try {
const [, , ship, name] = props.association["app-path"].split("/"); if (association["app-name"] === "chat") {
await props.api.graph.groupifyGraph( await props.api.chat.groupify(
ship, association["app-path"],
name, values.group,
values.group || undefined true
); );
} else {
const [, , ship, name] = association["app-path"].split("/");
await props.api.graph.groupifyGraph(
ship,
name,
values.group || undefined
);
}
const mod = association.metadata.module || association['app-name'];
history.push(`/~landscape${values.group}/resource/${mod}${association['app-path']}`);
actions.setStatus({ success: null }); actions.setStatus({ success: null });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -68,7 +81,7 @@ export function GroupifyForm(props: GroupifyFormProps) {
<GroupSearch <GroupSearch
id="group" id="group"
label="Group" label="Group"
caption="What group should this channel be added to? If blank, a new group will be made for the channel" caption="What group should this channel be added to? If blank, a new group will be made for the channel. Note that you must be an admin to add channels to a group"
groups={props.groups} groups={props.groups}
associations={props.associations} associations={props.associations}
adminOnly adminOnly