// @flow import { observer } from "mobx-react"; import * as React from "react"; import { useTranslation, Trans } from "react-i18next"; import styled from "styled-components"; import Group from "models/Group"; import Button from "components/Button"; import Flex from "components/Flex"; import HelpText from "components/HelpText"; import Input from "components/Input"; import Switch from "components/Switch"; import useToasts from "hooks/useToasts"; type Props = { group: Group, onSubmit: () => void, }; function GroupEdit({ group, onSubmit }: Props) { const { showToast } = useToasts(); const { t } = useTranslation(); const [name, setName] = React.useState(group.name); const [isPrivate, setIsPrivate] = React.useState(group.isPrivate); const [isSaving, setIsSaving] = React.useState(); const handleSubmit = React.useCallback( async (ev: SyntheticEvent<>) => { ev.preventDefault(); setIsSaving(true); try { await group.save({ name, isPrivate }); onSubmit(); } catch (err) { showToast(err.message, { type: "error" }); } finally { setIsSaving(false); } }, [group, isPrivate, name, onSubmit, showToast] ); const handleNameChange = React.useCallback((ev: SyntheticInputEvent<*>) => { setName(ev.target.value); }, []); return (
You can edit the name of this group at any time, however doing so too often might confuse your team mates. setIsPrivate((prev) => !prev)} checked={!isPrivate} /> {isPrivate ? t("Only members present in the group know about the group") : t("Everyone in the team can view the group")}
); } const SwitchWrapper = styled.div` margin: 20px 0; `; const SwitchLabel = styled(Flex)` flex-align: center; svg { flex-shrink: 0; } `; const SwitchText = styled(HelpText)` margin: 0; font-size: 15px; `; export default observer(GroupEdit);