28 lines
1005 B
Python
28 lines
1005 B
Python
# dashboard/callbacks/appointments_callbacks.py
|
|
import dash
|
|
from dash import Input, Output, State, dcc
|
|
from flask import session
|
|
from utils.db import execute_query, execute_non_query
|
|
|
|
@dash.callback(
|
|
Output("appointments-feedback", "children"),
|
|
Input("btn-add-appointment", "n_clicks"),
|
|
State("input-client-id", "value"),
|
|
State("input-appointment-date", "date"),
|
|
State("input-appointment-time", "value"),
|
|
State("input-appointment-desc", "value"),
|
|
prevent_initial_call=True
|
|
)
|
|
def add_appointment(n_clicks, client_id, date, time_str, desc):
|
|
if "role" not in session:
|
|
return dcc.Location(href="/login")
|
|
if n_clicks and n_clicks > 0:
|
|
datetime_str = f"{date} {time_str}:00"
|
|
sql = """
|
|
INSERT INTO appointments (client_id, start_datetime, description)
|
|
VALUES (%s, %s, %s)
|
|
"""
|
|
rc = execute_non_query(sql, (client_id, datetime_str, desc))
|
|
return "Erstellt." if rc else "Fehler beim Anlegen."
|
|
return ""
|