mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-11-18 07:22:06 +00:00
Zone collection + creation
Zone create UI flow
This commit is contained in:
@@ -1,28 +1,50 @@
|
||||
"use client";
|
||||
|
||||
import { FeatureCollection } from "geojson";
|
||||
import { useState } from "react";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
import { ZoneForm } from "../components/ZoneForm";
|
||||
import InfoMessage, { clearMessage } from "@/components/InfoMessage";
|
||||
import { createZone } from "@/server/createZone";
|
||||
import { useRouter } from "@/utils/navigation";
|
||||
|
||||
type ZoneFormValues = {
|
||||
features: FeatureCollection;
|
||||
};
|
||||
import { ZoneForm, ZoneFormValues } from "../components/ZoneForm";
|
||||
|
||||
const CreateZone = () => {
|
||||
const t = useTranslations("Zones");
|
||||
const router = useRouter();
|
||||
|
||||
const [responseMessage, setResponseMessage] = useState({
|
||||
isSuccessful: false,
|
||||
message: "",
|
||||
});
|
||||
|
||||
const onSubmit = async (data: ZoneFormValues) => {
|
||||
try {
|
||||
console.log(data);
|
||||
await createZone(data);
|
||||
router.push("/zones");
|
||||
} catch (err: unknown) {
|
||||
console.log(err);
|
||||
setResponseMessage({
|
||||
isSuccessful: false,
|
||||
message: t("createFailure"),
|
||||
});
|
||||
|
||||
clearMessage(setResponseMessage);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-screen-md px-4 py-8 lg:py-16">
|
||||
<ZoneForm />
|
||||
<div className="mx-auto max-w-screen-md px-4 pb-20 pt-8 lg:pt-16">
|
||||
<h2
|
||||
className="mb-4 text-center text-4xl font-extrabold tracking-tight text-gray-900 dark:text-white"
|
||||
data-test="header2"
|
||||
>
|
||||
{t("createTitle")}
|
||||
</h2>
|
||||
|
||||
<ZoneForm onSubmit={onSubmit} onCancel={() => router.push("/zones")} />
|
||||
<InfoMessage responseMessage={responseMessage} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user