Fix Zone types

This commit is contained in:
Timothy Armes
2024-04-15 11:45:07 +02:00
parent 8db61bc79b
commit 697131b0f3
2 changed files with 22 additions and 13 deletions
@@ -10,12 +10,13 @@ import { Label } from "@/components/form/Label";
import { TextField } from "@/components/form/TextField";
import { ZoneEditorField } from "@/components/form/ZoneEditorField";
import { zoneSchema } from "@/schemas";
import { Zone } from "@/server/myZones";
import { TimeControl } from "@/types";
export type ZoneFormValues = z.infer<typeof zoneSchema>;
type ZoneFormProps = {
zone?: ZoneFormValues;
zone?: Zone;
onSubmit: (data: ZoneFormValues) => Promise<void>;
onCancel: () => void;
submitTitle?: string;
@@ -35,15 +36,23 @@ export const ZoneForm = ({
// @ts-ignore - Type instantiation is excessively deep and possibly infinite
const form = useForm<ZoneFormValues>({
resolver: zodResolver(zoneSchema),
defaultValues: zone ?? {
classicNotifications: false,
rapidNotifications: false,
blitzNotifications: false,
features: {
type: "FeatureCollection",
features: [],
},
},
defaultValues: zone
? {
name: zone.name,
classicNotifications: zone.classicNotifications,
rapidNotifications: zone.rapidNotifications,
blitzNotifications: zone.blitzNotifications,
features: zone.features as ZoneFormValues["features"],
}
: {
classicNotifications: false,
rapidNotifications: false,
blitzNotifications: false,
features: {
type: "FeatureCollection",
features: [],
},
},
});
return (
@@ -4,16 +4,16 @@ import L, { LatLngLiteral } from "leaflet";
import "leaflet-defaulticon-compatibility";
import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css";
import "leaflet/dist/leaflet.css";
import { FeatureGroup, GeoJSON, MapContainer, TileLayer } from "react-leaflet";
import { GeoJSON, MapContainer, TileLayer } from "react-leaflet";
import { twMerge } from "tailwind-merge";
import { MapEvents } from "@/components/MapEvents";
import type { ZoneModel } from "@/server/models/zoneModel";
import { Zone } from "@/server/myZones";
const center: LatLngLiteral = { lat: 47.0844, lng: 2.3964 };
export type ZoneThumbnailProps = {
features: ZoneModel["features"];
features: Zone["features"];
className?: string;
};