> For the complete documentation index, see [llms.txt](https://docs.obto.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.obto.co/sofos/order-management/client/productmanagement/productform.md).

# ProductForm

ProductForm component client script is also using ReactJs and Ant Design react component library. This component renders the list of form to edit the product details. User can edit the details of the product and save them.

```javascript
// components/ProductForm.js
const { useState, useEffect } = React;
const { Form, Input, Modal, Button, Space, Select, InputNumber } = antd;
const { MinusCircleOutlined, PlusOutlined } = antdIcons;

const ProductForm = ({ visible, onCreate, onCancel, editingProduct }) => {
  const [form] = Form.useForm();

  useEffect(() => {
    form.setFieldsValue({
      name: editingProduct?.name,
      description: editingProduct?.description,
      specifications: editingProduct?.specifications || []
    });
  }, [editingProduct, form]);

  const handleChange = value => {
    console.log(`selected ${value}`);
  };

  const options = [
    {
      label: "Nursary",
      value: "Nursary"
    },
    {
      label: "I",
      value: "I"
    },
    {
      label: "II",
      value: "II"
    }
  ];

  return (
    <Modal
      visible={visible}
      title={editingProduct ? "Edit Product" : "Create a new product"}
      okText={editingProduct ? "Update" : "Create"}
      onCancel={onCancel}
      onOk={() => {
        form
          .validateFields()
          .then(values => {
            form.resetFields();
            onCreate(values);
          })
          .catch(info => {
            console.log("Validate Failed:", info);
          });
      }}
    >
      <Form
        form={form}
        layout="vertical"
        initialValues={{ specifications: [{ key: "", value: "" }] }}
      >
        {/* Name and Description Fields */}
        {/* ... */}

        <Form.Item
          name="title"
          label="Product Title"
          rules={[
            { required: true, message: "Please input the name of the product!" }
          ]}
        >
          <Input />
        </Form.Item>
        <Form.Item name="description" label="Description">
          <Input type="textarea" />
        </Form.Item>
        <Form.Item name="category" label="Category">
          <Select
            mode="multiple"
            allowClear
            style={{
              width: "100%"
            }}
            placeholder="Please select"
            defaultValue={["all"]}
            onChange={handleChange}
            options={options}
          />
        </Form.Item>

        <Form.List name="stock">
          {(fields, { add, remove }) => (
            <>
              {fields.map(({ key, name, fieldKey, ...restField }) => (
                <Space
                  key={key}
                  style={{ display: "flex", marginBottom: 8 }}
                  align="baseline"
                >
                  <Form.Item
                    {...restField}
                    name={[name, "quantity"]}
                    fieldKey={[fieldKey, "quantity"]}
                    rules={[
                      {
                        required: true,
                        message: "Please input quanity"
                      }
                    ]}
                  >
                    <InputNumber placeholder="Quantity" />
                  </Form.Item>
                  <Form.Item
                    {...restField}
                    name={[name, "price"]}
                    fieldKey={[fieldKey, "price"]}
                    rules={[
                      {
                        required: true,
                        message: "Please input price"
                      }
                    ]}
                  >
                    <InputNumber placeholder="Price" />
                  </Form.Item>
                  <MinusCircleOutlined onClick={() => remove(name)} />
                </Space>
              ))}
              <Form.Item>
                <Button
                  type="dashed"
                  onClick={() => add()}
                  block
                  icon={<PlusOutlined />}
                >
                  Add Stock Lines
                </Button>
              </Form.Item>
            </>
          )}
        </Form.List>
      </Form>
    </Modal>
  );
};

return ProductForm;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.obto.co/sofos/order-management/client/productmanagement/productform.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
