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 */}
+
);
}