<commit_before>import React, { useRef } from "react";
import { Button, Checkbox, Form, Input, notification } from "antd";
import { MarkdownEditor } from "../../../../components/markdown/MarkdownEditor";

/**
 * Render React component to show the form to create or update an announcement.
 * @param {object} announcement - the announcement that is to be edited.
 * @param {function} createAnnouncement - the function that creates an announcement.
 * @param {function} updateAnnouncement - the function that updates an announcement.
 * @param {function} deleteAnnouncement - the function that deletes an announcement.
 * @returns {*}
 * @constructor
 */
export default function AnnouncementForm({
  announcement,
  createAnnouncement,
  updateAnnouncement,
}) {
  const markdownRef = useRef();
  const [form] = Form.useForm();

  function saveAnnouncement() {
    form.validateFields().then(({ title, priority }) => {
      const markdown = markdownRef.current.getMarkdown();

      if (announcement) {
        updateAnnouncement({
          id: announcement.id,
          title,
          message: markdown,
          priority,
        }).catch((message) => notification.error({ message }));
      } else {
        createAnnouncement(title, markdown, priority).catch((message) =>
          notification.error({ message })
        );
      }
    });
  }

  return (
    <Form layout="vertical" form={form} initialValues={announcement}>
      <Form.Item
        name="title"
        label={i18n("AnnouncementForm.form.title")}
        rules={[
          {
            required: true,
            message: i18n("AnnouncementForm.form.error.title"),
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item name="message" label={i18n("AnnouncementForm.form.message")}>
        <MarkdownEditor
          ref={markdownRef}
          markdown={announcement ? announcement.message : null}
        />
      </Form.Item>
      <Form.Item name="priority" valuePropName="checked">
        <Checkbox>{i18n("AnnouncementForm.form.priority")}</Checkbox>
      </Form.Item><commit_msg>resetting the form after submission<commit_after>import React, { useRef } from "react";
import { Button, Checkbox, Form, Input, notification } from "antd";
import { MarkdownEditor } from "../../../../components/markdown/MarkdownEditor";

/**
 * Render React component to show the form to create or update an announcement.
 * @param {object} announcement - the announcement that is to be edited.
 * @param {function} createAnnouncement - the function that creates an announcement.
 * @param {function} updateAnnouncement - the function that updates an announcement.
 * @param {function} deleteAnnouncement - the function that deletes an announcement.
 * @returns {*}
 * @constructor
 */
export default function AnnouncementForm({
  announcement,
  createAnnouncement,
  updateAnnouncement,
}) {
  const markdownRef = useRef();
  const [form] = Form.useForm();

  function saveAnnouncement() {
    form.validateFields().then(({ title, priority }) => {
      const markdown = markdownRef.current.getMarkdown();

      if (announcement) {
        updateAnnouncement({
          id: announcement.id,
          title,
          message: markdown,
          priority,
        }).catch((message) => notification.error({ message }));
      } else {
        createAnnouncement(title, markdown, priority)
          .then(form.resetFields)
          .catch((message) => notification.error({ message }));
      }
    });
  }

  return (
    <Form layout="vertical" form={form} initialValues={announcement}>
      <Form.Item
        name="title"
        label={i18n("AnnouncementForm.form.title")}
        rules={[
          {
            required: true,
            message: i18n("AnnouncementForm.form.error.title"),
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item name="message" label={i18n("AnnouncementForm.form.message")}>
        <MarkdownEditor
          ref={markdownRef}
          markdown={announcement ? announcement.message : null}
        />
      </Form.Item>
      <Form.Item name="priority" valuePropName="checked">
        <Checkbox>{i18n("AnnouncementForm.form.priority")}</Checkbox>
      </Form.Item>
{'fraction_non_alphanumeric': 0.13154172560113153, 'fraction_numerical': 0.003771805752003772, 'mean_word_length': 2.7682060390763765, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7063661', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1159, 'n_words': 279}