small fixes

This commit is contained in:
Arseni
2026-02-11 15:26:11 +03:00
parent edb43f9909
commit 0a1e04d0d6
7 changed files with 138 additions and 53 deletions

View File

@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:share_plus/share_plus.dart';
import 'package:pshared/config/constants.dart';
import 'package:pshared/models/organization/organization.dart';
import 'package:pshared/provider/resource.dart';
@@ -88,4 +90,55 @@ class OrganizationsProvider extends ChangeNotifier {
// Best-effort cleanup of stored selection to avoid using stale org on next login.
await SecureStorageService.delete(Constants.currentOrgKey);
}
Future<Organization> uploadLogo(XFile logoFile) async {
if (!isOrganizationSet) {
throw StateError('Organization is not set');
}
_setResource(_resource.copyWith(isLoading: true, error: null));
try {
final updated = await OrganizationService.uploadLogoAndUpdate(current, logoFile);
final updatedList = organizations
.map((org) => org.id == updated.id ? updated : org)
.toList(growable: false);
_setResource(Resource(data: updatedList, isLoading: false));
_currentOrg = updated.id;
return updated;
} catch (e) {
_setResource(_resource.copyWith(isLoading: false, error: toException(e)));
rethrow;
}
}
Future<Organization> updateCurrent({
String? name,
String? description,
String? timeZone,
String? logoUrl,
}) async {
if (!isOrganizationSet) {
throw StateError('Organization is not set');
}
_setResource(_resource.copyWith(isLoading: true, error: null));
try {
final updated = await OrganizationService.updateSettings(
current,
name: name,
description: description,
timeZone: timeZone,
logoUrl: logoUrl,
);
final updatedList = organizations
.map((org) => org.id == updated.id ? updated : org)
.toList(growable: false);
_setResource(Resource(data: updatedList, isLoading: false));
_currentOrg = updated.id;
return updated;
} catch (e) {
_setResource(_resource.copyWith(isLoading: false, error: toException(e)));
rethrow;
}
}
}