From e6cac3576304e0b77e7419393b5c1467ede2fbc1 Mon Sep 17 00:00:00 2001
From: marco370 <48531002-marco370@users.noreply.replit.com>
Date: Fri, 17 Oct 2025 09:46:18 +0000
Subject: [PATCH] Add functionality to manage service types for scheduling
Introduce state management, form handling with Zod validation, and mutation logic for creating and updating service types via API endpoints.
Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e5565357-90e1-419f-b9a8-6ee8394636df
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e5565357-90e1-419f-b9a8-6ee8394636df/EEOXc3D
---
client/src/pages/services.tsx | 468 ++++++++++++++++++++++++++++++++++
1 file changed, 468 insertions(+)
diff --git a/client/src/pages/services.tsx b/client/src/pages/services.tsx
index 57a3ecd..e1af315 100644
--- a/client/src/pages/services.tsx
+++ b/client/src/pages/services.tsx
@@ -58,6 +58,7 @@ const getColorClasses = (color: string) => {
};
type SiteForm = z.infer;
+type ServiceTypeForm = z.infer;
export default function Services() {
const { toast } = useToast();
@@ -65,6 +66,12 @@ export default function Services() {
const [createDialogOpen, setCreateDialogOpen] = useState(false);
const [editDialogOpen, setEditDialogOpen] = useState(false);
const [selectedSite, setSelectedSite] = useState(null);
+
+ // Service Type management states
+ const [manageTypesDialogOpen, setManageTypesDialogOpen] = useState(false);
+ const [createTypeDialogOpen, setCreateTypeDialogOpen] = useState(false);
+ const [editTypeDialogOpen, setEditTypeDialogOpen] = useState(false);
+ const [selectedType, setSelectedType] = useState(null);
const { data: sites = [], isLoading: isLoadingSites } = useQuery({
queryKey: ["/api/sites"],
@@ -150,6 +157,89 @@ export default function Services() {
},
});
+ // Service Type Forms
+ const createTypeForm = useForm({
+ resolver: zodResolver(insertServiceTypeSchema),
+ defaultValues: {
+ code: "",
+ label: "",
+ description: "",
+ icon: "Building2",
+ color: "blue",
+ isActive: true,
+ },
+ });
+
+ const editTypeForm = useForm({
+ resolver: zodResolver(insertServiceTypeSchema),
+ defaultValues: {
+ code: "",
+ label: "",
+ description: "",
+ icon: "Building2",
+ color: "blue",
+ isActive: true,
+ },
+ });
+
+ // Service Type Mutations
+ const createTypeMutation = useMutation({
+ mutationFn: async (data: ServiceTypeForm) => {
+ return apiRequest("POST", "/api/service-types", data);
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ["/api/service-types"] });
+ toast({
+ title: "Tipologia creata",
+ description: "La tipologia di servizio รจ stata aggiunta con successo.",
+ });
+ setCreateTypeDialogOpen(false);
+ createTypeForm.reset();
+ },
+ onError: (error: any) => {
+ toast({
+ title: "Errore",
+ description: error.message || "Impossibile creare la tipologia.",
+ variant: "destructive",
+ });
+ },
+ });
+
+ const updateTypeMutation = useMutation({
+ mutationFn: async ({ id, data }: { id: string; data: ServiceTypeForm }) => {
+ return apiRequest("PATCH", `/api/service-types/${id}`, data);
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ["/api/service-types"] });
+ toast({
+ title: "Tipologia aggiornata",
+ description: "Le modifiche sono state salvate con successo.",
+ });
+ setEditTypeDialogOpen(false);
+ setSelectedType(null);
+ },
+ onError: (error: any) => {
+ toast({
+ title: "Errore",
+ description: error.message || "Impossibile aggiornare la tipologia.",
+ variant: "destructive",
+ });
+ },
+ });
+
+ const handleEditType = (type: ServiceType) => {
+ setSelectedType(type);
+ editTypeForm.reset({
+ code: type.code,
+ label: type.label,
+ description: type.description,
+ icon: type.icon,
+ color: type.color,
+ isActive: type.isActive,
+ });
+ setEditTypeDialogOpen(true);
+ };
+
const handleCreateSite = (serviceType: string) => {
createForm.reset({
name: "",
@@ -206,6 +296,13 @@ export default function Services() {
Panoramica tipologie di servizio e relative configurazioni
+
{isLoading ? (
@@ -712,6 +809,377 @@ export default function Services() {
+
+ {/* Manage Service Types Dialog */}
+
+
+ {/* Create Service Type Dialog */}
+
+
+ {/* Edit Service Type Dialog */}
+
);
}