intrgrating suggestions after betta 1

This commit is contained in:
2025-09-08 18:06:00 +03:00
parent eb262451ad
commit 106045d72a
34 changed files with 1549 additions and 146 deletions

View File

@@ -2,6 +2,7 @@ import flet as ft
import requests
import time
from config import API_BASE_URL
from pages.users_page import Users
class ProfilePage:
def __init__(self, page: ft.Page, dashboard):
@@ -138,9 +139,9 @@ class ProfilePage:
),
)
self.created_at_text = ft.Text(value="Created At: TBD") # Set dynamically later
self.edit_button = ft.ElevatedButton(text="Edit Profile", on_click=self.on_edit_click)
self.save_button = ft.ElevatedButton(text="Save Changes", visible=False, on_click=self.on_save_click)
self.cancel_button = ft.TextButton(text="Cancel", visible=False, on_click=self.on_cancel_click)
self.edit_button = ft.ElevatedButton(text="Edit Profile", on_click=self.on_edit_click, width=100)
self.save_button = ft.ElevatedButton(text="Save Changes", visible=False, on_click=self.on_save_click, width=130)
self.cancel_button = ft.ElevatedButton(text="Cancel", visible=False, on_click=self.on_cancel_click, width=100)
self.upload_logo_btn = ft.ElevatedButton("Upload Company Logo", icon=ft.Icons.UPLOAD, on_click=self.on_upload_click, disabled=True)
self.message = ft.Text()
self.logo = ft.Image(src="images/image_placeholder.png", width=250)
@@ -177,6 +178,18 @@ class ProfilePage:
),
)
self.add_users = ft.Button(
"Add Users",
icon=ft.Icons.MANAGE_ACCOUNTS_ROUNDED,
width=250,
on_click=self.on_add_users_btn_click
)
def on_add_users_btn_click(self, e):
users = Users(self.page, self.dashboard)
self.dashboard.placeholder.content = users.build()
self.dashboard.placeholder.update()
def _auth_headers(self):
"""Build Authorization header from client storage robustly (web/desktop)."""
t = self.page.client_storage.get("token")
@@ -408,12 +421,22 @@ class ProfilePage:
self.message.color = ft.Colors.RED
self.page.update()
def get_client_access(self):
token = self.page.client_storage.get("token")
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(f"{API_BASE_URL}/profile/", headers=headers, timeout=10)
user = response.json()
if user['user_role'] == 'user':
return True
else:
return False
def build(self):
self.populate_user_data()
return ft.Container(
content=ft.Column(
[
ft.Text("User Profile", size=24, weight=ft.FontWeight.BOLD),
ft.Text("Company Profile", size=24, weight=ft.FontWeight.BOLD),
ft.Row(
[
ft.Column(
@@ -425,7 +448,10 @@ class ProfilePage:
self.smtp_user,
self.smtp_host,
self.smtp_port,
ft.Row([self.edit_button, self.save_button, self.cancel_button])
ft.Text(),
ft.Row([self.edit_button, self.save_button, self.cancel_button]),
ft.Divider(),
self.add_users,ft.Text()
],
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
width=250
@@ -455,4 +481,30 @@ class ProfilePage:
],
scroll=ft.ScrollMode.ADAPTIVE
),
) if self.get_client_access() else ft.Container(
content=ft.Column(
[
ft.Row(
[
ft.Text("Company Profile", size=24, weight=ft.FontWeight.BOLD),
],
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
),
ft.Row(
[
ft.Text(
"You do not have access to this page content",
size=24,
weight=ft.FontWeight.BOLD,
color=ft.Colors.RED
)
],
alignment=ft.MainAxisAlignment.CENTER
),
ft.Text("")
],
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
expand=True
),
expand=True
)