Merge pull request #3717 from urbit/lf/group-autojoin

JoinGroup: restore autojoin
This commit is contained in:
matildepark 2020-10-14 21:58:35 -04:00 committed by GitHub
commit b1417c84e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import React, { useState, useCallback } from "react";
import React, { useState, useCallback, useEffect } from "react";
import { Body } from "~/views/components/Body";
import {
Col,
@ -6,7 +6,7 @@ import {
Text,
ManagedTextInputField as Input
} from "@tlon/indigo-react";
import { Formik, Form, FormikHelpers } from "formik";
import { Formik, Form, FormikHelpers, useFormikContext } from "formik";
import { AsyncButton } from "~/views/components/AsyncButton";
import * as Yup from "yup";
import { Groups, Rolodex } from "~/types";
@ -35,12 +35,25 @@ interface JoinGroupProps {
groups: Groups;
contacts: Rolodex;
api: GlobalApi;
autojoin: string | null;
}
function Autojoin(props: { autojoin: string | null; }) {
const { submitForm } = useFormikContext();
useEffect(() => {
if(props.autojoin) {
submitForm();
}
},[]);
return null;
}
export function JoinGroup(props: JoinGroupProps & RouteComponentProps) {
const { api, history } = props;
const { api, history, autojoin } = props;
const initialValues: FormSchema = {
group: "",
group: autojoin || "",
};
const waiter = useWaitForProps(props);
@ -77,6 +90,7 @@ export function JoinGroup(props: JoinGroupProps & RouteComponentProps) {
onSubmit={onSubmit}
>
<Form>
<Autojoin autojoin={autojoin} />
<Col gapY="4">
<Input
id="group"

View File

@ -91,13 +91,16 @@ export default class Landscape extends Component<LandscapeProps, {}> {
);
}}
/>
<Route path="/~landscape/join"
<Route path="/~landscape/join/:ship?/:name?"
render={routeProps=> {
const { ship, name } = routeProps.match.params;
const autojoin = ship && name ? `${ship}/${name}` : null;
return (
<JoinGroup
groups={props.groups}
contacts={props.contacts}
api={props.api}
autojoin={autojoin}
{...routeProps}
/>
);