mirror of
https://github.com/outline/outline.git
synced 2025-12-21 10:39:41 -06:00
* Iteration, before functional component * Use react-hook-form, shared form for new and edit * Avoid negative margin on input prefix * Centered now default for modals
33 lines
875 B
TypeScript
33 lines
875 B
TypeScript
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import { toast } from "sonner";
|
|
import Collection from "~/models/Collection";
|
|
import useStores from "~/hooks/useStores";
|
|
import history from "~/utils/history";
|
|
import { CollectionForm, FormData } from "./CollectionForm";
|
|
|
|
type Props = {
|
|
onSubmit: () => void;
|
|
};
|
|
|
|
export const CollectionNew = observer(function CollectionNew_({
|
|
onSubmit,
|
|
}: Props) {
|
|
const { collections } = useStores();
|
|
const handleSubmit = React.useCallback(
|
|
async (data: FormData) => {
|
|
try {
|
|
const collection = new Collection(data, collections);
|
|
await collection.save();
|
|
onSubmit?.();
|
|
history.push(collection.path);
|
|
} catch (error) {
|
|
toast.error(error.message);
|
|
}
|
|
},
|
|
[collections, onSubmit]
|
|
);
|
|
|
|
return <CollectionForm handleSubmit={handleSubmit} />;
|
|
});
|