feat: connect UsersPage and SettingsPage SMTP to API + extend user roles/fields

- Migration 034: extend users table with phone, position, active columns; add new roles (receptionist, accountant, security)
- Backend users.ts: accept phone/position on create, accept phone/position/active/role on update; managers can now assign all non-admin roles
- types/index.ts + api.ts: add phone, position, active to User type and users create/update payload types
- UsersPage: fix mapRole to handle all 5 roles, fix toStaffUser to use real phone/position/active from API, fix handleSave to pass all fields
- SettingsPage: load SMTP settings from hotelSettings API on mount, save SMTP on handleSave when section === 'notify'

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-26 00:29:13 +03:00
parent c610486d08
commit 943b97c200
6 changed files with 80 additions and 17 deletions

View File

@@ -174,7 +174,11 @@ const INITIAL_ROLE_PERMISSIONS: RolePermissions[] = [
// ── Helpers ────────────────────────────────────────────────────────────────────
function mapRole(r: string): StaffRole {
return r === 'housekeeper' ? 'housekeeper' : 'hotel_manager'
if (r === 'housekeeper') return 'housekeeper'
if (r === 'receptionist') return 'receptionist'
if (r === 'accountant') return 'accountant'
if (r === 'security') return 'security'
return 'hotel_manager'
}
function toStaffUser(u: User): StaffUser {
@@ -188,9 +192,10 @@ function toStaffUser(u: User): StaffUser {
firstName,
lastName,
email: u.email,
phone: u.phone ?? '',
role,
position: DEFAULT_POSITIONS[role]?.[0] ?? '',
isActive: true,
position: u.position ?? DEFAULT_POSITIONS[role]?.[0] ?? '',
isActive: u.active ?? true,
createdAt: u.createdAt?.slice(0, 10) ?? '',
avatarColor: AVATAR_COLORS[colorIndex],
}
@@ -701,15 +706,23 @@ export function UsersPage() {
const handleSave = async (u: StaffUser, password?: string) => {
const fullName = `${u.firstName} ${u.lastName}`.trim()
const backendRole = u.role === 'housekeeper' ? 'housekeeper' : 'manager'
const backendRole = u.role === 'housekeeper' ? 'housekeeper'
: u.role === 'receptionist' ? 'receptionist'
: u.role === 'accountant' ? 'accountant'
: u.role === 'security' ? 'security'
: 'manager'
try {
if (!u.id) {
const created = await api.users.create(slug, {
email: u.email, name: fullName, password: password ?? '', role: backendRole,
phone: u.phone || undefined, position: u.position || undefined,
})
setUsers(prev => [...prev, toStaffUser(created)])
} else {
const upd: Partial<{ name: string; email: string; password: string }> = { name: fullName, email: u.email }
const upd: Partial<{ name: string; email: string; password: string; role: string; phone: string; position: string; active: boolean }> = {
name: fullName, email: u.email, role: backendRole,
phone: u.phone || undefined, position: u.position || undefined, active: u.isActive,
}
if (password) upd.password = password
const updated = await api.users.update(slug, u.id, upd)
setUsers(prev => prev.map(x => x.id === u.id ? { ...toStaffUser(updated), lastLogin: x.lastLogin } : x))