ItemFormFactory.jsx 901 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from "react";
  2. import { Form } from "react-final-form";
  3. import arrayMutators from "final-form-arrays";
  4. import ItemForm from "../../gameComponents/ItemForm";
  5. import AutoSave from "../../ui/formUtils/AutoSave";
  6. const ItemFormFactory = ({ onUpdate, items, extraExcludeFields = {} }) => {
  7. const types = React.useMemo(
  8. () => Array.from(new Set(items.map(({ type }) => type))),
  9. [items]
  10. );
  11. return (
  12. <Form
  13. onSubmit={onUpdate}
  14. mutators={{
  15. ...arrayMutators,
  16. }}
  17. render={() => (
  18. <div
  19. style={{
  20. display: "flex",
  21. flexDirection: "column",
  22. }}
  23. >
  24. <AutoSave save={onUpdate} />
  25. <ItemForm
  26. items={items}
  27. types={types}
  28. extraExcludeFields={extraExcludeFields}
  29. />
  30. </div>
  31. )}
  32. />
  33. );
  34. };
  35. export default ItemFormFactory;