diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index 1a905db..9ac6c9d 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -107,6 +107,12 @@ function CustomersTab() { const [selected, setSelected] = useState(null) const [showForm, setShowForm] = useState(false) + const deleteCustomer = async (id) => { + await fetch(`${API}/customers/${id}`, { method: 'DELETE' }) + if (selected === id) setSelected(null) + reload() + } + if (!customers) return return (
@@ -143,7 +149,7 @@ function CustomersTab() {
- {selected ? : ( + {selected ? deleteCustomer(selected)} /> : (

בחר לקוח מהרשימה

@@ -226,7 +232,7 @@ function CustomerForm({ onDone, onCancel, customer }) { ) } -function CustomerDetail({ customerId }) { +function CustomerDetail({ customerId, onDelete }) { const { data: customer, reload } = useFetch(`${API}/customers/${customerId}`) const { data: allExtensions } = useFetch(`${API}/extensions`) const [deploying, setDeploying] = useState(null) @@ -366,6 +372,11 @@ function CustomerDetail({ customerId }) { title="עריכת לקוח"> +
)} diff --git a/server.py b/server.py index 1e9ab9a..ef8621f 100644 --- a/server.py +++ b/server.py @@ -492,6 +492,9 @@ class APIHandler(BaseHTTPRequestHandler): if re.match(r'/api/customers/\d+/extensions/\d+$', path): m = re.search(r'/api/customers/(\d+)/extensions/(\d+)', path) self._remove_extension(int(m.group(1)), int(m.group(2))) + elif re.match(r'/api/customers/\d+$', path): + cid = int(re.search(r'/api/customers/(\d+)', path).group(1)) + self._delete_customer(cid) else: self._respond(404, {'error': 'Not found'}) @@ -560,6 +563,12 @@ class APIHandler(BaseHTTPRequestHandler): (cid, body['extension_id'], body.get('auto_update', True), body.get('license_status', 'active')), fetch=None) self._respond(201, {'status': 'ok'}) + def _delete_customer(self, cid): + query("DELETE FROM customer_extensions WHERE customer_id = %s", (cid,), fetch=None) + query("DELETE FROM deployment_log WHERE customer_id = %s", (cid,), fetch=None) + query("DELETE FROM customers WHERE id = %s", (cid,), fetch=None) + self._respond(200, {'status': 'ok'}) + def _remove_extension(self, cid, ext_id): query("DELETE FROM customer_extensions WHERE customer_id = %s AND extension_id = %s", (cid, ext_id), fetch=None) self._respond(200, {'status': 'ok'})