Update: 2026-05-03 23:57:27
This commit is contained in:
@@ -153,6 +153,15 @@
|
||||
<option value="admin">مدير نظام</option>
|
||||
</select>
|
||||
</div>
|
||||
<div x-show="user?.role === 'super_admin'">
|
||||
<label class="block text-xs text-gray-500 uppercase mb-1">تعيين لمكتب (للسوبر أدمن فقط)</label>
|
||||
<select x-model="newUser.tenant_id" class="w-full bg-gray-950 border border-gray-800 p-3 rounded outline-none focus:border-emerald-500">
|
||||
<option value="">-- اختر المكتب --</option>
|
||||
<template x-for="t in tenants" :key="t.id">
|
||||
<option :value="t.id" x-text="t.name"></option>
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
<div class="pt-4 flex gap-3">
|
||||
<button type="submit" class="flex-1 bg-emerald-600 hover:bg-emerald-500 py-3 rounded font-bold transition">حفظ المستخدم</button>
|
||||
<button type="button" @click="showAddModal = false" class="px-6 py-3 border border-gray-800 rounded hover:bg-gray-800 transition">إلغاء</button>
|
||||
@@ -178,6 +187,20 @@
|
||||
<label class="block text-xs text-gray-500 uppercase mb-1">الهاتف</label>
|
||||
<input type="text" x-model="newTenant.phone" class="w-full bg-gray-950 border border-gray-800 p-3 rounded outline-none focus:border-emerald-500">
|
||||
</div>
|
||||
<hr class="border-gray-800 my-4">
|
||||
<h4 class="text-sm font-bold text-gray-400">معلومات مدير المكتب (Admin)</h4>
|
||||
<div>
|
||||
<label class="block text-xs text-gray-500 uppercase mb-1">اسم المدير</label>
|
||||
<input type="text" x-model="newTenant.manager_name" required class="w-full bg-gray-950 border border-gray-800 p-3 rounded outline-none focus:border-emerald-500">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-gray-500 uppercase mb-1">بريد المدير (لتسجيل الدخول)</label>
|
||||
<input type="email" x-model="newTenant.manager_email" required class="w-full bg-gray-950 border border-gray-800 p-3 rounded outline-none focus:border-emerald-500">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-gray-500 uppercase mb-1">كلمة المرور</label>
|
||||
<input type="password" x-model="newTenant.manager_password" required class="w-full bg-gray-950 border border-gray-800 p-3 rounded outline-none focus:border-emerald-500">
|
||||
</div>
|
||||
<div class="flex gap-3 pt-4">
|
||||
<button type="submit" class="flex-1 bg-emerald-600 hover:bg-emerald-500 p-3 rounded font-bold transition">حفظ</button>
|
||||
<button type="button" @click="showAddTenantModal = false" class="flex-1 bg-gray-800 hover:bg-gray-700 p-3 rounded transition">إلغاء</button>
|
||||
@@ -223,17 +246,22 @@
|
||||
page: 'dashboard',
|
||||
users: [],
|
||||
companies: [],
|
||||
tenants: [],
|
||||
stats: { total: 0, pending: 0, approved: 0 },
|
||||
showAddModal: false,
|
||||
showAddCompanyModal: false,
|
||||
newUser: { name: '', email: '', password: '', role: 'employee' },
|
||||
newUser: { name: '', email: '', password: '', role: 'employee', tenant_id: '' },
|
||||
newCompany: { name: '', tax_identification_number: '', commercial_registration_number: '', address: '' },
|
||||
newTenant: { name: '', email: '', phone: '', manager_name: '', manager_email: '', manager_password: '' },
|
||||
|
||||
init() {
|
||||
if (!this.user) window.location.href = '/login.php';
|
||||
this.loadUsers();
|
||||
this.loadStats();
|
||||
this.loadCompanies();
|
||||
if (this.user.role === 'super_admin') {
|
||||
this.loadTenants();
|
||||
}
|
||||
},
|
||||
|
||||
title() {
|
||||
@@ -277,7 +305,7 @@
|
||||
const json = await res.json();
|
||||
if (json.success) {
|
||||
this.showAddModal = false;
|
||||
this.newUser = { name: '', email: '', password: '', role: 'employee' };
|
||||
this.newUser = { name: '', email: '', password: '', role: 'employee', tenant_id: '' };
|
||||
this.loadUsers();
|
||||
alert('تم إضافة المستخدم بنجاح');
|
||||
} else {
|
||||
@@ -305,6 +333,34 @@
|
||||
}
|
||||
},
|
||||
|
||||
async loadTenants() {
|
||||
const res = await fetch('/api/v1/tenants', {
|
||||
headers: { 'Authorization': 'Bearer ' + localStorage.getItem('access_token') }
|
||||
});
|
||||
const json = await res.json();
|
||||
if (json.success) this.tenants = json.data;
|
||||
},
|
||||
|
||||
async createTenant() {
|
||||
const res = await fetch('/api/v1/tenants/create', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
|
||||
},
|
||||
body: JSON.stringify(this.newTenant)
|
||||
});
|
||||
const json = await res.json();
|
||||
if (json.success) {
|
||||
this.showAddTenantModal = false;
|
||||
this.newTenant = { name: '', email: '', phone: '', manager_name: '', manager_email: '', manager_password: '' };
|
||||
this.loadTenants();
|
||||
alert('تم إنشاء المكتب وتعيين المدير بنجاح!');
|
||||
} else {
|
||||
alert(json.message);
|
||||
}
|
||||
},
|
||||
|
||||
logout() {
|
||||
localStorage.clear();
|
||||
window.location.href = '/login.php';
|
||||
|
||||
Reference in New Issue
Block a user