{"size": 1101, "ext": "js", "max_stars_repo_path": "frontend/components/GroupEditContent.js", "max_stars_repo_name": "vjagaro/neo.pujas.live", "max_stars_repo_stars_event_min_datetime": "2021-07-31T23:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-31T23:39:44.000Z", "max_issues_repo_path": "frontend/components/GroupEditContent.js", "max_issues_repo_name": "vjagaro/neo.pujas.live", "max_issues_repo_issues_event_min_datetime": "2021-01-23T21:07:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-22T16:09:25.000Z", "max_forks_repo_path": "frontend/components/GroupEditContent.js", "max_forks_repo_name": "vjagaro/neo.pujas.live", "max_forks_repo_forks_event_min_datetime": "2021-01-23T11:35:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-24T07:08:56.000Z"}
{"max_stars_count": 1, "max_issues_count": 71, "max_forks_count": 2, "avg_line_length": 28.9736842105, "max_line_length": 66, "alphanum_fraction": 0.6630336058}
import { useMutation } from "@apollo/client";
import Container from "@material-ui/core/Container";

import GroupForm from "@/components/GroupForm";
import Title from "@/components/Title";
import { UPDATE_GROUP_MUTATION } from "@/lib/schema";
import { useSnackbar } from "@/lib/snackbar";
import { groupSchema, groupUpdateDbCast } from "@/lib/validation";

const GroupEditContent = ({ group }) => {
  const [updateGroup] = useMutation(UPDATE_GROUP_MUTATION);
  const { snackException, snackSuccess } = useSnackbar();

  const groupId = group.id;
  group = groupSchema.cast(group);

  const onSubmit = async (values) => {
    const data = groupUpdateDbCast.cast(values);
    try {
      await updateGroup({
        variables: { input: { where: { id: groupId }, data } },
      });
      snackSuccess("Successfully updated group");
    } catch (error) {
      snackException(error);
    }
  };

  return (
    <Container maxWidth="sm">
      {!!group.title && <Title title={group.title} />}
      <GroupForm group={group} onSubmit={onSubmit} />
    </Container>
  );
};

export default GroupEditContent;
