Skip to content

Commit cb48de4

Browse files
committed
added latitude and longitude code to schema
1 parent 71ec580 commit cb48de4

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

netmanager-app/app/(authenticated)/sites/create-site-form.tsx

+21-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,31 @@ import { MapContainer, TileLayer, Marker, useMap } from "react-leaflet";
3535
import "leaflet/dist/leaflet.css";
3636
import L from "leaflet";
3737
import { useApproximateCoordinates } from "@/core/hooks/useSites";
38+
import { AxiosError } from "axios";
39+
import Error from "next/error";
3840

3941
const siteFormSchema = z.object({
4042
name: z.string().min(2, {
4143
message: "Site name must be at least 2 characters.",
4244
}),
45+
latitude: z.string().refine(
46+
(val) => {
47+
const num = parseFloat(val);
48+
return !isNaN(num) && num >= -90 && num <= 90;
49+
},
50+
{
51+
message: "Latitude must be a valid number between -90 and 90",
52+
}
53+
),
54+
longitude: z.string().refine(
55+
(val) => {
56+
const num = parseFloat(val);
57+
return !isNaN(num) && num >= -180 && num <= 180;
58+
},
59+
{
60+
message: "Longitude must be a valid number between -180 and 180",
61+
}
62+
),
4363
});
4464

4565
type SiteFormValues = z.infer<typeof siteFormSchema>;
@@ -119,7 +139,6 @@ export function CreateSiteForm() {
119139
const [loading, setLoading] = useState(false);
120140
const [error, setError] = useState<string | null>(null);
121141
const [currentStep, setCurrentStep] = useState(0);
122-
const router = useRouter();
123142
const queryClient = useQueryClient();
124143
const activeNetwork = useAppSelector((state) => state.user.activeNetwork);
125144
const { getApproximateCoordinates, isPending } = useApproximateCoordinates();
@@ -309,7 +328,7 @@ export function CreateSiteForm() {
309328
Optimizing...
310329
</>
311330
) : (
312-
"⭐ Optimize Location"
331+
"⭐ Optimize Coordinates"
313332
)}
314333
</Button>
315334
</div>

0 commit comments

Comments
 (0)